/** * Validates the attributes. * * @param attributes the attributes to validate. Null shouldn't be specified. * @return the validated attribute map * @throws IllegalArgumentException if any invalid attributes were found. */ public Map<String, String> validateAttributes(List<Attribute> attributes) throws IllegalArgumentException { // Validate attributes if they are specified. Map<String, String> attributeNameValidationMap = new HashMap<>(); if (!CollectionUtils.isEmpty(attributes)) { for (Attribute attribute : attributes) { attribute.setName(alternateKeyHelper.validateStringParameter("An", "attribute name", attribute.getName())); // Ensure the attribute key isn't a duplicate by using a map with a "lowercase" name as the key for case insensitivity. String validationMapKey = attribute.getName().toLowerCase(); if (attributeNameValidationMap.containsKey(validationMapKey)) { throw new IllegalArgumentException("Duplicate attribute name found: " + attribute.getName()); } attributeNameValidationMap.put(validationMapKey, attribute.getValue()); } } return attributeNameValidationMap; }
/** * Validates the attributes. * * @param attributes the attributes to validate. Null shouldn't be specified. * @return the validated attribute map * @throws IllegalArgumentException if any invalid attributes were found. */ public Map<String, String> validateAttributes(List<Attribute> attributes) throws IllegalArgumentException { // Validate attributes if they are specified. Map<String, String> attributeNameValidationMap = new HashMap<>(); if (!CollectionUtils.isEmpty(attributes)) { for (Attribute attribute : attributes) { attribute.setName(alternateKeyHelper.validateStringParameter("An", "attribute name", attribute.getName())); // Ensure the attribute key isn't a duplicate by using a map with a "lowercase" name as the key for case insensitivity. String validationMapKey = attribute.getName().toLowerCase(); if (attributeNameValidationMap.containsKey(validationMapKey)) { throw new IllegalArgumentException("Duplicate attribute name found: " + attribute.getName()); } attributeNameValidationMap.put(validationMapKey, attribute.getValue()); } } return attributeNameValidationMap; }
attributeMap.put(attribute.getName().toLowerCase(), attribute.getValue());
/** * 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 theValue; theValue = this.getValue(); strategy.appendField(locator, this, "value", buffer, theValue, (this.value!= 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 theValue; theValue = this.getValue(); strategy.appendField(locator, this, "value", buffer, theValue, (this.value!= 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 theValue; theValue = this.getValue(); strategy.appendField(locator, this, "value", buffer, theValue, (this.value!= null)); } return buffer; }
public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) { if ((object == null)||(this.getClass()!= object.getClass())) { return false; } if (this == object) { return true; } final Attribute that = ((Attribute) object); { String lhsName; lhsName = this.getName(); String rhsName; rhsName = that.getName(); if (!strategy.equals(LocatorUtils.property(thisLocator, "name", lhsName), LocatorUtils.property(thatLocator, "name", rhsName), lhsName, rhsName, (this.name!= null), (that.name!= null))) { return false; } } { String lhsValue; lhsValue = this.getValue(); String rhsValue; rhsValue = that.getValue(); if (!strategy.equals(LocatorUtils.property(thisLocator, "value", lhsValue), LocatorUtils.property(thatLocator, "value", rhsValue), lhsValue, rhsValue, (this.value!= null), (that.value!= null))) { return false; } } return true; }
public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) { if ((object == null)||(this.getClass()!= object.getClass())) { return false; } if (this == object) { return true; } final Attribute that = ((Attribute) object); { String lhsName; lhsName = this.getName(); String rhsName; rhsName = that.getName(); if (!strategy.equals(LocatorUtils.property(thisLocator, "name", lhsName), LocatorUtils.property(thatLocator, "name", rhsName), lhsName, rhsName, (this.name!= null), (that.name!= null))) { return false; } } { String lhsValue; lhsValue = this.getValue(); String rhsValue; rhsValue = that.getValue(); if (!strategy.equals(LocatorUtils.property(thisLocator, "value", lhsValue), LocatorUtils.property(thatLocator, "value", rhsValue), lhsValue, rhsValue, (this.value!= null), (that.value!= null))) { return false; } } return true; }
public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) { if ((object == null)||(this.getClass()!= object.getClass())) { return false; } if (this == object) { return true; } final Attribute that = ((Attribute) object); { String lhsName; lhsName = this.getName(); String rhsName; rhsName = that.getName(); if (!strategy.equals(LocatorUtils.property(thisLocator, "name", lhsName), LocatorUtils.property(thatLocator, "name", rhsName), lhsName, rhsName, (this.name!= null), (that.name!= null))) { return false; } } { String lhsValue; lhsValue = this.getValue(); String rhsValue; rhsValue = that.getValue(); if (!strategy.equals(LocatorUtils.property(thisLocator, "value", lhsValue), LocatorUtils.property(thatLocator, "value", rhsValue), lhsValue, rhsValue, (this.value!= null), (that.value!= null))) { return false; } } return true; }
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 theValue; theValue = this.getValue(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "value", theValue), currentHashCode, theValue, (this.value!= null)); } return currentHashCode; }
/** * Validates a list of Attributes against the expected values. * * @param expectedAttributes the list of expected Attributes * @param actualAttributes the list of actual Attributes to be validated */ public void validateAttributes(List<Attribute> expectedAttributes, List<Attribute> actualAttributes) { assertEquals(expectedAttributes.size(), actualAttributes.size()); for (int i = 0; i < expectedAttributes.size(); i++) { Attribute expectedAttribute = expectedAttributes.get(i); Attribute actualAttribute = actualAttributes.get(i); assertEquals(expectedAttribute.getName(), actualAttribute.getName()); assertEquals(expectedAttribute.getValue(), actualAttribute.getValue()); } } }
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 theValue; theValue = this.getValue(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "value", theValue), currentHashCode, theValue, (this.value!= 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 theValue; theValue = this.getValue(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "value", theValue), currentHashCode, theValue, (this.value!= null)); } return currentHashCode; }
attributeEntities.add(attributeEntity); attributeEntity.setStorage(storageEntity); attributeEntity.setName(attribute.getName()); attributeEntity.setValue(attribute.getValue());
@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()); } }
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);
/** * Creates and persists a new storage entity. * * @param storageName the storage name * @param storagePlatformEntity the storage platform entity * * @return the newly created storage entity. */ public StorageEntity createStorageEntity(String storageName, StoragePlatformEntity storagePlatformEntity, List<Attribute> attributes) { StorageEntity storageEntity = new StorageEntity(); storageEntity.setName(storageName); storageEntity.setStoragePlatform(storagePlatformEntity); // Create the attributes if they are specified. if (!CollectionUtils.isEmpty(attributes)) { List<StorageAttributeEntity> attributeEntities = new ArrayList<>(); storageEntity.setAttributes(attributeEntities); for (Attribute attribute : attributes) { StorageAttributeEntity attributeEntity = new StorageAttributeEntity(); attributeEntities.add(attributeEntity); attributeEntity.setStorage(storageEntity); attributeEntity.setName(attribute.getName()); attributeEntity.setValue(attribute.getValue()); } } return storageDao.saveAndRefresh(storageEntity); }
for (Attribute attribute : getTestAttributes()) attributes.put(attribute.getName(), attribute.getValue());