@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 = ComputeInheritedRulesDeletePlugin.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 Compute Inherited Rules Delete Plugin"); 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(); for (JsonNode archiveUnit : archiveWithInheritedRules) { String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); ObjectNode updateMultiQuery = getUpdateQuery(); 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); } }
ComputeInheritedRulesDeletePlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute Compute Inherited Rules Delete Plugin"); 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(); for (JsonNode archiveUnit : archiveWithInheritedRules) { String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); ObjectNode updateMultiQuery = getUpdateQuery(); 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); } } }
ComputeInheritedRulesDeletePlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute Compute Inherited Rules Delete Plugin"); 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(); for (JsonNode archiveUnit : archiveWithInheritedRules) { String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); ObjectNode updateMultiQuery = getUpdateQuery(); 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); } } ComputeInheritedRulesDeletePlugin(); @VisibleForTesting  ComputeInheritedRulesDeletePlugin(MetaDataClientFactory metaDataClientFactory); }
ComputeInheritedRulesDeletePlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute Compute Inherited Rules Delete Plugin"); 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(); for (JsonNode archiveUnit : archiveWithInheritedRules) { String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); ObjectNode updateMultiQuery = getUpdateQuery(); 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); } } ComputeInheritedRulesDeletePlugin(); @VisibleForTesting  ComputeInheritedRulesDeletePlugin(MetaDataClientFactory metaDataClientFactory); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
ComputeInheritedRulesDeletePlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { LOGGER.debug("execute Compute Inherited Rules Delete Plugin"); 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(); for (JsonNode archiveUnit : archiveWithInheritedRules) { String unitId = archiveUnit.get(VitamFieldsHelper.id()).textValue(); ObjectNode updateMultiQuery = getUpdateQuery(); 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); } } ComputeInheritedRulesDeletePlugin(); @VisibleForTesting  ComputeInheritedRulesDeletePlugin(MetaDataClientFactory metaDataClientFactory); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }