KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > WfAssignmentIteratorWrapper


1 package org.enhydra.shark;
2
3 import java.util.*;
4
5 import org.enhydra.shark.api.RootException;
6 import org.enhydra.shark.api.SharkTransaction;
7 import org.enhydra.shark.api.client.wfbase.BaseException;
8 import org.enhydra.shark.api.client.wfmodel.WfAssignment;
9 import org.enhydra.shark.api.client.wfmodel.WfAssignmentIterator;
10 import org.enhydra.shark.api.common.SharkConstants;
11 import org.enhydra.shark.api.internal.instancepersistence.*;
12 import org.enhydra.shark.api.internal.scripting.Evaluator;
13
14
15 /**
16  * Iterator for assignments of activity.
17  * The following names may be used in queries: processId, resourceUsername,
18  * accepted, packageId, packageVersion, processDefinitionId, activitySetDefinitionId, activityDefinitionId.
19  * @author Sasa Bojanic
20  * @version 1.0
21  */

22 public class WfAssignmentIteratorWrapper extends BaseIteratorWrapper implements WfAssignmentIterator {
23
24    private String JavaDoc procId;
25    private String JavaDoc actId;
26    private String JavaDoc username;
27
28    protected WfAssignmentIteratorWrapper (SharkTransaction t,String JavaDoc userAuth,String JavaDoc procId,String JavaDoc actId) throws BaseException {
29       super(userAuth);
30       this.procId=procId;
31       this.actId=actId;
32    }
33
34    protected WfAssignmentIteratorWrapper (SharkTransaction t,String JavaDoc userAuth,String JavaDoc username) throws BaseException {
35       super(userAuth);
36       this.username=username;
37    }
38
39    public WfAssignment get_next_object () throws BaseException {
40       WfAssignment ret=null;
41       SharkTransaction t = null;
42       try {
43          t = SharkUtilities.createTransaction();
44          ret = get_next_object(t);
45          //SharkUtilities.commitTransaction(t);
46
} catch (RootException e) {
47          //SharkUtilities.rollbackTransaction(t);
48
SharkUtilities.emptyCaches(t);
49          if (e instanceof BaseException)
50             throw (BaseException)e;
51          else
52             throw new BaseException(e);
53       } finally {
54          SharkUtilities.releaseTransaction(t);
55       }
56       return ret;
57    }
58
59    public WfAssignment get_next_object (SharkTransaction t) throws BaseException {
60       return (WfAssignment)super.getNextObject(t);
61    }
62
63    public WfAssignment get_previous_object () throws BaseException {
64       WfAssignment ret=null;
65       SharkTransaction t = null;
66       try {
67          t = SharkUtilities.createTransaction();
68          ret = get_previous_object(t);
69          //SharkUtilities.commitTransaction(t);
70
} catch (RootException e) {
71          //SharkUtilities.rollbackTransaction(t);
72
SharkUtilities.emptyCaches(t);
73          if (e instanceof BaseException)
74             throw (BaseException)e;
75          else
76             throw new BaseException(e);
77       } finally {
78          SharkUtilities.releaseTransaction(t);
79       }
80       return ret;
81    }
82
83    public WfAssignment get_previous_object (SharkTransaction t) throws BaseException {
84       return (WfAssignment)super.getPreviousObject(t);
85    }
86
87    public WfAssignment[] get_next_n_sequence (int max_number) throws BaseException {
88       WfAssignment[] ret=null;
89       SharkTransaction t = null;
90       try {
91          t = SharkUtilities.createTransaction();
92          ret = get_next_n_sequence(t,max_number);
93          //SharkUtilities.commitTransaction(t);
94
} catch (RootException e) {
95          //SharkUtilities.rollbackTransaction(t);
96
SharkUtilities.emptyCaches(t);
97          if (e instanceof BaseException)
98             throw (BaseException)e;
99          else
100             throw new BaseException(e);
101       } finally {
102          SharkUtilities.releaseTransaction(t);
103       }
104       return ret;
105    }
106
107    public WfAssignment[] get_next_n_sequence (SharkTransaction t,int max_number) throws BaseException {
108       List l=super.getNextNSequence(t,max_number);
109       WfAssignment[] ret=new WfAssignment[l.size()];
110       l.toArray(ret);
111       return ret;
112    }
113
114    public WfAssignment[] get_previous_n_sequence (int max_number) throws BaseException {
115       WfAssignment[] ret=null;
116       SharkTransaction t = null;
117       try {
118          t = SharkUtilities.createTransaction();
119          ret = get_previous_n_sequence(t,max_number);
120          //SharkUtilities.commitTransaction(t);
121
} catch (RootException e) {
122          //SharkUtilities.rollbackTransaction(t);
123
SharkUtilities.emptyCaches(t);
124          if (e instanceof BaseException)
125             throw (BaseException)e;
126          else
127             throw new BaseException(e);
128       } finally {
129          SharkUtilities.releaseTransaction(t);
130       }
131       return ret;
132    }
133
134    public WfAssignment[] get_previous_n_sequence (SharkTransaction t,int max_number) throws BaseException {
135       List l=super.getPreviousNSequence(t,max_number);
136       WfAssignment[] ret=new WfAssignment[l.size()];
137       l.toArray(ret);
138       return ret;
139    }
140
141    protected void fillObjectList (SharkTransaction t) throws BaseException {
142       if (objectList!=null) return;
143       try {
144          List assignments=new ArrayList();
145
146          PersistentManagerInterface ipm = SharkEngineManager.getInstance().getInstancePersistenceManager();
147          ActivityPersistenceInterface apo=null;
148          ProcessPersistenceInterface ppo=null;
149          List l=new ArrayList();
150          boolean createNewPOs=true;
151          if (sqlWhere!=null) {
152             l = ipm.getAssignmentsWhere(t, sqlWhere);
153          } else if (username!=null) {
154             l.addAll(ipm.getAllValidAssignmentsForResource(username,t));
155          } else if (procId!=null && actId!=null) {
156             l.addAll(ipm.getAllValidAssignmentsForActivity(actId,t));
157             ppo=ipm.restoreProcess(procId,t);
158             apo=ipm.restoreActivity(actId,t);
159             createNewPOs=false;
160          }
161
162          Evaluator evaluator=SharkEngineManager
163             .getInstance()
164             .getScriptingManager()
165             .getEvaluator(t,queryGrammar);
166          //boolean eval=queryExpression!=null && queryExpression.trim().length()>0;
167
for (int i=0; i<l.size(); i++) {
168             AssignmentPersistenceInterface po=(AssignmentPersistenceInterface)l.get(i);
169             boolean toAdd=true;
170             if (eval) {
171                Map context=new HashMap();
172                context.put(SharkConstants.ASS_PROCESS_ID,po.getProcessId());
173                context.put(SharkConstants.ASS_RESOURCE_USERNAME,po.getResourceUsername());
174                if (createNewPOs) {
175                   ppo=ipm.restoreProcess(po.getProcessId(),t);
176                   apo=ipm.restoreActivity(po.getActivityId(),t);
177                }
178                String JavaDoc mgrName=ppo.getProcessMgrName();
179                String JavaDoc pkgId=SharkUtilities.getProcessMgrPkgId(mgrName);
180                String JavaDoc pDefId=SharkUtilities.getProcessMgrProcDefId(mgrName);
181                String JavaDoc ver=SharkUtilities.getProcessMgrVersion(mgrName);
182                context.put(SharkConstants.ASS_ACCEPTED,new Boolean JavaDoc(apo.getResourceUsername()!=null));
183                context.put(SharkConstants.ASS_PACKAGE_ID,pkgId);
184                context.put(SharkConstants.ASS_PACKAGE_VERSION,ver);
185                context.put(SharkConstants.ASS_PROCESS_DEFINITION_ID,pDefId);
186                context.put(SharkConstants.ASS_ACTIVITY_SET_DEFINITION_ID,apo.getActivitySetDefinitionId());
187                context.put(SharkConstants.ASS_ACTIVITY_DEFINITION_ID,apo.getActivityDefinitionId());
188                context.put(SharkConstants.ASS_ACTIVITY_ID,po.getActivityId());
189                toAdd=evaluator.evaluateCondition(t,queryExpression,context);
190             }
191             if (toAdd) {
192                assignments.add(SharkEngineManager.getInstance().getObjectFactory().createAssignmentWrapper(userAuth,po.getProcessMgrName(),po.getProcessId(),po.getActivityId(),po.getResourceUsername()));
193             }
194
195          }
196          setObjectList(assignments);
197       } catch (Exception JavaDoc ex) {
198          throw new BaseException(ex);
199       }
200    }
201
202 }
203
Popular Tags