@Test public void shouldStatusOKWhenBinaryObjectExists() throws Exception { reset(storageClient); Map<String, Boolean> existsResult = new HashMap<String, Boolean>(); existsResult.put("offer-fs-1.service.int.consul", Boolean.TRUE); existsResult.put("offer-fs-2.service.int.consul", Boolean.TRUE); when(storageClient.exists(any(), any(), eq("aeaaaaaaaahgotryaauzialjp5zkhgiaaaaq"), any())) .thenReturn(existsResult); 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()) { AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); if (PHYSICAL_MASTER.equals(object.getQualifier())) { StorageRacineModel storageInformation = gotDetail.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.KO : StatusCode.OK))); } else { StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.OK : 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; }
AuditExistenceService { 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()) { AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); if (PHYSICAL_MASTER.equals(object.getQualifier())) { StorageRacineModel storageInformation = gotDetail.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.KO : StatusCode.OK))); } else { StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.OK : 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; } }
AuditExistenceService { 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()) { AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); if (PHYSICAL_MASTER.equals(object.getQualifier())) { StorageRacineModel storageInformation = gotDetail.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.KO : StatusCode.OK))); } else { StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.OK : 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; } AuditExistenceService(); @VisibleForTesting  AuditExistenceService(StorageClientFactory storageClientFactory); }
AuditExistenceService { 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()) { AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); if (PHYSICAL_MASTER.equals(object.getQualifier())) { StorageRacineModel storageInformation = gotDetail.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.KO : StatusCode.OK))); } else { StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.OK : 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; } AuditExistenceService(); @VisibleForTesting  AuditExistenceService(StorageClientFactory storageClientFactory); AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies); }
AuditExistenceService { 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()) { AuditCheckObjectResult auditCheckObjectResult = new AuditCheckObjectResult(); auditCheckObjectResult.setIdObject(object.getId()); if (PHYSICAL_MASTER.equals(object.getQualifier())) { StorageRacineModel storageInformation = gotDetail.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.KO : StatusCode.OK))); } else { StorageJson storageInformation = object.getStorage(); List<String> offerIds = StorageStrategyUtils.loadOfferIds(storageInformation.getStrategyId(), storageStrategies); Map<String, Boolean> existsResult = storageClient.exists(storageInformation.getStrategyId(), DataCategory.OBJECT, object.getId(), offerIds); auditCheckObjectResult.getOfferStatuses() .putAll(existsResult.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> BooleanUtils.isTrue(e.getValue()) ? StatusCode.OK : 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; } AuditExistenceService(); @VisibleForTesting  AuditExistenceService(StorageClientFactory storageClientFactory); AuditCheckObjectGroupResult check(AuditObjectGroup gotDetail, List<StorageStrategy> storageStrategies); static final String CHECK_EXISTENCE_ID; }