001: /*
002: * $Id: ProjectWorker.java,v 1.2 2003/08/18 17:02:17 jonesde 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: */
025: package org.ofbiz.workeffort.project;
026:
027: import java.util.ArrayList;
028: import java.util.Collection;
029: import java.util.Iterator;
030:
031: import javax.servlet.jsp.PageContext;
032:
033: import org.ofbiz.base.util.Debug;
034: import org.ofbiz.base.util.UtilMisc;
035: import org.ofbiz.entity.GenericDelegator;
036: import org.ofbiz.entity.GenericEntityException;
037: import org.ofbiz.entity.GenericValue;
038: import org.ofbiz.entity.condition.EntityExpr;
039: import org.ofbiz.entity.condition.EntityOperator;
040:
041: /**
042: * WorkEffortWorker - Worker class to reduce code in JSPs & make it more reusable
043: *
044: * @author <a href="mailto:dustin@dscv.org">Dustin Caldwell</a>
045: * @version $Revision: 1.2 $
046: * @since 2.0
047: */
048: public class ProjectWorker {
049:
050: public static final String module = ProjectWorker.class.getName();
051:
052: public static void getAssignedProjects(PageContext pageContext,
053: String projectsAttrName) {
054: GenericDelegator delegator = (GenericDelegator) pageContext
055: .getRequest().getAttribute("delegator");
056: GenericValue userLogin = (GenericValue) pageContext
057: .getSession().getAttribute("userLogin");
058:
059: Collection validWorkEfforts = null;
060:
061: if (userLogin != null && userLogin.get("partyId") != null) {
062: try {
063: validWorkEfforts = delegator.findByAnd(
064: "WorkEffortAndPartyAssign", UtilMisc.toList(
065: new EntityExpr("partyId",
066: EntityOperator.EQUALS,
067: userLogin.get("partyId")),
068: new EntityExpr("currentStatusId",
069: EntityOperator.NOT_EQUAL,
070: "WF_COMPLETED"),
071: new EntityExpr("currentStatusId",
072: EntityOperator.NOT_EQUAL,
073: "WF_TERMINATED"),
074: new EntityExpr("currentStatusId",
075: EntityOperator.NOT_EQUAL,
076: "WF_ABORTED"), new EntityExpr(
077: "workEffortTypeId",
078: EntityOperator.EQUALS, "TASK"),
079: new EntityExpr(
080: "workEffortPurposeTypeId",
081: EntityOperator.EQUALS,
082: "WEPT_PROJECT")), UtilMisc
083: .toList("priority"));
084: } catch (GenericEntityException e) {
085: Debug.logWarning(e, module);
086: }
087: }
088: if (validWorkEfforts == null || validWorkEfforts.size() <= 0)
089: return;
090:
091: pageContext.setAttribute(projectsAttrName, validWorkEfforts);
092: }
093:
094: public static void getAllAssignedProjects(PageContext pageContext,
095: String projectsAttrName) {
096: GenericDelegator delegator = (GenericDelegator) pageContext
097: .getRequest().getAttribute("delegator");
098: GenericValue userLogin = (GenericValue) pageContext
099: .getSession().getAttribute("userLogin");
100:
101: Collection validWorkEfforts = null;
102:
103: if (userLogin != null && userLogin.get("partyId") != null) {
104: try {
105: validWorkEfforts = delegator.findByAnd(
106: "WorkEffortAndPartyAssign", UtilMisc.toList(
107: new EntityExpr("partyId",
108: EntityOperator.EQUALS,
109: userLogin.get("partyId")),
110: new EntityExpr("workEffortTypeId",
111: EntityOperator.EQUALS, "TASK"),
112: new EntityExpr(
113: "workEffortPurposeTypeId",
114: EntityOperator.EQUALS,
115: "WEPT_PROJECT")), UtilMisc
116: .toList("priority"));
117: } catch (GenericEntityException e) {
118: Debug.logWarning(e, module);
119: }
120: }
121: if (validWorkEfforts == null || validWorkEfforts.size() <= 0)
122: return;
123:
124: pageContext.setAttribute(projectsAttrName, validWorkEfforts);
125: }
126:
127: public static void getAllProjectPhases(PageContext pageContext,
128: String phasesAttrName) {
129: GenericDelegator delegator = (GenericDelegator) pageContext
130: .getRequest().getAttribute("delegator");
131: GenericValue userLogin = (GenericValue) pageContext
132: .getSession().getAttribute("userLogin");
133:
134: String projectWorkEffortId = pageContext.getRequest()
135: .getParameter("projectWorkEffortId");
136:
137: // if there was no parameter, check the request attribute, this may be a newly created entity
138: if (projectWorkEffortId == null)
139: projectWorkEffortId = (String) pageContext.getRequest()
140: .getAttribute("projectWorkEffortId");
141:
142: Collection relatedWorkEfforts = null;
143:
144: if (userLogin != null && userLogin.get("partyId") != null) {
145: try {
146: relatedWorkEfforts = delegator.findByAnd(
147: "WorkEffortAssoc", UtilMisc.toList(
148: new EntityExpr("workEffortIdFrom",
149: EntityOperator.EQUALS,
150: projectWorkEffortId),
151: new EntityExpr("workEffortAssocTypeId",
152: EntityOperator.EQUALS,
153: "WORK_EFF_BREAKDOWN")));
154: } catch (GenericEntityException e) {
155: Debug.logWarning(e, module);
156: }
157: }
158:
159: Collection validWorkEfforts = new ArrayList();
160:
161: if (relatedWorkEfforts != null) {
162: Iterator relatedWorkEffortsIter = relatedWorkEfforts
163: .iterator();
164:
165: try {
166: while (relatedWorkEffortsIter.hasNext()) {
167: GenericValue workEffortAssoc = (GenericValue) relatedWorkEffortsIter
168: .next();
169: GenericValue workEffort = workEffortAssoc
170: .getRelatedOne("ToWorkEffort");
171:
172: // only get phases
173: if ("TASK".equals(workEffort
174: .getString("workEffortTypeId"))
175: && ("WEPT_PHASE"
176: .equals(workEffort
177: .getString("workEffortPurposeTypeId")))) {
178: validWorkEfforts.add(workEffort);
179: }
180: }
181: } catch (GenericEntityException e) {
182: Debug.logWarning(e, module);
183: }
184: }
185: if (validWorkEfforts == null || validWorkEfforts.size() <= 0)
186: return;
187:
188: pageContext.setAttribute(phasesAttrName, validWorkEfforts);
189: }
190:
191: public static void getAllPhaseTasks(PageContext pageContext,
192: String tasksAttrName) {
193: GenericDelegator delegator = (GenericDelegator) pageContext
194: .getRequest().getAttribute("delegator");
195: GenericValue userLogin = (GenericValue) pageContext
196: .getSession().getAttribute("userLogin");
197:
198: String phaseWorkEffortId = pageContext.getRequest()
199: .getParameter("phaseWorkEffortId");
200:
201: // if there was no parameter, check the request attribute, this may be a newly created entity
202: if (phaseWorkEffortId == null)
203: phaseWorkEffortId = (String) pageContext.getRequest()
204: .getAttribute("phaseWorkEffortId");
205:
206: Collection relatedWorkEfforts = null;
207:
208: if (userLogin != null && userLogin.get("partyId") != null) {
209: try {
210: relatedWorkEfforts = delegator.findByAnd(
211: "WorkEffortAssoc", UtilMisc.toList(
212: new EntityExpr("workEffortIdFrom",
213: EntityOperator.EQUALS,
214: phaseWorkEffortId),
215: new EntityExpr("workEffortAssocTypeId",
216: EntityOperator.EQUALS,
217: "WORK_EFF_BREAKDOWN")));
218: } catch (GenericEntityException e) {
219: Debug.logWarning(e, module);
220: }
221: }
222:
223: Collection validWorkEfforts = new ArrayList();
224:
225: if (relatedWorkEfforts != null) {
226: Iterator relatedWorkEffortsIter = relatedWorkEfforts
227: .iterator();
228:
229: try {
230: while (relatedWorkEffortsIter.hasNext()) {
231: GenericValue workEffortAssoc = (GenericValue) relatedWorkEffortsIter
232: .next();
233: GenericValue workEffort = workEffortAssoc
234: .getRelatedOne("ToWorkEffort");
235:
236: // only get phases
237: if ("TASK".equals(workEffort
238: .getString("workEffortTypeId"))) {
239: validWorkEfforts.add(workEffort);
240: }
241: }
242: } catch (GenericEntityException e) {
243: Debug.logWarning(e, module);
244: }
245: }
246: if (validWorkEfforts == null || validWorkEfforts.size() <= 0)
247: return;
248:
249: pageContext.setAttribute(tasksAttrName, validWorkEfforts);
250: }
251:
252: public static void getTaskNotes(PageContext pageContext,
253: String notesAttrName) {
254: GenericDelegator delegator = (GenericDelegator) pageContext
255: .getRequest().getAttribute("delegator");
256: GenericValue userLogin = (GenericValue) pageContext
257: .getSession().getAttribute("userLogin");
258:
259: String workEffortId = pageContext.getRequest().getParameter(
260: "workEffortId");
261:
262: // if there was no parameter, check the request attribute, this may be a newly created entity
263: if (workEffortId == null)
264: workEffortId = (String) pageContext.getRequest()
265: .getAttribute("workEffortId");
266:
267: Collection notes = null;
268:
269: if (userLogin != null && userLogin.get("partyId") != null) {
270: try {
271: notes = delegator.findByAnd("WorkEffortNoteAndData",
272: UtilMisc.toList(new EntityExpr("workEffortId",
273: EntityOperator.EQUALS, workEffortId)),
274: UtilMisc.toList("noteDateTime"));
275: } catch (GenericEntityException e) {
276: Debug.logWarning(e, module);
277: }
278: }
279: if (notes == null || notes.size() <= 0)
280: return;
281:
282: pageContext.setAttribute(notesAttrName, notes);
283: }
284:
285: }
|