|
Author: mrisaliti
Date: Tue Jan 11 21:41:33 2011 New Revision: 1057884 URL: http://svn.apache.org/viewvc?rev=1057884&view=rev Log: Remove most of the java compilation warning (generics markup, unused code/import) (OFBIZ-4102) Please advice if you see some issues, I have tested but it could be some errors due to the migration. Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java?rev=1057884&r1=1057883&r2=1057884&view=diff ============================================================================== --- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java (original) +++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java Tue Jan 11 21:41:33 2011 @@ -20,19 +20,17 @@ package org.ofbiz.manufacturing.bom; import java.util.Date; -import java.util.List; -import java.util.Map; import java.util.Iterator; -import java.util.ArrayList; +import java.util.List; -import org.ofbiz.entity.util.EntityUtil; -import org.ofbiz.entity.Delegator; -import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.base.util.Debug; /** Helper class containing static method useful when dealing * with product's bills of materials. @@ -67,12 +65,11 @@ public class BOMHelper { // If the date is null, set it to today. if (inDate == null) inDate = new Date(); int maxDepth = 0; - List productNodesList = delegator.findByAndCache("ProductAssoc", - UtilMisc.toMap("productIdTo", productId, - "productAssocTypeId", bomType)); + List<GenericValue> productNodesList = delegator.findByAndCache("ProductAssoc", + UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", bomType)); productNodesList = EntityUtil.filterByDate(productNodesList, inDate); GenericValue oneNode = null; - Iterator nodesIterator = productNodesList.iterator(); + Iterator<GenericValue> nodesIterator = productNodesList.iterator(); int depth = 0; while (nodesIterator.hasNext()) { oneNode = (GenericValue)nodesIterator.next(); @@ -105,7 +102,8 @@ public class BOMHelper { return searchDuplicatedAncestor(productId, productIdKey, null, bomType, inDate, delegator, dispatcher, userLogin); } - private static GenericValue searchDuplicatedAncestor(String productId, String productIdKey, ArrayList productIdKeys, String bomType, Date inDate, Delegator delegator, LocalDispatcher dispatcher, GenericValue userLogin) throws GenericEntityException { + private static GenericValue searchDuplicatedAncestor(String productId, String productIdKey, List<String> productIdKeys, + String bomType, Date inDate, Delegator delegator, LocalDispatcher dispatcher, GenericValue userLogin) throws GenericEntityException { // If the date is null, set it to today. if (inDate == null) inDate = new Date(); if (productIdKeys == null) { @@ -113,13 +111,12 @@ public class BOMHelper { productIdKeys = tree.getAllProductsId(); productIdKeys.add(productIdKey); } - List productNodesList = delegator.findByAndCache("ProductAssoc", - UtilMisc.toMap("productIdTo", productId, - "productAssocTypeId", bomType)); + List<GenericValue> productNodesList = delegator.findByAndCache("ProductAssoc", + UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", bomType)); productNodesList = EntityUtil.filterByDate(productNodesList, inDate); GenericValue oneNode = null; GenericValue duplicatedNode = null; - Iterator nodesIterator = productNodesList.iterator(); + Iterator<GenericValue> nodesIterator = productNodesList.iterator(); while (nodesIterator.hasNext()) { oneNode = (GenericValue)nodesIterator.next(); for (int i = 0; i < productIdKeys.size(); i++) { @@ -143,18 +140,18 @@ public class BOMHelper { String shipmentId = request.getParameter("shipmentId"); try { - List shipmentPlans = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId)); - Iterator shipmentPlansIt = shipmentPlans.iterator(); + List<GenericValue> shipmentPlans = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId)); + Iterator<GenericValue> shipmentPlansIt = shipmentPlans.iterator(); while (shipmentPlansIt.hasNext()) { GenericValue shipmentPlan = (GenericValue)shipmentPlansIt.next(); GenericValue orderItem = shipmentPlan.getRelatedOne("OrderItem"); - List productionRuns = delegator.findByAndCache("WorkOrderItemFulfillment", UtilMisc.toMap("orderId", shipmentPlan.getString("orderId"), "orderItemSeqId", shipmentPlan.getString("orderItemSeqId"), "shipGroupSeqId", shipmentPlan.getString("shipGroupSeqId"))); + List<GenericValue> productionRuns = delegator.findByAndCache("WorkOrderItemFulfillment", UtilMisc.toMap("orderId", shipmentPlan.getString("orderId"), "orderItemSeqId", shipmentPlan.getString("orderItemSeqId"), "shipGroupSeqId", shipmentPlan.getString("shipGroupSeqId"))); if (UtilValidate.isNotEmpty(productionRuns)) { Debug.logError("Production Run for order item (" + orderItem.getString("orderId") + "/" + orderItem.getString("orderItemSeqId") + ") not created.", module); continue; } - Map result = dispatcher.runSync("createProductionRunsForOrder", UtilMisc.<String, Object>toMap("quantity", shipmentPlan.getBigDecimal("quantity"), "orderId", shipmentPlan.getString("orderId"), "orderItemSeqId", shipmentPlan.getString("orderItemSeqId"), "shipGroupSeqId", shipmentPlan.getString("shipGroupSeqId"), "shipmentId", shipmentId, "userLogin", userLogin)); + dispatcher.runSync("createProductionRunsForOrder", UtilMisc.<String, Object>toMap("quantity", shipmentPlan.getBigDecimal("quantity"), "orderId", shipmentPlan.getString("orderId"), "orderItemSeqId", shipmentPlan.getString("orderItemSeqId"), "shipGroupSeqId", shipmentPlan.getString("shipGroupSeqId"), "shipmentId", shipmentId, "userLogin", userLogin)); } } catch (Exception e) { // if there is an exception for either, the other probably wont work Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java?rev=1057884&r1=1057883&r2=1057884&view=diff ============================================================================== --- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java (original) +++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java Tue Jan 11 21:41:33 2011 @@ -21,26 +21,27 @@ package org.ofbiz.manufacturing.bom; import java.math.BigDecimal; import java.sql.Timestamp; -import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import javolution.util.FastList; +import javolution.util.FastMap; + import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.manufacturing.mrp.ProposedOrder; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.manufacturing.mrp.ProposedOrder; - /** An ItemCoinfigurationNode represents a component in a bill of materials. */ @@ -58,8 +59,8 @@ public class BOMNode { private String productForRules; private GenericValue product; // the current product (from Product entity) private GenericValue productAssoc; // the product assoc record (from ProductAssoc entity) in which the current product is in productIdTo - private ArrayList children; // current node's children (ProductAssocs) - private ArrayList childrenNodes; // current node's children nodes (BOMNode) + private List<GenericValue> children; // current node's children (ProductAssocs) + private List<BOMNode> childrenNodes; // current node's children nodes (BOMNode) private BigDecimal quantityMultiplier; // the necessary quantity as declared in the bom (from ProductAssocs or ProductManufacturingRule) private BigDecimal scrapFactor; // the scrap factor as declared in the bom (from ProductAssocs) // Runtime fields @@ -72,8 +73,8 @@ public class BOMNode { this.delegator = product.getDelegator(); this.dispatcher = dispatcher; this.userLogin = userLogin; - children = new ArrayList(); - childrenNodes = new ArrayList(); + children = FastList.newInstance(); + childrenNodes = FastList.newInstance(); parentNode = null; productForRules = null; bomTypeId = null; @@ -88,7 +89,7 @@ public class BOMNode { this(delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)), dispatcher, userLogin); } - protected void loadChildren(String partBomTypeId, Date inDate, List productFeatures, int type) throws GenericEntityException { + protected void loadChildren(String partBomTypeId, Date inDate, List<GenericValue> productFeatures, int type) throws GenericEntityException { if (product == null) { throw new GenericEntityException("product is null"); } @@ -96,10 +97,10 @@ public class BOMNode { if (inDate == null) inDate = new Date(); bomTypeId = partBomTypeId; // Delegator delegator = product.getDelegator(); - List rows = delegator.findByAnd("ProductAssoc", - UtilMisc.toMap("productId", product.get("productId"), - "productAssocTypeId", partBomTypeId), - UtilMisc.toList("sequenceNum","productIdTo ASC")); + List<GenericValue> rows = delegator.findByAnd("ProductAssoc", + UtilMisc.toMap("productId", product.get("productId"), + "productAssocTypeId", partBomTypeId), + UtilMisc.toList("sequenceNum","productIdTo ASC")); rows = EntityUtil.filterByDate(rows, inDate); if ((UtilValidate.isEmpty(rows)) && substitutedNode != null) { // If no child is found and this is a substituted node @@ -110,9 +111,10 @@ public class BOMNode { UtilMisc.toList("sequenceNum")); rows = EntityUtil.filterByDate(rows, inDate); } - children = new ArrayList(rows); - childrenNodes = new ArrayList(); - Iterator childrenIterator = children.iterator(); + children = FastList.newInstance(); + children.addAll(rows); + childrenNodes = FastList.newInstance(); + Iterator<GenericValue> childrenIterator = children.iterator(); GenericValue oneChild = null; BOMNode oneChildNode = null; while (childrenIterator.hasNext()) { @@ -138,7 +140,8 @@ public class BOMNode { } } - private BOMNode substituteNode(BOMNode oneChildNode, List productFeatures, List productPartRules) throws GenericEntityException { + private BOMNode substituteNode(BOMNode oneChildNode, List<GenericValue> productFeatures, + List<GenericValue> productPartRules) throws GenericEntityException { if (productPartRules != null) { GenericValue rule = null; for (int i = 0; i < productPartRules.size(); i++) { @@ -195,7 +198,8 @@ public class BOMNode { return oneChildNode; } - private BOMNode configurator(GenericValue node, List productFeatures, String productIdForRules, Date inDate) throws GenericEntityException { + 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); @@ -225,7 +229,7 @@ public class BOMNode { // If the part is VIRTUAL and // productFeatures and productPartRules are not null // we have to substitute the part with the right part's variant - List productPartRules = delegator.findByAnd("ProductManufacturingRule", + List<GenericValue> productPartRules = delegator.findByAnd("ProductManufacturingRule", UtilMisc.toMap("productId", productIdForRules, "productIdFor", node.get("productId"), "productIdIn", node.get("productIdTo"))); @@ -240,7 +244,7 @@ public class BOMNode { if (newNode.equals(oneChildNode)) { // If no substitution has been done (no valid rule applied), // we try to search for a generic link-rule - List genericLinkRules = delegator.findByAnd("ProductManufacturingRule", + List<GenericValue> genericLinkRules = delegator.findByAnd("ProductManufacturingRule", UtilMisc.toMap("productIdFor", node.get("productId"), "productIdIn", node.get("productIdTo"))); if (substitutedNode != null) { @@ -253,7 +257,7 @@ public class BOMNode { if (newNode.equals(oneChildNode)) { // If no substitution has been done (no valid rule applied), // we try to search for a generic node-rule - List genericNodeRules = delegator.findByAnd("ProductManufacturingRule", + List<GenericValue> genericNodeRules = delegator.findByAnd("ProductManufacturingRule", UtilMisc.toMap("productIdIn", node.get("productIdTo")), UtilMisc.toList("ruleSeqId")); genericNodeRules = EntityUtil.filterByDate(genericNodeRules, inDate); @@ -269,30 +273,29 @@ public class BOMNode { // ----------------------------------------------------------- // We try to apply directly the selected features if (newNode.equals(oneChildNode)) { - Map selectedFeatures = new HashMap(); + Map<String, String> selectedFeatures = FastMap.newInstance(); if (productFeatures != null) { GenericValue feature = null; for (int j = 0; j < productFeatures.size(); j++) { feature = (GenericValue)productFeatures.get(j); - selectedFeatures.put((String)feature.get("productFeatureTypeId"), (String)feature.get("productFeatureId")); // FIXME + selectedFeatures.put(feature.getString("productFeatureTypeId"), feature.getString("productFeatureId")); // FIXME } } if (selectedFeatures.size() > 0) { - Map context = new HashMap(); + Map<String, Object> context = FastMap.newInstance(); context.put("productId", node.get("productIdTo")); context.put("selectedFeatures", selectedFeatures); - Map storeResult = null; + Map<String, Object> storeResult = null; GenericValue variantProduct = null; try { storeResult = dispatcher.runSync("getProductVariant", context); - List variantProducts = (List) storeResult.get("products"); + List<GenericValue> variantProducts = UtilGenerics.checkList(storeResult.get("products")); if (variantProducts.size() == 1) { variantProduct = (GenericValue)variantProducts.get(0); } } catch (GenericServiceException e) { - String service = e.getMessage(); - if (Debug.infoOn()) Debug.logInfo("Error calling getProductVariant service", module); + if (Debug.infoOn()) Debug.logInfo("Error calling getProductVariant service " + e.getMessage(), module); } if (variantProduct != null) { newNode = new BOMNode(variantProduct, dispatcher, userLogin); @@ -313,7 +316,7 @@ public class BOMNode { return newNode; } - protected void loadParents(String partBomTypeId, Date inDate, List productFeatures) throws GenericEntityException { + protected void loadParents(String partBomTypeId, Date inDate, List<GenericValue> productFeatures) throws GenericEntityException { if (product == null) { throw new GenericEntityException("product is null"); } @@ -322,7 +325,7 @@ public class BOMNode { bomTypeId = partBomTypeId; // Delegator delegator = product.getDelegator(); - List rows = delegator.findByAnd("ProductAssoc", + List<GenericValue> rows = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", product.get("productId"), "productAssocTypeId", partBomTypeId), UtilMisc.toList("sequenceNum")); @@ -336,9 +339,10 @@ public class BOMNode { UtilMisc.toList("sequenceNum")); rows = EntityUtil.filterByDate(rows, inDate); } - children = new ArrayList(rows); - childrenNodes = new ArrayList(); - Iterator childrenIterator = children.iterator(); + children = FastList.newInstance(); + children.addAll(rows);; + childrenNodes = FastList.newInstance(); + Iterator<GenericValue> childrenIterator = children.iterator(); GenericValue oneChild = null; BOMNode oneChildNode = null; while (childrenIterator.hasNext()) { @@ -403,7 +407,7 @@ public class BOMNode { } } - public void print(ArrayList arr, BigDecimal quantity, int depth, boolean excludeWIPs) { + public void print(List<BOMNode> arr, BigDecimal quantity, int depth, boolean excludeWIPs) { // Now we set the depth and quantity of the current node // in this breakdown. this.depth = depth; @@ -418,8 +422,8 @@ public class BOMNode { } } if (serviceName != null) { - Map resultContext = null; - Map arguments = UtilMisc.toMap("neededQuantity", quantity.multiply(quantityMultiplier), "amount", tree != null ? tree.getRootAmount() : BigDecimal.ZERO); + Map<String, Object> resultContext = null; + Map<String, Object> arguments = UtilMisc.<String, Object>toMap("neededQuantity", quantity.multiply(quantityMultiplier), "amount", tree != null ? tree.getRootAmount() : BigDecimal.ZERO); BigDecimal width = null; if (getProduct().get("productWidth") != null) { width = getProduct().getBigDecimal("productWidth"); @@ -428,7 +432,7 @@ public class BOMNode { width = BigDecimal.ZERO; } arguments.put("width", width); - Map inputContext = UtilMisc.toMap("arguments", arguments, "userLogin", userLogin); + Map<String, Object> inputContext = UtilMisc.<String, Object>toMap("arguments", arguments, "userLogin", userLogin); try { resultContext = dispatcher.runSync(serviceName, inputContext); BigDecimal calcQuantity = (BigDecimal)resultContext.get("quantity"); @@ -444,11 +448,9 @@ public class BOMNode { // First of all we visit the current node. arr.add(this); // Now (recursively) we visit the children. - GenericValue oneChild = null; BOMNode oneChildNode = null; depth++; for (int i = 0; i < children.size(); i++) { - oneChild = (GenericValue)children.get(i); oneChildNode = (BOMNode)childrenNodes.get(i); if (excludeWIPs && "WIP".equals(oneChildNode.getProduct().getString("productTypeId"))) { continue; @@ -459,7 +461,7 @@ public class BOMNode { } } - public void getProductsInPackages(ArrayList arr, BigDecimal quantity, int depth, boolean excludeWIPs) { + public void getProductsInPackages(List<BOMNode> arr, BigDecimal quantity, int depth, boolean excludeWIPs) { // Now we set the depth and quantity of the current node // in this breakdown. this.depth = depth; @@ -468,11 +470,9 @@ public class BOMNode { if (this.getProduct().getString("defaultShipmentBoxTypeId") != null) { arr.add(this); } else { - GenericValue oneChild = null; BOMNode oneChildNode = null; depth++; for (int i = 0; i < children.size(); i++) { - oneChild = (GenericValue)children.get(i); oneChildNode = (BOMNode)childrenNodes.get(i); if (excludeWIPs && "WIP".equals(oneChildNode.getProduct().getString("productTypeId"))) { continue; @@ -484,7 +484,7 @@ public class BOMNode { } } - public void sumQuantity(HashMap nodes) { + public void sumQuantity(Map<String, BOMNode> nodes) { // First of all, we try to fetch a node with the same partId BOMNode sameNode = (BOMNode)nodes.get(product.getString("productId")); // If the node is not found we create a new node for the current product @@ -504,17 +504,17 @@ public class BOMNode { } } - public Map createManufacturingOrder(String facilityId, Date date, String workEffortName, String description, String routingId, String orderId, String orderItemSeqId, String shipGroupSeqId, String shipmentId, boolean useSubstitute, boolean ignoreSupplierProducts) throws GenericEntityException { + public Map<String, Object> createManufacturingOrder(String facilityId, Date date, String workEffortName, String description, String routingId, String orderId, String orderItemSeqId, String shipGroupSeqId, String shipmentId, boolean useSubstitute, boolean ignoreSupplierProducts) throws GenericEntityException { String productionRunId = null; Timestamp endDate = null; if (isManufactured(ignoreSupplierProducts)) { BOMNode oneChildNode = null; - ArrayList childProductionRuns = new ArrayList(); + List<String> childProductionRuns = FastList.newInstance(); Timestamp maxEndDate = null; for (int i = 0; i < childrenNodes.size(); i++) { oneChildNode = (BOMNode)childrenNodes.get(i); if (oneChildNode != null) { - Map tmpResult = oneChildNode.createManufacturingOrder(facilityId, date, null, null, null, null, null, shipGroupSeqId, shipmentId, false, false); + Map<String, Object> tmpResult = oneChildNode.createManufacturingOrder(facilityId, date, null, null, null, null, null, shipGroupSeqId, shipmentId, false, false); String childProductionRunId = (String)tmpResult.get("productionRunId"); Timestamp childEndDate = (Timestamp)tmpResult.get("endDate"); if (maxEndDate == null) { @@ -531,7 +531,7 @@ public class BOMNode { } Timestamp startDate = UtilDateTime.toTimestamp(UtilDateTime.toDateTimeString(date)); - Map serviceContext = new HashMap(); + Map<String, Object> serviceContext = FastMap.newInstance(); if (!useSubstitute) { serviceContext.put("productId", getProduct().getString("productId")); serviceContext.put("facilityId", getProduct().getString("facilityId")); @@ -562,7 +562,7 @@ public class BOMNode { serviceContext.put("startDate", startDate); } serviceContext.put("userLogin", userLogin); - Map resultService = null; + Map<String, Object> resultService = null; try { resultService = dispatcher.runSync("createProductionRun", serviceContext); productionRunId = (String)resultService.get("productionRunId"); @@ -616,7 +616,7 @@ public class BOMNode { if ("WIP".equals(getProduct().getString("productTypeId"))) { return false; } - List pfs = null; + List<GenericValue> pfs = null; if (UtilValidate.isEmpty(facilityId)) { pfs = getProduct().getRelatedCache("ProductFacility"); } else { @@ -652,7 +652,7 @@ public class BOMNode { * @return */ public boolean isManufactured(boolean ignoreSupplierProducts) { - List supplierProducts = null; + List<GenericValue> supplierProducts = null; try { supplierProducts = product.getRelated("SupplierProduct", UtilMisc.toMap("supplierPrefOrderId", "10_MAIN_SUPPL"), UtilMisc.toList("minimumOrderQuantity")); } catch (GenericEntityException gee) { @@ -674,16 +674,14 @@ public class BOMNode { return (product.get("isVirtual") != null? product.get("isVirtual").equals("Y"): false); } - public void isConfigured(ArrayList arr) { + public void isConfigured(List<BOMNode> arr) { // First of all we visit the current node. if (isVirtual()) { arr.add(this); } // Now (recursively) we visit the children. - GenericValue oneChild = null; BOMNode oneChildNode = null; for (int i = 0; i < children.size(); i++) { - oneChild = (GenericValue)children.get(i); oneChildNode = (BOMNode)childrenNodes.get(i); if (oneChildNode != null) { oneChildNode.isConfigured(arr); @@ -691,7 +689,6 @@ public class BOMNode { } } - /** Getter for property quantity. * @return Value of property quantity. * @@ -817,7 +814,7 @@ public class BOMNode { * @return Value of property childrenNodes. * */ - public java.util.ArrayList getChildrenNodes() { + public List<BOMNode> getChildrenNodes() { return childrenNodes; } @@ -825,7 +822,7 @@ public class BOMNode { * @param childrenNodes New value of property childrenNodes. * */ - public void setChildrenNodes(java.util.ArrayList childrenNodes) { + public void setChildrenNodes(List<BOMNode> childrenNodes) { this.childrenNodes = childrenNodes; } Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java?rev=1057884&r1=1057883&r2=1057884&view=diff ============================================================================== --- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java (original) +++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java Tue Jan 11 21:41:33 2011 @@ -21,15 +21,17 @@ package org.ofbiz.manufacturing.bom; import java.math.BigDecimal; import java.sql.Timestamp; -import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import javolution.util.FastList; +import javolution.util.FastMap; + import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; @@ -60,9 +62,8 @@ public class BOMServices { * @param context * @return */ - public static Map getMaxDepth(DispatchContext dctx, Map context) { - - Map result = new HashMap(); + public static Map<String, Object> getMaxDepth(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); String productId = (String) context.get("productId"); String fromDateStr = (String) context.get("fromDate"); @@ -78,11 +79,11 @@ public class BOMServices { if (fromDate == null) { fromDate = new Date(); } - List bomTypes = new ArrayList(); + List<String> bomTypes = FastList.newInstance(); if (bomType == null) { try { - List bomTypesValues = delegator.findByAnd("ProductAssocType", UtilMisc.toMap("parentTypeId", "PRODUCT_COMPONENT")); - Iterator bomTypesValuesIt = bomTypesValues.iterator(); + List<GenericValue> bomTypesValues = delegator.findByAnd("ProductAssocType", UtilMisc.toMap("parentTypeId", "PRODUCT_COMPONENT")); + Iterator<GenericValue> bomTypesValuesIt = bomTypesValues.iterator(); while (bomTypesValuesIt.hasNext()) { bomTypes.add(((GenericValue)bomTypesValuesIt.next()).getString("productAssocTypeId")); } @@ -95,7 +96,7 @@ public class BOMServices { int depth = 0; int maxDepth = 0; - Iterator bomTypesIt = bomTypes.iterator(); + Iterator<String> bomTypesIt = bomTypes.iterator(); try { while (bomTypesIt.hasNext()) { String oneBomType = (String)bomTypesIt.next(); @@ -120,8 +121,8 @@ public class BOMServices { * @param context * @return */ - public static Map updateLowLevelCode(DispatchContext dctx, Map context) { - Map result = new HashMap(); + public static Map<String, Object> updateLowLevelCode(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String productId = (String) context.get("productIdTo"); @@ -137,14 +138,16 @@ public class BOMServices { Long llc = null; try { GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); - Map depthResult = dispatcher.runSync("getMaxDepth", UtilMisc.toMap("productId", productId, "bomType", "MANUF_COMPONENT")); + Map<String, Object> depthResult = dispatcher.runSync("getMaxDepth", + UtilMisc.toMap("productId", productId, "bomType", "MANUF_COMPONENT")); llc = (Long)depthResult.get("depth"); // If the product is a variant of a virtual, then the billOfMaterialLevel cannot be // lower than the billOfMaterialLevel of the virtual product. - List virtualProducts = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "PRODUCT_VARIANT")); + List<GenericValue> virtualProducts = delegator.findByAnd("ProductAssoc", + UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "PRODUCT_VARIANT")); virtualProducts = EntityUtil.filterByDate(virtualProducts); int virtualMaxDepth = 0; - Iterator virtualProductsIt = virtualProducts.iterator(); + Iterator<GenericValue> virtualProductsIt = virtualProducts.iterator(); while (virtualProductsIt.hasNext()) { int virtualDepth = 0; GenericValue oneVirtualProductAssoc = (GenericValue)virtualProductsIt.next(); @@ -164,9 +167,9 @@ public class BOMServices { product.set("billOfMaterialLevel", llc); product.store(); if (alsoComponents.booleanValue()) { - Map treeResult = dispatcher.runSync("getBOMTree", UtilMisc.toMap("productId", productId, "bomType", "MANUF_COMPONENT")); + Map<String, Object> treeResult = dispatcher.runSync("getBOMTree", UtilMisc.toMap("productId", productId, "bomType", "MANUF_COMPONENT")); BOMTree tree = (BOMTree)treeResult.get("tree"); - ArrayList products = new ArrayList(); + List<BOMNode> products = FastList.newInstance(); tree.print(products, llc.intValue()); for (int i = 0; i < products.size(); i++) { BOMNode oneNode = (BOMNode)products.get(i); @@ -182,9 +185,10 @@ public class BOMServices { } } if (alsoVariants.booleanValue()) { - List variantProducts = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT")); + List<GenericValue> variantProducts = delegator.findByAnd("ProductAssoc", + UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT")); variantProducts = EntityUtil.filterByDate(variantProducts, true); - Iterator variantProductsIt = variantProducts.iterator(); + Iterator<GenericValue> variantProductsIt = variantProducts.iterator(); while (variantProductsIt.hasNext()) { GenericValue oneVariantProductAssoc = (GenericValue)variantProductsIt.next(); GenericValue variantProduct = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", oneVariantProductAssoc.getString("productId"))); @@ -205,16 +209,17 @@ public class BOMServices { * @param context * @return */ - public static Map initLowLevelCode(DispatchContext dctx, Map context) { - Map result = new HashMap(); + public static Map<String, Object> initLowLevelCode(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); try { - List products = delegator.findList("Product", null, null, UtilMisc.toList("isVirtual DESC"), null, false); - Iterator productsIt = products.iterator(); + List<GenericValue> products = delegator.findList("Product", null, null, + UtilMisc.toList("isVirtual DESC"), null, false); + Iterator<GenericValue> productsIt = products.iterator(); Long zero = Long.valueOf(0); - List allProducts = new ArrayList(); + List<GenericValue> allProducts = FastList.newInstance(); while (productsIt.hasNext()) { GenericValue product = (GenericValue)productsIt.next(); product.set("billOfMaterialLevel", zero); @@ -227,7 +232,7 @@ public class BOMServices { while (productsIt.hasNext()) { GenericValue product = (GenericValue)productsIt.next(); try { - Map depthResult = dispatcher.runSync("updateLowLevelCode", UtilMisc.<String, Object>toMap("productIdTo", product.getString("productId"), "alsoComponents", Boolean.valueOf(false), "alsoVariants", Boolean.valueOf(false))); + Map<String, Object> depthResult = dispatcher.runSync("updateLowLevelCode", UtilMisc.<String, Object>toMap("productIdTo", product.getString("productId"), "alsoComponents", Boolean.valueOf(false), "alsoVariants", Boolean.valueOf(false))); Debug.logInfo("Product [" + product.getString("productId") + "] Low Level Code [" + depthResult.get("lowLevelCode") + "]", module); } catch (Exception exc) { Debug.logWarning(exc.getMessage(), module); @@ -248,8 +253,8 @@ public class BOMServices { * @param context * @return */ - public static Map searchDuplicatedAncestor(DispatchContext dctx, Map context) { - Map result = new HashMap(); + public static Map<String, Object> searchDuplicatedAncestor(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue)context.get("userLogin"); @@ -281,9 +286,8 @@ public class BOMServices { * @param context * @return */ - public static Map getBOMTree(DispatchContext dctx, Map context) { - - Map result = new HashMap(); + public static Map<String, Object> getBOMTree(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue)context.get("userLogin"); @@ -332,13 +336,11 @@ public class BOMServices { * @param context * @return */ - public static Map getManufacturingComponents(DispatchContext dctx, Map context) { - - Map result = new HashMap(); + public static Map<String, Object> getManufacturingComponents(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue)context.get("userLogin"); - String productId = (String) context.get("productId"); BigDecimal quantity = (BigDecimal) context.get("quantity"); BigDecimal amount = (BigDecimal) context.get("amount"); @@ -370,7 +372,7 @@ public class BOMServices { // Components // BOMTree tree = null; - ArrayList components = new ArrayList(); + List<BOMNode> components = FastList.newInstance(); try { tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_SINGLE_LEVEL, delegator, dispatcher, userLogin); tree.setRootQuantity(quantity); @@ -385,8 +387,8 @@ public class BOMServices { // String workEffortId = null; try { - Map routingInMap = UtilMisc.toMap("productId", productId, "ignoreDefaultRouting", "Y", "userLogin", userLogin); - Map routingOutMap = dispatcher.runSync("getProductRouting", routingInMap); + Map<String, Object> routingInMap = UtilMisc.toMap("productId", productId, "ignoreDefaultRouting", "Y", "userLogin", userLogin); + Map<String, Object> routingOutMap = dispatcher.runSync("getProductRouting", routingInMap); GenericValue routing = (GenericValue)routingOutMap.get("routing"); if (routing == null) { // try to find a routing linked to the virtual product @@ -406,10 +408,10 @@ public class BOMServices { result.put("components", components); // also return a componentMap (useful in scripts and simple language code) - List componentsMap = new ArrayList(); - Iterator componentsIt = components.iterator(); + List<Map<String, Object>> componentsMap = FastList.newInstance(); + Iterator<BOMNode> componentsIt = components.iterator(); while (componentsIt.hasNext()) { - Map componentMap = new HashMap(); + Map<String, Object> componentMap = FastMap.newInstance(); BOMNode node = (BOMNode)componentsIt.next(); componentMap.put("product", node.getProduct()); componentMap.put("quantity", node.getQuantity()); @@ -419,8 +421,8 @@ public class BOMServices { return result; } - public static Map getNotAssembledComponents(DispatchContext dctx, Map context) { - Map result = new HashMap(); + public static Map<String, Object> getNotAssembledComponents(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String productId = (String) context.get("productId"); @@ -448,8 +450,8 @@ public class BOMServices { } BOMTree tree = null; - ArrayList components = new ArrayList(); - ArrayList notAssembledComponents = new ArrayList(); + List<BOMNode> components = FastList.newInstance(); + List<BOMNode> notAssembledComponents = FastList.newInstance(); try { tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin); tree.setRootQuantity(quantity); @@ -458,7 +460,7 @@ public class BOMServices { } catch (GenericEntityException gee) { return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage()); } - Iterator componentsIt = components.iterator(); + Iterator<BOMNode> componentsIt = components.iterator(); while (componentsIt.hasNext()) { BOMNode oneComponent = (BOMNode)componentsIt.next(); if (!oneComponent.isManufactured()) { @@ -472,8 +474,8 @@ public class BOMServices { // --------------------------------------------- // Service for the Product (Shipment) component // - public static Map createShipmentPackages(DispatchContext dctx, Map context) { - Map result = new HashMap(); + public static Map<String, Object> createShipmentPackages(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); @@ -481,7 +483,7 @@ public class BOMServices { String shipmentId = (String) context.get("shipmentId"); try { - List packages = delegator.findByAnd("ShipmentPackage", UtilMisc.toMap("shipmentId", shipmentId)); + List<GenericValue> packages = delegator.findByAnd("ShipmentPackage", UtilMisc.toMap("shipmentId", shipmentId)); if (!UtilValidate.isEmpty(packages)) { return ServiceUtil.returnError("Packages already found."); } @@ -489,23 +491,24 @@ public class BOMServices { return ServiceUtil.returnError("Error loading the ShipmentPackages"); } // ShipmentItems are loaded - List shipmentItems = null; + List<GenericValue> shipmentItems = null; try { shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId)); } catch (GenericEntityException gee) { return ServiceUtil.returnError("Error loading the ShipmentItems"); } - Iterator shipmentItemsIt = shipmentItems.iterator(); - HashMap orderReadHelpers = new HashMap(); - HashMap partyOrderShipments = new HashMap(); + Iterator<GenericValue> shipmentItemsIt = shipmentItems.iterator(); + Map<String, Object> orderReadHelpers = FastMap.newInstance(); + Map<String, Object> partyOrderShipments = FastMap.newInstance(); while (shipmentItemsIt.hasNext()) { GenericValue shipmentItem = (GenericValue)shipmentItemsIt.next(); // Get the OrderShipments - List orderShipments = null; + List<GenericValue> orderShipments = null; try { orderShipments = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", shipmentItem.getString("shipmentItemSeqId"))); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale)); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ManufacturingPackageConfiguratorError", locale)); } GenericValue orderShipment = org.ofbiz.entity.util.EntityUtil.getFirst(orderShipments); if (orderShipment != null && !orderReadHelpers.containsKey(orderShipment.getString("orderId"))) { @@ -513,41 +516,38 @@ public class BOMServices { } OrderReadHelper orderReadHelper = (OrderReadHelper)orderReadHelpers.get(orderShipment.getString("orderId")); if (orderReadHelper != null) { - Map orderShipmentReadMap = UtilMisc.toMap("orderShipment", orderShipment, "orderReadHelper", orderReadHelper); + Map<String, Object> orderShipmentReadMap = UtilMisc.toMap("orderShipment", orderShipment, "orderReadHelper", orderReadHelper); String partyId = (orderReadHelper.getPlacingParty() != null? orderReadHelper.getPlacingParty().getString("partyId"): null); // FIXME: is it the customer? if (partyId != null) { if (!partyOrderShipments.containsKey(partyId)) { - ArrayList orderShipmentReadMapList = new ArrayList(); + List<Map<String, Object>> orderShipmentReadMapList = FastList.newInstance(); partyOrderShipments.put(partyId, orderShipmentReadMapList); } - ArrayList orderShipmentReadMapList = (ArrayList)partyOrderShipments.get(partyId); + List<Map<String, Object>> orderShipmentReadMapList = UtilGenerics.checkList(partyOrderShipments.get(partyId)); orderShipmentReadMapList.add(orderShipmentReadMap); } } } // For each party: try to expand the shipment item products // (search for components that needs to be packaged). - Iterator partyOrderShipmentsIt = partyOrderShipments.entrySet().iterator(); - while (partyOrderShipmentsIt.hasNext()) { - Map.Entry partyOrderShipment = (Map.Entry)partyOrderShipmentsIt.next(); - String partyId = (String)partyOrderShipment.getKey(); - List orderShipmentReadMapList = (List)partyOrderShipment.getValue(); + for(Map.Entry<String, Object> partyOrderShipment : partyOrderShipments.entrySet()) { + List<Map<String, Object>> orderShipmentReadMapList = UtilGenerics.checkList(partyOrderShipment.getValue()); for (int i = 0; i < orderShipmentReadMapList.size(); i++) { - Map orderShipmentReadMap = (Map)orderShipmentReadMapList.get(i); + Map<String, Object> orderShipmentReadMap = UtilGenerics.checkMap(orderShipmentReadMapList.get(i)); GenericValue orderShipment = (GenericValue)orderShipmentReadMap.get("orderShipment"); OrderReadHelper orderReadHelper = (OrderReadHelper)orderShipmentReadMap.get("orderReadHelper"); GenericValue orderItem = orderReadHelper.getOrderItem(orderShipment.getString("orderItemSeqId")); // getProductsInPackages - Map serviceContext = new HashMap(); + Map<String, Object> serviceContext = FastMap.newInstance(); serviceContext.put("productId", orderItem.getString("productId")); serviceContext.put("quantity", orderShipment.getBigDecimal("quantity")); - Map resultService = null; + Map<String, Object> resultService = null; try { resultService = dispatcher.runSync("getProductsInPackages", serviceContext); } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale)); } - List productsInPackages = (List)resultService.get("productsInPackages"); + List<BOMNode> productsInPackages = UtilGenerics.checkList(resultService.get("productsInPackages")); if (productsInPackages.size() == 1) { BOMNode root = (BOMNode)productsInPackages.get(0); String rootProductId = (root.getSubstitutedNode() != null? root.getSubstitutedNode().getProduct().getString("productId"): root.getProduct().getString("productId")); @@ -565,24 +565,21 @@ public class BOMServices { } // Group together products and components // of the same box type. - HashMap boxTypes = new HashMap(); - partyOrderShipmentsIt = partyOrderShipments.entrySet().iterator(); - while (partyOrderShipmentsIt.hasNext()) { - HashMap boxTypeContent = new HashMap(); - Map.Entry partyOrderShipment = (Map.Entry)partyOrderShipmentsIt.next(); - String partyId = (String)partyOrderShipment.getKey(); - List orderShipmentReadMapList = (List)partyOrderShipment.getValue(); + Map<String, GenericValue> boxTypes = FastMap.newInstance(); + for(Map.Entry<String, Object> partyOrderShipment : partyOrderShipments.entrySet()) { + Map<String, List<Map<String, Object>>> boxTypeContent = FastMap.newInstance(); + List<Map<String, Object>> orderShipmentReadMapList = UtilGenerics.checkList(partyOrderShipment.getValue()); for (int i = 0; i < orderShipmentReadMapList.size(); i++) { - Map orderShipmentReadMap = (Map)orderShipmentReadMapList.get(i); + Map<String, Object> orderShipmentReadMap = UtilGenerics.checkMap(orderShipmentReadMapList.get(i)); GenericValue orderShipment = (GenericValue)orderShipmentReadMap.get("orderShipment"); OrderReadHelper orderReadHelper = (OrderReadHelper)orderShipmentReadMap.get("orderReadHelper"); - List productsInPackages = (List)orderShipmentReadMap.get("productsInPackages"); + List<BOMNode> productsInPackages = UtilGenerics.checkList(orderShipmentReadMap.get("productsInPackages")); if (productsInPackages != null) { // there are subcomponents: // this is a multi package shipment item for (int j = 0; j < productsInPackages.size(); j++) { BOMNode component = (BOMNode)productsInPackages.get(j); - HashMap boxTypeContentMap = new HashMap(); + Map<String, Object> boxTypeContentMap = FastMap.newInstance(); boxTypeContentMap.put("content", orderShipmentReadMap); boxTypeContentMap.put("componentIndex", Integer.valueOf(j)); GenericValue product = component.getProduct(); @@ -596,17 +593,17 @@ public class BOMServices { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale)); } boxTypes.put(boxTypeId, boxType); - boxTypeContent.put(boxTypeId, new ArrayList()); + List<Map<String, Object>> box = FastList.newInstance(); + boxTypeContent.put(boxTypeId, box); } - GenericValue boxType = (GenericValue)boxTypes.get(boxTypeId); - List boxTypeContentList = (List)boxTypeContent.get(boxTypeId); + List<Map<String, Object>> boxTypeContentList = UtilGenerics.checkList(boxTypeContent.get(boxTypeId)); boxTypeContentList.add(boxTypeContentMap); } } } else { // no subcomponents, the product has its own package: // this is a single package shipment item - HashMap boxTypeContentMap = new HashMap(); + Map<String, Object> boxTypeContentMap = FastMap.newInstance(); boxTypeContentMap.put("content", orderShipmentReadMap); GenericValue orderItem = orderReadHelper.getOrderItem(orderShipment.getString("orderItemSeqId")); GenericValue product = null; @@ -626,20 +623,18 @@ public class BOMServices { } boxTypes.put(boxTypeId, boxType); - boxTypeContent.put(boxTypeId, new ArrayList()); + List<Map<String, Object>> box = FastList.newInstance(); + boxTypeContent.put(boxTypeId, box); } - GenericValue boxType = (GenericValue)boxTypes.get(boxTypeId); - List boxTypeContentList = (List)boxTypeContent.get(boxTypeId); + List<Map<String, Object>> boxTypeContentList = UtilGenerics.checkList(boxTypeContent.get(boxTypeId)); boxTypeContentList.add(boxTypeContentMap); } } } // The packages and package contents are created. - Iterator boxTypeContentIt = boxTypeContent.entrySet().iterator(); - while (boxTypeContentIt.hasNext()) { - Map.Entry boxTypeContentEntry = (Map.Entry)boxTypeContentIt.next(); + for (Map.Entry<String, List<Map<String, Object>>> boxTypeContentEntry : boxTypeContent.entrySet()) { String boxTypeId = (String)boxTypeContentEntry.getKey(); - List contentList = (List)boxTypeContentEntry.getValue(); + List<Map<String, Object>> contentList = UtilGenerics.checkList(boxTypeContentEntry.getValue()); GenericValue boxType = (GenericValue)boxTypes.get(boxTypeId); BigDecimal boxWidth = boxType.getBigDecimal("boxLength"); BigDecimal totalWidth = BigDecimal.ZERO; @@ -648,10 +643,10 @@ public class BOMServices { } String shipmentPackageSeqId = null; for (int i = 0; i < contentList.size(); i++) { - Map contentMap = (Map)contentList.get(i); - Map content = (Map)contentMap.get("content"); + Map<String, Object> contentMap = UtilGenerics.checkMap(contentList.get(i)); + Map<String, Object> content = UtilGenerics.checkMap(contentMap.get("content")); OrderReadHelper orderReadHelper = (OrderReadHelper)content.get("orderReadHelper"); - List productsInPackages = (List)content.get("productsInPackages"); + List<BOMNode> productsInPackages = UtilGenerics.checkList(content.get("productsInPackages")); GenericValue orderShipment = (GenericValue)content.get("orderShipment"); GenericValue product = null; @@ -702,7 +697,7 @@ public class BOMServices { // If needed, create the package if (shipmentPackageSeqId == null) { try { - Map resultService = dispatcher.runSync("createShipmentPackage", UtilMisc.<String, Object>toMap("shipmentId", orderShipment.getString("shipmentId"), "shipmentBoxTypeId", boxTypeId, "userLogin", userLogin)); + Map<String, Object> resultService = dispatcher.runSync("createShipmentPackage", UtilMisc.<String, Object>toMap("shipmentId", orderShipment.getString("shipmentId"), "shipmentBoxTypeId", boxTypeId, "userLogin", userLogin)); shipmentPackageSeqId = (String)resultService.get("shipmentPackageSeqId"); } catch (GenericServiceException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale)); @@ -710,7 +705,7 @@ public class BOMServices { totalWidth = BigDecimal.ZERO; } try { - Map inputMap = null; + Map<String, Object> inputMap = null; if (subProduct) { inputMap = UtilMisc.toMap("shipmentId", orderShipment.getString("shipmentId"), "shipmentPackageSeqId", shipmentPackageSeqId, @@ -725,9 +720,10 @@ public class BOMServices { "userLogin", userLogin, "quantity", qty); } - Map resultService = dispatcher.runSync("createShipmentPackageContent", inputMap); + dispatcher.runSync("createShipmentPackageContent", inputMap); } catch (GenericServiceException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale)); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ManufacturingPackageConfiguratorError", locale)); } totalWidth = totalWidth.add(qty.multiply(productDepth)); if (qty.compareTo(maxQuantity) == 0) shipmentPackageSeqId = null; @@ -746,9 +742,8 @@ public class BOMServices { * @param context * @return */ - public static Map getProductsInPackages(DispatchContext dctx, Map context) { - - Map result = new HashMap(); + public static Map<String, Object> getProductsInPackages(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue)context.get("userLogin"); @@ -775,7 +770,7 @@ public class BOMServices { // Components // BOMTree tree = null; - ArrayList components = new ArrayList(); + List<BOMNode> components = FastList.newInstance(); try { tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin); tree.setRootQuantity(quantity); Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java?rev=1057884&r1=1057883&r2=1057884&view=diff ============================================================================== --- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java (original) +++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java Tue Jan 11 21:41:33 2011 @@ -20,27 +20,25 @@ package org.ofbiz.manufacturing.bom; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; +import javolution.util.FastList; + import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.util.EntityUtil; -import org.ofbiz.service.LocalDispatcher; - import org.ofbiz.product.store.ProductStoreWorker; +import org.ofbiz.service.LocalDispatcher; - /** It represents an (in-memory) bill of materials (in which each - * component is an BOMNode) - * Useful for tree traversal (breakdown, explosion, implosion). - */ - +/** It represents an (in-memory) bill of materials (in which each + * component is an BOMNode) + * Useful for tree traversal (breakdown, explosion, implosion). + */ public class BOMTree { public static final int EXPLOSION = 0; public static final int EXPLOSION_SINGLE_LEVEL = 1; @@ -103,15 +101,14 @@ public class BOMTree { String productIdForRules = productId; // The selected product features are loaded - List productFeaturesAppl = delegator.findByAnd("ProductFeatureAppl", - UtilMisc.toMap("productId", productId, - "productFeatureApplTypeId", "STANDARD_FEATURE")); - List productFeatures = new ArrayList(); + List<GenericValue> productFeaturesAppl = delegator.findByAnd("ProductFeatureAppl", + UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE")); + List<GenericValue> productFeatures = FastList.newInstance(); GenericValue oneProductFeatureAppl = null; for (int i = 0; i < productFeaturesAppl.size(); i++) { oneProductFeatureAppl = (GenericValue)productFeaturesAppl.get(i); productFeatures.add(delegator.findByPrimaryKey("ProductFeature", - UtilMisc.toMap("productFeatureId", oneProductFeatureAppl.getString("productFeatureId")))); + UtilMisc.toMap("productFeatureId", oneProductFeatureAppl.getString("productFeatureId")))); } // If the product is manufactured as a different product, @@ -119,9 +116,8 @@ public class BOMTree { GenericValue manufacturedAsProduct = manufacturedAsProduct(productId, inDate); // We load the information about the product that needs to be manufactured // from Product entity - GenericValue product = delegator.findByPrimaryKey("Product", - UtilMisc.toMap("productId", - (manufacturedAsProduct != null? manufacturedAsProduct.getString("productIdTo"): productId))); + GenericValue product = delegator.findByPrimaryKey("Product", + UtilMisc.toMap("productId", (manufacturedAsProduct != null? manufacturedAsProduct.getString("productIdTo"): productId))); if (product == null) return; BOMNode originalNode = new BOMNode(product, dispatcher, userLogin); originalNode.setTree(this); @@ -129,7 +125,7 @@ public class BOMTree { // the bill of materials of its virtual product (if the current // product is variant). if (!hasBom(product, inDate)) { - List virtualProducts = product.getRelatedByAnd("AssocProductAssoc", UtilMisc.toMap("productAssocTypeId", "PRODUCT_VARIANT")); + List<GenericValue> virtualProducts = product.getRelatedByAnd("AssocProductAssoc", UtilMisc.toMap("productAssocTypeId", "PRODUCT_VARIANT")); virtualProducts = EntityUtil.filterByDate(virtualProducts, inDate); GenericValue virtualProduct = EntityUtil.getFirst(virtualProducts); if (virtualProduct != null) { @@ -137,9 +133,8 @@ public class BOMTree { // load the new product productIdForRules = virtualProduct.getString("productId"); manufacturedAsProduct = manufacturedAsProduct(virtualProduct.getString("productId"), inDate); - product = delegator.findByPrimaryKey("Product", - UtilMisc.toMap("productId", - (manufacturedAsProduct != null? manufacturedAsProduct.getString("productIdTo"): virtualProduct.get("productId")))); + product = delegator.findByPrimaryKey("Product", + UtilMisc.toMap("productId", (manufacturedAsProduct != null? manufacturedAsProduct.getString("productIdTo"): virtualProduct.get("productId")))); } } if (product == null) return; @@ -167,7 +162,7 @@ public class BOMTree { } private GenericValue manufacturedAsProduct(String productId, Date inDate) throws GenericEntityException { - List manufacturedAsProducts = delegator.findByAnd("ProductAssoc", + List<GenericValue> manufacturedAsProducts = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_MANUFACTURED")); manufacturedAsProducts = EntityUtil.filterByDate(manufacturedAsProducts, inDate); @@ -179,7 +174,8 @@ public class BOMTree { } private boolean hasBom(GenericValue product, Date inDate) throws GenericEntityException { - List children = product.getRelatedByAnd("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", bomTypeId)); + List<GenericValue> children = product.getRelatedByAnd("MainProductAssoc", + UtilMisc.toMap("productAssocTypeId", bomTypeId)); children = EntityUtil.filterByDate(children, inDate); return UtilValidate.isNotEmpty(children); } @@ -191,7 +187,7 @@ public class BOMTree { * */ public boolean isConfigured() { - ArrayList notConfiguredParts = new ArrayList(); + List<BOMNode> notConfiguredParts = FastList.newInstance(); root.isConfigured(notConfiguredParts); return (notConfiguredParts.size() == 0); } @@ -264,40 +260,40 @@ public class BOMTree { } /** It visits the in-memory tree that represents a bill of materials - * and it collects info of its nodes in the ArrayList. + * and it collects info of its nodes in the List. * Method used for bom breakdown (explosion/implosion). - * @param arr The ArrayList used to collect tree info. + * @param arr The List used to collect tree info. * @param initialDepth The depth of the root node. */ - public void print(ArrayList arr, int initialDepth) { + public void print(List<BOMNode> arr, int initialDepth) { print(arr, initialDepth, true); } - public void print(ArrayList arr, int initialDepth, boolean excludeWIPs) { + public void print(List<BOMNode> arr, int initialDepth, boolean excludeWIPs) { if (root != null) { root.print(arr, getRootQuantity(), initialDepth, excludeWIPs); } } /** It visits the in-memory tree that represents a bill of materials - * and it collects info of its nodes in the ArrayList. + * and it collects info of its nodes in the List. * Method used for bom breakdown (explosion/implosion). - * @param arr The ArrayList used to collect tree info. + * @param arr The List used to collect tree info. */ - public void print(ArrayList arr) { + public void print(List<BOMNode> arr) { print(arr, 0, false); } - public void print(ArrayList arr, boolean excludeWIPs) { + public void print(List<BOMNode> arr, boolean excludeWIPs) { print(arr, 0, excludeWIPs); } /** It visits the in-memory tree that represents a bill of materials - * and it collects info of its nodes in the HashMap. + * and it collects info of its nodes in the Map. * Method used for bom summarized explosion. - * @param quantityPerNode The HashMap that will contain the summarized quantities per productId. + * @param quantityPerNode The Map that will contain the summarized quantities per productId. */ - public void sumQuantities(HashMap quantityPerNode) { + public void sumQuantities(Map<String, BOMNode> quantityPerNode) { if (root != null) { root.sumQuantity(quantityPerNode); } @@ -305,14 +301,14 @@ public class BOMTree { /** It visits the in-memory tree that represents a bill of materials * and it collects all the productId it contains. - * @return ArrayList containing all the tree's productId. + * @return List containing all the tree's productId. */ - public ArrayList getAllProductsId() { - ArrayList nodeArr = new ArrayList(); - ArrayList productsId = new ArrayList(); + public List<String> getAllProductsId() { + List<BOMNode> nodeArr = FastList.newInstance(); + List<String> productsId = FastList.newInstance(); print(nodeArr); for (int i = 0; i < nodeArr.size(); i++) { - productsId.add(((BOMNode)nodeArr.get(i)).getProduct().getString("productId")); + productsId.add((nodeArr.get(i)).getProduct().getString("productId")); } return productsId; } @@ -345,13 +341,13 @@ public class BOMTree { facilityId = shipment.getString("originFacilityId"); } } - Map tmpMap = root.createManufacturingOrder(facilityId, date, workEffortName, description, routingId, orderId, orderItemSeqId, shipGroupSeqId, shipmentId, true, true); + Map<String, Object> tmpMap = root.createManufacturingOrder(facilityId, date, workEffortName, description, routingId, orderId, orderItemSeqId, shipGroupSeqId, shipmentId, true, true); workEffortId = (String)tmpMap.get("productionRunId"); } return workEffortId; } - public void getProductsInPackages(ArrayList arr) { + public void getProductsInPackages(List<BOMNode> arr) { if (root != null) { root.getProductsInPackages(arr, getRootQuantity(), 0, false); } |
| Free forum by Nabble | Edit this page |
