@Test public void shouldStatusOKWhenBinaryDigestValid() throws Exception { ObjectNode offerIdToMetadata = JsonHandler.createObjectNode(); StorageMetadataResult metaData = new StorageMetadataResult("aeaaaaaaaacu6xzeabinwak6t5ecmlaaaaaq", "object", "86c0bc701ef6b5dd21b080bc5bb2af38097baa6237275da83a52f092c9eae3e4e4b0247391620bd732fe824d18bd3bb6c37e62ec73a8cf3585c6a799399861b1", 6096, "Tue Aug 31 10:20:56 SGT 2016", "Tue Aug 31 10:20:56 SGT 2016"); offerIdToMetadata.set("offer-fs-1.service.int.consul", JsonHandler.toJsonNode(metaData)); offerIdToMetadata.set("offer-fs-2.service.int.consul", JsonHandler.toJsonNode(metaData)); reset(storageClient); when(storageClient.getInformation(eq(VitamConfiguration.getDefaultStrategy()), eq(DataCategory.OBJECT), eq("aeaaaaaaaahgotryaauzialjp5zkhgiaaaaq"), any(), eq(true))).thenReturn(offerIdToMetadata); JsonLineModel objectGroupLine = getFromInputStream( getClass().getResourceAsStream("/AuditObjectWorkflow/objectGroup_1.json"), JsonLineModel.class); AuditObjectGroup detail = getFromJsonNode(objectGroupLine.getParams(), AuditObjectGroup.class); final AuditCheckObjectGroupResult response = service.check(detail, loadStorageStrategiesMock()); assertThat(response.getStatus()).isEqualTo(StatusCode.OK); assertThat(response.getObjectStatuses().size()).isEqualTo(1); assertThat(response.getObjectStatuses().get(0)).isNotNull(); assertThat(response.getObjectStatuses().get(0).getOfferStatuses().size()).isEqualTo(2); assertThat(response.getObjectStatuses().get(0).getOfferStatuses().get("offer-fs-1.service.int.consul")) .isEqualTo(StatusCode.OK); assertThat(response.getObjectStatuses().get(0).getOfferStatuses().get("offer-fs-2.service.int.consul")) .isEqualTo(StatusCode.OK); assertThat(response.getObjectStatuses().get(0).getGlobalStatus()).isEqualTo(StatusCode.OK); }
public AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies) throws ProcessingStatusException { AuditCheckObjectGroupResult result = new AuditCheckObjectGroupResult(); result.setIdObjectGroup(gotDetail.getId()); try (final StorageClient storageClient = storageClientFactory.getClient()) { for (AuditObject object : gotDetail.getObjects()) { if (PHYSICAL_MASTER.equals(object.getQualifier())) { continue; } AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); JsonNode offerToMetadata = storageClient.getInformation(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds, true); for (String offerId : offerIds) { JsonNode metadata = offerToMetadata.findValue(offerId); if (metadata == null || object.getMessageDigest() == null || !metadata.has("digest")) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } else { String digest = metadata.get("digest").asText(); if (StringUtils.equals(object.getMessageDigest(), digest)) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.OK); } else { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } } } result.getObjectStatuses().add(auditCheckObjectResult); } result.setStatus(result.getObjectsGlobalStatus()); } catch (StorageClientException | StorageStrategyNotFoundException e) { LOGGER.error("Storage server errors : ", e); throw new ProcessingStatusException(StatusCode.FATAL, String.format("Storage server errors : %s", e)); } if (result.getStatus() == null) { result.setStatus(StatusCode.OK); } return result; }
AuditIntegrityService { public AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies) throws ProcessingStatusException { AuditCheckObjectGroupResult result = new AuditCheckObjectGroupResult(); result.setIdObjectGroup(gotDetail.getId()); try (final StorageClient storageClient = storageClientFactory.getClient()) { for (AuditObject object : gotDetail.getObjects()) { if (PHYSICAL_MASTER.equals(object.getQualifier())) { continue; } AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); JsonNode offerToMetadata = storageClient.getInformation(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds, true); for (String offerId : offerIds) { JsonNode metadata = offerToMetadata.findValue(offerId); if (metadata == null || object.getMessageDigest() == null || !metadata.has("digest")) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } else { String digest = metadata.get("digest").asText(); if (StringUtils.equals(object.getMessageDigest(), digest)) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.OK); } else { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } } } result.getObjectStatuses().add(auditCheckObjectResult); } result.setStatus(result.getObjectsGlobalStatus()); } catch (StorageClientException | StorageStrategyNotFoundException e) { LOGGER.error("Storage server errors : ", e); throw new ProcessingStatusException(StatusCode.FATAL, String.format("Storage server errors : %s", e)); } if (result.getStatus() == null) { result.setStatus(StatusCode.OK); } return result; } }
AuditIntegrityService { public AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies) throws ProcessingStatusException { AuditCheckObjectGroupResult result = new AuditCheckObjectGroupResult(); result.setIdObjectGroup(gotDetail.getId()); try (final StorageClient storageClient = storageClientFactory.getClient()) { for (AuditObject object : gotDetail.getObjects()) { if (PHYSICAL_MASTER.equals(object.getQualifier())) { continue; } AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); JsonNode offerToMetadata = storageClient.getInformation(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds, true); for (String offerId : offerIds) { JsonNode metadata = offerToMetadata.findValue(offerId); if (metadata == null || object.getMessageDigest() == null || !metadata.has("digest")) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } else { String digest = metadata.get("digest").asText(); if (StringUtils.equals(object.getMessageDigest(), digest)) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.OK); } else { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } } } result.getObjectStatuses().add(auditCheckObjectResult); } result.setStatus(result.getObjectsGlobalStatus()); } catch (StorageClientException | StorageStrategyNotFoundException e) { LOGGER.error("Storage server errors : ", e); throw new ProcessingStatusException(StatusCode.FATAL, String.format("Storage server errors : %s", e)); } if (result.getStatus() == null) { result.setStatus(StatusCode.OK); } return result; } AuditIntegrityService(); @VisibleForTesting  AuditIntegrityService(StorageClientFactory storageClientFactory); }
AuditIntegrityService { public AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies) throws ProcessingStatusException { AuditCheckObjectGroupResult result = new AuditCheckObjectGroupResult(); result.setIdObjectGroup(gotDetail.getId()); try (final StorageClient storageClient = storageClientFactory.getClient()) { for (AuditObject object : gotDetail.getObjects()) { if (PHYSICAL_MASTER.equals(object.getQualifier())) { continue; } AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); JsonNode offerToMetadata = storageClient.getInformation(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds, true); for (String offerId : offerIds) { JsonNode metadata = offerToMetadata.findValue(offerId); if (metadata == null || object.getMessageDigest() == null || !metadata.has("digest")) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } else { String digest = metadata.get("digest").asText(); if (StringUtils.equals(object.getMessageDigest(), digest)) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.OK); } else { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } } } result.getObjectStatuses().add(auditCheckObjectResult); } result.setStatus(result.getObjectsGlobalStatus()); } catch (StorageClientException | StorageStrategyNotFoundException e) { LOGGER.error("Storage server errors : ", e); throw new ProcessingStatusException(StatusCode.FATAL, String.format("Storage server errors : %s", e)); } if (result.getStatus() == null) { result.setStatus(StatusCode.OK); } return result; } AuditIntegrityService(); @VisibleForTesting  AuditIntegrityService(StorageClientFactory storageClientFactory); AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies); }
AuditIntegrityService { public AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies) throws ProcessingStatusException { AuditCheckObjectGroupResult result = new AuditCheckObjectGroupResult(); result.setIdObjectGroup(gotDetail.getId()); try (final StorageClient storageClient = storageClientFactory.getClient()) { for (AuditObject object : gotDetail.getObjects()) { if (PHYSICAL_MASTER.equals(object.getQualifier())) { continue; } AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); JsonNode offerToMetadata = storageClient.getInformation(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds, true); for (String offerId : offerIds) { JsonNode metadata = offerToMetadata.findValue(offerId); if (metadata == null || object.getMessageDigest() == null || !metadata.has("digest")) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } else { String digest = metadata.get("digest").asText(); if (StringUtils.equals(object.getMessageDigest(), digest)) { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.OK); } else { auditCheckObjectResult.getOfferStatuses().put(offerId, StatusCode.KO); } } } result.getObjectStatuses().add(auditCheckObjectResult); } result.setStatus(result.getObjectsGlobalStatus()); } catch (StorageClientException | StorageStrategyNotFoundException e) { LOGGER.error("Storage server errors : ", e); throw new ProcessingStatusException(StatusCode.FATAL, String.format("Storage server errors : %s", e)); } if (result.getStatus() == null) { result.setStatus(StatusCode.OK); } return result; } AuditIntegrityService(); @VisibleForTesting  AuditIntegrityService(StorageClientFactory storageClientFactory); AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies); static final String CHECK_INTEGRITY_ID; }