@Test @RunWithCustomExecutor public void testVitamCollectionRequests() throws InvalidParseOperationException, BadRequestException, DatabaseException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); DbRequestSingle dbRequestSingle = new DbRequestSingle(vitamCollection, Collections::emptyList); assertEquals(0, vitamCollection.getCollection().countDocuments()); final ArrayNode data = JsonHandler.createArrayNode(); data.add(getNewDocument(GUIDFactory.newGUID().toString(), "title one", 1)); data.add(getNewDocument(GUIDFactory.newGUID().toString(), "title two", 2)); final Insert insert = new Insert(); insert.setData(data); final DbRequestResult insertResult = dbRequestSingle.execute(insert, 0, mock(DocumentValidator.class)); assertEquals(2, insertResult.getCount()); assertEquals(2, vitamCollection.getCollection().countDocuments()); insertResult.close(); final Select select = new Select(); final DbRequestResult selectResult = dbRequestSingle.execute(select); final List<VitamDocument> selectCursor = selectResult.getDocuments(VitamDocument.class); assertEquals(true, !selectCursor.isEmpty()); assertEquals(2, selectCursor.size()); selectCursor.clear(); selectResult.close(); Select select2 = new Select(); select2.setLimitFilter(11000, 11000); try { final DbRequestResult selectResult2 = dbRequestSingle.execute(select2); final List<VitamDocument> selectCursor2 = selectResult2.getDocuments(VitamDocument.class); fail("Should throw an exception, since max_result_window is 10000"); } catch (BadRequestException e) { } final Select sortedSelect = new Select(); sortedSelect.addOrderByDescFilter("Title.keyword"); final DbRequestResult sortedSelectResult = dbRequestSingle.execute(sortedSelect); final List<VitamDocument> sortedSelectCursor = sortedSelectResult.getDocuments(VitamDocument.class); final Document documentSorted1 = sortedSelectCursor.get(0); final Document documentSorted2 = sortedSelectCursor.get(1); assertEquals("title two", documentSorted1.getString("Title")); assertEquals("title one", documentSorted2.getString("Title")); sortedSelectCursor.clear(); sortedSelectResult.close(); final Select sortedSelectES = new Select(); sortedSelectES.setQuery(match("Title", "title")); sortedSelectES.addOrderByDescFilter("Title.keyword"); DbRequestResult sortedSelectESResult = dbRequestSingle.execute(sortedSelectES); List<VitamDocument> sortedSelectESCursor = sortedSelectESResult.getDocuments(VitamDocument.class); final Document documentSortedES1 = sortedSelectESCursor.get(0); final Document documentSortedES2 = sortedSelectESCursor.get(1); assertEquals("title two", documentSortedES1.getString("Title")); assertEquals("title one", documentSortedES2.getString("Title")); sortedSelectESCursor.clear(); sortedSelectESResult.close(); final Update update = new Update(); update.setQuery(eq("Title.keyword", "title one")); update.addActions(UpdateActionHelper.set("Title", "new name")); final DbRequestResult updateResult = dbRequestSingle.execute(update, mock(DocumentValidator.class)); assertEquals(1, updateResult.getCount()); updateResult.close(); sortedSelectESResult = dbRequestSingle.execute(sortedSelectES); sortedSelectESCursor = sortedSelectESResult.getDocuments(VitamDocument.class); assertEquals(1, sortedSelectESCursor.size()); sortedSelectESCursor.clear(); sortedSelectESResult.close(); final Delete delete = new Delete(); delete.setQuery(match("Title", "title")); final DbRequestResult deleteResult = dbRequestSingle.execute(delete); assertEquals(1, deleteResult.getCount()); assertEquals(1, vitamCollection.getCollection().countDocuments()); deleteResult.close(); }
public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); }
DbRequestSingle { public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); } }
DbRequestSingle { public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); } DbRequestSingle(VitamCollection collection, OntologyLoader ontologyLoader); }
DbRequestSingle { public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); } DbRequestSingle(VitamCollection collection, OntologyLoader ontologyLoader); DbRequestResult execute(Select request); DbRequestResult execute(Insert request, Integer version,
        DocumentValidator documentValidator); DbRequestResult execute(Delete request); DbRequestResult execute(Update request, DocumentValidator documentValidator); DbRequestResult execute(Update request, Integer version, DocumentValidator documentValidator); void replaceDocument(JsonNode document, String identifierValue, String identifierKey,
        VitamCollection vitamCollection); }
DbRequestSingle { public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); } DbRequestSingle(VitamCollection collection, OntologyLoader ontologyLoader); DbRequestResult execute(Select request); DbRequestResult execute(Insert request, Integer version,
        DocumentValidator documentValidator); DbRequestResult execute(Delete request); DbRequestResult execute(Update request, DocumentValidator documentValidator); DbRequestResult execute(Update request, Integer version, DocumentValidator documentValidator); void replaceDocument(JsonNode document, String identifierValue, String identifierKey,
        VitamCollection vitamCollection);  }