Source Code Cross Referenced for WorkgroupAction.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » workgroup » web » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.workgroup.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.Iterator;
021:        import java.util.List;
022:
023:        import javax.servlet.http.HttpServletRequest;
024:        import javax.servlet.http.HttpServletResponse;
025:
026:        import org.apache.commons.lang.ObjectUtils;
027:        import org.apache.commons.lang.StringUtils;
028:        import org.apache.struts.action.ActionForm;
029:        import org.apache.struts.action.ActionForward;
030:        import org.apache.struts.action.ActionMapping;
031:        import org.apache.struts.action.ActionMessage;
032:        import org.apache.struts.action.ActionMessages;
033:        import org.kuali.workflow.attribute.Extension;
034:        import org.kuali.workflow.attribute.ExtensionAttribute;
035:        import org.kuali.workflow.attribute.ExtensionData;
036:        import org.kuali.workflow.attribute.web.WebExtensions;
037:        import org.kuali.workflow.workgroup.BaseWorkgroupExtension;
038:        import org.kuali.workflow.workgroup.BaseWorkgroupExtensionData;
039:        import org.kuali.workflow.workgroup.WorkgroupType;
040:        import org.kuali.workflow.workgroup.WorkgroupTypeAttribute;
041:
042:        import edu.iu.uis.eden.EdenConstants;
043:        import edu.iu.uis.eden.KEWServiceLocator;
044:        import edu.iu.uis.eden.WorkflowServiceErrorException;
045:        import edu.iu.uis.eden.WorkflowServiceErrorImpl;
046:        import edu.iu.uis.eden.clientapp.IDocHandler;
047:        import edu.iu.uis.eden.clientapp.WorkflowDocument;
048:        import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
049:        import edu.iu.uis.eden.exception.EdenUserNotFoundException;
050:        import edu.iu.uis.eden.exception.WorkflowException;
051:        import edu.iu.uis.eden.exception.WorkflowRuntimeException;
052:        import edu.iu.uis.eden.export.ExportDataSet;
053:        import edu.iu.uis.eden.export.ExportFormat;
054:        import edu.iu.uis.eden.lookupable.Field;
055:        import edu.iu.uis.eden.lookupable.Row;
056:        import edu.iu.uis.eden.routeheader.Routable;
057:        import edu.iu.uis.eden.user.AuthenticationUserId;
058:        import edu.iu.uis.eden.user.Recipient;
059:        import edu.iu.uis.eden.user.WorkflowUser;
060:        import edu.iu.uis.eden.user.WorkflowUserId;
061:        import edu.iu.uis.eden.util.Utilities;
062:        import edu.iu.uis.eden.validation.ValidationContext;
063:        import edu.iu.uis.eden.validation.ValidationResults;
064:        import edu.iu.uis.eden.web.WorkflowAction;
065:        import edu.iu.uis.eden.workgroup.BaseWorkgroup;
066:        import edu.iu.uis.eden.workgroup.GroupNameId;
067:        import edu.iu.uis.eden.workgroup.WorkflowGroupId;
068:        import edu.iu.uis.eden.workgroup.Workgroup;
069:        import edu.iu.uis.eden.workgroup.WorkgroupRoutingService;
070:        import edu.iu.uis.eden.workgroup.WorkgroupService;
071:        import edu.iu.uis.eden.workgroup.web.WorkgroupForm.WorkgroupMember;
072:
073:        /**
074:         * A Struts Action which provides for creation, editing, and reporting on
075:         * {@link Workgroup}s.
076:         *
077:         * @see WorkgroupService
078:         *
079:         * @author xqi
080:         * @author rkirkend
081:         * @author temay
082:         * @author ewestfal
083:         */
084:        public class WorkgroupAction extends WorkflowAction {
085:
086:            protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
087:                    .getLogger(getClass());
088:
089:            public ActionForward start(ActionMapping mapping, ActionForm form,
090:                    HttpServletRequest request, HttpServletResponse response)
091:                    throws Exception {
092:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
093:                if (workgroupForm.getWorkgroup().getActiveInd() == null) {
094:                    workgroupForm.getWorkgroup().setActiveInd(Boolean.TRUE);
095:                }
096:                if (workgroupForm.getFlexDoc() == null) {
097:                    workgroupForm.setFlexDoc(getWorkgroupRoutingService()
098:                            .createWorkgroupDocument(getUserSession(request),
099:                                    workgroupForm.getWorkgroupType()));
100:                    workgroupForm.setDocId(workgroupForm.getFlexDoc()
101:                            .getRouteHeaderId());
102:                    workgroupForm.establishVisibleActionRequestCds();
103:                }
104:                return mapping.findForward("basic");
105:            }
106:
107:            public ActionForward edit(ActionMapping mapping, ActionForm form,
108:                    HttpServletRequest request, HttpServletResponse response)
109:                    throws Exception {
110:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
111:                // clear out any incoming members so that they don't appear twice
112:                workgroupForm.getWorkgroupMembers().clear();
113:                workgroupForm.setWorkgroupType(workgroupForm
114:                        .getExistingWorkgroupType());
115:                start(mapping, form, request, response);
116:                Workgroup existingWorkgroup = workgroupForm
117:                        .getExistingWorkgroup();
118:                WorkgroupType existingWorkgroupType = workgroupForm
119:                        .getExistingWorkgroupType();
120:                WebExtensions existingExtensions = workgroupForm
121:                        .getExistingExtensions();
122:                if (existingWorkgroup != null) {
123:                    Long lockedDocumentId = getWorkgroupRoutingService()
124:                            .getLockingDocumentId(
125:                                    existingWorkgroup.getWorkflowGroupId());
126:                    if (lockedDocumentId != null
127:                            && lockedDocumentId.longValue() > 0) {
128:                        ActionMessages messages = new ActionMessages();
129:                        messages
130:                                .add(
131:                                        ActionMessages.GLOBAL_MESSAGE,
132:                                        new ActionMessage(
133:                                                "workgroup.WorkgroupService.workgroupInRoute",
134:                                                "document " + lockedDocumentId));
135:                        saveMessages(request, messages);
136:                        workgroupForm.setWorkgroup(existingWorkgroup);
137:                        workgroupForm.setWorkgroupType(existingWorkgroupType);
138:                        workgroupForm.setExtensions(existingExtensions);
139:                        workgroupForm.setExistingWorkgroup(null);
140:                        workgroupForm.setExistingWorkgroupType(null);
141:                        workgroupForm.setExistingExtensions(null);
142:                        workgroupForm.setExistingWorkgroupMembers(null);
143:                        return mapping.findForward("summary");
144:                    }
145:                }
146:                // we are going to set the workgroup being edited as the existing workgroup, it is important to
147:                // note here that we are not making any changes to the existing workgroup (it could be an in-memory cached
148:                // version and should therefore be unmodifiable!  Instead it will effectively be
149:                // copied by the web tier and the form processing
150:                workgroupForm.setWorkgroup(existingWorkgroup);
151:                workgroupForm.setWorkgroupType(existingWorkgroupType);
152:                workgroupForm.setExtensions(existingExtensions);
153:                workgroupForm.loadWebWorkgroupValues();
154:                //initializeExtensions(workgroupForm);
155:                return mapping.findForward("basic");
156:            }
157:
158:            public ActionForward copy(ActionMapping mapping, ActionForm form,
159:                    HttpServletRequest request, HttpServletResponse response)
160:                    throws Exception {
161:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
162:                workgroupForm.getWorkgroup().setWorkflowGroupId(null);
163:                workgroupForm.setWorkgroupId(null);
164:                workgroupForm.setExistingWorkgroup(null);
165:                workgroupForm.setExistingWorkgroupType(null);
166:                workgroupForm.setExistingExtensions(null);
167:                workgroupForm.setExistingWorkgroupMembers(null);
168:                workgroupForm.setAnnotation(null);
169:                loadWorkgroupType(workgroupForm);
170:                initializeExtensions(workgroupForm);
171:                return start(mapping, form, request, response);
172:            }
173:
174:            public ActionForward addMember(ActionMapping mapping,
175:                    ActionForm form, HttpServletRequest request,
176:                    HttpServletResponse response) throws Exception {
177:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
178:                if (workgroupForm.getWorkgroupMember() != null
179:                        && !"".equals(workgroupForm.getWorkgroupMember())) {
180:                    List errors = new ArrayList();
181:                    if (EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD
182:                            .equals(workgroupForm.getMemberType())) {
183:                        try {
184:                            WorkflowUser user = KEWServiceLocator
185:                                    .getUserService()
186:                                    .getWorkflowUser(
187:                                            new AuthenticationUserId(
188:                                                    workgroupForm
189:                                                            .getWorkgroupMember()));
190:                            workgroupForm.getWorkgroup().getMembers().add(user);
191:                            workgroupForm.getWorkgroupMembers().add(
192:                                    new WorkgroupMember(user));
193:                        } catch (EdenUserNotFoundException e) {
194:                            LOG.warn("User "
195:                                    + workgroupForm.getWorkgroupMember()
196:                                    + " is invalid");
197:                            errors.add(new WorkflowServiceErrorImpl(
198:                                    "User is invalid",
199:                                    "user.userservice.id.invalid"));
200:                        }
201:                    } else if (EdenConstants.ACTION_REQUEST_WORKGROUP_RECIPIENT_CD
202:                            .equals(workgroupForm.getMemberType())) {
203:                        Workgroup workgroup = KEWServiceLocator
204:                                .getWorkgroupService().getWorkgroup(
205:                                        new GroupNameId(workgroupForm
206:                                                .getWorkgroupMember()));
207:                        if (workgroup == null) {
208:                            errors.add(new WorkflowServiceErrorImpl(
209:                                    "Workgroup is invalid",
210:                                    "workgroup.WorkgroupService.name.invalid"));
211:                        } else {
212:                            workgroupForm.getWorkgroup().getMembers().add(
213:                                    workgroup);
214:                            workgroupForm.getWorkgroupMembers().add(
215:                                    new WorkgroupMember(workgroup));
216:                        }
217:                    }
218:                    if (!errors.isEmpty()) {
219:                        throw new WorkflowServiceErrorException(
220:                                "Error occurred when adding a member", errors);
221:                    }
222:                    workgroupForm.setWorkgroupMember(null);
223:                }
224:                return mapping.findForward("basic");
225:            }
226:
227:            public ActionForward removeMember(ActionMapping mapping,
228:                    ActionForm form, HttpServletRequest request,
229:                    HttpServletResponse response) throws Exception {
230:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
231:                int removeIndex = new Integer(workgroupForm.getRemovedMember())
232:                        .intValue();
233:                workgroupForm.getWorkgroup().getMembers().remove(removeIndex);
234:                workgroupForm.getWorkgroupMembers().remove(removeIndex);
235:                workgroupForm.setRemovedMember(null);
236:                return mapping.findForward("basic");
237:            }
238:
239:            public ActionForward route(ActionMapping mapping, ActionForm form,
240:                    HttpServletRequest request, HttpServletResponse response)
241:                    throws Exception {
242:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
243:                establishFinalExtensionData(workgroupForm,
244:                        createValidationContext(workgroupForm, request));
245:                getWorkgroupRoutingService().route(
246:                        workgroupForm.getWorkgroup(), getUserSession(request),
247:                        workgroupForm.getAnnotation());
248:                ActionMessages messages = new ActionMessages();
249:                messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
250:                        "general.routing.routed", "Workgroup Document"));
251:                saveMessages(request, messages);
252:                return mapping.findForward("summary");
253:            }
254:
255:            /**
256:             * The validation context simply includes the parameters that were submitted with the form.
257:             */
258:            private ValidationContext createValidationContext(
259:                    WorkgroupForm workgroupForm, HttpServletRequest request) {
260:                ValidationContext context = new ValidationContext();
261:                // extract the extension values and add those as parameters
262:                context.getParameters().put("extensions",
263:                        workgroupForm.getExtensions().getData());
264:                context.getParameters().put("operation", "entry");
265:                return context;
266:            }
267:
268:            private void establishFinalExtensionData(
269:                    WorkgroupForm workgroupForm,
270:                    ValidationContext validationContext) {
271:                List<Object> errors = new ArrayList<Object>();
272:                WebExtensions extensions = workgroupForm.getExtensions();
273:                Workgroup workgroup = workgroupForm.getWorkgroup();
274:                WorkgroupType workgroupType = workgroupForm.getWorkgroupType();
275:                if (workgroupType != null) {
276:                    for (WorkgroupTypeAttribute workgroupTypeAttribute : workgroupForm
277:                            .getWorkgroupType().getActiveAttributes()) {
278:                        Object attribute = workgroupTypeAttribute
279:                                .loadAttribute();
280:                        if (attribute instanceof  ExtensionAttribute) {
281:                            BaseWorkgroupExtension extension = new BaseWorkgroupExtension();
282:                            extension.setWorkgroup((BaseWorkgroup) workgroup);
283:                            extension
284:                                    .setWorkgroupTypeAttribute(workgroupTypeAttribute);
285:                            ExtensionAttribute collectionAttribute = (ExtensionAttribute) attribute;
286:                            ValidationResults results = collectionAttribute
287:                                    .validate(validationContext);
288:                            if (results != null
289:                                    && !results.getValidationResults()
290:                                            .isEmpty()) {
291:                                errors.add(results);
292:                            }
293:                            for (Row row : collectionAttribute.getRows()) {
294:                                for (Field field : row.getFields()) {
295:                                    if (extensions.getData().containsKey(
296:                                            field.getPropertyName())) {
297:                                        String fieldValue = extensions
298:                                                .getData()
299:                                                .get(field.getPropertyName());
300:                                        BaseWorkgroupExtensionData extensionData = new BaseWorkgroupExtensionData();
301:                                        extensionData.setKey(field
302:                                                .getPropertyName());
303:                                        extensionData.setValue(fieldValue);
304:                                        extensionData
305:                                                .setWorkgroupExtension(extension);
306:                                        extension.getData().add(extensionData);
307:                                    }
308:                                }
309:                            }
310:                            if (!extension.getData().isEmpty()) {
311:                                workgroup.getExtensions().add(extension);
312:                            }
313:                        }
314:                    }
315:                }
316:                if (!errors.isEmpty()) {
317:                    throw new WorkflowServiceErrorException(
318:                            "Workgroup extension errors", errors);
319:                }
320:            }
321:
322:            public ActionForward clear(ActionMapping mapping, ActionForm form,
323:                    HttpServletRequest request, HttpServletResponse response)
324:                    throws Exception {
325:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
326:                if (workgroupForm.getShowEdit().equals("yes")) {
327:                    workgroupForm.setWorkgroup(workgroupForm
328:                            .getExistingWorkgroup());
329:                    workgroupForm.setWorkgroupType(workgroupForm
330:                            .getExistingWorkgroupType());
331:                    workgroupForm.setWorkgroupName(workgroupForm.getWorkgroup()
332:                            .getGroupNameId().getNameId());
333:                    workgroupForm.setWorkgroupMember(null);
334:                    workgroupForm.setAnnotation(null);
335:
336:                } else {
337:                    workgroupForm.setWorkgroup(getWorkgroupService()
338:                            .getBlankWorkgroup());
339:                    workgroupForm.setWorkgroupName("");
340:                    workgroupForm.getWorkgroup()
341:                            .setActiveInd(new Boolean(true));
342:                    workgroupForm.setWorkgroupMember(null);
343:                    workgroupForm.setAnnotation(null);
344:                    workgroupForm.getExtensions().clear();
345:                    workgroupForm.setExistingWorkgroup(null);
346:                    workgroupForm.setExistingWorkgroupType(null);
347:                    workgroupForm.setExistingWorkgroupMembers(null);
348:                }
349:                return mapping.findForward("basic");
350:            }
351:
352:            public ActionForward docHandler(ActionMapping mapping,
353:                    ActionForm form, HttpServletRequest request,
354:                    HttpServletResponse response) throws Exception {
355:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
356:                if (IDocHandler.INITIATE_COMMAND.equalsIgnoreCase(workgroupForm
357:                        .getCommand())) {
358:                    return start(mapping, form, request, response);
359:                } else {
360:                    if (workgroupForm.getFlexDoc().stateIsInitiated()
361:                            && workgroupForm.getFlexDoc().getRouteHeader()
362:                                    .getInitiator().getWorkflowId().equals(
363:                                            getUserSession(request)
364:                                                    .getWorkflowUser()
365:                                                    .getWorkflowId())) {
366:                        return start(mapping, form, request, response);
367:                    }
368:                    //workgroupForm.getWorkgroup().setRouteHeaderId(workgroupForm.getFlexDoc().getRouteHeaderId());
369:                    Workgroup workgroup = getWorkgroupRoutingService()
370:                            .findByDocumentId(workgroupForm.getDocId());
371:                    Routable routableWorkgroup = validateWorkgroupIsRoutable(workgroup);
372:                    if (workgroup != null) {
373:                        if (!routableWorkgroup.getCurrentInd().booleanValue()) {
374:                            // the existing workgroup will be the current workgroup from the cache
375:                            workgroupForm
376:                                    .setExistingWorkgroup(getWorkgroupService()
377:                                            .getWorkgroup(
378:                                                    workgroup
379:                                                            .getWorkflowGroupId()));
380:                            loadWorkgroupType(workgroupForm);
381:                            initializeExtensions(workgroupForm
382:                                    .getExistingExtensions(), workgroupForm
383:                                    .getExistingWorkgroup(), workgroupForm
384:                                    .getExistingWorkgroupType());
385:                        }
386:                        workgroupForm.setWorkgroup(workgroup);
387:                        workgroupForm.setWorkgroupName(workgroup
388:                                .getGroupNameId().getNameId());
389:                        workgroupForm.setWorkgroupId(workgroup
390:                                .getWorkflowGroupId().getGroupId());
391:                    }
392:                    workgroupForm.loadWebWorkgroupValues();
393:                    loadWorkgroupType(workgroupForm);
394:                    initializeExtensions(workgroupForm);
395:                    initializeExistingWorkgroupMembers(workgroupForm);
396:                    return mapping.findForward("docHandler");
397:                }
398:            }
399:
400:            public ActionForward refresh(ActionMapping mapping,
401:                    ActionForm form, HttpServletRequest request,
402:                    HttpServletResponse response) throws Exception {
403:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
404:                if (request.getParameter("networkId") != null
405:                        && !request.getParameter("networkId").equals("")) {
406:                    workgroupForm.setWorkgroupMember(request
407:                            .getParameter("networkId"));
408:                }
409:
410:                return mapping.findForward("basic");
411:            }
412:
413:            public ActionMessages establishRequiredState(
414:                    HttpServletRequest request, ActionForm form)
415:                    throws Exception {
416:
417:                request.getSession().getServletContext().setAttribute(
418:                        "WorkgroupCaps",
419:                        KEWServiceLocator.getWorkgroupService()
420:                                .getCapabilities());
421:
422:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
423:
424:                if (workgroupForm.getMethodToCall().equals("docHandler")
425:                        || workgroupForm.getMethodToCall().equals("report")) {
426:                    workgroupForm.setReadOnly(true);
427:                }
428:
429:                if (workgroupForm.getWorkgroupId() != null
430:                        && workgroupForm.getWorkgroupId().longValue() > 0) {
431:                    Workgroup existingWorkgroup = getWorkgroupService()
432:                            .getWorkgroup(
433:                                    new WorkflowGroupId(workgroupForm
434:                                            .getWorkgroupId()));
435:                    workgroupForm.setExistingWorkgroup(existingWorkgroup);
436:                }
437:
438:                workgroupForm.setWorkgroupTypes(KEWServiceLocator
439:                        .getWorkgroupTypeService().findAllActive());
440:                workgroupForm.getWorkgroupTypes().add(0,
441:                        WorkgroupForm.createDefaultWorkgroupType());
442:                loadWorkgroupType(workgroupForm);
443:
444:                if (workgroupForm.getDocId() != null) {
445:                    workgroupForm.setFlexDoc(new WorkflowDocument(
446:                            new WorkflowIdVO(getUserSession(request)
447:                                    .getWorkflowUser().getWorkflowId()),
448:                            workgroupForm.getDocId()));
449:                }
450:
451:                boolean typeChanged = workgroupForm.getCurrentWorkgroupType() != null
452:                        && !ObjectUtils.equals(workgroupForm
453:                                .getCurrentWorkgroupType(), workgroupForm
454:                                .getWorkgroup().getWorkgroupType());
455:                if (!workgroupForm.isReadOnly() && typeChanged
456:                        && workgroupForm.getFlexDoc() != null) {
457:                    workgroupForm
458:                            .getFlexDoc()
459:                            .cancel(
460:                                    "Workgroup Type was changed from "
461:                                            + renderWorkgroupTypeName(workgroupForm
462:                                                    .getCurrentWorkgroupType())
463:                                            + " to "
464:                                            + renderWorkgroupTypeName(workgroupForm
465:                                                    .getWorkgroup()
466:                                                    .getWorkgroupType()));
467:                    workgroupForm.setFlexDoc(getWorkgroupRoutingService()
468:                            .createWorkgroupDocument(getUserSession(request),
469:                                    workgroupForm.getWorkgroupType()));
470:                    workgroupForm.setDocId(workgroupForm.getFlexDoc()
471:                            .getRouteHeaderId());
472:                    workgroupForm.establishVisibleActionRequestCds();
473:                }
474:                workgroupForm.setCurrentWorkgroupType(workgroupForm
475:                        .getWorkgroup().getWorkgroupType());
476:                // set up the workgroup name and id on the workgroup from the form
477:                Workgroup workgroup = workgroupForm.getWorkgroup();
478:                workgroup
479:                        .setWorkflowGroupId(workgroupForm.getWorkgroupId() == null ? null
480:                                : new WorkflowGroupId(workgroupForm
481:                                        .getWorkgroupId()));
482:                workgroup
483:                        .setGroupNameId(workgroupForm.getWorkgroupName() == null ? null
484:                                : new GroupNameId(workgroupForm
485:                                        .getWorkgroupName()));
486:                // setup the workgroup's members
487:                workgroup.getMembers().clear();
488:                for (Iterator iterator = workgroupForm.getWorkgroupMembers()
489:                        .iterator(); iterator.hasNext();) {
490:                    WorkgroupMember member = (WorkgroupMember) iterator.next();
491:                    if (member.getMemberType().equals(
492:                            EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD)) {
493:                        workgroup.getMembers().add(
494:                                KEWServiceLocator.getUserService()
495:                                        .getWorkflowUser(
496:                                                new WorkflowUserId(member
497:                                                        .getWorkflowId())));
498:                    } else if (member
499:                            .getMemberType()
500:                            .equals(
501:                                    EdenConstants.ACTION_REQUEST_WORKGROUP_RECIPIENT_CD)) {
502:                        workgroup
503:                                .getMembers()
504:                                .add(
505:                                        KEWServiceLocator
506:                                                .getWorkgroupService()
507:                                                .getWorkgroup(
508:                                                        new WorkflowGroupId(
509:                                                                Long
510:                                                                        .parseLong(member
511:                                                                                .getWorkflowId()))));
512:                    }
513:                }
514:
515:                if (workgroupForm.getDocId() != null) {
516:                    workgroupForm.establishVisibleActionRequestCds();
517:                    if (workgroupForm.isRoutable()) {
518:                        workgroupForm.getRoutableWorkgroup().setDocumentId(
519:                                workgroupForm.getDocId());
520:                    }
521:                }
522:                // determine if blanket approve is cool
523:                if (workgroupForm.getFlexDoc() != null) {
524:                    workgroupForm.setShowBlanketApproveButton(workgroupForm
525:                            .getFlexDoc().isBlanketApproveCapable());
526:                }
527:
528:                initializeExtensions(workgroupForm);
529:                if (workgroupForm.getExistingWorkgroup() != null) {
530:                    initializeExtensions(workgroupForm.getExistingExtensions(),
531:                            workgroupForm.getExistingWorkgroup(), workgroupForm
532:                                    .getExistingWorkgroupType());
533:                    initializeExistingWorkgroupMembers(workgroupForm);
534:                }
535:                return null;
536:            }
537:
538:            @Override
539:            public ActionMessages establishFinalState(
540:                    HttpServletRequest request, ActionForm form)
541:                    throws Exception {
542:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
543:                // we only want to be able to change the workgroup type if the doc is initated (the workgroup type specifies the doc type)
544:                if (workgroupForm.getFlexDoc() != null) {
545:                    workgroupForm.setWorkgroupTypeEditable(workgroupForm
546:                            .getFlexDoc().stateIsInitiated());
547:                }
548:                return null;
549:            }
550:
551:            private String renderWorkgroupTypeName(String workgroupTypeName) {
552:                if (StringUtils.isEmpty(workgroupTypeName)) {
553:                    return "Default";
554:                }
555:                return workgroupTypeName;
556:            }
557:
558:            private void loadWorkgroupType(WorkgroupForm workgroupForm) {
559:                String workgroupTypeCode = workgroupForm.getWorkgroup()
560:                        .getWorkgroupType();
561:                WorkgroupType workgroupType = null;
562:                if (!isDefaultWorkgroupType(workgroupTypeCode)) {
563:                    workgroupType = KEWServiceLocator.getWorkgroupTypeService()
564:                            .findByName(workgroupTypeCode);
565:                    if (workgroupType == null) {
566:                        throw new WorkflowRuntimeException(
567:                                "Failed to locate workgroup type with the given code '"
568:                                        + workgroupTypeCode + "'");
569:                    }
570:                }
571:                workgroupForm.setWorkgroupType(workgroupType);
572:
573:                if (workgroupForm.getExistingWorkgroup() != null) {
574:                    WorkgroupType existingType = null;
575:                    if (!isDefaultWorkgroupType(workgroupForm
576:                            .getExistingWorkgroup().getWorkgroupType())) {
577:                        existingType = KEWServiceLocator
578:                                .getWorkgroupTypeService().findByName(
579:                                        workgroupForm.getExistingWorkgroup()
580:                                                .getWorkgroupType());
581:                        if (existingType == null) {
582:                            throw new WorkflowRuntimeException(
583:                                    "Failed to locate workgroup type with the given code '"
584:                                            + workgroupForm
585:                                                    .getExistingWorkgroup()
586:                                                    .getWorkgroupType() + "'");
587:                        }
588:                    }
589:                    workgroupForm.setExistingWorkgroupType(existingType);
590:                }
591:
592:            }
593:
594:            private void initializeExtensions(WebExtensions extensions,
595:                    Workgroup workgroup, WorkgroupType workgroupType) {
596:                if (workgroup == null) {
597:                    return;
598:                }
599:                // clear the rows out for the case when we are coming back from a lookup and the form was restored from session
600:                extensions.clearRows();
601:                if (workgroupType != null) {
602:                    for (WorkgroupTypeAttribute workgroupTypeAttribute : workgroupType
603:                            .getActiveAttributes()) {
604:                        Object attribute = workgroupTypeAttribute
605:                                .loadAttribute();
606:                        if (attribute instanceof  ExtensionAttribute) {
607:                            ExtensionAttribute collectionAttribute = (ExtensionAttribute) attribute;
608:                            extensions.load(collectionAttribute);
609:                        }
610:                    }
611:                }
612:                // copy workgroup extension data over
613:                for (Extension extension : workgroup.getExtensions()) {
614:                    for (ExtensionData data : extension.getData()) {
615:                        if (extensions.getData().containsKey(data.getKey())) {
616:                            extensions.getData().put(data.getKey(),
617:                                    data.getValue());
618:                        }
619:                    }
620:                }
621:            }
622:
623:            private void initializeExtensions(WorkgroupForm workgroupForm) {
624:                initializeExtensions(workgroupForm.getExtensions(),
625:                        workgroupForm.getWorkgroup(), workgroupForm
626:                                .getWorkgroupType());
627:            }
628:
629:            private void initializeExistingWorkgroupMembers(
630:                    WorkgroupForm workgroupForm) {
631:                if (workgroupForm.getExistingWorkgroup() != null) {
632:                    List<WorkgroupMember> existingMembers = new ArrayList<WorkgroupMember>();
633:                    for (Recipient member : workgroupForm
634:                            .getExistingWorkgroup().getMembers()) {
635:                        if (member instanceof  WorkflowUser) {
636:                            WorkflowUser user = (WorkflowUser) member;
637:                            existingMembers.add(new WorkgroupMember(user));
638:                        } else if (member instanceof  Workgroup) {
639:                            Workgroup nestedWorkgroup = (Workgroup) member;
640:                            existingMembers.add(new WorkgroupMember(
641:                                    nestedWorkgroup));
642:                        }
643:                    }
644:                    workgroupForm.setExistingWorkgroupMembers(existingMembers);
645:                }
646:            }
647:
648:            private boolean isDefaultWorkgroupType(String workgroupTypeCode) {
649:                return StringUtils.isEmpty(workgroupTypeCode)
650:                        || workgroupTypeCode
651:                                .equals(EdenConstants.LEGACY_DEFAULT_WORKGROUP_TYPE);
652:            }
653:
654:            public ActionForward report(ActionMapping mapping, ActionForm form,
655:                    HttpServletRequest request, HttpServletResponse response)
656:                    throws Exception {
657:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
658:                // establish required state will load the workgroup which we desire into the existingWorkgroup property on the form
659:                workgroupForm
660:                        .setWorkgroup(workgroupForm.getExistingWorkgroup());
661:                workgroupForm.loadWebWorkgroupValues();
662:                workgroupForm.setExistingWorkgroup(null);
663:                workgroupForm.setExistingWorkgroupType(null);
664:                workgroupForm.setExistingExtensions(null);
665:                workgroupForm.setExistingWorkgroupMembers(null);
666:                workgroupForm.setAnnotation(null);
667:                loadWorkgroupType(workgroupForm);
668:                initializeExtensions(workgroupForm);
669:                return mapping.findForward("report");
670:            }
671:
672:            public ActionForward blanketApprove(ActionMapping mapping,
673:                    ActionForm form, HttpServletRequest request,
674:                    HttpServletResponse response) throws Exception {
675:                LOG.info("entering blanketApprove() method ...");
676:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
677:                establishFinalExtensionData(workgroupForm,
678:                        createValidationContext(workgroupForm, request));
679:                getWorkgroupRoutingService().blanketApprove(
680:                        workgroupForm.getWorkgroup(), getUserSession(request),
681:                        workgroupForm.getAnnotation());
682:                saveDocumentActionMessage("general.routing.blanketApproved",
683:                        request);
684:                //workgroupForm.getWorkgroup().getMembersFromWorkgroupMembers();
685:                return mapping.findForward("summary");
686:            }
687:
688:            private void saveDocumentActionMessage(String messageKey,
689:                    HttpServletRequest request) {
690:                saveDocumentActionMessage(messageKey, request, null);
691:            }
692:
693:            private void saveDocumentActionMessage(String messageKey,
694:                    HttpServletRequest request, String secondMessageParameter) {
695:                ActionMessages messages = new ActionMessages();
696:                if (Utilities.isEmpty(secondMessageParameter)) {
697:                    messages.add(ActionMessages.GLOBAL_MESSAGE,
698:                            new ActionMessage(messageKey, "document"));
699:                } else {
700:                    messages.add(ActionMessages.GLOBAL_MESSAGE,
701:                            new ActionMessage(messageKey, "document",
702:                                    secondMessageParameter));
703:                }
704:                saveMessages(request, messages);
705:            }
706:
707:            public ActionForward performLookup(ActionMapping mapping,
708:                    ActionForm form, HttpServletRequest request,
709:                    HttpServletResponse response) throws Exception {
710:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
711:
712:                String lookupService = request
713:                        .getParameter("lookupableImplServiceName");
714:                String conversionFields = request
715:                        .getParameter("conversionFields");
716:                if (lookupService.equals("memberLookup")) {
717:                    if (workgroupForm
718:                            .getMemberType()
719:                            .equals(
720:                                    EdenConstants.ACTION_REQUEST_WORKGROUP_RECIPIENT_CD)) {
721:                        lookupService = "WorkGroupLookupableImplService";
722:                        conversionFields = "workgroupName:workgroupMember,workgroupId:null";
723:                    } else if (workgroupForm.getMemberType().equals(
724:                            EdenConstants.ACTION_REQUEST_USER_RECIPIENT_CD)) {
725:                        lookupService = "UserLookupableImplService";
726:                    }
727:                }
728:                String basePath = request.getScheme() + "://"
729:                        + request.getServerName() + ":"
730:                        + request.getServerPort() + request.getContextPath()
731:                        + mapping.getModuleConfig().getPrefix();
732:                StringBuffer lookupUrl = new StringBuffer(basePath);
733:                lookupUrl.append("/Lookup.do?methodToCall=start&docFormKey=")
734:                        .append(getUserSession(request).addObject(form))
735:                        .append("&lookupableImplServiceName=");
736:                lookupUrl.append(lookupService);
737:                lookupUrl.append("&conversionFields=").append(conversionFields);
738:
739:                //        String lookupType = workgroupForm.getLookupType();
740:                //        workgroupForm.setLookupType(null);
741:                //
742:                //        if (lookupType != null && !lookupType.equals("")) {
743:                //            lookupUrl.append("&conversionFields=");
744:                //            WorkflowLookupable workflowLookupable = (WorkflowLookupable) GlobalResourceLoader.getService(request.getParameter("lookupableImplServiceName"));// SpringServiceLocator.getExtensionService().getLookupable(request.getParameter("lookupableImplServiceName"));
745:                //            for (Iterator iterator = workflowLookupable.getDefaultReturnType().iterator(); iterator.hasNext();) {
746:                //                String returnType = (String) iterator.next();
747:                //                lookupUrl.append(returnType).append(":").append(lookupType);
748:                //            }
749:                //        }
750:
751:                lookupUrl.append("&returnLocation=").append(basePath).append(
752:                        mapping.getPath()).append(".do");
753:                return new ActionForward(lookupUrl.toString(), true);
754:            }
755:
756:            public ActionForward export(ActionMapping mapping, ActionForm form,
757:                    HttpServletRequest request, HttpServletResponse response)
758:                    throws Exception {
759:                WorkgroupForm workgroupForm = (WorkgroupForm) form;
760:                Workgroup workgroup = workgroupForm.getExistingWorkgroup();
761:                ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
762:                dataSet.getWorkgroups().add(workgroup);
763:                return exportDataSet(request, dataSet);
764:            }
765:
766:            private Routable validateWorkgroupIsRoutable(Workgroup workgroup)
767:                    throws WorkflowException {
768:                if (!(workgroup instanceof  Routable)) {
769:                    throw new WorkflowException(
770:                            "Workgroup instances must implement Routable in order to support document routing interfaces.");
771:                }
772:                return (Routable) workgroup;
773:            }
774:
775:            private WorkgroupService getWorkgroupService() {
776:                return KEWServiceLocator.getWorkgroupService();
777:            }
778:
779:            private WorkgroupRoutingService getWorkgroupRoutingService() {
780:                return KEWServiceLocator.getWorkgroupRoutingService();
781:            }
782:
783:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.