1 25 package org.ofbiz.workeffort.workeffort; 26 27 import java.util.Collection ; 28 import java.util.Map ; 29 30 import javax.servlet.jsp.PageContext ; 31 32 import org.ofbiz.base.util.Debug; 33 import org.ofbiz.base.util.UtilMisc; 34 import org.ofbiz.entity.GenericDelegator; 35 import org.ofbiz.entity.GenericEntityException; 36 import org.ofbiz.entity.GenericValue; 37 import org.ofbiz.security.Security; 38 import org.ofbiz.service.GenericServiceException; 39 import org.ofbiz.service.LocalDispatcher; 40 import org.ofbiz.service.ModelService; 41 42 50 public class WorkEffortWorker { 51 52 public static final String module = WorkEffortWorker.class.getName(); 53 54 public static void getWorkEffort(PageContext pageContext, String workEffortIdAttrName, String workEffortAttrName, String partyAssignsAttrName, 56 String canViewAttrName, String tryEntityAttrName, String currentStatusAttrName) { 57 GenericDelegator delegator = (GenericDelegator) pageContext.getRequest().getAttribute("delegator"); 58 Security security = (Security) pageContext.getRequest().getAttribute("security"); 59 GenericValue userLogin = (GenericValue) pageContext.getSession().getAttribute("userLogin"); 60 61 String workEffortId = pageContext.getRequest().getParameter("workEffortId"); 62 63 if (workEffortId == null) 65 workEffortId = (String ) pageContext.getRequest().getAttribute("workEffortId"); 66 67 GenericValue workEffort = null; 68 69 try { 70 workEffort = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId)); 71 } catch (GenericEntityException e) { 72 Debug.logWarning(e, module); 73 } 74 75 Boolean canView = null; 76 Collection workEffortPartyAssignments = null; 77 Boolean tryEntity = null; 78 GenericValue currentStatus = null; 79 80 if (workEffort == null) { 81 tryEntity = new Boolean (false); 82 canView = new Boolean (true); 83 84 String statusId = pageContext.getRequest().getParameter("currentStatusId"); 85 86 if (statusId != null && statusId.length() > 0) { 87 try { 88 currentStatus = delegator.findByPrimaryKeyCache("StatusItem", UtilMisc.toMap("statusId", statusId)); 89 } catch (GenericEntityException e) { 90 Debug.logWarning(e, module); 91 } 92 } 93 } else { 94 if (userLogin != null && userLogin.get("partyId") != null && workEffortId != null) { 96 try { 97 workEffortPartyAssignments = 98 delegator.findByAnd("WorkEffortPartyAssignment", UtilMisc.toMap("workEffortId", workEffortId, "partyId", userLogin.get("partyId"))); 99 } catch (GenericEntityException e) { 100 Debug.logWarning(e, module); 101 } 102 } 103 canView = (workEffortPartyAssignments != null && workEffortPartyAssignments.size() > 0) ? new Boolean (true) : new Boolean (false); 104 if (!canView.booleanValue() && security.hasEntityPermission("WORKEFFORTMGR", "_VIEW", pageContext.getSession())) { 105 canView = new Boolean (true); 106 } 107 108 tryEntity = new Boolean (true); 109 110 if (workEffort.get("currentStatusId") != null) { 111 try { 112 currentStatus = delegator.findByPrimaryKeyCache("StatusItem", UtilMisc.toMap("statusId", workEffort.get("currentStatusId"))); 113 } catch (GenericEntityException e) { 114 Debug.logWarning(e, module); 115 } 116 } 117 } 118 119 if (pageContext.getRequest().getAttribute("_ERROR_MESSAGE_") != null) { 121 tryEntity = new Boolean (false); 122 } 123 124 if (workEffortId != null) 125 pageContext.setAttribute(workEffortIdAttrName, workEffortId); 126 if (workEffort != null) 127 pageContext.setAttribute(workEffortAttrName, workEffort); 128 if (canView != null) 129 pageContext.setAttribute(canViewAttrName, canView); 130 if (workEffortPartyAssignments != null) 131 pageContext.setAttribute(partyAssignsAttrName, workEffortPartyAssignments); 132 if (tryEntity != null) 133 pageContext.setAttribute(tryEntityAttrName, tryEntity); 134 if (currentStatus != null) 135 pageContext.setAttribute(currentStatusAttrName, currentStatus); 136 } 137 138 public static void getMonthWorkEffortEvents(PageContext pageContext, String attributeName) {} 139 140 public static void getActivityContext(PageContext pageContext, String workEffortId) { 141 getActivityContext(pageContext, workEffortId, "activityContext"); 142 } 143 144 public static void getActivityContext(PageContext pageContext, String workEffortId, String attribute) { 145 GenericDelegator delegator = (GenericDelegator) pageContext.getRequest().getAttribute("delegator"); 146 LocalDispatcher dispatcher = (LocalDispatcher) pageContext.getRequest().getAttribute("dispatcher"); 147 GenericValue userLogin = (GenericValue) pageContext.getSession().getAttribute("userLogin"); 148 Map svcCtx = UtilMisc.toMap("workEffortId", workEffortId, "userLogin", userLogin); 149 Map result = null; 150 151 try { 152 result = dispatcher.runSync("wfGetActivityContext", svcCtx); 153 } catch (GenericServiceException e) { 154 Debug.logError(e, module); 155 } 156 if (result != null && result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR)) 157 Debug.logError((String ) result.get(ModelService.ERROR_MESSAGE), module); 158 if (result != null && result.containsKey("activityContext")) { 159 Map aC = (Map ) result.get("activityContext"); 160 161 pageContext.setAttribute(attribute, aC); 162 } 163 } 164 } 165 | Popular Tags |