1
2
3
4 package org.flowfuse.base.model;
5
6 import com.opensymphony.workflow.spi.Step;
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.flowfuse.base.Constants;
10 import org.flowfuse.base.services.workflow.WorkflowService;
11 import org.flowfuse.base.services.workitem.WorkItemManagementService;
12
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17 import java.io.Serializable;
18
19 /***
20 * <p>An instance of <code>Workflow</code> contains workflow data of
21 * a particular work item. It contains information about the current
22 * step(s), status and possible workflow actions as well as past steps and
23 * workflow actions. Instances of this class are not persisted it self,
24 * but act as a wrapper for lower level object from the OS Workflow
25 * engine.</p>
26 *
27 * @author <a href="stefan@flowfuse.org">Stefan Kleineikenscheidt</a>,
28 * Flowfuse.org
29 * @since 1.0
30 * @version $Id: Workflow.java,v 1.3 2005/12/12 21:34:19 skleinei Exp $
31 */
32 public class Workflow implements Serializable {
33
34 /***
35 * RCS ID
36 */
37 public final static String rcsid = "$Id: Workflow.java,v 1.3 2005/12/12 21:34:19 skleinei Exp $";
38
39 /***
40 * Logger
41 */
42 protected final Log logger = LogFactory.getLog(this.getClass());
43
44 /***
45 * The <code>WorkItem</code> this <code>Workflow</code> belongs to.
46 */
47 private WorkItem workItem = null;
48
49 /***
50 * The Spring Modules OsWorkflowTemplate which encapsulates OS
51 * Workflow's stateles Workflow.
52 */
53 private WorkflowService workflowService = null;
54
55 private WorkItemManagementService workItemManagementService = null;
56
57 /***
58 * Constructs a new Workflow instance.
59 *
60 * @param workItem Reference to the associated WorkItem
61 */
62 public Workflow(WorkItem workItem) {
63 this.workItem = workItem;
64 }
65
66 /***
67 * <p>Returns the state of the <code>Workflow</code>.</p>
68 *
69 * @return The <code>Workflow</code>'s state.
70 */
71 public int getState() {
72 return this.workflowService.getEntryState();
73 }
74
75 /***
76 * <p>Returns a list of current <code>WorkflowSteps</code> for this
77 * workflow. Most of the time, this will be just one current step - only
78 * in case of splits multiple steps are returned.</p>
79 *
80 * @return List of current workflow steps for this workflow.
81 * @see WorkflowStep
82 * @since 1.0
83 */
84 public List getCurrentSteps() {
85 List currentSteps = null;
86 List currentWorkflowSteps = new ArrayList();
87
88 currentSteps = this.workflowService.getCurrentSteps();
89
90 for (int i = 0; i < currentSteps.size(); i++) {
91 Object o = (Object) currentSteps.get(i);
92 Step step = (Step) o;
93
94 WorkflowStep workflowStep = new WorkflowStep(step,
95 this.workflowService.getWorkflowDescriptor());
96 currentWorkflowSteps.add(workflowStep);
97 }
98
99 return currentWorkflowSteps;
100 }
101
102 /***
103 * <p>Returns a list of history <code>WorkflowSteps</code> for this
104 * workflow.</p>
105 *
106 * @return List of history workflow steps for this workflow.
107 * @see WorkflowStep
108 * @since 1.0
109 */
110 public List getHistorySteps() {
111 List historySteps = null;
112 List historyWorkflowSteps = new ArrayList();
113
114 historySteps = this.workflowService.getHistorySteps();
115
116 for (int i = 0; i < historySteps.size(); i++) {
117 Object o = (Object) historySteps.get(i);
118 Step step = (Step) o;
119
120 WorkflowStep workflowStep = new WorkflowStep(step,
121 this.workflowService.getWorkflowDescriptor());
122 historyWorkflowSteps.add(workflowStep);
123 }
124
125 return historyWorkflowSteps;
126 }
127
128 /***
129 * <p>Returns a list of available <code>WorkflowActions</code> for this
130 * workflow.</p>
131 *
132 * @return List of available workflow actions for this workflow.
133 * @see WorkflowAction
134 * @since 1.0
135 */
136 public List getAvailableActions() {
137 return getAvailableActions(null);
138 }
139
140 /***
141 * <p>Returns a list of available <code>WorkflowActions</code> for this
142 * workflow.</p>
143 *
144 * @param inputs Map of parameters which may limit the resulting
145 * actions. May be null.
146 * @return List of available workflow actions for this workflow.
147 * @see WorkflowAction
148 * @since 1.0
149 */
150 public List getAvailableActions(Map inputs) {
151 int[] availableActionIds;
152 List availableActions = new ArrayList();
153
154 availableActionIds =
155 this.workflowService.getAvailableActions(inputs);
156
157 for (int i = 0; i < availableActionIds.length; i++) {
158 int actionId = availableActionIds[i];
159 WorkflowAction action = new WorkflowAction(actionId,
160 this.workflowService.getWorkflowDescriptor());
161 availableActions.add(action);
162 }
163
164 return availableActions;
165 }
166
167 public void startWorkflow() {
168 Map inputs = new HashMap();
169 inputs.put(Constants.WF_FUNCTION_WORKFLOWDATA, this.workItem);
170
171
172 this.workflowService.initialize(2801, inputs);
173 }
174
175 public void executeWorkflowAction(WorkflowAction workflowAction,
176 Map inputs) {
177
178
179 inputs.put(Constants.WF_FUNCTION_WORKFLOWDATA, this.workItem);
180 this.workflowService.doAction(workflowAction.getId(), inputs);
181 }
182
183 public WorkflowAction getWorkflowAction(int id) {
184 return new WorkflowAction(id,
185 this.workflowService.getWorkflowDescriptor());
186 }
187
188 /***
189 * Retrieves dependency (see <a href="http://www.springframework.org">
190 * http://www.springframework.org</a>).
191 *
192 * @return
193 */
194 public WorkflowService getWorkflowService() {
195 return workflowService;
196 }
197
198 /***
199 * Injects dependency (see <a href="http://www.springframework.org">
200 * http://www.springframework.org</a>).
201 */
202 public void setWorkflowService(WorkflowService workflowService) {
203 this.workflowService = workflowService;
204 }
205
206 /***
207 * Retrieves dependency (see <a href="http://www.springframework.org">
208 * http://www.springframework.org</a>).
209 *
210 * @return
211 */
212 public WorkItemManagementService getWorkflowManagementService() {
213 return workItemManagementService;
214 }
215
216 /***
217 * Injects dependency (see <a href="http://www.springframework.org">
218 * http://www.springframework.org</a>).
219 */
220 public void setWorkflowManagementService(
221 WorkItemManagementService workItemManagementService) {
222 this.workItemManagementService = workItemManagementService;
223 }
224 }
225
226