KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > order > task > TaskEvents


1 /*
2  * $Id: TaskEvents.java 6642 2006-02-01 02:29:51Z sichen $
3  *
4  * Copyright (c) 2001, 2002 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 package org.ofbiz.order.task;
25
26 import java.util.Map JavaDoc;
27
28 import javax.servlet.ServletContext JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import java.util.Locale JavaDoc;
32
33 import org.ofbiz.base.util.Debug;
34 import org.ofbiz.base.util.GeneralException;
35 import org.ofbiz.base.util.ObjectType;
36 import org.ofbiz.base.util.UtilHttp;
37 import org.ofbiz.base.util.UtilMisc;
38 import org.ofbiz.base.util.UtilProperties;
39 import org.ofbiz.webapp.control.RequestHandler;
40 import org.ofbiz.webapp.event.EventHandler;
41 import org.ofbiz.webapp.event.EventHandlerException;
42 import org.ofbiz.entity.GenericValue;
43 import org.ofbiz.service.GenericServiceException;
44 import org.ofbiz.service.LocalDispatcher;
45 import org.ofbiz.service.ModelService;
46
47 /**
48  * Order Processing Task Events
49  *
50  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
51  * @version $Rev: 6642 $
52  * @since 2.0
53  */

54 public class TaskEvents {
55     
56     public static final String JavaDoc module = TaskEvents.class.getName();
57     public static final String JavaDoc resource_error = "OrderErrorUiLabels";
58     
59     /** Complete assignment event */
60     public static String JavaDoc completeAssignment(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
61         LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
62         GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
63         
64         Map JavaDoc parameterMap = UtilHttp.getParameterMap(request);
65         String JavaDoc workEffortId = (String JavaDoc) parameterMap.remove("workEffortId");
66         String JavaDoc partyId = (String JavaDoc) parameterMap.remove("partyId");
67         String JavaDoc roleTypeId = (String JavaDoc) parameterMap.remove("roleTypeId");
68         String JavaDoc fromDateStr = (String JavaDoc) parameterMap.remove("fromDate");
69         java.sql.Timestamp JavaDoc fromDate = null;
70         Locale JavaDoc locale = UtilHttp.getLocale(request);
71         
72         try {
73             fromDate = (java.sql.Timestamp JavaDoc) ObjectType.simpleTypeConvert(fromDateStr, "java.sql.Timestamp", null, null);
74         } catch (GeneralException e) {
75             request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderInvalidDateFormatForFromDate", locale));
76             return "error";
77         }
78         
79         Map JavaDoc result = null;
80         try {
81             Map JavaDoc context = UtilMisc.toMap("workEffortId", workEffortId, "partyId", partyId, "roleTypeId", roleTypeId,
82                     "fromDate", fromDate, "result", parameterMap, "userLogin", userLogin);
83             result = dispatcher.runSync("wfCompleteAssignment", context);
84             if (result.containsKey(ModelService.RESPOND_ERROR)) {
85                 request.setAttribute("_ERROR_MESSAGE_", (String JavaDoc) result.get(ModelService.ERROR_MESSAGE));
86                 return "error";
87             }
88         } catch (GenericServiceException e) {
89             request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderProblemsInvokingTheCompleteAssignmentService", locale));
90             return "error";
91         }
92
93         return "success";
94     }
95     
96     /** Accept role assignment event */
97     public static String JavaDoc acceptRoleAssignment(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
98         ServletContext JavaDoc ctx = (ServletContext JavaDoc) request.getAttribute("servletContext");
99         RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
100         Locale JavaDoc locale = UtilHttp.getLocale(request);
101         
102         if (addToOrderRole(request)) {
103             try {
104                 EventHandler eh = rh.getEventFactory().getEventHandler("service");
105                 eh.invoke("", "wfAcceptRoleAssignment", request, response);
106             } catch (EventHandlerException e) {
107                 Debug.logError(e, "Invocation error", module);
108                 request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderFailedToInvokeTheWfAcceptRoleAssignmentService", locale));
109                 return "error";
110             }
111             return "success";
112         }
113         return "error";
114     }
115     
116     /** Delegate and accept assignment event */
117     public static String JavaDoc delegateAndAcceptAssignment(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
118         ServletContext JavaDoc ctx = (ServletContext JavaDoc) request.getAttribute("servletContext");
119         RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
120         Locale JavaDoc locale = UtilHttp.getLocale(request);
121         
122         if (addToOrderRole(request)) {
123             try {
124                 EventHandler eh = rh.getEventFactory().getEventHandler("service");
125                 eh.invoke("", "wfDelegateAndAcceptAssignmet", request, response);
126             } catch (EventHandlerException e) {
127                 Debug.logError(e, "Invocation error", module);
128                 request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderFailedToInvokeTheWfDelegateAndAcceptAssignmentService", locale));
129                 return "error";
130             }
131             return "success";
132         }
133         return "error";
134     }
135         
136     private static boolean addToOrderRole(HttpServletRequest JavaDoc request) {
137         LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
138         String JavaDoc partyId = request.getParameter("partyId");
139         String JavaDoc roleTypeId = request.getParameter("roleTypeId");
140         String JavaDoc orderId = request.getParameter("orderId");
141         Map JavaDoc context = UtilMisc.toMap("orderId", orderId, "partyId", partyId, "roleTypeId", roleTypeId);
142         Map JavaDoc result = null;
143         try {
144             result = dispatcher.runSync("addOrderRole", context);
145             Debug.logInfo("Added user to order role " + result, module);
146         } catch (GenericServiceException gse) {
147             request.setAttribute("_ERROR_MESSAGE_", gse.getMessage());
148             return false;
149         }
150         return true;
151     }
152
153 }
154
Popular Tags