Source Code Cross Referenced for BeanConverter.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » server » 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.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2005-2006 The Kuali Foundation.
0003:         *
0004:         *
0005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
0006:         * you may not use this file except in compliance with the License.
0007:         * You may obtain a copy of the License at
0008:         *
0009:         * http://www.opensource.org/licenses/ecl1.php
0010:         *
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS,
0013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         * See the License for the specific language governing permissions and
0015:         * limitations under the License.
0016:         */
0017:        package edu.iu.uis.eden.server;
0018:
0019:        import java.sql.Timestamp;
0020:        import java.util.ArrayList;
0021:        import java.util.Collection;
0022:        import java.util.Date;
0023:        import java.util.HashMap;
0024:        import java.util.Iterator;
0025:        import java.util.List;
0026:        import java.util.Map;
0027:
0028:        import javax.xml.parsers.DocumentBuilder;
0029:        import javax.xml.parsers.DocumentBuilderFactory;
0030:
0031:        import org.apache.commons.lang.StringUtils;
0032:        import org.apache.log4j.Logger;
0033:        import org.kuali.rice.definition.DataDefinition;
0034:        import org.kuali.rice.definition.ObjectDefinition;
0035:        import org.kuali.rice.definition.PropertyDefinition;
0036:        import org.kuali.rice.resourceloader.GlobalResourceLoader;
0037:        import org.w3c.dom.Document;
0038:        import org.w3c.dom.Element;
0039:        import org.w3c.dom.NodeList;
0040:
0041:        import edu.iu.uis.eden.ActionTakenEvent;
0042:        import edu.iu.uis.eden.DocumentRouteLevelChange;
0043:        import edu.iu.uis.eden.DocumentRouteStatusChange;
0044:        import edu.iu.uis.eden.EdenConstants;
0045:        import edu.iu.uis.eden.KEWServiceLocator;
0046:        import edu.iu.uis.eden.actionlist.ActionToTake;
0047:        import edu.iu.uis.eden.actionrequests.ActionRequestFactory;
0048:        import edu.iu.uis.eden.actionrequests.ActionRequestValue;
0049:        import edu.iu.uis.eden.actions.AdHocRevoke;
0050:        import edu.iu.uis.eden.actions.MovePoint;
0051:        import edu.iu.uis.eden.actions.ValidActions;
0052:        import edu.iu.uis.eden.actiontaken.ActionTakenValue;
0053:        import edu.iu.uis.eden.clientapp.DeleteEvent;
0054:        import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
0055:        import edu.iu.uis.eden.clientapp.vo.ActionTakenEventVO;
0056:        import edu.iu.uis.eden.clientapp.vo.ActionTakenVO;
0057:        import edu.iu.uis.eden.clientapp.vo.AdHocRevokeVO;
0058:        import edu.iu.uis.eden.clientapp.vo.DeleteEventVO;
0059:        import edu.iu.uis.eden.clientapp.vo.DocumentContentVO;
0060:        import edu.iu.uis.eden.clientapp.vo.DocumentDetailVO;
0061:        import edu.iu.uis.eden.clientapp.vo.DocumentRouteLevelChangeVO;
0062:        import edu.iu.uis.eden.clientapp.vo.DocumentRouteStatusChangeVO;
0063:        import edu.iu.uis.eden.clientapp.vo.DocumentTypeVO;
0064:        import edu.iu.uis.eden.clientapp.vo.EmplIdVO;
0065:        import edu.iu.uis.eden.clientapp.vo.MovePointVO;
0066:        import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
0067:        import edu.iu.uis.eden.clientapp.vo.NoteVO;
0068:        import edu.iu.uis.eden.clientapp.vo.ProcessVO;
0069:        import edu.iu.uis.eden.clientapp.vo.PropertyDefinitionVO;
0070:        import edu.iu.uis.eden.clientapp.vo.ReportActionToTakeVO;
0071:        import edu.iu.uis.eden.clientapp.vo.ReportCriteriaVO;
0072:        import edu.iu.uis.eden.clientapp.vo.ResponsiblePartyVO;
0073:        import edu.iu.uis.eden.clientapp.vo.RouteHeaderVO;
0074:        import edu.iu.uis.eden.clientapp.vo.RouteNodeInstanceVO;
0075:        import edu.iu.uis.eden.clientapp.vo.RouteNodeVO;
0076:        import edu.iu.uis.eden.clientapp.vo.RoutePathVO;
0077:        import edu.iu.uis.eden.clientapp.vo.RouteTemplateEntryVO;
0078:        import edu.iu.uis.eden.clientapp.vo.RuleDelegationVO;
0079:        import edu.iu.uis.eden.clientapp.vo.RuleExtensionVO;
0080:        import edu.iu.uis.eden.clientapp.vo.RuleResponsibilityVO;
0081:        import edu.iu.uis.eden.clientapp.vo.RuleVO;
0082:        import edu.iu.uis.eden.clientapp.vo.StateVO;
0083:        import edu.iu.uis.eden.clientapp.vo.UserIdVO;
0084:        import edu.iu.uis.eden.clientapp.vo.UserVO;
0085:        import edu.iu.uis.eden.clientapp.vo.UuIdVO;
0086:        import edu.iu.uis.eden.clientapp.vo.ValidActionsVO;
0087:        import edu.iu.uis.eden.clientapp.vo.WorkflowAttributeDefinitionVO;
0088:        import edu.iu.uis.eden.clientapp.vo.WorkflowAttributeValidationErrorVO;
0089:        import edu.iu.uis.eden.clientapp.vo.WorkflowGroupIdVO;
0090:        import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
0091:        import edu.iu.uis.eden.clientapp.vo.WorkgroupIdVO;
0092:        import edu.iu.uis.eden.clientapp.vo.WorkgroupNameIdVO;
0093:        import edu.iu.uis.eden.clientapp.vo.WorkgroupVO;
0094:        import edu.iu.uis.eden.definition.AttributeDefinition;
0095:        import edu.iu.uis.eden.docsearch.SearchableAttribute;
0096:        import edu.iu.uis.eden.docsearch.xml.GenericXMLSearchableAttribute;
0097:        import edu.iu.uis.eden.doctype.DocumentType;
0098:        import edu.iu.uis.eden.engine.CompatUtils;
0099:        import edu.iu.uis.eden.engine.node.BranchState;
0100:        import edu.iu.uis.eden.engine.node.KeyValuePair;
0101:        import edu.iu.uis.eden.engine.node.Process;
0102:        import edu.iu.uis.eden.engine.node.RouteNode;
0103:        import edu.iu.uis.eden.engine.node.RouteNodeInstance;
0104:        import edu.iu.uis.eden.engine.node.State;
0105:        import edu.iu.uis.eden.engine.simulation.SimulationActionToTake;
0106:        import edu.iu.uis.eden.engine.simulation.SimulationCriteria;
0107:        import edu.iu.uis.eden.exception.DocumentTypeNotFoundException;
0108:        import edu.iu.uis.eden.exception.EdenUserNotFoundException;
0109:        import edu.iu.uis.eden.exception.WorkflowException;
0110:        import edu.iu.uis.eden.exception.WorkflowRuntimeException;
0111:        import edu.iu.uis.eden.notes.Note;
0112:        import edu.iu.uis.eden.notes.NoteService;
0113:        import edu.iu.uis.eden.plugin.attributes.WorkflowAttribute;
0114:        import edu.iu.uis.eden.plugin.attributes.WorkflowAttributeXmlValidator;
0115:        import edu.iu.uis.eden.routeheader.DocumentContent;
0116:        import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
0117:        import edu.iu.uis.eden.routeheader.StandardDocumentContent;
0118:        import edu.iu.uis.eden.routetemplate.RuleAttribute;
0119:        import edu.iu.uis.eden.routetemplate.RuleBaseValues;
0120:        import edu.iu.uis.eden.routetemplate.RuleDelegation;
0121:        import edu.iu.uis.eden.routetemplate.RuleExtension;
0122:        import edu.iu.uis.eden.routetemplate.RuleExtensionValue;
0123:        import edu.iu.uis.eden.routetemplate.RuleResponsibility;
0124:        import edu.iu.uis.eden.routetemplate.WorkflowAttributeValidationError;
0125:        import edu.iu.uis.eden.routetemplate.xmlrouting.GenericXMLRuleAttribute;
0126:        import edu.iu.uis.eden.user.AuthenticationUserId;
0127:        import edu.iu.uis.eden.user.EmplId;
0128:        import edu.iu.uis.eden.user.Recipient;
0129:        import edu.iu.uis.eden.user.RoleRecipient;
0130:        import edu.iu.uis.eden.user.UserId;
0131:        import edu.iu.uis.eden.user.UuId;
0132:        import edu.iu.uis.eden.user.WorkflowUser;
0133:        import edu.iu.uis.eden.user.WorkflowUserId;
0134:        import edu.iu.uis.eden.util.ResponsibleParty;
0135:        import edu.iu.uis.eden.util.Utilities;
0136:        import edu.iu.uis.eden.util.XmlHelper;
0137:        import edu.iu.uis.eden.workgroup.GroupId;
0138:        import edu.iu.uis.eden.workgroup.GroupNameId;
0139:        import edu.iu.uis.eden.workgroup.WorkflowGroupId;
0140:        import edu.iu.uis.eden.workgroup.Workgroup;
0141:
0142:        /**
0143:         * Translates Workflow server side beans into client side VO beans.
0144:         *
0145:         * @author rkirkend
0146:         * @author ewestfal
0147:         * @author ahamid
0148:         */
0149:        public class BeanConverter {
0150:            private static final Logger LOG = Logger
0151:                    .getLogger(BeanConverter.class);
0152:
0153:            public static RouteHeaderVO convertRouteHeader(
0154:                    DocumentRouteHeaderValue routeHeader, WorkflowUser user)
0155:                    throws WorkflowException, EdenUserNotFoundException {
0156:                RouteHeaderVO routeHeaderVO = new RouteHeaderVO();
0157:                if (routeHeader == null) {
0158:                    return null;
0159:                }
0160:                populateRouteHeaderVO(routeHeaderVO, routeHeader);
0161:
0162:                if (user != null) {
0163:                    routeHeaderVO.setUserBlanketApprover(false); // default to false
0164:                    if (routeHeader.getDocumentType() != null) {
0165:                        routeHeaderVO.setUserBlanketApprover(routeHeader
0166:                                .getDocumentType().isUserBlanketApprover(user));
0167:                    }
0168:                    String topActionRequested = EdenConstants.ACTION_REQUEST_FYI_REQ;
0169:                    for (Iterator iter = routeHeader.getActionRequests()
0170:                            .iterator(); iter.hasNext();) {
0171:                        ActionRequestValue actionRequest = (ActionRequestValue) iter
0172:                                .next();
0173:                        // below will control what buttons are drawn on the client we only want the
0174:                        // heaviest action button to show on the client making this code a little combersome
0175:                        if (actionRequest.isRecipientRoutedRequest(user)
0176:                                && actionRequest.isActive()) {
0177:                            int actionRequestComparison = ActionRequestValue
0178:                                    .compareActionCode(actionRequest
0179:                                            .getActionRequested(),
0180:                                            topActionRequested);
0181:                            if (actionRequest.isFYIRequest()
0182:                                    && actionRequestComparison >= 0) {
0183:                                routeHeaderVO.setFyiRequested(true);
0184:                            } else if (actionRequest.isAcknowledgeRequest()
0185:                                    && actionRequestComparison >= 0) {
0186:                                routeHeaderVO.setAckRequested(true);
0187:                                routeHeaderVO.setFyiRequested(false);
0188:                                topActionRequested = actionRequest
0189:                                        .getActionRequested();
0190:                            } else if (actionRequest.isApproveRequest()
0191:                                    && actionRequestComparison >= 0) {
0192:                                routeHeaderVO.setApproveRequested(true);
0193:                                routeHeaderVO.setAckRequested(false);
0194:                                routeHeaderVO.setFyiRequested(false);
0195:                                topActionRequested = actionRequest
0196:                                        .getActionRequested();
0197:                                if (actionRequest.isCompleteRequst()) {
0198:                                    routeHeaderVO.setCompleteRequested(true);
0199:                                }
0200:                            }
0201:                        }
0202:                    }
0203:                    // Update notes and notesToDelete arrays in routeHeaderVO
0204:                    routeHeaderVO.setNotesToDelete(null);
0205:                    routeHeaderVO
0206:                            .setNotes(convertNotesArrayListToNoteVOArray(routeHeader
0207:                                    .getNotes()));
0208:                }
0209:
0210:                if (user != null) {
0211:                    routeHeaderVO
0212:                            .setValidActions(convertValidActions(KEWServiceLocator
0213:                                    .getActionRegistry().getValidActions(user,
0214:                                            routeHeader)));
0215:                }
0216:                return routeHeaderVO;
0217:            }
0218:
0219:            public static RouteHeaderVO convertActionListRouteHeader(
0220:                    DocumentRouteHeaderValue routeHeader, WorkflowUser user)
0221:                    throws WorkflowException, EdenUserNotFoundException {
0222:                RouteHeaderVO routeHeaderVO = new RouteHeaderVO();
0223:                if (routeHeader == null) {
0224:                    return null;
0225:                }
0226:                populateRouteHeaderVO(routeHeaderVO, routeHeader);
0227:
0228:                if (user != null) {
0229:                    routeHeaderVO.setUserBlanketApprover(false); // default to false
0230:                    if (routeHeader.getDocumentType() != null) {
0231:                        routeHeaderVO.setUserBlanketApprover(routeHeader
0232:                                .getDocumentType().isUserBlanketApprover(user));
0233:                    }
0234:                    String topActionRequested = EdenConstants.ACTION_REQUEST_FYI_REQ;
0235:                    for (Iterator iter = routeHeader.getActionRequests()
0236:                            .iterator(); iter.hasNext();) {
0237:                        ActionRequestValue actionRequest = (ActionRequestValue) iter
0238:                                .next();
0239:                        // below will control what buttons are drawn on the client we only want the
0240:                        // heaviest action button to show on the client making this code a little combersome
0241:                        if (actionRequest.isRecipientRoutedRequest(user)
0242:                                && actionRequest.isActive()) {
0243:                            int actionRequestComparison = ActionRequestValue
0244:                                    .compareActionCode(actionRequest
0245:                                            .getActionRequested(),
0246:                                            topActionRequested);
0247:                            if (actionRequest.isFYIRequest()
0248:                                    && actionRequestComparison >= 0) {
0249:                                routeHeaderVO.setFyiRequested(true);
0250:                            } else if (actionRequest.isAcknowledgeRequest()
0251:                                    && actionRequestComparison >= 0) {
0252:                                routeHeaderVO.setAckRequested(true);
0253:                                routeHeaderVO.setFyiRequested(false);
0254:                                topActionRequested = actionRequest
0255:                                        .getActionRequested();
0256:                            } else if (actionRequest.isApproveRequest()
0257:                                    && actionRequestComparison >= 0) {
0258:                                routeHeaderVO.setApproveRequested(true);
0259:                                routeHeaderVO.setAckRequested(false);
0260:                                routeHeaderVO.setFyiRequested(false);
0261:                                topActionRequested = actionRequest
0262:                                        .getActionRequested();
0263:                                if (actionRequest.isCompleteRequst()) {
0264:                                    routeHeaderVO.setCompleteRequested(true);
0265:                                }
0266:                            }
0267:                        }
0268:                    }
0269:                }
0270:
0271:                routeHeaderVO
0272:                        .setValidActions(convertValidActions(KEWServiceLocator
0273:                                .getActionRegistry().getValidActions(user,
0274:                                        routeHeader)));
0275:                return routeHeaderVO;
0276:            }
0277:
0278:            public static ValidActionsVO convertValidActions(
0279:                    ValidActions validActions) {
0280:                ValidActionsVO validActionsVO = new ValidActionsVO();
0281:                for (Iterator iter = validActions.getActionTakenCodes()
0282:                        .iterator(); iter.hasNext();) {
0283:                    String actionTakenCode = (String) iter.next();
0284:                    validActionsVO.addValidActionsAllowed(actionTakenCode);
0285:                }
0286:                return validActionsVO;
0287:            }
0288:
0289:            // private static void populateActionListRouteHeaderVO(RouteHeaderVO routeHeaderVO, DocumentRouteHeaderValue routeHeader) throws WorkflowException {
0290:            // routeHeaderVO.setAppDocId(routeHeader.getAppDocId());
0291:            // routeHeaderVO.setDateApproved(Utilities.convertTimestamp(routeHeader.getApprovedDate()));
0292:            // routeHeaderVO.setDateCreated(Utilities.convertTimestamp(routeHeader.getCreateDate()));
0293:            // routeHeaderVO.setDateFinalized(Utilities.convertTimestamp(routeHeader.getFinalizedDate()));
0294:            // routeHeaderVO.setDateLastModified(Utilities.convertTimestamp(routeHeader.getStatusModDate()));
0295:            // //routeHeaderVO.setDocumentContent(convertDocumentContent(routeHeader.getDocContent()));
0296:            // routeHeaderVO.setDocRouteLevel(routeHeader.getDocRouteLevel());
0297:            //
0298:            // Collection activeNodes = SpringServiceLocator.getRouteNodeService().getActiveNodeInstances(routeHeaderVO.getRouteHeaderId());
0299:            // routeHeaderVO.setNodeNames(new String[activeNodes.size()]);
0300:            // int index = 0;
0301:            // for (Iterator iterator = activeNodes.iterator(); iterator.hasNext(); index++) {
0302:            // RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator.next();
0303:            // routeHeaderVO.getNodeNames()[index++] = nodeInstance.getRouteNode().getRouteNodeName();
0304:            // }
0305:            //
0306:            // routeHeaderVO.setDocRouteStatus(routeHeader.getDocRouteStatus());
0307:            // routeHeaderVO.setDocTitle(routeHeader.getDocTitle());
0308:            // if (routeHeader.getDocumentType() != null) {
0309:            // routeHeaderVO.setDocTypeName(routeHeader.getDocumentType().getName());
0310:            // routeHeaderVO.setDocumentUrl(routeHeader.getDocumentType().getDocHandlerUrl());
0311:            // }
0312:            // routeHeaderVO.setDocVersion(routeHeader.getDocVersion());
0313:            // routeHeaderVO.setInitiator(convertUser(routeHeader.getInitiatorUser()));
0314:            // routeHeaderVO.setOverrideInd(routeHeader.getOverrideInd());
0315:            // routeHeaderVO.setRouteHeaderId(routeHeader.getRouteHeaderId());
0316:            // }
0317:
0318:            private static void populateRouteHeaderVO(
0319:                    RouteHeaderVO routeHeaderVO,
0320:                    DocumentRouteHeaderValue routeHeader)
0321:                    throws WorkflowException {
0322:                routeHeaderVO.setRouteHeaderId(routeHeader.getRouteHeaderId());
0323:                routeHeaderVO.setAppDocId(routeHeader.getAppDocId());
0324:                routeHeaderVO.setDateApproved(Utilities
0325:                        .convertTimestamp(routeHeader.getApprovedDate()));
0326:                routeHeaderVO.setDateCreated(Utilities
0327:                        .convertTimestamp(routeHeader.getCreateDate()));
0328:                routeHeaderVO.setDateFinalized(Utilities
0329:                        .convertTimestamp(routeHeader.getFinalizedDate()));
0330:                routeHeaderVO.setDateLastModified(Utilities
0331:                        .convertTimestamp(routeHeader.getStatusModDate()));
0332:
0333:                /**
0334:                 * This is the original code which set everything up for lazy loading of document content
0335:                 */
0336:                // by default, a non-initialized document content object will be sent so that it can be fetched lazily
0337:                //DocumentContentVO documentContentVO = new DocumentContentVO();
0338:                //documentContentVO.setRouteHeaderId(routeHeader.getRouteHeaderId());
0339:                //routeHeaderVO.setDocumentContent(documentContentVO);
0340:                /**
0341:                 * Since we removed the lazy loading in the 2.3 release, this is the code which bypasses lazy loading
0342:                 */
0343:                //routeHeaderVO.setDocumentContent(convertDocumentContent(routeHeader.getDocContent(), routeHeader.getRouteHeaderId()));
0344:                routeHeaderVO.setDocRouteLevel(routeHeader.getDocRouteLevel());
0345:                routeHeaderVO.setCurrentRouteNodeNames(routeHeader
0346:                        .getCurrentRouteLevelName());
0347:
0348:                /*Collection activeNodes = SpringServiceLocator.getRouteNodeService().getActiveNodeInstances(routeHeaderVO.getRouteHeaderId());
0349:                routeHeaderVO.setNodeNames(new String[activeNodes.size()]);
0350:                int index = 0;
0351:                for (Iterator iterator = activeNodes.iterator(); iterator.hasNext();) {
0352:                    RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator.next();
0353:                    routeHeaderVO.getNodeNames()[index++] = nodeInstance.getRouteNode().getRouteNodeName();
0354:                }*/
0355:
0356:                routeHeaderVO
0357:                        .setDocRouteStatus(routeHeader.getDocRouteStatus());
0358:                routeHeaderVO.setDocTitle(routeHeader.getDocTitle());
0359:                if (routeHeader.getDocumentType() != null) {
0360:                    routeHeaderVO.setDocTypeName(routeHeader.getDocumentType()
0361:                            .getName());
0362:                    routeHeaderVO.setDocumentUrl(routeHeader.getDocumentType()
0363:                            .getDocHandlerUrl());
0364:                    routeHeaderVO.setDocTypeId(routeHeader.getDocumentTypeId());
0365:                }
0366:                routeHeaderVO.setDocVersion(routeHeader.getDocVersion());
0367:                routeHeaderVO.setInitiator(convertUser(routeHeader
0368:                        .getInitiatorUser()));
0369:                routeHeaderVO.setRoutedByUser(convertUser(routeHeader
0370:                        .getRoutedByUser()));
0371:                routeHeaderVO.setOverrideInd(routeHeader.getOverrideInd());
0372:
0373:                /* populate the routeHeaderVO with the document variables */
0374:                // FIXME: we assume there is only one for now
0375:                RouteNodeInstance routeNodeInstance = (RouteNodeInstance) routeHeader
0376:                        .getInitialRouteNodeInstance(0);
0377:                // Ok, we are using the "branch state" as the arbitrary convenient repository for flow/process/edoc variables
0378:                // so we need to stuff them into the VO
0379:                if (routeNodeInstance.getBranch() != null) {
0380:                    List listOfBranchStates = routeNodeInstance.getBranch()
0381:                            .getBranchState();
0382:                    Iterator it = listOfBranchStates.iterator();
0383:                    while (it.hasNext()) {
0384:                        BranchState bs = (BranchState) it.next();
0385:                        if (bs.getKey() != null
0386:                                && bs.getKey().startsWith(
0387:                                        BranchState.VARIABLE_PREFIX)) {
0388:                            LOG.debug("Setting branch state variable on vo: "
0389:                                    + bs.getKey() + "=" + bs.getValue());
0390:                            routeHeaderVO.setVariable(bs.getKey().substring(
0391:                                    BranchState.VARIABLE_PREFIX.length()), bs
0392:                                    .getValue());
0393:                        }
0394:                    }
0395:                }
0396:            }
0397:
0398:            public static DocumentRouteHeaderValue convertRouteHeaderVO(
0399:                    RouteHeaderVO routeHeaderVO) throws WorkflowException,
0400:                    EdenUserNotFoundException {
0401:                DocumentRouteHeaderValue routeHeader = new DocumentRouteHeaderValue();
0402:                routeHeader.setAppDocId(routeHeaderVO.getAppDocId());
0403:                routeHeader.setApprovedDate(Utilities
0404:                        .convertCalendar(routeHeaderVO.getDateApproved()));
0405:                routeHeader.setCreateDate(Utilities
0406:                        .convertCalendar(routeHeaderVO.getDateCreated()));
0407:                //String updatedDocumentContent = buildUpdatedDocumentContent(routeHeaderVO);
0408:                // if null is returned from this method it indicates that the document content on the route header
0409:                // contained no changes, since we are creating a new document here, we will default the
0410:                // document content approriately if no changes are detected on the incoming DocumentContentVO
0411:                //if (updatedDocumentContent != null) {
0412:                //	routeHeader.setDocContent(updatedDocumentContent);
0413:                //} else {
0414:                //	routeHeader.setDocContent(EdenConstants.DEFAULT_DOCUMENT_CONTENT);
0415:                //}
0416:                if (StringUtils.isEmpty(routeHeader.getDocContent())) {
0417:                    routeHeader
0418:                            .setDocContent(EdenConstants.DEFAULT_DOCUMENT_CONTENT);
0419:                }
0420:                routeHeader.setDocRouteLevel(routeHeaderVO.getDocRouteLevel());
0421:                routeHeader
0422:                        .setDocRouteStatus(routeHeaderVO.getDocRouteStatus());
0423:                routeHeader.setDocTitle(routeHeaderVO.getDocTitle());
0424:                if (routeHeaderVO.getDocTypeName() != null) {
0425:                    DocumentType documentType = KEWServiceLocator
0426:                            .getDocumentTypeService().findByName(
0427:                                    routeHeaderVO.getDocTypeName());
0428:                    if (documentType == null) {
0429:                        throw new DocumentTypeNotFoundException(
0430:                                "Could not locate the given document type name: "
0431:                                        + routeHeaderVO.getDocTypeName());
0432:                    }
0433:                    routeHeader.setDocumentTypeId(documentType
0434:                            .getDocumentTypeId());
0435:                }
0436:                routeHeader.setDocVersion(routeHeaderVO.getDocVersion());
0437:                routeHeader.setFinalizedDate(Utilities
0438:                        .convertCalendar(routeHeaderVO.getDateFinalized()));
0439:                if (routeHeaderVO.getInitiator() != null) {
0440:                    routeHeader.setInitiatorWorkflowId(routeHeaderVO
0441:                            .getInitiator().getWorkflowId());
0442:                }
0443:                if (routeHeaderVO.getRoutedByUser() != null) {
0444:                    routeHeader.setRoutedByUserWorkflowId(routeHeaderVO
0445:                            .getRoutedByUser().getWorkflowId());
0446:                }
0447:                routeHeader.setOverrideInd(routeHeaderVO.getOverrideInd());
0448:                routeHeader.setRouteHeaderId(routeHeaderVO.getRouteHeaderId());
0449:                routeHeader.setStatusModDate(Utilities
0450:                        .convertCalendar(routeHeaderVO.getDateLastModified()));
0451:
0452:                return routeHeader;
0453:            }
0454:
0455:            //    private static boolean hasDocumentContentChanged(DocumentContentVO documentContentVO) {
0456:            //    	return documentContentVO.getApplicationContent() != null ||
0457:            //    		documentContentVO.getAttributeContent() != null ||
0458:            //    		documentContentVO.getSearchableContent() != null ||
0459:            //    		documentContentVO.getAttributeDefinitions().length > 0 ||
0460:            //    		documentContentVO.getSearchableDefinitions().length > 0;
0461:            //    }
0462:
0463:            /**
0464:             * Converts the given DocumentContentVO to a document content string.  This method considers existing
0465:             * content on the document and updates approriately.  The string returned will be the new document
0466:             * content for the document.  If null is returned, then the document content is unchanged.
0467:             */
0468:            //    public static String buildUpdatedDocumentContent(RouteHeaderVO routeHeaderVO) throws WorkflowException {
0469:            //    	// prevent the document content from auto materializing when we are looking through it
0470:            //
0471:            //    	//documentContentVO.turnOffMaterialization();
0472:            //    	DocumentContentVO documentContentVO = routeHeaderVO.getDocumentContent();
0473:            //    	// if the document content hasn't changed, no need to eagerly update it
0474:            //    	if (!hasDocumentContentChanged(documentContentVO)) {
0475:            //    		return null;
0476:            //    	}
0477:            //        String documentContent = EdenConstants.DEFAULT_DOCUMENT_CONTENT;
0478:            //        try {
0479:            //        	// parse the existing content on the document
0480:            //        	String existingDocContent = EdenConstants.DEFAULT_DOCUMENT_CONTENT;
0481:            //        	if (documentContentVO.getRouteHeaderId() != null) {
0482:            //        		DocumentRouteHeaderValue document = SpringServiceLocator.getRouteHeaderService().getRouteHeader(documentContentVO.getRouteHeaderId());
0483:            //        		existingDocContent = document.getDocContent();
0484:            //        	}
0485:            //        	StandardDocumentContent standardDocContent = new StandardDocumentContent(existingDocContent);
0486:            //        	DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
0487:            //        	Document document = builder.newDocument();
0488:            //        	Element root = document.createElement(EdenConstants.DOCUMENT_CONTENT_ELEMENT);
0489:            //        	document.appendChild(root);
0490:            //        	Element applicationContentElement = standardDocContent.getApplicationContent();
0491:            //        	if (documentContentVO.getApplicationContent() != null) {
0492:            //        		// application content has changed
0493:            //            	if (!Utilities.isEmpty(documentContentVO.getApplicationContent())) {
0494:            //            		applicationContentElement = document.createElement(EdenConstants.APPLICATION_CONTENT_ELEMENT);
0495:            //            		XmlHelper.appendXml(applicationContentElement, documentContentVO.getApplicationContent());
0496:            //            	} else {
0497:            //            		// they've cleared the application content
0498:            //            		applicationContentElement = null;
0499:            //            	}
0500:            //        	}
0501:            //        	Element attributeContentElement = createDocumentContentSection(document, standardDocContent.getAttributeContent(), documentContentVO.getAttributeDefinitions(), documentContentVO.getAttributeContent(), EdenConstants.ATTRIBUTE_CONTENT_ELEMENT, routeHeaderVO);
0502:            //        	Element searchableContentElement = createDocumentContentSection(document, standardDocContent.getSearchableContent(), documentContentVO.getSearchableDefinitions(), documentContentVO.getSearchableContent(), EdenConstants.SEARCHABLE_CONTENT_ELEMENT, routeHeaderVO);
0503:            //        	if (applicationContentElement != null) {
0504:            //        		root.appendChild(applicationContentElement);
0505:            //        	}
0506:            //        	if (attributeContentElement != null) {
0507:            //        		root.appendChild(attributeContentElement);
0508:            //        	}
0509:            //        	if (searchableContentElement != null) {
0510:            //        		root.appendChild(searchableContentElement);
0511:            //        	}
0512:            //        	documentContent = XmlHelper.writeNode(document);
0513:            //        } catch (Exception e) {
0514:            //            handleException("Error parsing document content.", e);
0515:            //        }
0516:            //        return documentContent;
0517:            //    }
0518:            public static String buildUpdatedDocumentContent(
0519:                    DocumentContentVO documentContentVO)
0520:                    throws WorkflowException {
0521:                // if the document content hasn't changed, no need to eagerly update it
0522:                //		if (!hasDocumentContentChanged(documentContentVO)) {
0523:                //			return null;
0524:                //		}
0525:                DocumentType documentType = null;
0526:                String documentContent = EdenConstants.DEFAULT_DOCUMENT_CONTENT;
0527:                try {
0528:                    // parse the existing content on the document
0529:                    String existingDocContent = EdenConstants.DEFAULT_DOCUMENT_CONTENT;
0530:                    if (documentContentVO.getRouteHeaderId() != null) {
0531:                        DocumentRouteHeaderValue document = KEWServiceLocator
0532:                                .getRouteHeaderService().getRouteHeader(
0533:                                        documentContentVO.getRouteHeaderId());
0534:                        documentType = document.getDocumentType();
0535:                        existingDocContent = document.getDocContent();
0536:                    }
0537:                    StandardDocumentContent standardDocContent = new StandardDocumentContent(
0538:                            existingDocContent);
0539:                    DocumentBuilder builder = DocumentBuilderFactory
0540:                            .newInstance().newDocumentBuilder();
0541:                    Document document = builder.newDocument();
0542:                    Element root = document
0543:                            .createElement(EdenConstants.DOCUMENT_CONTENT_ELEMENT);
0544:                    document.appendChild(root);
0545:                    Element applicationContentElement = standardDocContent
0546:                            .getApplicationContent();
0547:                    if (documentContentVO.getApplicationContent() != null) {
0548:                        // application content has changed
0549:                        if (!Utilities.isEmpty(documentContentVO
0550:                                .getApplicationContent())) {
0551:                            applicationContentElement = document
0552:                                    .createElement(EdenConstants.APPLICATION_CONTENT_ELEMENT);
0553:                            XmlHelper.appendXml(applicationContentElement,
0554:                                    documentContentVO.getApplicationContent());
0555:                        } else {
0556:                            // they've cleared the application content
0557:                            applicationContentElement = null;
0558:                        }
0559:                    }
0560:                    Element attributeContentElement = createDocumentContentSection(
0561:                            document, standardDocContent.getAttributeContent(),
0562:                            documentContentVO.getAttributeDefinitions(),
0563:                            documentContentVO.getAttributeContent(),
0564:                            EdenConstants.ATTRIBUTE_CONTENT_ELEMENT,
0565:                            documentType);
0566:                    Element searchableContentElement = createDocumentContentSection(
0567:                            document,
0568:                            standardDocContent.getSearchableContent(),
0569:                            documentContentVO.getSearchableDefinitions(),
0570:                            documentContentVO.getSearchableContent(),
0571:                            EdenConstants.SEARCHABLE_CONTENT_ELEMENT,
0572:                            documentType);
0573:                    if (applicationContentElement != null) {
0574:                        root.appendChild(applicationContentElement);
0575:                    }
0576:                    if (attributeContentElement != null) {
0577:                        root.appendChild(attributeContentElement);
0578:                    }
0579:                    if (searchableContentElement != null) {
0580:                        root.appendChild(searchableContentElement);
0581:                    }
0582:                    documentContent = XmlHelper.writeNode(document);
0583:                } catch (Exception e) {
0584:                    handleException("Error parsing document content.", e);
0585:                }
0586:                return documentContent;
0587:            }
0588:
0589:            private static Element createDocumentContentSection(
0590:                    Document document, Element existingAttributeElement,
0591:                    WorkflowAttributeDefinitionVO[] definitions,
0592:                    String content, String elementName,
0593:                    DocumentType documentType) throws Exception {
0594:                Element contentSectionElement = existingAttributeElement;
0595:                // if they've updated the content, we're going to re-build the content section element from scratch
0596:                if (content != null) {
0597:                    if (!Utilities.isEmpty(content)) {
0598:                        contentSectionElement = document
0599:                                .createElement(elementName);
0600:                        // if they didn't merely clear the content, let's build the content section element by combining the children of the incoming XML content
0601:                        Element incomingAttributeElement = XmlHelper.readXml(
0602:                                content).getDocumentElement();
0603:                        NodeList children = incomingAttributeElement
0604:                                .getChildNodes();
0605:                        for (int index = 0; index < children.getLength(); index++) {
0606:                            contentSectionElement.appendChild(document
0607:                                    .importNode(children.item(index), true));
0608:                        }
0609:                    } else {
0610:                        contentSectionElement = null;
0611:                    }
0612:                }
0613:                // if they have new definitions we're going to append those to the existing content section
0614:                if (!Utilities.isEmpty(definitions)) {
0615:                    String errorMessage = "";
0616:                    boolean inError = false;
0617:                    if (contentSectionElement == null) {
0618:                        contentSectionElement = document
0619:                                .createElement(elementName);
0620:                    }
0621:                    for (int index = 0; index < definitions.length; index++) {
0622:                        WorkflowAttributeDefinitionVO definitionVO = definitions[index];
0623:                        AttributeDefinition definition = convertWorkflowAttributeDefinitionVO(
0624:                                definitionVO, documentType);
0625:                        RuleAttribute ruleAttribute = definition
0626:                                .getRuleAttribute();
0627:                        Object attribute = GlobalResourceLoader
0628:                                .getResourceLoader().getObject(
0629:                                        definition.getObjectDefinition());
0630:                        boolean propertiesAsMap = false;
0631:                        if (EdenConstants.RULE_XML_ATTRIBUTE_TYPE
0632:                                .equals(ruleAttribute.getType())) {
0633:                            ((GenericXMLRuleAttribute) attribute)
0634:                                    .setRuleAttribute(ruleAttribute);
0635:                            propertiesAsMap = true;
0636:                        } else if (EdenConstants.SEARCHABLE_XML_ATTRIBUTE_TYPE
0637:                                .equals(ruleAttribute.getType())) {
0638:                            ((GenericXMLSearchableAttribute) attribute)
0639:                                    .setRuleAttribute(ruleAttribute);
0640:                            propertiesAsMap = true;
0641:                        } else {
0642:                            LOG
0643:                                    .error("Unknown/invalid attribute type: "
0644:                                            + ruleAttribute
0645:                                            + " "
0646:                                            + ruleAttribute.getType()
0647:                                            + "; must be '"
0648:                                            + EdenConstants.RULE_XML_ATTRIBUTE_TYPE
0649:                                            + "' or '"
0650:                                            + EdenConstants.SEARCHABLE_XML_ATTRIBUTE_TYPE
0651:                                            + "'");
0652:                        }
0653:                        if (propertiesAsMap) {
0654:                            for (PropertyDefinitionVO propertyDefinitionVO : definitionVO
0655:                                    .getProperties()) {
0656:                                if (attribute instanceof  GenericXMLRuleAttribute) {
0657:                                    ((GenericXMLRuleAttribute) attribute)
0658:                                            .getParamMap().put(
0659:                                                    propertyDefinitionVO
0660:                                                            .getName(),
0661:                                                    propertyDefinitionVO
0662:                                                            .getValue());
0663:                                } else if (attribute instanceof  GenericXMLSearchableAttribute) {
0664:                                    ((GenericXMLSearchableAttribute) attribute)
0665:                                            .getParamMap().put(
0666:                                                    propertyDefinitionVO
0667:                                                            .getName(),
0668:                                                    propertyDefinitionVO
0669:                                                            .getValue());
0670:                                }
0671:                            }
0672:                        }
0673:
0674:                        // validate inputs from client application if the attribute is capable
0675:                        if (attribute instanceof  WorkflowAttributeXmlValidator) {
0676:                            List errors = ((WorkflowAttributeXmlValidator) attribute)
0677:                                    .validateClientRoutingData();
0678:                            if (!errors.isEmpty()) {
0679:                                inError = true;
0680:                                errorMessage += "Error validating attribute "
0681:                                        + definitions[index].getAttributeName()
0682:                                        + " ";
0683:                                for (Iterator iter = errors.iterator(); iter
0684:                                        .hasNext();) {
0685:                                    WorkflowAttributeValidationError error = (WorkflowAttributeValidationError) iter
0686:                                            .next();
0687:                                    errorMessage += error.getMessage() + " ";
0688:                                }
0689:                            }
0690:                        }
0691:                        // dont add to xml if attribute is in error
0692:                        if (!inError) {
0693:                            if (attribute instanceof  WorkflowAttribute) {
0694:                                String attributeDocContent = ((WorkflowAttribute) attribute)
0695:                                        .getDocContent();
0696:                                if (!StringUtils.isEmpty(attributeDocContent)) {
0697:                                    XmlHelper.appendXml(contentSectionElement,
0698:                                            attributeDocContent);
0699:                                }
0700:                            } else if (attribute instanceof  SearchableAttribute) {
0701:                                String searcheAttributeContent = ((SearchableAttribute) attribute)
0702:                                        .getSearchContent();
0703:                                if (!StringUtils
0704:                                        .isEmpty(searcheAttributeContent)) {
0705:                                    XmlHelper.appendXml(contentSectionElement,
0706:                                            searcheAttributeContent);
0707:                                }
0708:                            }
0709:                        }
0710:                    }
0711:                    if (inError) {
0712:                        throw new WorkflowRuntimeException(errorMessage);
0713:                    }
0714:
0715:                }
0716:                if (contentSectionElement != null) {
0717:                    // always be sure and import the element into the new document, if it originated from the existing doc content and
0718:                    // appended to it, it will need to be imported
0719:                    contentSectionElement = (Element) document.importNode(
0720:                            contentSectionElement, true);
0721:                }
0722:                return contentSectionElement;
0723:            }
0724:
0725:            public static DocumentContentVO convertDocumentContent(
0726:                    String documentContentValue, Long documentId)
0727:                    throws WorkflowException {
0728:                if (documentContentValue == null) {
0729:                    return null;
0730:                }
0731:                DocumentContentVO documentContentVO = new DocumentContentVO();
0732:                // initialize the content fields
0733:                documentContentVO.setApplicationContent("");
0734:                documentContentVO.setAttributeContent("");
0735:                documentContentVO.setSearchableContent("");
0736:                documentContentVO.setRouteHeaderId(documentId);
0737:                try {
0738:                    DocumentContent documentContent = new StandardDocumentContent(
0739:                            documentContentValue);
0740:                    if (documentContent.getApplicationContent() != null) {
0741:                        documentContentVO.setApplicationContent(XmlHelper
0742:                                .writeNode(documentContent
0743:                                        .getApplicationContent()));
0744:                    }
0745:                    if (documentContent.getAttributeContent() != null) {
0746:                        documentContentVO.setAttributeContent(XmlHelper
0747:                                .writeNode(documentContent
0748:                                        .getAttributeContent()));
0749:                    }
0750:                    if (documentContent.getSearchableContent() != null) {
0751:                        documentContentVO.setSearchableContent(XmlHelper
0752:                                .writeNode(documentContent
0753:                                        .getSearchableContent()));
0754:                    }
0755:                } catch (Exception e) {
0756:                    handleException("Error parsing document content.", e);
0757:                }
0758:                return documentContentVO;
0759:            }
0760:
0761:            public static WorkgroupVO convertWorkgroup(Workgroup workgroup) {
0762:                if (workgroup == null) {
0763:                    return null;
0764:                }
0765:                WorkgroupVO workgroupVO = new WorkgroupVO();
0766:                workgroupVO.setActiveInd(workgroup.getActiveInd()
0767:                        .booleanValue());
0768:                workgroupVO.setDescription(workgroup.getDescription());
0769:                workgroupVO.setWorkgroupId(workgroup.getWorkflowGroupId()
0770:                        .getGroupId());
0771:                workgroupVO.setWorkgroupName(workgroup.getGroupNameId()
0772:                        .getNameId());
0773:                workgroupVO.setWorkgroupType(workgroup.getWorkgroupType());
0774:                if (workgroup.getUsers() != null) {
0775:                    workgroupVO.setMembers(new UserVO[workgroup.getUsers()
0776:                            .size()]);
0777:                    int index = 0;
0778:                    for (Iterator iterator = workgroup.getUsers().iterator(); iterator
0779:                            .hasNext(); index++) {
0780:                        WorkflowUser user = (WorkflowUser) iterator.next();
0781:                        workgroupVO.getMembers()[index] = convertUser(user);
0782:                    }
0783:                }
0784:                return workgroupVO;
0785:            }
0786:
0787:            public static UserVO convertUser(WorkflowUser user) {
0788:                if (user == null) {
0789:                    return null;
0790:                }
0791:                UserVO userVO = new UserVO();
0792:                userVO
0793:                        .setNetworkId(user.getAuthenticationUserId() == null ? null
0794:                                : user.getAuthenticationUserId()
0795:                                        .getAuthenticationId());
0796:                userVO.setUuId(user.getUuId() == null ? null : user.getUuId()
0797:                        .getUuId());
0798:                userVO.setEmplId(user.getEmplId() == null ? null : user
0799:                        .getEmplId().getEmplId());
0800:                userVO.setWorkflowId(user.getWorkflowUserId() == null ? null
0801:                        : user.getWorkflowUserId().getWorkflowId());
0802:                userVO.setDisplayName(user.getDisplayName());
0803:                userVO.setLastName(user.getLastName());
0804:                userVO.setFirstName(user.getGivenName());
0805:                userVO.setEmailAddress(user.getEmailAddress());
0806:                // Preferences preferences = SpringServiceLocator.getPreferencesService().getPreferences(user);
0807:                // userVO.setUserPreferencePopDocHandler(EdenConstants.PREFERENCES_YES_VAL.equals(preferences.getOpenNewWindow()));
0808:
0809:                userVO.setUserPreferencePopDocHandler(true);
0810:                return userVO;
0811:            }
0812:
0813:            public static WorkflowUser convertUserVO(UserVO userVO)
0814:                    throws EdenUserNotFoundException {
0815:                if (userVO == null) {
0816:                    return null;
0817:                }
0818:                UserId userId = null;
0819:                if (userVO.getWorkflowId() != null) {
0820:                    userId = new WorkflowUserId(userVO.getWorkflowId());
0821:                } else if (userVO.getNetworkId() != null) {
0822:                    userId = new AuthenticationUserId(userVO.getNetworkId());
0823:                } else if (userVO.getEmplId() != null) {
0824:                    userId = new EmplId(userVO.getEmplId());
0825:                } else if (userVO.getUuId() != null) {
0826:                    userId = new UuId(userVO.getUuId());
0827:                } else {
0828:                    throw new EdenUserNotFoundException(
0829:                            "Cannot convert the given UserVO, it does not contain any valid user ids.");
0830:                }
0831:                return KEWServiceLocator.getUserService().getWorkflowUser(
0832:                        userId);
0833:            }
0834:
0835:            public static DocumentTypeVO convertDocumentType(
0836:                    DocumentType docType) {
0837:                DocumentTypeVO docTypeVO = new DocumentTypeVO();
0838:                docTypeVO.setDocTypeParentId(docType.getDocTypeParentId());
0839:                if (docType.getParentDocType() != null) {
0840:                    docTypeVO.setDocTypeParentName(docType.getParentDocType()
0841:                            .getName());
0842:                }
0843:
0844:                docTypeVO.setDocTypeDescription(docType.getDescription());
0845:                docTypeVO.setDocTypeHandlerUrl(docType.getDocHandlerUrl());
0846:                docTypeVO.setDocTypeId(docType.getDocumentTypeId());
0847:                docTypeVO.setDocTypeLabel(docType.getLabel());
0848:                docTypeVO.setName(docType.getName());
0849:                docTypeVO.setDocTypeVersion(docType.getVersion());
0850:                Boolean currentInd = docType.getCurrentInd();
0851:                if (currentInd == null) {
0852:                    docTypeVO.setDocTypeCurrentInd(null);
0853:                } else if (currentInd.booleanValue()) {
0854:                    docTypeVO.setDocTypeCurrentInd(EdenConstants.ACTIVE_CD);
0855:                } else {
0856:                    docTypeVO.setDocTypeCurrentInd(EdenConstants.INACTIVE_CD);
0857:                }
0858:                docTypeVO.setPostProcessorName(docType.getPostProcessorName());
0859:                docTypeVO.setDocTypeJndiFactoryClass(null);
0860:                docTypeVO.setDocTypeActiveInd(docType.getActiveInd()
0861:                        .booleanValue());
0862:                if (docType.getParentDocType() != null) {
0863:                    docTypeVO.setDocTypeActiveInherited(true);
0864:                } else {
0865:                    docTypeVO.setDocTypeActiveInherited(false);
0866:                }
0867:                docTypeVO.setDocTypePreApprovalPolicy(docType
0868:                        .getPreApprovePolicy().getPolicyValue().booleanValue());
0869:                Workgroup blanketWorkgroup = docType
0870:                        .getBlanketApproveWorkgroup();
0871:                if (blanketWorkgroup != null) {
0872:                    docTypeVO.setBlanketApproveWorkgroupId(blanketWorkgroup
0873:                            .getWorkflowGroupId().getGroupId());
0874:                }
0875:                docTypeVO.setBlanketApprovePolicy(docType
0876:                        .getBlanketApprovePolicy());
0877:                if (CompatUtils.isRouteLevelCompatible(docType)) {
0878:                    List nodes = CompatUtils
0879:                            .getRouteLevelCompatibleNodeList(docType);
0880:                    RouteTemplateEntryVO[] templates = new RouteTemplateEntryVO[nodes
0881:                            .size()];
0882:                    int index = 0;
0883:                    for (Iterator iterator = nodes.iterator(); iterator
0884:                            .hasNext();) {
0885:                        RouteNode node = (RouteNode) iterator.next();
0886:                        templates[index++] = convertRouteTemplateEntry(node);
0887:                    }
0888:                    docTypeVO.setRouteTemplates(templates);
0889:                }
0890:                docTypeVO.setRoutePath(convertRoutePath(docType));
0891:                return docTypeVO;
0892:            }
0893:
0894:            public static RouteTemplateEntryVO convertRouteTemplateEntry(
0895:                    RouteNode node) {
0896:                RouteTemplateEntryVO entryVO = new RouteTemplateEntryVO();
0897:                entryVO.setFinalApprover(node.getFinalApprovalInd()
0898:                        .booleanValue());
0899:                entryVO.setMandatoryRoute(node.getMandatoryRouteInd()
0900:                        .booleanValue());
0901:                entryVO.setRouteLevel(CompatUtils.getLevelForNode(node
0902:                        .getDocumentType(), node.getRouteNodeName()));
0903:                entryVO.setRouteLevelName(node.getRouteNodeName());
0904:                entryVO.setRouteMethodName(node.getRouteMethodName());
0905:                entryVO.setDocTypeId(node.getDocumentTypeId());
0906:                entryVO.setExceptionWorkgroupId(node.getExceptionWorkgroupId());
0907:                entryVO.setJrf_ver_nbr(node.getLockVerNbr());
0908:                entryVO.setMandatoryRoute(node.getMandatoryRouteInd()
0909:                        .toString());
0910:                return entryVO;
0911:            }
0912:
0913:            public static RoutePathVO convertRoutePath(DocumentType documentType) {
0914:                RoutePathVO routePath = new RoutePathVO();
0915:                ProcessVO[] processes = new ProcessVO[documentType
0916:                        .getProcesses().size()];
0917:                int index = 0;
0918:                for (Iterator iterator = documentType.getProcesses().iterator(); iterator
0919:                        .hasNext();) {
0920:                    Process process = (Process) iterator.next();
0921:                    processes[index++] = convertProcess(process);
0922:                }
0923:                routePath.setProcesses(processes);
0924:                return routePath;
0925:            }
0926:
0927:            public static ActionRequestVO convertActionRequest(
0928:                    ActionRequestValue actionRequest)
0929:                    throws EdenUserNotFoundException {
0930:                // TODO some newly added actionrequest properties are not here (delegation stuff)
0931:                ActionRequestVO actionRequestVO = new ActionRequestVO();
0932:                actionRequestVO.setActionRequested(actionRequest
0933:                        .getActionRequested());
0934:                actionRequestVO.setActionRequestId(actionRequest
0935:                        .getActionRequestId());
0936:
0937:                if (actionRequest.getActionTaken() != null) {
0938:                    actionRequestVO.setActionTakenId(actionRequest
0939:                            .getActionTakenId());
0940:                    actionRequestVO
0941:                            .setActionTaken(convertActionTaken(actionRequest
0942:                                    .getActionTaken()));
0943:                }
0944:
0945:                actionRequestVO.setAnnotation(actionRequest.getAnnotation());
0946:                actionRequestVO.setDateCreated(Utilities
0947:                        .convertTimestamp(actionRequest.getCreateDate()));
0948:                actionRequestVO.setDocVersion(actionRequest.getDocVersion());
0949:                actionRequestVO.setUserVO(convertUser(actionRequest
0950:                        .getWorkflowUser()));
0951:                if (actionRequest.getWorkflowId() != null) {
0952:                    // TODO switch this to a user vo
0953:                    actionRequestVO.setEmplyId(actionRequest.getWorkflowUser()
0954:                            .getEmplId().getEmplId());
0955:                }
0956:                actionRequestVO.setIgnorePrevAction(actionRequest
0957:                        .getIgnorePrevAction());
0958:                actionRequestVO.setPriority(actionRequest.getPriority());
0959:                actionRequestVO.setRecipientTypeCd(actionRequest
0960:                        .getRecipientTypeCd());
0961:                actionRequestVO.setResponsibilityDesc(actionRequest
0962:                        .getResponsibilityDesc());
0963:                actionRequestVO.setResponsibilityId(actionRequest
0964:                        .getResponsibilityId());
0965:                actionRequestVO.setRouteHeaderId(actionRequest
0966:                        .getRouteHeaderId());
0967:                actionRequestVO.setRouteLevel(actionRequest.getRouteLevel());
0968:                actionRequestVO.setNodeName(actionRequest
0969:                        .getPotentialNodeName());
0970:                actionRequestVO.setNodeInstanceId((actionRequest
0971:                        .getNodeInstance() == null ? null : actionRequest
0972:                        .getNodeInstance().getRouteNodeInstanceId()));
0973:                //        actionRequestVO.setRouteMethodName(actionRequest.getRouteMethodName());
0974:                // TODO delyea - should below be using actionRequest.getRoleName()?
0975:                actionRequestVO.setRoleName(actionRequest
0976:                        .getQualifiedRoleName());
0977:                actionRequestVO.setQualifiedRoleName(actionRequest
0978:                        .getQualifiedRoleName());
0979:                actionRequestVO.setQualifiedRoleNameLabel(actionRequest
0980:                        .getQualifiedRoleNameLabel());
0981:                actionRequestVO.setStatus(actionRequest.getStatus());
0982:                if (actionRequest.isWorkgroupRequest()) {
0983:                    actionRequestVO.setWorkgroupId(actionRequest
0984:                            .getWorkgroupId());
0985:                    actionRequestVO
0986:                            .setWorkgroupVO(convertWorkgroup(actionRequest
0987:                                    .getWorkgroup()));
0988:                }
0989:                ActionRequestVO[] childRequestVOs = new ActionRequestVO[actionRequest
0990:                        .getChildrenRequests().size()];
0991:                int index = 0;
0992:                for (Iterator iterator = actionRequest.getChildrenRequests()
0993:                        .iterator(); iterator.hasNext();) {
0994:                    ActionRequestValue childRequest = (ActionRequestValue) iterator
0995:                            .next();
0996:                    ActionRequestVO childRequestVO = convertActionRequest(childRequest);
0997:                    childRequestVO.setParentActionRequest(actionRequestVO);
0998:                    childRequestVOs[index++] = childRequestVO;
0999:                }
1000:                actionRequestVO.setChildrenRequests(childRequestVOs);
1001:                return actionRequestVO;
1002:            }
1003:
1004:            public static ActionTakenVO convertActionTaken(
1005:                    ActionTakenValue actionTaken)
1006:                    throws EdenUserNotFoundException {
1007:                if (actionTaken == null) {
1008:                    return null;
1009:                }
1010:                ActionTakenVO actionTakenVO = new ActionTakenVO();
1011:                actionTakenVO.setActionDate(Utilities
1012:                        .convertTimestamp(actionTaken.getActionDate()));
1013:                actionTakenVO.setActionTaken(actionTaken.getActionTaken());
1014:                actionTakenVO.setActionTakenId(actionTaken.getActionTakenId());
1015:                actionTakenVO.setAnnotation(actionTaken.getAnnotation());
1016:                actionTakenVO.setDocVersion(actionTaken.getDocVersion());
1017:                actionTakenVO.setRouteHeaderId(actionTaken.getRouteHeaderId());
1018:                WorkflowUser user = actionTaken.getWorkflowUser();
1019:                if (user != null) {
1020:                    actionTakenVO.setUserVO(convertUser(user));
1021:                }
1022:                WorkflowUser delegator = actionTaken.getDelegatorUser();
1023:                if (delegator != null) {
1024:                    actionTakenVO.setDelegatorVO(convertUser(delegator));
1025:                }
1026:                return actionTakenVO;
1027:            }
1028:
1029:            public static WorkgroupIdVO convertGroupId(GroupId groupId) {
1030:                WorkgroupIdVO workgroupId = null;
1031:                if (groupId instanceof  GroupNameId) {
1032:                    GroupNameId groupName = (GroupNameId) groupId;
1033:                    workgroupId = new WorkgroupNameIdVO(groupName.getNameId());
1034:                } else if (groupId instanceof  WorkflowGroupId) {
1035:                    WorkflowGroupId workflowGroupId = (WorkflowGroupId) groupId;
1036:                    workgroupId = new WorkflowGroupIdVO(workflowGroupId
1037:                            .getGroupId());
1038:                }
1039:                return workgroupId;
1040:            }
1041:
1042:            public static GroupId convertWorkgroupIdVO(WorkgroupIdVO workgroupId) {
1043:                GroupId groupId = null;
1044:                if (workgroupId instanceof  WorkgroupNameIdVO) {
1045:                    WorkgroupNameIdVO workgroupName = (WorkgroupNameIdVO) workgroupId;
1046:                    groupId = new GroupNameId(workgroupName.getWorkgroupName());
1047:                } else if (workgroupId instanceof  WorkflowGroupIdVO) {
1048:                    WorkflowGroupIdVO workflowGroupId = (WorkflowGroupIdVO) workgroupId;
1049:                    groupId = new WorkflowGroupId(workflowGroupId
1050:                            .getWorkgroupId());
1051:                }
1052:
1053:                return groupId;
1054:            }
1055:
1056:            public static UserIdVO convertUserId(UserId userId) {
1057:                UserIdVO userIdVO = null;
1058:                if (userId instanceof  AuthenticationUserId) {
1059:                    AuthenticationUserId id = (AuthenticationUserId) userId;
1060:                    userIdVO = new NetworkIdVO(id.getAuthenticationId());
1061:                } else if (userId instanceof  EmplId) {
1062:                    EmplId id = (EmplId) userId;
1063:                    userIdVO = new EmplIdVO(id.getEmplId());
1064:                } else if (userId instanceof  UuId) {
1065:                    UuId id = (UuId) userId;
1066:                    userIdVO = new UuIdVO(id.getUuId());
1067:                } else if (userId instanceof  WorkflowUserId) {
1068:                    WorkflowUserId id = (WorkflowUserId) userId;
1069:                    userIdVO = new WorkflowIdVO(id.getWorkflowId());
1070:                }
1071:                return userIdVO;
1072:            }
1073:
1074:            public static UserId convertUserIdVO(UserIdVO userIdVO) {
1075:                UserId userId = null;
1076:                if (userIdVO instanceof  NetworkIdVO) {
1077:                    NetworkIdVO id = (NetworkIdVO) userIdVO;
1078:                    userId = new AuthenticationUserId(id.getNetworkId());
1079:                    if (userId.isEmpty()) {
1080:                        throw new RuntimeException(
1081:                                "Attempting to use empty NetworkId");
1082:                    }
1083:                } else if (userIdVO instanceof  EmplIdVO) {
1084:                    EmplIdVO id = (EmplIdVO) userIdVO;
1085:                    userId = new EmplId(id.getEmplId());
1086:                    if (userId.isEmpty()) {
1087:                        throw new RuntimeException(
1088:                                "Attempting to use empty EmplId");
1089:                    }
1090:                } else if (userIdVO instanceof  UuIdVO) {
1091:                    UuIdVO id = (UuIdVO) userIdVO;
1092:                    userId = new UuId(id.getUuId());
1093:                    if (userId.isEmpty()) {
1094:                        throw new RuntimeException(
1095:                                "Attempting to use empty UuId");
1096:                    }
1097:                } else if (userIdVO instanceof  WorkflowIdVO) {
1098:                    WorkflowIdVO id = (WorkflowIdVO) userIdVO;
1099:                    userId = new WorkflowUserId(id.getWorkflowId());
1100:                    if (userId.isEmpty()) {
1101:                        throw new RuntimeException(
1102:                                "Attempting to use empty WorkflowId");
1103:                    }
1104:                }
1105:                return userId;
1106:            }
1107:
1108:            public static ResponsiblePartyVO convertResponsibleParty(
1109:                    ResponsibleParty responsibleParty) {
1110:                if (responsibleParty == null) {
1111:                    return null;
1112:                }
1113:                ResponsiblePartyVO responsiblePartyVO = new ResponsiblePartyVO();
1114:                responsiblePartyVO.setWorkgroupId(BeanConverter
1115:                        .convertGroupId(responsibleParty.getGroupId()));
1116:                responsiblePartyVO.setUserId(BeanConverter
1117:                        .convertUserId(responsibleParty.getUserId()));
1118:                responsiblePartyVO.setRoleName(responsibleParty.getRoleName());
1119:                return responsiblePartyVO;
1120:            }
1121:
1122:            public static ResponsibleParty convertResponsiblePartyVO(
1123:                    ResponsiblePartyVO responsiblePartyVO) {
1124:                if (responsiblePartyVO == null) {
1125:                    return null;
1126:                }
1127:                ResponsibleParty responsibleParty = new ResponsibleParty();
1128:                responsibleParty.setGroupId(BeanConverter
1129:                        .convertWorkgroupIdVO(responsiblePartyVO
1130:                                .getWorkgroupId()));
1131:                responsibleParty.setUserId(BeanConverter
1132:                        .convertUserIdVO(responsiblePartyVO.getUserId()));
1133:                responsibleParty.setRoleName(responsiblePartyVO.getRoleName());
1134:                return responsibleParty;
1135:            }
1136:
1137:            /**
1138:             * refactor name to convertResponsiblePartyVO when ResponsibleParty object is gone
1139:             * @param responsiblePartyVO
1140:             * @return
1141:             * @throws EdenUserNotFoundException
1142:             */
1143:            public static Recipient convertResponsiblePartyVOtoRecipient(
1144:                    ResponsiblePartyVO responsiblePartyVO)
1145:                    throws EdenUserNotFoundException {
1146:                if (responsiblePartyVO == null) {
1147:                    return null;
1148:                }
1149:                if (responsiblePartyVO.getRoleName() != null) {
1150:                    return new RoleRecipient(responsiblePartyVO.getRoleName());
1151:                }
1152:                GroupId groupId = convertWorkgroupIdVO(responsiblePartyVO
1153:                        .getWorkgroupId());
1154:                if (groupId != null) {
1155:                    return KEWServiceLocator.getWorkgroupService()
1156:                            .getWorkgroup(groupId);
1157:                }
1158:                UserId userId = convertUserIdVO(responsiblePartyVO.getUserId());
1159:                if (userId != null) {
1160:                    return KEWServiceLocator.getUserService().getWorkflowUser(
1161:                            userId);
1162:                }
1163:                throw new WorkflowRuntimeException(
1164:                        "ResponsibleParty of unknown type");
1165:            }
1166:
1167:            /**
1168:             * Converts an ActionRequestVO to an ActionRequest. The ActionRequestVO passed in must be the root action request in the graph, otherwise an IllegalArgumentException is thrown. This is to avoid potentially sticky issues with circular references in the conversion. NOTE: This method's primary purpose is to convert ActionRequestVOs returned from a RouteModule. Incidentally, the VO's returned from the route module will be lacking some information (like the node instance) so no attempts are made to convert this data since further initialization is handled by a higher level component (namely ActionRequestService.initializeActionRequestGraph).
1169:             */
1170:            public static ActionRequestValue convertActionRequestVO(
1171:                    ActionRequestVO actionRequestVO)
1172:                    throws EdenUserNotFoundException {
1173:                if (actionRequestVO == null) {
1174:                    return null;
1175:                }
1176:                if (actionRequestVO.getParentActionRequest() != null
1177:                        || actionRequestVO.getParentActionRequestId() != null) {
1178:                    throw new IllegalArgumentException(
1179:                            "Cannot convert a non-root ActionRequestVO");
1180:                }
1181:                ActionRequestValue actionRequest = new ActionRequestFactory()
1182:                        .createBlankActionRequest();
1183:                populateActionRequest(actionRequest, actionRequestVO);
1184:                if (actionRequestVO.getChildrenRequests() != null) {
1185:                    for (int i = 0; i < actionRequestVO.getChildrenRequests().length; i++) {
1186:                        ActionRequestVO childVO = actionRequestVO
1187:                                .getChildrenRequests()[i];
1188:                        actionRequest.getChildrenRequests().add(
1189:                                convertActionRequestVO(childVO, actionRequest));
1190:                    }
1191:                }
1192:                return actionRequest;
1193:            }
1194:
1195:            public static ActionRequestValue convertActionRequestVO(
1196:                    ActionRequestVO actionRequestVO,
1197:                    ActionRequestValue parentActionRequest)
1198:                    throws EdenUserNotFoundException {
1199:                if (actionRequestVO == null) {
1200:                    return null;
1201:                }
1202:                ActionRequestValue actionRequest = new ActionRequestFactory()
1203:                        .createBlankActionRequest();
1204:                populateActionRequest(actionRequest, actionRequestVO);
1205:                actionRequest.setParentActionRequest(parentActionRequest);
1206:                actionRequest.setParentActionRequestId(parentActionRequest
1207:                        .getActionRequestId());
1208:                if (actionRequestVO.getChildrenRequests() != null) {
1209:                    for (int i = 0; i < actionRequestVO.getChildrenRequests().length; i++) {
1210:                        ActionRequestVO childVO = actionRequestVO
1211:                                .getChildrenRequests()[i];
1212:                        actionRequest.getChildrenRequests().add(
1213:                                convertActionRequestVO(childVO, actionRequest));
1214:                    }
1215:                }
1216:                return actionRequest;
1217:            }
1218:
1219:            /**
1220:             * This method converts everything except for the parent and child requests
1221:             */
1222:            private static void populateActionRequest(
1223:                    ActionRequestValue actionRequest,
1224:                    ActionRequestVO actionRequestVO)
1225:                    throws EdenUserNotFoundException {
1226:
1227:                actionRequest.setActionRequested(actionRequestVO
1228:                        .getActionRequested());
1229:                actionRequest.setActionRequestId(actionRequestVO
1230:                        .getActionRequestId());
1231:                actionRequest.setActionTakenId(actionRequestVO
1232:                        .getActionTakenId());
1233:                actionRequest.setAnnotation(actionRequestVO.getAnnotation());
1234:                actionRequest.setApprovePolicy(actionRequestVO
1235:                        .getApprovePolicy());
1236:                actionRequest
1237:                        .setCreateDate(new Timestamp(new Date().getTime()));
1238:                actionRequest.setCurrentIndicator(actionRequestVO
1239:                        .getCurrentIndicator());
1240:                actionRequest.setDelegationType(actionRequestVO
1241:                        .getDelegationType());
1242:                actionRequest.setDocVersion(actionRequestVO.getDocVersion());
1243:                actionRequest.setIgnorePrevAction(actionRequestVO
1244:                        .getIgnorePrevAction());
1245:                actionRequest.setPriority(actionRequestVO.getPriority());
1246:                actionRequest.setQualifiedRoleName(actionRequestVO
1247:                        .getQualifiedRoleName());
1248:                actionRequest.setQualifiedRoleNameLabel(actionRequestVO
1249:                        .getQualifiedRoleNameLabel());
1250:                actionRequest.setRecipientTypeCd(actionRequestVO
1251:                        .getRecipientTypeCd());
1252:                actionRequest.setResponsibilityDesc(actionRequestVO
1253:                        .getResponsibilityDesc());
1254:                actionRequest.setResponsibilityId(actionRequestVO
1255:                        .getResponsibilityId());
1256:                actionRequest.setRoleName(actionRequestVO.getRoleName());
1257:                Long routeHeaderId = actionRequestVO.getRouteHeaderId();
1258:                if (routeHeaderId != null) {
1259:                    actionRequest.setRouteHeaderId(routeHeaderId);
1260:                    actionRequest.setRouteHeader(KEWServiceLocator
1261:                            .getRouteHeaderService().getRouteHeader(
1262:                                    routeHeaderId));
1263:                }
1264:                // properties set in routemanagerservice
1265:                actionRequest.setRouteLevel(actionRequestVO.getRouteLevel());
1266:                // TODO add the node instance to the VO
1267:                //        actionRequest.setRouteMethodName(actionRequestVO.getRouteMethodName());
1268:                actionRequest.setStatus(actionRequestVO.getStatus());
1269:                // TODO this should be moved to a validate somewhere's...
1270:                boolean userSet = false;
1271:                if (actionRequestVO.getUserIdVO() != null) {
1272:                    UserId userId = convertUserIdVO(actionRequestVO
1273:                            .getUserIdVO());
1274:                    WorkflowUser user = KEWServiceLocator.getUserService()
1275:                            .getWorkflowUser(userId);
1276:                    actionRequest.setWorkflowId(user.getWorkflowId());
1277:                    userSet = true;
1278:                } else if (actionRequestVO.getEmplyId() != null) {
1279:                    WorkflowUser user = KEWServiceLocator.getUserService()
1280:                            .getWorkflowUser(
1281:                                    new EmplId(actionRequestVO.getEmplyId()));
1282:                    actionRequest.setWorkflowId(user.getWorkflowId());
1283:                    userSet = true;
1284:                } else if (actionRequestVO.getUserVO() != null) {
1285:                    WorkflowUser user = convertUserVO(actionRequestVO
1286:                            .getUserVO());
1287:                    actionRequest.setWorkflowId(user.getWorkflowId());
1288:                    userSet = true;
1289:                }
1290:                if (actionRequestVO.getWorkgroupId() != null) {
1291:                    Long workgroupId = actionRequestVO.getWorkgroupId();
1292:                    // validate that the workgroup is good.
1293:                    Workgroup workgroup = KEWServiceLocator
1294:                            .getWorkgroupService().getWorkgroup(
1295:                                    new WorkflowGroupId(workgroupId));
1296:                    if (workgroup == null) {
1297:                        throw new RuntimeException(
1298:                                "Workgroup Id "
1299:                                        + workgroupId
1300:                                        + " is invalid.  Action Request cannot be activated.");
1301:                    }
1302:                    actionRequest.setWorkgroupId(workgroupId);
1303:                    userSet = true;
1304:                } else if (actionRequestVO.getWorkgroupVO() != null) {
1305:                    Long workgroupId = actionRequestVO.getWorkgroupVO()
1306:                            .getWorkgroupId();
1307:                    // validate that the workgroup is good.
1308:                    Workgroup workgroup = KEWServiceLocator
1309:                            .getWorkgroupService().getWorkgroup(
1310:                                    new WorkflowGroupId(workgroupId));
1311:                    if (workgroup == null) {
1312:                        throw new RuntimeException(
1313:                                "Workgroup Id "
1314:                                        + workgroupId
1315:                                        + " is invalid.  Action Request cannot be activated.");
1316:                    }
1317:                    actionRequest.setWorkgroupId(workgroupId);
1318:                    userSet = true;
1319:                }
1320:                // TODO role requests will not have a user or workgroup, so this code needs to handle that case
1321:                if (!userSet) {
1322:                    throw new RuntimeException(
1323:                            "Post processor didn't set a user or workgroup on the request");
1324:                }
1325:            }
1326:
1327:            public static ActionTakenValue convertActionTakenVO(
1328:                    ActionTakenVO actionTakenVO)
1329:                    throws EdenUserNotFoundException {
1330:                if (actionTakenVO == null) {
1331:                    return null;
1332:                }
1333:                ActionTakenValue actionTaken = new ActionTakenValue();
1334:                actionTaken.setActionDate(new Timestamp(actionTakenVO
1335:                        .getActionDate().getTimeInMillis()));
1336:                actionTaken.setActionTaken(actionTakenVO.getActionTaken());
1337:                actionTaken.setActionTakenId(actionTakenVO.getActionTakenId());
1338:                actionTaken.setAnnotation(actionTakenVO.getAnnotation());
1339:                actionTaken.setCurrentIndicator(Boolean.TRUE);
1340:                WorkflowUser delegator = convertUserVO(actionTakenVO
1341:                        .getDelegatorVO());
1342:                actionTaken.setDelegator(delegator);
1343:                if (delegator != null) {
1344:                    actionTaken.setDelegatorWorkflowId(delegator
1345:                            .getWorkflowUserId().getWorkflowId());
1346:                }
1347:                actionTaken.setDocVersion(actionTakenVO.getDocVersion());
1348:                DocumentRouteHeaderValue routeHeader = KEWServiceLocator
1349:                        .getRouteHeaderService().getRouteHeader(
1350:                                actionTakenVO.getRouteHeaderId());
1351:                actionTaken.setRouteHeader(routeHeader);
1352:                actionTaken.setRouteHeaderId(actionTaken.getRouteHeaderId());
1353:                WorkflowUser user = convertUserVO(actionTakenVO.getUserVO());
1354:                actionTaken.setWorkflowId(user.getWorkflowUserId()
1355:                        .getWorkflowId());
1356:                return actionTaken;
1357:            }
1358:
1359:            public static DocumentRouteStatusChangeVO convertDocumentRouteStatusChange(
1360:                    DocumentRouteStatusChange statusChange) {
1361:                if (statusChange == null) {
1362:                    return null;
1363:                }
1364:                DocumentRouteStatusChangeVO statusChangeVO = new DocumentRouteStatusChangeVO();
1365:                statusChangeVO
1366:                        .setRouteHeaderId(statusChange.getRouteHeaderId());
1367:                statusChangeVO.setAppDocId(statusChange.getAppDocId());
1368:                statusChangeVO.setOldRouteStatus(statusChange
1369:                        .getOldRouteStatus());
1370:                statusChangeVO.setNewRouteStatus(statusChange
1371:                        .getNewRouteStatus());
1372:                return statusChangeVO;
1373:            }
1374:
1375:            public static DocumentRouteLevelChangeVO convertDocumentRouteLevelChange(
1376:                    DocumentRouteLevelChange routeLevelChange) {
1377:                if (routeLevelChange == null) {
1378:                    return null;
1379:                }
1380:                DocumentRouteLevelChangeVO routeLevelChangeVO = new DocumentRouteLevelChangeVO();
1381:                routeLevelChangeVO.setRouteHeaderId(routeLevelChange
1382:                        .getRouteHeaderId());
1383:                routeLevelChangeVO.setAppDocId(routeLevelChange.getAppDocId());
1384:                routeLevelChangeVO.setOldRouteLevel(routeLevelChange
1385:                        .getOldRouteLevel());
1386:                routeLevelChangeVO.setNewRouteLevel(routeLevelChange
1387:                        .getNewRouteLevel());
1388:                routeLevelChangeVO.setOldNodeName(routeLevelChange
1389:                        .getOldNodeName());
1390:                routeLevelChangeVO.setNewNodeName(routeLevelChange
1391:                        .getNewNodeName());
1392:                routeLevelChangeVO.setOldNodeInstanceId(routeLevelChange
1393:                        .getOldNodeInstanceId());
1394:                routeLevelChangeVO.setNewNodeInstanceId(routeLevelChange
1395:                        .getNewNodeInstanceId());
1396:                return routeLevelChangeVO;
1397:            }
1398:
1399:            public static DeleteEventVO convertDeleteEvent(
1400:                    DeleteEvent deleteEvent) {
1401:                if (deleteEvent == null) {
1402:                    return null;
1403:                }
1404:                DeleteEventVO deleteEventVO = new DeleteEventVO();
1405:                deleteEventVO.setRouteHeaderId(deleteEvent.getRouteHeaderId());
1406:                deleteEventVO.setAppDocId(deleteEvent.getAppDocId());
1407:                return deleteEventVO;
1408:            }
1409:
1410:            public static ActionTakenEventVO convertActionTakenEvent(
1411:                    ActionTakenEvent actionTakenEvent)
1412:                    throws EdenUserNotFoundException {
1413:                if (actionTakenEvent == null) {
1414:                    return null;
1415:                }
1416:                ActionTakenEventVO actionTakenEventVO = new ActionTakenEventVO();
1417:                actionTakenEventVO.setRouteHeaderId(actionTakenEvent
1418:                        .getRouteHeaderId());
1419:                actionTakenEventVO.setAppDocId(actionTakenEvent.getAppDocId());
1420:                actionTakenEventVO
1421:                        .setActionTaken(convertActionTaken(actionTakenEvent
1422:                                .getActionTaken()));
1423:                return actionTakenEventVO;
1424:            }
1425:
1426:            public static AttributeDefinition convertWorkflowAttributeDefinitionVO(
1427:                    WorkflowAttributeDefinitionVO definitionVO,
1428:                    edu.iu.uis.eden.doctype.DocumentType documentType) {
1429:                if (definitionVO == null) {
1430:                    return null;
1431:                }
1432:                // get the rule attribute so we can get's it's message antity and not blow up if it's remote
1433:                RuleAttribute ruleAttribute = KEWServiceLocator
1434:                        .getRuleAttributeService().findByClassName(
1435:                                definitionVO.getAttributeName());
1436:                if (ruleAttribute == null) {
1437:                    ruleAttribute = KEWServiceLocator.getRuleAttributeService()
1438:                            .findByName(definitionVO.getAttributeName());
1439:                }
1440:                if (ruleAttribute == null) {
1441:                    throw new WorkflowRuntimeException("Attribute "
1442:                            + definitionVO.getAttributeName() + " not found");
1443:                }
1444:
1445:                ObjectDefinition definition = new ObjectDefinition(
1446:                        ruleAttribute.getClassName());
1447:                for (int index = 0; index < definitionVO
1448:                        .getConstructorParameters().length; index++) {
1449:                    String parameter = definitionVO.getConstructorParameters()[index];
1450:                    definition.addConstructorParameter(new DataDefinition(
1451:                            parameter, String.class));
1452:                }
1453:                boolean propertiesAsMap = EdenConstants.RULE_XML_ATTRIBUTE_TYPE
1454:                        .equals(ruleAttribute.getType())
1455:                        || EdenConstants.SEARCHABLE_XML_ATTRIBUTE_TYPE
1456:                                .equals(ruleAttribute.getType());
1457:                if (!propertiesAsMap) {
1458:                    for (int index = 0; index < definitionVO.getProperties().length; index++) {
1459:                        PropertyDefinitionVO propertyDefVO = definitionVO
1460:                                .getProperties()[index];
1461:                        definition
1462:                                .addProperty(new PropertyDefinition(
1463:                                        propertyDefVO.getName(),
1464:                                        new DataDefinition(propertyDefVO
1465:                                                .getValue(), String.class)));
1466:                    }
1467:                }
1468:
1469:                //this is likely from an EDL validate call and ME may needed to be added to the AttDefinitionVO.
1470:                if (ruleAttribute.getMessageEntity() != null) {
1471:                    definition.setMessageEntity(ruleAttribute
1472:                            .getMessageEntity());
1473:                } else {
1474:                    //get the me from the document type if it's been passed in - the document is having action taken on it.
1475:                    if (documentType != null) {
1476:                        definition.setMessageEntity(documentType
1477:                                .getMessageEntity());
1478:                    }
1479:                }
1480:
1481:                return new AttributeDefinition(ruleAttribute, definition);
1482:            }
1483:
1484:            public static DocumentDetailVO convertDocumentDetail(
1485:                    DocumentRouteHeaderValue routeHeader)
1486:                    throws WorkflowException {
1487:                if (routeHeader == null) {
1488:                    return null;
1489:                }
1490:                DocumentDetailVO detail = new DocumentDetailVO();
1491:                populateRouteHeaderVO(detail, routeHeader);
1492:                Map nodeInstances = new HashMap();
1493:                List actionRequestVOs = new ArrayList();
1494:                List rootActionRequests = KEWServiceLocator
1495:                        .getActionRequestService().getRootRequests(
1496:                                routeHeader.getActionRequests());
1497:                for (Iterator iterator = rootActionRequests.iterator(); iterator
1498:                        .hasNext();) {
1499:                    ActionRequestValue actionRequest = (ActionRequestValue) iterator
1500:                            .next();
1501:                    actionRequestVOs.add(convertActionRequest(actionRequest));
1502:                    RouteNodeInstance nodeInstance = actionRequest
1503:                            .getNodeInstance();
1504:                    if (nodeInstance == null) {
1505:                        continue;
1506:                    }
1507:                    if (nodeInstance.getRouteNodeInstanceId() == null) {
1508:                        throw new WorkflowException(
1509:                                "Error creating document detail structure because of NULL node instance id.");
1510:                    }
1511:                    nodeInstances.put(nodeInstance.getRouteNodeInstanceId(),
1512:                            nodeInstance);
1513:                }
1514:                detail.setActionRequests((ActionRequestVO[]) actionRequestVOs
1515:                        .toArray(new ActionRequestVO[0]));
1516:                List nodeInstanceVOs = new ArrayList();
1517:                for (Iterator iterator = nodeInstances.values().iterator(); iterator
1518:                        .hasNext();) {
1519:                    RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator
1520:                            .next();
1521:                    nodeInstanceVOs.add(convertRouteNodeInstance(nodeInstance));
1522:                }
1523:                detail.setNodeInstances((RouteNodeInstanceVO[]) nodeInstanceVOs
1524:                        .toArray(new RouteNodeInstanceVO[0]));
1525:                List actionTakenVOs = new ArrayList();
1526:                for (Iterator iterator = routeHeader.getActionsTaken()
1527:                        .iterator(); iterator.hasNext();) {
1528:                    ActionTakenValue actionTaken = (ActionTakenValue) iterator
1529:                            .next();
1530:                    actionTakenVOs.add(convertActionTaken(actionTaken));
1531:                }
1532:                detail.setActionsTaken((ActionTakenVO[]) actionTakenVOs
1533:                        .toArray(new ActionTakenVO[0]));
1534:                return detail;
1535:            }
1536:
1537:            public static RouteNodeInstanceVO convertRouteNodeInstance(
1538:                    RouteNodeInstance nodeInstance) throws WorkflowException {
1539:                if (nodeInstance == null) {
1540:                    return null;
1541:                }
1542:                RouteNodeInstanceVO nodeInstanceVO = new RouteNodeInstanceVO();
1543:                nodeInstanceVO.setActive(nodeInstance.isActive());
1544:                nodeInstanceVO.setBranchId(nodeInstance.getBranch()
1545:                        .getBranchId());
1546:                nodeInstanceVO.setComplete(nodeInstance.isComplete());
1547:                nodeInstanceVO.setDocumentId(nodeInstance.getDocumentId());
1548:                nodeInstanceVO.setInitial(nodeInstance.isInitial());
1549:                nodeInstanceVO.setName(nodeInstance.getName());
1550:                nodeInstanceVO
1551:                        .setProcessId(nodeInstance.getProcess() != null ? nodeInstance
1552:                                .getProcess().getRouteNodeInstanceId()
1553:                                : null);
1554:                nodeInstanceVO.setRouteNodeId(nodeInstance.getRouteNode()
1555:                        .getRouteNodeId());
1556:                nodeInstanceVO.setRouteNodeInstanceId(nodeInstance
1557:                        .getRouteNodeInstanceId());
1558:                nodeInstanceVO.setState(convertStates(nodeInstance.getState()));
1559:
1560:                nodeInstanceVO
1561:                        .setNextNodes(new RouteNodeInstanceVO[nodeInstance
1562:                                .getNextNodeInstances().size()]);
1563:                int i = 0;
1564:                for (Iterator iter = nodeInstance.getNextNodeInstances()
1565:                        .iterator(); iter.hasNext(); i++) {
1566:                    RouteNodeInstance nextNodeInstance = (RouteNodeInstance) iter
1567:                            .next();
1568:                    nodeInstanceVO.getNextNodes()[i] = convertRouteNodeInstance(nextNodeInstance);
1569:                }
1570:
1571:                return nodeInstanceVO;
1572:            }
1573:
1574:            public static StateVO[] convertStates(Collection states) {
1575:                if (states == null) {
1576:                    return null;
1577:                }
1578:                StateVO[] stateVOs = new StateVO[states.size()];
1579:                int index = 0;
1580:                for (Iterator iterator = states.iterator(); iterator.hasNext();) {
1581:                    State state = (State) iterator.next();
1582:                    stateVOs[index++] = convertState(state);
1583:                }
1584:                return stateVOs;
1585:            }
1586:
1587:            public static StateVO convertState(State nodeState) {
1588:                if (nodeState == null) {
1589:                    return null;
1590:                }
1591:                StateVO stateVO = new StateVO();
1592:                stateVO.setStateId(nodeState.getStateId());
1593:                stateVO.setKey(nodeState.getKey());
1594:                stateVO.setValue(nodeState.getValue());
1595:                return stateVO;
1596:            }
1597:
1598:            public static RouteNodeVO convertRouteNode(RouteNode node) {
1599:                if (node == null) {
1600:                    return null;
1601:                }
1602:                RouteNodeVO nodeVO = new RouteNodeVO();
1603:                nodeVO.setActivationType(node.getActivationType());
1604:                nodeVO.setBranchName(node.getBranch() != null ? node
1605:                        .getBranch().getName() : null);
1606:                nodeVO.setDocumentTypeId(node.getDocumentTypeId());
1607:                try {
1608:                    nodeVO.setExceptionWorkgroup(convertWorkgroup(node
1609:                            .getExceptionWorkgroup()));
1610:                } catch (EdenUserNotFoundException e) {
1611:                    throw new WorkflowRuntimeException(
1612:                            "Could not locate users in exception workgroup for node "
1613:                                    + node.getRouteNodeId() + ".", e);
1614:                }
1615:                nodeVO.setFinalApprovalInd(node.getFinalApprovalInd()
1616:                        .booleanValue());
1617:                nodeVO.setMandatoryRouteInd(node.getMandatoryRouteInd()
1618:                        .booleanValue());
1619:                nodeVO.setNodeType(node.getNodeType());
1620:                nodeVO.setRouteMethodCode(node.getRouteMethodCode());
1621:                nodeVO.setRouteMethodName(node.getRouteMethodName());
1622:                nodeVO.setRouteNodeId(node.getRouteNodeId());
1623:                nodeVO.setRouteNodeName(node.getRouteNodeName());
1624:                int index = 0;
1625:                Long[] previousNodeIds = new Long[node.getPreviousNodes()
1626:                        .size()];
1627:                for (Iterator iterator = node.getPreviousNodes().iterator(); iterator
1628:                        .hasNext();) {
1629:                    RouteNode prevNode = (RouteNode) iterator.next();
1630:                    previousNodeIds[index++] = prevNode.getRouteNodeId();
1631:                }
1632:                nodeVO.setPreviousNodeIds(previousNodeIds);
1633:                index = 0;
1634:                Long[] nextNodeIds = new Long[node.getNextNodes().size()];
1635:                for (Iterator iterator = node.getNextNodes().iterator(); iterator
1636:                        .hasNext();) {
1637:                    RouteNode nextNode = (RouteNode) iterator.next();
1638:                    nextNodeIds[index++] = nextNode.getRouteNodeId();
1639:                }
1640:                nodeVO.setNextNodeIds(nextNodeIds);
1641:                return nodeVO;
1642:            }
1643:
1644:            public static ProcessVO convertProcess(Process process) {
1645:                ProcessVO processVO = new ProcessVO();
1646:                processVO.setInitial(process.isInitial());
1647:                processVO.setInitialRouteNode(convertRouteNode(process
1648:                        .getInitialRouteNode()));
1649:                processVO.setName(process.getName());
1650:                processVO.setProcessId(process.getProcessId());
1651:                return processVO;
1652:            }
1653:
1654:            public static MovePoint convertMovePointVO(MovePointVO movePointVO) {
1655:                MovePoint movePoint = new MovePoint();
1656:                movePoint.setStartNodeName(movePointVO.getStartNodeName());
1657:                movePoint.setStepsToMove(movePointVO.getStepsToMove());
1658:                return movePoint;
1659:            }
1660:
1661:            public static AdHocRevoke convertAdHocRevokeVO(
1662:                    AdHocRevokeVO revokeVO) throws WorkflowException {
1663:                AdHocRevoke revoke = new AdHocRevoke();
1664:                revoke.setActionRequestId(revokeVO.getActionRequestId());
1665:                revoke.setNodeName(revokeVO.getNodeName());
1666:                if (revokeVO.getUserId() != null) {
1667:                    revoke.setUser(KEWServiceLocator.getUserService()
1668:                            .getWorkflowUser(revokeVO.getUserId()));
1669:                }
1670:                if (revokeVO.getWorkgroupId() != null) {
1671:                    revoke.setWorkgroup(KEWServiceLocator.getWorkgroupService()
1672:                            .getWorkgroup(revokeVO.getWorkgroupId()));
1673:                }
1674:                return revoke;
1675:            }
1676:
1677:            public static WorkflowAttributeValidationErrorVO convertWorkflowAttributeValidationError(
1678:                    WorkflowAttributeValidationError error) {
1679:                return new WorkflowAttributeValidationErrorVO(error.getKey(),
1680:                        error.getMessage());
1681:            }
1682:
1683:            //Method added for updating notes on server sites based on NoteVO change. Modfy on April 7, 2006
1684:            public static void updateNotes(RouteHeaderVO routeHeaderVO,
1685:                    Long routeHeaderId) {
1686:                NoteVO[] notes = routeHeaderVO.getNotes();
1687:                NoteVO[] notesToDelete = routeHeaderVO.getNotesToDelete();
1688:                Note noteToDelete = null;
1689:                Note noteToSave = null;
1690:
1691:                // Add or update notes to note table based on notes array in RouteHeaderVO
1692:                if (notes != null) {
1693:                    for (int i = 0; i < notes.length; i++) {
1694:                        if (notes[i] != null) {
1695:                            noteToSave = new Note();
1696:                            noteToSave.setNoteId(notes[i].getNoteId());
1697:                            noteToSave.setRouteHeaderId(routeHeaderId);
1698:                            noteToSave.setNoteAuthorWorkflowId(notes[i]
1699:                                    .getNoteAuthorWorkflowId());
1700:                            noteToSave.setNoteCreateDate(Utilities
1701:                                    .convertCalendar(notes[i]
1702:                                            .getNoteCreateDate()));
1703:                            noteToSave.setNoteText(notes[i].getNoteText());
1704:                            noteToSave.setLockVerNbr(notes[i].getLockVerNbr());
1705:                            //	    			 if notes[i].getNoteId() == null, add note to note table, otherwise update note to note table
1706:                            getNoteService().saveNote(noteToSave);
1707:                        }
1708:                    }
1709:
1710:                }
1711:
1712:                //  Delete notes from note table based on notesToDelete array in RouteHeaderVO
1713:                if (notesToDelete != null) {
1714:                    for (int i = 0; i < notesToDelete.length; i++) {
1715:                        noteToDelete = getNoteService().getNoteByNoteId(
1716:                                notesToDelete[i].getNoteId());
1717:                        if (noteToDelete != null) {
1718:                            getNoteService().deleteNote(noteToDelete);
1719:                        }
1720:                    }
1721:                    routeHeaderVO.setNotesToDelete(null);
1722:                }
1723:            }
1724:
1725:            private static NoteService getNoteService() {
1726:                return (NoteService) KEWServiceLocator
1727:                        .getService(KEWServiceLocator.NOTE_SERVICE);
1728:            }
1729:
1730:            private static NoteVO[] convertNotesArrayListToNoteVOArray(
1731:                    List notesArrayList) {
1732:                if (notesArrayList.size() > 0) {
1733:                    NoteVO[] noteVOArray = new NoteVO[notesArrayList.size()];
1734:                    int i = 0;
1735:                    Note tempNote;
1736:                    NoteVO tempNoteVO;
1737:                    for (Iterator it = notesArrayList.iterator(); it.hasNext();) {
1738:                        tempNote = (Note) it.next();
1739:                        tempNoteVO = new NoteVO();
1740:                        tempNoteVO.setNoteId(tempNote.getNoteId());
1741:                        tempNoteVO
1742:                                .setRouteHeaderId(tempNote.getRouteHeaderId());
1743:                        tempNoteVO.setNoteAuthorWorkflowId(tempNote
1744:                                .getNoteAuthorWorkflowId());
1745:                        tempNoteVO
1746:                                .setNoteCreateDate(Utilities
1747:                                        .convertTimestamp(tempNote
1748:                                                .getNoteCreateDate()));
1749:                        tempNoteVO.setNoteText(tempNote.getNoteText());
1750:                        tempNoteVO.setLockVerNbr(tempNote.getLockVerNbr());
1751:                        noteVOArray[i] = tempNoteVO;
1752:                        i++;
1753:                    }
1754:                    return noteVOArray;
1755:                } else {
1756:                    return null;
1757:                }
1758:            }
1759:
1760:            public static SimulationCriteria convertReportCriteriaVO(
1761:                    ReportCriteriaVO criteriaVO)
1762:                    throws EdenUserNotFoundException {
1763:                if (criteriaVO == null) {
1764:                    return null;
1765:                }
1766:                SimulationCriteria criteria = new SimulationCriteria();
1767:                criteria.setDestinationNodeName(criteriaVO.getTargetNodeName());
1768:                criteria.setDocumentId(criteriaVO.getRouteHeaderId());
1769:                criteria.setDocumentTypeName(criteriaVO.getDocumentTypeName());
1770:                criteria.setXmlContent(criteriaVO.getXmlContent());
1771:                if (criteriaVO.getRoutingUser() != null) {
1772:                    WorkflowUser user = KEWServiceLocator.getUserService()
1773:                            .getWorkflowUser(criteriaVO.getRoutingUser());
1774:                    if (user == null) {
1775:                        throw new EdenUserNotFoundException(
1776:                                "Could not locate user for the given id: "
1777:                                        + criteriaVO.getRoutingUser());
1778:                    }
1779:                    criteria.setRoutingUser(user);
1780:                }
1781:                if (criteriaVO.getRuleTemplateNames() != null) {
1782:                    for (int index = 0; index < criteriaVO
1783:                            .getRuleTemplateNames().length; index++) {
1784:                        String ruleTemplateName = criteriaVO
1785:                                .getRuleTemplateNames()[index];
1786:                        criteria.getRuleTemplateNames().add(ruleTemplateName);
1787:                    }
1788:                }
1789:                if (criteriaVO.getNodeNames() != null) {
1790:                    for (int i = 0; i < criteriaVO.getNodeNames().length; i++) {
1791:                        String nodeName = criteriaVO.getNodeNames()[i];
1792:                        criteria.getNodeNames().add(nodeName);
1793:                    }
1794:                }
1795:                if (criteriaVO.getTargetUsers() != null) {
1796:                    for (int index = 0; index < criteriaVO.getTargetUsers().length; index++) {
1797:                        UserIdVO userIdVO = criteriaVO.getTargetUsers()[index];
1798:                        WorkflowUser user = KEWServiceLocator.getUserService()
1799:                                .getWorkflowUser(userIdVO);
1800:                        if (user == null) {
1801:                            throw new EdenUserNotFoundException(
1802:                                    "Could not locate user for the given id: "
1803:                                            + userIdVO);
1804:                        }
1805:                        criteria.getDestinationRecipients().add(user);
1806:                    }
1807:                }
1808:                if (criteriaVO.getActionsToTake() != null) {
1809:                    for (int index = 0; index < criteriaVO.getActionsToTake().length; index++) {
1810:                        ReportActionToTakeVO actionToTakeVO = criteriaVO
1811:                                .getActionsToTake()[index];
1812:                        criteria.getActionsToTake().add(
1813:                                convertReportActionToTakeVO(actionToTakeVO));
1814:                    }
1815:                }
1816:                return criteria;
1817:            }
1818:
1819:            public static SimulationActionToTake convertReportActionToTakeVO(
1820:                    ReportActionToTakeVO actionToTakeVO)
1821:                    throws EdenUserNotFoundException {
1822:                if (actionToTakeVO == null) {
1823:                    return null;
1824:                }
1825:                SimulationActionToTake actionToTake = new SimulationActionToTake();
1826:                actionToTake.setNodeName(actionToTakeVO.getNodeName());
1827:                if (StringUtils.isBlank(actionToTakeVO.getActionToPerform())) {
1828:                    throw new IllegalArgumentException(
1829:                            "ReportActionToTakeVO must contain an action taken code and does not");
1830:                }
1831:                actionToTake.setActionToPerform(actionToTakeVO
1832:                        .getActionToPerform());
1833:                if (actionToTakeVO.getUserIdVO() == null) {
1834:                    throw new IllegalArgumentException(
1835:                            "ReportActionToTakeVO must contain a userId and does not");
1836:                }
1837:                WorkflowUser user = KEWServiceLocator.getUserService()
1838:                        .getWorkflowUser(actionToTakeVO.getUserIdVO());
1839:                if (user == null) {
1840:                    throw new EdenUserNotFoundException(
1841:                            "Could not locate user for the given id: "
1842:                                    + actionToTakeVO.getUserIdVO());
1843:                }
1844:                actionToTake.setUser(user);
1845:                return actionToTake;
1846:            }
1847:
1848:            public static RuleDelegationVO convertRuleDelegation(
1849:                    RuleDelegation ruleDelegation) throws WorkflowException {
1850:                if (ruleDelegation == null) {
1851:                    return null;
1852:                }
1853:                RuleDelegationVO ruleDelegationVO = new RuleDelegationVO();
1854:                ruleDelegationVO.setDelegationType(ruleDelegation
1855:                        .getDelegationType());
1856:                ruleDelegationVO.setDelegationRule(convertRule(ruleDelegation
1857:                        .getDelegationRuleBaseValues()));
1858:                return ruleDelegationVO;
1859:            }
1860:
1861:            //    public static RuleDelegation convertRuleExtensionVO(RuleExtensionVO ruleExtensionVO) throws WorkflowException {}
1862:
1863:            public static Collection<RuleExtensionVO> convertRuleExtension(
1864:                    RuleExtension ruleExtension) throws WorkflowException {
1865:                if (ruleExtension == null) {
1866:                    return null;
1867:                }
1868:                List<RuleExtensionVO> extensionVOs = new ArrayList<RuleExtensionVO>();
1869:                for (Iterator iter = ruleExtension.getExtensionValues()
1870:                        .iterator(); iter.hasNext();) {
1871:                    RuleExtensionValue extensionValue = (RuleExtensionValue) iter
1872:                            .next();
1873:                    extensionVOs.add(new RuleExtensionVO(extensionValue
1874:                            .getKey(), extensionValue.getValue()));
1875:                }
1876:                return extensionVOs;
1877:            }
1878:
1879:            public static KeyValuePair convertRuleExtensionVO(
1880:                    RuleExtensionVO ruleExtensionVO) throws WorkflowException {
1881:                if (ruleExtensionVO == null) {
1882:                    return null;
1883:                }
1884:                return new KeyValuePair(ruleExtensionVO.getKey(),
1885:                        ruleExtensionVO.getValue());
1886:            }
1887:
1888:            public static RuleResponsibilityVO convertRuleResponsibility(
1889:                    RuleResponsibility ruleResponsibility)
1890:                    throws WorkflowException {
1891:                if (ruleResponsibility == null) {
1892:                    return null;
1893:                }
1894:                RuleResponsibilityVO ruleResponsibilityVO = new RuleResponsibilityVO();
1895:                ruleResponsibilityVO.setActionRequestedCd(ruleResponsibility
1896:                        .getActionRequestedCd());
1897:                ruleResponsibilityVO.setApprovePolicy(ruleResponsibility
1898:                        .getApprovePolicy());
1899:                ruleResponsibilityVO.setPriority(ruleResponsibility
1900:                        .getPriority());
1901:                ruleResponsibilityVO.setResponsibilityId(ruleResponsibility
1902:                        .getResponsibilityId());
1903:                ruleResponsibilityVO.setRoleName(ruleResponsibility.getRole());
1904:                ruleResponsibilityVO.setUser(convertUser(ruleResponsibility
1905:                        .getWorkflowUser()));
1906:                ruleResponsibilityVO
1907:                        .setWorkgroup(convertWorkgroup(ruleResponsibility
1908:                                .getWorkgroup()));
1909:                for (Iterator iter = ruleResponsibility.getDelegationRules()
1910:                        .iterator(); iter.hasNext();) {
1911:                    RuleDelegation ruleDelegation = (RuleDelegation) iter
1912:                            .next();
1913:                    ruleResponsibilityVO
1914:                            .addDelegationRule(convertRuleDelegation(ruleDelegation));
1915:                }
1916:                return ruleResponsibilityVO;
1917:            }
1918:
1919:            //    public static KeyValuePair convertRuleResponsibilityVO(RuleResponsibilityVO ruleResponsibilityVO) throws WorkflowException {}
1920:
1921:            public static RuleVO convertRule(RuleBaseValues ruleValues)
1922:                    throws WorkflowException {
1923:                if (ruleValues == null) {
1924:                    return null;
1925:                }
1926:                RuleVO rule = new RuleVO();
1927:                rule.setActiveInd(ruleValues.getActiveInd());
1928:                rule.setDescription(ruleValues.getDescription());
1929:                rule.setDocTypeName(ruleValues.getDocTypeName());
1930:                rule.setFromDate(ruleValues.getFromDateString());
1931:                rule.setToDate(ruleValues.getToDateString());
1932:                rule.setIgnorePrevious(ruleValues.getIgnorePrevious());
1933:                rule.setRuleTemplateId(ruleValues.getRuleTemplateId());
1934:                rule.setRuleTemplateName(ruleValues.getRuleTemplateName());
1935:
1936:                // get keyPair values to setup RuleExtensionVOs
1937:                for (Iterator iter = ruleValues.getRuleExtensions().iterator(); iter
1938:                        .hasNext();) {
1939:                    RuleExtension ruleExtension = (RuleExtension) iter.next();
1940:                    rule.addRuleExtensions(convertRuleExtension(ruleExtension));
1941:                }
1942:                // get keyPair values to setup RuleExtensionVOs
1943:                for (Iterator iter = ruleValues.getResponsibilities()
1944:                        .iterator(); iter.hasNext();) {
1945:                    RuleResponsibility ruleResponsibility = (RuleResponsibility) iter
1946:                            .next();
1947:                    rule
1948:                            .addRuleResponsibility(convertRuleResponsibility(ruleResponsibility));
1949:                }
1950:                return rule;
1951:            }
1952:
1953:            //    public static RuleBaseValues convertRuleVO(RuleVO ruleVO) throws WorkflowException {}
1954:
1955:            private static void handleException(String message, Exception e)
1956:                    throws WorkflowException {
1957:                if (e instanceof  RuntimeException) {
1958:                    throw (RuntimeException) e;
1959:                } else if (e instanceof  WorkflowException) {
1960:                    throw (WorkflowException) e;
1961:                }
1962:                throw new WorkflowException(message, e);
1963:            }
1964:
1965:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.