Source Code Cross Referenced for VariableTransformer.java in  » Project-Management » EmForce » org » emforge » jbpm » 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 » Project Management » EmForce » org.emforge.jbpm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.emforge.jbpm;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collection;
005:
006:        import org.acegisecurity.userdetails.UserDetails;
007:        import org.apache.commons.collections.Transformer;
008:        import org.apache.commons.lang.StringUtils;
009:        import org.emforge.projectmanager.ProjectService;
010:        import org.emforge.projectmanager.base.MilestoneDO;
011:        import org.emforge.projectmanager.base.ProjectDO;
012:        import org.emforge.xfer.SelectValueTO;
013:        import org.emforge.xfer.VariableTO;
014:        import org.jbpm.context.def.VariableAccess;
015:        import org.jbpm.graph.exe.ProcessInstance;
016:
017:        import ru.emdev.EmForge.security.EmForgeUserDetails;
018:        import ru.emdev.EmForge.security.UserFactory;
019:        import ru.emdev.EmForge.security.dao.Role;
020:
021:        /** Variable Transformer
022:         * Used for converting VariableAccess and Value to VariableTO
023:         * 
024:         * It is not implementing Transformer interface, since it is required 2 input objects  
025:         */
026:        class VariableTransformer implements  Transformer {
027:            private ProjectService projectService;
028:            private UserFactory userFactory;
029:            private ProjectDO project;
030:
031:            public VariableTransformer(ProjectService projectService,
032:                    UserFactory userFactory, ProcessInstance process,
033:                    String projectName) {
034:                this .projectService = projectService;
035:                this .userFactory = userFactory;
036:
037:                // process may not to be specified - in this case we can get project by name
038:                if (projectName != null) {
039:                    this .project = projectService.getProject(projectName);
040:                } else {
041:                    // process should be specified!
042:                    this .project = ProcessTransformer.getProject(process);
043:                }
044:            }
045:
046:            public VariableTO transform(Object i_input) {
047:                VariableAccess var = (VariableAccess) i_input;
048:                return transform(var, null);
049:            }
050:
051:            /** Create Step Variable from variable Access and Value 
052:             * 
053:             */
054:            public VariableTO transform(VariableAccess i_var, Object i_value) {
055:                VariableTO variableTO = transform(i_var.getMappedName(),
056:                        i_value);
057:
058:                variableTO.setReadable(i_var.isReadable());
059:                variableTO.setRequired(i_var.isRequired());
060:                variableTO.setWritable(i_var.isWritable());
061:
062:                return variableTO;
063:            }
064:
065:            public VariableTO transform(String i_label, Object i_value) {
066:                String value = null;
067:
068:                String displayValue = null;
069:                SelectValueTO[] selectValues = null;
070:
071:                // check variable type: is it milestone?
072:                if (BpmVariable.MILESTONE.getVariable().equals(i_label)) {
073:                    // convert values from milestone
074:                    MilestoneDO milestone = (MilestoneDO) i_value;
075:
076:                    value = milestone != null ? milestone.getName().toString()
077:                            : null;
078:                    displayValue = milestone != null ? milestone
079:                            .getDisplayName() : null;
080:
081:                } else if (isVarTypeUser(i_label)) {
082:                    value = i_value != null ? i_value.toString() : null;
083:
084:                    UserDetails user = null;
085:                    try {
086:                        user = i_value != null ? userFactory.getUser(value)
087:                                : null;
088:                    } catch (Exception ex) {
089:                        // just ignore it here
090:                    }
091:                    displayValue = user != null ? user.getUsername() : null;
092:                } else {
093:                    value = i_value != null ? i_value.toString() : null;
094:                    displayValue = value;
095:                }
096:
097:                // create variable
098:                VariableTO variableTO = new VariableTO();
099:                variableTO.setLabel(i_label);
100:                variableTO.setDisplayLabel(getDisplayLabel(i_label));
101:
102:                variableTO.setValue(value);
103:                variableTO.setDisplayValue(displayValue);
104:
105:                // get select values for variable
106:                selectValues = getVarSelectValues(i_label);
107:
108:                variableTO.setSelectValues(selectValues);
109:
110:                variableTO.setReadable(true);
111:                variableTO.setRequired(true);
112:                variableTO.setWritable(true);
113:
114:                return variableTO;
115:            }
116:
117:            private boolean isVarTypeUser(String label) {
118:                return label != null
119:                        && label.startsWith(BpmVariable.ASSIGNTO.getVariable());
120:            }
121:
122:            private String getDisplayLabel(String i_label) {
123:                String label = StringUtils.removeStart(i_label, "_");
124:
125:                if (label.startsWith(BpmVariable.ASSIGNTO.getVariable())) {
126:                    // This is Assign To Variable
127:                    if (label.length() > BpmVariable.ASSIGNTO.getVariable()
128:                            .length() + 1) {
129:                        String roleName = label.substring(BpmVariable.ASSIGNTO
130:                                .getVariable().length() + 1);
131:                        label = roleName;
132:                    } else {
133:                        label = "Assigned To";
134:                    }
135:                }
136:
137:                return label;
138:            }
139:
140:            protected SelectValueTO[] getVarSelectValues(String label) {
141:                if (BpmVariable.MILESTONE.getVariable().equals(label)) {
142:                    SelectValueTO[] selectValues = null;
143:
144:                    if (project != null) {
145:                        Collection<MilestoneDO> milestones = projectService
146:                                .getOpenedMilestones(project);
147:
148:                        selectValues = new SelectValueTO[milestones.size() + 1];
149:                        selectValues[0] = new SelectValueTO("", "");
150:
151:                        int i = 1;
152:                        for (MilestoneDO openMilestone : milestones) {
153:                            selectValues[i++] = new SelectValueTO(openMilestone
154:                                    .getName(), openMilestone.getDisplayName());
155:                        }
156:                    }
157:
158:                    return selectValues;
159:                } else if (isVarTypeUser(label)) {
160:                    return getUserVarSelectValues(label);
161:                } else {
162:                    return null;
163:                }
164:            }
165:
166:            /** Created collection of selectValues for user-variable */
167:            private SelectValueTO[] getUserVarSelectValues(String label) {
168:
169:                Collection<SelectValueTO> result = new ArrayList<SelectValueTO>();
170:
171:                // try to get role name
172:                Role role = null;
173:                if (Role.isVariableName(label)) {
174:                    String roleName = Role.getName(label);
175:                    role = userFactory.getRole(roleName);
176:                    if (role != null) {
177:                        result.add(new SelectValueTO(roleName, role
178:                                .getDecoratedName()));
179:                    } else {
180:                        result.add(new SelectValueTO("", ""));
181:                    }
182:                } else {
183:                    result.add(new SelectValueTO("", ""));
184:                }
185:
186:                fillUsersCollection(project, role, result);
187:                return result.toArray(new SelectValueTO[result.size()]);
188:            }
189:
190:            /**
191:             * Fills specified collection with users of specified role
192:             * 
193:             * @param role a role to get users
194:             * @param result a collection to return
195:             * @author szakusov, 21.02.2008: Implemented for request [^74641]
196:             */
197:            private void fillUsersCollection(ProjectDO project, Role role,
198:                    Collection<SelectValueTO> result) {
199:
200:                Collection<EmForgeUserDetails> users = null;
201:
202:                if (role != null) {
203:                    users = projectService.getUsers(project, role);
204:                } else {
205:                    users = projectService.getAllProjectUsers(project);
206:                }
207:
208:                for (EmForgeUserDetails user : users) {
209:                    result.add(new SelectValueTO(user.getUsername(), user
210:                            .getDisplayName()));
211:                }
212:            }
213:
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.