You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2009/10/17 11:38:02 UTC

svn commit: r826206 - /ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java

Author: lektran
Date: Sat Oct 17 09:38:02 2009
New Revision: 826206

URL: http://svn.apache.org/viewvc?rev=826206&view=rev
Log:
Prevent an NPE when a primaryOrderId hasn't been supplied, also set partyIdFrom using the facility.ownerPartyId in this situation.
(This bug was exposed using the unit tests)

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java?rev=826206&r1=826205&r2=826206&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java Sat Oct 17 09:38:02 2009
@@ -725,25 +725,33 @@
         if (UtilValidate.isNotEmpty(orderRoleShipTo)) {
             newShipment.put("partyIdTo", orderRoleShipTo.getString("partyId"));
         }
-        String partyIdFrom = null; 
-        GenericValue orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", primaryOrderId, "shipGroupSeqId", primaryShipGrp)));
-        if (UtilValidate.isNotEmpty(orderItemShipGroup.getString("vendorPartyId"))) {
-            partyIdFrom = orderItemShipGroup.getString("vendorPartyId");
-        } else if (UtilValidate.isNotEmpty(orderItemShipGroup.getString("facilityId"))) {
-            GenericValue facility = delegator.findOne("Facility", UtilMisc.toMap("facilityId", orderItemShipGroup.getString("facilityId")), false);
+        String partyIdFrom = null;
+        if (primaryOrderId != null) {
+            GenericValue orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", primaryOrderId, "shipGroupSeqId", primaryShipGrp)));
+            if (UtilValidate.isNotEmpty(orderItemShipGroup.getString("vendorPartyId"))) {
+                partyIdFrom = orderItemShipGroup.getString("vendorPartyId");
+            } else if (UtilValidate.isNotEmpty(orderItemShipGroup.getString("facilityId"))) {
+                GenericValue facility = delegator.findOne("Facility", UtilMisc.toMap("facilityId", orderItemShipGroup.getString("facilityId")), false);
+                if (UtilValidate.isNotEmpty(facility.getString("ownerPartyId"))) {
+                    partyIdFrom = facility.getString("ownerPartyId");
+                }
+            }
+            if (UtilValidate.isEmpty(partyIdFrom)) {
+                GenericValue orderRoleShipFrom = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", primaryOrderId, "roleTypeId", "SHIP_FROM_VENDOR")));
+                if (UtilValidate.isNotEmpty(orderRoleShipFrom)) {
+                    partyIdFrom = orderRoleShipFrom.getString("partyId");
+                } else {
+                    orderRoleShipFrom = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", primaryOrderId, "roleTypeId", "BILL_FROM_VENDOR")));
+                    partyIdFrom = orderRoleShipFrom.getString("partyId");
+                }
+            }
+        } else if (this.facilityId != null) {
+            GenericValue facility = delegator.findOne("Facility", UtilMisc.toMap("facilityId", this.facilityId), false);
             if (UtilValidate.isNotEmpty(facility.getString("ownerPartyId"))) {
                 partyIdFrom = facility.getString("ownerPartyId");
             }
         }
-        if (UtilValidate.isEmpty(partyIdFrom)) {
-            GenericValue orderRoleShipFrom = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", primaryOrderId, "roleTypeId", "SHIP_FROM_VENDOR")));
-            if (UtilValidate.isNotEmpty(orderRoleShipFrom)) {
-                partyIdFrom = orderRoleShipFrom.getString("partyId");
-            } else {
-                orderRoleShipFrom = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", primaryOrderId, "roleTypeId", "BILL_FROM_VENDOR")));
-                partyIdFrom = orderRoleShipFrom.getString("partyId");
-            }
-        }
+
         newShipment.put("partyIdFrom", partyIdFrom);
         Debug.log("Creating new shipment with context: " + newShipment, module);
         Map<String, Object> newShipResp = this.getDispatcher().runSync("createShipment", newShipment);