KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > common > status > StatusServices


1 /*
2  * $Id: StatusServices.java 5719 2005-09-13 01:57:32Z jonesde $
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.common.status;
26
27 import java.util.Collection JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.LinkedList JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import org.ofbiz.base.util.Debug;
35 import org.ofbiz.base.util.UtilMisc;
36 import org.ofbiz.entity.GenericDelegator;
37 import org.ofbiz.entity.GenericEntityException;
38 import org.ofbiz.service.DispatchContext;
39 import org.ofbiz.service.ServiceUtil;
40
41 /**
42  * StatusServices
43  *
44  * @author <a HREF="mailto:johan@ibibi.com">Johan Isacsson</a>
45  * @version $Rev: 5719 $
46  * @since 2.1
47  */

48 public class StatusServices {
49     
50     public static final String JavaDoc module = StatusServices.class.getName();
51     
52     public static Map JavaDoc getStatusItems(DispatchContext ctx, Map JavaDoc context) {
53         GenericDelegator delegator = (GenericDelegator) ctx.getDelegator();
54         List JavaDoc statusTypes = (List JavaDoc) context.get("statusTypeIds");
55         if (statusTypes == null || statusTypes.size() == 0) {
56             return ServiceUtil.returnError("Parameter statusTypeIds can not be null and must contain at least one element");
57         }
58         
59         Iterator JavaDoc i = statusTypes.iterator();
60         List JavaDoc statusItems = new LinkedList JavaDoc();
61         while (i.hasNext()) {
62             String JavaDoc statusTypeId = (String JavaDoc) i.next();
63             try {
64                 Collection JavaDoc myStatusItems = delegator.findByAndCache("StatusItem", UtilMisc.toMap("statusTypeId", statusTypeId), UtilMisc.toList("sequenceId"));
65                 statusItems.addAll(myStatusItems);
66             } catch (GenericEntityException e) {
67                 Debug.logError(e, module);
68             }
69         }
70         Map JavaDoc ret = new HashMap JavaDoc();
71         ret.put("statusItems",statusItems);
72         return ret;
73     }
74
75     public static Map JavaDoc getStatusValidChangeToDetails(DispatchContext ctx, Map JavaDoc context) {
76         GenericDelegator delegator = (GenericDelegator) ctx.getDelegator();
77         List JavaDoc statusValidChangeToDetails = null;
78         String JavaDoc statusId = (String JavaDoc) context.get("statusId");
79         try {
80             statusValidChangeToDetails = delegator.findByAndCache("StatusValidChangeToDetail", UtilMisc.toMap("statusId", statusId), UtilMisc.toList("sequenceId"));
81         } catch (GenericEntityException e) {
82             Debug.logError(e, module);
83         }
84         Map JavaDoc ret = ServiceUtil.returnSuccess();
85         if (statusValidChangeToDetails != null) {
86             ret.put("statusValidChangeToDetails", statusValidChangeToDetails);
87         }
88         return ret;
89     }
90 }
91
Popular Tags