public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) { final Object draftCopy = ((target == null)?createNewInstance():target); if (draftCopy instanceof Storage) { final Storage copy = ((Storage) draftCopy); if (nameShouldBeCopiedAndSet == Boolean.TRUE) { String sourceName; sourceName = this.getName(); String copyName = ((String) strategy.copy(LocatorUtils.property(locator, "name", sourceName), sourceName, (this.name!= null))); copy.setName(copyName); } else { if (nameShouldBeCopiedAndSet == Boolean.FALSE) { if (storagePlatformNameShouldBeCopiedAndSet == Boolean.TRUE) { String sourceStoragePlatformName; sourceStoragePlatformName = this.getStoragePlatformName(); String copyStoragePlatformName = ((String) strategy.copy(LocatorUtils.property(locator, "storagePlatformName", sourceStoragePlatformName), sourceStoragePlatformName, (this.storagePlatformName!= null))); copy.setStoragePlatformName(copyStoragePlatformName); } else { if (storagePlatformNameShouldBeCopiedAndSet == Boolean.FALSE) { if (attributesShouldBeCopiedAndSet == Boolean.TRUE) { List<Attribute> sourceAttributes; sourceAttributes = ((this.attributes!= null)?this.getAttributes():null); @SuppressWarnings("unchecked") List<Attribute> copyAttributes = ((List<Attribute> ) strategy.copy(LocatorUtils.property(locator, "attributes", sourceAttributes), sourceAttributes, (this.attributes!= null))); copy.attributes = null; if (copyAttributes!= null) { copy.setAttributes(copyAttributes);
/** * Create an instance of {@link Storage } * */ public Storage createStorage() { return new Storage(); }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theName; theName = this.getName(); strategy.appendField(locator, this, "name", buffer, theName, (this.name!= null)); } { String theStoragePlatformName; theStoragePlatformName = this.getStoragePlatformName(); strategy.appendField(locator, this, "storagePlatformName", buffer, theStoragePlatformName, (this.storagePlatformName!= null)); } { List<Attribute> theAttributes; theAttributes = ((this.attributes!= null)?this.getAttributes():null); strategy.appendField(locator, this, "attributes", buffer, theAttributes, (this.attributes!= null)); } return buffer; }
/** * Gets attribute value by name from the storage object instance. * * @param attributeName the attribute name (case insensitive) * @param storage the storage * @param required specifies whether the attribute value is mandatory * * @return the attribute value from the attribute with the attribute name, or {@code null} if this list contains no attribute with this attribute name */ public String getStorageAttributeValueByName(String attributeName, Storage storage, Boolean required) { String attributeValue = null; for (Attribute attribute : storage.getAttributes()) { if (attribute.getName().equalsIgnoreCase(attributeName)) { attributeValue = attribute.getValue(); break; } } if (required && StringUtils.isBlank(attributeValue)) { throw new IllegalStateException(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", attributeName, storage.getName())); } return attributeValue; }
/** * 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; }
/** * Gets a new storage object with the specified information. * * @param storageName the storage name. * * @return the newly created storage. */ private Storage getNewStorage(String storageName) { Storage storage = new Storage(); storage.setName(storageName); storage.setStoragePlatformName(StoragePlatformEntity.S3); List<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucket")); /* * Set the KMS key attribute if the storage name contains ignore case the word "KMS" (ex. S3_MANAGED_KMS) */ if (storageName.toLowerCase().contains("kms")) { attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), "testKmsKeyId")); } storage.setAttributes(attributes); return storage; }
@Test public void testUpdateStorage() { // Create a storage. Storage storage = storageService.createStorage(getNewStorageCreateRequest()); // Update the storage. // TODO: Update various attributes of the storage update request in the future when there is something to update. Storage result = storageService.updateStorage(new StorageKey(storage.getName()), new StorageUpdateRequest()); // Validate the results. // TODO: Add asserts to ensure fields that were update indeed got updated. assertEquals(new Storage(storage.getName(), storage.getStoragePlatformName(), storage.getAttributes()), result); }
@Test public void testGetStorageAttributeValueByNameFromStorage() { final String testStorageName = "MY_TEST_STORAGE"; final String testAttributeNameNoExists = "I_DO_NOT_EXIST"; Storage testStorage = new Storage(); testStorage.setName(testStorageName); testStorage.setAttributes(businessObjectDefinitionServiceTestHelper.getNewAttributes()); assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE, testStorage, Boolean.FALSE)); assertEquals(ATTRIBUTE_VALUE_2, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_2_MIXED_CASE, testStorage, Boolean.TRUE)); // Testing attribute name case insensitivity. assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), testStorage, Boolean.TRUE)); assertEquals(ATTRIBUTE_VALUE_1, storageHelper.getStorageAttributeValueByName(ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), testStorage, Boolean.TRUE)); assertNull(storageHelper.getStorageAttributeValueByName(testAttributeNameNoExists, testStorage, Boolean.FALSE)); // Try to get a required attribute value what does not exist. try { storageHelper.getStorageAttributeValueByName(testAttributeNameNoExists, testStorage, Boolean.TRUE); fail("Suppose to throw a RuntimeException when required storage attribute does not exist or has a blank value."); } catch (RuntimeException e) { assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", testAttributeNameNoExists, testStorage.getName()), e.getMessage()); } }
@Test public void testUpdateStorageAttributesRemoveAllAttributes() { // Create and persist a valid storage. StorageCreateRequest request = getNewStorageCreateRequest(); Storage storage = storageService.createStorage(request); // Update attributes for the storage. Storage result = storageService.updateStorageAttributes(new StorageKey(storage.getName()), new StorageAttributesUpdateRequest(NO_ATTRIBUTES)); // Validate the results. assertEquals(new Storage(storage.getName(), storage.getStoragePlatformName(), NO_ATTRIBUTES), result); }
@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()); } }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theName; theName = this.getName(); strategy.appendField(locator, this, "name", buffer, theName, (this.name!= null)); } { String theStoragePlatformName; theStoragePlatformName = this.getStoragePlatformName(); strategy.appendField(locator, this, "storagePlatformName", buffer, theStoragePlatformName, (this.storagePlatformName!= null)); } { List<Attribute> theAttributes; theAttributes = ((this.attributes!= null)?this.getAttributes():null); strategy.appendField(locator, this, "attributes", buffer, theAttributes, (this.attributes!= null)); } return buffer; }
/** * 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; }
storageUnits.add(storageUnit); Storage storage = new Storage(); storageUnit.setStorage(storage); storage.setName(storageEntity.getName()); storage.setStoragePlatformName(storageEntity.getStoragePlatform().getName()); storage.setAttributes(storageAttributes); for (StorageAttributeEntity storageAttributeEntity : storageEntity.getAttributes())
/** * Gets attribute value by name from the storage object instance. * * @param attributeName the attribute name (case insensitive) * @param storage the storage * @param required specifies whether the attribute value is mandatory * * @return the attribute value from the attribute with the attribute name, or {@code null} if this list contains no attribute with this attribute name */ public String getStorageAttributeValueByName(String attributeName, Storage storage, Boolean required) { String attributeValue = null; for (Attribute attribute : storage.getAttributes()) { if (attribute.getName().equalsIgnoreCase(attributeName)) { attributeValue = attribute.getValue(); break; } } if (required && StringUtils.isBlank(attributeValue)) { throw new IllegalStateException(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", attributeName, storage.getName())); } return attributeValue; }
@Test public void testUpdateStorageAttributes() { // Create and persist a valid storage. StorageCreateRequest request = getNewStorageCreateRequest(); Storage storage = storageService.createStorage(request); // Update attributes for the storage. Storage result = storageService.updateStorageAttributes(new StorageKey(storage.getName()), new StorageAttributesUpdateRequest(businessObjectDefinitionServiceTestHelper.getNewAttributes2())); // Validate the results. assertEquals(new Storage(storage.getName(), storage.getStoragePlatformName(), businessObjectDefinitionServiceTestHelper.getNewAttributes2()), result); }
public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) { final Object draftCopy = ((target == null)?createNewInstance():target); if (draftCopy instanceof Storage) { final Storage copy = ((Storage) draftCopy); if (nameShouldBeCopiedAndSet == Boolean.TRUE) { String sourceName; sourceName = this.getName(); String copyName = ((String) strategy.copy(LocatorUtils.property(locator, "name", sourceName), sourceName, (this.name!= null))); copy.setName(copyName); } else { if (nameShouldBeCopiedAndSet == Boolean.FALSE) { if (storagePlatformNameShouldBeCopiedAndSet == Boolean.TRUE) { String sourceStoragePlatformName; sourceStoragePlatformName = this.getStoragePlatformName(); String copyStoragePlatformName = ((String) strategy.copy(LocatorUtils.property(locator, "storagePlatformName", sourceStoragePlatformName), sourceStoragePlatformName, (this.storagePlatformName!= null))); copy.setStoragePlatformName(copyStoragePlatformName); } else { if (storagePlatformNameShouldBeCopiedAndSet == Boolean.FALSE) { if (attributesShouldBeCopiedAndSet == Boolean.TRUE) { List<Attribute> sourceAttributes; sourceAttributes = ((this.attributes!= null)?this.getAttributes():null); @SuppressWarnings("unchecked") List<Attribute> copyAttributes = ((List<Attribute> ) strategy.copy(LocatorUtils.property(locator, "attributes", sourceAttributes), sourceAttributes, (this.attributes!= null))); copy.attributes = null; if (copyAttributes!= null) { copy.setAttributes(copyAttributes);
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theName; theName = this.getName(); strategy.appendField(locator, this, "name", buffer, theName, (this.name!= null)); } { String theStoragePlatformName; theStoragePlatformName = this.getStoragePlatformName(); strategy.appendField(locator, this, "storagePlatformName", buffer, theStoragePlatformName, (this.storagePlatformName!= null)); } { List<Attribute> theAttributes; theAttributes = ((this.attributes!= null)?this.getAttributes():null); strategy.appendField(locator, this, "attributes", buffer, theAttributes, (this.attributes!= null)); } return buffer; }
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()));
/** * Create an instance of {@link Storage } * */ public Storage createStorage() { return new Storage(); }