001: /*
002: * Bossa Workflow System
003: *
004: * $Id: WorkItem.java,v 1.20 2004/02/04 21:46:36 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:
029: import com.bigbross.bossa.BossaException;
030: import com.bigbross.bossa.resource.Expression;
031: import com.bigbross.bossa.resource.Resource;
032:
033: /**
034: * This class represents a transition of a specific case instance. <p>
035: *
036: * We use a somewhat non standard definition of a work item: instead of
037: * a <emph>fireable</emph> transition a work item is a <emph>likely
038: * fireable</emph> transition. All methods of this class account for this
039: * and it is possible to discover in advance if a work item is actually
040: * fireable without opening it. <p>
041: *
042: * @author <a href="http://www.bigbross.com">BigBross Team</a>
043: */
044: public class WorkItem implements Serializable {
045:
046: private Case caze;
047:
048: private Transition transition;
049:
050: private boolean fireable;
051:
052: /**
053: * Creates a new work item. <p>
054: *
055: * @param caze the case.
056: * @param transition the transition.
057: * @param fireable the work item fireable status.
058: */
059: WorkItem(Case caze, Transition transition, boolean fireable) {
060: this .caze = caze;
061: this .transition = transition;
062: this .fireable = fireable;
063: }
064:
065: /**
066: * Returns the case type of this work item. <p>
067: *
068: * @return the case type of this work item.
069: */
070: public CaseType getCaseType() {
071: return getCase().getCaseType();
072: }
073:
074: /**
075: * Returns the case of this work item. <p>
076: *
077: * @return the case of this work item.
078: */
079: public Case getCase() {
080: return caze;
081: }
082:
083: /**
084: * Returns the transition this work item represents. <p>
085: *
086: * @return the transition this work item represents.
087: */
088: Transition getTransition() {
089: return transition;
090: }
091:
092: /**
093: * Returns the id of this work item. It is the same id of the
094: * transition this work item represents. <p>
095: *
096: * @return the id of this work item.
097: */
098: public String getId() {
099: return getTransition().getId();
100: }
101:
102: /**
103: * Indicates if this work item is fireable. <p>
104: *
105: * @return <code>true</code> if the work item is fireable;
106: * <code>false</code> otherwise.
107: */
108: public boolean isFireable() {
109: return fireable;
110: }
111:
112: /**
113: * Indicates if this work item can be open by the provided resource. <p>
114: *
115: * @param resource the resource.
116: * @return <code>true</code> if the resource can open this work item;
117: * <code>false</code> otherwise.
118: */
119: public boolean canBePerformedBy(Resource resource) {
120: Expression e = getTransition().getResource();
121: return e == null ? true : e.contains(
122: caze.getResourceRegistry(), resource);
123: }
124:
125: /**
126: * Updates the firing status of this work item. <p>
127: *
128: * @return <code>true</code> if the work item is fireable,
129: * <code>false</code> otherwise.
130: * @exception EvaluationException if an expression evaluation error
131: * occurs.
132: */
133: boolean update() throws EvaluationException {
134: return fireable = getCase().isFireable(transition);
135: }
136:
137: /**
138: * Opens this work item. A open work item is represented by
139: * an activity and is locked to the resource who opened it. The actual
140: * completion of the work item in handled by the created activity. <p>
141: *
142: * @param resource the resource that is opening the work item.
143: * @return the activity created by the opening of this work item,
144: * <code>null</code> if the work item could not be opened.
145: * @exception EvaluationException if an expression evaluation error
146: * occurs. If this exception is thrown the state of the case
147: * may be left inconsistent.
148: * @exception PersistenceException if an error occours when making the
149: * execution of this method persistent.
150: */
151: public Activity open(Resource resource) throws BossaException {
152: WFNetTransaction openTransaction = new OpenWorkItem(this ,
153: resource);
154: return (Activity) getCaseType().getCaseTypeManager().getBossa()
155: .execute(openTransaction);
156: }
157: }
|