KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > workflow > client > WorkflowServices


1 /*
2  * $Id: WorkflowServices.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.workflow.client;
26
27 import java.sql.Timestamp JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import org.ofbiz.base.util.Debug;
35 import org.ofbiz.base.util.UtilDateTime;
36 import org.ofbiz.base.util.UtilMisc;
37 import org.ofbiz.entity.GenericDelegator;
38 import org.ofbiz.entity.GenericEntityException;
39 import org.ofbiz.entity.GenericValue;
40 import org.ofbiz.entity.condition.EntityExpr;
41 import org.ofbiz.entity.condition.EntityOperator;
42 import org.ofbiz.security.Security;
43 import org.ofbiz.service.DispatchContext;
44 import org.ofbiz.service.GenericServiceException;
45 import org.ofbiz.service.LocalDispatcher;
46 import org.ofbiz.service.ModelService;
47 import org.ofbiz.workflow.WfException;
48 import org.ofbiz.workflow.WfFactory;
49 import org.ofbiz.workflow.WfProcess;
50
51 /**
52  * Workflow Services - 'Services' and 'Workers' for interaction with Workflow API
53  *
54  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
55  * @version $Rev: 5462 $
56  * @since 2.0
57  */

58 public class WorkflowServices {
59     
60     public static final String JavaDoc module = WorkflowServices.class.getName();
61
62     // -------------------------------------------------------------------
63
// Client 'Service' Methods
64
// -------------------------------------------------------------------
65

66     /** Cancel Workflow */
67     public static Map JavaDoc cancelWorkflow(DispatchContext ctx, Map JavaDoc context) {
68         Map JavaDoc result = new HashMap JavaDoc();
69         GenericDelegator delegator = ctx.getDelegator();
70         Security security = ctx.getSecurity();
71         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
72         
73         // if we passed in an activity id, lets get the process id instead
74
try {
75             GenericValue testObject = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));
76             if (testObject == null) {
77                 result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
78                 result.put(ModelService.ERROR_MESSAGE, "Not a valid workflow runtime identifier");
79                 return result;
80             } else if (testObject.get("workEffortTypeId") != null && testObject.getString("workEffortTypeId").equals("WORK_FLOW")) {
81                 // we are a valid process - do nothing
82
} else if (testObject.get("workEffortTypeId") != null && testObject.getString("workEffortTypeId").equals("ACTIVITY")) {
83                 // we are a valid activitiy; get the process id
84
workEffortId = testObject.getString("workEffortParentId");
85             } else {
86                 result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
87                 result.put(ModelService.ERROR_MESSAGE, "Not a valid workflow runtime identifier");
88                 return result;
89             }
90         } catch (GenericEntityException e) {
91             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
92             result.put(ModelService.ERROR_MESSAGE, "Problems looking up runtime object; invalid id");
93             return result;
94         }
95                                 
96         GenericValue userLogin = (GenericValue) context.get("userLogin");
97
98         if (!hasPermission(security, workEffortId, userLogin)) {
99             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
100             result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this workflow");
101             return result;
102         }
103         try {
104             WfProcess process = WfFactory.getWfProcess(delegator, workEffortId);
105             process.abort();
106         } catch (WfException we) {
107             we.printStackTrace();
108             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
109             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
110         }
111         return result;
112     }
113     
114     /** Suspend activity */
115     public static Map JavaDoc suspendActivity(DispatchContext ctx, Map JavaDoc context) {
116         Map JavaDoc result = new HashMap JavaDoc();
117         GenericDelegator delegator = ctx.getDelegator();
118         Security security = ctx.getSecurity();
119         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
120
121         GenericValue userLogin = (GenericValue) context.get("userLogin");
122
123         if (!hasPermission(security, workEffortId, userLogin)) {
124             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
125             result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");
126             return result;
127         }
128         try {
129             WorkflowClient client = WfFactory.getClient(ctx);
130             client.suspend(workEffortId);
131             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
132         } catch (WfException we) {
133             we.printStackTrace();
134             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
135             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
136         }
137         return result;
138     }
139     
140     /** Resume activity */
141     public static Map JavaDoc resumeActivity(DispatchContext ctx, Map JavaDoc context) {
142         Map JavaDoc result = new HashMap JavaDoc();
143         GenericDelegator delegator = ctx.getDelegator();
144         Security security = ctx.getSecurity();
145         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
146
147         GenericValue userLogin = (GenericValue) context.get("userLogin");
148
149         if (!hasPermission(security, workEffortId, userLogin)) {
150             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
151             result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");
152             return result;
153         }
154         try {
155             WorkflowClient client = WfFactory.getClient(ctx);
156             client.resume(workEffortId);
157             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
158         } catch (WfException we) {
159             we.printStackTrace();
160             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
161             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
162         }
163         return result;
164     }
165
166     /** Change the state of an activity */
167     public static Map JavaDoc changeActivityState(DispatchContext ctx, Map JavaDoc context) {
168         Map JavaDoc result = new HashMap JavaDoc();
169         GenericDelegator delegator = ctx.getDelegator();
170         Security security = ctx.getSecurity();
171         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
172         String JavaDoc newState = (String JavaDoc) context.get("newState");
173
174         GenericValue userLogin = (GenericValue) context.get("userLogin");
175
176         if (!hasPermission(security, workEffortId, userLogin)) {
177             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
178             result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");
179             return result;
180         }
181         try {
182             WorkflowClient client = WfFactory.getClient(ctx);
183             client.setState(workEffortId, newState);
184             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
185         } catch (WfException we) {
186             we.printStackTrace();
187             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
188             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
189         }
190         return result;
191     }
192
193     /** Check the state of an activity */
194     public static Map JavaDoc checkActivityState(DispatchContext ctx, Map JavaDoc context) {
195         Map JavaDoc result = new HashMap JavaDoc();
196         GenericDelegator delegator = ctx.getDelegator();
197         Security security = ctx.getSecurity();
198         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
199
200         try {
201             WorkflowClient client = WfFactory.getClient(ctx);
202             result.put("activityState", client.getState(workEffortId));
203             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
204         } catch (WfException we) {
205             we.printStackTrace();
206             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
207             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
208         }
209         return result;
210     }
211
212     /** Get the current activity context */
213     public static Map JavaDoc getActivityContext(DispatchContext ctx, Map JavaDoc context) {
214         Map JavaDoc result = new HashMap JavaDoc();
215         GenericDelegator delegator = ctx.getDelegator();
216         Security security = ctx.getSecurity();
217         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
218
219         try {
220             WorkflowClient client = WfFactory.getClient(ctx);
221             result.put("activityContext", client.getContext(workEffortId));
222             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
223         } catch (WfException we) {
224             we.printStackTrace();
225             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
226             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
227         }
228         return result;
229     }
230
231     /** Appends data to the activity context */
232     public static Map JavaDoc appendActivityContext(DispatchContext ctx, Map JavaDoc context) {
233         Map JavaDoc result = new HashMap JavaDoc();
234         GenericDelegator delegator = ctx.getDelegator();
235         Security security = ctx.getSecurity();
236         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
237         Map JavaDoc appendContext = (Map JavaDoc) context.get("currentContext");
238
239         if (appendContext == null || appendContext.size() == 0) {
240             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
241             result.put(ModelService.ERROR_MESSAGE, "The passed context is empty");
242         }
243
244         GenericValue userLogin = (GenericValue) context.get("userLogin");
245
246         if (!hasPermission(security, workEffortId, userLogin)) {
247             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
248             result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");
249             return result;
250         }
251         try {
252             WorkflowClient client = WfFactory.getClient(ctx);
253             client.appendContext(workEffortId, appendContext);
254             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
255         } catch (WfException we) {
256             we.printStackTrace();
257             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
258             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
259         }
260         return result;
261     }
262
263     /** Assign activity to a new or additional party */
264     public static Map JavaDoc assignActivity(DispatchContext ctx, Map JavaDoc context) {
265         Map JavaDoc result = new HashMap JavaDoc();
266         GenericDelegator delegator = ctx.getDelegator();
267         Security security = ctx.getSecurity();
268         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
269         String JavaDoc partyId = (String JavaDoc) context.get("partyId");
270         String JavaDoc roleType = (String JavaDoc) context.get("roleTypeId");
271         boolean removeOldAssign = false;
272
273         if (context.containsKey("removeOldAssignments")) {
274             removeOldAssign = ((String JavaDoc) context.get("removeOldAssignments")).equals("true") ? true : false;
275         }
276
277         GenericValue userLogin = (GenericValue) context.get("userLogin");
278
279         if (!hasPermission(security, workEffortId, userLogin)) {
280             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
281             result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");
282             return result;
283         }
284         try {
285             WorkflowClient client = WfFactory.getClient(ctx);
286             client.assign(workEffortId, partyId, roleType, null, removeOldAssign ? false : true);
287             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
288         } catch (WfException we) {
289             we.printStackTrace();
290             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
291             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
292         }
293         return result;
294     }
295
296     /** Accept an assignment and attempt to start the activity */
297     public static Map JavaDoc acceptAssignment(DispatchContext ctx, Map JavaDoc context) {
298         Map JavaDoc result = new HashMap JavaDoc();
299         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
300         String JavaDoc partyId = (String JavaDoc) context.get("partyId");
301         String JavaDoc roleType = (String JavaDoc) context.get("roleTypeId");
302         Timestamp JavaDoc fromDate = (Timestamp JavaDoc) context.get("fromDate");
303  
304         try {
305             WorkflowClient client = WfFactory.getClient(ctx);
306             client.acceptAndStart(workEffortId, partyId, roleType, fromDate);
307             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
308         } catch (WfException we) {
309             we.printStackTrace();
310             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
311             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
312         }
313         return result;
314
315     }
316     
317     /** Delegate an assignment */
318     public static Map JavaDoc delegateAssignment(DispatchContext ctx, Map JavaDoc context) {
319         Map JavaDoc result = new HashMap JavaDoc();
320         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
321         String JavaDoc fromParty = (String JavaDoc) context.get("fromPartyId");
322         String JavaDoc fromRole = (String JavaDoc) context.get("fromRoleTypeId");
323         Timestamp JavaDoc fromFromDate = (Timestamp JavaDoc) context.get("fromFromDate");
324         String JavaDoc toParty = (String JavaDoc) context.get("toPartyId");
325         String JavaDoc toRole = (String JavaDoc) context.get("toRoleTypeId");
326         Timestamp JavaDoc toFromDate = (Timestamp JavaDoc) context.get("toFromDate");
327        
328         // optional fromDate (default now)
329
if (toFromDate == null)
330             toFromDate = UtilDateTime.nowTimestamp();
331
332         try {
333             WorkflowClient client = new WorkflowClient(ctx);
334             client.delegate(workEffortId, fromParty, fromRole, fromFromDate, toParty, toRole, toFromDate);
335             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
336         } catch (WfException we) {
337              we.printStackTrace();
338              result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
339              result.put(ModelService.ERROR_MESSAGE, we.getMessage());
340         }
341         return result;
342     }
343     
344     /** Delegate, accept an assignment */
345     public static Map JavaDoc delegateAcceptAssignment(DispatchContext ctx, Map JavaDoc context) {
346         Map JavaDoc result = new HashMap JavaDoc();
347         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
348         String JavaDoc fromParty = (String JavaDoc) context.get("fromPartyId");
349         String JavaDoc fromRole = (String JavaDoc) context.get("fromRoleTypeId");
350         Timestamp JavaDoc fromFromDate = (Timestamp JavaDoc) context.get("fromFromDate");
351         String JavaDoc toParty = (String JavaDoc) context.get("toPartyId");
352         String JavaDoc toRole = (String JavaDoc) context.get("toRoleTypeId");
353         Timestamp JavaDoc toFromDate = (Timestamp JavaDoc) context.get("toFromDate");
354         Boolean JavaDoc startObj = (Boolean JavaDoc) context.get("startActivity");
355         
356         // optional start activity (default false)
357
boolean start = false;
358         if (startObj != null)
359             start = startObj.booleanValue();
360         
361         // optional fromDate (default now)
362
if (toFromDate == null)
363             toFromDate = UtilDateTime.nowTimestamp();
364                   
365         try {
366             WorkflowClient client = new WorkflowClient(ctx);
367             client.delegateAndAccept(workEffortId, fromParty, fromRole, fromFromDate, toParty, toRole, toFromDate, start);
368             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
369         } catch (WfException we) {
370              we.printStackTrace();
371              result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
372              result.put(ModelService.ERROR_MESSAGE, we.getMessage());
373         }
374         return result;
375     }
376         
377     /** Accept a role assignment and attempt to start the activity */
378     public static Map JavaDoc acceptRoleAssignment(DispatchContext ctx, Map JavaDoc context) {
379         Map JavaDoc result = new HashMap JavaDoc();
380         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
381         String JavaDoc partyId = (String JavaDoc) context.get("partyId");
382         String JavaDoc roleType = (String JavaDoc) context.get("roleTypeId");
383         Timestamp JavaDoc fromDate = (Timestamp JavaDoc) context.get("fromDate");
384         
385         try {
386             WorkflowClient client = new WorkflowClient(ctx);
387             client.delegateAndAccept(workEffortId, "_NA_", roleType, fromDate, partyId, roleType, fromDate, true);
388             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
389         } catch (WfException we) {
390             we.printStackTrace();
391             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
392             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
393         }
394         return result;
395     }
396
397     /** Complete an assignment */
398     public static Map JavaDoc completeAssignment(DispatchContext ctx, Map JavaDoc context) {
399         Map JavaDoc result = new HashMap JavaDoc();
400         GenericDelegator delegator = ctx.getDelegator();
401         Security security = ctx.getSecurity();
402         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
403         String JavaDoc partyId = (String JavaDoc) context.get("partyId");
404         String JavaDoc roleType = (String JavaDoc) context.get("roleTypeId");
405         Timestamp JavaDoc fromDate = (Timestamp JavaDoc) context.get("fromDate");
406         Map JavaDoc actResults = (Map JavaDoc) context.get("result");
407
408         GenericValue userLogin = (GenericValue) context.get("userLogin");
409
410         if (!hasPermission(security, workEffortId, userLogin)) {
411             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
412             result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this assignment");
413             return result;
414         }
415      
416         try {
417             WorkflowClient client = WfFactory.getClient(ctx);
418             client.complete(workEffortId, partyId, roleType, fromDate, actResults);
419             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
420         } catch (WfException we) {
421             we.printStackTrace();
422             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
423             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
424         }
425         return result;
426     }
427
428     public static Map JavaDoc limitInvoker(DispatchContext ctx, Map JavaDoc context) {
429         Map JavaDoc result = new HashMap JavaDoc();
430         GenericDelegator delegator = ctx.getDelegator();
431         LocalDispatcher dispatcher = ctx.getDispatcher();
432         String JavaDoc workEffortId = (String JavaDoc) context.get("workEffortId");
433         String JavaDoc limitService = (String JavaDoc) context.get("serviceName");
434         Map JavaDoc limitContext = (Map JavaDoc) context.get("serviceContext");
435
436         try {
437             WorkflowClient client = WfFactory.getClient(ctx);
438             String JavaDoc state = client.getState(workEffortId);
439
440             if (state.startsWith("open")) {
441                 dispatcher.runSync(limitService, limitContext);
442             }
443             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
444         } catch (WfException we) {
445             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
446             result.put(ModelService.ERROR_MESSAGE, we.getMessage());
447         } catch (GenericServiceException se) {
448             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
449             result.put(ModelService.ERROR_MESSAGE, se.getMessage());
450         }
451         return result;
452     }
453
454     // -------------------------------------------------------------------
455
// Service 'Worker' Methods
456
// -------------------------------------------------------------------
457

458     /**
459      * Checks if a user has permission to access workflow data.
460      */

461     public static boolean hasPermission(Security security, String JavaDoc workEffortId, GenericValue userLogin) {
462         if (userLogin == null || workEffortId == null) {
463             Debug.logWarning("No UserLogin object or no Workeffort ID was passed.", module);
464             return false;
465         }
466         if (security.hasPermission("WORKFLOW_MAINT", userLogin)) {
467             return true;
468         } else {
469             String JavaDoc partyId = userLogin.getString("partyId");
470             List JavaDoc expr = new ArrayList JavaDoc();
471
472             expr.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
473             expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
474             expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
475             expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
476             expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
477             expr.add(new EntityExpr("workEffortId", EntityOperator.EQUALS, workEffortId));
478             expr.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime.nowTimestamp()));
479
480             Collection JavaDoc c = null;
481
482             try {
483                 c = userLogin.getDelegator().findByAnd("WorkEffortAndPartyAssign", expr);
484                 //Debug.logInfo("Found " + c.size() + " records.", module);
485
} catch (GenericEntityException e) {
486                 Debug.logWarning(e, module);
487                 return false;
488             }
489             if (c.size() == 0) {
490                 expr = new ArrayList JavaDoc();
491                 expr.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
492                 expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
493                 expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
494                 expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
495                 expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
496                 expr.add(new EntityExpr("workEffortParentId", EntityOperator.EQUALS, workEffortId));
497                 expr.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime.nowTimestamp()));
498                 try {
499                     c = userLogin.getDelegator().findByAnd("WorkEffortAndPartyAssign", expr);
500                     //Debug.logInfo("Found " + c.size() + " records.", module);
501
} catch (GenericEntityException e) {
502                     Debug.logWarning(e, module);
503                     return false;
504                 }
505             }
506
507             if (c.size() > 0) {
508                 return true;
509             }
510         }
511         return false;
512     }
513
514     /**
515      * Returns the owner of the workflow.
516      */

517     public static GenericValue getOwner(GenericDelegator delegator, String JavaDoc workEffortId) {
518         try {
519             GenericValue we = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));
520
521             if (we != null && we.getString("workEffortParentId") == null) {
522                 Collection JavaDoc c = delegator.findByAnd("WorkEffortPartyAssignment",
523                         UtilMisc.toMap("workEffortId", workEffortId, "roleTypeId", "WF_OWNER"));
524
525                 return (GenericValue) c.iterator().next();
526             } else {
527                 return getOwner(delegator, we.getString("workEffortParentId"));
528             }
529         } catch (GenericEntityException e) {
530             Debug.logWarning(e, module);
531         }
532         return null;
533     }
534
535 }
536
537
Popular Tags