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


001:        package org.emforge.jbpm.web.bean;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collection;
005:        import java.util.Date;
006:        import java.util.LinkedList;
007:
008:        import javax.faces.model.SelectItem;
009:
010:        import org.apache.commons.lang.StringUtils;
011:        import org.apache.commons.logging.Log;
012:        import org.apache.commons.logging.LogFactory;
013:        import org.emforge.BpmService;
014:        import org.emforge.EmForgeException;
015:        import org.emforge.projectmanager.ProjectService;
016:        import org.emforge.projectmanager.base.ProjectDO;
017:        import org.emforge.xfer.PriorityTO;
018:        import org.emforge.xfer.StepTO;
019:        import org.emforge.xfer.TransitionTO;
020:        import org.emforge.xfer.VariableTO;
021:        import org.emforge.xfer.WorkflowTO;
022:
023:        import ru.emdev.EmForge.security.EmForgeUserDetails;
024:        import ru.emdev.EmForge.security.UserFactory;
025:        import ru.emdev.EmForge.security.dao.Role;
026:
027:        /**
028:         * Bean to represent Step in GUI
029:         */
030:        public class StepBean {
031:
032:            protected final Log logger = LogFactory.getLog(getClass());
033:
034:            private Integer num;
035:            private StepTO step;
036:            private PriorityTO priority;
037:
038:            private static final String NEXT_ACTION_DEFAULT_TRANSITION = "__default_transition__";
039:            private static final String NEXT_ACTION_SUBPROCESS = "__subprocess__";
040:
041:            /** Next Action Name */
042:            private String nextAction = NEXT_ACTION_DEFAULT_TRANSITION;
043:
044:            /** Process Definition to create subprocess */
045:            private WorkflowTO subWorkflow;
046:            private String stepMessage;
047:            private String reassignTo;
048:
049:            private TaskController taskController;
050:            private ProjectService projectService;
051:            private UserFactory userFactory;
052:            private BpmService bpmService;
053:            private NewTaskController newTaskController;
054:
055:            /**
056:             * @param taskController
057:             * @param num
058:             * @param globalselectItems
059:             * @param projectService
060:             * @param userFactory
061:             * @param bpmService
062:             * @param newTaskController
063:             * @param step
064:             */
065:            public StepBean(TaskController taskController, Integer num,
066:                    ProjectService projectService, UserFactory userFactory,
067:                    BpmService bpmService, NewTaskController newTaskController,
068:                    StepTO step) {
069:
070:                this .num = num;
071:                this .taskController = taskController;
072:                this .projectService = projectService;
073:                this .userFactory = userFactory;
074:                this .bpmService = bpmService;
075:                this .newTaskController = newTaskController;
076:
077:                this .step = step;
078:
079:                this .priority = step.getPriority();
080:            }
081:
082:            /**
083:             * @return
084:             */
085:            public Integer getNum() {
086:
087:                return num;
088:            }
089:
090:            /**
091:             * @return
092:             */
093:            public Long getId() {
094:
095:                return step.getId();
096:            }
097:
098:            /**
099:             * @return
100:             */
101:            public PriorityTO getPriority() {
102:
103:                return priority;
104:            }
105:
106:            /**
107:             * @param i_priority
108:             */
109:            public void setPriority(PriorityTO i_priority) {
110:
111:                priority = i_priority;
112:            }
113:
114:            /**
115:             * @return
116:             */
117:            public String getOwner() {
118:
119:                return step.getActor();
120:            }
121:
122:            /**
123:             * @return
124:             */
125:            public Date getStartTime() {
126:
127:                return step.getActualStartTime();
128:            }
129:
130:            /**
131:             * @return
132:             */
133:            public String getName() {
134:
135:                return step.getName();
136:            }
137:
138:            /**
139:             * @return
140:             */
141:            public Date getDueDate() {
142:
143:                return step.getDueDate();
144:            }
145:
146:            /**
147:             * @return
148:             */
149:            public String getStepMessage() {
150:
151:                return stepMessage;
152:            }
153:
154:            /**
155:             * Is current user can work with this step?
156:             * 
157:             * @return
158:             */
159:            public boolean isCanSubmit() {
160:                return bpmService.canCompleteStep(step);
161:            }
162:
163:            public boolean isCanRequestStatus() throws EmForgeException {
164:                return bpmService.isPossibleRequestStatus(step.getId());
165:            }
166:
167:            /**
168:             * In case then step is assigned to role - return it. Othervise return null
169:             * 
170:             * @return
171:             */
172:            public Role getAssignedRole() {
173:
174:                if (step == null) {
175:                    return null;
176:                }
177:
178:                // Is task owner - role name?
179:                Role role = userFactory.getRole(step.getActor());
180:                return role;
181:            }
182:
183:            /**
184:             * @return
185:             */
186:            public VariableTO[] getVariables() {
187:                return step.getWritableVariables();
188:            }
189:
190:            // actions
191:
192:            /**
193:             * @return
194:             */
195:            public String getNextAction() {
196:
197:                return nextAction;
198:            }
199:
200:            /**
201:             * @param nextAction
202:             */
203:            public void setNextAction(String nextAction) {
204:
205:                this .nextAction = nextAction;
206:            }
207:
208:            /**
209:             * Return List of Next Options
210:             * 
211:             * @return
212:             */
213:            public Collection<SelectItem> getNextActions() {
214:
215:                Collection<SelectItem> result = new LinkedList<SelectItem>();
216:
217:                if (userFactory.getCurrentUser().isAnonymous()) {
218:                    return result;
219:                }
220:
221:                TransitionTO[] transitions = step.getTransitions();
222:
223:                for (TransitionTO transition : transitions) {
224:                    String transitionName = transition.getName();
225:                    if (StringUtils.isEmpty(transitionName)) {
226:                        transitionName = NEXT_ACTION_DEFAULT_TRANSITION;
227:                    }
228:
229:                    result.add(new SelectItem(transitionName, transition
230:                            .getLabel()));
231:                }
232:
233:                result.add(new SelectItem(NEXT_ACTION_SUBPROCESS,
234:                        "Create a new subtask"));
235:
236:                return result;
237:            }
238:
239:            /**
240:             * @return
241:             */
242:            public WorkflowTO getSubWorkflow() {
243:
244:                return subWorkflow;
245:            }
246:
247:            /**
248:             * @param i_subProcessDef
249:             */
250:            public void setSubWorkflow(WorkflowTO i_subWorkflow) {
251:
252:                subWorkflow = i_subWorkflow;
253:            }
254:
255:            /**
256:             * @return
257:             */
258:            public String getReassignTo() {
259:
260:                return reassignTo;
261:            }
262:
263:            /**
264:             * @param i_reassignTo
265:             */
266:            public void setReassignTo(String i_reassignTo) {
267:
268:                reassignTo = i_reassignTo;
269:            }
270:
271:            /**
272:             * @return
273:             */
274:            public Collection<SelectItem> getWorkflows()
275:                    throws EmForgeException {
276:
277:                Collection<SelectItem> result = new ArrayList<SelectItem>();
278:
279:                result.add(new SelectItem("", ""));
280:
281:                WorkflowTO[] workflows = bpmService.getWorkflows();
282:                for (WorkflowTO workflow : workflows) {
283:                    result
284:                            .add(new SelectItem(workflow, workflow
285:                                    .getStartName()));
286:                }
287:
288:                return result;
289:            }
290:
291:            /**
292:             * @return
293:             */
294:            public String submit() {
295:
296:                if (!isCanSubmit()) {
297:                    return null;
298:                }
299:
300:                if (nextAction.equals(NEXT_ACTION_SUBPROCESS)) {
301:                    // add comment
302:                    taskController.addComment();
303:
304:                    if (subWorkflow != null) {
305:                        // start new process wizard for subprocess
306:                        newTaskController.clean();
307:                        newTaskController.setTaskProject(projectService
308:                                .getProject(step.getProjectName()));
309:                        newTaskController.setWorkflow(subWorkflow);
310:                        newTaskController.setParentStep(step);
311:                        // skip workflow selection
312:                        newTaskController.next();
313:                        return "newtask";
314:                    }
315:
316:                    return null;
317:                } else {
318:                    // complete task with specified transition
319:                    String transitionName = nextAction;
320:                    if (transitionName.equals(NEXT_ACTION_DEFAULT_TRANSITION)) {
321:                        transitionName = "";
322:                    }
323:
324:                    try {
325:                        bpmService.completeStep(step, transitionName,
326:                                taskController.getComment());
327:                        taskController.clearComment();
328:                    } catch (EmForgeException ex) {
329:                        logger.warn("Cannot close task:", ex);
330:
331:                        taskController.addErrorMessage(ex.getMessage(), ex
332:                                .getMessage());
333:                        return null;
334:                    }
335:
336:                    // always stay in the process - this method will refresh all
337:                    // data in controller
338:                    taskController.setTaskId(step.getTaskId());
339:                    return null;
340:                }
341:            }
342:
343:            /**
344:             * @return
345:             */
346:            public String changeStepPriority() {
347:                try {
348:                    step = bpmService.changeStepPriority(step, priority,
349:                            taskController.getComment());
350:                    taskController.clearComment();
351:                } catch (EmForgeException ex) {
352:                    stepMessage = "Cannot change priority: " + ex.getMessage();
353:                    return null;
354:                }
355:
356:                stepMessage = "Individual Step Priority changed to "
357:                        + priority.getName();
358:                return null;
359:            }
360:
361:            /**
362:             * @return
363:             */
364:            public String assignToMe() {
365:                String userName = userFactory.getCurrentUser().getUsername();
366:
367:                try {
368:                    // save new task information into database
369:                    step = bpmService.assignStep(step, userName, taskController
370:                            .getComment());
371:                    taskController.clearComment();
372:                } catch (EmForgeException ex) {
373:                    taskController.addErrorMessage("Cannot reassign step", ex
374:                            .getMessage());
375:                }
376:
377:                return null;
378:            }
379:
380:            public Collection<SelectItem> getReassignToUserNames()
381:                    throws Exception {
382:
383:                Collection<SelectItem> result = new ArrayList<SelectItem>();
384:
385:                String swimlaneName = step.getSwimlane();
386:                Role role = null;
387:                if (swimlaneName != null) {
388:                    role = userFactory.getRole(swimlaneName);
389:                    if (role != null) {
390:                        result.add(new SelectItem(swimlaneName, role
391:                                .getDecoratedName()));
392:                    }
393:                }
394:
395:                fillUsersCollection(role, result);
396:                return result;
397:            }
398:
399:            /**
400:             * Fills specified collection with users of specified role
401:             * 
402:             * @param role a role to get users
403:             * @param result a collection to return
404:             * @author szakusov, 21.02.2008: Implemented for request [^74641]
405:             */
406:            protected void fillUsersCollection(Role role,
407:                    Collection<SelectItem> result) {
408:
409:                ProjectDO project = projectService.getProject(step
410:                        .getProjectName());
411:                Collection<EmForgeUserDetails> users = null;
412:
413:                if (role != null) {
414:                    users = projectService.getUsers(project, role);
415:                } else {
416:                    users = projectService.getAllProjectUsers(project);
417:                }
418:
419:                for (EmForgeUserDetails user : users) {
420:                    result.add(new SelectItem(user.getUsername(), user
421:                            .getDisplayName()));
422:                }
423:            }
424:
425:            /**
426:             * @return
427:             */
428:            public String reassignStep() {
429:
430:                if (StringUtils.isNotEmpty(reassignTo)) {
431:                    try {
432:                        step = bpmService.assignStep(step, reassignTo,
433:                                taskController.getComment());
434:
435:                        taskController.clearComment();
436:                    } catch (EmForgeException ex) {
437:                        stepMessage = "Cannot reassing step:" + ex.getMessage();
438:                    }
439:                }
440:
441:                return null;
442:            }
443:
444:            /**
445:             * @todo This code is dublicated with BpmServiceImpl - need to be refactored
446:             * @return
447:             */
448:            public boolean isGroupMember() {
449:                ProjectDO project = projectService.getProject(step
450:                        .getProjectName());
451:                if (project == null) {
452:                    return false;
453:                }
454:
455:                // Is task owner - role name?
456:                Role role = getAssignedRole(step);
457:                if (role == null) {
458:                    return false;
459:                }
460:
461:                return projectService.hasRole(project, userFactory
462:                        .getCurrentUser(), role);
463:            }
464:
465:            /**
466:             * @todo This code is dublicated with BpmServiceImpl - need to be refactored
467:             * @return
468:             */
469:            private Role getAssignedRole(StepTO i_step) {
470:                // Is task owner - role name?
471:                Role role = userFactory.getRole(i_step.getActor());
472:                return role;
473:            }
474:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.