@Test public void should_not_save_units_when_no_children() throws Exception { HandlerIO handlerIO = givenHandlerIo(Collections.singletonList("BATMAN_UNIT")); WorkerParameters workerParameters = givenWorkerParameters(); JsonNode emptyResponse = JsonHandler.toJsonNode(new RequestResponseOK<JsonNode>()); when(metaDataClient.selectUnits(any())).thenReturn(emptyResponse); computeInheritedRuleProgenyIdentifierPlugin.executeList(workerParameters, handlerIO); verify(batchReportClient, never()).appendReportEntries(any()); 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);  }