KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.*;
6 import java.util.Map JavaDoc;
7 import org.enhydra.shark.api.RootException;
8 import org.enhydra.shark.api.SharkTransaction;
9 import org.enhydra.shark.api.client.wfbase.BaseException;
10 import org.enhydra.shark.api.client.wfmodel.WfEventAudit;
11 import org.enhydra.shark.api.client.wfmodel.WfEventAuditIterator;
12 import org.enhydra.shark.api.common.SharkConstants;
13 import org.enhydra.shark.api.internal.scripting.Evaluator;
14 import org.enhydra.shark.api.internal.working.WfEventAuditInternal;
15 import org.enhydra.shark.api.internal.eventaudit.*;
16
17
18 /**
19  * Iterator for event audits of activity or the process.
20  * The following names may be used: time_stamp, event_type, activity_key,
21  * activity_name, process_key, process_name, process_mgr_name, process_mgr_version,
22  * package_id, process_definition_id, activity_set_definition_id,
23  * activity_definition_id that will be applied for all event types.
24  * <p> Here are the list of attributes that if specified will be applied
25  * to specific event type:
26  * <p> WfCreateProcessEventAudit: p_activity_key, p_process_key, p_process_name,
27  * p_process_mgr_name, p_process_mgr_version, p_package_id, p_process_definition_id,
28  * p_activity_set_definition_id and p_activity_definition_id
29  * <p> WfDataEventAudit: old_data_varId and new_data_varId, where varId is the
30  * Id of variable from appropriate process/activity
31  * <p> WfStateEventAudit: old_state and new_state
32  * <p> WfAssignmentEventAudit: old_res, new_res and is_accepted
33  * @author Sasa Bojanic
34  */

35 public class WfEventAuditIteratorWrapper extends BaseIteratorWrapper implements WfEventAuditIterator {
36
37    private String JavaDoc procId;
38    private String JavaDoc actId;
39
40    protected WfEventAuditIteratorWrapper (SharkTransaction t,String JavaDoc userAuth,String JavaDoc procId) throws BaseException {
41       super(userAuth);
42       this.procId=procId;
43    }
44
45    protected WfEventAuditIteratorWrapper (SharkTransaction t,String JavaDoc userAuth,String JavaDoc procId,String JavaDoc actId) throws BaseException {
46       super(userAuth);
47       this.procId=procId;
48       this.actId=actId;
49    }
50
51    public WfEventAudit get_next_object () throws BaseException {
52       WfEventAudit ret=null;
53       SharkTransaction t = null;
54       try {
55          t = SharkUtilities.createTransaction();
56          ret = get_next_object(t);
57          //SharkUtilities.commitTransaction(t);
58
} catch (RootException e) {
59          //SharkUtilities.rollbackTransaction(t);
60
SharkUtilities.emptyCaches(t);
61          if (e instanceof BaseException)
62             throw (BaseException)e;
63          else
64             throw new BaseException(e);
65       } finally {
66          SharkUtilities.releaseTransaction(t);
67       }
68       return ret;
69    }
70
71    public WfEventAudit get_next_object (SharkTransaction t) throws BaseException {
72       return (WfEventAudit)super.getNextObject(t);
73    }
74
75
76    public WfEventAudit get_previous_object () throws BaseException {
77       WfEventAudit ret=null;
78       SharkTransaction t = null;
79       try {
80          t = SharkUtilities.createTransaction();
81          ret = get_previous_object(t);
82          //SharkUtilities.commitTransaction(t);
83
} catch (RootException e) {
84          //SharkUtilities.rollbackTransaction(t);
85
SharkUtilities.emptyCaches(t);
86          if (e instanceof BaseException)
87             throw (BaseException)e;
88          else
89             throw new BaseException(e);
90       } finally {
91          SharkUtilities.releaseTransaction(t);
92       }
93       return ret;
94    }
95
96    public WfEventAudit get_previous_object (SharkTransaction t) throws BaseException {
97       return (WfEventAudit)super.getPreviousObject(t);
98    }
99
100    public WfEventAudit[] get_next_n_sequence (int max_number) throws BaseException {
101       WfEventAudit[] ret=null;
102       SharkTransaction t = null;
103       try {
104          t = SharkUtilities.createTransaction();
105          ret = get_next_n_sequence(t,max_number);
106          //SharkUtilities.commitTransaction(t);
107
} catch (RootException e) {
108          //SharkUtilities.rollbackTransaction(t);
109
SharkUtilities.emptyCaches(t);
110          if (e instanceof BaseException)
111             throw (BaseException)e;
112          else
113             throw new BaseException(e);
114       } finally {
115          SharkUtilities.releaseTransaction(t);
116       }
117       return ret;
118    }
119
120    public WfEventAudit[] get_next_n_sequence (SharkTransaction t,int max_number) throws BaseException {
121       List JavaDoc l=super.getNextNSequence(t,max_number);
122       WfEventAudit[] ret=new WfEventAudit[l.size()];
123       l.toArray(ret);
124       return ret;
125    }
126
127    public WfEventAudit[] get_previous_n_sequence (int max_number) throws BaseException {
128       WfEventAudit[] ret=null;
129       SharkTransaction t = null;
130       try {
131          t = SharkUtilities.createTransaction();
132          ret = get_previous_n_sequence(t,max_number);
133          //SharkUtilities.commitTransaction(t);
134
} catch (RootException e) {
135          //SharkUtilities.rollbackTransaction(t);
136
SharkUtilities.emptyCaches(t);
137          if (e instanceof BaseException)
138             throw (BaseException)e;
139          else
140             throw new BaseException(e);
141       } finally {
142          SharkUtilities.releaseTransaction(t);
143       }
144       return ret;
145    }
146
147    public WfEventAudit[] get_previous_n_sequence (SharkTransaction t,int max_number) throws BaseException {
148       List JavaDoc l=super.getPreviousNSequence(t,max_number);
149       WfEventAudit[] ret=new WfEventAudit[l.size()];
150       l.toArray(ret);
151       return ret;
152    }
153
154    protected void fillObjectList (SharkTransaction t) throws BaseException {
155       if (objectList!=null) return;
156       try {
157          List JavaDoc events=new ArrayList JavaDoc();
158
159          EventAuditManagerInterface eam = SharkEngineManager
160             .getInstance()
161             .getEventAuditManager();
162          if (null != eam) {
163             List JavaDoc l=new ArrayList JavaDoc();
164             if (actId==null) {
165                l.addAll(eam.restoreProcessHistory(procId, t));
166             } else {
167                l.addAll(eam.restoreActivityHistory(procId,actId,t));
168             }
169             Evaluator evaluator=SharkEngineManager
170                .getInstance()
171                .getScriptingManager()
172                .getEvaluator(t,queryGrammar);
173
174             boolean eval=queryExpression!=null && queryExpression.trim().length()>0;
175
176             for (int i=0; i<l.size(); i++) {
177                EventAuditPersistenceInterface po=(EventAuditPersistenceInterface)l.get(i);
178                boolean toAdd=true;
179                if (eval) {
180                   Map JavaDoc context=new HashMap JavaDoc();
181                   context.put(SharkConstants.EA_TIME_STAMP,new Long JavaDoc(po.getUTCTime()));
182                   context.put(SharkConstants.EA_EVENT_TYPE,po.getType());
183                   context.put(SharkConstants.EA_ACTIVITY_KEY,po.getActivityId());
184                   context.put(SharkConstants.EA_ACTIVITY_NAME,po.getActivityName());
185                   context.put(SharkConstants.EA_PROCESS_KEY,po.getProcessId());
186                   context.put(SharkConstants.EA_PROCESS_NAME,po.getProcessName());
187                   context.put(SharkConstants.EA_PROCESS_MGR_NAME,po.getProcessDefinitionName());
188                   context.put(SharkConstants.EA_PROCESS_MGR_VERSION,po.getProcessDefinitionVersion());
189                   context.put(SharkConstants.EA_PACKAGE_ID,po.getPackageId());
190                   context.put(SharkConstants.EA_PROCESS_DEFINITION_ID,po.getProcessDefinitionId());
191                   context.put(SharkConstants.EA_ACTIVITY_SET_DEFINITION_ID,po.getActivitySetDefinitionId());
192                   context.put(SharkConstants.EA_ACTIVITY_DEFINITION_ID,po.getActivityDefinitionId());
193
194                   if (po instanceof CreateProcessEventAuditPersistenceInterface) {
195                      CreateProcessEventAuditPersistenceInterface cpo=(CreateProcessEventAuditPersistenceInterface)po;
196                      context.put(SharkConstants.CEA_P_ACTIVITY_KEY,cpo.getPActivityId());
197                      context.put(SharkConstants.CEA_P_PROCESS_KEY,cpo.getPProcessId());
198                      context.put(SharkConstants.CEA_P_PROCESS_NAME,cpo.getPProcessName());
199                      context.put(SharkConstants.CEA_P_PROCESS_MGR_NAME,cpo.getPProcessDefinitionName());
200                      context.put(SharkConstants.CEA_P_PROCESS_MGR_VERSION,cpo.getPProcessDefinitionVersion());
201                      context.put(SharkConstants.CEA_P_PACKAGE_ID,cpo.getPPackageId());
202                      context.put(SharkConstants.CEA_P_PROCESS_DEFINITION_ID,cpo.getPProcessDefinitionId());
203                      context.put(SharkConstants.CEA_P_ACTIVITY_SET_DEFINITION_ID,cpo.getPActivitySetDefinitionId());
204                      context.put(SharkConstants.CEA_P_ACTIVITY_DEFINITION_ID,cpo.getPActivityDefinitionId());
205                   } else if (po instanceof DataEventAuditPersistenceInterface) {
206                      DataEventAuditPersistenceInterface dpo=(DataEventAuditPersistenceInterface)po;
207                      if (queryExpression.indexOf(SharkConstants.DEA_OLD_DATA_)!=-1) {
208                         Map JavaDoc od=dpo.getOldData();
209                         if (od!=null) {
210                            Iterator it=od.entrySet().iterator();
211                            while (it.hasNext()) {
212                               Map.Entry JavaDoc me=(Map.Entry JavaDoc)it.next();
213                               try {
214                                  String JavaDoc name=SharkConstants.DEA_OLD_DATA_+me.getKey().toString();
215                                  Object JavaDoc value=me.getValue();
216                                  context.put(name,value);
217                               } catch (Exception JavaDoc ex) {
218                                  throw new BaseException(ex);
219                               }
220                            }
221                         }
222                      }
223                      if (queryExpression.indexOf(SharkConstants.DEA_NEW_DATA_)!=-1) {
224                         Map JavaDoc nd=dpo.getNewData();
225                         if (nd!=null) {
226                            Iterator it=nd.entrySet().iterator();
227                            while (it.hasNext()) {
228                               Map.Entry JavaDoc me=(Map.Entry JavaDoc)it.next();
229                               try {
230                                  String JavaDoc name=SharkConstants.DEA_NEW_DATA_+me.getKey().toString();
231                                  Object JavaDoc value=me.getValue();
232                                  context.put(name,value);
233                               } catch (Exception JavaDoc ex) {
234                                  throw new BaseException(ex);
235                               }
236                            }
237                         }
238                      }
239
240                   } else if (po instanceof StateEventAuditPersistenceInterface) {
241                      StateEventAuditPersistenceInterface spo=(StateEventAuditPersistenceInterface)po;
242                      context.put(SharkConstants.SEA_OLD_STATE,spo.getOldState());
243                      context.put(SharkConstants.SEA_NEW_STATE,spo.getNewState());
244                   } else if (po instanceof AssignmentEventAuditPersistenceInterface) {
245                      AssignmentEventAuditPersistenceInterface apo=(AssignmentEventAuditPersistenceInterface)po;
246                      context.put(SharkConstants.AEA_OLD_RES,apo.getOldResourceUsername());
247                      context.put(SharkConstants.AEA_NEW_RES,apo.getNewResourceUsername());
248                      context.put(SharkConstants.AEA_IS_ACCEPTED,new Boolean JavaDoc(apo.getIsAccepted()));
249                   }
250
251                   toAdd=evaluator.evaluateCondition(t,queryExpression,context);
252                }
253                if (toAdd) {
254                   if (po instanceof CreateProcessEventAuditPersistenceInterface) {
255                      events.add(SharkEngineManager
256                                    .getInstance()
257                                    .getObjectFactory()
258                                    .createCreateProcessEventAuditWrapper
259                                    (userAuth,(CreateProcessEventAuditPersistenceInterface)po));
260                   } else if (po instanceof DataEventAuditPersistenceInterface) {
261                      events.add(SharkEngineManager
262                                    .getInstance()
263                                    .getObjectFactory()
264                                    .createDataEventAuditWrapper
265                                    (userAuth,(DataEventAuditPersistenceInterface)po));
266                   } else if (po instanceof StateEventAuditPersistenceInterface) {
267                      events.add(SharkEngineManager
268                                    .getInstance()
269                                    .getObjectFactory()
270                                    .createStateEventAuditWrapper
271                                    (userAuth,(StateEventAuditPersistenceInterface)po));
272                   } else if (po instanceof AssignmentEventAuditPersistenceInterface) {
273                      events.add(SharkEngineManager
274                                    .getInstance()
275                                    .getObjectFactory()
276                                    .createAssignmentEventAuditWrapper
277                                    (userAuth,(AssignmentEventAuditPersistenceInterface)po));
278                   }
279                }
280             }
281
282          }
283
284          setObjectList(events);
285       } catch (Exception JavaDoc ex) {
286          throw new BaseException(ex);
287       }
288    }
289
290 }
291
Popular Tags