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 3ba80c8432 Remove this-escape warnings in ProductConfigWrapper and
BOMTree
3ba80c8432 is described below
commit 3ba80c843230f18fc1df335fd1cb0ce8c01eddc9
Author: Mridul Pathak <[email protected]>
AuthorDate: Fri Oct 30 17:07:41 2026 +0530
Remove this-escape warnings in ProductConfigWrapper and BOMTree
- ProductConfigWrapper.ConfigItem and ConfigOption are now static nested
classes and get their context explicitly instead of through the enclosing
wrapper: setContent takes the dispatcher, the pricing ConfigOption constructor
takes the product store id, and recalculateOptionPrice reads it from the
wrapper it is given. The constructor computes the default price through a
private helper instead of the overridable getDefaultOptions.
- BOMNode no longer keeps a reference to its BOMTree, which it only used to
read the root amount: BOMTree passes the root amount to print instead, and
BOMNode.setTree and getTree are removed.
---
.../apache/ofbiz/manufacturing/bom/BOMNode.java | 28 ++++------------------
.../apache/ofbiz/manufacturing/bom/BOMTree.java | 4 +---
.../ofbiz/product/config/ProductConfigWrapper.java | 25 +++++++++++--------
3 files changed, 20 insertions(+), 37 deletions(-)
diff --git
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/bom/BOMNode.java
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/bom/BOMNode.java
index 3aa98de8fc..601afba088 100644
---
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/bom/BOMNode.java
+++
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/bom/BOMNode.java
@@ -52,7 +52,6 @@ public class BOMNode {
private Delegator delegator = null;
private GenericValue userLogin = null;
- private BOMTree tree; // the tree to which this node belongs
private BOMNode parentNode; // the parent node (null if it's not present)
private BOMNode substitutedNode; // The virtual node (if any) that this
instance substitutes
private GenericValue ruleApplied; // The rule (if any) that that has been
applied to configure the current node
@@ -183,7 +182,6 @@ public class BOMNode {
} else {
BOMNode origNode = oneChildNode;
oneChildNode = new BOMNode(newPart, delegator,
dispatcher, userLogin);
- oneChildNode.setTree(tree);
oneChildNode.setSubstitutedNode(tmpNode);
oneChildNode.setRuleApplied(rule);
oneChildNode.setProductAssoc(origNode.getProductAssoc());
@@ -206,7 +204,6 @@ public class BOMNode {
private BOMNode configurator(GenericValue node, List<GenericValue>
productFeatures,
String productIdForRules, Date inDate) throws
GenericEntityException {
BOMNode oneChildNode = new BOMNode((String) node.get("productIdTo"),
delegator, dispatcher, userLogin);
- oneChildNode.setTree(tree);
oneChildNode.setProductAssoc(node);
try {
oneChildNode.setQuantityMultiplier(node.getBigDecimal("quantity"));
@@ -309,7 +306,6 @@ public class BOMNode {
}
if (variantProduct != null) {
newNode = new BOMNode(variantProduct, dispatcher,
userLogin);
- newNode.setTree(tree);
newNode.setSubstitutedNode(oneChildNode);
newNode.setQuantityMultiplier(oneChildNode.getQuantityMultiplier());
newNode.setScrapFactor(oneChildNode.getScrapFactor());
@@ -363,7 +359,6 @@ public class BOMNode {
// Configurator
// If the node is null this means that the node has been discarded
by the rules.
oneChildNode.setParentNode(this);
- oneChildNode.setTree(tree);
oneChildNode.loadParents(partBomTypeId, inDate, productFeatures);
childrenNodes.add(oneChildNode);
}
@@ -422,10 +417,11 @@ public class BOMNode {
* Print.
* @param arr the arr
* @param quantity the quantity
+ * @param rootAmount the amount of the root product, passed to the
estimate calculation service
* @param depth the depth
* @param excludeWIPs the exclude wi ps
*/
- public void print(List<BOMNode> arr, BigDecimal quantity, int depth,
boolean excludeWIPs) {
+ public void print(List<BOMNode> arr, BigDecimal quantity, BigDecimal
rootAmount, int depth, boolean excludeWIPs) {
// Now we set the depth and quantity of the current node
// in this breakdown.
this.depth = depth;
@@ -442,7 +438,7 @@ public class BOMNode {
if (serviceName != null) {
Map<String, Object> resultContext = null;
Map<String, Object> arguments = UtilMisc.<String,
Object>toMap("neededQuantity", quantity.multiply(quantityMultiplier),
- "amount", tree != null ? tree.getRootAmount() :
BigDecimal.ZERO);
+ "amount", rootAmount);
BigDecimal width = null;
if (getProduct().get("productWidth") != null) {
width = getProduct().getBigDecimal("productWidth");
@@ -479,7 +475,7 @@ public class BOMNode {
continue;
}
if (oneChildNode != null) {
- oneChildNode.print(arr, this.quantity, depth, excludeWIPs);
+ oneChildNode.print(arr, this.quantity, rootAmount, depth,
excludeWIPs);
}
}
}
@@ -912,20 +908,4 @@ public class BOMNode {
this.productAssoc = productAssoc;
}
- /**
- * Sets tree.
- * @param tree the tree
- */
- public void setTree(BOMTree tree) {
- this.tree = tree;
- }
-
- /**
- * Gets tree.
- * @return the tree
- */
- public BOMTree getTree() {
- return tree;
- }
-
}
diff --git
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/bom/BOMTree.java
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/bom/BOMTree.java
index 68a972b31f..427bf6ce86 100644
---
a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/bom/BOMTree.java
+++
b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/bom/BOMTree.java
@@ -117,7 +117,6 @@ public class BOMTree {
.queryOne();
if (product == null) return;
BOMNode originalNode = new BOMNode(product, dispatcher, userLogin);
- originalNode.setTree(this);
// If the product hasn't a bill of materials we try to retrieve
// the bill of materials of its virtual product (if the current
// product is variant).
@@ -140,7 +139,6 @@ public class BOMTree {
if (product == null) return;
try {
root = new BOMNode(product, dispatcher, userLogin);
- root.setTree(this);
root.setProductForRules(productIdForRules);
root.setSubstitutedNode(originalNode);
if (type == IMPLOSION) {
@@ -268,7 +266,7 @@ public class BOMTree {
*/
public void print(List<BOMNode> arr, int initialDepth, boolean
excludeWIPs) {
if (root != null) {
- root.print(arr, getRootQuantity(), initialDepth, excludeWIPs);
+ root.print(arr, getRootQuantity(), getRootAmount(), initialDepth,
excludeWIPs);
}
}
diff --git
a/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java
b/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java
index 1e5c3c0e7f..fbaf038468 100644
---
a/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java
+++
b/applications/product/src/main/java/org/apache/ofbiz/product/config/ProductConfigWrapper.java
@@ -146,7 +146,7 @@ public class ProductConfigWrapper implements Serializable {
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
+ oneQuestion.setContent(dispatcher, locale, "text/html"); //
TODO: mime-type shouldn't be hardcoded
if
(itemIds.contains(oneQuestion.getConfigItem().getString("configItemId"))) {
oneQuestion.setFirst(false);
} else {
@@ -156,8 +156,8 @@ public class ProductConfigWrapper implements Serializable {
List<GenericValue> configOptions =
EntityQuery.use(delegator).from("ProductConfigOption").where("configItemId",
oneQuestion.getConfigItemAssoc().getString("configItemId")).orderBy("sequenceNum").filterByDate().queryList();
for (GenericValue configOption: configOptions) {
- ConfigOption option = new ConfigOption(delegator,
dispatcher, configOption, oneQuestion, catalogId, webSiteId,
- currencyUomId, autoUserLogin);
+ ConfigOption option = new ConfigOption(delegator,
dispatcher, configOption, oneQuestion, productStoreId, catalogId,
+ webSiteId, currencyUomId, autoUserLogin);
oneQuestion.addOption(option);
}
}
@@ -404,6 +404,10 @@ public class ProductConfigWrapper implements Serializable {
* @return the default options
*/
public List<ConfigOption> getDefaultOptions() {
+ return defaultOptions();
+ }
+
+ private List<ConfigOption> defaultOptions() {
List<ConfigOption> defaultOptions = new LinkedList<>();
for (ConfigItem ci: questions) {
ConfigOption co = ci.getDefault();
@@ -442,7 +446,7 @@ public class ProductConfigWrapper implements Serializable {
private void setDefaultPrice() {
BigDecimal totalPrice = basePrice;
- List<ConfigOption> options = getDefaultOptions();
+ List<ConfigOption> options = defaultOptions();
for (ConfigOption oneOption: options) {
totalPrice = totalPrice.add(oneOption.getPrice());
}
@@ -500,7 +504,7 @@ public class ProductConfigWrapper implements Serializable {
return null;
}
- public class ConfigItem implements java.io.Serializable {
+ public static class ConfigItem implements java.io.Serializable {
private GenericValue configItem = null;
private GenericValue configItemAssoc = null;
private transient ProductConfigItemContentWrapper content = null;
@@ -526,10 +530,11 @@ public class ProductConfigWrapper implements Serializable
{
/**
* Sets content.
+ * @param dispatcher the dispatcher
* @param locale the locale
* @param mimeTypeId the mime type id
*/
- public void setContent(Locale locale, String mimeTypeId) {
+ public void setContent(LocalDispatcher dispatcher, Locale locale,
String mimeTypeId) {
content = new ProductConfigItemContentWrapper(dispatcher,
configItem, locale, mimeTypeId);
}
@@ -738,7 +743,7 @@ public class ProductConfigWrapper implements Serializable {
/**
* The type Config option.
*/
- public class ConfigOption implements java.io.Serializable {
+ public static class ConfigOption implements java.io.Serializable {
private BigDecimal optionListPrice = BigDecimal.ZERO;
private BigDecimal optionPrice = BigDecimal.ZERO;
private Date availabilityDate = null;
@@ -758,8 +763,8 @@ public class ProductConfigWrapper implements Serializable {
return configOption;
}
- public ConfigOption(Delegator delegator, LocalDispatcher dispatcher,
GenericValue option, ConfigItem configItem, String catalogId,
- String webSiteId, String currencyUomId,
GenericValue autoUserLogin) throws Exception {
+ public ConfigOption(Delegator delegator, LocalDispatcher dispatcher,
GenericValue option, ConfigItem configItem, String productStoreId,
+ String catalogId, String webSiteId, String
currencyUomId, GenericValue autoUserLogin) throws Exception {
configOption = option;
parentConfigItem = configItem;
componentList =
option.getRelated("ConfigOptionProductConfigProduct", null, null, false);
@@ -854,7 +859,7 @@ public class ProductConfigWrapper implements Serializable {
// Get the component's price
Map<String, Object> fieldMap = UtilMisc.toMap("product",
oneComponentProduct, "prodCatalogId", pcw.catalogId, "webSiteId",
pcw.webSiteId, "currencyUomId", pcw.currencyUomId,
"productPricePurposeId", "COMPONENT_PRICE", "autoUserLogin",
- pcw.autoUserLogin, "productStoreId", productStoreId);
+ pcw.autoUserLogin, "productStoreId",
pcw.productStoreId);
Map<String, Object> priceMap =
pcw.getDispatcher().runSync("calculateProductPrice", fieldMap);
if (ServiceUtil.isError(priceMap)) {
String errorMessage =
ServiceUtil.getErrorMessage(priceMap);