Author: jleroux
Date: Fri Jan 23 13:44:42 2009 New Revision: 737200 URL: http://svn.apache.org/viewvc?rev=737200&view=rev Log: A slightly modified patch from Stephen Rufle "OrderServices.updateApprovedOrderItems should update OrderItemAttributes" '(https://issues.apache.org/jira/browse/OFBIZ-2115) - OFBIZ-2115 Modified: ofbiz/trunk/applications/order/servicedef/services.xml ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Modified: ofbiz/trunk/applications/order/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?rev=737200&r1=737199&r2=737200&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services.xml Fri Jan 23 13:44:42 2009 @@ -301,6 +301,7 @@ <attribute name="overridePriceMap" type="Map" mode="IN" string-map-prefix="opm_" optional="false"/> <attribute name="itemReasonMap" type="Map" mode="IN" string-map-prefix="irm_" optional="true"/> <attribute name="itemCommentMap" type="Map" mode="IN" string-map-prefix="icm_" optional="true"/> + <attribute name="itemAttributesMap" type="Map" mode="IN" string-map-prefix="iam_" optional="true"/> <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="OUT" optional="false"/> </service> @@ -317,6 +318,8 @@ <attribute name="overridePrice" type="String" mode="IN" optional="true"/> <attribute name="reasonEnumId" type="String" mode="IN" optional="true"/> <attribute name="changeComments" type="String" mode="IN" optional="true"/> + <attribute name="itemDesiredDeliveryDate" type="Timestamp" mode="IN" optional="true"/> + <attribute name="itemAttributesMap" type="Map" mode="IN" optional="true"/> <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="OUT" optional="false"/> </service> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=737200&r1=737199&r2=737200&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Fri Jan 23 13:44:42 2009 @@ -26,6 +26,7 @@ import javolution.util.FastList; import javolution.util.FastMap; +import javolution.util.FastSet; import org.ofbiz.base.util.*; import org.ofbiz.base.util.collections.ResourceBundleMapWrapper; @@ -3259,7 +3260,9 @@ BigDecimal basePrice = (BigDecimal) context.get("basePrice"); BigDecimal quantity = (BigDecimal) context.get("quantity"); BigDecimal amount = (BigDecimal) context.get("amount"); + Timestamp itemDesiredDeliveryDate = (Timestamp) context.get("itemDesiredDeliveryDate"); String overridePrice = (String) context.get("overridePrice"); + Map itemAttributesMap = (Map) context.get("itemAttributesMap"); String reasonEnumId = (String) context.get("reasonEnumId"); String changeComments = (String) context.get("changeComments"); @@ -3304,6 +3307,7 @@ // set the item in the selected ship group + item.setShipBeforeDate(itemDesiredDeliveryDate); cart.setItemShipGroupQty(item, item.getQuantity(), shipGroupIdx); } catch (CartItemModifyException e) { Debug.logError(e, module); @@ -3349,6 +3353,7 @@ Map itemQtyMap = (Map) context.get("itemQtyMap"); Map itemReasonMap = (Map) context.get("itemReasonMap"); Map itemCommentMap = (Map) context.get("itemCommentMap"); + Map itemAttributesMap = (Map) context.get("itemAttributesMap"); // obtain a shopping cart object for updating ShoppingCart cart = null; @@ -3361,6 +3366,14 @@ return ServiceUtil.returnError("ERROR: Null shopping cart object returned!"); } + // 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 itemTotals = new HashMap(); Iterator i = itemQtyMap.keySet().iterator(); @@ -3433,6 +3446,19 @@ return ServiceUtil.returnError("Item description must not be empty"); } } + + // update the order item attributes + if (itemAttributesMap != null) { + String attrValue = null; + for (String attrName : attributeNames) { + attrValue = (String) itemAttributesMap.get(attrName + ":" + itemSeqId); + if (UtilValidate.isNotEmpty(attrName)) { + cartItem.setOrderItemAttribute(attrName, attrValue); + Debug.log("Set item attribute Name: [" + itemSeqId + "] " + attrName + " , Value:" + attrValue, module); + } + } + } + } else { Debug.logInfo("Unable to locate shopping cart item for seqId #" + itemSeqId, module); } @@ -3694,13 +3720,18 @@ throw new GeneralException(ServiceUtil.getErrorMessage(validateResp)); } - // get the new orderItems, adjustments, shipping info and payments from the cart + // get the new orderItems, adjustments, shipping info, payments and order item atrributes from the cart List<Map> modifiedItems = FastList.newInstance(); List toStore = new LinkedList(); toStore.addAll(cart.makeOrderItems()); toStore.addAll(cart.makeAllAdjustments()); toStore.addAll(cart.makeAllShipGroupInfos()); toStore.addAll(cart.makeAllOrderPaymentInfos(dispatcher)); + toStore.addAll(cart.makeAllOrderItemAttributes(orderId, ShoppingCart.FILLED_ONLY)); + + // get the empty order item atrributes from the cart and remove them + List toRemove = FastList.newInstance(); + toRemove.addAll(cart.makeAllOrderItemAttributes(orderId, ShoppingCart.EMPTY_ONLY)); // set the orderId & other information on all new value objects List dropShipGroupIds = FastList.newInstance(); // this list will contain the ids of all the ship groups for drop shipments (no reservations) @@ -3814,7 +3845,15 @@ } Debug.log("To Store Contains: " + toStore, module); - // store the new items/adjustments + // remove any order item attributes that were set to empty + try { + delegator.removeAll(toRemove,true); + } catch (GenericEntityException e) { + Debug.logError(e, module); + throw new GeneralException(e.getMessage()); + } + + // store the new items/adjustments/order item attributes try { delegator.storeAll(toStore); } catch (GenericEntityException e) { Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?rev=737200&r1=737199&r2=737200&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Fri Jan 23 13:44:42 2009 @@ -54,6 +54,11 @@ public static final String module = ShoppingCart.class.getName(); public static final String resource_error = "OrderErrorUiLabels"; + // modes for getting OrderItemAttributes + public static final int ALL = 1; + public static final int EMPTY_ONLY = 2; + public static final int FILLED_ONLY = 3; + // scales and rounding modes for BigDecimal math public static final int scale = UtilNumber.getBigDecimalScale("order.decimals"); public static final int rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding"); @@ -100,7 +105,7 @@ private boolean orderTermSet = false; private List orderTerms = new LinkedList(); - private List cartLines = FastList.newInstance(); + private List<ShoppingCartItem> cartLines = FastList.newInstance(); private Map itemGroupByNumberMap = FastMap.newInstance(); protected long nextGroupNumber = 1; private List paymentInfo = FastList.newInstance(); @@ -631,9 +636,7 @@ List itemsToReturn = FastList.newInstance(); // Check for existing cart item. - Iterator cartItemIter = this.cartLines.iterator(); - while (cartItemIter.hasNext()) { - ShoppingCartItem cartItem = (ShoppingCartItem) cartItemIter.next(); + for (ShoppingCartItem cartItem : cartLines) { if (UtilValidate.isNotEmpty(groupNumber) && !cartItem.isInItemGroup(groupNumber)) { continue; } @@ -652,9 +655,7 @@ List itemsToReturn = FastList.newInstance(); try { // Check for existing cart item - Iterator cartItemIter = this.cartLines.iterator(); - while (cartItemIter.hasNext()) { - ShoppingCartItem cartItem = (ShoppingCartItem) cartItemIter.next(); + for (ShoppingCartItem cartItem : cartLines) { //Debug.logInfo("Checking cartItem with product [" + cartItem.getProductId() + "] becuase that is in group [" + (cartItem.getItemGroup()==null ? "no group" : cartItem.getItemGroup().getGroupNumber()) + "]", module); if (UtilValidate.isNotEmpty(groupNumber) && !cartItem.isInItemGroup(groupNumber)) { @@ -898,9 +899,7 @@ public List getCartItemsInNoGroup() { List cartItemList = FastList.newInstance(); - Iterator cartLineIter = this.cartLines.iterator(); - while (cartLineIter.hasNext()) { - ShoppingCartItem cartItem = (ShoppingCartItem) cartLineIter.next(); + for (ShoppingCartItem cartItem : cartLines) { if (cartItem.getItemGroup() == null) { cartItemList.add(cartItem); } @@ -912,9 +911,7 @@ List cartItemList = FastList.newInstance(); ShoppingCart.ShoppingCartItemGroup itemGroup = this.getItemGroupByNumber(groupNumber); if (itemGroup != null) { - Iterator cartLineIter = this.cartLines.iterator(); - while (cartLineIter.hasNext()) { - ShoppingCartItem cartItem = (ShoppingCartItem) cartLineIter.next(); + for (ShoppingCartItem cartItem : cartLines) { if (itemGroup.equals(cartItem.getItemGroup())) { cartItemList.add(cartItem); } @@ -2099,7 +2096,7 @@ return true; } - protected void cleanUpShipGroups() { + public void cleanUpShipGroups() { for (int i = 0; i < this.shipInfo.size(); i++) { CartShipInfo csi = this.getShipInfo(i); Iterator si = csi.shipItemInfo.keySet().iterator(); @@ -3394,10 +3391,7 @@ synchronized (cartLines) { List result = FastList.newInstance(); - Iterator itemIter = cartLines.iterator(); - while (itemIter.hasNext()) { - ShoppingCartItem item = (ShoppingCartItem) itemIter.next(); - + for (ShoppingCartItem item : cartLines) { if (UtilValidate.isEmpty(item.getOrderItemSeqId())) { String orderItemSeqId = UtilFormatOut.formatPaddedNumber(nextItemSeq, 5); item.setOrderItemSeqId(orderItemSeqId); @@ -3469,10 +3463,7 @@ /** create WorkEfforts from the shoppingcart items when itemType = RENTAL_ORDER_ITEM */ public List makeWorkEfforts() { List allWorkEfforts = new LinkedList(); - Iterator itemIter = cartLines.iterator(); - - while (itemIter.hasNext()) { - ShoppingCartItem item = (ShoppingCartItem) itemIter.next(); + for (ShoppingCartItem item : cartLines) { if ("RENTAL_ORDER_ITEM".equals(item.getItemType())) { // prepare workeffort when the order item is a rental item GenericValue workEffort = getDelegator().makeValue("WorkEffort"); workEffort.set("workEffortId",item.getOrderItemSeqId()); // fill temporary with sequence number @@ -3532,10 +3523,7 @@ } // add all of the item adjustments to this list too - Iterator itemIter = cartLines.iterator(); - - while (itemIter.hasNext()) { - ShoppingCartItem item = (ShoppingCartItem) itemIter.next(); + for (ShoppingCartItem item : cartLines) { Collection adjs = item.getAdjustments(); if (adjs != null) { @@ -3670,10 +3658,7 @@ List allInfos = new LinkedList(); // add all of the item adjustments to this list too - Iterator itemIter = cartLines.iterator(); - - while (itemIter.hasNext()) { - ShoppingCartItem item = (ShoppingCartItem) itemIter.next(); + for (ShoppingCartItem item : cartLines) { Collection infos = item.getOrderItemPriceInfos(); if (infos != null) { @@ -3764,10 +3749,7 @@ public List makeAllOrderItemContactMechs() { List allOrderContactMechs = new LinkedList(); - Iterator itemIter = cartLines.iterator(); - - while (itemIter.hasNext()) { - ShoppingCartItem item = (ShoppingCartItem) itemIter.next(); + for (ShoppingCartItem item : cartLines) { Map itemContactMechIds = item.getOrderItemContactMechIds(); if (itemContactMechIds != null) { @@ -3801,35 +3783,96 @@ } public List makeAllOrderItemAttributes() { - List allOrderItemAttributes = new LinkedList(); + return makeAllOrderItemAttributes(null, ALL); + } - Iterator itemIter = cartLines.iterator(); - while (itemIter.hasNext()) { - ShoppingCartItem item = (ShoppingCartItem) itemIter.next(); - Map attrs = item.getOrderItemAttributes(); - Iterator i = attrs.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry entry = (Map.Entry) i.next(); - GenericValue itemAtt = this.getDelegator().makeValue("OrderItemAttribute"); - itemAtt.set("orderItemSeqId", item.getOrderItemSeqId()); - itemAtt.set("attrName", entry.getKey()); - itemAtt.set("attrValue", entry.getValue()); - allOrderItemAttributes.add(itemAtt); + public List makeAllOrderItemAttributes(String orderId, int mode) { + + // now build order item attributes + synchronized (cartLines) { + List result = FastList.newInstance(); + + for (ShoppingCartItem item : cartLines) { + Map orderItemAttributes = item.getOrderItemAttributes(); + Iterator attributesIter = orderItemAttributes.keySet().iterator(); + while (attributesIter.hasNext()) { + String key = (String) attributesIter.next(); + String value = (String) orderItemAttributes.get(key); + + GenericValue orderItemAttribute = getDelegator().makeValue("OrderItemAttribute"); + if (UtilValidate.isNotEmpty(orderId)) { + orderItemAttribute.set("orderId", orderId); + } + + orderItemAttribute.set("orderItemSeqId", item.getOrderItemSeqId()); + orderItemAttribute.set("attrName", key); + orderItemAttribute.set("attrValue", value); + + switch (mode) { + case ALL: + result.add(orderItemAttribute); + break; + case FILLED_ONLY: + if (UtilValidate.isNotEmpty(value)) { + result.add(orderItemAttribute); + } + break; + case EMPTY_ONLY: + if (UtilValidate.isEmpty(value)) { + result.add(orderItemAttribute); + } + break; + default: + result.add(orderItemAttribute); + break; + } + } } + return result; } - return allOrderItemAttributes; } public List makeAllOrderAttributes() { + + return makeAllOrderAttributes(null, ALL); + } + + public List makeAllOrderAttributes(String orderId, int mode) { + List allOrderAttributes = new LinkedList(); Iterator i = orderAttributes.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); GenericValue orderAtt = this.getDelegator().makeValue("OrderAttribute"); - orderAtt.put("attrName", entry.getKey()); - orderAtt.put("attrValue", entry.getValue()); - allOrderAttributes.add(orderAtt); + if (UtilValidate.isNotEmpty(orderId)) { + orderAtt.set("orderId", orderId); + } + String key = (String) entry.getKey(); + String value = (String) entry.getValue(); + + orderAtt.put("attrName", key); + orderAtt.put("attrValue", value); + + switch (mode) { + case ALL: + allOrderAttributes.add(orderAtt); + break; + case FILLED_ONLY: + if (UtilValidate.isNotEmpty(value)) { + allOrderAttributes.add(orderAtt); + } + break; + case EMPTY_ONLY: + if (UtilValidate.isEmpty(value)) { + allOrderAttributes.add(orderAtt); + } + break; + default: + allOrderAttributes.add(orderAtt); + break; + } + } return allOrderAttributes; } @@ -3837,10 +3880,7 @@ public List makeAllOrderItemAssociations() { List allOrderItemAssociations = new LinkedList(); - Iterator itemIter = cartLines.iterator(); - - while (itemIter.hasNext()) { - ShoppingCartItem item = (ShoppingCartItem) itemIter.next(); + for (ShoppingCartItem item : cartLines) { String requirementId = item.getRequirementId(); if (requirementId != null) { try { |
Free forum by Nabble | Edit this page |