@Test @RunWithCustomExecutor public void should_launch_plugin_with_multiple_input_then_return_ok() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(0); JsonNode response = getJsonNodeResponse(); given(metaDataClient.selectUnitsWithInheritedRules(ArgumentMatchers.any())).willReturn(response); List<ItemStatus> itemStatus = ComputeInheritedRulesActionPlugin.executeList(workerParameters, HandlerIO); assertThat(itemStatus).hasSize(4); assertThat(itemStatus.stream().filter(i -> i.getGlobalStatus() == StatusCode.OK)).hasSize(4); }
@Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute MaxEndDatePlugin"); try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery select = new SelectMultiQuery(); InQuery query = QueryHelper.in(VitamFieldsHelper.id(), workerParameters.getObjectNameList().toArray(new String[0])); select.setQuery(query); JsonNode response = metaDataClient.selectUnitsWithInheritedRules(select.getFinalSelect()); RequestResponseOK<JsonNode> requestResponseOK = RequestResponseOK.getFromJsonNode(response); List<JsonNode> archiveWithInheritedRules = requestResponseOK.getResults(); String tenantId = VitamThreadUtils.getVitamSession().getTenantId().toString(); boolean isApiIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithAPIV2OutputByTenant()); boolean isRuleIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithRulesIdByTenant()); for (JsonNode archiveUnit : archiveWithInheritedRules) { UnitInheritedRulesResponseModel unitInheritedResponseModel = JsonHandler.getFromJsonNode(archiveUnit.get(INHERITED_RULES), UnitInheritedRulesResponseModel.class); String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); Map<String, InheritedRule> inheritedRulesWithAllOption = unitInheritedResponseModel.getRuleCategories() .entrySet() .stream() .map(entry -> mapToCategoriesWithEndDateAndProperties(entry.getKey(), entry.getValue(), isRuleIndexable)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Object> globalInheritedProperties = unitInheritedResponseModel.getGlobalProperties() .stream() .collect(Collectors.toMap(InheritedPropertyResponseModel::getPropertyName, InheritedPropertyResponseModel::getPropertyValue, PROPERTY_MERGER)); JsonNode inheritedRulesAPIOutput = isApiIndexable ? JsonHandler.toJsonNode(unitInheritedResponseModel) : null; ComputedInheritedRules computedInheritedRules = getComputedInheritedRules( inheritedRulesWithAllOption, inheritedRulesAPIOutput, globalInheritedProperties, isApiIndexable ); ObjectNode updateMultiQuery = getUpdateQuery(computedInheritedRules); metaDataClient.updateUnitById(updateMultiQuery, unitId); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } catch (InvalidCreateOperationException | MetaDataException e) { throw new ProcessingException(e); } catch (final InvalidParseOperationException e) { LOGGER.error("File couldn't be converted into json", e); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.KO); } }
ComputeInheritedRulesActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute MaxEndDatePlugin"); try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery select = new SelectMultiQuery(); InQuery query = QueryHelper.in(VitamFieldsHelper.id(), workerParameters.getObjectNameList().toArray(new String[0])); select.setQuery(query); JsonNode response = metaDataClient.selectUnitsWithInheritedRules(select.getFinalSelect()); RequestResponseOK<JsonNode> requestResponseOK = RequestResponseOK.getFromJsonNode(response); List<JsonNode> archiveWithInheritedRules = requestResponseOK.getResults(); String tenantId = VitamThreadUtils.getVitamSession().getTenantId().toString(); boolean isApiIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithAPIV2OutputByTenant()); boolean isRuleIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithRulesIdByTenant()); for (JsonNode archiveUnit : archiveWithInheritedRules) { UnitInheritedRulesResponseModel unitInheritedResponseModel = JsonHandler.getFromJsonNode(archiveUnit.get(INHERITED_RULES), UnitInheritedRulesResponseModel.class); String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); Map<String, InheritedRule> inheritedRulesWithAllOption = unitInheritedResponseModel.getRuleCategories() .entrySet() .stream() .map(entry -> mapToCategoriesWithEndDateAndProperties(entry.getKey(), entry.getValue(), isRuleIndexable)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Object> globalInheritedProperties = unitInheritedResponseModel.getGlobalProperties() .stream() .collect(Collectors.toMap(InheritedPropertyResponseModel::getPropertyName, InheritedPropertyResponseModel::getPropertyValue, PROPERTY_MERGER)); JsonNode inheritedRulesAPIOutput = isApiIndexable ? JsonHandler.toJsonNode(unitInheritedResponseModel) : null; ComputedInheritedRules computedInheritedRules = getComputedInheritedRules( inheritedRulesWithAllOption, inheritedRulesAPIOutput, globalInheritedProperties, isApiIndexable ); ObjectNode updateMultiQuery = getUpdateQuery(computedInheritedRules); metaDataClient.updateUnitById(updateMultiQuery, unitId); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } catch (InvalidCreateOperationException | MetaDataException e) { throw new ProcessingException(e); } catch (final InvalidParseOperationException e) { LOGGER.error("File couldn't be converted into json", e); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.KO); } } }
ComputeInheritedRulesActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute MaxEndDatePlugin"); try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery select = new SelectMultiQuery(); InQuery query = QueryHelper.in(VitamFieldsHelper.id(), workerParameters.getObjectNameList().toArray(new String[0])); select.setQuery(query); JsonNode response = metaDataClient.selectUnitsWithInheritedRules(select.getFinalSelect()); RequestResponseOK<JsonNode> requestResponseOK = RequestResponseOK.getFromJsonNode(response); List<JsonNode> archiveWithInheritedRules = requestResponseOK.getResults(); String tenantId = VitamThreadUtils.getVitamSession().getTenantId().toString(); boolean isApiIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithAPIV2OutputByTenant()); boolean isRuleIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithRulesIdByTenant()); for (JsonNode archiveUnit : archiveWithInheritedRules) { UnitInheritedRulesResponseModel unitInheritedResponseModel = JsonHandler.getFromJsonNode(archiveUnit.get(INHERITED_RULES), UnitInheritedRulesResponseModel.class); String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); Map<String, InheritedRule> inheritedRulesWithAllOption = unitInheritedResponseModel.getRuleCategories() .entrySet() .stream() .map(entry -> mapToCategoriesWithEndDateAndProperties(entry.getKey(), entry.getValue(), isRuleIndexable)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Object> globalInheritedProperties = unitInheritedResponseModel.getGlobalProperties() .stream() .collect(Collectors.toMap(InheritedPropertyResponseModel::getPropertyName, InheritedPropertyResponseModel::getPropertyValue, PROPERTY_MERGER)); JsonNode inheritedRulesAPIOutput = isApiIndexable ? JsonHandler.toJsonNode(unitInheritedResponseModel) : null; ComputedInheritedRules computedInheritedRules = getComputedInheritedRules( inheritedRulesWithAllOption, inheritedRulesAPIOutput, globalInheritedProperties, isApiIndexable ); ObjectNode updateMultiQuery = getUpdateQuery(computedInheritedRules); metaDataClient.updateUnitById(updateMultiQuery, unitId); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } catch (InvalidCreateOperationException | MetaDataException e) { throw new ProcessingException(e); } catch (final InvalidParseOperationException e) { LOGGER.error("File couldn't be converted into json", e); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.KO); } } ComputeInheritedRulesActionPlugin(); @VisibleForTesting  ComputeInheritedRulesActionPlugin(MetaDataClientFactory metaDataClientFactory); }
ComputeInheritedRulesActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute MaxEndDatePlugin"); try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery select = new SelectMultiQuery(); InQuery query = QueryHelper.in(VitamFieldsHelper.id(), workerParameters.getObjectNameList().toArray(new String[0])); select.setQuery(query); JsonNode response = metaDataClient.selectUnitsWithInheritedRules(select.getFinalSelect()); RequestResponseOK<JsonNode> requestResponseOK = RequestResponseOK.getFromJsonNode(response); List<JsonNode> archiveWithInheritedRules = requestResponseOK.getResults(); String tenantId = VitamThreadUtils.getVitamSession().getTenantId().toString(); boolean isApiIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithAPIV2OutputByTenant()); boolean isRuleIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithRulesIdByTenant()); for (JsonNode archiveUnit : archiveWithInheritedRules) { UnitInheritedRulesResponseModel unitInheritedResponseModel = JsonHandler.getFromJsonNode(archiveUnit.get(INHERITED_RULES), UnitInheritedRulesResponseModel.class); String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); Map<String, InheritedRule> inheritedRulesWithAllOption = unitInheritedResponseModel.getRuleCategories() .entrySet() .stream() .map(entry -> mapToCategoriesWithEndDateAndProperties(entry.getKey(), entry.getValue(), isRuleIndexable)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Object> globalInheritedProperties = unitInheritedResponseModel.getGlobalProperties() .stream() .collect(Collectors.toMap(InheritedPropertyResponseModel::getPropertyName, InheritedPropertyResponseModel::getPropertyValue, PROPERTY_MERGER)); JsonNode inheritedRulesAPIOutput = isApiIndexable ? JsonHandler.toJsonNode(unitInheritedResponseModel) : null; ComputedInheritedRules computedInheritedRules = getComputedInheritedRules( inheritedRulesWithAllOption, inheritedRulesAPIOutput, globalInheritedProperties, isApiIndexable ); ObjectNode updateMultiQuery = getUpdateQuery(computedInheritedRules); metaDataClient.updateUnitById(updateMultiQuery, unitId); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } catch (InvalidCreateOperationException | MetaDataException e) { throw new ProcessingException(e); } catch (final InvalidParseOperationException e) { LOGGER.error("File couldn't be converted into json", e); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.KO); } } ComputeInheritedRulesActionPlugin(); @VisibleForTesting  ComputeInheritedRulesActionPlugin(MetaDataClientFactory metaDataClientFactory); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); static String getId(); }
ComputeInheritedRulesActionPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute MaxEndDatePlugin"); try (MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { SelectMultiQuery select = new SelectMultiQuery(); InQuery query = QueryHelper.in(VitamFieldsHelper.id(), workerParameters.getObjectNameList().toArray(new String[0])); select.setQuery(query); JsonNode response = metaDataClient.selectUnitsWithInheritedRules(select.getFinalSelect()); RequestResponseOK<JsonNode> requestResponseOK = RequestResponseOK.getFromJsonNode(response); List<JsonNode> archiveWithInheritedRules = requestResponseOK.getResults(); String tenantId = VitamThreadUtils.getVitamSession().getTenantId().toString(); boolean isApiIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithAPIV2OutputByTenant()); boolean isRuleIndexable = isIndexable(tenantId, VitamConfiguration.getIndexInheritedRulesWithRulesIdByTenant()); for (JsonNode archiveUnit : archiveWithInheritedRules) { UnitInheritedRulesResponseModel unitInheritedResponseModel = JsonHandler.getFromJsonNode(archiveUnit.get(INHERITED_RULES), UnitInheritedRulesResponseModel.class); String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); Map<String, InheritedRule> inheritedRulesWithAllOption = unitInheritedResponseModel.getRuleCategories() .entrySet() .stream() .map(entry -> mapToCategoriesWithEndDateAndProperties(entry.getKey(), entry.getValue(), isRuleIndexable)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Object> globalInheritedProperties = unitInheritedResponseModel.getGlobalProperties() .stream() .collect(Collectors.toMap(InheritedPropertyResponseModel::getPropertyName, InheritedPropertyResponseModel::getPropertyValue, PROPERTY_MERGER)); JsonNode inheritedRulesAPIOutput = isApiIndexable ? JsonHandler.toJsonNode(unitInheritedResponseModel) : null; ComputedInheritedRules computedInheritedRules = getComputedInheritedRules( inheritedRulesWithAllOption, inheritedRulesAPIOutput, globalInheritedProperties, isApiIndexable ); ObjectNode updateMultiQuery = getUpdateQuery(computedInheritedRules); metaDataClient.updateUnitById(updateMultiQuery, unitId); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } catch (InvalidCreateOperationException | MetaDataException e) { throw new ProcessingException(e); } catch (final InvalidParseOperationException e) { LOGGER.error("File couldn't be converted into json", e); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.KO); } } ComputeInheritedRulesActionPlugin(); @VisibleForTesting  ComputeInheritedRulesActionPlugin(MetaDataClientFactory metaDataClientFactory); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); static String getId();  }