📄 taskevents.java
字号:
/*
* $Id: TaskEvents.java,v 1.1 2003/08/19 06:42:54 ajzeneski Exp $
*
* Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.ofbiz.order.task;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.ObjectType;
import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.content.webapp.control.RequestHandler;
import org.ofbiz.content.webapp.event.EventHandler;
import org.ofbiz.content.webapp.event.EventHandlerException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
/**
* Order Processing Task Events
*
* @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
* @version $Revision: 1.1 $
* @since 2.0
*/
public class TaskEvents {
public static final String module = TaskEvents.class.getName();
/** Complete assignment event */
public static String completeAssignment(HttpServletRequest request, HttpServletResponse response) {
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
Map parameterMap = UtilHttp.getParameterMap(request);
String workEffortId = (String) parameterMap.remove("workEffortId");
String partyId = (String) parameterMap.remove("partyId");
String roleTypeId = (String) parameterMap.remove("roleTypeId");
String fromDateStr = (String) parameterMap.remove("fromDate");
java.sql.Timestamp fromDate = null;
try {
fromDate = (java.sql.Timestamp) ObjectType.simpleTypeConvert(fromDateStr, "java.sql.Timestamp", null, null);
} catch (GeneralException e) {
request.setAttribute("_ERROR_MESSAGE_", "Invalid date format for fromDate");
return "error";
}
Map result = null;
try {
Map context = UtilMisc.toMap("workEffortId", workEffortId, "partyId", partyId, "roleTypeId", roleTypeId,
"fromDate", fromDate, "result", parameterMap, "userLogin", userLogin);
result = dispatcher.runSync("wfCompleteAssignment", context);
if (result.containsKey(ModelService.RESPOND_ERROR)) {
request.setAttribute("_ERROR_MESSAGE_", (String) result.get(ModelService.ERROR_MESSAGE));
return "error";
}
} catch (GenericServiceException e) {
request.setAttribute("_ERROR_MESSAGE_", "Problems invoking the complete assignment service");
return "error";
}
return "success";
}
/** Accept role assignment event */
public static String acceptRoleAssignment(HttpServletRequest request, HttpServletResponse response) {
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
if (addToOrderRole(request)) {
try {
EventHandler eh = rh.getEventFactory().getEventHandler("service");
eh.invoke("", "wfAcceptRoleAssignment", request, response);
} catch (EventHandlerException e) {
Debug.logError(e, "Invocation error", module);
request.setAttribute("_ERROR_MESSAGE_", "Failed to invoke the wfAcceptRoleAssignment service.");
return "error";
}
return "success";
}
return "error";
}
/** Delegate and accept assignment event */
public static String delegateAndAcceptAssignment(HttpServletRequest request, HttpServletResponse response) {
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
if (addToOrderRole(request)) {
try {
EventHandler eh = rh.getEventFactory().getEventHandler("service");
eh.invoke("", "wfDelegateAndAcceptAssignmet", request, response);
} catch (EventHandlerException e) {
Debug.logError(e, "Invocation error", module);
request.setAttribute("_ERROR_MESSAGE_", "Failed to invoke the wfDelegateAndAcceptAssignmet service.");
return "error";
}
return "success";
}
return "error";
}
private static boolean addToOrderRole(HttpServletRequest request) {
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
String partyId = request.getParameter("partyId");
String roleTypeId = request.getParameter("roleTypeId");
String orderId = request.getParameter("order_id");
Map context = UtilMisc.toMap("orderId", orderId, "partyId", partyId, "roleTypeId", roleTypeId);
Map result = null;
try {
result = dispatcher.runSync("addOrderRole", context);
Debug.logInfo("Added user to order role " + result, module);
} catch (GenericServiceException gse) {
request.setAttribute("_ERROR_MESSAGE_", gse.getMessage());
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -