1 package org.enhydra.shark; 2 3 import org.enhydra.shark.api.RootException; 4 import org.enhydra.shark.api.SharkTransaction; 5 import org.enhydra.shark.api.client.wfbase.BaseException; 6 import org.enhydra.shark.api.client.wfmodel.CannotAcceptSuspended; 7 import org.enhydra.shark.api.client.wfmodel.InvalidResource; 8 import org.enhydra.shark.api.client.wfmodel.WfActivity; 9 import org.enhydra.shark.api.client.wfmodel.WfAssignment; 10 import org.enhydra.shark.api.client.wfmodel.WfResource; 11 import org.enhydra.shark.api.internal.security.SecurityManager; 12 import org.enhydra.shark.api.internal.working.WfActivityInternal; 13 import org.enhydra.shark.api.internal.working.WfAssignmentInternal; 14 15 20 public class WfAssignmentWrapper implements WfAssignment { 21 22 private String userAuth; 23 private String mgrName; 24 private String processId; 25 private String activityId; 26 private String username; 27 28 34 protected WfAssignmentWrapper(String userAuth,String mgrName,String processId,String actId,String username) { 35 this.userAuth=userAuth; 36 this.mgrName=mgrName; 37 this.processId = processId; 38 this.activityId = actId; 39 this.username = username; 40 } 41 42 46 public WfActivity activity () throws BaseException { 47 WfActivity ret = null; 48 SharkTransaction t = null; 49 try { 50 t = SharkUtilities.createTransaction(); 51 ret = activity(t); 52 } catch (RootException e) { 54 SharkUtilities.emptyCaches(t); 56 if (e instanceof BaseException) 57 throw (BaseException)e; 58 else 59 throw new BaseException(e); 60 } finally { 61 SharkUtilities.releaseTransaction(t); 62 } 63 return ret; 64 } 65 66 70 public WfActivity activity (SharkTransaction t) throws BaseException { 71 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 72 if (sm!=null) { 73 WfActivityInternal actInt=SharkUtilities.getActivity(t,processId,activityId); try { 74 sm.check_assignment_activity(t, 75 processId, 76 activityId, 77 username, 78 userAuth, 79 actInt.container(t).requester(t).getResourceRequesterUsername(t), 80 actInt.getResourceUsername(t), 81 actInt.getAssignmentResourceIds(t)); 82 } catch (Exception ex) { 83 throw new BaseException(ex); 84 } 85 } 86 return SharkEngineManager.getInstance().getObjectFactory().createActivityWrapper(userAuth,mgrName,processId,activityId); 87 } 88 89 93 public WfResource assignee () throws BaseException { 94 WfResource ret = null; 95 SharkTransaction t = null; 96 try { 97 t = SharkUtilities.createTransaction(); 98 ret = assignee(t); 99 } catch (RootException e) { 101 SharkUtilities.emptyCaches(t); 103 if (e instanceof BaseException) 104 throw (BaseException)e; 105 else 106 throw new BaseException(e); 107 } finally { 108 SharkUtilities.releaseTransaction(t); 109 } 110 return ret; 111 } 112 113 122 public WfResource assignee (SharkTransaction t) throws BaseException { 123 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 124 if (sm!=null) { 125 WfActivityInternal actInt=SharkUtilities.getActivity(t,processId,activityId); 126 try { 127 sm.check_assignment_assignee(t, 128 processId, 129 activityId, 130 username, 131 userAuth, 132 actInt.container(t).requester(t).getResourceRequesterUsername(t), 133 actInt.getResourceUsername(t), 134 actInt.getAssignmentResourceIds(t)); 135 } catch (Exception ex) { 136 throw new BaseException(ex); 137 } 138 } 139 return SharkEngineManager.getInstance().getObjectFactory().createResourceWrapper(userAuth,username); 140 } 141 142 145 public void set_assignee (WfResource new_value) throws BaseException, InvalidResource { 146 SharkTransaction t = null; 147 try { 148 t = SharkUtilities.createTransaction(); 149 set_assignee(t, new_value); 150 SharkUtilities.commitTransaction(t); 151 } catch (RootException e) { 152 SharkUtilities.rollbackTransaction(t,e); 153 if (e instanceof InvalidResource) 154 throw (InvalidResource)e; 155 else if (e instanceof BaseException) 156 throw (BaseException)e; 157 else 158 throw new BaseException(e); 159 } finally { 160 SharkUtilities.releaseTransaction(t); 161 } 162 } 163 164 173 public void set_assignee (SharkTransaction t,WfResource new_value) throws BaseException, InvalidResource { 174 WfAssignmentInternal assInternal=WfAssignmentWrapper.getAssignmentImpl(t,processId,activityId,username); 175 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 176 if (sm!=null) { 177 try { 178 sm.check_assignment_set_assignee(t, 179 processId, 180 activityId, 181 username, 182 userAuth, 183 assInternal.activity(t).container(t).requester(t).getResourceRequesterUsername(t), 184 assInternal.activity(t).getResourceUsername(t), 185 assInternal.activity(t).getAssignmentResourceIds(t)); 186 } catch (Exception ex) { 187 throw new BaseException(ex); 188 } 189 } 190 191 if (new_value==null) throw new BaseException("Assignee can't be null"); 192 193 assInternal.set_assignee(t,SharkUtilities 194 .getResource(t, new_value.resource_key(t))); 195 username = new_value.resource_key(t); 196 } 197 198 206 public void set_accepted_status (boolean accept) 207 throws BaseException, CannotAcceptSuspended { 208 SharkTransaction t = null; 209 try { 210 t = SharkUtilities.createTransaction(); 211 set_accepted_status(t,accept); 212 SharkUtilities.commitTransaction(t); 213 } catch (RootException e) { 214 SharkUtilities.rollbackTransaction(t,e); 215 if (e instanceof CannotAcceptSuspended) 216 throw (CannotAcceptSuspended)e; 217 else if (e instanceof BaseException) 218 throw (BaseException)e; 219 else 220 throw new BaseException(e); 221 } finally { 222 SharkUtilities.releaseTransaction(t); 223 } 224 } 225 226 235 public void set_accepted_status (SharkTransaction t,boolean accept) 236 throws BaseException, CannotAcceptSuspended { 237 238 WfActivityInternal actInt=SharkUtilities.getActivity(t,processId,activityId); 239 if (actInt==null) { 240 throw new BaseException("Assignment is not valid anymore"); 241 } 242 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 243 if (sm!=null) { 244 try { 245 sm.check_assignment_set_accepted_status(t, 246 processId, 247 activityId, 248 username, 249 userAuth, 250 actInt.container(t).requester(t).getResourceRequesterUsername(t), 251 actInt.getResourceUsername(t), 252 actInt.getAssignmentResourceIds(t)); 253 } catch (Exception ex) { 254 throw new BaseException(ex); 255 } 256 } 257 258 actInt.set_accepted_status(t,accept,username); 259 } 260 261 268 public boolean get_accepted_status() throws BaseException { 269 boolean ret = false; 270 SharkTransaction t = null; 271 try { 272 t = SharkUtilities.createTransaction(); 273 ret = get_accepted_status(t); 274 } catch (RootException e) { 276 SharkUtilities.emptyCaches(t); 278 if (e instanceof BaseException) 279 throw (BaseException)e; 280 else 281 throw new BaseException(e); 282 } finally { 283 SharkUtilities.releaseTransaction(t); 284 } 285 return ret; 286 } 287 288 297 public boolean get_accepted_status (SharkTransaction t) throws BaseException { 298 WfActivityInternal actInt=SharkUtilities.getActivity(t,processId,activityId); 300 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 301 if (sm!=null) { 302 try { 303 sm.check_assignment_get_accepted_status(t, 304 processId, 305 activityId, 306 username, 307 userAuth, 308 actInt.container(t).requester(t).getResourceRequesterUsername(t), 309 actInt.getResourceUsername(t), 310 actInt.getAssignmentResourceIds(t)); 311 } catch (Exception ex) { 312 throw new BaseException(ex); 313 } 314 } 315 316 return actInt.accepted_status(t); 318 } 319 320 325 public String toString () { 326 return "[pId="+processId+",aId="+activityId+"-> un="+username+"]"; 327 } 328 329 336 public boolean equals (Object obj) { 337 if (!(obj instanceof WfAssignment)) return false; 338 WfAssignment ass=(WfAssignment)obj; 339 try { 340 if (obj instanceof WfAssignmentWrapper) { 341 WfAssignmentWrapper aw=(WfAssignmentWrapper)obj; 342 return aw.activityId.equals(activityId) && 343 aw.username.equals(username); 344 } else { 345 return (ass.activity().key().equals(activityId) 346 && ass.assignee().resource_key().equals(username)); 347 } 348 } catch (Exception ex) { 349 return false; 350 } 351 } 352 353 private static WfAssignmentInternal getAssignmentImpl ( 354 SharkTransaction t, 355 String procId, 356 String actId, 357 String username) throws BaseException { 358 359 WfAssignmentInternal ass=SharkUtilities.getAssignment(t, procId, actId, username); 360 if (ass==null) throw new BaseException("Assignment is not valid anymore"); 361 return ass; 362 } 363 364 } 365 366 | Popular Tags |