@Test public void should_check_audit_data_base() throws Exception { WorkerParameters defaultWorkerParameters = mock(WorkerParameters.class); when(defaultWorkerParameters.getObjectName()).thenReturn("test"); File file = tempFolder.newFile(); File file2 = tempFolder.newFile(); writeAsFile(getFromString(UNITTYPE), file); when(handlerIO.getFileFromWorkspace("Object/test")).thenReturn(file); EvidenceAuditParameters evidenceAuditParameters = JsonHandler .getFromFile(PropertiesUtils.getResourceFile("evidenceAudit/parameters.json"), EvidenceAuditParameters.class); when(handlerIO.getNewLocalFile("test.tmp")).thenReturn(file2); when(handlerIO.getInput(0)).thenReturn(PropertiesUtils.getResourceFile("evidenceAudit/strategies.json")); when(evidenceService.evidenceAuditsChecks(eq("test"), eq(MetadataType.UNIT), any())).thenReturn(evidenceAuditParameters); ItemStatus execute = evidenceAuditDatabaseCheck.execute(defaultWorkerParameters, handlerIO); assertThat(execute.getGlobalStatus()).isEqualTo(StatusCode.OK); EvidenceAuditParameters evidenceAuditParameters2 = JsonHandler.getFromFile(file2, EvidenceAuditParameters.class); assertThat(evidenceAuditParameters.getAuditMessage()).isEqualTo(evidenceAuditParameters2.getAuditMessage()); assertThat(evidenceAuditParameters.getObjectStorageMetadataResultMap()) .isEqualTo(evidenceAuditParameters2.getObjectStorageMetadataResultMap()); assertThat(evidenceAuditParameters.getEvidenceStatus()).isEqualTo(evidenceAuditParameters2.getEvidenceStatus()); when(handlerIO.getFileFromWorkspace(any())).thenThrow(IOException.class); execute = evidenceAuditDatabaseCheck.execute(defaultWorkerParameters, handlerIO); assertThat(execute.getGlobalStatus()).isEqualTo(StatusCode.FATAL); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE); String objectToAuditId = param.getObjectName(); try { File file = handlerIO.getFileFromWorkspace("Object/" + objectToAuditId); JsonNode objectIdToAudit = JsonHandler.getFromFile(file); MetadataType metadataType = MetadataType.valueOf(objectIdToAudit.get(METADA_TYPE).textValue()); List<StorageStrategy> storageStrategies = loadStorageStrategies(handlerIO); EvidenceAuditParameters parameters = evidenceService.evidenceAuditsChecks(objectToAuditId, metadataType, storageStrategies); File newLocalFile = handlerIO.getNewLocalFile(objectToAuditId + ".tmp"); JsonHandler.writeAsFile(parameters, newLocalFile); handlerIO.transferFileToWorkspace(DATA + "/" + objectToAuditId, newLocalFile, true, false); if ( parameters.getEvidenceStatus().equals(EvidenceStatus.FATAL) ) { itemStatus.increment(StatusCode.FATAL); ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "Fatal Technical error "+ parameters.getAuditMessage()); itemStatus.setEvDetailData(unprettyPrint(infoNode)); evidenceAuditReportService.cleanupReport(param.getContainerName()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE).setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } if (parameters.getEvidenceStatus().equals(EvidenceStatus.KO) || parameters.getEvidenceStatus().equals(EvidenceStatus.WARN)) { EvidenceAuditReportLine evidenceAuditReportLine = null; evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); evidenceAuditReportLine.setStrategyId(parameters.getMdOptimisticStorageInfo().getStrategy()); JsonHandler.writeAsFile(evidenceAuditReportLine, file); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, true, false); if(!param.getWorkflowIdentifier().equals("RECTIFICATION_AUDIT")) addReportEntry(param.getContainerName(), createEvidenceReportEntry(parameters, evidenceAuditReportLine)); } itemStatus.increment(StatusCode.OK); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (VitamException | IOException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (ProcessingStatusException e) { LOGGER.error(e); itemStatus.increment(e.getStatusCode()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } }
EvidenceAuditDatabaseCheck extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE); String objectToAuditId = param.getObjectName(); try { File file = handlerIO.getFileFromWorkspace("Object/" + objectToAuditId); JsonNode objectIdToAudit = JsonHandler.getFromFile(file); MetadataType metadataType = MetadataType.valueOf(objectIdToAudit.get(METADA_TYPE).textValue()); List<StorageStrategy> storageStrategies = loadStorageStrategies(handlerIO); EvidenceAuditParameters parameters = evidenceService.evidenceAuditsChecks(objectToAuditId, metadataType, storageStrategies); File newLocalFile = handlerIO.getNewLocalFile(objectToAuditId + ".tmp"); JsonHandler.writeAsFile(parameters, newLocalFile); handlerIO.transferFileToWorkspace(DATA + "/" + objectToAuditId, newLocalFile, true, false); if ( parameters.getEvidenceStatus().equals(EvidenceStatus.FATAL) ) { itemStatus.increment(StatusCode.FATAL); ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "Fatal Technical error "+ parameters.getAuditMessage()); itemStatus.setEvDetailData(unprettyPrint(infoNode)); evidenceAuditReportService.cleanupReport(param.getContainerName()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE).setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } if (parameters.getEvidenceStatus().equals(EvidenceStatus.KO) || parameters.getEvidenceStatus().equals(EvidenceStatus.WARN)) { EvidenceAuditReportLine evidenceAuditReportLine = null; evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); evidenceAuditReportLine.setStrategyId(parameters.getMdOptimisticStorageInfo().getStrategy()); JsonHandler.writeAsFile(evidenceAuditReportLine, file); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, true, false); if(!param.getWorkflowIdentifier().equals("RECTIFICATION_AUDIT")) addReportEntry(param.getContainerName(), createEvidenceReportEntry(parameters, evidenceAuditReportLine)); } itemStatus.increment(StatusCode.OK); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (VitamException | IOException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (ProcessingStatusException e) { LOGGER.error(e); itemStatus.increment(e.getStatusCode()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } } }
EvidenceAuditDatabaseCheck extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE); String objectToAuditId = param.getObjectName(); try { File file = handlerIO.getFileFromWorkspace("Object/" + objectToAuditId); JsonNode objectIdToAudit = JsonHandler.getFromFile(file); MetadataType metadataType = MetadataType.valueOf(objectIdToAudit.get(METADA_TYPE).textValue()); List<StorageStrategy> storageStrategies = loadStorageStrategies(handlerIO); EvidenceAuditParameters parameters = evidenceService.evidenceAuditsChecks(objectToAuditId, metadataType, storageStrategies); File newLocalFile = handlerIO.getNewLocalFile(objectToAuditId + ".tmp"); JsonHandler.writeAsFile(parameters, newLocalFile); handlerIO.transferFileToWorkspace(DATA + "/" + objectToAuditId, newLocalFile, true, false); if ( parameters.getEvidenceStatus().equals(EvidenceStatus.FATAL) ) { itemStatus.increment(StatusCode.FATAL); ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "Fatal Technical error "+ parameters.getAuditMessage()); itemStatus.setEvDetailData(unprettyPrint(infoNode)); evidenceAuditReportService.cleanupReport(param.getContainerName()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE).setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } if (parameters.getEvidenceStatus().equals(EvidenceStatus.KO) || parameters.getEvidenceStatus().equals(EvidenceStatus.WARN)) { EvidenceAuditReportLine evidenceAuditReportLine = null; evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); evidenceAuditReportLine.setStrategyId(parameters.getMdOptimisticStorageInfo().getStrategy()); JsonHandler.writeAsFile(evidenceAuditReportLine, file); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, true, false); if(!param.getWorkflowIdentifier().equals("RECTIFICATION_AUDIT")) addReportEntry(param.getContainerName(), createEvidenceReportEntry(parameters, evidenceAuditReportLine)); } itemStatus.increment(StatusCode.OK); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (VitamException | IOException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (ProcessingStatusException e) { LOGGER.error(e); itemStatus.increment(e.getStatusCode()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } } @VisibleForTesting  EvidenceAuditDatabaseCheck(EvidenceService evidenceService, EvidenceAuditReportService evidenceAuditReportService);  EvidenceAuditDatabaseCheck(); }
EvidenceAuditDatabaseCheck extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE); String objectToAuditId = param.getObjectName(); try { File file = handlerIO.getFileFromWorkspace("Object/" + objectToAuditId); JsonNode objectIdToAudit = JsonHandler.getFromFile(file); MetadataType metadataType = MetadataType.valueOf(objectIdToAudit.get(METADA_TYPE).textValue()); List<StorageStrategy> storageStrategies = loadStorageStrategies(handlerIO); EvidenceAuditParameters parameters = evidenceService.evidenceAuditsChecks(objectToAuditId, metadataType, storageStrategies); File newLocalFile = handlerIO.getNewLocalFile(objectToAuditId + ".tmp"); JsonHandler.writeAsFile(parameters, newLocalFile); handlerIO.transferFileToWorkspace(DATA + "/" + objectToAuditId, newLocalFile, true, false); if ( parameters.getEvidenceStatus().equals(EvidenceStatus.FATAL) ) { itemStatus.increment(StatusCode.FATAL); ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "Fatal Technical error "+ parameters.getAuditMessage()); itemStatus.setEvDetailData(unprettyPrint(infoNode)); evidenceAuditReportService.cleanupReport(param.getContainerName()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE).setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } if (parameters.getEvidenceStatus().equals(EvidenceStatus.KO) || parameters.getEvidenceStatus().equals(EvidenceStatus.WARN)) { EvidenceAuditReportLine evidenceAuditReportLine = null; evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); evidenceAuditReportLine.setStrategyId(parameters.getMdOptimisticStorageInfo().getStrategy()); JsonHandler.writeAsFile(evidenceAuditReportLine, file); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, true, false); if(!param.getWorkflowIdentifier().equals("RECTIFICATION_AUDIT")) addReportEntry(param.getContainerName(), createEvidenceReportEntry(parameters, evidenceAuditReportLine)); } itemStatus.increment(StatusCode.OK); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (VitamException | IOException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (ProcessingStatusException e) { LOGGER.error(e); itemStatus.increment(e.getStatusCode()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } } @VisibleForTesting  EvidenceAuditDatabaseCheck(EvidenceService evidenceService, EvidenceAuditReportService evidenceAuditReportService);  EvidenceAuditDatabaseCheck(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handlerIO); }
EvidenceAuditDatabaseCheck extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handlerIO) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE); String objectToAuditId = param.getObjectName(); try { File file = handlerIO.getFileFromWorkspace("Object/" + objectToAuditId); JsonNode objectIdToAudit = JsonHandler.getFromFile(file); MetadataType metadataType = MetadataType.valueOf(objectIdToAudit.get(METADA_TYPE).textValue()); List<StorageStrategy> storageStrategies = loadStorageStrategies(handlerIO); EvidenceAuditParameters parameters = evidenceService.evidenceAuditsChecks(objectToAuditId, metadataType, storageStrategies); File newLocalFile = handlerIO.getNewLocalFile(objectToAuditId + ".tmp"); JsonHandler.writeAsFile(parameters, newLocalFile); handlerIO.transferFileToWorkspace(DATA + "/" + objectToAuditId, newLocalFile, true, false); if ( parameters.getEvidenceStatus().equals(EvidenceStatus.FATAL) ) { itemStatus.increment(StatusCode.FATAL); ObjectNode infoNode = JsonHandler.createObjectNode(); infoNode.put("Message", "Fatal Technical error "+ parameters.getAuditMessage()); itemStatus.setEvDetailData(unprettyPrint(infoNode)); evidenceAuditReportService.cleanupReport(param.getContainerName()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE).setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } if (parameters.getEvidenceStatus().equals(EvidenceStatus.KO) || parameters.getEvidenceStatus().equals(EvidenceStatus.WARN)) { EvidenceAuditReportLine evidenceAuditReportLine = null; evidenceAuditReportLine = new EvidenceAuditReportLine(objectToAuditId); evidenceAuditReportLine.setEvidenceStatus(parameters.getEvidenceStatus()); evidenceAuditReportLine.setMessage(parameters.getAuditMessage()); evidenceAuditReportLine.setStrategyId(parameters.getMdOptimisticStorageInfo().getStrategy()); JsonHandler.writeAsFile(evidenceAuditReportLine, file); handlerIO.transferFileToWorkspace(REPORTS + "/" + objectToAuditId + ".report.json", file, true, false); if(!param.getWorkflowIdentifier().equals("RECTIFICATION_AUDIT")) addReportEntry(param.getContainerName(), createEvidenceReportEntry(parameters, evidenceAuditReportLine)); } itemStatus.increment(StatusCode.OK); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (VitamException | IOException e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } catch (ProcessingStatusException e) { LOGGER.error(e); itemStatus.increment(e.getStatusCode()); return new ItemStatus(EVIDENCE_AUDIT_CHECK_DATABASE) .setItemsStatus(EVIDENCE_AUDIT_CHECK_DATABASE, itemStatus); } } @VisibleForTesting  EvidenceAuditDatabaseCheck(EvidenceService evidenceService, EvidenceAuditReportService evidenceAuditReportService);  EvidenceAuditDatabaseCheck(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handlerIO);  }