You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2014/08/09 15:08:26 UTC

svn commit: r1616943 - in /ofbiz/branches/release13.07: ./ applications/order/src/org/ofbiz/order/order/OrderServices.java

Author: jleroux
Date: Sat Aug  9 13:08:26 2014
New Revision: 1616943

URL: http://svn.apache.org/r1616943
Log:
"Applied fix from trunk for revision: 1616940" 
------------------------------------------------------------------------
r1616940 | jleroux | 2014-08-09 15:05:05 +0200 (sam. 09 août 2014) | 2 lignes

The updateApprovedOrderItems defines the itemAttributesMap, itemEstimatedDeliveryDateMap and itemEstimatedShipDateMap IN parameters as optional. But if you use this service out of an event context then you cross NPEs
This is because in the context of an event the missing parameters are initialised as empty. This hid the issue so far because updateApprovedOrderItems is only used once, called by an event.
------------------------------------------------------------------------


Modified:
    ofbiz/branches/release13.07/   (props changed)
    ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java

Propchange: ofbiz/branches/release13.07/
------------------------------------------------------------------------------
  Merged /ofbiz/trunk:r1616940

Modified: ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=1616943&r1=1616942&r2=1616943&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java Sat Aug  9 13:08:26 2014
@@ -3631,40 +3631,32 @@ public class OrderServices {
                     "OrderShoppingCartEmpty", locale));
         }
 
-        // go through the item attributes map once to get a list of key names
-        Set<String> attributeNames =FastSet.newInstance();
-        Set<String> keys  = itemAttributesMap.keySet();
-        for (String key : keys) {
-            String[] attributeInfo = key.split(":");
-            attributeNames.add(attributeInfo[0]);
-        }
-
         // go through the item map and obtain the totals per item
         Map<String, BigDecimal> itemTotals = new HashMap<String, BigDecimal>();
-        for(String key : itemQtyMap.keySet()) {
-            String quantityStr = itemQtyMap.get(key);
-            BigDecimal groupQty = BigDecimal.ZERO;
-            try {
-                groupQty = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, "BigDecimal", null, locale);
-            } catch (GeneralException e) {
-                Debug.logError(e, module);
-                return ServiceUtil.returnError(e.getMessage());
-            }
-
-            if (groupQty.compareTo(BigDecimal.ONE) < 0) {
-                return ServiceUtil.returnError(UtilProperties.getMessage(resource,
-                        "OrderItemQtyMustBePositive", locale));
-            }
-
-            String[] itemInfo = key.split(":");
-            BigDecimal tally = itemTotals.get(itemInfo[0]);
-            if (tally == null) {
-                tally = groupQty;
-            } else {
-                tally = tally.add(groupQty);
+            for (String key : itemQtyMap.keySet()) {
+                String quantityStr = itemQtyMap.get(key);
+                BigDecimal groupQty = BigDecimal.ZERO;
+                try {
+                    groupQty = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, "BigDecimal", null, locale);
+                } catch (GeneralException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
+    
+                if (groupQty.compareTo(BigDecimal.ONE) < 0) {
+                    return ServiceUtil.returnError(UtilProperties.getMessage(resource,
+                            "OrderItemQtyMustBePositive", locale));
+                }
+    
+                String[] itemInfo = key.split(":");
+                BigDecimal tally = itemTotals.get(itemInfo[0]);
+                if (tally == null) {
+                    tally = groupQty;
+                } else {
+                    tally = tally.add(groupQty);
+                }
+                itemTotals.put(itemInfo[0], tally);
             }
-            itemTotals.put(itemInfo[0], tally);
-        }
 
         // set the items amount/price
         for(String itemSeqId : itemTotals.keySet()) {
@@ -3718,6 +3710,14 @@ public class OrderServices {
 
                 // update the order item attributes
                 if (itemAttributesMap != null) {
+                    // go through the item attributes map once to get a list of key names
+                    Set<String> attributeNames =FastSet.newInstance();
+                    Set<String> keys  = itemAttributesMap.keySet();
+                    for (String key : keys) {
+                        String[] attributeInfo = key.split(":");
+                        attributeNames.add(attributeInfo[0]);
+                    }
+                    
                     String attrValue = null;
                     for (String attrName : attributeNames) {
                         attrValue = itemAttributesMap.get(attrName + ":" + itemSeqId);
@@ -3733,64 +3733,69 @@ public class OrderServices {
             }
         }
         // Create Estimated Delivery dates
-        for (Map.Entry<String, String> entry : itemEstimatedDeliveryDateMap.entrySet()) {
-            String itemSeqId =  entry.getKey();
-
-            // ignore internationalised variant of dates
-            if (!itemSeqId.endsWith("_i18n")) {
-                String estimatedDeliveryDate = entry.getValue();
-                if (UtilValidate.isNotEmpty(estimatedDeliveryDate)) {
-                    Timestamp deliveryDate = Timestamp.valueOf(estimatedDeliveryDate);
-                    ShoppingCartItem cartItem = cart.findCartItem(itemSeqId);
-                    cartItem.setDesiredDeliveryDate(deliveryDate);
+        if (null != itemEstimatedDeliveryDateMap) {
+            for (Map.Entry<String, String> entry : itemEstimatedDeliveryDateMap.entrySet()) {
+                String itemSeqId =  entry.getKey();
+
+                // ignore internationalised variant of dates
+                if (!itemSeqId.endsWith("_i18n")) {
+                    String estimatedDeliveryDate = entry.getValue();
+                    if (UtilValidate.isNotEmpty(estimatedDeliveryDate)) {
+                        Timestamp deliveryDate = Timestamp.valueOf(estimatedDeliveryDate);
+                        ShoppingCartItem cartItem = cart.findCartItem(itemSeqId);
+                        cartItem.setDesiredDeliveryDate(deliveryDate);
+                    }
                 }
             }
         }
 
         // Create Estimated ship dates
-        for (Map.Entry<String, String> entry : itemEstimatedShipDateMap.entrySet()) {
-            String itemSeqId =  entry.getKey();
-
-            // ignore internationalised variant of dates
-            if (!itemSeqId.endsWith("_i18n")) {
-                String estimatedShipDate = entry.getValue();
-                if (UtilValidate.isNotEmpty(estimatedShipDate)) {
-                    Timestamp shipDate = Timestamp.valueOf(estimatedShipDate);
-                    ShoppingCartItem cartItem = cart.findCartItem(itemSeqId);
-                    cartItem.setEstimatedShipDate(shipDate);
+        if (null != itemEstimatedShipDateMap) {
+            for (Map.Entry<String, String> entry : itemEstimatedShipDateMap.entrySet()) {
+                String itemSeqId =  entry.getKey();
+
+                // ignore internationalised variant of dates
+                if (!itemSeqId.endsWith("_i18n")) {
+                    String estimatedShipDate = entry.getValue();
+                    if (UtilValidate.isNotEmpty(estimatedShipDate)) {
+                        Timestamp shipDate = Timestamp.valueOf(estimatedShipDate);
+                        ShoppingCartItem cartItem = cart.findCartItem(itemSeqId);
+                        cartItem.setEstimatedShipDate(shipDate);
+                    }
                 }
             }
         }
 
         // update the group amounts
-        for(String key : itemQtyMap.keySet()) {
-            String quantityStr = itemQtyMap.get(key);
-            BigDecimal groupQty = BigDecimal.ZERO;
-            try {
-                groupQty = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, "BigDecimal", null, locale);
-            } catch (GeneralException e) {
-                Debug.logError(e, module);
-                return ServiceUtil.returnError(e.getMessage());
-            }
+            for (String key : itemQtyMap.keySet()) {
+                String quantityStr = itemQtyMap.get(key);
+                BigDecimal groupQty = BigDecimal.ZERO;
+                try {
+                    groupQty = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, "BigDecimal", null, locale);
+                } catch (GeneralException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
 
-            String[] itemInfo = key.split(":");
-            int groupIdx = -1;
-            try {
-                groupIdx = Integer.parseInt(itemInfo[1]);
-            } catch (NumberFormatException e) {
-                Debug.logError(e, module);
-                return ServiceUtil.returnError(e.getMessage());
-            }
+                String[] itemInfo = key.split(":");
+                @SuppressWarnings("unused")
+                int groupIdx = -1;
+                try {
+                    groupIdx = Integer.parseInt(itemInfo[1]);
+                } catch (NumberFormatException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
 
-            // set the group qty
-            ShoppingCartItem cartItem = cart.findCartItem(itemInfo[0]);
-            if (cartItem != null) {
+                // set the group qty
+                ShoppingCartItem cartItem = cart.findCartItem(itemInfo[0]);
+                if (cartItem != null) {
                 Debug.logInfo("Shipping info (before) for group #" + (groupIdx-1) + " [" + cart.getShipmentMethodTypeId(groupIdx-1) + " / " + cart.getCarrierPartyId(groupIdx-1) + "]", module);
                 cart.setItemShipGroupQty(cartItem, groupQty, groupIdx - 1);
                 Debug.logInfo("Set ship group qty: [" + itemInfo[0] + " / " + itemInfo[1] + " (" + (groupIdx-1) + ")] " + groupQty, module);
                 Debug.logInfo("Shipping info (after) for group #" + (groupIdx-1) + " [" + cart.getShipmentMethodTypeId(groupIdx-1) + " / " + cart.getCarrierPartyId(groupIdx-1) + "]", module);
+                }
             }
-        }
 
         // save all the updated information
         try {
@@ -4051,7 +4056,7 @@ public class OrderServices {
             cart.setItemShipGroupEstimate(shippingTotal, gi);
         }
 
-        // calc the sales tax        
+        // calc the sales tax
         CheckOutHelper coh = new CheckOutHelper(dispatcher, delegator, cart);
         if (calcTax) {
             try {
@@ -4101,7 +4106,7 @@ public class OrderServices {
                 for (GenericValue stored: toStore) {
                     if ("OrderAdjustment".equals(stored.getEntityName())) {
                         if (("SHIPPING_CHARGES".equals(stored.get("orderAdjustmentTypeId")) ||
-                                "SALES_TAX".equals(stored.get("orderAdjustmentTypeId"))) &&
+                               "SALES_TAX".equals(stored.get("orderAdjustmentTypeId"))) &&
                                 stored.get("orderId").equals(orderId) &&
                                 stored.get("shipGroupSeqId").equals(shipGroupSeqId)) {
                             // Removing objects from toStore list for old Shipping and Handling Charges Adjustment and Sales Tax Adjustment.
@@ -4157,10 +4162,10 @@ public class OrderServices {
 
         // get the promo uses and codes
         for (String promoCodeEntered : cart.getProductPromoCodesEntered()) {
-            GenericValue orderProductPromoCode = delegator.makeValue("OrderProductPromoCode");                                   
+            GenericValue orderProductPromoCode = delegator.makeValue("OrderProductPromoCode");
             orderProductPromoCode.set("orderId", orderId);
             orderProductPromoCode.set("productPromoCodeId", promoCodeEntered);
-            toStore.add(orderProductPromoCode);                                    
+            toStore.add(orderProductPromoCode);
         }
         for (GenericValue promoUse : cart.makeProductPromoUses()) {
             promoUse.set("orderId", orderId);