@RunWithCustomExecutor @Test public void testUpdateWithArchiveUnitProfileAndOntologyValidationOK() 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); final DbRequest dbRequest = new DbRequest( new MongoDbMetadataRepository<Unit>(() -> MetadataCollections.UNIT.getCollection()), new MongoDbMetadataRepository<ObjectGroup>(() -> MetadataCollections.OBJECTGROUP.getCollection()), fieldHistoryManager); final UpdateMultiQuery update = new UpdateMultiQuery(); update.addActions(set("Title", "New Title")); update.addActions(set("Flag", "false")); update.addActions(set("Number", "12")); final 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()); ObjectNode expectedUnit = (ObjectNode) JsonHandler.getFromString(BsonHelper.stringify(initialUnit)); expectedUnit.put("Title", "New Title"); expectedUnit.putArray("Flag").add(false); expectedUnit.putArray("Number").add(12); expectedUnit.put("_v", 1); expectedUnit.put("_av", 1); String expected = JsonHandler.unprettyPrint(expectedUnit); String after = JsonHandler.unprettyPrint(MetadataCollections.UNIT.getCollection().find(Filters.eq("_id", uuid)).first()); JsonAssert.assertJsonEquals(expected, after); JsonAssert.assertJsonEquals(BsonHelper.stringify(initialUnit), JsonHandler.unprettyPrint(updatedDocument.getBeforeUpdate())); JsonAssert.assertJsonEquals(expected, JsonHandler.unprettyPrint(updatedDocument.getAfterUpdate())); assertThat(updatedDocument.getDocumentId()).isEqualTo(uuid); }
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);  }