001: /*
002: * Bossa Workflow System
003: *
004: * $Id: WFNetEvents.java,v 1.11 2004/02/11 21:31:14 gdvieira Exp $
005: *
006: * Copyright (C) 2003,2004 OpenBR Sistemas S/C Ltda.
007: *
008: * This file is part of Bossa.
009: *
010: * Bossa is free software; you can redistribute it and/or modify it
011: * under the terms of version 2 of the GNU General Public License as
012: * published by the Free Software Foundation.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public
020: * License along with this program; if not, write to the
021: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
022: * Boston, MA 02111-1307, USA.
023: */
024:
025: package com.bigbross.bossa.wfnet;
026:
027: import java.util.HashMap;
028: import java.util.Map;
029:
030: import com.bigbross.bossa.Bossa;
031: import com.bigbross.bossa.notify.Event;
032: import com.bigbross.bossa.notify.NotificationQueue;
033: import com.bigbross.bossa.resource.Resource;
034:
035: /**
036: * This class holds as static constants all ids of WFNet events. It also
037: * provides methods used by the WFNet classes to create and notify these
038: * events. <p>
039: *
040: * @author <a href="http://www.bigbross.com">BigBross Team</a>
041: */
042: public class WFNetEvents extends NotificationQueue {
043:
044: /**
045: * Constant to indicate the event of a case type registration. <p>
046: *
047: * This event contains the following attributes: ATTRIB_CASE_TYPE_ID <p>
048: *
049: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
050: */
051: public static final String ID_REGISTER_CASE_TYPE = "register_case_type";
052:
053: /**
054: * Constant to indicate the event of a case type removal. <p>
055: *
056: * This event contains the following attributes: ATTRIB_CASE_TYPE_ID <p>
057: *
058: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
059: */
060: public static final String ID_REMOVE_CASE_TYPE = "remove_case_type";
061:
062: /**
063: * Constant to indicate the event of opening a case. <p>
064: *
065: * This event contains the following attributes: ATTRIB_CASE_ID and
066: * ATTRIB_CASE_TYPE_ID <p>
067: *
068: * @see WFNetEvents#ATTRIB_CASE_ID
069: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
070: */
071: public static final String ID_OPEN_CASE = "open_case";
072:
073: /**
074: * Constant to indicate the event of closing a case. <p>
075: *
076: * This event contains the following attributes: ATTRIB_CASE_ID and
077: * ATTRIB_CASE_TYPE_ID <p>
078: *
079: * @see WFNetEvents#ATTRIB_CASE_ID
080: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
081: */
082: public static final String ID_CLOSE_CASE = "close_case";
083:
084: /**
085: * Constant to indicate the event of tokens being added to a place. <p>
086: *
087: * This event contains the following attributes: ATTRIB_PLACE_ID,
088: * ATTRIB_CASE_ID and ATTRIB_CASE_TYPE_ID <p>
089: *
090: * @see WFNetEvents#ATTRIB_PLACE_ID
091: * @see WFNetEvents#ATTRIB_CASE_ID
092: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
093: */
094: public static final String ID_ADD_TOKENS = "add_tokens";
095:
096: /**
097: * Constant to indicate the event of tokens being removed from a place. <p>
098: *
099: * This event contains the following attributes: ATTRIB_PLACE_ID,
100: * ATTRIB_TOKEN_NUMBER_ID, ATTRIB_CASE_ID and ATTRIB_CASE_TYPE_ID <p>
101: *
102: * @see WFNetEvents#ATTRIB_PLACE_ID
103: * @see WFNetEvents#ATTRIB_TOKEN_NUMBER_ID
104: * @see WFNetEvents#ATTRIB_CASE_ID
105: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
106: */
107: public static final String ID_REMOVE_TOKENS = "remove_tokens";
108:
109: /**
110: * Constant to indicate the event of a specific number of tokens being
111: * put in a place. <p>
112: *
113: * This event contains the following attributes: ATTRIB_PLACE_ID,
114: * ATTRIB_TOKEN_NUMBER_ID, ATTRIB_CASE_ID and ATTRIB_CASE_TYPE_ID <p>
115: *
116: * @see WFNetEvents#ATTRIB_PLACE_ID
117: * @see WFNetEvents#ATTRIB_TOKEN_NUMBER_ID
118: * @see WFNetEvents#ATTRIB_CASE_ID
119: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
120: */
121: public static final String ID_SET_TOKENS = "set_tokens";
122:
123: /**
124: * Constant to indicate the activation of an inactive work item. <p>
125: *
126: * This event contains the following attributes: ATTRIB_WORK_ITEM_ID,
127: * ATTRIB_CASE_ID and ATTRIB_CASE_TYPE_ID <p>
128: *
129: * @see WFNetEvents#ATTRIB_WORK_ITEM_ID
130: * @see WFNetEvents#ATTRIB_CASE_ID
131: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
132: */
133: public static final String ID_WORK_ITEM_ACTIVE = "work_item_active";
134:
135: /**
136: * Constant to indicate the deactivation of an active work item. <p>
137: *
138: * This event contains the following attributes: ATTRIB_WORK_ITEM_ID,
139: * ATTRIB_CASE_ID and ATTRIB_CASE_TYPE_ID <p>
140: *
141: * @see WFNetEvents#ATTRIB_WORK_ITEM_ID
142: * @see WFNetEvents#ATTRIB_CASE_ID
143: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
144: */
145: public static final String ID_WORK_ITEM_INACTIVE = "work_item_inactive";
146:
147: /**
148: * Constant to indicate the event of opening a work item. <p>
149: *
150: * This event contains the following attributes: ATTRIB_WORK_ITEM_ID,
151: * ATTRIB_CASE_ID, ATTRIB_CASE_TYPE_ID and ATTRIB_RESOURCE_ID <p>
152: *
153: * @see WFNetEvents#ATTRIB_WORK_ITEM_ID
154: * @see WFNetEvents#ATTRIB_CASE_ID
155: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
156: * @see WFNetEvents#ATTRIB_RESOURCE_ID
157: */
158: public static final String ID_OPEN_WORK_ITEM = "open_work_item";
159:
160: /**
161: * Constant to indicate the event of closing an activity. <p>
162: *
163: * This event contains the following attributes: ATTRIB_ACTIVITY_ID,
164: * ATTRIB_ACTIVITY_WI_ID, ATTRIB_CASE_ID, ATTRIB_CASE_TYPE_ID and
165: * ATTRIB_RESOURCE_ID <p>
166: *
167: * @see WFNetEvents#ATTRIB_ACTIVITY_ID
168: * @see WFNetEvents#ATTRIB_ACTIVITY_WI_ID
169: * @see WFNetEvents#ATTRIB_CASE_ID
170: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
171: * @see WFNetEvents#ATTRIB_RESOURCE_ID
172: */
173: public static final String ID_CLOSE_ACTIVITY = "close_activity";
174:
175: /**
176: * Constant to indicate the event of canceling an activity. <p>
177: *
178: * This event contains the following attributes: ATTRIB_ACTIVITY_ID,
179: * ATTRIB_ACTIVITY_WI_ID, ATTRIB_CASE_ID, ATTRIB_CASE_TYPE_ID and
180: * ATTRIB_RESOURCE_ID <p>
181: *
182: * @see WFNetEvents#ATTRIB_ACTIVITY_ID
183: * @see WFNetEvents#ATTRIB_ACTIVITY_WI_ID
184: * @see WFNetEvents#ATTRIB_CASE_ID
185: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
186: * @see WFNetEvents#ATTRIB_RESOURCE_ID
187: */
188: public static final String ID_CANCEL_ACTIVITY = "cancel_activity";
189:
190: /**
191: * Constant to indicate the event of a manual state change in a
192: * case. <p>
193: *
194: * This event contains the following attributes: ATTRIB_CASE_ID and
195: * ATTRIB_CASE_TYPE_ID <p>
196: *
197: * @see WFNetEvents#ATTRIB_CASE_ID
198: * @see WFNetEvents#ATTRIB_CASE_TYPE_ID
199: */
200: public static final String ID_SET_STATE = "set_state";
201:
202: /**
203: * Constant to indicate the case type id attribute.
204: */
205: public static final String ATTRIB_CASE_TYPE_ID = "case_type_id";
206:
207: /**
208: * Constant to indicate the case id attribute.
209: */
210: public static final String ATTRIB_CASE_ID = "case_id";
211:
212: /**
213: * Constant to indicate the place id attribute.
214: */
215: public static final String ATTRIB_PLACE_ID = "place_id";
216:
217: /**
218: * Constant to indicate the token number id attribute.
219: */
220: public static final String ATTRIB_TOKEN_NUMBER_ID = "token_number_id";
221:
222: /**
223: * Constant to indicate the work item id attribute.
224: */
225: public static final String ATTRIB_WORK_ITEM_ID = "work_item_id";
226:
227: /**
228: * Constant to indicate the activity id attribute.
229: */
230: public static final String ATTRIB_ACTIVITY_ID = "activity_id";
231:
232: /**
233: * Constant to indicate the work item id of an activity attribute.
234: */
235: public static final String ATTRIB_ACTIVITY_WI_ID = "activity_wi_id";
236:
237: /**
238: * Constant to indicate the resource id attribute.
239: */
240: public static final String ATTRIB_RESOURCE_ID = "resource_id";
241:
242: /**
243: * Creates a case type related event and puts it in the queue. <p>
244: *
245: * @param bossa the root of the bossa system.
246: * @param notificationId the id of this event.
247: * @param caseType the case type involved.
248: */
249: void newCaseTypeEvent(Bossa bossa, String notificationId,
250: CaseType caseType) {
251: if (bossa != null) {
252: Map attrib = new HashMap();
253: attrib.put(ATTRIB_CASE_TYPE_ID, caseType.getId());
254: addEvent(new Event(notificationId, Event.WFNET_EVENT,
255: attrib, bossa.getTimeSource().getTime()));
256: }
257: }
258:
259: /**
260: * Creates a case related event and puts it in the queue. <p>
261: *
262: * @param bossa the root of the bossa system.
263: * @param notificationId the id of this event.
264: * @param caze the case involved.
265: */
266: void newCaseEvent(Bossa bossa, String notificationId, Case caze) {
267: if (bossa != null) {
268: Map attrib = new HashMap();
269: attrib.put(ATTRIB_CASE_ID, Integer.toString(caze.getId()));
270: attrib.put(ATTRIB_CASE_TYPE_ID, caze.getCaseType().getId());
271: addEvent(new Event(notificationId, Event.WFNET_EVENT,
272: attrib, bossa.getTimeSource().getTime()));
273: }
274: }
275:
276: /**
277: * Creates a place related event and puts it in the queue. <p>
278: *
279: * @param bossa the root of the bossa system.
280: * @param notificationId the id of this event.
281: * @param caze the case involved.
282: * @param place the place involved.
283: * @param amount the number of tokens involved.
284: */
285: void newPlaceEvent(Bossa bossa, String notificationId, Case caze,
286: Place place, int amount) {
287: if (bossa != null
288: && (amount != 0 || notificationId.equals(ID_SET_TOKENS))) {
289: Map attrib = new HashMap();
290: attrib.put(ATTRIB_PLACE_ID, place.getId());
291: attrib
292: .put(ATTRIB_TOKEN_NUMBER_ID, Integer
293: .toString(amount));
294: attrib.put(ATTRIB_CASE_ID, Integer.toString(caze.getId()));
295: attrib.put(ATTRIB_CASE_TYPE_ID, caze.getCaseType().getId());
296: addEvent(new Event(notificationId, Event.WFNET_EVENT,
297: attrib, bossa.getTimeSource().getTime()));
298: }
299: }
300:
301: /**
302: * Creates a work item related event and puts it in the queue. <p>
303: *
304: * @param bossa the root of the bossa system.
305: * @param notificationId the id of this event.
306: * @param wi the work item involved.
307: * @param resource the resource involved.
308: */
309: void newWorkItemEvent(Bossa bossa, String notificationId,
310: WorkItem wi, Resource resource) {
311: if (bossa != null) {
312: Map attrib = new HashMap();
313: attrib.put(ATTRIB_WORK_ITEM_ID, wi.getId());
314: attrib.put(ATTRIB_CASE_ID, Integer.toString(wi.getCase()
315: .getId()));
316: attrib.put(ATTRIB_CASE_TYPE_ID, wi.getCaseType().getId());
317: if (resource != null) {
318: attrib.put(ATTRIB_RESOURCE_ID, resource.getId());
319: }
320: addEvent(new Event(notificationId, Event.WFNET_EVENT,
321: attrib, bossa.getTimeSource().getTime()));
322: }
323: }
324:
325: /**
326: * Creates an activity related event and puts it in the queue. <p>
327: *
328: * @param bossa the root of the bossa system.
329: * @param notificationId the id of this event.
330: * @param act the activity involved.
331: */
332: void newActivityEvent(Bossa bossa, String notificationId,
333: Activity act) {
334: if (bossa != null) {
335: Map attrib = new HashMap();
336: attrib.put(ATTRIB_ACTIVITY_ID, Integer
337: .toString(act.getId()));
338: attrib.put(ATTRIB_ACTIVITY_WI_ID, act.getWorkItemId());
339: attrib.put(ATTRIB_CASE_ID, Integer.toString(act.getCase()
340: .getId()));
341: attrib.put(ATTRIB_CASE_TYPE_ID, act.getCaseType().getId());
342: attrib.put(ATTRIB_RESOURCE_ID, act.getResource().getId());
343: addEvent(new Event(notificationId, Event.WFNET_EVENT,
344: attrib, bossa.getTimeSource().getTime()));
345: }
346: }
347: }
|