KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > shipment > picklist > PickListServices


1 /*
2  * $Id$
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.shipment.picklist;
26
27 import java.util.Map JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 import org.ofbiz.service.DispatchContext;
33 import org.ofbiz.service.ServiceUtil;
34 import org.ofbiz.entity.condition.EntityExpr;
35 import org.ofbiz.entity.condition.EntityOperator;
36 import org.ofbiz.entity.condition.EntityConditionList;
37 import org.ofbiz.entity.condition.EntityCondition;
38 import org.ofbiz.entity.GenericDelegator;
39 import org.ofbiz.entity.GenericEntityException;
40 import org.ofbiz.base.util.UtilMisc;
41 import org.ofbiz.base.util.Debug;
42
43 /**
44  *
45  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
46  * @version $Rev: 5829 $
47  * @since 3.5
48  */

49 public class PickListServices {
50
51     public static final String JavaDoc module = PickListServices.class.getName();
52
53     public static Map JavaDoc convertOrderIdListToHeaders(DispatchContext dctx, Map JavaDoc context) {
54         GenericDelegator delegator = dctx.getDelegator();
55
56         List JavaDoc orderHeaderList = (List JavaDoc) context.get("orderHeaderList");
57         List JavaDoc orderIdList = (List JavaDoc) context.get("orderIdList");
58
59         // we don't want to process if there is already a header list
60
if (orderHeaderList == null) {
61             // convert the ID list to headers
62
if (orderIdList != null) {
63                 List JavaDoc conditionList1 = new ArrayList JavaDoc();
64                 List JavaDoc conditionList2 = new ArrayList JavaDoc();
65
66                 // we are only concerned about approved sales orders
67
conditionList2.add(new EntityExpr("statusId", EntityOperator.EQUALS, "ORDER_APPROVED"));
68                 conditionList2.add(new EntityExpr("orderTypeId", EntityOperator.EQUALS, "SALES_ORDER"));
69
70                 // build the expression list from the IDs
71
Iterator JavaDoc i = orderIdList.iterator();
72                 while (i.hasNext()) {
73                     String JavaDoc orderId = (String JavaDoc) i.next();
74                     conditionList1.add(new EntityExpr("orderId", EntityOperator.EQUALS, orderId));
75                 }
76
77                 // create the conditions
78
EntityCondition idCond = new EntityConditionList(conditionList1, EntityOperator.OR);
79                 conditionList2.add(idCond);
80
81                 EntityCondition cond = new EntityConditionList(conditionList2, EntityOperator.AND);
82
83                 // run the query
84
try {
85                     orderHeaderList = delegator.findByCondition("OrderHeader", cond, null, UtilMisc.toList("+orderDate"));
86                 } catch (GenericEntityException e) {
87                     Debug.logError(e, module);
88                     return ServiceUtil.returnError(e.getMessage());
89                 }
90                 Debug.log("Recieved orderIdList - " + orderIdList, module);
91                 Debug.log("Found orderHeaderList - " + orderHeaderList, module);
92             }
93         }
94
95         Map JavaDoc result = ServiceUtil.returnSuccess();
96         result.put("orderHeaderList", orderHeaderList);
97         return result;
98     }
99 }
100
Popular Tags