@Test @RunWithCustomExecutor public void givenNothingSpecialWhenExecuteThenReturnResponseOK() throws Exception { handlerIO.addOutIOParameters(in); handlerIO.addOutputResult(0, PropertiesUtils.getResourceFile(LAST_OPERATION), false); handlerIO.addOutputResult(1, PropertiesUtils.getResourceFile(TRACEABILITY_INFO), false); handlerIO.addOutputResult(2, PropertiesUtils.getResourceFile(TRACEABILITY_DATA), false); handlerIO.addOutputResult(3, PropertiesUtils.getResourceFile(TRACEABILITY_STATS), false); handlerIO.addInIOParameters(in); VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); Mockito.doNothing().when(workspaceClient).createContainer(any()); Mockito.doReturn(getLogbookOperation()).when(logbookOperationsClient).selectOperation(any()); GenerateObjectGroupLifecycleTraceabilityActionPlugin plugin = new GenerateObjectGroupLifecycleTraceabilityActionPlugin( logbookOperationsClientFactory, workspaceClientFactory); final ItemStatus response = plugin.execute(params, handlerIO); assertEquals(StatusCode.OK, response.getGlobalStatus()); verify(workspaceClient, times(2)).putObject(anyString(), anyString(), any()); verify(workspaceClient).putObject(anyString(), eq(TRACEABILITY_EVENT_FILE_NAME), any()); verify(workspaceClient).putObject(anyString(), eq(TRACEABILITY_ZIP_FILE_NAME), any()); InputStream stream = getSavedWorkspaceObject(TRACEABILITY_ZIP_FILE_NAME); assertNotNull(stream); JsonNode evDetData = JsonHandler.getFromInputStream(getSavedWorkspaceObject(TRACEABILITY_EVENT_FILE_NAME)); JsonAssert.assertJsonEquals(evDetData.get("Statistics"), JsonHandler.getFromFile(PropertiesUtils.getResourceFile(TRACEABILITY_STATS))); }
@Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(ACTION_HANDLER_ID); File traceabilityDataFile = (File) handler.getInput(TRACEABILITY_DATA_IN_RANK); try (final LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient(); InputStream is = new FileInputStream(traceabilityDataFile); JsonLineGenericIterator<JsonLineModel> traceabilityDataIterator = new JsonLineGenericIterator<>(is, TYPE_REFERENCE)) { LogbookLifeCycleTraceabilityHelper helper = new LogbookObjectGroupLifeCycleTraceabilityHelper(handler, logbookOperationsClient, itemStatus, params.getContainerName(), workspaceClientFactory, traceabilityDataIterator, TRACEABILITY_EVENT_FILE_NAME, TRACEABILITY_ZIP_FILE_NAME); generateLifecycleTraceabilityFile(helper); itemStatus.increment(StatusCode.OK); } catch (TraceabilityException | IOException e) { LOGGER.error("Exception while finalizing", e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(ACTION_HANDLER_ID).setItemsStatus(ACTION_HANDLER_ID, itemStatus); }
GenerateObjectGroupLifecycleTraceabilityActionPlugin extends GenerateLifecycleTraceabilityActionPlugin { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(ACTION_HANDLER_ID); File traceabilityDataFile = (File) handler.getInput(TRACEABILITY_DATA_IN_RANK); try (final LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient(); InputStream is = new FileInputStream(traceabilityDataFile); JsonLineGenericIterator<JsonLineModel> traceabilityDataIterator = new JsonLineGenericIterator<>(is, TYPE_REFERENCE)) { LogbookLifeCycleTraceabilityHelper helper = new LogbookObjectGroupLifeCycleTraceabilityHelper(handler, logbookOperationsClient, itemStatus, params.getContainerName(), workspaceClientFactory, traceabilityDataIterator, TRACEABILITY_EVENT_FILE_NAME, TRACEABILITY_ZIP_FILE_NAME); generateLifecycleTraceabilityFile(helper); itemStatus.increment(StatusCode.OK); } catch (TraceabilityException | IOException e) { LOGGER.error("Exception while finalizing", e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(ACTION_HANDLER_ID).setItemsStatus(ACTION_HANDLER_ID, itemStatus); } }
GenerateObjectGroupLifecycleTraceabilityActionPlugin extends GenerateLifecycleTraceabilityActionPlugin { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(ACTION_HANDLER_ID); File traceabilityDataFile = (File) handler.getInput(TRACEABILITY_DATA_IN_RANK); try (final LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient(); InputStream is = new FileInputStream(traceabilityDataFile); JsonLineGenericIterator<JsonLineModel> traceabilityDataIterator = new JsonLineGenericIterator<>(is, TYPE_REFERENCE)) { LogbookLifeCycleTraceabilityHelper helper = new LogbookObjectGroupLifeCycleTraceabilityHelper(handler, logbookOperationsClient, itemStatus, params.getContainerName(), workspaceClientFactory, traceabilityDataIterator, TRACEABILITY_EVENT_FILE_NAME, TRACEABILITY_ZIP_FILE_NAME); generateLifecycleTraceabilityFile(helper); itemStatus.increment(StatusCode.OK); } catch (TraceabilityException | IOException e) { LOGGER.error("Exception while finalizing", e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(ACTION_HANDLER_ID).setItemsStatus(ACTION_HANDLER_ID, itemStatus); } GenerateObjectGroupLifecycleTraceabilityActionPlugin(); @VisibleForTesting  GenerateObjectGroupLifecycleTraceabilityActionPlugin(LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory); }
GenerateObjectGroupLifecycleTraceabilityActionPlugin extends GenerateLifecycleTraceabilityActionPlugin { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(ACTION_HANDLER_ID); File traceabilityDataFile = (File) handler.getInput(TRACEABILITY_DATA_IN_RANK); try (final LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient(); InputStream is = new FileInputStream(traceabilityDataFile); JsonLineGenericIterator<JsonLineModel> traceabilityDataIterator = new JsonLineGenericIterator<>(is, TYPE_REFERENCE)) { LogbookLifeCycleTraceabilityHelper helper = new LogbookObjectGroupLifeCycleTraceabilityHelper(handler, logbookOperationsClient, itemStatus, params.getContainerName(), workspaceClientFactory, traceabilityDataIterator, TRACEABILITY_EVENT_FILE_NAME, TRACEABILITY_ZIP_FILE_NAME); generateLifecycleTraceabilityFile(helper); itemStatus.increment(StatusCode.OK); } catch (TraceabilityException | IOException e) { LOGGER.error("Exception while finalizing", e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(ACTION_HANDLER_ID).setItemsStatus(ACTION_HANDLER_ID, itemStatus); } GenerateObjectGroupLifecycleTraceabilityActionPlugin(); @VisibleForTesting  GenerateObjectGroupLifecycleTraceabilityActionPlugin(LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory); @Override ItemStatus execute(WorkerParameters params, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); static String getId(); }
GenerateObjectGroupLifecycleTraceabilityActionPlugin extends GenerateLifecycleTraceabilityActionPlugin { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(ACTION_HANDLER_ID); File traceabilityDataFile = (File) handler.getInput(TRACEABILITY_DATA_IN_RANK); try (final LogbookOperationsClient logbookOperationsClient = logbookOperationsClientFactory.getClient(); InputStream is = new FileInputStream(traceabilityDataFile); JsonLineGenericIterator<JsonLineModel> traceabilityDataIterator = new JsonLineGenericIterator<>(is, TYPE_REFERENCE)) { LogbookLifeCycleTraceabilityHelper helper = new LogbookObjectGroupLifeCycleTraceabilityHelper(handler, logbookOperationsClient, itemStatus, params.getContainerName(), workspaceClientFactory, traceabilityDataIterator, TRACEABILITY_EVENT_FILE_NAME, TRACEABILITY_ZIP_FILE_NAME); generateLifecycleTraceabilityFile(helper); itemStatus.increment(StatusCode.OK); } catch (TraceabilityException | IOException e) { LOGGER.error("Exception while finalizing", e); itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(ACTION_HANDLER_ID).setItemsStatus(ACTION_HANDLER_ID, itemStatus); } GenerateObjectGroupLifecycleTraceabilityActionPlugin(); @VisibleForTesting  GenerateObjectGroupLifecycleTraceabilityActionPlugin(LogbookOperationsClientFactory logbookOperationsClientFactory,
        WorkspaceClientFactory workspaceClientFactory); @Override ItemStatus execute(WorkerParameters params, HandlerIO handler); @Override void checkMandatoryIOParameter(HandlerIO handler); static String getId();  }