@RunWithCustomExecutor() @Test public void auditEvidenceNominalCaseForUnit() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); EvidenceService evidenceService = new EvidenceService(metaDataClientFactory, logbookOperationsClientFactory, logbookLifeCyclesClientFactory, storageClientFactory); JsonNode unitMd = getUnitMd(); JsonNode liceCycle = getLifcycle(); JsonNode logbook = getLogbook(); RequestResponseOK<JsonNode> response1 = new RequestResponseOK<JsonNode>().addResult(unitMd); when(metaDataClient.getUnitByIdRaw("aeaqaaaaaaguu2zzaazsualbwlwdgwaaaaaq")).thenReturn(response1); when(logbookLifeCyclesClient.getRawUnitLifeCycleById("aeaqaaaaaaguu2zzaazsualbwlwdgwaaaaaq")) .thenReturn(liceCycle); JsonNode select = getSelectlogbookLCsecure(); JsonNode select2 = getSelect2(); when(logbookOperationsClient.selectOperationById(anyString())).thenReturn(logbook); when(logbookOperationsClient.selectOperation(select)) .thenReturn(JsonHandler.getFromFile(PropertiesUtils.getResourceFile(RESULT_SELECT_LOGBOOK_SECUR_OP))); when(logbookOperationsClient.selectOperation(select2)) .thenReturn(JsonHandler.getFromFile(PropertiesUtils.getResourceFile(RESULT_SELECT_ISLAST))); when(storageClient.getInformation(anyString(), eq(DataCategory.UNIT), anyString(), any(), eq(true))) .thenReturn(OFFERS_INFO); EvidenceAuditParameters parameters = evidenceService.evidenceAuditsChecks("aeaqaaaaaaguu2zzaazsualbwlwdgwaaaaaq", MetadataType.UNIT, loadStorageStrategiesMock()); EvidenceAuditParameters expected = JsonHandler.getFromFile(PropertiesUtils.getResourceFile(result), EvidenceAuditParameters.class); assertThat(parameters.getHashLfcFromDatabase()).isEqualTo(expected.getHashLfcFromDatabase()); assertThat(parameters.getHashMdFromDatabase()).isEqualTo(expected.getHashMdFromDatabase()); assertThat(parameters.getLfcVersion()).isEqualTo(expected.getLfcVersion()); assertThat(parameters.getObjectStorageMetadataResultMap()).isNull(); assertThat(parameters.getMdOptimisticStorageInfo().getStrategy()).isEqualTo("default"); }
public EvidenceAuditParameters evidenceAuditsChecks(String id, MetadataType metadataType, List<StorageStrategy> storageStrategies) { EvidenceAuditParameters auditParameters = new EvidenceAuditParameters(); try { auditParameters.setId(id); auditParameters.setMetadataType(metadataType); JsonNode metadata = getRawMetadata(id, metadataType); StoredInfoResult mdOptimisticStorageInfo = fromMetadataJson(metadata, storageStrategies); auditParameters.setMdOptimisticStorageInfo(mdOptimisticStorageInfo); JsonNode lifecycle = getRawLifeCycle(id, metadataType); int lfcVersion = lifecycle.get(LogbookDocument.VERSION).asInt(); auditParameters.setLfcVersion(lfcVersion); JsonNode storageResultsJsonNode = getStorageResultsJsonNode(auditParameters.getMdOptimisticStorageInfo(), getDataCategory(auditParameters.getMetadataType()), auditParameters.getId() + JSON); String logbookOperationSecurisationId = getLogbookSecureOperationId(lifecycle, metadataType); auditParameters.setSecurisationOperationId(logbookOperationSecurisationId); boolean isLastLifeCycleTraceabilityOperation = isLastLifeCycleTraceabilityOperation(logbookOperationSecurisationId, metadataType); auditParameters.setLastSecurisation(isLastLifeCycleTraceabilityOperation); loadFileInfoFromLogbook(logbookOperationSecurisationId, auditParameters); if (metadataType.equals(MetadataType.OBJECTGROUP)) { extractObjectStorageMetadataResultMap(metadata, auditParameters, storageStrategies); } switch (metadataType) { case UNIT: MetadataDocumentHelper.removeComputedFieldsFromUnit(metadata); break; case OBJECTGROUP: MetadataDocumentHelper.removeComputedFieldsFromObjectGroup(metadata); break; default: throw new UnsupportedOperationException("Unknown metadata type " + metadataType); } final String hashMdFromDatabase = generateDigest(metadata, auditParameters.getDigestType()); final String hashLfcFromDatabase = generateDigest(lifecycle, auditParameters.getDigestType()); auditParameters.setHashMdFromDatabase(hashMdFromDatabase); auditParameters.setHashLfcFromDatabase(hashLfcFromDatabase); auditParameters.setStorageMetadataResultListJsonNode(storageResultsJsonNode); auditParameters.setEvidenceStatus(EvidenceStatus.OK); } catch (StorageException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(EvidenceStatus.FATAL); auditParameters.setAuditMessage(e.getMessage()); } catch (EvidenceAuditException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(e.getStatus()); auditParameters.setAuditMessage(e.getMessage()); } return auditParameters; }
EvidenceService { public EvidenceAuditParameters evidenceAuditsChecks(String id, MetadataType metadataType, List<StorageStrategy> storageStrategies) { EvidenceAuditParameters auditParameters = new EvidenceAuditParameters(); try { auditParameters.setId(id); auditParameters.setMetadataType(metadataType); JsonNode metadata = getRawMetadata(id, metadataType); StoredInfoResult mdOptimisticStorageInfo = fromMetadataJson(metadata, storageStrategies); auditParameters.setMdOptimisticStorageInfo(mdOptimisticStorageInfo); JsonNode lifecycle = getRawLifeCycle(id, metadataType); int lfcVersion = lifecycle.get(LogbookDocument.VERSION).asInt(); auditParameters.setLfcVersion(lfcVersion); JsonNode storageResultsJsonNode = getStorageResultsJsonNode(auditParameters.getMdOptimisticStorageInfo(), getDataCategory(auditParameters.getMetadataType()), auditParameters.getId() + JSON); String logbookOperationSecurisationId = getLogbookSecureOperationId(lifecycle, metadataType); auditParameters.setSecurisationOperationId(logbookOperationSecurisationId); boolean isLastLifeCycleTraceabilityOperation = isLastLifeCycleTraceabilityOperation(logbookOperationSecurisationId, metadataType); auditParameters.setLastSecurisation(isLastLifeCycleTraceabilityOperation); loadFileInfoFromLogbook(logbookOperationSecurisationId, auditParameters); if (metadataType.equals(MetadataType.OBJECTGROUP)) { extractObjectStorageMetadataResultMap(metadata, auditParameters, storageStrategies); } switch (metadataType) { case UNIT: MetadataDocumentHelper.removeComputedFieldsFromUnit(metadata); break; case OBJECTGROUP: MetadataDocumentHelper.removeComputedFieldsFromObjectGroup(metadata); break; default: throw new UnsupportedOperationException("Unknown metadata type " + metadataType); } final String hashMdFromDatabase = generateDigest(metadata, auditParameters.getDigestType()); final String hashLfcFromDatabase = generateDigest(lifecycle, auditParameters.getDigestType()); auditParameters.setHashMdFromDatabase(hashMdFromDatabase); auditParameters.setHashLfcFromDatabase(hashLfcFromDatabase); auditParameters.setStorageMetadataResultListJsonNode(storageResultsJsonNode); auditParameters.setEvidenceStatus(EvidenceStatus.OK); } catch (StorageException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(EvidenceStatus.FATAL); auditParameters.setAuditMessage(e.getMessage()); } catch (EvidenceAuditException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(e.getStatus()); auditParameters.setAuditMessage(e.getMessage()); } return auditParameters; } }
EvidenceService { public EvidenceAuditParameters evidenceAuditsChecks(String id, MetadataType metadataType, List<StorageStrategy> storageStrategies) { EvidenceAuditParameters auditParameters = new EvidenceAuditParameters(); try { auditParameters.setId(id); auditParameters.setMetadataType(metadataType); JsonNode metadata = getRawMetadata(id, metadataType); StoredInfoResult mdOptimisticStorageInfo = fromMetadataJson(metadata, storageStrategies); auditParameters.setMdOptimisticStorageInfo(mdOptimisticStorageInfo); JsonNode lifecycle = getRawLifeCycle(id, metadataType); int lfcVersion = lifecycle.get(LogbookDocument.VERSION).asInt(); auditParameters.setLfcVersion(lfcVersion); JsonNode storageResultsJsonNode = getStorageResultsJsonNode(auditParameters.getMdOptimisticStorageInfo(), getDataCategory(auditParameters.getMetadataType()), auditParameters.getId() + JSON); String logbookOperationSecurisationId = getLogbookSecureOperationId(lifecycle, metadataType); auditParameters.setSecurisationOperationId(logbookOperationSecurisationId); boolean isLastLifeCycleTraceabilityOperation = isLastLifeCycleTraceabilityOperation(logbookOperationSecurisationId, metadataType); auditParameters.setLastSecurisation(isLastLifeCycleTraceabilityOperation); loadFileInfoFromLogbook(logbookOperationSecurisationId, auditParameters); if (metadataType.equals(MetadataType.OBJECTGROUP)) { extractObjectStorageMetadataResultMap(metadata, auditParameters, storageStrategies); } switch (metadataType) { case UNIT: MetadataDocumentHelper.removeComputedFieldsFromUnit(metadata); break; case OBJECTGROUP: MetadataDocumentHelper.removeComputedFieldsFromObjectGroup(metadata); break; default: throw new UnsupportedOperationException("Unknown metadata type " + metadataType); } final String hashMdFromDatabase = generateDigest(metadata, auditParameters.getDigestType()); final String hashLfcFromDatabase = generateDigest(lifecycle, auditParameters.getDigestType()); auditParameters.setHashMdFromDatabase(hashMdFromDatabase); auditParameters.setHashLfcFromDatabase(hashLfcFromDatabase); auditParameters.setStorageMetadataResultListJsonNode(storageResultsJsonNode); auditParameters.setEvidenceStatus(EvidenceStatus.OK); } catch (StorageException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(EvidenceStatus.FATAL); auditParameters.setAuditMessage(e.getMessage()); } catch (EvidenceAuditException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(e.getStatus()); auditParameters.setAuditMessage(e.getMessage()); } return auditParameters; } EvidenceService(); @VisibleForTesting  EvidenceService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        StorageClientFactory storageClientFactory); }
EvidenceService { public EvidenceAuditParameters evidenceAuditsChecks(String id, MetadataType metadataType, List<StorageStrategy> storageStrategies) { EvidenceAuditParameters auditParameters = new EvidenceAuditParameters(); try { auditParameters.setId(id); auditParameters.setMetadataType(metadataType); JsonNode metadata = getRawMetadata(id, metadataType); StoredInfoResult mdOptimisticStorageInfo = fromMetadataJson(metadata, storageStrategies); auditParameters.setMdOptimisticStorageInfo(mdOptimisticStorageInfo); JsonNode lifecycle = getRawLifeCycle(id, metadataType); int lfcVersion = lifecycle.get(LogbookDocument.VERSION).asInt(); auditParameters.setLfcVersion(lfcVersion); JsonNode storageResultsJsonNode = getStorageResultsJsonNode(auditParameters.getMdOptimisticStorageInfo(), getDataCategory(auditParameters.getMetadataType()), auditParameters.getId() + JSON); String logbookOperationSecurisationId = getLogbookSecureOperationId(lifecycle, metadataType); auditParameters.setSecurisationOperationId(logbookOperationSecurisationId); boolean isLastLifeCycleTraceabilityOperation = isLastLifeCycleTraceabilityOperation(logbookOperationSecurisationId, metadataType); auditParameters.setLastSecurisation(isLastLifeCycleTraceabilityOperation); loadFileInfoFromLogbook(logbookOperationSecurisationId, auditParameters); if (metadataType.equals(MetadataType.OBJECTGROUP)) { extractObjectStorageMetadataResultMap(metadata, auditParameters, storageStrategies); } switch (metadataType) { case UNIT: MetadataDocumentHelper.removeComputedFieldsFromUnit(metadata); break; case OBJECTGROUP: MetadataDocumentHelper.removeComputedFieldsFromObjectGroup(metadata); break; default: throw new UnsupportedOperationException("Unknown metadata type " + metadataType); } final String hashMdFromDatabase = generateDigest(metadata, auditParameters.getDigestType()); final String hashLfcFromDatabase = generateDigest(lifecycle, auditParameters.getDigestType()); auditParameters.setHashMdFromDatabase(hashMdFromDatabase); auditParameters.setHashLfcFromDatabase(hashLfcFromDatabase); auditParameters.setStorageMetadataResultListJsonNode(storageResultsJsonNode); auditParameters.setEvidenceStatus(EvidenceStatus.OK); } catch (StorageException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(EvidenceStatus.FATAL); auditParameters.setAuditMessage(e.getMessage()); } catch (EvidenceAuditException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(e.getStatus()); auditParameters.setAuditMessage(e.getMessage()); } return auditParameters; } EvidenceService(); @VisibleForTesting  EvidenceService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        StorageClientFactory storageClientFactory); EvidenceAuditReportLine auditAndGenerateReportIfKo(EvidenceAuditParameters parameters,
        List<String> securedLines,
        String id); File downloadAndExtractDataFromStorage(String fileName, String fileToExtract, String extension,boolean delele); static LifeCycleTraceabilitySecureFileObject loadInformationFromFile(List<String> securedLines,
        MetadataType metadataType,
        String id); File extractFileStreamFromZip(File file, String fileToExtract, String extension, boolean delete); EvidenceAuditParameters evidenceAuditsChecks(String id, MetadataType metadataType, List<StorageStrategy> storageStrategies); }
EvidenceService { public EvidenceAuditParameters evidenceAuditsChecks(String id, MetadataType metadataType, List<StorageStrategy> storageStrategies) { EvidenceAuditParameters auditParameters = new EvidenceAuditParameters(); try { auditParameters.setId(id); auditParameters.setMetadataType(metadataType); JsonNode metadata = getRawMetadata(id, metadataType); StoredInfoResult mdOptimisticStorageInfo = fromMetadataJson(metadata, storageStrategies); auditParameters.setMdOptimisticStorageInfo(mdOptimisticStorageInfo); JsonNode lifecycle = getRawLifeCycle(id, metadataType); int lfcVersion = lifecycle.get(LogbookDocument.VERSION).asInt(); auditParameters.setLfcVersion(lfcVersion); JsonNode storageResultsJsonNode = getStorageResultsJsonNode(auditParameters.getMdOptimisticStorageInfo(), getDataCategory(auditParameters.getMetadataType()), auditParameters.getId() + JSON); String logbookOperationSecurisationId = getLogbookSecureOperationId(lifecycle, metadataType); auditParameters.setSecurisationOperationId(logbookOperationSecurisationId); boolean isLastLifeCycleTraceabilityOperation = isLastLifeCycleTraceabilityOperation(logbookOperationSecurisationId, metadataType); auditParameters.setLastSecurisation(isLastLifeCycleTraceabilityOperation); loadFileInfoFromLogbook(logbookOperationSecurisationId, auditParameters); if (metadataType.equals(MetadataType.OBJECTGROUP)) { extractObjectStorageMetadataResultMap(metadata, auditParameters, storageStrategies); } switch (metadataType) { case UNIT: MetadataDocumentHelper.removeComputedFieldsFromUnit(metadata); break; case OBJECTGROUP: MetadataDocumentHelper.removeComputedFieldsFromObjectGroup(metadata); break; default: throw new UnsupportedOperationException("Unknown metadata type " + metadataType); } final String hashMdFromDatabase = generateDigest(metadata, auditParameters.getDigestType()); final String hashLfcFromDatabase = generateDigest(lifecycle, auditParameters.getDigestType()); auditParameters.setHashMdFromDatabase(hashMdFromDatabase); auditParameters.setHashLfcFromDatabase(hashLfcFromDatabase); auditParameters.setStorageMetadataResultListJsonNode(storageResultsJsonNode); auditParameters.setEvidenceStatus(EvidenceStatus.OK); } catch (StorageException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(EvidenceStatus.FATAL); auditParameters.setAuditMessage(e.getMessage()); } catch (EvidenceAuditException e) { LOGGER.error(e); auditParameters.setEvidenceStatus(e.getStatus()); auditParameters.setAuditMessage(e.getMessage()); } return auditParameters; } EvidenceService(); @VisibleForTesting  EvidenceService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory,
        LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        StorageClientFactory storageClientFactory); EvidenceAuditReportLine auditAndGenerateReportIfKo(EvidenceAuditParameters parameters,
        List<String> securedLines,
        String id); File downloadAndExtractDataFromStorage(String fileName, String fileToExtract, String extension,boolean delele); static LifeCycleTraceabilitySecureFileObject loadInformationFromFile(List<String> securedLines,
        MetadataType metadataType,
        String id); File extractFileStreamFromZip(File file, String fileToExtract, String extension, boolean delete); EvidenceAuditParameters evidenceAuditsChecks(String id, MetadataType metadataType, List<StorageStrategy> storageStrategies); static final String JSON; static final String OK; static final String WARNING; }