@Test public void should_generate_invalidation_distribution_file() throws Exception { List<String> distributedUnits = Collections.singletonList("momaUnit"); HandlerIO handlerIO = givenHandlerIo(distributedUnits); WorkerParameters workerParameters = givenWorkerParameters(); List<String> progenyUnits = Collections.singletonList("daughter"); List<String> allUnitsToInvalidate = new ArrayList<>(); allUnitsToInvalidate.addAll(distributedUnits); allUnitsToInvalidate.addAll(progenyUnits); when(metaDataClient.selectUnits(any(JsonNode.class))) .thenReturn(createMetadataResponseFromList(allUnitsToInvalidate)); ArgumentCaptor<ReportBody<UnitComputedInheritedRulesInvalidationReportEntry>> reportBodyArgumentCaptor = ArgumentCaptor.forClass(ReportBody.class); doNothing().when(batchReportClient).appendReportEntries(reportBodyArgumentCaptor.capture()); computeInheritedRuleProgenyIdentifierPlugin.executeList(workerParameters, handlerIO); ReportBody<UnitComputedInheritedRulesInvalidationReportEntry> reportBody = reportBodyArgumentCaptor.getValue(); assertThat(reportBody.getProcessId()).isEqualTo("processId"); assertThat(reportBody.getReportType()).isEqualTo(ReportType.UNIT_COMPUTED_INHERITED_RULES_INVALIDATION); assertThat(reportBody.getEntries()) .extracting("unitId").containsAll(allUnitsToInvalidate); verify(batchReportClient).exportUnitsToInvalidate(anyString(), any()); }
@Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { String processId = handler.getContainerName(); if (StringUtils.isEmpty(processId)) { LOGGER.error("processId null or empty."); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.FATAL); } handler.setCurrentObjectId(workerParameters.getObjectNameList().get(0)); try (InputStream inputStream = new FileInputStream((File) handler.getInput(0)); JsonLineGenericIterator<JsonLineModel> lines = new JsonLineGenericIterator<>(inputStream, TYPE_REFERENCE); BatchReportClient batchReportClient = batchReportClientFactory.getClient(); MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { Iterator<List<JsonLineModel>> bulkLines = Iterators.partition(lines, bulkSize); bulkLines.forEachRemaining( unitsToBatch -> findAndSaveUnitsProgeny(metaDataClient, batchReportClient, unitsToBatch, processId)); batchReportClient.exportUnitsToInvalidate(processId, new ReportExportRequest(UNITS_JSONL_FILE_NAME)); } catch (IOException | VitamClientInternalException e) { throw new ProcessingException(e); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); }
ComputeInheritedRuleProgenyIdentifierPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { String processId = handler.getContainerName(); if (StringUtils.isEmpty(processId)) { LOGGER.error("processId null or empty."); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.FATAL); } handler.setCurrentObjectId(workerParameters.getObjectNameList().get(0)); try (InputStream inputStream = new FileInputStream((File) handler.getInput(0)); JsonLineGenericIterator<JsonLineModel> lines = new JsonLineGenericIterator<>(inputStream, TYPE_REFERENCE); BatchReportClient batchReportClient = batchReportClientFactory.getClient(); MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { Iterator<List<JsonLineModel>> bulkLines = Iterators.partition(lines, bulkSize); bulkLines.forEachRemaining( unitsToBatch -> findAndSaveUnitsProgeny(metaDataClient, batchReportClient, unitsToBatch, processId)); batchReportClient.exportUnitsToInvalidate(processId, new ReportExportRequest(UNITS_JSONL_FILE_NAME)); } catch (IOException | VitamClientInternalException e) { throw new ProcessingException(e); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } }
ComputeInheritedRuleProgenyIdentifierPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { String processId = handler.getContainerName(); if (StringUtils.isEmpty(processId)) { LOGGER.error("processId null or empty."); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.FATAL); } handler.setCurrentObjectId(workerParameters.getObjectNameList().get(0)); try (InputStream inputStream = new FileInputStream((File) handler.getInput(0)); JsonLineGenericIterator<JsonLineModel> lines = new JsonLineGenericIterator<>(inputStream, TYPE_REFERENCE); BatchReportClient batchReportClient = batchReportClientFactory.getClient(); MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { Iterator<List<JsonLineModel>> bulkLines = Iterators.partition(lines, bulkSize); bulkLines.forEachRemaining( unitsToBatch -> findAndSaveUnitsProgeny(metaDataClient, batchReportClient, unitsToBatch, processId)); batchReportClient.exportUnitsToInvalidate(processId, new ReportExportRequest(UNITS_JSONL_FILE_NAME)); } catch (IOException | VitamClientInternalException e) { throw new ProcessingException(e); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } ComputeInheritedRuleProgenyIdentifierPlugin(); @VisibleForTesting  ComputeInheritedRuleProgenyIdentifierPlugin(MetaDataClientFactory metaDataClientFactory,
        BatchReportClientFactory batchReportClientFactory, int bulkSize); }
ComputeInheritedRuleProgenyIdentifierPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { String processId = handler.getContainerName(); if (StringUtils.isEmpty(processId)) { LOGGER.error("processId null or empty."); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.FATAL); } handler.setCurrentObjectId(workerParameters.getObjectNameList().get(0)); try (InputStream inputStream = new FileInputStream((File) handler.getInput(0)); JsonLineGenericIterator<JsonLineModel> lines = new JsonLineGenericIterator<>(inputStream, TYPE_REFERENCE); BatchReportClient batchReportClient = batchReportClientFactory.getClient(); MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { Iterator<List<JsonLineModel>> bulkLines = Iterators.partition(lines, bulkSize); bulkLines.forEachRemaining( unitsToBatch -> findAndSaveUnitsProgeny(metaDataClient, batchReportClient, unitsToBatch, processId)); batchReportClient.exportUnitsToInvalidate(processId, new ReportExportRequest(UNITS_JSONL_FILE_NAME)); } catch (IOException | VitamClientInternalException e) { throw new ProcessingException(e); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } ComputeInheritedRuleProgenyIdentifierPlugin(); @VisibleForTesting  ComputeInheritedRuleProgenyIdentifierPlugin(MetaDataClientFactory metaDataClientFactory,
        BatchReportClientFactory batchReportClientFactory, int bulkSize); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); }
ComputeInheritedRuleProgenyIdentifierPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { String processId = handler.getContainerName(); if (StringUtils.isEmpty(processId)) { LOGGER.error("processId null or empty."); return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.FATAL); } handler.setCurrentObjectId(workerParameters.getObjectNameList().get(0)); try (InputStream inputStream = new FileInputStream((File) handler.getInput(0)); JsonLineGenericIterator<JsonLineModel> lines = new JsonLineGenericIterator<>(inputStream, TYPE_REFERENCE); BatchReportClient batchReportClient = batchReportClientFactory.getClient(); MetaDataClient metaDataClient = metaDataClientFactory.getClient()) { Iterator<List<JsonLineModel>> bulkLines = Iterators.partition(lines, bulkSize); bulkLines.forEachRemaining( unitsToBatch -> findAndSaveUnitsProgeny(metaDataClient, batchReportClient, unitsToBatch, processId)); batchReportClient.exportUnitsToInvalidate(processId, new ReportExportRequest(UNITS_JSONL_FILE_NAME)); } catch (IOException | VitamClientInternalException e) { throw new ProcessingException(e); } return buildBulkItemStatus(workerParameters, PLUGIN_NAME, StatusCode.OK); } ComputeInheritedRuleProgenyIdentifierPlugin(); @VisibleForTesting  ComputeInheritedRuleProgenyIdentifierPlugin(MetaDataClientFactory metaDataClientFactory,
        BatchReportClientFactory batchReportClientFactory, int bulkSize); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler);  }