001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.workeffort.project;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Iterator;
023:
024: import javax.servlet.jsp.PageContext;
025:
026: import org.ofbiz.base.util.Debug;
027: import org.ofbiz.base.util.UtilMisc;
028: import org.ofbiz.entity.GenericDelegator;
029: import org.ofbiz.entity.GenericEntityException;
030: import org.ofbiz.entity.GenericValue;
031: import org.ofbiz.entity.condition.EntityExpr;
032: import org.ofbiz.entity.condition.EntityOperator;
033:
034: /**
035: * WorkEffortWorker - Worker class to reduce code in JSPs & make it more reusable
036: */
037: public class ProjectWorker {
038:
039: public static final String module = ProjectWorker.class.getName();
040:
041: public static void getAssignedProjects(PageContext pageContext,
042: String projectsAttrName) {
043: GenericDelegator delegator = (GenericDelegator) pageContext
044: .getRequest().getAttribute("delegator");
045: GenericValue userLogin = (GenericValue) pageContext
046: .getSession().getAttribute("userLogin");
047:
048: Collection validWorkEfforts = null;
049:
050: if (userLogin != null && userLogin.get("partyId") != null) {
051: try {
052: validWorkEfforts = delegator.findByAnd(
053: "WorkEffortAndPartyAssign", UtilMisc.toList(
054: new EntityExpr("partyId",
055: EntityOperator.EQUALS,
056: userLogin.get("partyId")),
057: new EntityExpr("currentStatusId",
058: EntityOperator.NOT_EQUAL,
059: "WF_COMPLETED"),
060: new EntityExpr("currentStatusId",
061: EntityOperator.NOT_EQUAL,
062: "WF_TERMINATED"),
063: new EntityExpr("currentStatusId",
064: EntityOperator.NOT_EQUAL,
065: "WF_ABORTED"), new EntityExpr(
066: "workEffortTypeId",
067: EntityOperator.EQUALS, "TASK"),
068: new EntityExpr(
069: "workEffortPurposeTypeId",
070: EntityOperator.EQUALS,
071: "WEPT_PROJECT")), UtilMisc
072: .toList("priority"));
073: } catch (GenericEntityException e) {
074: Debug.logWarning(e, module);
075: }
076: }
077: if (validWorkEfforts == null || validWorkEfforts.size() <= 0)
078: return;
079:
080: pageContext.setAttribute(projectsAttrName, validWorkEfforts);
081: }
082:
083: public static void getAllAssignedProjects(PageContext pageContext,
084: String projectsAttrName) {
085: GenericDelegator delegator = (GenericDelegator) pageContext
086: .getRequest().getAttribute("delegator");
087: GenericValue userLogin = (GenericValue) pageContext
088: .getSession().getAttribute("userLogin");
089:
090: Collection validWorkEfforts = null;
091:
092: if (userLogin != null && userLogin.get("partyId") != null) {
093: try {
094: validWorkEfforts = delegator.findByAnd(
095: "WorkEffortAndPartyAssign", UtilMisc.toList(
096: new EntityExpr("partyId",
097: EntityOperator.EQUALS,
098: userLogin.get("partyId")),
099: new EntityExpr("workEffortTypeId",
100: EntityOperator.EQUALS, "TASK"),
101: new EntityExpr(
102: "workEffortPurposeTypeId",
103: EntityOperator.EQUALS,
104: "WEPT_PROJECT")), UtilMisc
105: .toList("priority"));
106: } catch (GenericEntityException e) {
107: Debug.logWarning(e, module);
108: }
109: }
110: if (validWorkEfforts == null || validWorkEfforts.size() <= 0)
111: return;
112:
113: pageContext.setAttribute(projectsAttrName, validWorkEfforts);
114: }
115:
116: public static void getAllProjectPhases(PageContext pageContext,
117: String phasesAttrName) {
118: GenericDelegator delegator = (GenericDelegator) pageContext
119: .getRequest().getAttribute("delegator");
120: GenericValue userLogin = (GenericValue) pageContext
121: .getSession().getAttribute("userLogin");
122:
123: String projectWorkEffortId = pageContext.getRequest()
124: .getParameter("projectWorkEffortId");
125:
126: // if there was no parameter, check the request attribute, this may be a newly created entity
127: if (projectWorkEffortId == null)
128: projectWorkEffortId = (String) pageContext.getRequest()
129: .getAttribute("projectWorkEffortId");
130:
131: Collection relatedWorkEfforts = null;
132:
133: if (userLogin != null && userLogin.get("partyId") != null) {
134: try {
135: relatedWorkEfforts = delegator.findByAnd(
136: "WorkEffortAssoc", UtilMisc.toList(
137: new EntityExpr("workEffortIdFrom",
138: EntityOperator.EQUALS,
139: projectWorkEffortId),
140: new EntityExpr("workEffortAssocTypeId",
141: EntityOperator.EQUALS,
142: "WORK_EFF_BREAKDOWN")));
143: } catch (GenericEntityException e) {
144: Debug.logWarning(e, module);
145: }
146: }
147:
148: Collection validWorkEfforts = new ArrayList();
149:
150: if (relatedWorkEfforts != null) {
151: Iterator relatedWorkEffortsIter = relatedWorkEfforts
152: .iterator();
153:
154: try {
155: while (relatedWorkEffortsIter.hasNext()) {
156: GenericValue workEffortAssoc = (GenericValue) relatedWorkEffortsIter
157: .next();
158: GenericValue workEffort = workEffortAssoc
159: .getRelatedOne("ToWorkEffort");
160:
161: // only get phases
162: if ("TASK".equals(workEffort
163: .getString("workEffortTypeId"))
164: && ("WEPT_PHASE"
165: .equals(workEffort
166: .getString("workEffortPurposeTypeId")))) {
167: validWorkEfforts.add(workEffort);
168: }
169: }
170: } catch (GenericEntityException e) {
171: Debug.logWarning(e, module);
172: }
173: }
174: if (validWorkEfforts == null || validWorkEfforts.size() <= 0)
175: return;
176:
177: pageContext.setAttribute(phasesAttrName, validWorkEfforts);
178: }
179:
180: public static void getAllPhaseTasks(PageContext pageContext,
181: String tasksAttrName) {
182: GenericDelegator delegator = (GenericDelegator) pageContext
183: .getRequest().getAttribute("delegator");
184: GenericValue userLogin = (GenericValue) pageContext
185: .getSession().getAttribute("userLogin");
186:
187: String phaseWorkEffortId = pageContext.getRequest()
188: .getParameter("phaseWorkEffortId");
189:
190: // if there was no parameter, check the request attribute, this may be a newly created entity
191: if (phaseWorkEffortId == null)
192: phaseWorkEffortId = (String) pageContext.getRequest()
193: .getAttribute("phaseWorkEffortId");
194:
195: Collection relatedWorkEfforts = null;
196:
197: if (userLogin != null && userLogin.get("partyId") != null) {
198: try {
199: relatedWorkEfforts = delegator.findByAnd(
200: "WorkEffortAssoc", UtilMisc.toList(
201: new EntityExpr("workEffortIdFrom",
202: EntityOperator.EQUALS,
203: phaseWorkEffortId),
204: new EntityExpr("workEffortAssocTypeId",
205: EntityOperator.EQUALS,
206: "WORK_EFF_BREAKDOWN")));
207: } catch (GenericEntityException e) {
208: Debug.logWarning(e, module);
209: }
210: }
211:
212: Collection validWorkEfforts = new ArrayList();
213:
214: if (relatedWorkEfforts != null) {
215: Iterator relatedWorkEffortsIter = relatedWorkEfforts
216: .iterator();
217:
218: try {
219: while (relatedWorkEffortsIter.hasNext()) {
220: GenericValue workEffortAssoc = (GenericValue) relatedWorkEffortsIter
221: .next();
222: GenericValue workEffort = workEffortAssoc
223: .getRelatedOne("ToWorkEffort");
224:
225: // only get phases
226: if ("TASK".equals(workEffort
227: .getString("workEffortTypeId"))) {
228: validWorkEfforts.add(workEffort);
229: }
230: }
231: } catch (GenericEntityException e) {
232: Debug.logWarning(e, module);
233: }
234: }
235: if (validWorkEfforts == null || validWorkEfforts.size() <= 0)
236: return;
237:
238: pageContext.setAttribute(tasksAttrName, validWorkEfforts);
239: }
240:
241: public static void getTaskNotes(PageContext pageContext,
242: String notesAttrName) {
243: GenericDelegator delegator = (GenericDelegator) pageContext
244: .getRequest().getAttribute("delegator");
245: GenericValue userLogin = (GenericValue) pageContext
246: .getSession().getAttribute("userLogin");
247:
248: String workEffortId = pageContext.getRequest().getParameter(
249: "workEffortId");
250:
251: // if there was no parameter, check the request attribute, this may be a newly created entity
252: if (workEffortId == null)
253: workEffortId = (String) pageContext.getRequest()
254: .getAttribute("workEffortId");
255:
256: Collection notes = null;
257:
258: if (userLogin != null && userLogin.get("partyId") != null) {
259: try {
260: notes = delegator.findByAnd("WorkEffortNoteAndData",
261: UtilMisc.toList(new EntityExpr("workEffortId",
262: EntityOperator.EQUALS, workEffortId)),
263: UtilMisc.toList("noteDateTime"));
264: } catch (GenericEntityException e) {
265: Debug.logWarning(e, module);
266: }
267: }
268: if (notes == null || notes.size() <= 0)
269: return;
270:
271: pageContext.setAttribute(notesAttrName, notes);
272: }
273:
274: }
|