001: /*
002: * Bossa Workflow System
003: *
004: * $Id: WorkManager.java,v 1.6 2003/04/30 18:11:03 gdvieira Exp $
005: *
006: * Copyright (C) 2003 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.work;
026:
027: import java.io.Serializable;
028: import java.util.Iterator;
029: import java.util.List;
030:
031: import com.bigbross.bossa.Bossa;
032: import com.bigbross.bossa.resource.Resource;
033: import com.bigbross.bossa.wfnet.Activity;
034: import com.bigbross.bossa.wfnet.WorkItem;
035:
036: /**
037: * This class manages the generation of work item lists. <p>
038: *
039: * @author <a href="http://www.bigbross.com">BigBross Team</a>
040: */
041: public class WorkManager implements Serializable {
042:
043: private Bossa engine;
044:
045: /**
046: * Creates a new empty work manager. <p>
047: *
048: * @param engine the bossa engine this work manager is part.
049: */
050: public WorkManager(Bossa engine) {
051: this .engine = engine;
052: }
053:
054: /**
055: * Creates a new empty work manager. <p>
056: */
057: public WorkManager() {
058: this (null);
059: }
060:
061: /**
062: * Returns the bossa engine this work manager is part. <p>
063: *
064: * @return The bossa engine this work manager is part.
065: */
066: Bossa getBossa() {
067: return engine;
068: }
069:
070: /**
071: * Returns a list of all work items in the engine that can be opened
072: * by the provided resource. <p>
073: *
074: * @param resource the resource.
075: * @return the list of work items.
076: */
077: public List getWorkItems(Resource resource) {
078: return getWorkItems(resource, false);
079: }
080:
081: /**
082: * Returns a list of all work items in the engine that can be opened
083: * by the provided resource, including the initial work items. <p>
084: *
085: * @param resource the resource.
086: * @param getInitial set to <code>true</code> to get the initial work
087: * items and to <code>false</code> to only get the
088: * standard work items.
089: * @return the list of work items.
090: */
091: public List getWorkItems(Resource resource, boolean getInitial) {
092: List workItems = getBossa().getCaseTypeManager().getWorkItems(
093: getInitial);
094: Iterator i = workItems.iterator();
095: while (i.hasNext()) {
096: if (!((WorkItem) i.next()).canBePerformedBy(resource)) {
097: i.remove();
098: }
099: }
100: return workItems;
101: }
102:
103: /**
104: * Returns a list of all activities in the engine that are under the
105: * responsability of the provided resource. <p>
106: *
107: * @param resource the resource.
108: * @return the list of activities.
109: */
110: public List getActivities(Resource resource) {
111: List activities = getBossa().getCaseTypeManager()
112: .getActivities();
113: Iterator i = activities.iterator();
114: while (i.hasNext()) {
115: Resource responsible = ((Activity) i.next()).getResource();
116: if (!responsible.contains(resource)) {
117: i.remove();
118: }
119: }
120: return activities;
121: }
122: }
|