This is an automated email from the ASF dual-hosted git repository. jleroux 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 70b57e4 Improved: Fix some bugs Spotbugs reports (OFBIZ-12386) 70b57e4 is described below commit 70b57e4ad83ee763197a3952f759164f11411438 Author: Jacques Le Roux <jacques.le.r...@les7arts.com> AuthorDate: Tue Nov 30 17:59:01 2021 +0100 Improved: Fix some bugs Spotbugs reports (OFBIZ-12386) Removes repeated conditional tests --- .../apache/ofbiz/manufacturing/bom/BOMNode.java | 108 ++++++++++----------- 1 file changed, 52 insertions(+), 56 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 a67f3d8..44ee6e7 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 @@ -261,68 +261,64 @@ public class BOMNode { .filterByDate(inDate).queryList()); } newNode = substituteNode(oneChildNode, productFeatures, genericLinkRules); + // If no substitution has been done (no valid rule applied), + // we try to search for a generic node-rule + List<GenericValue> genericNodeRules = EntityQuery.use(delegator).from("ProductManufacturingRule") + .where("productIdIn", node.get("productIdTo")) + .orderBy("ruleSeqId") + .filterByDate(inDate).queryList(); + newNode = null; + newNode = substituteNode(oneChildNode, productFeatures, genericNodeRules); + // If no substitution has been done (no valid rule applied), + // we try to set the default (first) node-substitution + // if (UtilValidate.isNotEmpty(genericNodeRules)) { + // FIXME + // ... + // } + // ----------------------------------------------------------- + // We try to apply directly the selected features if (newNode.equals(oneChildNode)) { - // If no substitution has been done (no valid rule applied), - // we try to search for a generic node-rule - List<GenericValue> genericNodeRules = EntityQuery.use(delegator).from("ProductManufacturingRule") - .where("productIdIn", node.get("productIdTo")) - .orderBy("ruleSeqId") - .filterByDate(inDate).queryList(); - newNode = null; - newNode = substituteNode(oneChildNode, productFeatures, genericNodeRules); - if (newNode.equals(oneChildNode)) { - // If no substitution has been done (no valid rule applied), - // we try to set the default (first) node-substitution - // if (UtilValidate.isNotEmpty(genericNodeRules)) { - // FIXME - //... - // } - // ----------------------------------------------------------- - // We try to apply directly the selected features - if (newNode.equals(oneChildNode)) { - Map<String, String> selectedFeatures = new HashMap<>(); - if (productFeatures != null) { - GenericValue feature = null; - for (GenericValue productFeature : productFeatures) { - feature = productFeature; - selectedFeatures.put(feature.getString("productFeatureTypeId"), feature.getString("productFeatureId")); // FIXME - } - } + Map<String, String> selectedFeatures = new HashMap<>(); + if (productFeatures != null) { + GenericValue feature = null; + for (GenericValue productFeature : productFeatures) { + feature = productFeature; + selectedFeatures.put(feature.getString("productFeatureTypeId"), feature.getString("productFeatureId")); // FIXME + } + } - if (!selectedFeatures.isEmpty()) { - Map<String, Object> context = new HashMap<>(); - context.put("productId", node.get("productIdTo")); - context.put("selectedFeatures", selectedFeatures); - Map<String, Object> storeResult = null; - GenericValue variantProduct = null; - try { - storeResult = dispatcher.runSync("getProductVariant", context); - if (ServiceUtil.isError(storeResult)) { - String errorMessage = ServiceUtil.getErrorMessage(storeResult); - Debug.logError(errorMessage, MODULE); - throw new GenericEntityException(errorMessage); - } - List<GenericValue> variantProducts = UtilGenerics.cast(storeResult.get("products")); - if (variantProducts.size() == 1) { - variantProduct = variantProducts.get(0); - } - } catch (GenericServiceException e) { - Debug.logError("Error calling getProductVariant service " + e.getMessage(), MODULE); - } - if (variantProduct != null) { - newNode = new BOMNode(variantProduct, dispatcher, userLogin); - newNode.setTree(tree); - newNode.setSubstitutedNode(oneChildNode); - newNode.setQuantityMultiplier(oneChildNode.getQuantityMultiplier()); - newNode.setScrapFactor(oneChildNode.getScrapFactor()); - newNode.setProductAssoc(oneChildNode.getProductAssoc()); - } + if (!selectedFeatures.isEmpty()) { + Map<String, Object> context = new HashMap<>(); + context.put("productId", node.get("productIdTo")); + context.put("selectedFeatures", selectedFeatures); + Map<String, Object> storeResult = null; + GenericValue variantProduct = null; + try { + storeResult = dispatcher.runSync("getProductVariant", context); + if (ServiceUtil.isError(storeResult)) { + String errorMessage = ServiceUtil.getErrorMessage(storeResult); + Debug.logError(errorMessage, MODULE); + throw new GenericEntityException(errorMessage); } - + List<GenericValue> variantProducts = UtilGenerics.cast(storeResult.get("products")); + if (variantProducts.size() == 1) { + variantProduct = variantProducts.get(0); + } + } catch (GenericServiceException e) { + Debug.logError("Error calling getProductVariant service " + e.getMessage(), MODULE); + } + if (variantProduct != null) { + newNode = new BOMNode(variantProduct, dispatcher, userLogin); + newNode.setTree(tree); + newNode.setSubstitutedNode(oneChildNode); + newNode.setQuantityMultiplier(oneChildNode.getQuantityMultiplier()); + newNode.setScrapFactor(oneChildNode.getScrapFactor()); + newNode.setProductAssoc(oneChildNode.getProductAssoc()); } - // ----------------------------------------------------------- } + } + // ----------------------------------------------------------- } } // end of if (isVirtual()) return newNode;