Author: jleroux Date: Sat Aug 9 13:18:14 2014 New Revision: 1616949 URL: http://svn.apache.org/r1616949 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/release12.04/ (props changed) ofbiz/branches/release12.04/applications/order/src/org/ofbiz/order/order/OrderServices.java Propchange: ofbiz/branches/release12.04/ ------------------------------------------------------------------------------ Merged /ofbiz/trunk:r1616940 Modified: ofbiz/branches/release12.04/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=1616949&r1=1616948&r2=1616949&view=diff ============================================================================== --- ofbiz/branches/release12.04/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/branches/release12.04/applications/order/src/org/ofbiz/order/order/OrderServices.java Sat Aug 9 13:18:14 2014 @@ -3620,17 +3620,9 @@ 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()) { + for (String key : itemQtyMap.keySet()) { String quantityStr = itemQtyMap.get(key); BigDecimal groupQty = BigDecimal.ZERO; try { @@ -3707,6 +3699,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); @@ -3722,37 +3722,41 @@ 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()) { + for (String key : itemQtyMap.keySet()) { String quantityStr = itemQtyMap.get(key); BigDecimal groupQty = BigDecimal.ZERO; try { @@ -3763,6 +3767,7 @@ public class OrderServices { } String[] itemInfo = key.split(":"); + @SuppressWarnings("unused") int groupIdx = -1; try { groupIdx = Integer.parseInt(itemInfo[1]); @@ -3774,10 +3779,10 @@ public class OrderServices { // 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); + 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); } } @@ -4040,7 +4045,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 { @@ -4090,7 +4095,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. @@ -4146,10 +4151,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);