@Test @RunWithCustomExecutor public void testSelectResult() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID_0); final DbRequest dbRequest = new DbRequest(); final JsonNode selectRequest = JsonHandler.getFromString(REQUEST_SELECT_TEST); final SelectParserMultiple selectParser = new SelectParserMultiple(mongoDbVarNameAdapter); selectParser.parse(selectRequest); LOGGER.debug("SelectParser: {}", selectRequest); final Result result = dbRequest.execRequest(selectParser, Collections.emptyList()); assertEquals("[]", result.getFinal().toString()); }
public Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies) throws MetaDataExecutionException, InvalidParseOperationException, BadRequestException, VitamDBException { final RequestMultiple request = requestParser.getRequest(); final RequestToAbstract requestToMongodb = RequestToMongodb.getRequestToMongoDb(requestParser); final int maxQuery = request.getNbQueries(); boolean checkConsistency = false; Result<MetadataDocument<?>> roots; MetadataCollections metadataCollections; if (requestParser.model() == FILTERARGS.UNITS) { roots = checkUnitStartupRoots(requestParser); metadataCollections = MetadataCollections.UNIT; } else { metadataCollections = MetadataCollections.OBJECTGROUP; if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("OBJECTGROUPS DbRequest: %s", requestParser.toString())); } roots = checkObjectGroupStartupRoots(requestParser); } DynamicParserTokens parserTokens = new DynamicParserTokens(metadataCollections.getVitamDescriptionResolver(), ontologies); Result<MetadataDocument<?>> result = roots; int rank = 0; if (result.getCurrentIds().isEmpty() && maxQuery > 0) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult != null && !newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; checkConsistency = true; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(requestParser.model()) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result).setTotal(newResult != null ? newResult.total : 0); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); rank++; } for (; !result.getCurrentIds().isEmpty() && rank < maxQuery; rank++) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult == null) { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result.getCurrentIds().toString()) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (!newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(newResult.type) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); } if (result.getCurrentIds().isEmpty()) { LOGGER.debug(NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result != null ? result.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (request instanceof DeleteMultiQuery) { final Result<MetadataDocument<?>> newResult = lastDeleteFilterProjection((DeleteToMongodb) requestToMongodb, result); if (newResult != null) { result = newResult; } } else { final Result<MetadataDocument<?>> newResult = lastSelectFilterProjection((SelectToMongodb) requestToMongodb, result, checkConsistency); if (newResult != null) { result = newResult; } } LOGGER.debug("Results: {}", result); return result; }
DbRequest { public Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies) throws MetaDataExecutionException, InvalidParseOperationException, BadRequestException, VitamDBException { final RequestMultiple request = requestParser.getRequest(); final RequestToAbstract requestToMongodb = RequestToMongodb.getRequestToMongoDb(requestParser); final int maxQuery = request.getNbQueries(); boolean checkConsistency = false; Result<MetadataDocument<?>> roots; MetadataCollections metadataCollections; if (requestParser.model() == FILTERARGS.UNITS) { roots = checkUnitStartupRoots(requestParser); metadataCollections = MetadataCollections.UNIT; } else { metadataCollections = MetadataCollections.OBJECTGROUP; if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("OBJECTGROUPS DbRequest: %s", requestParser.toString())); } roots = checkObjectGroupStartupRoots(requestParser); } DynamicParserTokens parserTokens = new DynamicParserTokens(metadataCollections.getVitamDescriptionResolver(), ontologies); Result<MetadataDocument<?>> result = roots; int rank = 0; if (result.getCurrentIds().isEmpty() && maxQuery > 0) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult != null && !newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; checkConsistency = true; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(requestParser.model()) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result).setTotal(newResult != null ? newResult.total : 0); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); rank++; } for (; !result.getCurrentIds().isEmpty() && rank < maxQuery; rank++) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult == null) { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result.getCurrentIds().toString()) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (!newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(newResult.type) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); } if (result.getCurrentIds().isEmpty()) { LOGGER.debug(NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result != null ? result.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (request instanceof DeleteMultiQuery) { final Result<MetadataDocument<?>> newResult = lastDeleteFilterProjection((DeleteToMongodb) requestToMongodb, result); if (newResult != null) { result = newResult; } } else { final Result<MetadataDocument<?>> newResult = lastSelectFilterProjection((SelectToMongodb) requestToMongodb, result, checkConsistency); if (newResult != null) { result = newResult; } } LOGGER.debug("Results: {}", result); return result; } }
DbRequest { public Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies) throws MetaDataExecutionException, InvalidParseOperationException, BadRequestException, VitamDBException { final RequestMultiple request = requestParser.getRequest(); final RequestToAbstract requestToMongodb = RequestToMongodb.getRequestToMongoDb(requestParser); final int maxQuery = request.getNbQueries(); boolean checkConsistency = false; Result<MetadataDocument<?>> roots; MetadataCollections metadataCollections; if (requestParser.model() == FILTERARGS.UNITS) { roots = checkUnitStartupRoots(requestParser); metadataCollections = MetadataCollections.UNIT; } else { metadataCollections = MetadataCollections.OBJECTGROUP; if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("OBJECTGROUPS DbRequest: %s", requestParser.toString())); } roots = checkObjectGroupStartupRoots(requestParser); } DynamicParserTokens parserTokens = new DynamicParserTokens(metadataCollections.getVitamDescriptionResolver(), ontologies); Result<MetadataDocument<?>> result = roots; int rank = 0; if (result.getCurrentIds().isEmpty() && maxQuery > 0) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult != null && !newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; checkConsistency = true; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(requestParser.model()) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result).setTotal(newResult != null ? newResult.total : 0); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); rank++; } for (; !result.getCurrentIds().isEmpty() && rank < maxQuery; rank++) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult == null) { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result.getCurrentIds().toString()) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (!newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(newResult.type) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); } if (result.getCurrentIds().isEmpty()) { LOGGER.debug(NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result != null ? result.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (request instanceof DeleteMultiQuery) { final Result<MetadataDocument<?>> newResult = lastDeleteFilterProjection((DeleteToMongodb) requestToMongodb, result); if (newResult != null) { result = newResult; } } else { final Result<MetadataDocument<?>> newResult = lastSelectFilterProjection((SelectToMongodb) requestToMongodb, result, checkConsistency); if (newResult != null) { result = newResult; } } LOGGER.debug("Results: {}", result); return result; } @VisibleForTesting  DbRequest(MongoDbMetadataRepository<Unit> mongoDbUnitRepository,
        MongoDbMetadataRepository<ObjectGroup> mongoDbObjectGroupRepository,
        FieldHistoryManager fieldHistoryManager);  DbRequest(); }
DbRequest { public Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies) throws MetaDataExecutionException, InvalidParseOperationException, BadRequestException, VitamDBException { final RequestMultiple request = requestParser.getRequest(); final RequestToAbstract requestToMongodb = RequestToMongodb.getRequestToMongoDb(requestParser); final int maxQuery = request.getNbQueries(); boolean checkConsistency = false; Result<MetadataDocument<?>> roots; MetadataCollections metadataCollections; if (requestParser.model() == FILTERARGS.UNITS) { roots = checkUnitStartupRoots(requestParser); metadataCollections = MetadataCollections.UNIT; } else { metadataCollections = MetadataCollections.OBJECTGROUP; if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("OBJECTGROUPS DbRequest: %s", requestParser.toString())); } roots = checkObjectGroupStartupRoots(requestParser); } DynamicParserTokens parserTokens = new DynamicParserTokens(metadataCollections.getVitamDescriptionResolver(), ontologies); Result<MetadataDocument<?>> result = roots; int rank = 0; if (result.getCurrentIds().isEmpty() && maxQuery > 0) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult != null && !newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; checkConsistency = true; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(requestParser.model()) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result).setTotal(newResult != null ? newResult.total : 0); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); rank++; } for (; !result.getCurrentIds().isEmpty() && rank < maxQuery; rank++) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult == null) { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result.getCurrentIds().toString()) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (!newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(newResult.type) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); } if (result.getCurrentIds().isEmpty()) { LOGGER.debug(NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result != null ? result.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (request instanceof DeleteMultiQuery) { final Result<MetadataDocument<?>> newResult = lastDeleteFilterProjection((DeleteToMongodb) requestToMongodb, result); if (newResult != null) { result = newResult; } } else { final Result<MetadataDocument<?>> newResult = lastSelectFilterProjection((SelectToMongodb) requestToMongodb, result, checkConsistency); if (newResult != null) { result = newResult; } } LOGGER.debug("Results: {}", result); return result; } @VisibleForTesting  DbRequest(MongoDbMetadataRepository<Unit> mongoDbUnitRepository,
        MongoDbMetadataRepository<ObjectGroup> mongoDbObjectGroupRepository,
        FieldHistoryManager fieldHistoryManager);  DbRequest(); UpdatedDocument execRuleRequest(final String documentId, final RuleActions ruleActions,
        Map<String, DurationData> bindRuleToDuration, OntologyValidator ontologyValidator, UnitValidator unitValidator,
        List<OntologyModel> ontologyModels); Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies); UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId,
        MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator,
        List<OntologyModel> ontologyModels); void execInsertUnitRequest(InsertParserMultiple requestParser); void execInsertObjectGroupRequests(List<InsertParserMultiple> requestParsers); void execInsertUnitRequests(BulkUnitInsertRequest request); void deleteUnits(List<String> documentsToDelete); void deleteObjectGroups(List<String> documentsToDelete); }
DbRequest { public Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies) throws MetaDataExecutionException, InvalidParseOperationException, BadRequestException, VitamDBException { final RequestMultiple request = requestParser.getRequest(); final RequestToAbstract requestToMongodb = RequestToMongodb.getRequestToMongoDb(requestParser); final int maxQuery = request.getNbQueries(); boolean checkConsistency = false; Result<MetadataDocument<?>> roots; MetadataCollections metadataCollections; if (requestParser.model() == FILTERARGS.UNITS) { roots = checkUnitStartupRoots(requestParser); metadataCollections = MetadataCollections.UNIT; } else { metadataCollections = MetadataCollections.OBJECTGROUP; if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("OBJECTGROUPS DbRequest: %s", requestParser.toString())); } roots = checkObjectGroupStartupRoots(requestParser); } DynamicParserTokens parserTokens = new DynamicParserTokens(metadataCollections.getVitamDescriptionResolver(), ontologies); Result<MetadataDocument<?>> result = roots; int rank = 0; if (result.getCurrentIds().isEmpty() && maxQuery > 0) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult != null && !newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; checkConsistency = true; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(requestParser.model()) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result).setTotal(newResult != null ? newResult.total : 0); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); rank++; } for (; !result.getCurrentIds().isEmpty() && rank < maxQuery; rank++) { final Result<MetadataDocument<?>> newResult = executeQuery(requestParser, requestToMongodb, rank, result, parserTokens); if (newResult == null) { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result.getCurrentIds().toString()) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (!newResult.getCurrentIds().isEmpty() && !newResult.isError()) { result = newResult; } else { LOGGER.debug( NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(newResult.type) .addError(newResult != null ? newResult.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } LOGGER.debug("Query: {}\n\tResult: {}", requestParser, result); } if (result.getCurrentIds().isEmpty()) { LOGGER.debug(NO_RESULT_AT_RANK + rank + FROM + requestParser + WHERE_PREVIOUS_IS + result); result = new ResultError(result.type) .addError(result != null ? result.getCurrentIds().toString() : NO_RESULT_TRUE) .addError(NO_RESULT_AT_RANK2 + rank).addError(FROM2 + requestParser) .addError(WHERE_PREVIOUS_RESULT_WAS + result); return result; } if (request instanceof DeleteMultiQuery) { final Result<MetadataDocument<?>> newResult = lastDeleteFilterProjection((DeleteToMongodb) requestToMongodb, result); if (newResult != null) { result = newResult; } } else { final Result<MetadataDocument<?>> newResult = lastSelectFilterProjection((SelectToMongodb) requestToMongodb, result, checkConsistency); if (newResult != null) { result = newResult; } } LOGGER.debug("Results: {}", result); return result; } @VisibleForTesting  DbRequest(MongoDbMetadataRepository<Unit> mongoDbUnitRepository,
        MongoDbMetadataRepository<ObjectGroup> mongoDbObjectGroupRepository,
        FieldHistoryManager fieldHistoryManager);  DbRequest(); UpdatedDocument execRuleRequest(final String documentId, final RuleActions ruleActions,
        Map<String, DurationData> bindRuleToDuration, OntologyValidator ontologyValidator, UnitValidator unitValidator,
        List<OntologyModel> ontologyModels); Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies); UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId,
        MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator,
        List<OntologyModel> ontologyModels); void execInsertUnitRequest(InsertParserMultiple requestParser); void execInsertObjectGroupRequests(List<InsertParserMultiple> requestParsers); void execInsertUnitRequests(BulkUnitInsertRequest request); void deleteUnits(List<String> documentsToDelete); void deleteObjectGroups(List<String> documentsToDelete);  }