public Object getValue(String attributeCode, Long marketAreaId, String localizationCode) { ProductMarketingAttribute productMarketingAttribute = getProductMarketingAttribute(attributeCode, marketAreaId, localizationCode); if (productMarketingAttribute != null) { return productMarketingAttribute.getValue(); } return null; }
private ProductMarketingAttribute getProductMarketingAttribute( Set<ProductMarketingAttribute> productMarketingAttributes, String attributeCode, Long marketAreaId, String localizationCode) { ProductMarketingAttribute productMarketingAttributeToReturn = null; List<ProductMarketingAttribute> productMarketingAttributesFilter = new ArrayList<ProductMarketingAttribute>(); if (productMarketingAttributes != null) { // GET ALL CategoryAttributes FOR THIS ATTRIBUTE for (Iterator<ProductMarketingAttribute> iterator = productMarketingAttributes.iterator(); iterator.hasNext(); ) { ProductMarketingAttribute productMarketingAttribute = (ProductMarketingAttribute) iterator.next(); AttributeDefinition attributeDefinition = productMarketingAttribute.getAttributeDefinition(); if (attributeDefinition != null && attributeDefinition.getCode().equalsIgnoreCase(attributeCode)) { productMarketingAttributesFilter.add(productMarketingAttribute); } } // REMOVE ALL CategoryAttributes NOT ON THIS MARKET AREA if (marketAreaId != null) { for (Iterator<ProductMarketingAttribute> iterator = productMarketingAttributesFilter.iterator(); iterator.hasNext(); ) { ProductMarketingAttribute productMarketingAttribute = (ProductMarketingAttribute) iterator.next(); AttributeDefinition attributeDefinition = productMarketingAttribute.getAttributeDefinition(); if (BooleanUtils.negate(attributeDefinition.isGlobal())) { if (productMarketingAttribute.getMarketAreaId() != null && BooleanUtils.negate( productMarketingAttribute.getMarketAreaId().equals(marketAreaId))) { iterator.remove(); } } } } // FINALLY RETAIN ONLY CategoryAttributes FOR THIS LOCALIZATION CODE if (StringUtils.isNotEmpty(localizationCode)) { for (Iterator<ProductMarketingAttribute> iterator = productMarketingAttributesFilter.iterator(); iterator.hasNext(); ) { ProductMarketingAttribute productMarketingAttribute = (ProductMarketingAttribute) iterator.next(); String attributeLocalizationCode = productMarketingAttribute.getLocalizationCode(); if (StringUtils.isNotEmpty(attributeLocalizationCode) && BooleanUtils.negate(attributeLocalizationCode.equals(localizationCode))) { iterator.remove(); } } if (productMarketingAttributesFilter.size() == 0) { // TODO : warning ? // NOT ANY CategoryAttributes FOR THIS LOCALIZATION CODE - GET A FALLBACK for (Iterator<ProductMarketingAttribute> iterator = productMarketingAttributes.iterator(); iterator.hasNext(); ) { ProductMarketingAttribute productMarketingAttribute = (ProductMarketingAttribute) iterator.next(); // TODO : get a default locale code from setting database ? if (Constants.DEFAULT_LOCALE_CODE.equals( productMarketingAttribute.getLocalizationCode())) { productMarketingAttributeToReturn = productMarketingAttribute; } } } } } if (productMarketingAttributesFilter.size() == 1) { productMarketingAttributeToReturn = productMarketingAttributesFilter.get(0); } else { // TODO : throw error ? } return productMarketingAttributeToReturn; }