001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.workgroup.web;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import javax.servlet.http.HttpServletRequest;
023:
024: import org.apache.commons.collections.Factory;
025: import org.apache.commons.collections.ListUtils;
026: import org.apache.commons.lang.StringUtils;
027: import org.apache.struts.action.ActionErrors;
028: import org.apache.struts.action.ActionMapping;
029: import org.kuali.workflow.attribute.web.WebExtensions;
030: import org.kuali.workflow.workgroup.WorkgroupType;
031:
032: import edu.iu.uis.eden.EdenConstants;
033: import edu.iu.uis.eden.KEWServiceLocator;
034: import edu.iu.uis.eden.routeheader.Routable;
035: import edu.iu.uis.eden.user.Recipient;
036: import edu.iu.uis.eden.user.WorkflowUser;
037: import edu.iu.uis.eden.util.KeyLabelPair;
038: import edu.iu.uis.eden.util.Utilities;
039: import edu.iu.uis.eden.web.WorkflowRoutingForm;
040: import edu.iu.uis.eden.workgroup.GroupNameId;
041: import edu.iu.uis.eden.workgroup.WorkflowGroupId;
042: import edu.iu.uis.eden.workgroup.Workgroup;
043:
044: /**
045: * A Struts ActionForm for the {@link WorkgroupAction}.
046: *
047: * @see WorkgroupAction
048: *
049: * @author xqi
050: * @author rkirkend
051: */
052: public class WorkgroupForm extends WorkflowRoutingForm {
053:
054: private static final long serialVersionUID = 6253549718029785616L;
055:
056: private Long workgroupId;
057: private String workgroupName = "";
058: private List workgroupMembers = ListUtils.lazyList(new ArrayList(),
059: new Factory() {
060: public Object create() {
061: return new WorkgroupMember();
062: }
063: });
064: private String workgroupMember;
065: private String memberType = "";
066: private String removedMember;
067: private String methodToCall = "";
068: private String showEdit;
069: private String command;
070: private String instructionForCreateNew;
071: private String lookupableImplServiceName;
072: private Workgroup existingWorkgroup;
073: private WorkgroupType existingWorkgroupType;
074: private WebExtensions existingExtensions = new WebExtensions();
075: private List<WorkgroupMember> existingWorkgroupMembers;
076: private Workgroup workgroup;
077: private WorkgroupType workgroupType;
078: private String lookupType;
079: private List<WorkgroupType> workgroupTypes;
080: private String currentWorkgroupType;
081: private WebExtensions extensions = new WebExtensions();
082: public boolean workgroupTypeEditable = true;
083: public boolean readOnly = false;
084: private List<KeyLabelPair> memberTypes = new ArrayList<KeyLabelPair>();
085:
086: public WorkgroupForm() {
087: workgroup = KEWServiceLocator.getWorkgroupService()
088: .getBlankWorkgroup();
089: instructionForCreateNew = Utilities
090: .getApplicationConstant(EdenConstants.WORKGROUP_CREATE_NEW_INSTRUCTION_KEY);
091: memberTypes
092: .add(new KeyLabelPair(
093: EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD,
094: "User"));
095: memberTypes.add(new KeyLabelPair(
096: EdenConstants.ACTION_REQUEST_WORKGROUP_RECIPIENT_CD,
097: "Workgroup"));
098: }
099:
100: public Long getWorkgroupId() {
101: return workgroupId;
102: }
103:
104: public void setWorkgroupId(Long workgroupId) {
105: this .workgroupId = workgroupId;
106: }
107:
108: public String getWorkgroupName() {
109: return workgroupName;
110: }
111:
112: public void setWorkgroupName(String workgroupName) {
113: this .workgroupName = workgroupName;
114: }
115:
116: public String getRouteLogPopup() {
117: return Utilities.getApplicationConstant(
118: EdenConstants.WORKGROUP_ROUTE_LOG_POPUP_KEY).trim();
119: }
120:
121: public Workgroup getExistingWorkgroup() {
122: return existingWorkgroup;
123: }
124:
125: public void setExistingWorkgroup(Workgroup existingWorkgroup) {
126: this .existingWorkgroup = existingWorkgroup;
127: }
128:
129: public WorkgroupType getExistingWorkgroupType() {
130: return existingWorkgroupType;
131: }
132:
133: public void setExistingWorkgroupType(
134: WorkgroupType existingWorkgroupType) {
135: this .existingWorkgroupType = existingWorkgroupType;
136: }
137:
138: public WebExtensions getExistingExtensions() {
139: return existingExtensions;
140: }
141:
142: public void setExistingExtensions(WebExtensions existingExtensions) {
143: this .existingExtensions = existingExtensions;
144: }
145:
146: public String getRemovedMember() {
147: return removedMember;
148: }
149:
150: public void setRemovedMember(String removedMember) {
151: this .removedMember = removedMember;
152: }
153:
154: public String getMethodToCall() {
155: return methodToCall;
156: }
157:
158: public void setMethodToCall(String methodToCall) {
159: this .methodToCall = methodToCall;
160: }
161:
162: public String getWorkgroupMember() {
163: return workgroupMember;
164: }
165:
166: public void setWorkgroupMember(String workgroupMember) {
167: this .workgroupMember = (workgroupMember == null) ? workgroupMember
168: : workgroupMember.trim();
169: }
170:
171: public String getMemberType() {
172: return memberType;
173: }
174:
175: public void setMemberType(String memberType) {
176: this .memberType = memberType;
177: }
178:
179: public Workgroup getWorkgroup() {
180: return workgroup;
181: }
182:
183: public void setWorkgroup(Workgroup workgroup) {
184: this .workgroup = workgroup;
185: }
186:
187: public ActionErrors validate(ActionMapping arg0,
188: HttpServletRequest arg1) {
189: if (workgroup.getGroupNameId() != null
190: && !StringUtils.isEmpty(workgroup.getGroupNameId()
191: .getNameId())) {
192: workgroup.setGroupNameId(new GroupNameId(workgroup
193: .getGroupNameId().getNameId().trim()));
194: }
195: if (workgroup.getDescription() != null) {
196: workgroup.setDescription(workgroup.getDescription().trim());
197: }
198: return null;
199: }
200:
201: public String getShowEdit() {
202: return showEdit;
203: }
204:
205: public void setShowEdit(String showEdit) {
206: this .showEdit = showEdit;
207: }
208:
209: public String getCommand() {
210: return command;
211: }
212:
213: public void setCommand(String command) {
214: this .command = command;
215: }
216:
217: public String getInstructionForCreateNew() {
218: return instructionForCreateNew;
219: }
220:
221: public void setInstructionForCreateNew(
222: String instructionForCreateNew) {
223: this .instructionForCreateNew = instructionForCreateNew;
224: }
225:
226: public String getSearchLink() {
227: return "Lookup.do?lookupableImplServiceName=WorkGroupLookupableImplService";
228: }
229:
230: public String getSearchLinkText() {
231: return "Workgroup Search";
232: }
233:
234: public String getLookupableImplServiceName() {
235: return lookupableImplServiceName;
236: }
237:
238: public void setLookupableImplServiceName(
239: String lookupableImplServiceName) {
240: this .lookupableImplServiceName = lookupableImplServiceName;
241: }
242:
243: public String getLookupType() {
244: return lookupType;
245: }
246:
247: public void setLookupType(String lookupType) {
248: this .lookupType = lookupType;
249: }
250:
251: public List getWorkgroupMembers() {
252: return workgroupMembers;
253: }
254:
255: public void setWorkgroupMembers(List workgroupMembers) {
256: this .workgroupMembers = workgroupMembers;
257: }
258:
259: public List<WorkgroupType> getWorkgroupTypes() {
260: return workgroupTypes;
261: }
262:
263: public void setWorkgroupTypes(List<WorkgroupType> workgroupTypes) {
264: this .workgroupTypes = workgroupTypes;
265: }
266:
267: /**
268: * Returns true if the workgroups on this form represent Routable workgroups
269: */
270: public boolean isRoutable() {
271: return (existingWorkgroup == null || existingWorkgroup instanceof Routable)
272: && workgroup instanceof Routable;
273: }
274:
275: public Routable getRoutableWorkgroup() {
276: return (Routable) getWorkgroup();
277: }
278:
279: public void setDocId(Long docId) {
280: super .setDocId(docId);
281: if (isRoutable()) {
282: getRoutableWorkgroup().setDocumentId(docId);
283: }
284: }
285:
286: /**
287: * This method grabs the ids and members off of the Workgroup and populates them on the
288: * form bean in a manner which can easily be accessed by the JSP Expression Language
289: */
290: public void loadWebWorkgroupValues() {
291: if (workgroup != null) {
292: WorkflowGroupId groupId = workgroup.getWorkflowGroupId();
293: setWorkgroupId(groupId == null ? null : groupId
294: .getGroupId());
295: GroupNameId nameId = workgroup.getGroupNameId();
296: setWorkgroupName(nameId == null ? "" : nameId.getNameId());
297: for (Recipient member : workgroup.getMembers()) {
298: if (member instanceof WorkflowUser) {
299: WorkflowUser user = (WorkflowUser) member;
300: getWorkgroupMembers()
301: .add(new WorkgroupMember(user));
302: } else if (member instanceof Workgroup) {
303: Workgroup nestedWorkgroup = (Workgroup) member;
304: getWorkgroupMembers().add(
305: new WorkgroupMember(nestedWorkgroup));
306: }
307: }
308: }
309: }
310:
311: public static WorkgroupType createDefaultWorkgroupType() {
312: WorkgroupType workgroupType = new WorkgroupType();
313: workgroupType.setActive(true);
314: workgroupType.setLabel("Default");
315: workgroupType.setName("");
316: return workgroupType;
317: }
318:
319: /**
320: * A simple wrapper to allow the Struts indexed properties to work correctly.
321: */
322: public static class WorkgroupMember {
323: private String workflowId;
324: private String memberType;
325: private String displayName;
326: private String authenticationId;
327:
328: public WorkgroupMember() {
329: }
330:
331: public WorkgroupMember(WorkflowUser user) {
332: this .workflowId = user.getWorkflowId();
333: this .memberType = EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD;
334: this .displayName = user.getDisplayName();
335: this .authenticationId = user.getAuthenticationUserId()
336: .getAuthenticationId();
337: }
338:
339: public WorkgroupMember(Workgroup workgroup) {
340: this .workflowId = workgroup.getWorkflowGroupId()
341: .getGroupId().toString();
342: this .memberType = EdenConstants.ACTION_REQUEST_WORKGROUP_RECIPIENT_CD;
343: this .displayName = workgroup.getDisplayName();
344: }
345:
346: public String getWorkflowId() {
347: return workflowId;
348: }
349:
350: public void setWorkflowId(String workflowId) {
351: this .workflowId = workflowId;
352: }
353:
354: public String getMemberType() {
355: return memberType;
356: }
357:
358: public void setMemberType(String memberType) {
359: this .memberType = memberType;
360: }
361:
362: public String getAuthenticationId() {
363: return authenticationId;
364: }
365:
366: public void setAuthenticationId(String authenticationId) {
367: this .authenticationId = authenticationId;
368: }
369:
370: public String getDisplayName() {
371: return displayName;
372: }
373:
374: public void setDisplayName(String displayName) {
375: this .displayName = displayName;
376: }
377: }
378:
379: public String getCurrentWorkgroupType() {
380: return currentWorkgroupType;
381: }
382:
383: public void setCurrentWorkgroupType(String currentWorkgroupType) {
384: this .currentWorkgroupType = currentWorkgroupType;
385: }
386:
387: public WebExtensions getExtensions() {
388: return extensions;
389: }
390:
391: public void setExtensions(WebExtensions extensions) {
392: this .extensions = extensions;
393: }
394:
395: public WorkgroupType getWorkgroupType() {
396: return workgroupType;
397: }
398:
399: public void setWorkgroupType(WorkgroupType workgroupType) {
400: this .workgroupType = workgroupType;
401: }
402:
403: public boolean isWorkgroupTypeEditable() {
404: return workgroupTypeEditable;
405: }
406:
407: public void setWorkgroupTypeEditable(boolean workgroupTypeEditable) {
408: this .workgroupTypeEditable = workgroupTypeEditable;
409: }
410:
411: public boolean isReadOnly() {
412: return readOnly;
413: }
414:
415: public void setReadOnly(boolean readOnly) {
416: this .readOnly = readOnly;
417: }
418:
419: public List<KeyLabelPair> getMemberTypes() {
420: return memberTypes;
421: }
422:
423: public List<WorkgroupMember> getExistingWorkgroupMembers() {
424: return existingWorkgroupMembers;
425: }
426:
427: public void setExistingWorkgroupMembers(
428: List<WorkgroupMember> existingWorkgroupMembers) {
429: this.existingWorkgroupMembers = existingWorkgroupMembers;
430: }
431:
432: }
|