@Test public void testDiffResultOnUpdate() throws Exception { List<OntologyModel> ontologyModels = Arrays.asList( new OntologyModel().setType(OntologyType.KEYWORD).setIdentifier("_id"), new OntologyModel().setType(OntologyType.TEXT).setIdentifier("title") ); when(adminManagementClient.findOntologies(any())) .thenReturn(new RequestResponseOK<OntologyModel>().addAllResults(ontologyModels)); final JsonNode wantedDiff = JsonHandler.getFromFile(PropertiesUtils.findFile("wantedDiff.json")); final Result updateResult = new ResultDefault(FILTERARGS.UNITS); updateResult.addId("unitId", (float) 1); Unit unit = new Unit(); unit.put("_id", "unitId"); unit.put("title", "title"); unit.put("description", "description"); Unit secondUnit = new Unit(); secondUnit.put("_id", "unitId"); secondUnit.put("title", "MODIFIED title"); secondUnit.put("description", "MODIFIED \"description"); final JsonNode updateRequest = JsonHandler.getFromFile(PropertiesUtils.findFile("updateQuery.json")); when(request.execUpdateRequest(any(), eq("unitId"), eq(MetadataCollections.UNIT), any(OntologyValidator.class), any(UnitValidator.class), anyList())) .thenReturn( new UpdatedDocument("unitId", JsonHandler.toJsonNode(unit), JsonHandler.toJsonNode(secondUnit))); UpdateUnit result = metaDataImpl.updateUnitById(updateRequest, "unitId"); assertEquals(wantedDiff.get("#diff").asText(), result.getDiff()); }
public UpdateUnit updateUnitById(JsonNode updateQuery, String unitId) throws MetaDataNotFoundException, InvalidParseOperationException, MetaDataExecutionException, MetadataValidationException { final RequestParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); UpdatedDocument updatedDocument = dbRequest .execUpdateRequest(updateRequest, unitId, MetadataCollections.UNIT, this.unitOntologyValidator, this.unitValidator, this.unitOntologyLoader.loadOntologies()); String diffs = String.join("\n", VitamDocument.getConcernedDiffLines( VitamDocument.getUnifiedDiff(JsonHandler.prettyPrint(updatedDocument.getBeforeUpdate()), JsonHandler.prettyPrint(updatedDocument.getAfterUpdate())))); return new UpdateUnit(unitId, StatusCode.OK, UNIT_METADATA_UPDATE, "Update unit OK.", diffs); }
MetaDataImpl { public UpdateUnit updateUnitById(JsonNode updateQuery, String unitId) throws MetaDataNotFoundException, InvalidParseOperationException, MetaDataExecutionException, MetadataValidationException { final RequestParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); UpdatedDocument updatedDocument = dbRequest .execUpdateRequest(updateRequest, unitId, MetadataCollections.UNIT, this.unitOntologyValidator, this.unitValidator, this.unitOntologyLoader.loadOntologies()); String diffs = String.join("\n", VitamDocument.getConcernedDiffLines( VitamDocument.getUnifiedDiff(JsonHandler.prettyPrint(updatedDocument.getBeforeUpdate()), JsonHandler.prettyPrint(updatedDocument.getAfterUpdate())))); return new UpdateUnit(unitId, StatusCode.OK, UNIT_METADATA_UPDATE, "Update unit OK.", diffs); } }
MetaDataImpl { public UpdateUnit updateUnitById(JsonNode updateQuery, String unitId) throws MetaDataNotFoundException, InvalidParseOperationException, MetaDataExecutionException, MetadataValidationException { final RequestParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); UpdatedDocument updatedDocument = dbRequest .execUpdateRequest(updateRequest, unitId, MetadataCollections.UNIT, this.unitOntologyValidator, this.unitValidator, this.unitOntologyLoader.loadOntologies()); String diffs = String.join("\n", VitamDocument.getConcernedDiffLines( VitamDocument.getUnifiedDiff(JsonHandler.prettyPrint(updatedDocument.getBeforeUpdate()), JsonHandler.prettyPrint(updatedDocument.getAfterUpdate())))); return new UpdateUnit(unitId, StatusCode.OK, UNIT_METADATA_UPDATE, "Update unit OK.", diffs); } MetaDataImpl(MongoDbAccessMetadataImpl mongoDbAccess,
        int ontologyCacheMaxEntries, int ontologyCacheTimeoutInSeconds,
        int archiveUnitProfileCacheMaxEntries, int archiveUnitProfileCacheTimeoutInSeconds,
        int schemaValidatorCacheMaxEntries, int schemaValidatorCacheTimeoutInSeconds); @VisibleForTesting  MetaDataImpl(MongoDbAccessMetadataImpl mongoDbAccess,
        AdminManagementClientFactory adminManagementClientFactory,
        IndexationHelper indexationHelper,
        DbRequest dbRequest, int ontologyCacheMaxEntries, int ontologyCacheTimeoutInSeconds,
        int archiveUnitProfileCacheMaxEntries, int archiveUnitProfileCacheTimeoutInSeconds,
        int schemaValidatorCacheMaxEntries, int schemaValidatorCacheTimeoutInSeconds); }
MetaDataImpl { public UpdateUnit updateUnitById(JsonNode updateQuery, String unitId) throws MetaDataNotFoundException, InvalidParseOperationException, MetaDataExecutionException, MetadataValidationException { final RequestParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); UpdatedDocument updatedDocument = dbRequest .execUpdateRequest(updateRequest, unitId, MetadataCollections.UNIT, this.unitOntologyValidator, this.unitValidator, this.unitOntologyLoader.loadOntologies()); String diffs = String.join("\n", VitamDocument.getConcernedDiffLines( VitamDocument.getUnifiedDiff(JsonHandler.prettyPrint(updatedDocument.getBeforeUpdate()), JsonHandler.prettyPrint(updatedDocument.getAfterUpdate())))); return new UpdateUnit(unitId, StatusCode.OK, UNIT_METADATA_UPDATE, "Update unit OK.", diffs); } MetaDataImpl(MongoDbAccessMetadataImpl mongoDbAccess,
        int ontologyCacheMaxEntries, int ontologyCacheTimeoutInSeconds,
        int archiveUnitProfileCacheMaxEntries, int archiveUnitProfileCacheTimeoutInSeconds,
        int schemaValidatorCacheMaxEntries, int schemaValidatorCacheTimeoutInSeconds); @VisibleForTesting  MetaDataImpl(MongoDbAccessMetadataImpl mongoDbAccess,
        AdminManagementClientFactory adminManagementClientFactory,
        IndexationHelper indexationHelper,
        DbRequest dbRequest, int ontologyCacheMaxEntries, int ontologyCacheTimeoutInSeconds,
        int archiveUnitProfileCacheMaxEntries, int archiveUnitProfileCacheTimeoutInSeconds,
        int schemaValidatorCacheMaxEntries, int schemaValidatorCacheTimeoutInSeconds); static MetaDataImpl newMetadata(MongoDbAccessMetadataImpl mongoDbAccessMetadata,
        int ontologyCacheMaxEntries, int ontologyCacheTimeoutInSeconds,
        int archiveUnitProfileCacheMaxEntries, int archiveUnitProfileCacheTimeoutInSeconds,
        int schemaValidatorCacheMaxEntries, int schemaValidatorCacheTimeoutInSeconds); MongoDbAccessMetadataImpl getMongoDbAccess(); void insertUnits(BulkUnitInsertRequest request); void deleteUnits(List<String> idList); void deleteObjectGroups(List<String> idList); void insertObjectGroup(JsonNode objectGroupRequest); void insertObjectGroups(List<JsonNode> objectGroupRequest); List<FacetBucket> selectOwnAccessionRegisterOnUnitByOperationId(String operationId); List<Document> createAccessionRegisterSymbolic(Integer tenant); List<ObjectGroupPerOriginatingAgency> selectOwnAccessionRegisterOnObjectGroupByOperationId(Integer tenant,
        String operationId); RequestResponse<JsonNode> selectUnitsByQuery(JsonNode selectQuery); RequestResponse<JsonNode> selectObjectGroupsByQuery(JsonNode selectQuery); RequestResponse<JsonNode> selectUnitsById(JsonNode selectQuery, String unitId); RequestResponse<JsonNode> selectObjectGroupById(JsonNode selectQuery, String objectGroupId); void updateObjectGroupId(JsonNode updateQuery, String objectId); RequestResponse<UpdateUnit> updateUnits(JsonNode updateQuery); RequestResponse<UpdateUnit> updateUnitsRules(List<String> unitIds, RuleActions ruleActions,
        Map<String, DurationData> bindRuleToDuration); UpdateUnit updateUnitById(JsonNode updateQuery, String unitId); void refreshUnit(); void refreshObjectGroup(); IndexationResult reindex(IndexParameters indexParam); void switchIndex(String alias, String newIndexName); }
MetaDataImpl { public UpdateUnit updateUnitById(JsonNode updateQuery, String unitId) throws MetaDataNotFoundException, InvalidParseOperationException, MetaDataExecutionException, MetadataValidationException { final RequestParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); UpdatedDocument updatedDocument = dbRequest .execUpdateRequest(updateRequest, unitId, MetadataCollections.UNIT, this.unitOntologyValidator, this.unitValidator, this.unitOntologyLoader.loadOntologies()); String diffs = String.join("\n", VitamDocument.getConcernedDiffLines( VitamDocument.getUnifiedDiff(JsonHandler.prettyPrint(updatedDocument.getBeforeUpdate()), JsonHandler.prettyPrint(updatedDocument.getAfterUpdate())))); return new UpdateUnit(unitId, StatusCode.OK, UNIT_METADATA_UPDATE, "Update unit OK.", diffs); } MetaDataImpl(MongoDbAccessMetadataImpl mongoDbAccess,
        int ontologyCacheMaxEntries, int ontologyCacheTimeoutInSeconds,
        int archiveUnitProfileCacheMaxEntries, int archiveUnitProfileCacheTimeoutInSeconds,
        int schemaValidatorCacheMaxEntries, int schemaValidatorCacheTimeoutInSeconds); @VisibleForTesting  MetaDataImpl(MongoDbAccessMetadataImpl mongoDbAccess,
        AdminManagementClientFactory adminManagementClientFactory,
        IndexationHelper indexationHelper,
        DbRequest dbRequest, int ontologyCacheMaxEntries, int ontologyCacheTimeoutInSeconds,
        int archiveUnitProfileCacheMaxEntries, int archiveUnitProfileCacheTimeoutInSeconds,
        int schemaValidatorCacheMaxEntries, int schemaValidatorCacheTimeoutInSeconds); static MetaDataImpl newMetadata(MongoDbAccessMetadataImpl mongoDbAccessMetadata,
        int ontologyCacheMaxEntries, int ontologyCacheTimeoutInSeconds,
        int archiveUnitProfileCacheMaxEntries, int archiveUnitProfileCacheTimeoutInSeconds,
        int schemaValidatorCacheMaxEntries, int schemaValidatorCacheTimeoutInSeconds); MongoDbAccessMetadataImpl getMongoDbAccess(); void insertUnits(BulkUnitInsertRequest request); void deleteUnits(List<String> idList); void deleteObjectGroups(List<String> idList); void insertObjectGroup(JsonNode objectGroupRequest); void insertObjectGroups(List<JsonNode> objectGroupRequest); List<FacetBucket> selectOwnAccessionRegisterOnUnitByOperationId(String operationId); List<Document> createAccessionRegisterSymbolic(Integer tenant); List<ObjectGroupPerOriginatingAgency> selectOwnAccessionRegisterOnObjectGroupByOperationId(Integer tenant,
        String operationId); RequestResponse<JsonNode> selectUnitsByQuery(JsonNode selectQuery); RequestResponse<JsonNode> selectObjectGroupsByQuery(JsonNode selectQuery); RequestResponse<JsonNode> selectUnitsById(JsonNode selectQuery, String unitId); RequestResponse<JsonNode> selectObjectGroupById(JsonNode selectQuery, String objectGroupId); void updateObjectGroupId(JsonNode updateQuery, String objectId); RequestResponse<UpdateUnit> updateUnits(JsonNode updateQuery); RequestResponse<UpdateUnit> updateUnitsRules(List<String> unitIds, RuleActions ruleActions,
        Map<String, DurationData> bindRuleToDuration); UpdateUnit updateUnitById(JsonNode updateQuery, String unitId); void refreshUnit(); void refreshObjectGroup(); IndexationResult reindex(IndexParameters indexParam); void switchIndex(String alias, String newIndexName);  }