@Test @RunWithCustomExecutor public void should_store_report_atomically_when_report_not_exists_in_workspace() throws Exception { String probativeEntryIdInDistributionFile = "BATMAN_GOT_ID"; String containerName = "MyContainerName"; HandlerIO handler = mock(HandlerIO.class); doReturn(false).when(handler).isExistingFileInWorkspace(containerName + JSON); doReturn(containerName).when(handler).getContainerName(); doReturn(tempFolder.newFile(GUIDFactory.newGUID().getId())).when(handler).getNewLocalFile(anyString()); PreservationRequest request = new PreservationRequest(); doReturn(pojoToFile(request)).when(handler).getFileFromWorkspace("request"); doReturn(writeDistributionFile(new JsonLineModel(probativeEntryIdInDistributionFile, 0, null))) .when(handler).getInputStreamFromWorkspace("distributionFile.jsonl"); ProbativeReportEntry object = ProbativeReportEntry .koFrom(LocalDateUtil.getFormattedDateForMongo(LocalDateUtil.now()), Collections.singletonList("unitId"), "groupId", "objectId", "usageVersion"); doReturn(pojoToFile(object)).when(handler).getFileFromWorkspace(probativeEntryIdInDistributionFile); WorkerParameters build = workerParameterBuilder() .withContainerName(containerName) .build(); ItemStatus execute = probativeCreateReport.execute(build, handler); assertThat(execute.getGlobalStatus()).isEqualTo(StatusCode.OK); verify(handler).transferAtomicFileToWorkspace(eq(containerName + JSON), any()); verify(backupService) .storeIntoOffers(eq(containerName), eq(containerName + JSON), eq(REPORT), eq(containerName + JSON), eq(VitamConfiguration.getDefaultStrategy())); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } }
ProbativeCreateReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } } }
ProbativeCreateReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } } @VisibleForTesting  ProbativeCreateReport(BackupService backupService);  ProbativeCreateReport(); }
ProbativeCreateReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } } @VisibleForTesting  ProbativeCreateReport(BackupService backupService);  ProbativeCreateReport(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
ProbativeCreateReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { try { String reportFileName = param.getContainerName() + JSON; generateReportToWorkspace(param, handler, reportFileName); storeReportToOffers(handler, reportFileName); return buildItemStatusWithMasterData(HANDLER_ID, StatusCode.OK, EventDetails.of("Probative value report success."), JsonHandler.unprettyPrint(REPORT_VERSION_2)); } catch (Exception e) { LOGGER.error(e); return buildItemStatus(HANDLER_ID, StatusCode.FATAL, EventDetails.of("Probative value report error.")); } } @VisibleForTesting  ProbativeCreateReport(BackupService backupService);  ProbativeCreateReport(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }