1 package org.enhydra.shark; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.*; 6 import java.util.Map ; 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 35 public class WfEventAuditIteratorWrapper extends BaseIteratorWrapper implements WfEventAuditIterator { 36 37 private String procId; 38 private String actId; 39 40 protected WfEventAuditIteratorWrapper (SharkTransaction t,String userAuth,String procId) throws BaseException { 41 super(userAuth); 42 this.procId=procId; 43 } 44 45 protected WfEventAuditIteratorWrapper (SharkTransaction t,String userAuth,String procId,String 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 } catch (RootException e) { 59 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 } catch (RootException e) { 84 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 } catch (RootException e) { 108 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 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 } catch (RootException e) { 135 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 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 events=new ArrayList (); 158 159 EventAuditManagerInterface eam = SharkEngineManager 160 .getInstance() 161 .getEventAuditManager(); 162 if (null != eam) { 163 List l=new ArrayList (); 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 context=new HashMap (); 181 context.put(SharkConstants.EA_TIME_STAMP,new Long (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 od=dpo.getOldData(); 209 if (od!=null) { 210 Iterator it=od.entrySet().iterator(); 211 while (it.hasNext()) { 212 Map.Entry me=(Map.Entry )it.next(); 213 try { 214 String name=SharkConstants.DEA_OLD_DATA_+me.getKey().toString(); 215 Object value=me.getValue(); 216 context.put(name,value); 217 } catch (Exception ex) { 218 throw new BaseException(ex); 219 } 220 } 221 } 222 } 223 if (queryExpression.indexOf(SharkConstants.DEA_NEW_DATA_)!=-1) { 224 Map nd=dpo.getNewData(); 225 if (nd!=null) { 226 Iterator it=nd.entrySet().iterator(); 227 while (it.hasNext()) { 228 Map.Entry me=(Map.Entry )it.next(); 229 try { 230 String name=SharkConstants.DEA_NEW_DATA_+me.getKey().toString(); 231 Object value=me.getValue(); 232 context.put(name,value); 233 } catch (Exception 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 (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 ex) { 286 throw new BaseException(ex); 287 } 288 } 289 290 } 291 | Popular Tags |