@Test @RunWithCustomExecutor public void should_return_and_updated_document_with_no_diff_when_ops_already_present() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID_0); VitamThreadUtils.getVitamSession().setRequestId(GUIDFactory.newRequestIdGUID(TENANT_ID_0)); String uuid = "aeaqaaaabeghay2jabzuaalbarkww4iaaaba"; List<OntologyModel> ontologyModels = JsonHandler .getFromInputStreamAsTypeReference(OntologyTestHelper.loadOntologies(), new TypeReference<List<OntologyModel>>() { }); ontologyModels.addAll(Arrays.asList( new OntologyModel().setType(OntologyType.BOOLEAN).setOrigin(OntologyOrigin.EXTERNAL).setIdentifier("Flag"), new OntologyModel().setType(OntologyType.LONG).setOrigin(OntologyOrigin.EXTERNAL).setIdentifier("Number") )); final Unit initialUnit = new Unit( JsonHandler.getFromFile(PropertiesUtils.getResourceFile("unitToUpdate.json"))); MetadataCollections.UNIT.getCollection().insertOne(initialUnit); MetadataCollections.UNIT.getEsClient().insertFullDocument(MetadataCollections.UNIT, 0, uuid, initialUnit); AdminManagementClientFactory adminManagementClientFactory = mock(AdminManagementClientFactory.class); AdminManagementClient adminManagementClient = mock(AdminManagementClient.class); doReturn(adminManagementClient).when(adminManagementClientFactory).getClient(); doReturn(new RequestResponseOK<ArchiveUnitProfileModel>().addResult(new ArchiveUnitProfileModel() .setControlSchema(PropertiesUtils.getResourceAsString("unitAUP_OK.json")) .setStatus(ArchiveUnitProfileStatus.ACTIVE) )).when(adminManagementClient).findArchiveUnitProfilesByID("AUP_IDENTIFIER"); CachedArchiveUnitProfileLoader archiveUnitProfileLoader = new CachedArchiveUnitProfileLoader(adminManagementClientFactory, 100, 300); DbRequest dbRequest = new DbRequest( new MongoDbMetadataRepository<Unit>(() -> MetadataCollections.UNIT.getCollection()), new MongoDbMetadataRepository<ObjectGroup>(() -> MetadataCollections.OBJECTGROUP.getCollection()), fieldHistoryManager ); UpdateMultiQuery update = new UpdateMultiQuery(); update.addActions( push("#operations", "aedqaaaabggsoscfaat22albarkwtiqaaaaq")); UpdateParserMultiple updateParser = new UpdateParserMultiple(mongoDbVarNameAdapter); updateParser.parse(update.getFinalUpdate()); CachedSchemaValidatorLoader schemaValidatorLoader = new CachedSchemaValidatorLoader(100, 300); OntologyValidator ontologyValidator = new OntologyValidator(() -> ontologyModels); UnitValidator unitValidator = new UnitValidator(archiveUnitProfileLoader, schemaValidatorLoader); UpdatedDocument updatedDocument = dbRequest .execUpdateRequest(updateParser, uuid, MetadataCollections.UNIT, ontologyValidator, unitValidator, Collections.emptyList()); String diff = String.join("\n", VitamDocument.getConcernedDiffLines(VitamDocument .getUnifiedDiff(JsonHandler.prettyPrint(updatedDocument.getBeforeUpdate()), JsonHandler.prettyPrint(updatedDocument.getAfterUpdate())))); assertThat(diff).isEmpty(); }
public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); LOGGER.debug("Results: {}", result); return result; }
DbRequest { public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); LOGGER.debug("Results: {}", result); return result; } }
DbRequest { public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); LOGGER.debug("Results: {}", result); return result; } @VisibleForTesting  DbRequest(MongoDbMetadataRepository<Unit> mongoDbUnitRepository,
        MongoDbMetadataRepository<ObjectGroup> mongoDbObjectGroupRepository,
        FieldHistoryManager fieldHistoryManager);  DbRequest(); }
DbRequest { public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); 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 UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); 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);  }