1 24 package org.ofbiz.order.task; 25 26 import java.util.Map ; 27 28 import javax.servlet.ServletContext ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import java.util.Locale ; 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 54 public class TaskEvents { 55 56 public static final String module = TaskEvents.class.getName(); 57 public static final String resource_error = "OrderErrorUiLabels"; 58 59 60 public static String completeAssignment(HttpServletRequest request, HttpServletResponse response) { 61 LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); 62 GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); 63 64 Map parameterMap = UtilHttp.getParameterMap(request); 65 String workEffortId = (String ) parameterMap.remove("workEffortId"); 66 String partyId = (String ) parameterMap.remove("partyId"); 67 String roleTypeId = (String ) parameterMap.remove("roleTypeId"); 68 String fromDateStr = (String ) parameterMap.remove("fromDate"); 69 java.sql.Timestamp fromDate = null; 70 Locale locale = UtilHttp.getLocale(request); 71 72 try { 73 fromDate = (java.sql.Timestamp ) 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 result = null; 80 try { 81 Map 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 ) 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 97 public static String acceptRoleAssignment(HttpServletRequest request, HttpServletResponse response) { 98 ServletContext ctx = (ServletContext ) request.getAttribute("servletContext"); 99 RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); 100 Locale 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 117 public static String delegateAndAcceptAssignment(HttpServletRequest request, HttpServletResponse response) { 118 ServletContext ctx = (ServletContext ) request.getAttribute("servletContext"); 119 RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); 120 Locale 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 request) { 137 LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); 138 String partyId = request.getParameter("partyId"); 139 String roleTypeId = request.getParameter("roleTypeId"); 140 String orderId = request.getParameter("orderId"); 141 Map context = UtilMisc.toMap("orderId", orderId, "partyId", partyId, "roleTypeId", roleTypeId); 142 Map 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 |