001: /*
002: * $Id: TaskEvents.java,v 1.1 2003/08/19 06:42:54 ajzeneski Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024: package org.ofbiz.order.task;
025:
026: import java.util.Map;
027:
028: import javax.servlet.ServletContext;
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpServletResponse;
031:
032: import org.ofbiz.base.util.Debug;
033: import org.ofbiz.base.util.GeneralException;
034: import org.ofbiz.base.util.ObjectType;
035: import org.ofbiz.base.util.UtilHttp;
036: import org.ofbiz.base.util.UtilMisc;
037: import org.ofbiz.content.webapp.control.RequestHandler;
038: import org.ofbiz.content.webapp.event.EventHandler;
039: import org.ofbiz.content.webapp.event.EventHandlerException;
040: import org.ofbiz.entity.GenericValue;
041: import org.ofbiz.service.GenericServiceException;
042: import org.ofbiz.service.LocalDispatcher;
043: import org.ofbiz.service.ModelService;
044:
045: /**
046: * Order Processing Task Events
047: *
048: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
049: * @version $Revision: 1.1 $
050: * @since 2.0
051: */
052: public class TaskEvents {
053:
054: public static final String module = TaskEvents.class.getName();
055:
056: /** Complete assignment event */
057: public static String completeAssignment(HttpServletRequest request,
058: HttpServletResponse response) {
059: LocalDispatcher dispatcher = (LocalDispatcher) request
060: .getAttribute("dispatcher");
061: GenericValue userLogin = (GenericValue) request.getSession()
062: .getAttribute("userLogin");
063:
064: Map parameterMap = UtilHttp.getParameterMap(request);
065: String workEffortId = (String) parameterMap
066: .remove("workEffortId");
067: String partyId = (String) parameterMap.remove("partyId");
068: String roleTypeId = (String) parameterMap.remove("roleTypeId");
069: String fromDateStr = (String) parameterMap.remove("fromDate");
070: java.sql.Timestamp fromDate = null;
071: try {
072: fromDate = (java.sql.Timestamp) ObjectType
073: .simpleTypeConvert(fromDateStr,
074: "java.sql.Timestamp", null, null);
075: } catch (GeneralException e) {
076: request.setAttribute("_ERROR_MESSAGE_",
077: "Invalid date format for fromDate");
078: return "error";
079: }
080:
081: Map result = null;
082: try {
083: Map context = UtilMisc.toMap("workEffortId", workEffortId,
084: "partyId", partyId, "roleTypeId", roleTypeId,
085: "fromDate", fromDate, "result", parameterMap,
086: "userLogin", userLogin);
087: result = dispatcher
088: .runSync("wfCompleteAssignment", context);
089: if (result.containsKey(ModelService.RESPOND_ERROR)) {
090: request.setAttribute("_ERROR_MESSAGE_", (String) result
091: .get(ModelService.ERROR_MESSAGE));
092: return "error";
093: }
094: } catch (GenericServiceException e) {
095: request
096: .setAttribute("_ERROR_MESSAGE_",
097: "Problems invoking the complete assignment service");
098: return "error";
099: }
100:
101: return "success";
102: }
103:
104: /** Accept role assignment event */
105: public static String acceptRoleAssignment(
106: HttpServletRequest request, HttpServletResponse response) {
107: ServletContext ctx = (ServletContext) request
108: .getAttribute("servletContext");
109: RequestHandler rh = (RequestHandler) ctx
110: .getAttribute("_REQUEST_HANDLER_");
111:
112: if (addToOrderRole(request)) {
113: try {
114: EventHandler eh = rh.getEventFactory().getEventHandler(
115: "service");
116: eh.invoke("", "wfAcceptRoleAssignment", request,
117: response);
118: } catch (EventHandlerException e) {
119: Debug.logError(e, "Invocation error", module);
120: request
121: .setAttribute("_ERROR_MESSAGE_",
122: "Failed to invoke the wfAcceptRoleAssignment service.");
123: return "error";
124: }
125: return "success";
126: }
127: return "error";
128: }
129:
130: /** Delegate and accept assignment event */
131: public static String delegateAndAcceptAssignment(
132: HttpServletRequest request, HttpServletResponse response) {
133: ServletContext ctx = (ServletContext) request
134: .getAttribute("servletContext");
135: RequestHandler rh = (RequestHandler) ctx
136: .getAttribute("_REQUEST_HANDLER_");
137:
138: if (addToOrderRole(request)) {
139: try {
140: EventHandler eh = rh.getEventFactory().getEventHandler(
141: "service");
142: eh.invoke("", "wfDelegateAndAcceptAssignmet", request,
143: response);
144: } catch (EventHandlerException e) {
145: Debug.logError(e, "Invocation error", module);
146: request
147: .setAttribute("_ERROR_MESSAGE_",
148: "Failed to invoke the wfDelegateAndAcceptAssignmet service.");
149: return "error";
150: }
151: return "success";
152: }
153: return "error";
154: }
155:
156: private static boolean addToOrderRole(HttpServletRequest request) {
157: LocalDispatcher dispatcher = (LocalDispatcher) request
158: .getAttribute("dispatcher");
159: String partyId = request.getParameter("partyId");
160: String roleTypeId = request.getParameter("roleTypeId");
161: String orderId = request.getParameter("order_id");
162: Map context = UtilMisc.toMap("orderId", orderId, "partyId",
163: partyId, "roleTypeId", roleTypeId);
164: Map result = null;
165: try {
166: result = dispatcher.runSync("addOrderRole", context);
167: Debug.logInfo("Added user to order role " + result, module);
168: } catch (GenericServiceException gse) {
169: request.setAttribute("_ERROR_MESSAGE_", gse.getMessage());
170: return false;
171: }
172: return true;
173: }
174:
175: }
|