@RunWithCustomExecutor @Test public void shouldFinalizeAuditWithWarning() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(0); VitamThreadUtils.getVitamSession().setRequestId("aeeaaaaaacfpuagsaauscallwn434oaaaaaq"); File file = tempFolder.newFile(); when(handlerIO.getNewLocalFile("report.json")).thenReturn(file); when(logbookClient.selectOperationById(any())) .thenReturn(getFromInputStream(getClass().getResourceAsStream(JOP_EVIDENCE_AUDIT_RESULTS_WARNING))); ItemStatus execute = evidenceAuditPrepareReport.execute(defaultWorkerParameters, handlerIO); Assertions.assertThat(execute.getGlobalStatus()).isEqualTo(StatusCode.OK); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT); Report evidenceReport; try { evidenceReport = generateEvidenceAuditReport(param, handlerIO); } catch (EvidenceAuditException e) { LOGGER.error(String.format("Evidence Audit finalization failed with status %s", e.getStatus()), e); return buildItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT, StatusCode.FATAL, null); } try { List<URI> uriListObjectsWorkspace = handlerIO.getUriList(handlerIO.getContainerName(), param.getObjectName()); for (URI uri : uriListObjectsWorkspace) { File file = handlerIO.getFileFromWorkspace(param.getObjectName() + File.separator + uri.getPath()); EvidenceAuditReportLine reportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); itemStatus.increment(getStatusCode(reportLine)); } } catch (ContentAddressableStorageNotFoundException | IOException | InvalidParseOperationException | ContentAddressableStorageServerException e) { throw new ProcessingException(e); } if (itemStatus.getGlobalStatus().isGreaterOrEqualToFatal()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some audits fails see the report for more details"); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToKo()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToWarn()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There are some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(infoNode)); } else { LOGGER.info("EvidenceAudit finalization terminated Successfully"); itemStatus.increment(StatusCode.OK); } try { evidenceAuditReportService.storeReportToWorkspace(evidenceReport); } catch (ProcessingStatusException e) { throw new ProcessingException(e); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT).setItemsStatus(EVIDENCE_AUDIT_PREPARE_REPORT, itemStatus); }
EvidenceAuditPrepareReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT); Report evidenceReport; try { evidenceReport = generateEvidenceAuditReport(param, handlerIO); } catch (EvidenceAuditException e) { LOGGER.error(String.format("Evidence Audit finalization failed with status %s", e.getStatus()), e); return buildItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT, StatusCode.FATAL, null); } try { List<URI> uriListObjectsWorkspace = handlerIO.getUriList(handlerIO.getContainerName(), param.getObjectName()); for (URI uri : uriListObjectsWorkspace) { File file = handlerIO.getFileFromWorkspace(param.getObjectName() + File.separator + uri.getPath()); EvidenceAuditReportLine reportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); itemStatus.increment(getStatusCode(reportLine)); } } catch (ContentAddressableStorageNotFoundException | IOException | InvalidParseOperationException | ContentAddressableStorageServerException e) { throw new ProcessingException(e); } if (itemStatus.getGlobalStatus().isGreaterOrEqualToFatal()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some audits fails see the report for more details"); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToKo()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToWarn()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There are some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(infoNode)); } else { LOGGER.info("EvidenceAudit finalization terminated Successfully"); itemStatus.increment(StatusCode.OK); } try { evidenceAuditReportService.storeReportToWorkspace(evidenceReport); } catch (ProcessingStatusException e) { throw new ProcessingException(e); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT).setItemsStatus(EVIDENCE_AUDIT_PREPARE_REPORT, itemStatus); } }
EvidenceAuditPrepareReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT); Report evidenceReport; try { evidenceReport = generateEvidenceAuditReport(param, handlerIO); } catch (EvidenceAuditException e) { LOGGER.error(String.format("Evidence Audit finalization failed with status %s", e.getStatus()), e); return buildItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT, StatusCode.FATAL, null); } try { List<URI> uriListObjectsWorkspace = handlerIO.getUriList(handlerIO.getContainerName(), param.getObjectName()); for (URI uri : uriListObjectsWorkspace) { File file = handlerIO.getFileFromWorkspace(param.getObjectName() + File.separator + uri.getPath()); EvidenceAuditReportLine reportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); itemStatus.increment(getStatusCode(reportLine)); } } catch (ContentAddressableStorageNotFoundException | IOException | InvalidParseOperationException | ContentAddressableStorageServerException e) { throw new ProcessingException(e); } if (itemStatus.getGlobalStatus().isGreaterOrEqualToFatal()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some audits fails see the report for more details"); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToKo()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToWarn()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There are some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(infoNode)); } else { LOGGER.info("EvidenceAudit finalization terminated Successfully"); itemStatus.increment(StatusCode.OK); } try { evidenceAuditReportService.storeReportToWorkspace(evidenceReport); } catch (ProcessingStatusException e) { throw new ProcessingException(e); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT).setItemsStatus(EVIDENCE_AUDIT_PREPARE_REPORT, itemStatus); } @VisibleForTesting  EvidenceAuditPrepareReport(EvidenceAuditReportService evidenceAuditReportService,
        LogbookOperationsClientFactory logbookOperationsClientFactory);  EvidenceAuditPrepareReport(); }
EvidenceAuditPrepareReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT); Report evidenceReport; try { evidenceReport = generateEvidenceAuditReport(param, handlerIO); } catch (EvidenceAuditException e) { LOGGER.error(String.format("Evidence Audit finalization failed with status %s", e.getStatus()), e); return buildItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT, StatusCode.FATAL, null); } try { List<URI> uriListObjectsWorkspace = handlerIO.getUriList(handlerIO.getContainerName(), param.getObjectName()); for (URI uri : uriListObjectsWorkspace) { File file = handlerIO.getFileFromWorkspace(param.getObjectName() + File.separator + uri.getPath()); EvidenceAuditReportLine reportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); itemStatus.increment(getStatusCode(reportLine)); } } catch (ContentAddressableStorageNotFoundException | IOException | InvalidParseOperationException | ContentAddressableStorageServerException e) { throw new ProcessingException(e); } if (itemStatus.getGlobalStatus().isGreaterOrEqualToFatal()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some audits fails see the report for more details"); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToKo()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToWarn()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There are some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(infoNode)); } else { LOGGER.info("EvidenceAudit finalization terminated Successfully"); itemStatus.increment(StatusCode.OK); } try { evidenceAuditReportService.storeReportToWorkspace(evidenceReport); } catch (ProcessingStatusException e) { throw new ProcessingException(e); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT).setItemsStatus(EVIDENCE_AUDIT_PREPARE_REPORT, itemStatus); } @VisibleForTesting  EvidenceAuditPrepareReport(EvidenceAuditReportService evidenceAuditReportService,
        LogbookOperationsClientFactory logbookOperationsClientFactory);  EvidenceAuditPrepareReport(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handlerIO); }
EvidenceAuditPrepareReport extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT); Report evidenceReport; try { evidenceReport = generateEvidenceAuditReport(param, handlerIO); } catch (EvidenceAuditException e) { LOGGER.error(String.format("Evidence Audit finalization failed with status %s", e.getStatus()), e); return buildItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT, StatusCode.FATAL, null); } try { List<URI> uriListObjectsWorkspace = handlerIO.getUriList(handlerIO.getContainerName(), param.getObjectName()); for (URI uri : uriListObjectsWorkspace) { File file = handlerIO.getFileFromWorkspace(param.getObjectName() + File.separator + uri.getPath()); EvidenceAuditReportLine reportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); itemStatus.increment(getStatusCode(reportLine)); } } catch (ContentAddressableStorageNotFoundException | IOException | InvalidParseOperationException | ContentAddressableStorageServerException e) { throw new ProcessingException(e); } if (itemStatus.getGlobalStatus().isGreaterOrEqualToFatal()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some audits fails see the report for more details"); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToKo()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(unprettyPrint(infoNode)); } else if (itemStatus.getGlobalStatus().isGreaterOrEqualToWarn()) { ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "There are some objects not securised yet see the report for more details "); itemStatus.setEvDetailData(JsonHandler.unprettyPrint(infoNode)); } else { LOGGER.info("EvidenceAudit finalization terminated Successfully"); itemStatus.increment(StatusCode.OK); } try { evidenceAuditReportService.storeReportToWorkspace(evidenceReport); } catch (ProcessingStatusException e) { throw new ProcessingException(e); } return new ItemStatus(EVIDENCE_AUDIT_PREPARE_REPORT).setItemsStatus(EVIDENCE_AUDIT_PREPARE_REPORT, itemStatus); } @VisibleForTesting  EvidenceAuditPrepareReport(EvidenceAuditReportService evidenceAuditReportService,
        LogbookOperationsClientFactory logbookOperationsClientFactory);  EvidenceAuditPrepareReport(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handlerIO);  }