1 package org.apache.fulcrum.osworkflow.example.tools;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.apache.fulcrum.osworkflow.WorkflowInstance;
28 import org.apache.fulcrum.osworkflow.WorkflowService;
29 import org.apache.fulcrum.osworkflow.WorkflowServiceFacade;
30 import org.apache.turbine.om.security.User;
31 import org.apache.turbine.services.pull.ApplicationTool;
32 import org.apache.turbine.util.RunData;
33
34 import com.opensymphony.workflow.Workflow;
35 import com.opensymphony.workflow.WorkflowException;
36 /***
37 * A pull tool which provides lookups of workflows by delegating
38 * to the configured Fulcrum <code>WorkflowService</code>.
39 *
40 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
41 */
42 public class WorkflowTool implements ApplicationTool
43 {
44
45 /*** Fulcrum Localization component */
46 private WorkflowService workflowService;
47
48 /*** Turbine rundata object */
49 private RunData data;
50
51 /*** Turbine User object */
52 private User user;
53
54
55 /***
56 * Creates a new instance. Used by <code>PullService</code>.
57 */
58 public WorkflowTool()
59 {
60 refresh();
61 }
62
63 /***
64 * Initialize the tool with the RunData object.
65 */
66 public final void init(Object obj)
67 {
68 data = (RunData) obj;
69 }
70 /***
71 * Remove the Turbine RunData object.
72 */
73 public void refresh()
74 {
75 data = null;
76 }
77
78 /***
79 * Sets the Turbine User object
80 * @param user The User object to set
81 */
82 public void setUser(User user)
83 {
84 this.user = user;
85 }
86
87 /***
88 * Retrieve the Turbine User object
89 * @return Turbine User
90 */
91 public User getUser()
92 {
93 if (user == null)
94 {
95 user = data.getUser();
96 }
97 return user;
98 }
99
100 /***
101 * Returns all workflows that belong the user and have a
102 * certain status specified in the workflow xml file.
103 *
104 * @param status A string like 'Accepted'
105 * @return A list of WorkflowInstance objects
106 * @throws WorkflowException is thrown if there is an error.
107 */
108 public List retrieveWorkflows(String status) throws WorkflowException
109 {
110 List workflows = new ArrayList();
111 String caller = getUser().getName();
112 long workflowIds[] =
113 WorkflowServiceFacade.retrieveWorkflows(caller, status);
114 Workflow workflow = WorkflowServiceFacade.retrieveWorkflow(caller);
115 for (int i = 0; i < workflowIds.length; i++)
116 {
117 WorkflowInstance workflowInstance =
118 new WorkflowInstance(workflow, workflowIds[i]);
119 workflows.add(workflowInstance);
120 }
121 return workflows;
122 }
123
124 /***
125 * Retrieve Workflow
126 *
127 * @return Workflow object
128 * @throws WorkflowException
129 */
130 public Workflow retrieveWorkflow() throws WorkflowException
131 {
132 return retrieveWorkflow(getUser());
133 }
134
135 /***
136 * Retrieve Workflow of given User
137 *
138 * @param User A user object to look workflows up for
139 * @return Workflow The workflow for the specified user.
140 * @throws WorkflowException
141 */
142 public Workflow retrieveWorkflow(User user) throws WorkflowException
143 {
144 return WorkflowServiceFacade.retrieveWorkflow(user.getName());
145 }
146
147 }