1 5 package org.ofbiz.shark.audit; 6 7 import java.util.ArrayList ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 11 import org.ofbiz.base.util.Debug; 12 import org.ofbiz.base.util.UtilMisc; 13 import org.ofbiz.entity.GenericDelegator; 14 import org.ofbiz.entity.GenericEntityException; 15 import org.ofbiz.entity.GenericValue; 16 import org.ofbiz.shark.container.SharkContainer; 17 18 import org.enhydra.shark.api.RootException; 19 import org.enhydra.shark.api.SharkTransaction; 20 import org.enhydra.shark.api.internal.eventaudit.AssignmentEventAuditPersistenceInterface; 21 import org.enhydra.shark.api.internal.eventaudit.CreateProcessEventAuditPersistenceInterface; 22 import org.enhydra.shark.api.internal.eventaudit.DataEventAuditPersistenceInterface; 23 import org.enhydra.shark.api.internal.eventaudit.EventAuditException; 24 import org.enhydra.shark.api.internal.eventaudit.EventAuditManagerInterface; 25 import org.enhydra.shark.api.internal.eventaudit.StateEventAuditPersistenceInterface; 26 import org.enhydra.shark.api.internal.working.CallbackUtilities; 27 28 34 public class EntityAuditMgr implements EventAuditManagerInterface { 35 36 public static final String module = EntityAuditMgr.class.getName(); 37 38 protected CallbackUtilities callBackUtil = null; 39 40 public void configure(CallbackUtilities callBackUtil) throws RootException { 41 this.callBackUtil = callBackUtil; 42 } 43 44 public AssignmentEventAuditPersistenceInterface createAssignmentEventAudit() { 46 return new AssignmentEventAudit(this, SharkContainer.getDelegator()); 47 } 48 49 public CreateProcessEventAuditPersistenceInterface createCreateProcessEventAudit() { 50 return new CreateProcessEventAudit(this, SharkContainer.getDelegator()); 51 } 52 53 public DataEventAuditPersistenceInterface createDataEventAudit() { 54 return new DataEventAudit(this, SharkContainer.getDelegator()); 55 } 56 57 public StateEventAuditPersistenceInterface createStateEventAudit() { 58 return new StateEventAudit(this, SharkContainer.getDelegator()); 59 } 60 61 public void persist(AssignmentEventAuditPersistenceInterface assignmentEvent, SharkTransaction trans) throws EventAuditException { 63 try { 64 ((AssignmentEventAudit) assignmentEvent).store(); 65 } catch (GenericEntityException e) { 66 throw new EventAuditException(e); 67 } 68 } 69 70 public void persist(CreateProcessEventAuditPersistenceInterface processEvent, SharkTransaction trans) throws EventAuditException { 71 try { 72 ((CreateProcessEventAudit) processEvent).store(); 73 } catch (GenericEntityException e) { 74 throw new EventAuditException(e); 75 } 76 } 77 78 public void persist(DataEventAuditPersistenceInterface dataEvent, SharkTransaction trans) throws EventAuditException { 79 try { 80 ((DataEventAudit) dataEvent).store(); 81 } catch (GenericEntityException e) { 82 throw new EventAuditException(e); 83 } 84 } 85 86 public void persist(StateEventAuditPersistenceInterface stateEvent, SharkTransaction trans) throws EventAuditException { 87 try { 88 ((StateEventAudit) stateEvent).store(); 89 } catch (GenericEntityException e) { 90 throw new EventAuditException(e); 91 } 92 } 93 94 public boolean restore(AssignmentEventAuditPersistenceInterface assignment, SharkTransaction trans) throws EventAuditException { 96 if (assignment == null) { 97 return false; 98 } 99 return true; 100 } 101 102 public boolean restore(CreateProcessEventAuditPersistenceInterface createProcess, SharkTransaction trans) throws EventAuditException { 103 if (createProcess == null) { 104 return false; 105 } 106 return true; 107 } 108 109 public boolean restore(DataEventAuditPersistenceInterface data, SharkTransaction trans) throws EventAuditException { 110 if (data == null) { 111 return false; 112 } 113 return true; 114 } 115 116 public boolean restore(StateEventAuditPersistenceInterface state, SharkTransaction trans) throws EventAuditException { 117 if (state == null) { 118 return false; 119 } 120 return true; 121 } 122 123 public void delete(AssignmentEventAuditPersistenceInterface assignmentEventAuditPersistenceInterface, SharkTransaction trans) throws EventAuditException { 125 } 127 128 public void delete(CreateProcessEventAuditPersistenceInterface createProcessEventAuditPersistenceInterface, SharkTransaction trans) throws EventAuditException { 129 } 131 132 public void delete(DataEventAuditPersistenceInterface dataEventAuditPersistenceInterface, SharkTransaction trans) throws EventAuditException { 133 } 135 136 public void delete(StateEventAuditPersistenceInterface stateEventAuditPersistenceInterface, SharkTransaction trans) throws EventAuditException { 137 } 139 140 public List restoreProcessHistory(String processId, SharkTransaction trans) throws EventAuditException { 142 List processHistory = new ArrayList (); 143 processHistory.addAll(getCreateProcessEvents(processId)); 144 processHistory.addAll(getProcessDataEvents(processId)); 145 processHistory.addAll(getProcessStateEvents(processId)); 146 if (Debug.verboseOn()) Debug.log(":: restoreProcessHistory :: " + processHistory.size(), module); 147 return processHistory; 148 } 149 150 public List restoreActivityHistory(String processId, String activityId, SharkTransaction trans) throws EventAuditException { 151 if (Debug.verboseOn()) Debug.log(":: restoreActivityHistory ::", module); 152 List activityHistory = new ArrayList (); 153 activityHistory.addAll(getAssignmentEvents(processId, activityId)); 154 activityHistory.addAll(getActivityDataEvents(processId, activityId)); 155 activityHistory.addAll(getActivityStateEvents(processId, activityId)); 156 if (Debug.verboseOn()) Debug.log(":: restoreActivityHistory :: " + activityHistory.size(), module); 157 return activityHistory; 158 } 159 160 private List getCreateProcessEvents(String processId) throws EventAuditException { 162 if (Debug.verboseOn()) Debug.log(":: getCreateProcessEvents ::", module); 163 GenericDelegator delegator = SharkContainer.getDelegator(); 164 List createProcessEvents = new ArrayList (); 165 List lookupList = null; 166 try { 167 lookupList = delegator.findByAnd("WfEventAudit", UtilMisc.toMap("auditType", "processCreated", "processId", processId)); 168 } catch (GenericEntityException e) { 169 Debug.logError(e, module); 170 throw new EventAuditException(e); 171 } 172 if (lookupList != null && lookupList.size() > 0) { 173 Iterator i = lookupList.iterator(); 174 while (i.hasNext()) { 175 GenericValue v = (GenericValue) i.next(); 176 if (v != null) { 177 createProcessEvents.add(new CreateProcessEventAudit(this, delegator, v.getString("eventAuditId"))); 178 } 179 } 180 } 181 return createProcessEvents; 182 } 183 184 private List getProcessStateEvents(String processId) throws EventAuditException { 185 if (Debug.verboseOn()) Debug.log(":: getProcessStateEvents ::", module); 186 GenericDelegator delegator = SharkContainer.getDelegator(); 187 List stateEvents = new ArrayList (); 188 List lookupList = null; 189 try { 190 lookupList = delegator.findByAnd("WfEventAudit", UtilMisc.toMap("auditType", "processStateChanged", "processId", processId)); 191 } catch (GenericEntityException e) { 192 Debug.logError(e, module); 193 throw new EventAuditException(e); 194 } 195 if (lookupList != null && lookupList.size() > 0) { 196 Iterator i = lookupList.iterator(); 197 while (i.hasNext()) { 198 GenericValue v = (GenericValue) i.next(); 199 if (v != null) { 200 stateEvents.add(new StateEventAudit(this, delegator, v.getString("eventAuditId"))); 201 } 202 } 203 } 204 return stateEvents; 205 } 206 207 private List getProcessDataEvents(String processId) throws EventAuditException { 208 if (Debug.verboseOn()) Debug.log(":: getProcessDataEvents ::", module); 209 GenericDelegator delegator = SharkContainer.getDelegator(); 210 List dataEvents = new ArrayList (); 211 List lookupList = null; 212 try { 213 lookupList = delegator.findByAnd("WfEventAudit", UtilMisc.toMap("auditType", "processContextChanged", "processId", processId)); 214 } catch (GenericEntityException e) { 215 Debug.logError(e, module); 216 throw new EventAuditException(e); 217 } 218 if (lookupList != null && lookupList.size() > 0) { 219 Iterator i = lookupList.iterator(); 220 while (i.hasNext()) { 221 GenericValue v = (GenericValue) i.next(); 222 if (v != null) { 223 dataEvents.add(new DataEventAudit(this, delegator, v.getString("eventAuditId"))); 224 } 225 } 226 } 227 return dataEvents; 228 } 229 230 private List getAssignmentEvents(String processId, String activityId) throws EventAuditException { 232 if (Debug.verboseOn()) Debug.log(":: getAssignmentEvents ::", module); 233 GenericDelegator delegator = SharkContainer.getDelegator(); 234 List assignmentEvents = new ArrayList (); 235 List lookupList = null; 236 try { 237 lookupList = delegator.findByAnd("WfEventAudit", UtilMisc.toMap("auditType", "activityAssignmentChanged", "processId", processId, "activityId", activityId)); 238 } catch (GenericEntityException e) { 239 Debug.logError(e, module); 240 throw new EventAuditException(e); 241 } 242 if (lookupList != null && lookupList.size() > 0) { 243 Iterator i = lookupList.iterator(); 244 while (i.hasNext()) { 245 GenericValue v = (GenericValue) i.next(); 246 if (v != null) { 247 assignmentEvents.add(new AssignmentEventAudit(this, delegator, v.getString("eventAuditId"))); 248 } 249 } 250 } 251 return assignmentEvents; 252 } 253 254 private List getActivityStateEvents(String processId, String activityId) throws EventAuditException { 255 if (Debug.verboseOn()) Debug.log(":: getActivityStateEvents ::", module); 256 GenericDelegator delegator = SharkContainer.getDelegator(); 257 List stateEvents = new ArrayList (); 258 List lookupList = null; 259 try { 260 lookupList = delegator.findByAnd("WfEventAudit", UtilMisc.toMap("auditType", "activityStateChanged", "processId", processId, "activityId", activityId)); 261 } catch (GenericEntityException e) { 262 Debug.logError(e, module); 263 throw new EventAuditException(e); 264 } 265 if (lookupList != null && lookupList.size() > 0) { 266 Iterator i = lookupList.iterator(); 267 while (i.hasNext()) { 268 GenericValue v = (GenericValue) i.next(); 269 if (v != null) { 270 stateEvents.add(new StateEventAudit(this, delegator, v.getString("eventAuditId"))); 271 } 272 } 273 } 274 return stateEvents; 275 } 276 277 private List getActivityDataEvents(String processId, String activityId) throws EventAuditException { 278 if (Debug.verboseOn()) Debug.log(":: getActivityDataEvents ::", module); 279 GenericDelegator delegator = SharkContainer.getDelegator(); 280 List dataEvents = new ArrayList (); 281 List lookupList = null; 282 try { 283 lookupList = delegator.findByAnd("WfEventAudit", UtilMisc.toMap("auditType", "activityContextChanged", "processId", processId, "activityId", activityId)); 284 } catch (GenericEntityException e) { 285 Debug.logError(e, module); 286 throw new EventAuditException(e); 287 } 288 if (lookupList != null && lookupList.size() > 0) { 289 Iterator i = lookupList.iterator(); 290 while (i.hasNext()) { 291 GenericValue v = (GenericValue) i.next(); 292 if (v != null) { 293 dataEvents.add(new DataEventAudit(this, delegator, v.getString("eventAuditId"))); 294 } 295 } 296 } 297 return dataEvents; 298 } 299 300 public synchronized String getNextId(String string) throws EventAuditException { 301 GenericDelegator delegator = SharkContainer.getDelegator(); 302 return delegator.getNextSeqId("SharkAuditSeq").toString(); 303 } 304 } 305 | Popular Tags |