Author: mbrohl
Date: Sat Dec 16 14:23:33 2017 New Revision: 1818416 URL: http://svn.apache.org/viewvc?rev=1818416&view=rev Log: Improved: General refactoring and code improvements, package org.apache.ofbiz.product.config. (OFBIZ-10069) Thanks Julian Leichert for reporting and providing the patches. Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigItemContentWrapper.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWorker.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigItemContentWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigItemContentWrapper.java?rev=1818416&r1=1818415&r2=1818416&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigItemContentWrapper.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigItemContentWrapper.java Sat Dec 16 14:23:33 2017 @@ -89,6 +89,7 @@ public class ProductConfigItemContentWra this.mimeTypeId = EntityUtilProperties.getPropertyValue("content", "defaultMimeType", "text/html; charset=utf-8", this.delegator); } + @Override public StringWrapper get(String confItemContentTypeId, String encoderType) { return StringUtil.makeStringWrapper(getProductConfigItemContentAsText(productConfigItem, confItemContentTypeId, locale, mimeTypeId, getDelegator(), getDispatcher(), encoderType)); } @@ -136,11 +137,7 @@ public class ProductConfigItemContentWra outString = encoder.sanitize(outString, null); configItemContentCache.put(cacheKey, outString); return outString; - } catch (GeneralException e) { - Debug.logError(e, "Error rendering ProdConfItemContent, inserting empty String", module); - String candidateOut = productConfigItem.getModelEntity().isField(candidateFieldName) ? productConfigItem.getString(candidateFieldName): ""; - return candidateOut == null? "" : encoder.sanitize(candidateOut, null); - } catch (IOException e) { + } catch (GeneralException | IOException e) { Debug.logError(e, "Error rendering ProdConfItemContent, inserting empty String", module); String candidateOut = productConfigItem.getModelEntity().isField(candidateFieldName) ? productConfigItem.getString(candidateFieldName): ""; return candidateOut == null? "" : encoder.sanitize(candidateOut, null); @@ -172,13 +169,13 @@ public class ProductConfigItemContentWra .queryFirst(); if (productConfigItemContent != null) { // when rendering the product config item content, always include the ProductConfigItem and ProdConfItemContent records that this comes from - Map<String, Object> inContext = new HashMap<String, Object>(); + Map<String, Object> inContext = new HashMap<>(); inContext.put("productConfigItem", productConfigItem); inContext.put("productConfigItemContent", productConfigItemContent); ContentWorker.renderContentAsText(dispatcher, productConfigItemContent.getString("contentId"), outWriter, inContext, locale, mimeTypeId, null, null, cache); return; } - + String candidateFieldName = ModelUtil.dbNameToVarName(confItemContentTypeId); ModelEntity productConfigItemModel = delegator.getModelEntity("ProductConfigItem"); if (productConfigItemModel.isField(candidateFieldName)) { Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWorker.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWorker.java?rev=1818416&r1=1818415&r2=1818416&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWorker.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWorker.java Sat Dec 16 14:23:33 2017 @@ -92,7 +92,7 @@ public final class ProductConfigWorker { Map<String, Object> combinedMap = UtilHttp.getCombinedMap(request); for (int k = 0; k < numOfQuestions; k++) { String[] opts = new String[0]; - Object o = combinedMap.get(Integer.toString(k));; + Object o = combinedMap.get(Integer.toString(k)); if (o instanceof String) { opts = new String[]{(String)o}; } else if(o instanceof List) { @@ -151,7 +151,7 @@ public final class ProductConfigWorker { if (ProductWorker.isVirtual((Delegator)request.getAttribute("delegator"), selectedProductId)) { if ("VV_FEATURETREE".equals(ProductWorker.getProductVirtualVariantMethod((Delegator)request.getAttribute("delegator"), selectedProductId))) { // get the selected features - List<String> selectedFeatures = new LinkedList<String>(); + List<String> selectedFeatures = new LinkedList<>(); Enumeration<String> paramNames = UtilGenerics.cast(request.getParameterNames()); while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); @@ -195,15 +195,17 @@ public final class ProductConfigWorker { * @param delegator the delegator */ public static void storeProductConfigWrapper(ProductConfigWrapper configWrapper, Delegator delegator) { - if (configWrapper == null || (!configWrapper.isCompleted())) return; + if (configWrapper == null || (!configWrapper.isCompleted())) { + return; + } String configId = null; List<ConfigItem> questions = configWrapper.getQuestions(); - List<GenericValue> configsToCheck = new LinkedList<GenericValue>(); + List<GenericValue> configsToCheck = new LinkedList<>(); int selectedOptionSize = 0; for (ConfigItem ci: questions) { String configItemId = null; Long sequenceNum = null; - List<ProductConfigWrapper.ConfigOption> selectedOptions = new LinkedList<ProductConfigWrapper.ConfigOption>(); + List<ProductConfigWrapper.ConfigOption> selectedOptions = new LinkedList<>(); List<ConfigOption> options = ci.getOptions(); if (ci.isStandard()) { selectedOptions.addAll(options); @@ -252,7 +254,7 @@ public final class ProductConfigWorker { for (ConfigItem ci: questions) { String configItemId = null; Long sequenceNum = null; - List<ProductConfigWrapper.ConfigOption> selectedOptions = new LinkedList<ProductConfigWrapper.ConfigOption>(); + List<ProductConfigWrapper.ConfigOption> selectedOptions = new LinkedList<>(); List<ConfigOption> options = ci.getOptions(); if (ci.isStandard()) { selectedOptions.addAll(options); @@ -321,7 +323,7 @@ public final class ProductConfigWorker { for (ConfigItem ci: questions) { String configItemId = null; Long sequenceNum = null; - List<ProductConfigWrapper.ConfigOption> selectedOptions = new LinkedList<ProductConfigWrapper.ConfigOption>(); + List<ProductConfigWrapper.ConfigOption> selectedOptions = new LinkedList<>(); List<ConfigOption> options = ci.getOptions(); if (ci.isStandard()) { selectedOptions.addAll(options); @@ -343,7 +345,7 @@ public final class ProductConfigWorker { sequenceNum = ci.getConfigItemAssoc().getLong("sequenceNum"); for (ConfigOption oneOption: selectedOptions) { Map<String, String> componentOptions = oneOption.componentOptions; - List<GenericValue> toBeStored = new LinkedList<GenericValue>(); + List<GenericValue> toBeStored = new LinkedList<>(); String configOptionId = oneOption.configOption.getString("configOptionId"); String description = oneOption.getComments(); GenericValue productConfigConfig = delegator.makeValue("ProductConfigConfig"); Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java?rev=1818416&r1=1818415&r2=1818416&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java Sat Dec 16 14:23:33 2017 @@ -78,7 +78,7 @@ public class ProductConfigWrapper implem listPrice = pcw.listPrice; basePrice = pcw.basePrice; defaultPrice = pcw.defaultPrice; - questions = new LinkedList<ProductConfigWrapper.ConfigItem>(); + questions = new LinkedList<>(); delegator = pcw.getDelegator(); delegatorName = delegator.getDelegatorName(); dispatcher = pcw.getDispatcher(); @@ -120,10 +120,10 @@ public class ProductConfigWrapper implem if (price != null) { basePrice = price; } - questions = new LinkedList<ProductConfigWrapper.ConfigItem>(); + questions = new LinkedList<>(); if ("AGGREGATED".equals(product.getString("productTypeId")) || "AGGREGATED_SERVICE".equals(product.getString("productTypeId"))) { List<GenericValue> questionsValues = EntityQuery.use(delegator).from("ProductConfig").where("productId", productId).orderBy("sequenceNum").filterByDate().queryList(); - Set<String> itemIds = new HashSet<String>(); + Set<String> itemIds = new HashSet<>(); for (GenericValue questionsValue: questionsValues) { ConfigItem oneQuestion = new ConfigItem(questionsValue); oneQuestion.setContent(locale, "text/html"); // TODO: mime-type shouldn't be hardcoded @@ -293,7 +293,7 @@ public class ProductConfigWrapper implem GenericValue oneComponent = components.get(component); if (theOption.isVirtualComponent(oneComponent)) { if (theOption.componentOptions == null) { - theOption.componentOptions = new HashMap<String, String>(); + theOption.componentOptions = new HashMap<>(); } theOption.componentOptions.put(oneComponent.getString("productId"), componentOption); @@ -303,7 +303,7 @@ public class ProductConfigWrapper implem } public List<ConfigOption> getSelectedOptions() { - List<ConfigOption> selectedOptions = new LinkedList<ProductConfigWrapper.ConfigOption>(); + List<ConfigOption> selectedOptions = new LinkedList<>(); for (ConfigItem ci: questions) { if (ci.isStandard()) { selectedOptions.addAll(ci.getOptions()); @@ -319,7 +319,7 @@ public class ProductConfigWrapper implem } public List<ConfigOption> getDefaultOptions() { - List<ConfigOption> defaultOptions = new LinkedList<ProductConfigWrapper.ConfigOption>(); + List<ConfigOption> defaultOptions = new LinkedList<>(); for (ConfigItem ci: questions) { ConfigOption co = ci.getDefault(); if (co != null) { @@ -369,9 +369,8 @@ public class ProductConfigWrapper implem if (oneOption.isSelected()) { completed = true; break; - } else { - completed = false; } + completed = false; } if (!completed) { break; @@ -404,13 +403,13 @@ public class ProductConfigWrapper implem public ConfigItem(GenericValue questionAssoc) throws Exception { configItemAssoc = questionAssoc; configItem = configItemAssoc.getRelatedOne("ConfigItemProductConfigItem", false); - options = new LinkedList<ProductConfigWrapper.ConfigOption>(); + options = new LinkedList<>(); } public ConfigItem(ConfigItem ci) { configItem = GenericValue.create(ci.configItem); configItemAssoc = GenericValue.create(ci.configItemAssoc); - options = new LinkedList<ProductConfigWrapper.ConfigOption>(); + options = new LinkedList<>(); for (ConfigOption co: ci.options) { options.add(new ConfigOption(co)); } @@ -491,7 +490,9 @@ public class ProductConfigWrapper implem } public boolean isSelected() { - if (isStandard()) return true; + if (isStandard()) { + return true; + } for (ConfigOption oneOption: getOptions()) { if (oneOption.isSelected()) { return true; @@ -609,7 +610,7 @@ public class ProductConfigWrapper implem public ConfigOption(ConfigOption co) { configOption = GenericValue.create(co.configOption); - componentList = new LinkedList<GenericValue>(); + componentList = new LinkedList<>(); for (GenericValue component: co.componentList) { componentList.add(GenericValue.create(component)); } @@ -677,7 +678,7 @@ public class ProductConfigWrapper implem } public String getOptionName(Locale locale) { - + return (configOption.getString("configOptionName") != null? (String) configOption.get("configOptionName", locale): "no option name"); } @@ -713,18 +714,18 @@ public class ProductConfigWrapper implem ConfigOption defaultConfigOption = parentConfigItem.getDefault(); if (parentConfigItem.isSingleChoice() && UtilValidate.isNotEmpty(defaultConfigOption)) { return optionListPrice.subtract(defaultConfigOption.getListPrice()); - } else { // can select multiple or no default; show full price - return optionListPrice; } + // can select multiple or no default; show full price + return optionListPrice; } public BigDecimal getOffsetPrice() { ConfigOption defaultConfigOption = parentConfigItem.getDefault(); if (parentConfigItem.isSingleChoice() && UtilValidate.isNotEmpty(defaultConfigOption)) { return optionPrice.subtract(defaultConfigOption.getPrice()); - } else { // can select multiple or no default; show full price - return optionPrice; } + // can select multiple or no default; show full price + return optionPrice; } public boolean isDefault() { @@ -796,7 +797,7 @@ public class ProductConfigWrapper implem return result; } - + @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof ConfigOption)) { |
Free forum by Nabble | Edit this page |