001: /*
002: * Bossa Workflow System
003: *
004: * $Id: Activity.java,v 1.17 2004/03/03 19:17:28 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.io.Serializable;
028: import java.util.Map;
029:
030: import com.bigbross.bossa.BossaException;
031: import com.bigbross.bossa.resource.Resource;
032:
033: /**
034: * This class represents an open (firing) work item. <p>
035: *
036: * @author <a href="http://www.bigbross.com">BigBross Team</a>
037: */
038: public class Activity implements Serializable {
039:
040: private int id;
041:
042: private WorkItem workItem;
043:
044: private Resource resource;
045:
046: /**
047: * Creates a new activity. <p>
048: *
049: * @param workItem the open work item this activity represents.
050: * @param resource the resource that opened the work item.
051: */
052: Activity(WorkItem workItem, Resource resource) {
053: this .workItem = workItem;
054: this .id = getCase().nextActivityId();
055: this .resource = resource;
056: }
057:
058: /**
059: * Returns the id of this activity. <p>
060: *
061: * @return the id of this activity.
062: */
063: public int getId() {
064: return id;
065: }
066:
067: /**
068: * Returns the resource responsible by this activity. <p>
069: *
070: * @return the resource id.
071: */
072: public Resource getResource() {
073: return resource;
074: }
075:
076: /**
077: * Returns the id of the work item that created this activity. <p>
078: *
079: * @return the id of the work item that created this activity.
080: */
081: public String getWorkItemId() {
082: return getTransition().getId();
083: }
084:
085: /**
086: * Returns the case type of this activity. <p>
087: *
088: * @return The case type of this activity.
089: */
090: public CaseType getCaseType() {
091: return workItem.getCaseType();
092: }
093:
094: /**
095: * Returns the case of this activity. <p>
096: *
097: * @return The case of this activity.
098: */
099: public Case getCase() {
100: return workItem.getCase();
101: }
102:
103: /**
104: * Returns the transition the open work item represents. <p>
105: *
106: * @return The transition the open work item represents.
107: */
108: Transition getTransition() {
109: return workItem.getTransition();
110: }
111:
112: /**
113: * Closes and finishes this activity. Call this method when the
114: * activity is successfully completed. <p>
115: *
116: * @return <code>true</code> if the activity is succesfully opened,
117: * <code>false</code> otherwise.
118: * @exception SetAttributeException if the underlying expression
119: * evaluation system has problems setting an attribute.
120: * @exception EvaluationException if an expression evaluation error
121: * occurs. If this exception is thrown the state of the case
122: * may be left inconsistent.
123: * @exception PersistenceException if an error occours when making the
124: * execution of this method persistent.
125: */
126: public boolean close() throws BossaException {
127: return dispatchTransaction(new CloseActivity(this , null));
128: }
129:
130: /**
131: * Closes and finishes an activity. Call this method when the
132: * activity is successfully completed. <p>
133: *
134: * An attribute mapping should be passed when this method is called.
135: * This is a (<code>String</code>, <code>Object</code>) mapping of
136: * variables names (as used in edge weight expressions) and Java objects.
137: * The Java objects should be understandable by the underlying BSF
138: * engine being used (for JavaScript, <code>Boolean</code>,
139: * <code>Integer</code> and <code>String</code> are known to work).
140: * The attributes provided will overwrite current set attributes and
141: * the value of these attributes will be used when evaluating edge
142: * weights. <p>
143: *
144: * @param attributes the attributes mapping.
145: * @return <code>true</code> if the activity is succesfully opened,
146: * <code>false</code> otherwise.
147: * @exception SetAttributeException if the underlying expression
148: * evaluation system has problems setting an attribute.
149: * @exception EvaluationException if an expression evaluation error
150: * occurs. If this exception is thrown the state of the case
151: * may be left inconsistent.
152: * @exception PersistenceException if an error occours when making the
153: * execution of this method persistent.
154: */
155: public boolean close(Map attributes) throws BossaException {
156: return dispatchTransaction(new CloseActivity(this , attributes));
157: }
158:
159: /**
160: * Cancel this activity. Call this method if the activity could not
161: * be completed. The related work item will return to the list of
162: * available work items and can be opened again. <p>
163: *
164: * @return <code>true</code> if the activity is succesfully canceled,
165: * <code>false</code> otherwise.
166: * @exception EvaluationException if an expression evaluation error
167: * occurs. If this exception is thrown the state of the case
168: * may be left inconsistent.
169: * @exception PersistenceException if an error occours when making the
170: * execution of this method persistent.
171: */
172: public boolean cancel() throws BossaException {
173: return dispatchTransaction(new CancelActivity(this ));
174: }
175:
176: /**
177: * Executes a transaction that returns a boolean value. <p>
178: *
179: * @param transaction the transaction;
180: * @return The <code>boolean</code> returned by the transaction execution.
181: */
182: private boolean dispatchTransaction(WFNetTransaction transaction)
183: throws BossaException {
184: Boolean result = (Boolean) getCaseType().getCaseTypeManager()
185: .getBossa().execute(transaction);
186: return result.booleanValue();
187: }
188: }
|