@Test public void testBulkUnitUpdate_OK() 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 Result updateResult = new ResultDefault(FILTERARGS.UNITS); updateResult.addId("unitId1", (float) 1); updateResult.addId("unitId2", (float) 1); final Unit unit1Before = createSelectUnitResult("unitId1", "value v1"); final Unit unit1After = createSelectUnitResult("unitId1", "value v2"); final Unit unit2Before = createSelectUnitResult("unitId2", "value v1"); final Unit unit2After = createSelectUnitResult("unitId2", "value v2"); when(request.execRequest(isA(SelectParserMultiple.class), eq(ontologyModels))).thenReturn( new ResultDefault(FILTERARGS.UNITS).addFinal(unit1Before), new ResultDefault(FILTERARGS.UNITS).addFinal(unit2Before)); when(request.execUpdateRequest(any(), any(), eq(MetadataCollections.UNIT), any(OntologyValidator.class), any(UnitValidator.class), anyList())) .thenReturn( new UpdatedDocument("unit1", JsonHandler.toJsonNode(unit1Before), JsonHandler.toJsonNode(unit1After)), new UpdatedDocument("unit2", JsonHandler.toJsonNode(unit2Before), JsonHandler.toJsonNode(unit2After))); final JsonNode updateRequest = JsonHandler.getFromFile(PropertiesUtils.findFile("updateUnits.json")); RequestResponseOK<UpdateUnit> requestResponse = (RequestResponseOK<UpdateUnit>) metaDataImpl.updateUnits(updateRequest); assertThat(requestResponse.getResults().stream()) .extracting(UpdateUnit::getUnitId, UpdateUnit::getKey, UpdateUnit::getMessage, UpdateUnit::getStatus, UpdateUnit::getKey, UpdateUnit::getDiff) .containsExactlyInAnyOrder( tuple("unitId1", UNIT_METADATA_UPDATE, "Update unit OK.", OK, UNIT_METADATA_UPDATE, "- \"field\" : \"value v1\"\n+ \"field\" : \"value v2\""), tuple("unitId2", UNIT_METADATA_UPDATE, "Update unit OK.", OK, UNIT_METADATA_UPDATE, "- \"field\" : \"value v1\"\n+ \"field\" : \"value v2\"") ); }
public RequestResponse<UpdateUnit> updateUnits(JsonNode updateQuery) throws InvalidParseOperationException { Set<String> unitIds; final UpdateParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); final RequestMultiple request = updateRequest.getRequest(); unitIds = request.getRoots(); List<UpdateUnit> updatedUnits = unitIds.stream() .map(unitId -> updateAndTransformUnit(updateRequest, unitId)) .collect(Collectors.toList()); return new RequestResponseOK<UpdateUnit>(updateQuery) .addAllResults(updatedUnits) .setTotal(updatedUnits.size()); }
MetaDataImpl { public RequestResponse<UpdateUnit> updateUnits(JsonNode updateQuery) throws InvalidParseOperationException { Set<String> unitIds; final UpdateParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); final RequestMultiple request = updateRequest.getRequest(); unitIds = request.getRoots(); List<UpdateUnit> updatedUnits = unitIds.stream() .map(unitId -> updateAndTransformUnit(updateRequest, unitId)) .collect(Collectors.toList()); return new RequestResponseOK<UpdateUnit>(updateQuery) .addAllResults(updatedUnits) .setTotal(updatedUnits.size()); } }
MetaDataImpl { public RequestResponse<UpdateUnit> updateUnits(JsonNode updateQuery) throws InvalidParseOperationException { Set<String> unitIds; final UpdateParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); final RequestMultiple request = updateRequest.getRequest(); unitIds = request.getRoots(); List<UpdateUnit> updatedUnits = unitIds.stream() .map(unitId -> updateAndTransformUnit(updateRequest, unitId)) .collect(Collectors.toList()); return new RequestResponseOK<UpdateUnit>(updateQuery) .addAllResults(updatedUnits) .setTotal(updatedUnits.size()); } 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 RequestResponse<UpdateUnit> updateUnits(JsonNode updateQuery) throws InvalidParseOperationException { Set<String> unitIds; final UpdateParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); final RequestMultiple request = updateRequest.getRequest(); unitIds = request.getRoots(); List<UpdateUnit> updatedUnits = unitIds.stream() .map(unitId -> updateAndTransformUnit(updateRequest, unitId)) .collect(Collectors.toList()); return new RequestResponseOK<UpdateUnit>(updateQuery) .addAllResults(updatedUnits) .setTotal(updatedUnits.size()); } 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 RequestResponse<UpdateUnit> updateUnits(JsonNode updateQuery) throws InvalidParseOperationException { Set<String> unitIds; final UpdateParserMultiple updateRequest = new UpdateParserMultiple(DEFAULT_VARNAME_ADAPTER); updateRequest.parse(updateQuery); final RequestMultiple request = updateRequest.getRequest(); unitIds = request.getRoots(); List<UpdateUnit> updatedUnits = unitIds.stream() .map(unitId -> updateAndTransformUnit(updateRequest, unitId)) .collect(Collectors.toList()); return new RequestResponseOK<UpdateUnit>(updateQuery) .addAllResults(updatedUnits) .setTotal(updatedUnits.size()); } 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);  }