KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
16  * WfAssignmentWrapper - Workflow Assignment Object implementation
17  * @author Sasa Bojanic
18  * @author Vladimir Puskas
19  */

20 public class WfAssignmentWrapper implements WfAssignment {
21
22    private String JavaDoc userAuth;
23    private String JavaDoc mgrName;
24    private String JavaDoc processId;
25    private String JavaDoc activityId;
26    private String JavaDoc username;
27
28    /**
29     * Creates new WfAssignment.
30     * @param processId - process of activity of assignment
31     * @param actId - activity Id for this assignment.
32     * @param username
33     */

34    protected WfAssignmentWrapper(String JavaDoc userAuth,String JavaDoc mgrName,String JavaDoc processId,String JavaDoc actId,String JavaDoc username) {
35       this.userAuth=userAuth;
36       this.mgrName=mgrName;
37       this.processId = processId;
38       this.activityId = actId;
39       this.username = username;
40    }
41
42    /**
43     * Gets the activity object of this assignment.
44     * @return WfActivity The activity object of this assignment.
45     */

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          //SharkUtilities.commitTransaction(t);
53
} catch (RootException e) {
54          //SharkUtilities.rollbackTransaction(t);
55
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    /**
67     * Gets the activity object of this assignment.
68     * @return WfActivity The activity object of this assignment.
69     */

70    public WfActivity activity (SharkTransaction t) throws BaseException {
71       SecurityManager JavaDoc 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 JavaDoc ex) {
83             throw new BaseException(ex);
84          }
85       }
86       return SharkEngineManager.getInstance().getObjectFactory().createActivityWrapper(userAuth,mgrName,processId,activityId);
87    }
88
89    /**
90     * Gets the assignee (resource) of this assignment.
91     * @return WfResource The assignee of this assignment.
92     */

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          //SharkUtilities.commitTransaction(t);
100
} catch (RootException e) {
101          //SharkUtilities.rollbackTransaction(t);
102
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    /**
114     * Method assignee
115     *
116     * @param t a SharkTransaction
117     *
118     * @return a WfResource
119     *
120     * @exception BaseException
121     */

122    public WfResource assignee (SharkTransaction t) throws BaseException {
123       SecurityManager JavaDoc 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 JavaDoc ex) {
136             throw new BaseException(ex);
137          }
138       }
139       return SharkEngineManager.getInstance().getObjectFactory().createResourceWrapper(userAuth,username);
140    }
141
142    /**
143     * Sets the assignee of this assignment.
144     */

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    /**
165     * Method set_assignee
166     *
167     * @param t a SharkTransaction
168     * @param new_value a WfResource
169     *
170     * @exception BaseException
171     * @exception InvalidResource
172     */

173    public void set_assignee (SharkTransaction t,WfResource new_value) throws BaseException, InvalidResource {
174       WfAssignmentInternal assInternal=WfAssignmentWrapper.getAssignmentImpl(t,processId,activityId,username);
175       SecurityManager JavaDoc 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 JavaDoc 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    /**
199     * Method set_accepted_status
200     *
201     * @param accept a boolean
202     *
203     * @exception BaseException
204     * @exception CannotAcceptSuspended
205     */

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    /**
227     * Method set_accepted_status
228     *
229     * @param t a SharkTransaction
230     * @param accept a boolean
231     *
232     * @exception BaseException
233     * @exception CannotAcceptSuspended
234     */

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 JavaDoc 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 JavaDoc ex) {
254             throw new BaseException(ex);
255          }
256       }
257
258       actInt.set_accepted_status(t,accept,username);
259    }
260
261    /**
262     * Method get_accepted_status
263     *
264     * @return a boolean
265     *
266     * @exception BaseException
267     */

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          //SharkUtilities.commitTransaction(t);
275
} catch (RootException e) {
276          //SharkUtilities.rollbackTransaction(t);
277
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    /**
289     * Method get_accepted_status
290     *
291     * @param t a SharkTransaction
292     *
293     * @return a boolean
294     *
295     * @exception BaseException
296     */

297    public boolean get_accepted_status (SharkTransaction t) throws BaseException {
298       //WfAssignmentInternal assInternal=WfAssignmentWrapper.getAssignmentImpl(t,processId,activityId,username);
299
WfActivityInternal actInt=SharkUtilities.getActivity(t,processId,activityId);
300       SecurityManager JavaDoc 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 JavaDoc ex) {
312             throw new BaseException(ex);
313          }
314       }
315
316       //return assInternal.get_acceted_status(t);
317
return actInt.accepted_status(t);
318    }
319
320    /**
321     * Method toString
322     *
323     * @return a String
324     */

325    public String JavaDoc toString () {
326       return "[pId="+processId+",aId="+activityId+"-> un="+username+"]";
327    }
328
329    /**
330     * Method equals
331     *
332     * @param obj an Object
333     *
334     * @return a boolean
335     */

336    public boolean equals (Object JavaDoc 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 JavaDoc ex) {
349          return false;
350       }
351    }
352
353    private static WfAssignmentInternal getAssignmentImpl (
354       SharkTransaction t,
355       String JavaDoc procId,
356       String JavaDoc actId,
357       String JavaDoc 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