/** * Create an instance of {@link StorageUnit } * */ public StorageUnit createStorageUnit() { return new StorageUnit(); }
public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) { final Object draftCopy = ((target == null)?createNewInstance():target); if (draftCopy instanceof StorageUnit) { final StorageUnit copy = ((StorageUnit) draftCopy); if (storageShouldBeCopiedAndSet == Boolean.TRUE) { Storage sourceStorage; sourceStorage = this.getStorage(); Storage copyStorage = ((Storage) strategy.copy(LocatorUtils.property(locator, "storage", sourceStorage), sourceStorage, (this.storage!= null))); copy.setStorage(copyStorage); } else { if (storageShouldBeCopiedAndSet == Boolean.FALSE) { if (storageDirectoryShouldBeCopiedAndSet == Boolean.TRUE) { StorageDirectory sourceStorageDirectory; sourceStorageDirectory = this.getStorageDirectory(); StorageDirectory copyStorageDirectory = ((StorageDirectory) strategy.copy(LocatorUtils.property(locator, "storageDirectory", sourceStorageDirectory), sourceStorageDirectory, (this.storageDirectory!= null))); copy.setStorageDirectory(copyStorageDirectory); } else { if (storageDirectoryShouldBeCopiedAndSet == Boolean.FALSE) { if (storageFilesShouldBeCopiedAndSet == Boolean.TRUE) { List<StorageFile> sourceStorageFiles; sourceStorageFiles = ((this.storageFiles!= null)?this.getStorageFiles():null); @SuppressWarnings("unchecked") List<StorageFile> copyStorageFiles = ((List<StorageFile> ) strategy.copy(LocatorUtils.property(locator, "storageFiles", sourceStorageFiles), sourceStorageFiles, (this.storageFiles!= null))); copy.storageFiles = null; if (copyStorageFiles!= null) { copy.setStorageFiles(copyStorageFiles);
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { theStorage = this.getStorage(); strategy.appendField(locator, this, "storage", buffer, theStorage, (this.storage!= null)); theStorageDirectory = this.getStorageDirectory(); strategy.appendField(locator, this, "storageDirectory", buffer, theStorageDirectory, (this.storageDirectory!= null)); theStorageFiles = ((this.storageFiles!= null)?this.getStorageFiles():null); strategy.appendField(locator, this, "storageFiles", buffer, theStorageFiles, (this.storageFiles!= null)); theStorageUnitStatus = this.getStorageUnitStatus(); strategy.appendField(locator, this, "storageUnitStatus", buffer, theStorageUnitStatus, (this.storageUnitStatus!= null)); theStorageUnitStatusHistory = ((this.storageUnitStatusHistory!= null)?this.getStorageUnitStatusHistory():null); strategy.appendField(locator, this, "storageUnitStatusHistory", buffer, theStorageUnitStatusHistory, (this.storageUnitStatusHistory!= null)); theStoragePolicyTransitionFailedAttempts = this.getStoragePolicyTransitionFailedAttempts(); strategy.appendField(locator, this, "storagePolicyTransitionFailedAttempts", buffer, theStoragePolicyTransitionFailedAttempts, (this.storagePolicyTransitionFailedAttempts!= null)); theRestoreExpirationOn = this.getRestoreExpirationOn(); strategy.appendField(locator, this, "restoreExpirationOn", buffer, theRestoreExpirationOn, (this.restoreExpirationOn!= null));
if (!CollectionUtils.isEmpty(storageUnit.getStorageFiles())) for (StorageFile storageFile : storageUnit.getStorageFiles()) String.format("Registered file \"%s\" does not exist in \"%s\" storage.", registeredS3Files.get(0), storageUnit.getStorage().getName())); throw new IllegalStateException(String .format("Found S3 file \"%s\" in \"%s\" storage not registered with this business object data.", actualS3Files.get(0), storageUnit.getStorage().getName()));
StorageUnit storageUnit = new StorageUnit(); storageUnits.add(storageUnit); storageUnit.setStorage(storage); storageUnit.setStorageDirectory(storageDirectory); storageDirectory.setDirectoryPath(storageUnitEntity.getDirectoryPath()); storageUnit.setStorageFiles(storageFiles); storageUnit.setStorageUnitStatus(storageUnitEntity.getStatus().getCode()); storageUnit.setStorageUnitStatusHistory(storageUnitStatusChangeEvents); for (StorageUnitStatusHistoryEntity storageUnitStatusHistoryEntity : storageUnitEntity.getHistoricalStatuses()) storageUnit.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts()); storageUnit.setRestoreExpirationOn(HerdDateUtils.getXMLGregorianCalendarValue(storageUnitEntity.getRestoreExpirationOn()));
StorageUnit storageUnit = new StorageUnit(); storageUnit.setStorage(storage); storageUnit.setStorageFiles(storageFiles); if (!CollectionUtils.isEmpty(files)) storageUnit.setStorageUnitStatus(StorageUnitStatusEntity.ENABLED);
StorageUnit actualStorageUnit = actualBusinessObjectData.getStorageUnits().get(0); assertEquals(expectedStorageName, actualStorageUnit.getStorage().getName()); assertEquals(expectedStorageDirectoryPath, actualStorageUnit.getStorageDirectory() != null ? actualStorageUnit.getStorageDirectory().getDirectoryPath() : null); AbstractServiceTest.assertEqualsIgnoreOrder("storage files", expectedStorageFiles, actualStorageUnit.getStorageFiles());
StorageUnit expectedStorageUnit = new StorageUnit(); expectedStorageUnit .setStorage(new Storage(STORAGE_NAME, StoragePlatformEntity.RELATIONAL, relationalTableRegistrationServiceTestHelper.getStorageAttributes())); expectedStorageUnit.setStorageUnitStatus(StorageUnitStatusEntity.ENABLED);
@Test public void getStorageUnitByStorageName() { // Create business object data with several test storage units. BusinessObjectData businessObjectData = new BusinessObjectData(); List<String> testStorageNames = Arrays.asList("Storage_1", "storage-2", "STORAGE3"); List<StorageUnit> storageUnits = new ArrayList<>(); businessObjectData.setStorageUnits(storageUnits); for (String testStorageName : testStorageNames) { StorageUnit storageUnit = new StorageUnit(); storageUnits.add(storageUnit); Storage storage = new Storage(); storageUnit.setStorage(storage); storage.setName(testStorageName); } // Validate that we can find all storage units regardless of the storage name case. for (String testStorageName : testStorageNames) { assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName).getStorage().getName()); assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName.toUpperCase()).getStorage().getName()); assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName.toLowerCase()).getStorage().getName()); } }
/** * Validate downloaded S3 files per storage unit information. * * @param baseDirectory the local parent directory path, relative to which the files are expected to be located * @param s3KeyPrefix the S3 key prefix that was prepended to the S3 file paths, when they were uploaded to S3 * @param storageUnit the storage unit that contains a list of storage files to be validated * * @throws IllegalStateException if files are not valid */ public void validateDownloadedS3Files(String baseDirectory, String s3KeyPrefix, StorageUnit storageUnit) throws IllegalStateException { validateDownloadedS3Files(baseDirectory, s3KeyPrefix, storageUnit.getStorageFiles()); }
/** * Trigger business object data and storage unit notification for business object data creation event. * * @param businessObjectData the business object data */ public void triggerNotificationsForCreateBusinessObjectData(BusinessObjectData businessObjectData) { BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData); // Create business object data notifications. for (NotificationEventTypeEntity.EventTypesBdata eventType : Arrays .asList(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG)) { notificationEventService.processBusinessObjectDataNotificationEventAsync(eventType, businessObjectDataKey, businessObjectData.getStatus(), null); } // Create storage unit notifications. for (StorageUnit storageUnit : businessObjectData.getStorageUnits()) { notificationEventService .processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, storageUnit.getStorage().getName(), storageUnit.getStorageUnitStatus(), null); } }
/** * Builds a business object data create response. * * @param response the response. * @param uri the URI of the incoming request. * * @throws JAXBException if a JAXB error occurred. */ private void buildPostBusinessObjectDataResponse(MockCloseableHttpResponse response, URI uri) throws JAXBException { BusinessObjectData businessObjectData = new BusinessObjectData(); List<StorageUnit> storageUnits = new ArrayList<>(); businessObjectData.setStorageUnits(storageUnits); StorageUnit storageUnit = new StorageUnit(); storageUnit.setStorageDirectory(new StorageDirectory("app-a/exchange-a/prc/txt/new-orders/frmt-v0/data-v0/process-date=2014-01-31")); storageUnits.add(storageUnit); response.setEntity(getHttpEntity(businessObjectData)); }
/** * Gets a storage unit by storage name (case insensitive). * * @param businessObjectData the business object data * @param storageName the storage name * * @return the storage unit * @throws IllegalStateException if business object data has no storage unit with the specified storage name */ public StorageUnit getStorageUnitByStorageName(BusinessObjectData businessObjectData, String storageName) throws IllegalStateException { StorageUnit resultStorageUnit = null; // Find a storage unit that belongs to the specified storage. for (StorageUnit storageUnit : businessObjectData.getStorageUnits()) { if (storageUnit.getStorage().getName().equalsIgnoreCase(storageName)) { resultStorageUnit = storageUnit; break; } } // Validate that we found a storage unit that belongs to the specified storage. if (resultStorageUnit == null) { throw new IllegalStateException(String.format("Business object data has no storage unit with storage name \"%s\".", storageName)); } return resultStorageUnit; }
String s3KeyPrefix = IterableUtils.get(businessObjectData.getStorageUnits(), 0).getStorageDirectory().getDirectoryPath();
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { theStorage = this.getStorage(); strategy.appendField(locator, this, "storage", buffer, theStorage, (this.storage!= null)); theStorageDirectory = this.getStorageDirectory(); strategy.appendField(locator, this, "storageDirectory", buffer, theStorageDirectory, (this.storageDirectory!= null)); theStorageFiles = ((this.storageFiles!= null)?this.getStorageFiles():null); strategy.appendField(locator, this, "storageFiles", buffer, theStorageFiles, (this.storageFiles!= null)); theStorageUnitStatus = this.getStorageUnitStatus(); strategy.appendField(locator, this, "storageUnitStatus", buffer, theStorageUnitStatus, (this.storageUnitStatus!= null)); theStorageUnitStatusHistory = ((this.storageUnitStatusHistory!= null)?this.getStorageUnitStatusHistory():null); strategy.appendField(locator, this, "storageUnitStatusHistory", buffer, theStorageUnitStatusHistory, (this.storageUnitStatusHistory!= null)); theStoragePolicyTransitionFailedAttempts = this.getStoragePolicyTransitionFailedAttempts(); strategy.appendField(locator, this, "storagePolicyTransitionFailedAttempts", buffer, theStoragePolicyTransitionFailedAttempts, (this.storagePolicyTransitionFailedAttempts!= null)); theRestoreExpirationOn = this.getRestoreExpirationOn(); strategy.appendField(locator, this, "restoreExpirationOn", buffer, theRestoreExpirationOn, (this.restoreExpirationOn!= null));
StorageUnit storageUnit = new StorageUnit(); storageUnits.add(storageUnit); storageUnit.setStorage(storage); storageUnit.setStorageDirectory(storageDirectory); storageDirectory.setDirectoryPath(storageUnitEntity.getDirectoryPath()); storageUnit.setStorageFiles(storageFiles); storageUnit.setStorageUnitStatus(storageUnitEntity.getStatus().getCode()); storageUnit.setStorageUnitStatusHistory(storageUnitStatusChangeEvents); for (StorageUnitStatusHistoryEntity storageUnitStatusHistoryEntity : storageUnitEntity.getHistoricalStatuses()) storageUnit.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts()); storageUnit.setRestoreExpirationOn(HerdDateUtils.getXMLGregorianCalendarValue(storageUnitEntity.getRestoreExpirationOn()));
businessObjectData.setStorageUnits(storageUnits); StorageUnit storageUnit = new StorageUnit(); storageUnits.add(storageUnit); storageUnit.setStorage(getNewStorage(StorageEntity.MANAGED_STORAGE)); storageUnit.setStorageFiles(storageFiles); storageUnit.setStorageUnitStatus(StorageUnitStatusEntity.ENABLED);
assertEquals(expectedStorageName, storageUnit.getStorage().getName()); String expectedStorageDirectoryPath = String.format("%s/%s/%s", AbstractServiceTest.ENVIRONMENT_NAME.trim().toLowerCase().replace('_', '-'), expectedNamespaceCode.trim().toLowerCase().replace('_', '-'), businessObjectData.getPartitionValue()); assertEquals(expectedStorageDirectoryPath, storageUnit.getStorageDirectory().getDirectoryPath()); assertEquals(1, storageUnit.getStorageFiles().size()); StorageFile storageFile = storageUnit.getStorageFiles().get(0); String expectedStorageFilePath = String.format("%s/%s", expectedStorageDirectoryPath, expectedFileName); assertEquals(expectedStorageFilePath, storageFile.getFilePath());
StorageUnit expectedStorageUnit = new StorageUnit(); expectedStorageUnit .setStorage(new Storage(STORAGE_NAME, StoragePlatformEntity.RELATIONAL, relationalTableRegistrationServiceTestHelper.getStorageAttributes())); expectedStorageUnit.setStorageUnitStatus(StorageUnitStatusEntity.ENABLED);
if (!CollectionUtils.isEmpty(storageUnit.getStorageFiles())) for (StorageFile storageFile : storageUnit.getStorageFiles()) String.format("Registered file \"%s\" does not exist in \"%s\" storage.", registeredS3Files.get(0), storageUnit.getStorage().getName())); throw new IllegalStateException(String .format("Found S3 file \"%s\" in \"%s\" storage not registered with this business object data.", actualS3Files.get(0), storageUnit.getStorage().getName()));