/** * 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 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; }
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; }
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; }
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; }
@Test public void testValidateStorageUnitS3FilesNotRegisteredS3FileFound() throws IOException { StorageUnit storageUnit = createStorageUnit(TEST_S3_KEY_PREFIX, new ArrayList<>(), FILE_SIZE_1_KB); List<String> actualS3Files = Collections.singletonList(String.format("%s/%s", TEST_S3_KEY_PREFIX, LOCAL_FILES.get(0))); // Try to validate S3 files when we have not registered S3 file. try { storageFileHelper.validateStorageUnitS3Files(storageUnit, actualS3Files, TEST_S3_KEY_PREFIX); fail("Should throw a RuntimeException when S3 contains unregistered S3 file."); } catch (RuntimeException e) { String expectedErrMsg = String.format("Found S3 file \"%s\" in \"%s\" storage not registered with this business object data.", actualS3Files.get(0), storageUnit.getStorage().getName()); assertEquals(expectedErrMsg, e.getMessage()); } }
/** * 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); } }
/** * 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); } }
@Test public void testDeleteStorage() { // Create and persist a valid storage. Storage storage = storageService.createStorage(getNewStorageCreateRequest()); // Delete the storage. Storage result = storageService.deleteStorage(new StorageKey(storage.getName())); assertEquals(storage, result); // Retrieve the storage by its name and verify that it doesn't exist. assertNull(storageDao.getStorageByName(storage.getName())); }
@Test public void testValidateStorageUnitS3FilesRegisteredFileNoExists() throws IOException { StorageUnit storageUnit = createStorageUnit(TEST_S3_KEY_PREFIX, LOCAL_FILES, FILE_SIZE_1_KB); List<String> actualS3Files = new ArrayList<>(); // Try to validate S3 files when actual S3 files do not exist. try { storageFileHelper.validateStorageUnitS3Files(storageUnit, actualS3Files, TEST_S3_KEY_PREFIX); fail("Should throw a RuntimeException when actual S3 files do not exist."); } catch (RuntimeException e) { String expectedErrMsg = String .format("Registered file \"%s\" does not exist in \"%s\" storage.", storageUnit.getStorageFiles().get(0).getFilePath(), storageUnit.getStorage().getName()); assertEquals(expectedErrMsg, e.getMessage()); } }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theName; theName = this.getName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "name", theName), currentHashCode, theName, (this.name!= null)); } { String theStoragePlatformName; theStoragePlatformName = this.getStoragePlatformName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "storagePlatformName", theStoragePlatformName), currentHashCode, theStoragePlatformName, (this.storagePlatformName!= null)); } { List<Attribute> theAttributes; theAttributes = ((this.attributes!= null)?this.getAttributes():null); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "attributes", theAttributes), currentHashCode, theAttributes, (this.attributes!= null)); } return currentHashCode; }
@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); }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theName; theName = this.getName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "name", theName), currentHashCode, theName, (this.name!= null)); } { String theStoragePlatformName; theStoragePlatformName = this.getStoragePlatformName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "storagePlatformName", theStoragePlatformName), currentHashCode, theStoragePlatformName, (this.storagePlatformName!= null)); } { List<Attribute> theAttributes; theAttributes = ((this.attributes!= null)?this.getAttributes():null); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "attributes", theAttributes), currentHashCode, theAttributes, (this.attributes!= null)); } return currentHashCode; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theName; theName = this.getName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "name", theName), currentHashCode, theName, (this.name!= null)); } { String theStoragePlatformName; theStoragePlatformName = this.getStoragePlatformName(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "storagePlatformName", theStoragePlatformName), currentHashCode, theStoragePlatformName, (this.storagePlatformName!= null)); } { List<Attribute> theAttributes; theAttributes = ((this.attributes!= null)?this.getAttributes():null); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "attributes", theAttributes), currentHashCode, theAttributes, (this.attributes!= null)); } return currentHashCode; }
@Test public void testUpdateStorageAttributesStorageHasDuplicateAttributes() { // Create and persist a valid storage. StorageCreateRequest request = getNewStorageCreateRequest(); Storage storage = storageService.createStorage(request); // Add a duplicate attribute to the storage. StorageEntity storageEntity = storageDao.getStorageByName(storage.getName()); StorageAttributeEntity storageAttributeEntity = new StorageAttributeEntity(); storageAttributeEntity.setStorage(storageEntity); storageAttributeEntity.setName(request.getAttributes().get(0).getName().toUpperCase()); storageEntity.getAttributes().add(storageAttributeEntity); storageDao.saveAndRefresh(storageEntity); // Try to update attributes for the storage. try { storageService.updateStorageAttributes(new StorageKey(storage.getName()), new StorageAttributesUpdateRequest(businessObjectDefinitionServiceTestHelper.getNewAttributes2())); } catch (IllegalStateException e) { assertEquals(String.format("Found duplicate attribute with name \"%s\" for \"%s\" storage.", request.getAttributes().get(0).getName().toLowerCase(), storage.getName()), e.getMessage()); } }
@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); }
/** * Calls getStorage() method and makes assertions. * * @param useSsl specifies whether to use SSL or not * * @throws JAXBException if a JAXB error was encountered * @throws IOException if an I/O error was encountered * @throws URISyntaxException if a URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */ private void testGetStorage(boolean useSsl) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(useSsl); String expectedStorageName = "testStorage"; Storage storage = dataBridgeWebClient.getStorage(expectedStorageName); assertNotNull("storage is null", storage); assertEquals("storage name", expectedStorageName, storage.getName()); }
@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); }
@Test public void testGetStorage() { // Create and persist a valid storage. Storage storage = storageService.createStorage(getNewStorageCreateRequest()); // Retrieve the storage by its name. Storage result = storageService.getStorage(new StorageKey(storage.getName())); // Validate the results. assertEquals(storage, result); }
/** * Validates actualBusinessObjectData contents against specified arguments and expected (hard coded) test values. * * @param expectedDataVersion the expected business object data version * @param expectedAttributes the expected attributes * @param expectedParents the expected business object data parents * @param actualBusinessObjectData the BusinessObjectData object instance to be validated */ protected void assertBusinessObjectData(Integer expectedDataVersion, List<Attribute> expectedAttributes, List<BusinessObjectDataKey> expectedParents, BusinessObjectData actualBusinessObjectData) { assertNotNull(actualBusinessObjectData); assertEquals(TEST_BUSINESS_OBJECT_DEFINITION, actualBusinessObjectData.getBusinessObjectDefinitionName()); assertEquals(TEST_BUSINESS_OBJECT_FORMAT_USAGE, actualBusinessObjectData.getBusinessObjectFormatUsage()); assertEquals(TEST_BUSINESS_OBJECT_FORMAT_FILE_TYPE, actualBusinessObjectData.getBusinessObjectFormatFileType()); assertEquals(TEST_BUSINESS_OBJECT_FORMAT_VERSION.intValue(), actualBusinessObjectData.getBusinessObjectFormatVersion()); assertEquals(TEST_BUSINESS_OBJECT_FORMAT_PARTITION_KEY, actualBusinessObjectData.getPartitionKey()); assertEquals(TEST_PARTITION_VALUE, actualBusinessObjectData.getPartitionValue()); assertEquals(expectedDataVersion.intValue(), actualBusinessObjectData.getVersion()); assertEquals(1, actualBusinessObjectData.getStorageUnits().size()); assertEquals(StorageEntity.MANAGED_STORAGE, actualBusinessObjectData.getStorageUnits().get(0).getStorage().getName()); assertEquals(testManifestFiles.size(), actualBusinessObjectData.getStorageUnits().get(0).getStorageFiles().size()); assertEquals(expectedAttributes, actualBusinessObjectData.getAttributes()); assertEquals(expectedParents, actualBusinessObjectData.getBusinessObjectDataParents()); }