Source Code Cross Referenced for WorkflowServices.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » workflow » client » 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 » SourceTap CRM » org.ofbiz.workflow.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: WorkflowServices.java,v 1.1 2003/08/17 09:29:34 ajzeneski Exp $
003:         *
004:         * Copyright (c) 2002 The Open For Business Project - www.ofbiz.org
005:         *
006:         * Permission is hereby granted, free of charge, to any person obtaining a
007:         * copy of this software and associated documentation files (the "Software"),
008:         * to deal in the Software without restriction, including without limitation
009:         * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         * and/or sell copies of the Software, and to permit persons to whom the
011:         * Software is furnished to do so, subject to the following conditions:
012:         *
013:         * The above copyright notice and this permission notice shall be included
014:         * in all copies or substantial portions of the Software.
015:         *
016:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         *
024:         */
025:        package org.ofbiz.workflow.client;
026:
027:        import java.sql.Timestamp;
028:        import java.util.ArrayList;
029:        import java.util.Collection;
030:        import java.util.HashMap;
031:        import java.util.List;
032:        import java.util.Map;
033:
034:        import org.ofbiz.base.util.Debug;
035:        import org.ofbiz.base.util.UtilDateTime;
036:        import org.ofbiz.base.util.UtilMisc;
037:        import org.ofbiz.entity.GenericDelegator;
038:        import org.ofbiz.entity.GenericEntityException;
039:        import org.ofbiz.entity.GenericValue;
040:        import org.ofbiz.entity.condition.EntityExpr;
041:        import org.ofbiz.entity.condition.EntityOperator;
042:        import org.ofbiz.security.Security;
043:        import org.ofbiz.service.DispatchContext;
044:        import org.ofbiz.service.GenericServiceException;
045:        import org.ofbiz.service.LocalDispatcher;
046:        import org.ofbiz.service.ModelService;
047:        import org.ofbiz.workflow.WfException;
048:        import org.ofbiz.workflow.WfFactory;
049:        import org.ofbiz.workflow.WfProcess;
050:
051:        /**
052:         * Workflow Services - 'Services' and 'Workers' for interaction with Workflow API
053:         *
054:         * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
055:         * @version    $Revision: 1.1 $
056:         * @since      2.0
057:         */
058:        public class WorkflowServices {
059:
060:            public static final String module = WorkflowServices.class
061:                    .getName();
062:
063:            // -------------------------------------------------------------------
064:            // Client 'Service' Methods
065:            // -------------------------------------------------------------------
066:
067:            /** Cancel Workflow */
068:            public static Map cancelWorkflow(DispatchContext ctx, Map context) {
069:                Map result = new HashMap();
070:                GenericDelegator delegator = ctx.getDelegator();
071:                Security security = ctx.getSecurity();
072:                String workEffortId = (String) context.get("workEffortId");
073:
074:                // if we passed in an activity id, lets get the process id instead
075:                try {
076:                    GenericValue testObject = delegator.findByPrimaryKey(
077:                            "WorkEffort", UtilMisc.toMap("workEffortId",
078:                                    workEffortId));
079:                    if (testObject == null) {
080:                        result.put(ModelService.RESPONSE_MESSAGE,
081:                                ModelService.RESPOND_ERROR);
082:                        result.put(ModelService.ERROR_MESSAGE,
083:                                "Not a valid workflow runtime identifier");
084:                        return result;
085:                    } else if (testObject.get("workEffortTypeId") != null
086:                            && testObject.getString("workEffortTypeId").equals(
087:                                    "WORK_FLOW")) {
088:                        // we are a valid process - do nothing
089:                    } else if (testObject.get("workEffortTypeId") != null
090:                            && testObject.getString("workEffortTypeId").equals(
091:                                    "ACTIVITY")) {
092:                        // we are a valid activitiy; get the process id
093:                        workEffortId = testObject
094:                                .getString("workEffortParentId");
095:                    } else {
096:                        result.put(ModelService.RESPONSE_MESSAGE,
097:                                ModelService.RESPOND_ERROR);
098:                        result.put(ModelService.ERROR_MESSAGE,
099:                                "Not a valid workflow runtime identifier");
100:                        return result;
101:                    }
102:                } catch (GenericEntityException e) {
103:                    result.put(ModelService.RESPONSE_MESSAGE,
104:                            ModelService.RESPOND_ERROR);
105:                    result.put(ModelService.ERROR_MESSAGE,
106:                            "Problems looking up runtime object; invalid id");
107:                    return result;
108:                }
109:
110:                GenericValue userLogin = (GenericValue) context
111:                        .get("userLogin");
112:
113:                if (!hasPermission(security, workEffortId, userLogin)) {
114:                    result.put(ModelService.RESPONSE_MESSAGE,
115:                            ModelService.RESPOND_ERROR);
116:                    result
117:                            .put(ModelService.ERROR_MESSAGE,
118:                                    "You do not have permission to access this workflow");
119:                    return result;
120:                }
121:                try {
122:                    WfProcess process = WfFactory.getWfProcess(delegator,
123:                            workEffortId);
124:                    process.abort();
125:                } catch (WfException we) {
126:                    we.printStackTrace();
127:                    result.put(ModelService.RESPONSE_MESSAGE,
128:                            ModelService.RESPOND_ERROR);
129:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
130:                }
131:                return result;
132:            }
133:
134:            /** Suspend activity */
135:            public static Map suspendActivity(DispatchContext ctx, Map context) {
136:                Map result = new HashMap();
137:                GenericDelegator delegator = ctx.getDelegator();
138:                Security security = ctx.getSecurity();
139:                String workEffortId = (String) context.get("workEffortId");
140:
141:                GenericValue userLogin = (GenericValue) context
142:                        .get("userLogin");
143:
144:                if (!hasPermission(security, workEffortId, userLogin)) {
145:                    result.put(ModelService.RESPONSE_MESSAGE,
146:                            ModelService.RESPOND_ERROR);
147:                    result
148:                            .put(ModelService.ERROR_MESSAGE,
149:                                    "You do not have permission to access this activity");
150:                    return result;
151:                }
152:                try {
153:                    WorkflowClient client = WfFactory.getClient(ctx);
154:                    client.suspend(workEffortId);
155:                    result.put(ModelService.RESPONSE_MESSAGE,
156:                            ModelService.RESPOND_SUCCESS);
157:                } catch (WfException we) {
158:                    we.printStackTrace();
159:                    result.put(ModelService.RESPONSE_MESSAGE,
160:                            ModelService.RESPOND_ERROR);
161:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
162:                }
163:                return result;
164:            }
165:
166:            /** Resume activity */
167:            public static Map resumeActivity(DispatchContext ctx, Map context) {
168:                Map result = new HashMap();
169:                GenericDelegator delegator = ctx.getDelegator();
170:                Security security = ctx.getSecurity();
171:                String workEffortId = (String) context.get("workEffortId");
172:
173:                GenericValue userLogin = (GenericValue) context
174:                        .get("userLogin");
175:
176:                if (!hasPermission(security, workEffortId, userLogin)) {
177:                    result.put(ModelService.RESPONSE_MESSAGE,
178:                            ModelService.RESPOND_ERROR);
179:                    result
180:                            .put(ModelService.ERROR_MESSAGE,
181:                                    "You do not have permission to access this activity");
182:                    return result;
183:                }
184:                try {
185:                    WorkflowClient client = WfFactory.getClient(ctx);
186:                    client.resume(workEffortId);
187:                    result.put(ModelService.RESPONSE_MESSAGE,
188:                            ModelService.RESPOND_SUCCESS);
189:                } catch (WfException we) {
190:                    we.printStackTrace();
191:                    result.put(ModelService.RESPONSE_MESSAGE,
192:                            ModelService.RESPOND_ERROR);
193:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
194:                }
195:                return result;
196:            }
197:
198:            /** Change the state of an activity */
199:            public static Map changeActivityState(DispatchContext ctx,
200:                    Map context) {
201:                Map result = new HashMap();
202:                GenericDelegator delegator = ctx.getDelegator();
203:                Security security = ctx.getSecurity();
204:                String workEffortId = (String) context.get("workEffortId");
205:                String newState = (String) context.get("newState");
206:
207:                GenericValue userLogin = (GenericValue) context
208:                        .get("userLogin");
209:
210:                if (!hasPermission(security, workEffortId, userLogin)) {
211:                    result.put(ModelService.RESPONSE_MESSAGE,
212:                            ModelService.RESPOND_ERROR);
213:                    result
214:                            .put(ModelService.ERROR_MESSAGE,
215:                                    "You do not have permission to access this activity");
216:                    return result;
217:                }
218:                try {
219:                    WorkflowClient client = WfFactory.getClient(ctx);
220:                    client.setState(workEffortId, newState);
221:                    result.put(ModelService.RESPONSE_MESSAGE,
222:                            ModelService.RESPOND_SUCCESS);
223:                } catch (WfException we) {
224:                    we.printStackTrace();
225:                    result.put(ModelService.RESPONSE_MESSAGE,
226:                            ModelService.RESPOND_ERROR);
227:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
228:                }
229:                return result;
230:            }
231:
232:            /** Check the state of an activity */
233:            public static Map checkActivityState(DispatchContext ctx,
234:                    Map context) {
235:                Map result = new HashMap();
236:                GenericDelegator delegator = ctx.getDelegator();
237:                Security security = ctx.getSecurity();
238:                String workEffortId = (String) context.get("workEffortId");
239:
240:                try {
241:                    WorkflowClient client = WfFactory.getClient(ctx);
242:                    result.put("activityState", client.getState(workEffortId));
243:                    result.put(ModelService.RESPONSE_MESSAGE,
244:                            ModelService.RESPOND_SUCCESS);
245:                } catch (WfException we) {
246:                    we.printStackTrace();
247:                    result.put(ModelService.RESPONSE_MESSAGE,
248:                            ModelService.RESPOND_ERROR);
249:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
250:                }
251:                return result;
252:            }
253:
254:            /** Get the current activity context */
255:            public static Map getActivityContext(DispatchContext ctx,
256:                    Map context) {
257:                Map result = new HashMap();
258:                GenericDelegator delegator = ctx.getDelegator();
259:                Security security = ctx.getSecurity();
260:                String workEffortId = (String) context.get("workEffortId");
261:
262:                try {
263:                    WorkflowClient client = WfFactory.getClient(ctx);
264:                    result.put("activityContext", client
265:                            .getContext(workEffortId));
266:                    result.put(ModelService.RESPONSE_MESSAGE,
267:                            ModelService.RESPOND_SUCCESS);
268:                } catch (WfException we) {
269:                    we.printStackTrace();
270:                    result.put(ModelService.RESPONSE_MESSAGE,
271:                            ModelService.RESPOND_ERROR);
272:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
273:                }
274:                return result;
275:            }
276:
277:            /** Appends data to the activity context */
278:            public static Map appendActivityContext(DispatchContext ctx,
279:                    Map context) {
280:                Map result = new HashMap();
281:                GenericDelegator delegator = ctx.getDelegator();
282:                Security security = ctx.getSecurity();
283:                String workEffortId = (String) context.get("workEffortId");
284:                Map appendContext = (Map) context.get("currentContext");
285:
286:                if (appendContext == null || appendContext.size() == 0) {
287:                    result.put(ModelService.RESPONSE_MESSAGE,
288:                            ModelService.RESPOND_ERROR);
289:                    result.put(ModelService.ERROR_MESSAGE,
290:                            "The passed context is empty");
291:                }
292:
293:                GenericValue userLogin = (GenericValue) context
294:                        .get("userLogin");
295:
296:                if (!hasPermission(security, workEffortId, userLogin)) {
297:                    result.put(ModelService.RESPONSE_MESSAGE,
298:                            ModelService.RESPOND_ERROR);
299:                    result
300:                            .put(ModelService.ERROR_MESSAGE,
301:                                    "You do not have permission to access this activity");
302:                    return result;
303:                }
304:                try {
305:                    WorkflowClient client = WfFactory.getClient(ctx);
306:                    client.appendContext(workEffortId, appendContext);
307:                    result.put(ModelService.RESPONSE_MESSAGE,
308:                            ModelService.RESPOND_SUCCESS);
309:                } catch (WfException we) {
310:                    we.printStackTrace();
311:                    result.put(ModelService.RESPONSE_MESSAGE,
312:                            ModelService.RESPOND_ERROR);
313:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
314:                }
315:                return result;
316:            }
317:
318:            /** Assign activity to a new or additional party */
319:            public static Map assignActivity(DispatchContext ctx, Map context) {
320:                Map result = new HashMap();
321:                GenericDelegator delegator = ctx.getDelegator();
322:                Security security = ctx.getSecurity();
323:                String workEffortId = (String) context.get("workEffortId");
324:                String partyId = (String) context.get("partyId");
325:                String roleType = (String) context.get("roleTypeId");
326:                boolean removeOldAssign = false;
327:
328:                if (context.containsKey("removeOldAssignments")) {
329:                    removeOldAssign = ((String) context
330:                            .get("removeOldAssignments")).equals("true") ? true
331:                            : false;
332:                }
333:
334:                GenericValue userLogin = (GenericValue) context
335:                        .get("userLogin");
336:
337:                if (!hasPermission(security, workEffortId, userLogin)) {
338:                    result.put(ModelService.RESPONSE_MESSAGE,
339:                            ModelService.RESPOND_ERROR);
340:                    result
341:                            .put(ModelService.ERROR_MESSAGE,
342:                                    "You do not have permission to access this activity");
343:                    return result;
344:                }
345:                try {
346:                    WorkflowClient client = WfFactory.getClient(ctx);
347:                    client.assign(workEffortId, partyId, roleType, null,
348:                            removeOldAssign ? false : true);
349:                    result.put(ModelService.RESPONSE_MESSAGE,
350:                            ModelService.RESPOND_SUCCESS);
351:                } catch (WfException we) {
352:                    we.printStackTrace();
353:                    result.put(ModelService.RESPONSE_MESSAGE,
354:                            ModelService.RESPOND_ERROR);
355:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
356:                }
357:                return result;
358:            }
359:
360:            /** Accept an assignment and attempt to start the activity */
361:            public static Map acceptAssignment(DispatchContext ctx, Map context) {
362:                Map result = new HashMap();
363:                String workEffortId = (String) context.get("workEffortId");
364:                String partyId = (String) context.get("partyId");
365:                String roleType = (String) context.get("roleTypeId");
366:                Timestamp fromDate = (Timestamp) context.get("fromDate");
367:
368:                try {
369:                    WorkflowClient client = WfFactory.getClient(ctx);
370:                    client.acceptAndStart(workEffortId, partyId, roleType,
371:                            fromDate);
372:                    result.put(ModelService.RESPONSE_MESSAGE,
373:                            ModelService.RESPOND_SUCCESS);
374:                } catch (WfException we) {
375:                    we.printStackTrace();
376:                    result.put(ModelService.RESPONSE_MESSAGE,
377:                            ModelService.RESPOND_ERROR);
378:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
379:                }
380:                return result;
381:
382:            }
383:
384:            /** Delegate an assignment */
385:            public static Map delegateAssignment(DispatchContext ctx,
386:                    Map context) {
387:                Map result = new HashMap();
388:                String workEffortId = (String) context.get("workEffortId");
389:                String fromParty = (String) context.get("fromPartyId");
390:                String fromRole = (String) context.get("fromRoleTypeId");
391:                Timestamp fromFromDate = (Timestamp) context
392:                        .get("fromFromDate");
393:                String toParty = (String) context.get("toPartyId");
394:                String toRole = (String) context.get("toRoleTypeId");
395:                Timestamp toFromDate = (Timestamp) context.get("toFromDate");
396:
397:                // optional fromDate (default now)
398:                if (toFromDate == null)
399:                    toFromDate = UtilDateTime.nowTimestamp();
400:
401:                try {
402:                    WorkflowClient client = new WorkflowClient(ctx);
403:                    client.delegate(workEffortId, fromParty, fromRole,
404:                            fromFromDate, toParty, toRole, toFromDate);
405:                    result.put(ModelService.RESPONSE_MESSAGE,
406:                            ModelService.RESPOND_SUCCESS);
407:                } catch (WfException we) {
408:                    we.printStackTrace();
409:                    result.put(ModelService.RESPONSE_MESSAGE,
410:                            ModelService.RESPOND_ERROR);
411:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
412:                }
413:                return result;
414:            }
415:
416:            /** Delegate, accept an assignment */
417:            public static Map delegateAcceptAssignment(DispatchContext ctx,
418:                    Map context) {
419:                Map result = new HashMap();
420:                String workEffortId = (String) context.get("workEffortId");
421:                String fromParty = (String) context.get("fromPartyId");
422:                String fromRole = (String) context.get("fromRoleTypeId");
423:                Timestamp fromFromDate = (Timestamp) context
424:                        .get("fromFromDate");
425:                String toParty = (String) context.get("toPartyId");
426:                String toRole = (String) context.get("toRoleTypeId");
427:                Timestamp toFromDate = (Timestamp) context.get("toFromDate");
428:                Boolean startObj = (Boolean) context.get("startActivity");
429:
430:                // optional start activity (default false)
431:                boolean start = false;
432:                if (startObj != null)
433:                    start = startObj.booleanValue();
434:
435:                // optional fromDate (default now)
436:                if (toFromDate == null)
437:                    toFromDate = UtilDateTime.nowTimestamp();
438:
439:                try {
440:                    WorkflowClient client = new WorkflowClient(ctx);
441:                    client.delegateAndAccept(workEffortId, fromParty, fromRole,
442:                            fromFromDate, toParty, toRole, toFromDate, start);
443:                    result.put(ModelService.RESPONSE_MESSAGE,
444:                            ModelService.RESPOND_SUCCESS);
445:                } catch (WfException we) {
446:                    we.printStackTrace();
447:                    result.put(ModelService.RESPONSE_MESSAGE,
448:                            ModelService.RESPOND_ERROR);
449:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
450:                }
451:                return result;
452:            }
453:
454:            /** Accept a role assignment and attempt to start the activity */
455:            public static Map acceptRoleAssignment(DispatchContext ctx,
456:                    Map context) {
457:                Map result = new HashMap();
458:                String workEffortId = (String) context.get("workEffortId");
459:                String partyId = (String) context.get("partyId");
460:                String roleType = (String) context.get("roleTypeId");
461:                Timestamp fromDate = (Timestamp) context.get("fromDate");
462:
463:                try {
464:                    WorkflowClient client = new WorkflowClient(ctx);
465:                    client.delegateAndAccept(workEffortId, "_NA_", roleType,
466:                            fromDate, partyId, roleType, fromDate, true);
467:                    result.put(ModelService.RESPONSE_MESSAGE,
468:                            ModelService.RESPOND_SUCCESS);
469:                } catch (WfException we) {
470:                    we.printStackTrace();
471:                    result.put(ModelService.RESPONSE_MESSAGE,
472:                            ModelService.RESPOND_ERROR);
473:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
474:                }
475:                return result;
476:            }
477:
478:            /** Complete an assignment */
479:            public static Map completeAssignment(DispatchContext ctx,
480:                    Map context) {
481:                Map result = new HashMap();
482:                GenericDelegator delegator = ctx.getDelegator();
483:                Security security = ctx.getSecurity();
484:                String workEffortId = (String) context.get("workEffortId");
485:                String partyId = (String) context.get("partyId");
486:                String roleType = (String) context.get("roleTypeId");
487:                Timestamp fromDate = (Timestamp) context.get("fromDate");
488:                Map actResults = (Map) context.get("result");
489:
490:                GenericValue userLogin = (GenericValue) context
491:                        .get("userLogin");
492:
493:                if (!hasPermission(security, workEffortId, userLogin)) {
494:                    result.put(ModelService.RESPONSE_MESSAGE,
495:                            ModelService.RESPOND_ERROR);
496:                    result
497:                            .put(ModelService.ERROR_MESSAGE,
498:                                    "You do not have permission to access this assignment");
499:                    return result;
500:                }
501:
502:                try {
503:                    WorkflowClient client = WfFactory.getClient(ctx);
504:                    client.complete(workEffortId, partyId, roleType, fromDate,
505:                            actResults);
506:                    result.put(ModelService.RESPONSE_MESSAGE,
507:                            ModelService.RESPOND_SUCCESS);
508:                } catch (WfException we) {
509:                    we.printStackTrace();
510:                    result.put(ModelService.RESPONSE_MESSAGE,
511:                            ModelService.RESPOND_ERROR);
512:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
513:                }
514:                return result;
515:            }
516:
517:            public static Map limitInvoker(DispatchContext ctx, Map context) {
518:                Map result = new HashMap();
519:                GenericDelegator delegator = ctx.getDelegator();
520:                LocalDispatcher dispatcher = ctx.getDispatcher();
521:                String workEffortId = (String) context.get("workEffortId");
522:                String limitService = (String) context.get("serviceName");
523:                Map limitContext = (Map) context.get("serviceContext");
524:
525:                try {
526:                    WorkflowClient client = WfFactory.getClient(ctx);
527:                    String state = client.getState(workEffortId);
528:
529:                    if (state.startsWith("open")) {
530:                        dispatcher.runSync(limitService, limitContext);
531:                    }
532:                    result.put(ModelService.RESPONSE_MESSAGE,
533:                            ModelService.RESPOND_SUCCESS);
534:                } catch (WfException we) {
535:                    result.put(ModelService.RESPONSE_MESSAGE,
536:                            ModelService.RESPOND_ERROR);
537:                    result.put(ModelService.ERROR_MESSAGE, we.getMessage());
538:                } catch (GenericServiceException se) {
539:                    result.put(ModelService.RESPONSE_MESSAGE,
540:                            ModelService.RESPOND_ERROR);
541:                    result.put(ModelService.ERROR_MESSAGE, se.getMessage());
542:                }
543:                return result;
544:            }
545:
546:            // -------------------------------------------------------------------
547:            // Service 'Worker' Methods
548:            // -------------------------------------------------------------------
549:
550:            /**
551:             * Checks if a user has permission to access workflow data.
552:             */
553:            public static boolean hasPermission(Security security,
554:                    String workEffortId, GenericValue userLogin) {
555:                if (userLogin == null || workEffortId == null) {
556:                    Debug
557:                            .logWarning(
558:                                    "No UserLogin object or no Workeffort ID was passed.",
559:                                    module);
560:                    return false;
561:                }
562:                if (security.hasPermission("WORKFLOW_MAINT", userLogin)) {
563:                    return true;
564:                } else {
565:                    String partyId = userLogin.getString("partyId");
566:                    List expr = new ArrayList();
567:
568:                    expr.add(new EntityExpr("partyId", EntityOperator.EQUALS,
569:                            partyId));
570:                    expr.add(new EntityExpr("statusId",
571:                            EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
572:                    expr.add(new EntityExpr("statusId",
573:                            EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
574:                    expr.add(new EntityExpr("statusId",
575:                            EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
576:                    expr.add(new EntityExpr("statusId",
577:                            EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
578:                    expr.add(new EntityExpr("workEffortId",
579:                            EntityOperator.EQUALS, workEffortId));
580:                    expr.add(new EntityExpr("fromDate",
581:                            EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime
582:                                    .nowTimestamp()));
583:
584:                    Collection c = null;
585:
586:                    try {
587:                        c = userLogin.getDelegator().findByAnd(
588:                                "WorkEffortAndPartyAssign", expr);
589:                        //Debug.logInfo("Found " + c.size() + " records.", module);
590:                    } catch (GenericEntityException e) {
591:                        Debug.logWarning(e, module);
592:                        return false;
593:                    }
594:                    if (c.size() == 0) {
595:                        expr = new ArrayList();
596:                        expr.add(new EntityExpr("partyId",
597:                                EntityOperator.EQUALS, partyId));
598:                        expr.add(new EntityExpr("statusId",
599:                                EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
600:                        expr.add(new EntityExpr("statusId",
601:                                EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
602:                        expr.add(new EntityExpr("statusId",
603:                                EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
604:                        expr.add(new EntityExpr("statusId",
605:                                EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
606:                        expr.add(new EntityExpr("workEffortParentId",
607:                                EntityOperator.EQUALS, workEffortId));
608:                        expr.add(new EntityExpr("fromDate",
609:                                EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime
610:                                        .nowTimestamp()));
611:                        try {
612:                            c = userLogin.getDelegator().findByAnd(
613:                                    "WorkEffortAndPartyAssign", expr);
614:                            //Debug.logInfo("Found " + c.size() + " records.", module);
615:                        } catch (GenericEntityException e) {
616:                            Debug.logWarning(e, module);
617:                            return false;
618:                        }
619:                    }
620:
621:                    if (c.size() > 0) {
622:                        return true;
623:                    }
624:                }
625:                return false;
626:            }
627:
628:            /**
629:             * Returns the owner of the workflow.
630:             */
631:            public static GenericValue getOwner(GenericDelegator delegator,
632:                    String workEffortId) {
633:                try {
634:                    GenericValue we = delegator.findByPrimaryKey("WorkEffort",
635:                            UtilMisc.toMap("workEffortId", workEffortId));
636:
637:                    if (we != null
638:                            && we.getString("workEffortParentId") == null) {
639:                        Collection c = delegator.findByAnd(
640:                                "WorkEffortPartyAssignment", UtilMisc.toMap(
641:                                        "workEffortId", workEffortId,
642:                                        "roleTypeId", "WF_OWNER"));
643:
644:                        return (GenericValue) c.iterator().next();
645:                    } else {
646:                        return getOwner(delegator, we
647:                                .getString("workEffortParentId"));
648:                    }
649:                } catch (GenericEntityException e) {
650:                    Debug.logWarning(e, module);
651:                }
652:                return null;
653:            }
654:
655:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.