class StorageHelper {

    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;
    }

}