This is an automated email from the ASF dual-hosted git repository.
mridulpathak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new e24de029eb Remove this-escape warnings in shopping cart, shipping
estimate, survey and production run classes
e24de029eb is described below
commit e24de029ebdcd0f1b10e34bbec2d0520ec7e3f0a
Author: Mridul Pathak <[email protected]>
AuthorDate: Tue Oct 27 15:30:15 2026 +0530
Remove this-escape warnings in shopping cart, shipping estimate, survey and
production run classes
- ShoppingCartItem constructors assign fields directly and use private
static helpers to look up the parent product and build the additional feature
adjustments, which are still computed at quantity 0 as before.
- WebShoppingCart passes the session user logins and order party to a new
protected ShoppingCart constructor instead of calling the setters.
- ShippingEstimateWrapper runs its protected load methods once, on first
use, instead of from the constructor.
- SurveyWrapper and ProductStoreSurveyWrapper chain to the full constructor
with values computed beforehand; the pass-thru map is sanitized on a copy.
- ProductionRun loads its header in a private static helper, and the header
and dispatcher fields are final.
---
.../apache/ofbiz/content/survey/SurveyWrapper.java | 20 ++++--
.../manufacturing/jobshopmgt/ProductionRun.java | 46 ++++++++-----
.../ofbiz/order/shoppingcart/ShoppingCart.java | 11 +++
.../ofbiz/order/shoppingcart/ShoppingCartItem.java | 78 ++++++++++++++--------
.../ofbiz/order/shoppingcart/WebShoppingCart.java | 10 +--
.../shipping/ShippingEstimateWrapper.java | 24 ++++++-
.../product/store/ProductStoreSurveyWrapper.java | 49 ++++++++------
7 files changed, 158 insertions(+), 80 deletions(-)
diff --git
a/applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java
b/applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java
index 565b69827a..754cf211a2 100644
---
a/applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java
+++
b/applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java
@@ -103,9 +103,9 @@ public class SurveyWrapper {
this.responseId = responseId;
this.partyId = partyId;
this.surveyId = surveyId;
- this.setPassThru(passThru);
- this.setDefaultValues(defaultValues);
- this.checkParameters();
+ this.passThru = copyOf(passThru);
+ this.defaultValues = copyOf(defaultValues);
+ checkParameters(delegator, surveyId);
}
public SurveyWrapper(Delegator delegator, String responseId, String
partyId, String surveyId, Map<String, Object> passThru) {
@@ -120,19 +120,26 @@ public class SurveyWrapper {
* Check parameters.
*/
protected void checkParameters() {
+ checkParameters(delegator, surveyId);
+ }
+
+ private static void checkParameters(Delegator delegator, String surveyId) {
if (delegator == null || surveyId == null) {
throw new IllegalArgumentException("Missing one or more required
parameters (delegator, surveyId)");
}
}
+ private static Map<String, Object> copyOf(Map<String, Object> values) {
+ return values != null ? new HashMap<>(values) : null;
+ }
+
/**
* Sets the pass-thru values (hidden form fields)
* @param passThru
*/
public void setPassThru(Map<String, Object> passThru) {
if (passThru != null) {
- this.passThru = new HashMap<>();
- this.passThru.putAll(passThru);
+ this.passThru = copyOf(passThru);
}
}
@@ -142,8 +149,7 @@ public class SurveyWrapper {
*/
public void setDefaultValues(Map<String, Object> defaultValues) {
if (defaultValues != null) {
- this.defaultValues = new HashMap<>();
- this.defaultValues.putAll(defaultValues);
+ this.defaultValues = copyOf(defaultValues);
}
}
diff --git
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRun.java
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRun.java
index 57dbe20a7f..d54df837fc 100644
---
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRun.java
+++
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/jobshopmgt/ProductionRun.java
@@ -49,7 +49,7 @@ public class ProductionRun {
private static final String MODULE = ProductionRun.class.getName();
private static final String RESOURCE = "ManufacturingUiLabels";
- private GenericValue productionRun; // WorkEffort (PROD_ORDER_HEADER)
+ private final GenericValue productionRun; // WorkEffort (PROD_ORDER_HEADER)
private GenericValue productionRunProduct; // WorkEffortGoodStandard
(type: PRUN_PROD_DELIV)
private GenericValue productProduced; // Product (from
WorkEffortGoodStandard of type: PRUN_PROD_DELIV)
private BigDecimal quantity; // the estimatedQuantity
@@ -61,7 +61,7 @@ public class ProductionRun {
private GenericValue currentStatus;
private List<GenericValue> productionRunComponents;
private List<GenericValue> productionRunRoutingTasks;
- private LocalDispatcher dispatcher;
+ private final LocalDispatcher dispatcher;
/**
* indicate if quantity or estimatedStartDate has been modified and
@@ -74,27 +74,37 @@ public class ProductionRun {
private boolean quantityIsUpdated = false;
public ProductionRun(String productionRunId, Delegator delegator,
LocalDispatcher dispatcher) {
+ this.dispatcher = UtilValidate.isEmpty(productionRunId) ? null :
dispatcher;
+ this.productionRun = findProductionRun(productionRunId, delegator);
+ if (productionRun != null) {
+ this.estimatedStartDate =
productionRun.getTimestamp("estimatedStartDate");
+ this.estimatedCompletionDate =
productionRun.getTimestamp("estimatedCompletionDate");
+ this.productionRunName = productionRun.getString("workEffortName");
+ this.description = productionRun.getString("description");
+ }
+ }
+
+ /**
+ * Finds the production run header; when the id is the one of a task, the
header is its parent.
+ * @return the production run header, or null if it is not found
+ */
+ private static GenericValue findProductionRun(String productionRunId,
Delegator delegator) {
+ if (UtilValidate.isEmpty(productionRunId)) {
+ return null;
+ }
try {
- if (!UtilValidate.isEmpty(productionRunId)) {
- this.dispatcher = dispatcher;
- GenericValue workEffort =
EntityQuery.use(delegator).from("WorkEffort").where("workEffortId",
productionRunId).queryOne();
- if (workEffort != null) {
- // If this is a task, get the parent production run
- if (workEffort.getString("workEffortTypeId") != null &&
"PROD_ORDER_TASK".equals(workEffort.getString("workEffortTypeId"))) {
- workEffort =
EntityQuery.use(delegator).from("WorkEffort").where("workEffortId",
-
workEffort.getString("workEffortParentId")).queryOne();
- }
- }
- this.productionRun = workEffort;
- if (exist()) {
- this.estimatedStartDate =
productionRun.getTimestamp("estimatedStartDate");
- this.estimatedCompletionDate =
productionRun.getTimestamp("estimatedCompletionDate");
- this.productionRunName =
productionRun.getString("workEffortName");
- this.description = productionRun.getString("description");
+ GenericValue workEffort =
EntityQuery.use(delegator).from("WorkEffort").where("workEffortId",
productionRunId).queryOne();
+ if (workEffort != null) {
+ // If this is a task, get the parent production run
+ if (workEffort.getString("workEffortTypeId") != null &&
"PROD_ORDER_TASK".equals(workEffort.getString("workEffortTypeId"))) {
+ workEffort =
EntityQuery.use(delegator).from("WorkEffort").where("workEffortId",
+
workEffort.getString("workEffortParentId")).queryOne();
}
}
+ return workEffort;
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), MODULE);
+ return null;
}
}
diff --git
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
index cc7de04b11..ed806aea54 100644
---
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
+++
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
@@ -302,6 +302,17 @@ public class ShoppingCart implements
Iterable<ShoppingCartItem>, Serializable {
}
}
+
+ /** Creates new empty ShoppingCart object for the given user logins and
order party. */
+ protected ShoppingCart(LocalDispatcher dispatcher, String productStoreId,
String webSiteId, Locale locale, String currencyUom,
+ String billToCustomerPartyId, String
billFromVendorPartyId, GenericValue userLogin, GenericValue autoUserLogin,
+ String orderPartyId) {
+ this(dispatcher, productStoreId, webSiteId, locale, currencyUom,
billToCustomerPartyId, billFromVendorPartyId);
+ this.userLogin = userLogin;
+ this.autoUserLogin = autoUserLogin;
+ this.orderPartyId = orderPartyId;
+ }
+
public ShoppingCart(Delegator delegator, String productStoreId, String
webSiteId, Locale locale, String currencyUom,
String billToCustomerPartyId, String
billFromVendorPartyId) {
this(getDispatcher(delegator), productStoreId, webSiteId, locale,
currencyUom,
diff --git
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
index 5337e5e90e..bd96134e70 100644
---
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
+++
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
@@ -209,16 +209,16 @@ public class ShoppingCartItem implements
java.io.Serializable {
this.accommodationMapId = item.getAccommodationMapId();
this.accommodationSpotId = item.getAccommodationSpotId();
this.quantity = item.getQuantity();
- this.setBasePrice(item.getBasePrice());
- this.setDisplayPrice(item.getDisplayPrice());
- this.setRecurringBasePrice(item.getRecurringBasePrice());
- this.setRecurringDisplayPrice(item.getRecurringDisplayPrice());
- this.setSpecialPromoPrice(item.getSpecialPromoPrice());
+ this.basePrice = item.getBasePrice();
+ this.displayPrice = item.getDisplayPrice();
+ this.recurringBasePrice = item.getRecurringBasePrice();
+ this.recurringDisplayPrice = item.getRecurringDisplayPrice();
+ this.specialPromoPrice = item.getSpecialPromoPrice();
this.reserv2ndPPPerc = item.getReserv2ndPPPerc();
this.reservNthPPPerc = item.getReservNthPPPerc();
this.listPrice = item.getListPrice();
this.discountRate = item.getDiscountRate();
- this.setIsModifiedPrice(item.getIsModifiedPrice());
+ this.isModifiedPrice = item.getIsModifiedPrice();
this.selectedAmount = item.getSelectedAmount();
this.requirementId = item.getRequirementId();
this.quoteId = item.getQuoteId();
@@ -226,15 +226,15 @@ public class ShoppingCartItem implements
java.io.Serializable {
this.associatedOrderId = item.getAssociatedOrderId();
this.associatedOrderItemSeqId = item.getAssociatedOrderItemSeqId();
this.orderItemAssocTypeId = item.getOrderItemAssocTypeId();
- this.setStatusId(item.getStatusId());
+ this.statusId = item.getStatusId();
this.orderItemAttributes = item.getOrderItemAttributes() == null ? new
HashMap<>() : new HashMap<>(item.getOrderItemAttributes());
this.attributes = item.getAttributes() == null ? new HashMap<>() : new
HashMap<>(item.getAttributes());
- this.setOrderItemSeqId(item.getOrderItemSeqId());
+ this.orderItemSeqId = item.getOrderItemSeqId();
this.locale = item.locale;
- this.setShipBeforeDate(item.getShipBeforeDate());
- this.setShipAfterDate(item.getShipAfterDate());
- this.setEstimatedShipDate(item.getEstimatedShipDate());
- this.setCancelBackOrderDate(item.getCancelBackOrderDate());
+ this.shipBeforeDate = item.getShipBeforeDate();
+ this.shipAfterDate = item.getShipAfterDate();
+ this.estimatedShipDate = item.getEstimatedShipDate();
+ this.cancelBackOrderDate = item.getCancelBackOrderDate();
this.contactMechIdsMap = item.getOrderItemContactMechIds() == null ?
null : new HashMap<>(item.getOrderItemContactMechIds());
this.orderItemPriceInfos = item.getOrderItemPriceInfos() == null ?
null : new LinkedList<>(item.getOrderItemPriceInfos());
this.itemAdjustments.addAll(item.getAdjustments());
@@ -248,7 +248,7 @@ public class ShoppingCartItem implements
java.io.Serializable {
if (item.getAlternativeOptionProductIds() != null) {
List<String> tempAlternativeOptionProductIds = new LinkedList<>();
tempAlternativeOptionProductIds.addAll(item.getAlternativeOptionProductIds());
-
this.setAlternativeOptionProductIds(tempAlternativeOptionProductIds);
+ this.alternativeOptionProductIds = tempAlternativeOptionProductIds;
}
if (item.configWrapper != null) {
this.configWrapper = new ProductConfigWrapper(item.configWrapper);
@@ -284,7 +284,8 @@ public class ShoppingCartItem implements
java.io.Serializable {
String productName =
ProductContentWrapper.getProductContentAsText(product, "PRODUCT_NAME",
this.locale, dispatcher, "html");
// if the productName is null or empty, see if there is an associated
virtual product and get the productName of that product
if (UtilValidate.isEmpty(productName)) {
- GenericValue parentProduct = this.getParentProduct();
+ this.parentProduct = findParentProduct(this.productId,
this.delegator);
+ GenericValue parentProduct = this.parentProduct;
if (parentProduct != null) {
productName =
ProductContentWrapper.getProductContentAsText(parentProduct, "PRODUCT_NAME",
this.locale, dispatcher, "html");
}
@@ -343,12 +344,24 @@ public class ShoppingCartItem implements
java.io.Serializable {
this.itemGroup = itemGroup;
this.prodCatalogId = prodCatalogId;
this.attributes = (attributes == null ? new HashMap<>() : attributes);
- this.addAllProductFeatureAndAppls(additionalProductFeatureAndAppls);
+ if (additionalProductFeatureAndAppls != null) {
+ for (GenericValue additionalProductFeatureAndAppl :
additionalProductFeatureAndAppls.values()) {
+ if (additionalProductFeatureAndAppl != null) {
+ GenericValue replaced =
this.additionalProductFeatureAndAppls.put(
+
additionalProductFeatureAndAppl.getString("productFeatureTypeId"),
additionalProductFeatureAndAppl);
+ if (replaced != null) {
+ removeFeatureAdjustments(this.itemAdjustments,
replaced.getString("productFeatureId"));
+ }
+ // the quantity is still zero here, so the adjustment
amounts are zero too
+
this.itemAdjustments.add(makeFeatureAdjustment(this.delegator,
additionalProductFeatureAndAppl, this.quantity));
+ }
+ }
+ }
this.locale = locale;
if (UtilValidate.isNotEmpty(configWrapper)) {
this.configWrapper = configWrapper;
if (UtilValidate.isEmpty(configWrapper.getConfigId())) { //new
product configuration. Persist it
- ProductConfigWorker.storeProductConfigWrapper(configWrapper,
getDelegator());
+ ProductConfigWorker.storeProductConfigWrapper(configWrapper,
this.delegator);
}
}
}
@@ -374,8 +387,8 @@ public class ShoppingCartItem implements
java.io.Serializable {
this.itemDescription = description;
this.productCategoryId = categoryId;
if (basePrice != null) {
- this.setBasePrice(basePrice);
- this.setDisplayPrice(basePrice);
+ this.basePrice = basePrice;
+ this.displayPrice = basePrice;
}
this.attributes = (attributes == null ? new HashMap<>() : attributes);
this.prodCatalogId = prodCatalogId;
@@ -2701,7 +2714,11 @@ public class ShoppingCartItem implements
java.io.Serializable {
String featureType =
additionalProductFeatureAndAppl.getString("productFeatureTypeId");
this.additionalProductFeatureAndAppls.put(featureType,
additionalProductFeatureAndAppl);
- GenericValue orderAdjustment =
this.getDelegator().makeValue("OrderAdjustment");
+ this.addAdjustment(makeFeatureAdjustment(this.getDelegator(),
additionalProductFeatureAndAppl, this.getQuantity()));
+ }
+
+ private static GenericValue makeFeatureAdjustment(Delegator delegator,
GenericValue additionalProductFeatureAndAppl, BigDecimal quantity) {
+ GenericValue orderAdjustment = delegator.makeValue("OrderAdjustment");
orderAdjustment.set("orderAdjustmentTypeId", "ADDITIONAL_FEATURE");
orderAdjustment.set("description",
additionalProductFeatureAndAppl.get("description"));
orderAdjustment.set("productFeatureId",
additionalProductFeatureAndAppl.get("productFeatureId"));
@@ -2709,13 +2726,13 @@ public class ShoppingCartItem implements
java.io.Serializable {
// NOTE: this is a VERY simple pricing scheme for additional features
and will likely need to be extended for most real applications
BigDecimal amount = (BigDecimal)
additionalProductFeatureAndAppl.get("amount");
if (amount != null) {
- amount = amount.multiply(this.getQuantity());
+ amount = amount.multiply(quantity);
orderAdjustment.set("amount", amount);
}
BigDecimal recurringAmount = (BigDecimal)
additionalProductFeatureAndAppl.get("recurringAmount");
if (recurringAmount != null) {
- recurringAmount = recurringAmount.multiply(this.getQuantity());
+ recurringAmount = recurringAmount.multiply(quantity);
orderAdjustment.set("recurringAmount", recurringAmount);
}
@@ -2723,8 +2740,7 @@ public class ShoppingCartItem implements
java.io.Serializable {
Debug.logWarning("In putAdditionalProductFeatureAndAppl the amount
and recurringAmount are null for this adjustment: "
+ orderAdjustment, MODULE);
}
-
- this.addAdjustment(orderAdjustment);
+ return orderAdjustment;
}
/**
@@ -2893,6 +2909,10 @@ public class ShoppingCartItem implements
java.io.Serializable {
* @param productFeatureId the product feature id
*/
public void removeFeatureAdjustment(String productFeatureId) {
+ removeFeatureAdjustments(itemAdjustments, productFeatureId);
+ }
+
+ private static void removeFeatureAdjustments(List<GenericValue>
itemAdjustments, String productFeatureId) {
if (productFeatureId == null) {
return;
}
@@ -3148,15 +3168,19 @@ public class ShoppingCartItem implements
java.io.Serializable {
if (this.parentProduct != null) {
return this.parentProduct;
}
- if (this.productId == null) {
- throw new IllegalStateException("Bad product id");
- }
- this.parentProduct = ProductWorker.getParentProduct(productId,
this.getDelegator());
+ this.parentProduct = findParentProduct(this.productId,
this.getDelegator());
return this.parentProduct;
}
+ private static GenericValue findParentProduct(String productId, Delegator
delegator) {
+ if (productId == null) {
+ throw new IllegalStateException("Bad product id");
+ }
+ return ProductWorker.getParentProduct(productId, delegator);
+ }
+
/**
* Gets parent product id.
* @return the parent product id
diff --git
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/WebShoppingCart.java
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/WebShoppingCart.java
index 1a51c53418..06ca20b2a5 100644
---
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/WebShoppingCart.java
+++
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/WebShoppingCart.java
@@ -46,12 +46,14 @@ public class WebShoppingCart extends ShoppingCart {
WebSiteWorker.getWebSiteId(request), (locale != null ? locale
: ProductStoreWorker.getStoreLocale(request)), (currencyUom != null
? currencyUom :
ProductStoreWorker.getStoreCurrencyUomId(request)),
request.getParameter("billToCustomerPartyId"), (
request.getParameter("supplierPartyId") != null ?
request.getParameter("supplierPartyId")
- : request.getParameter("billFromVendorPartyId")));
+ : request.getParameter("billFromVendorPartyId")),
+ (GenericValue) getSessionAttribute(request, "userLogin"),
(GenericValue) getSessionAttribute(request, "autoUserLogin"),
+ (String) getSessionAttribute(request, "orderPartyId"));
+ }
+ private static Object getSessionAttribute(HttpServletRequest request,
String name) {
HttpSession session = request.getSession(true);
- this.setUserLogin((GenericValue) session.getAttribute("userLogin"));
- this.setAutoUserLogin((GenericValue)
session.getAttribute("autoUserLogin"));
- this.setOrderPartyId((String) session.getAttribute("orderPartyId"));
+ return session.getAttribute(name);
}
public WebShoppingCart(HttpServletRequest request) {
diff --git
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
index cb962a752a..c00317bf58 100644
---
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
+++
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
@@ -58,6 +58,8 @@ public class ShippingEstimateWrapper {
private BigDecimal shippableTotal = BigDecimal.ZERO;
private String partyId = null;
private String supplierPartyId = null;
+ private final BigDecimal totalAllowance;
+ private boolean loaded = false;
public static ShippingEstimateWrapper getWrapper(LocalDispatcher
dispatcher, ShoppingCart cart, int shipGroup) {
return new ShippingEstimateWrapper(dispatcher, cart, shipGroup);
@@ -93,9 +95,20 @@ public class ShippingEstimateWrapper {
Debug.logError(gee.getMessage(), MODULE);
}
}
- this.loadShippingMethods();
- this.loadEstimates(totalAllowance);
- this.loadShipmentTimeEstimates();
+ this.totalAllowance = totalAllowance;
+ }
+
+ /**
+ * Runs the load methods on first use, so they are not called from the
constructor and their overrides
+ * see a fully constructed object.
+ */
+ private synchronized void ensureLoaded() {
+ if (!loaded) {
+ loaded = true;
+ this.loadShippingMethods();
+ this.loadEstimates(totalAllowance);
+ this.loadShipmentTimeEstimates();
+ }
}
/**
@@ -160,6 +173,7 @@ public class ShippingEstimateWrapper {
* @return the shipping methods
*/
public List<GenericValue> getShippingMethods() {
+ ensureLoaded();
return shippingMethods;
}
@@ -168,6 +182,7 @@ public class ShippingEstimateWrapper {
* @return the all estimates
*/
public Map<GenericValue, BigDecimal> getAllEstimates() {
+ ensureLoaded();
return shippingEstimates;
}
@@ -177,6 +192,7 @@ public class ShippingEstimateWrapper {
* @return the shipping estimate
*/
public BigDecimal getShippingEstimate(GenericValue storeCarrierShipMethod)
{
+ ensureLoaded();
return shippingEstimates.get(storeCarrierShipMethod);
}
@@ -185,6 +201,7 @@ public class ShippingEstimateWrapper {
* @return the shipping time estimates
*/
public List<GenericValue> getShippingTimeEstimates() {
+ ensureLoaded();
return shippingTimeEstimates;
}
@@ -194,6 +211,7 @@ public class ShippingEstimateWrapper {
* @return the shipping time estimate in day
*/
public Double getShippingTimeEstimateInDay(GenericValue
storeCarrierShipMethod) {
+ ensureLoaded();
return ShippingEvents.getShippingTimeEstimateInDay(dispatcher,
storeCarrierShipMethod, shippingTimeEstimates);
}
}
diff --git
a/applications/product/src/main/java/org/apache/ofbiz/product/store/ProductStoreSurveyWrapper.java
b/applications/product/src/main/java/org/apache/ofbiz/product/store/ProductStoreSurveyWrapper.java
index aded7dfb0a..11958bcd5f 100644
---
a/applications/product/src/main/java/org/apache/ofbiz/product/store/ProductStoreSurveyWrapper.java
+++
b/applications/product/src/main/java/org/apache/ofbiz/product/store/ProductStoreSurveyWrapper.java
@@ -19,6 +19,7 @@
package org.apache.ofbiz.product.store;
import java.io.Writer;
+import java.util.HashMap;
import java.util.Map;
import org.apache.ofbiz.base.util.UtilValidate;
@@ -32,38 +33,44 @@ public class ProductStoreSurveyWrapper extends
SurveyWrapper {
private static final String MODULE =
ProductStoreSurveyWrapper.class.getName();
- private GenericValue productStoreSurveyAppl = null;
- private String surveyTemplate = null;
- private String resultTemplate = null;
+ private final GenericValue productStoreSurveyAppl;
+ private final String surveyTemplate;
+ private final String resultTemplate;
private boolean callResult = false;
- protected ProductStoreSurveyWrapper() { }
+ protected ProductStoreSurveyWrapper() {
+ this.productStoreSurveyAppl = null;
+ this.surveyTemplate = null;
+ this.resultTemplate = null;
+ }
public ProductStoreSurveyWrapper(GenericValue productStoreSurveyAppl,
String partyId, Map<String, Object> passThru,
Map<String, Object> defaultValues) {
+ super(requireAppl(productStoreSurveyAppl).getDelegator(), null,
partyId, productStoreSurveyAppl.getString("surveyId"),
+ sanitizePassThru(passThru), defaultValues);
this.productStoreSurveyAppl = productStoreSurveyAppl;
+ this.surveyTemplate =
productStoreSurveyAppl.getString("surveyTemplate");
+ this.resultTemplate =
productStoreSurveyAppl.getString("resultTemplate");
+ }
- if (this.productStoreSurveyAppl != null) {
- this.setPartyId(partyId);
- this.setDelegator(productStoreSurveyAppl.getDelegator());
- this.setSurveyId(productStoreSurveyAppl.getString("surveyId"));
- this.surveyTemplate =
productStoreSurveyAppl.getString("surveyTemplate");
- this.resultTemplate =
productStoreSurveyAppl.getString("resultTemplate");
- } else {
+ public ProductStoreSurveyWrapper(GenericValue productStoreSurveyAppl,
String partyId, Map<String, Object> passThru) {
+ this(productStoreSurveyAppl, partyId, passThru, null);
+ }
+
+ private static GenericValue requireAppl(GenericValue
productStoreSurveyAppl) {
+ if (productStoreSurveyAppl == null) {
throw new IllegalArgumentException("Required parameter
productStoreSurveyAppl missing");
}
- this.setDefaultValues(defaultValues);
- // sanitize pass-thru, we need to remove hidden fields values that are
set
- // by the survey so they won't be duplicated in additionalFields
- passThru.remove("surveyId");
- passThru.remove("partyId");
- passThru.remove("surveyResponseId");
- this.setPassThru(passThru);
- this.checkParameters();
+ return productStoreSurveyAppl;
}
- public ProductStoreSurveyWrapper(GenericValue productStoreSurveyAppl,
String partyId, Map<String, Object> passThru) {
- this(productStoreSurveyAppl, partyId, passThru, null);
+ private static Map<String, Object> sanitizePassThru(Map<String, Object>
passThru) {
+ // remove hidden fields values that are set by the survey so they
won't be duplicated in additionalFields
+ Map<String, Object> sanitized = new HashMap<>(passThru);
+ sanitized.remove("surveyId");
+ sanitized.remove("partyId");
+ sanitized.remove("surveyResponseId");
+ return sanitized;
}
/**