Source code file content
» Project Revision History
» Checkout URL
Access the source code using the following URL:
https://svn.java.net/svn/bpmworklist~worklist
You must be logged in to see SSH URLs.
https://svn.java.net/svn/bpmworklist~worklist
You must be logged in to see SSH URLs.
worklist / trunk / src / main / java / com / oracle / ateam / domain / MTaskList.java
Size: 32735 bytes, 1 line
001.
// Copyright 2009-2011 Oracle Corporation.
002.
// All Rights Reserved.
003.
//
004.
// Provided on an 'as is' basis, without warranties or conditions of any kind,
005.
// either express or implied, including, without limitation, any warranties or
006.
// conditions of title, non-infringement, merchantability, or fitness for a
007.
// particular purpose. You are solely responsible for determining the
008.
// appropriateness of using and assume any risks. You may not redistribute.
009.
//
010.
// Please refer to http://redstack.wordpress.com/worklist for details.
011.
012.
package
com.oracle.ateam.domain;
013.
014.
import
java.util.ArrayList;
015.
import
java.util.Collections;
016.
import
java.util.HashMap;
017.
import
java.util.List;
018.
import
java.util.Map;
019.
import
java.io.InputStream;
020.
import
java.io.OutputStream;
021.
import
java.io.ByteArrayOutputStream;
022.
023.
import
com.oracle.ateam.util.MLog;
024.
025.
import
oracle.bpel.services.workflow.IWorkflowConstants;
026.
import
oracle.bpel.services.workflow.client.IWorkflowServiceClient;
027.
import
oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
028.
import
oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
029.
import
oracle.bpel.services.workflow.query.ITaskQueryService;
030.
import
oracle.bpel.services.workflow.repos.Predicate;
031.
import
oracle.bpel.services.workflow.repos.TableConstants;
032.
import
oracle.bpel.services.workflow.repos.Column;
033.
import
oracle.bpel.services.workflow.task.ITaskService;
034.
import
oracle.bpel.services.workflow.task.model.AnyType;
035.
import
oracle.bpel.services.workflow.task.model.Task;
036.
import
oracle.bpel.services.workflow.task.model.AttachmentType;
037.
import
oracle.bpel.services.workflow.task.model.Attachment;
038.
import
oracle.bpel.services.workflow.task.model.AttachmentImpl;
039.
import
oracle.bpel.services.workflow.task.model.ProcessType;
040.
import
oracle.bpel.services.workflow.task.model.ObjectFactory;
041.
import
oracle.bpel.services.workflow.verification.IWorkflowContext;
042.
import
oracle.bpel.services.workflow.worklist.api.util.WorklistUtil;
043.
import
oracle.bpel.services.workflow.worklist.servlet.Constants;
044.
import
oracle.bpel.services.bpm.common.IBPMContext;
045.
046.
import
oracle.bpm.client.BPMServiceClientFactory;
047.
import
oracle.bpm.services.processmetadata.IProcessMetadataService;
048.
import
oracle.bpm.services.processmetadata.ProcessMetadataSummary;
049.
import
oracle.bpm.services.instancemanagement.model.IProcessInstance;
050.
import
oracle.bpm.services.instancequery.IInstanceQueryInput;
051.
import
oracle.bpm.services.instancequery.impl.InstanceQueryInput;
052.
import
oracle.bpm.services.instancequery.IColumnConstants;
053.
import
oracle.bpm.example.util.ProcessDiagramUtil;
054.
055.
import
javax.servlet.http.HttpServletRequest;
056.
057.
import
org.springframework.web.multipart.MultipartFile;
058.
059.
/**
060.
A wrapper around the BPM API that simplifies access to the API and
061.
handles some caching and 'business' logic.
062.
This class includes a number of methods that wrap the BPM API and
063.
make it easier to consume from our Controllers. All of the detail
064.
of the BPM API is encapsulated in this class so that Controllers
065.
do not need to know about it. It alo handles caching of some
066.
important objects to improve performance.
067.
*/
068.
public
class
MTaskList {
069.
070.
private
static
Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, java.lang.String> properties;
071.
private
static
IWorkflowServiceClient wfsc;
072.
private
static
ITaskQueryService tqs;
073.
private
static
ITaskService ts;
074.
private
static
IWorkflowContext ctx;
075.
private
static
List columns;
076.
private
static
List tasks;
077.
private
static
BPMServiceClientFactory bpmscf;
078.
079.
/**
080.
Retrieve a list of tasks from the workflow engine.
081.
This method retrieves a list of the tasks that match the user,
082.
filter and status provided.
083.
The tasks are NOT fully populated, they just have the basic
084.
details. This method is intended to get a list of tasks with
085.
minimal detail, suitable for displaying on a 'task list' page.
086.
087.
Allowed values for <code>state</code> are
088.
<code>any</code>,
089.
<code>completed</code>,
090.
<code>suspended</code>,
091.
<code>withdrawn</code>,
092.
<code>expired</code>,
093.
<code>errored</code>,
094.
<code>altered</code>,
095.
<code>info</code>.
096.
097.
Allowed values for <code>filter</code> are
098.
<code>me</code>,
099.
<code>group</code>,
100.
<code>megroup</code>,
101.
<code>previous</code>,
102.
<code>reviewer</code>.
103.
104.
@param user The username to return tasks for.
105.
@param filter The filter to apply to the task list. This determines
106.
whether tasks assigned to the user exclusively, or to their group, or
107.
various others are returned.
108.
@param state The status of tasks we want in the output, e.g. assigned,
109.
suspended, errored, etc.
110.
@return A list of tasks, wrapped in the <code>MTask</code> with minimal
111.
details.
112.
*/
113.
public
static
List<MTask> getMTasks(String user, String filter, String state) {
114.
return
getMTasks(user, filter, state,
null
);
115.
}
116.
117.
private
static
List<MTask> getMTasks(String user, Predicate predicate) {
118.
return
getMTasks(user,
null
,
null
, predicate);
119.
}
120.
121.
private
static
List<MTask> getMTasks(String user, String filter, String state, Predicate predicate) {
122.
123.
MLog.log(
"MTaskList"
,
"Entering getMTasks()"
);
124.
125.
try
{
126.
127.
if
(filter ==
null
) filter =
"megroup"
;
128.
if
(state ==
null
) state =
"any"
;
129.
130.
// get login credentials
131.
ctx = ContextCache.getContextCache().get(user);
132.
MLog.log(
"MTaskList"
,
"Got context... "
+ ctx);
133.
134.
// setup query columns
135.
columns =
new
ArrayList();
136.
columns.add(
"TASKID"
);
137.
columns.add(
"TASKNUMBER"
);
138.
columns.add(
"TITLE"
);
139.
columns.add(
"STATE"
);
140.
columns.add(
"OUTCOME"
);
141.
columns.add(
"PRIORITY"
);
142.
143.
Predicate pred;
144.
if
(predicate ==
null
) {
145.
// build predicate
146.
pred =
new
Predicate(TableConstants.WFTASK_STATE_COLUMN,
147.
Predicate.OP_EQ,
148.
IWorkflowConstants.TASK_STATE_ASSIGNED);
149.
if
(
"any"
.compareTo(state) ==
0
) {
150.
pred =
null
;
151.
}
else
if
(
"completed"
.compareTo(state) ==
0
) {
152.
pred =
new
Predicate(TableConstants.WFTASK_STATE_COLUMN,
153.
Predicate.OP_EQ,
154.
IWorkflowConstants.TASK_STATE_COMPLETED);
155.
}
else
if
(
"suspended"
.compareTo(state) ==
0
) {
156.
pred =
new
Predicate(TableConstants.WFTASK_STATE_COLUMN,
157.
Predicate.OP_EQ,
158.
IWorkflowConstants.TASK_STATE_SUSPENDED);
159.
}
else
if
(
"withdrawn"
.compareTo(state) ==
0
) {
160.
pred =
new
Predicate(TableConstants.WFTASK_STATE_COLUMN,
161.
Predicate.OP_EQ,
162.
IWorkflowConstants.TASK_STATE_WITHDRAWN);
163.
}
else
if
(
"expired"
.compareTo(state) ==
0
) {
164.
pred =
new
Predicate(TableConstants.WFTASK_STATE_COLUMN,
165.
Predicate.OP_EQ,
166.
IWorkflowConstants.TASK_STATE_EXPIRED);
167.
}
else
if
(
"errored"
.compareTo(state) ==
0
) {
168.
pred =
new
Predicate(TableConstants.WFTASK_STATE_COLUMN,
169.
Predicate.OP_EQ,
170.
IWorkflowConstants.TASK_STATE_ERRORED);
171.
}
else
if
(
"alerted"
.compareTo(state) ==
0
) {
172.
pred =
new
Predicate(TableConstants.WFTASK_STATE_COLUMN,
173.
Predicate.OP_EQ,
174.
IWorkflowConstants.TASK_STATE_ALERTED);
175.
}
else
if
(
"info"
.compareTo(state) ==
0
) {
176.
pred =
new
Predicate(TableConstants.WFTASK_STATE_COLUMN,
177.
Predicate.OP_EQ,
178.
IWorkflowConstants.TASK_STATE_INFO_REQUESTED);
179.
}
180.
}
else
{
181.
// predicate was provided
182.
pred = predicate;
183.
}
184.
185.
// set assignment filter
186.
ITaskQueryService.AssignmentFilter aFilter = ITaskQueryService.AssignmentFilter.MY_AND_GROUP;
187.
if
(
"me"
.compareTo(filter) ==
0
) {
188.
aFilter = ITaskQueryService.AssignmentFilter.MY;
189.
}
else
if
(
"group"
.compareTo(filter) ==
0
) {
190.
aFilter = ITaskQueryService.AssignmentFilter.GROUP;
191.
}
else
if
(
"megroup"
.compareTo(filter) ==
0
) {
192.
aFilter = ITaskQueryService.AssignmentFilter.MY_AND_GROUP;
193.
}
else
if
(
"previous"
.compareTo(filter) ==
0
) {
194.
aFilter = ITaskQueryService.AssignmentFilter.PREVIOUS;
195.
}
else
if
(
"reviewer"
.compareTo(filter) ==
0
) {
196.
aFilter = ITaskQueryService.AssignmentFilter.REVIEWER;
197.
}
198.
199.
// get list of tasks
200.
MLog.log(
"MTaskList"
,
"About to queryTasks()"
);
201.
boolean
moreTasks =
true
;
202.
tasks =
new
ArrayList();
203.
int
start =
1
;
204.
int
end =
200
;
205.
while
(moreTasks) {
206.
List someTasks = getTaskQueryService().queryTasks(
207.
ctx,
208.
columns,
209.
null
,
// additional info
210.
aFilter,
// asssignment filter
211.
null
,
// keywords
212.
pred,
// custom predicate
213.
null
,
// order
214.
start,
// paging - start
215.
end);
// paging - end
216.
tasks.addAll(someTasks);
217.
if
(someTasks.size() <
200
) {
218.
moreTasks =
false
;
219.
}
else
{
220.
start +=
200
;
221.
end +=
200
;
222.
}
223.
}
224.
225.
// iterate over tasks and build return data
226.
List result =
new
ArrayList<MTask>();
227.
for
(
int
i =
0
; i < tasks.size(); i++) {
228.
Task task = (Task)tasks.get(i);
229.
result.add(
new
MTask(
230.
task.getSystemAttributes().getTaskNumber(),
231.
notNull(task.getTitle()),
232.
notNull(task.getSystemAttributes().getTaskId()),
233.
notNull(task.getSystemAttributes().getOutcome()),
234.
task.getPriority(),
235.
notNull(task.getSystemAttributes().getState())
236.
));
237.
}
238.
239.
// sort the list by priority
240.
Collections.sort(result,
new
MTaskComparator());
241.
242.
return
result;
243.
244.
}
catch
(Exception e) {
245.
e.printStackTrace();
246.
}
247.
return
null
;
248.
}
249.
250.
/**
251.
Get all of the details for a <code>Task</code>.
252.
This method will return all of the details for a <code>Task</code>,
253.
wrapped in an <code>MTask</code> object. This method should be
254.
used to retrieve a task with all of its details populated, suitable
255.
for a task detail View.
256.
@param user The user who wants the task details.
257.
@param taskNumber The number of the task to retireve.
258.
@return The task details, wrapped in an <code>MTask</code>.
259.
*/
260.
public
static
MTask getTaskDetails(String user, String taskNumber) {
261.
MLog.log(
"MTaskList"
,
"Entering getTaskDetails()"
);
262.
263.
try
{
264.
265.
// login
266.
ctx = ContextCache.getContextCache().get(user);
267.
268.
// get task details
269.
Task task = getTaskQueryService().getTaskDetailsByNumber(ctx, Integer.parseInt(taskNumber));
270.
271.
MLog.log(
"MTaskList"
,
"Leaving getTaskDetails()"
);
272.
return
new
MTask(task);
273.
274.
}
catch
(Exception e) {
275.
e.printStackTrace();
276.
}
277.
return
null
;
278.
}
279.
280.
/**
281.
Process a task, i.e. take an action on the task.
282.
This method will process a task. This may mean taking a 'custom' action
283.
on the task, i.e. those defined in the Task Definition as the outcomes
284.
for the task, or taking a 'system' action, e.g. escalate, suspend,
285.
withdraw.
286.
The allowed system actions are:
287.
<code>SYS_ESCALATE</code>,
288.
<code>SYS_WITHDRAW</code>,
289.
<code>SYS_SUSPEND</code>,
290.
<code>SYS_RESUME</code>,
291.
<code>SYS_PURGE</code>,
292.
<code>SYS_ERROR</code>,
293.
<code>SYS_ACQUIRE</code>.
294.
Note that this method will just fail (throw an Exception) if the user
295.
does not have the right to take the action. This needs to be tidied
296.
up in a future version.
297.
@param user The user who wants to take the action.
298.
@param taskNumber The number of task to take the action on.
299.
@param outcome The action to take on the task.
300.
*/
301.
public
static
void
processTask(String user, String taskNumber, String outcome) {
302.
MLog.log(
"MTaskList"
,
"Entering processTask()"
);
303.
304.
try
{
305.
306.
// login
307.
ctx = ContextCache.getContextCache().get(user);
308.
309.
// get task details
310.
Task task = getTaskQueryService().getTaskDetailsByNumber(ctx, Integer.parseInt(taskNumber));
311.
312.
if
(
"SYS_ESCALATE"
.compareTo(outcome) ==
0
) {
313.
getTaskService().escalateTask(ctx, task);
314.
}
else
if
(
"SYS_WITHDRAW"
.compareTo(outcome) ==
0
) {
315.
getTaskService().withdrawTask(ctx, task);
316.
}
else
if
(
"SYS_SUSPEND"
.compareTo(outcome) ==
0
) {
317.
getTaskService().suspendTask(ctx, task);
318.
}
else
if
(
"SYS_RESUME"
.compareTo(outcome) ==
0
) {
319.
getTaskService().resumeTask(ctx, task);
320.
}
else
if
(
"SYS_PURGE"
.compareTo(outcome) ==
0
) {
321.
getTaskService().purgeTask(ctx, task);
322.
}
else
if
(
"SYS_ERROR"
.compareTo(outcome) ==
0
) {
323.
getTaskService().errorTask(ctx, task);
324.
}
else
if
(
"SYS_ACQUIRE"
.compareTo(outcome) ==
0
) {
325.
getTaskService().acquireTask(ctx, task);
326.
}
else
{
327.
// this is a CustomAction
328.
MLog.log(
"MTaskList"
,
"Updating outcome of task "
+ task.getSystemAttributes().getTaskNumber() +
" to "
+ outcome);
329.
getTaskService().updateTaskOutcome(ctx, task.getSystemAttributes().getTaskId(), outcome);
330.
}
331.
332.
MLog.log(
"MTaskList"
,
"Leaving processTask()"
);
333.
334.
}
catch
(Exception e) {
335.
// TODO need to handle execptions properly - if the user does not
336.
// have permission to execute the requested outcome, an
337.
// exception will be thrown
338.
e.printStackTrace();
339.
}
340.
}
341.
342.
/**
343.
Add a comment to a task.
344.
@param user The user who wished to add a comment to the task.
345.
@param taskNumber The number of the task to add the comment to.
346.
@param comment The comment to add to the task.
347.
*/
348.
public
static
void
addComment(String user, String taskNumber, String comment) {
349.
MLog.log(
"MTaskList"
,
"Entering addComment()"
);
350.
351.
try
{
352.
353.
// login
354.
ctx = ContextCache.getContextCache().get(user);
355.
356.
// get task details
357.
Task task = getTaskQueryService().getTaskDetailsByNumber(ctx, Integer.parseInt(taskNumber));
358.
359.
// add the comment
360.
getTaskService();
361.
MLog.log(
"MTaskList"
,
"Adding comment to task "
+ task.getSystemAttributes().getTaskNumber() +
": "
+ comment);
362.
getTaskService().addComment(ctx, task.getSystemAttributes().getTaskId(), comment);
363.
364.
MLog.log(
"MTaskList"
,
"Leaving addComment()"
);
365.
366.
}
catch
(Exception e) {
367.
e.printStackTrace();
368.
}
369.
}
370.
371.
/**
372.
Add an attachment to a task.
373.
@param user The user who wishes to add an attachment to the task.
374.
@param taskNumber The number of the task to add the attachment to.
375.
@param attachment The attachment to add to the task.
376.
*/
377.
public
static
void
addAttachment(String user, String taskNumber, MultipartFile attachment) {
378.
MLog.log(
"MTaskList"
,
"Entering addAttachment()"
);
379.
380.
try
{
381.
382.
// login
383.
ctx = ContextCache.getContextCache().get(user);
384.
385.
// get task details
386.
Task task = getTaskQueryService().getTaskDetailsByNumber(ctx, Integer.parseInt(taskNumber));
387.
388.
// add the attachment
389.
getTaskService();
390.
MLog.log(
"MTaskList"
,
"Adding attachment to task "
+ task.getSystemAttributes().getTaskNumber());
391.
392.
// OLD API (which did not work anyway)
393.
//AttachmentType xAttachment = new AttachmentImpl();
394.
//xAttachment.setInputStream(attachment.getInputStream());
395.
396.
// NEW API - from 11.1.1.5.1
397.
AttachmentType xAttachment =
new
ObjectFactory().createAttachment();
398.
xAttachment.setName(attachment.getOriginalFilename());
399.
xAttachment.setInputStream(attachment.getInputStream());
400.
xAttachment.setMimeType(attachment.getContentType());
401.
xAttachment.setDescription(attachment.getOriginalFilename());
402.
403.
getTaskService().addAttachment(ctx, task.getSystemAttributes().getTaskId(), xAttachment);
404.
405.
MLog.log(
"MTaskList"
,
"Leaving addAttachment()"
);
406.
407.
}
catch
(Exception e) {
408.
e.printStackTrace();
409.
}
410.
411.
}
412.
413.
/**
414.
Gets the taskId for the given taskNumber.
415.
@param taskNumber The taskNumber for the task you want the taskId for.
416.
@return The taskId for the given task.
417.
*/
418.
public
static
String getTaskIdFromNumber(String taskNumber, String user) {
419.
MLog.log(
"MTaskList"
,
"Entering getTaskIdFromNumber()"
);
420.
421.
try
{
422.
423.
// retrieve context
424.
ctx = ContextCache.getContextCache().get(user);
425.
426.
// get task details
427.
Task task = getTaskQueryService().getTaskDetailsByNumber(ctx, Integer.parseInt(taskNumber));
428.
429.
// return the taskId
430.
MLog.log(
"MTaskList"
,
"Leaving getTaskIdFromNumber()"
);
431.
return
task.getSystemAttributes().getTaskId();
432.
433.
}
catch
(Exception e) {
434.
e.printStackTrace();
435.
}
436.
return
null
;
437.
438.
}
439.
440.
/**
441.
Attempt to authenticate the user with the workflow engine.
442.
The user must be logged in to WebLogic Server for this method to work.
443.
If the user is logged in to WebLogic, their <code>HttpServletRequest</code>
444.
will be authenticated. This is required to use this method.
445.
If the user is successfully authenticated to the workflow engine, their
446.
credentials, i.e. a <code>IWorkflowContext</code>, will be added to the
447.
<code>ContextCache</code> using their username as the key. The username is
448.
obtained by calling <code>HttpServletRequest.getRemoteUser()</code>.
449.
@param request The pre-authenticated <code>HttpServletRequest</code> for the user.
450.
@return <code>true</code> if the user was authenticated successfully,
451.
<code>false</code> otherwise.
452.
*/
453.
public
static
boolean
login(HttpServletRequest request) {
454.
MLog.log(
"MTaskList"
,
"Entering login()"
);
455.
456.
try
{
457.
458.
// login
459.
ctx = getTaskQueryService().createContext(request);
460.
MLog.log(
"MTaskList"
,
"ctx="
+ ctx);
461.
462.
// save the context in the cache
463.
MLog.log(
"MTaskList"
,
"+++ request.getRemoteUser() returns "
+ request.getRemoteUser());
464.
String user = ((request.getUserPrincipal() ==
null
) ?
null
: request.getUserPrincipal().getName());
465.
if
(user ==
null
) {
466.
MLog.log(
"MTaskList"
,
"Problem getting user principal from request"
);
467.
return
false
;
468.
}
469.
ContextCache.getContextCache().put(user, ctx);
470.
471.
MLog.log(
"MTaskList"
,
"Leaving login() ... success"
);
472.
return
true
;
473.
474.
}
catch
(Exception e) {
475.
e.printStackTrace();
476.
}
477.
MLog.log(
"MTaskList"
,
"Leaving login() ... failed"
);
478.
return
false
;
479.
}
480.
481.
/**
482.
Retrieve a list of the tasks that the specified user is able to initiate.
483.
@param user The user you want a list of initiatable tasks for.
484.
@return A list of the tasks that the user can initiate.
485.
*/
486.
public
static
List<ProcessMetadataSummary> getInitiateLinks(String user) {
487.
MLog.log(
"MTaskList"
,
"Entering getInitiateLinks()"
);
488.
489.
try
{
490.
491.
// get the process metadata service
492.
IProcessMetadataService pms = getBPMServiceClientFactory().getBPMServiceClient().getProcessMetadataService();
493.
494.
// get the list of initiatable proceses
495.
List<ProcessMetadataSummary> result = pms.getInitiatableProcesses(
496.
(IBPMContext) ContextCache.getContextCache().get(user));
497.
MLog.log(
"MTaskList"
,
"Leaving getInitiateLinks()"
);
498.
return
result;
499.
500.
}
catch
(Exception e) {
501.
e.printStackTrace();
502.
}
503.
MLog.log(
"MTaskList"
,
"Leaving getInitiateLinks() ... failed"
);
504.
return
null
;
505.
506.
}
507.
508.
/**
509.
Initiate a task (and therefore start a process instance) and obtain a
510.
URL to open the task form.
511.
@param user The user who wants to initiate the task.
512.
@param compositeDN The unique identifier of the task to initiate.
513.
@return The URL to open the task form.
514.
*/
515.
public
static
String initiateTask(String user, String compositeDN) {
516.
MLog.log(
"MTaskList"
,
"Entering initiateTask()"
);
517.
518.
try
{
519.
520.
MLog.log(
"MTaskList"
,
"got a request to initiate task "
+ compositeDN +
" for user "
+ user);
521.
Map parameters =
new
HashMap();
522.
Task task = getBPMServiceClientFactory().getBPMServiceClient().getInstanceManagementService().createProcessInstanceTask(
523.
(IBPMContext) ContextCache.getContextCache().get(user),
524.
compositeDN);
525.
parameters.put(Constants.BPM_WORKLIST_TASK_ID, task.getSystemAttributes().getTaskId());
526.
parameters.put(Constants.BPM_WORKLIST_CONTEXT, ContextCache.getContextCache().get(user).getToken());
527.
// TODO fix this - serverUrl is looked up now, but contextRoot is still hardcoded
528.
parameters.put(Constants.BPM_PARENT_URL, getServerURL() +
"/worklist"
);
529.
String url = WorklistUtil.getTaskDisplayURL(
530.
getBPMServiceClientFactory().getWorkflowServiceClient(),
531.
ContextCache.getContextCache().get(user),
532.
task,
533.
null
,
534.
"worklist"
,
535.
parameters);
536.
return
url;
537.
538.
}
catch
(Exception e) {
539.
e.printStackTrace();
540.
}
541.
return
null
;
542.
}
543.
544.
/**
545.
Get a list of instances in the given state.
546.
@param user The user who wants the list.
547.
@param state The desired state.
548.
@return A list of instances.
549.
*/
550.
public
static
List<IProcessInstance> queryInstances(String user, String state) {
551.
MLog.log(
"MTaskList"
,
"Entering queryInstances()"
);
552.
553.
try
{
554.
List<Column> displayColumns =
new
ArrayList<Column>();
555.
displayColumns.add(IColumnConstants.PROCESS_ID_COLUMN);
556.
displayColumns.add(IColumnConstants.PROCESS_PROCESSNAME_COLUMN);
557.
displayColumns.add(IColumnConstants.PROCESS_STATE_COLUMN);
558.
displayColumns.add(IColumnConstants.PROCESS_TITLE_COLUMN);
559.
displayColumns.add(IColumnConstants.PROCESS_CREATOR_COLUMN);
560.
displayColumns.add(IColumnConstants.PROCESS_CREATEDDATE_COLUMN);
561.
562.
/* other columns....
563.
displayColumns.add(IColumnConstants.PROCESS_ACTIVITYID_COLUMN);
564.
displayColumns.add(IColumnConstants.PROCESS_ACTIVITYNAME_COLUMN);
565.
displayColumns.add(IColumnConstants.PROCESS_APPLICATIONCONTEXT_COLUMN);
566.
displayColumns.add(IColumnConstants.PROCESS_APPLICATIONNAME_COLUMN);
567.
displayColumns.add(IColumnConstants.PROCESS_COMPONENTNAME_COLUMN);
568.
displayColumns.add(IColumnConstants.PROCESS_COMPONENTTYPE_COLUMN);
569.
displayColumns.add(IColumnConstants.PROCESS_COMPOSITEDN_COLUMN);
570.
displayColumns.add(IColumnConstants.PROCESS_COMPOSITEINSTANCEID_COLUMN);
571.
displayColumns.add(IColumnConstants.PROCESS_COMPOSITENAME_COLUMN);
572.
displayColumns.add(IColumnConstants.PROCESS_COMPOSITEVERSION_COLUMN);
573.
displayColumns.add(IColumnConstants.PROCESS_DUEDATE_COLUMN);
574.
displayColumns.add(IColumnConstants.PROCESS_ENDDATE_COLUMN);
575.
displayColumns.add(IColumnConstants.PROCESS_EXPIRATIONDATE_COLUMN);
576.
displayColumns.add(IColumnConstants.PROCESS_EXPIRATIONDURATION_COLUMN);
577.
displayColumns.add(IColumnConstants.PROCESS_IDENTITYCONTEXT_COLUMN);
578.
displayColumns.add(IColumnConstants.PROCESS_INSTANCEID_COLUMN);
579.
displayColumns.add(IColumnConstants.PROCESS_NUMBER_COLUMN);
580.
displayColumns.add(IColumnConstants.PROCESS_NUMBEROFTIMESMODIFIED_COLUMN);
581.
displayColumns.add(IColumnConstants.PROCESS_OWNERGROUP_COLUMN);
582.
displayColumns.add(IColumnConstants.PROCESS_OWNERROLE_COLUMN);
583.
displayColumns.add(IColumnConstants.PROCESS_OWNERUSER_COLUMN);
584.
displayColumns.add(IColumnConstants.PROCESS_PARENTTHREAD_COLUMN);
585.
displayColumns.add(IColumnConstants.PROCESS_PROCESSDEFINITIONID_COLUMN);
586.
displayColumns.add(IColumnConstants.PROCESS_PROCESSDEFINITIONNAME_COLUMN);
587.
*/
588.
589.
IInstanceQueryInput input =
new
InstanceQueryInput();
590.
if
(state ==
null
) state =
"running"
;
591.
592.
if
(
"running"
.equals(state)) {
593.
input.addState(IInstanceQueryInput.PROCESS_STATE_OPEN);
594.
}
else
if
(
"completed"
.equals(state)) {
595.
input.addState(IInstanceQueryInput.PROCESS_STATE_COMPLETE);
596.
}
else
if
(
"canceled"
.equals(state)) {
597.
input.addState(IInstanceQueryInput.PROCESS_CANCEL_STATE);
598.
input.addState(IInstanceQueryInput.PROCESS_ABORT_STATE);
599.
}
else
if
(
"errored"
.equals(state)) {
600.
input.addState(IInstanceQueryInput.PROCESS_ERRORED_STATE);
601.
}
602.
input.setAssignmentFilter(IInstanceQueryInput.AssignmentFilter.ALL);
603.
604.
return
getBPMServiceClientFactory()
605.
.getBPMServiceClient()
606.
.getInstanceQueryService()
607.
.queryInstances(
608.
(IBPMContext) ContextCache.getContextCache().get(user),
609.
displayColumns,
610.
null
,
611.
null
,
612.
input);
613.
614.
}
catch
(Exception e) {
615.
e.printStackTrace();
616.
}
617.
return
null
;
618.
}
619.
620.
/**
621.
Get details for the specified instance.
622.
@param user The user who wants the list.
623.
@param instanceId The desired process instance.
624.
@return Details for the specified instance.
625.
*/
626.
public
static
IProcessInstance getInstanceDetails(String user, String instanceId) {
627.
MLog.log(
"MTaskList"
,
"Entering getInstanceDetails()"
);
628.
MLog.log(
"MTaskList"
,
"Got request for instanceId "
+ instanceId);
629.
630.
try
{
631.
632.
return
getBPMServiceClientFactory()
633.
.getBPMServiceClient()
634.
.getInstanceQueryService()
635.
.getProcessInstance(
636.
(IBPMContext) ContextCache.getContextCache().get(user),
637.
instanceId);
638.
639.
}
catch
(Exception e) {
640.
e.printStackTrace();
641.
}
642.
return
null
;
643.
}
644.
645.
/**
646.
Get list of tasks for the specified process instance.
647.
@param user The user who wants the list.
648.
@param instanceId The desired process instance.
649.
@return Details for the specified instance.
650.
*/
651.
public
static
List<MTask> findTasksForProcess(String user, String processInstanceId) {
652.
MLog.log(
"MTaskList"
,
"Entering findTasksForProcess()"
);
653.
654.
try
{
655.
Predicate instancePredicate =
new
Predicate(TableConstants.WFTASK_INSTANCEID_COLUMN, Predicate.OP_EQ, processInstanceId);
656.
return
getMTasks(user, instancePredicate);
657.
}
catch
(Exception e) {
658.
e.printStackTrace();
659.
}
660.
return
null
;
661.
}
662.
663.
664.
/**
665.
Get the process instance ID for the process instance that is associated
666.
with the given task number.
667.
@param taskNumber The task number for the task you want the process instanceId for.
668.
@param user The user who wants this information.
669.
@return The process instance ID associated with the specified task number, or
670.
<code>null</code> in the event of an error.
671.
*/
672.
public
static
String getProcessInstanceId(String user, String taskNumber) {
673.
MLog.log(
"MTaskList"
,
"Entering getProcessInstanceId()"
);
674.
675.
try
{
676.
677.
// retrieve context
678.
ctx = ContextCache.getContextCache().get(user);
679.
680.
// get task details
681.
Task task = getTaskQueryService().getTaskDetailsByNumber(ctx, Integer.parseInt(taskNumber));
682.
683.
// return the process instanceId
684.
ProcessType processInfo = task.getProcessInfo();
685.
if
(processInfo !=
null
) {
686.
return
processInfo.getInstanceId();
687.
}
688.
MLog.log(
"MTaskList"
,
"Leaving getProcessInstanceId()"
);
689.
690.
}
catch
(Exception e) {
691.
e.printStackTrace();
692.
}
693.
return
null
;
694.
}
695.
696.
697.
698.
/**
699.
*/
700.
public
static
String getServerURL() {
701.
try
{
702.
703.
MLog.log(
"MTaskList"
,
"Entering getServerURL"
);
704.
705.
// set up connection properties
706.
properties =
new
707.
HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,java.lang.String>();
708.
709.
// create workflow service client
710.
wfsc = WorkflowServiceClientFactory.getWorkflowServiceClient(
711.
WorkflowServiceClientFactory.REMOTE_CLIENT, properties,
null
);
712.
713.
// get the server URL
714.
MLog.log(
"MTaskList"
,
"Leaving getServerURL"
);
715.
return
wfsc.getRuntimeConfigService().getServerURLFromFabricConfig();
716.
717.
}
catch
(Exception e) {
718.
return
null
;
719.
}
720.
721.
}
722.
723.
/**
724.
Utility method to ensure that a <code>String</code> is not <code>null</code>.
725.
@param input The <code>String</code> that you wish to ensure is not <code>null</code>.
726.
@return A <code>String</code> equivalent to the input, except that it is guaranteed to
727.
be not <code>null</code>.
728.
*/
729.
private
static
String notNull(String input) {
730.
if
(input ==
null
)
return
""
;
731.
return
input;
732.
}
733.
734.
/**
735.
Get the graphical audit image for a given process instance.
736.
@param user The user who wants the image.
737.
@param instanceId The instanceId for the process instance you want the audit image for.
738.
@return An <code>OutputStream</code> containing the image.
739.
*/
740.
public
static
InputStream getAuditImage(String user, String instanceId) {
741.
MLog.log(
"MTaskList"
,
"Entering getAuditImage()"
);
742.
743.
try
{
744.
745.
// get the utility class which will retrieve the image for us
746.
ProcessDiagramUtil pdu =
new
ProcessDiagramUtil(
747.
getBPMServiceClientFactory().getBPMServiceClient());
748.
MLog.log(
"MTaskList"
,
"Got the PDU "
+ pdu.toString());
749.
// get the image for the requested instance
750.
InputStream auditDiagramData =
null
;
751.
try
{
752.
MLog.log(
"MTaskList"
,
"About to call ProcessDiagramUtil.getProcessAuditDiagram()"
);
753.
auditDiagramData = pdu.getProcessAuditDiagram(
754.
(IBPMContext) ContextCache.getContextCache().get(user), instanceId);
755.
}
catch
(Exception e) {
756.
MLog.log(
"MTaskList"
,
"Got Exception in ProcessDiagramUtil.getProcessAuditDiagram()"
);
757.
e.printStackTrace();
758.
}
759.
MLog.log(
"MTaskList"
,
"Got image data, image is "
+ ((auditDiagramData ==
null
) ?
"null"
:
"not null"
));
760.
// if there is no data in the image, return null
761.
if
(auditDiagramData ==
null
) {
762.
return
null
;
763.
}
764.
return
auditDiagramData;
765.
766.
}
catch
(Exception e) {
767.
e.printStackTrace();
768.
}
769.
return
null
;
770.
}
771.
772.
/**
773.
Retrieve the Task Query Service.
774.
This method will retrieve the Task Query Service. As this is not specific to a user,
775.
it is cached to improve performance. This method will create the <code>TaskQueryService</code>
776.
if it does not exist.
777.
@return The <code>TaskQueryService</code>.
778.
*/
779.
private
static
ITaskQueryService getTaskQueryService() {
780.
781.
if
(tqs ==
null
) {
782.
try
{
783.
784.
MLog.log(
"MTaskList"
,
"Initialising the Task Query Service"
);
785.
786.
// set up connection properties
787.
properties =
new
788.
HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,java.lang.String>();
789.
790.
// create workflow service client
791.
wfsc = WorkflowServiceClientFactory.getWorkflowServiceClient(
792.
WorkflowServiceClientFactory.REMOTE_CLIENT, properties,
null
);
793.
794.
// get the task query service
795.
tqs = wfsc.getTaskQueryService();
796.
797.
}
catch
(Exception e) {
798.
return
null
;
799.
}
800.
}
801.
return
tqs;
802.
}
803.
804.
/**
805.
Retrieve the Task Service.
806.
This method will retrieve the Task Service. As this is not specific to a user,
807.
it is cached to improve performance. This method will create the <code>ITaskService</code>
808.
if it does not exist.
809.
@return The <code>ITaskService</code>.
810.
*/
811.
private
static
ITaskService getTaskService() {
812.
813.
if
(ts ==
null
) {
814.
try
{
815.
816.
MLog.log(
"MTaskList"
,
"Initialising the Task Service"
);
817.
818.
// set up connection properties
819.
properties =
new
820.
HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,java.lang.String>();
821.
822.
// create workflow service client
823.
wfsc = WorkflowServiceClientFactory.getWorkflowServiceClient(
824.
WorkflowServiceClientFactory.REMOTE_CLIENT, properties,
null
);
825.
826.
// get the task query service
827.
ts = wfsc.getTaskService();
828.
829.
}
catch
(Exception e) {
830.
return
null
;
831.
}
832.
}
833.
return
ts;
834.
}
835.
836.
/**
837.
Retrieve the BPM Service Client Factory.
838.
This method will retrieve the BPM Service Client Factory. As this is not specific to a user,
839.
it is cached to improve performance. This method will create the <code>BPMServiceClientFactory</code>
840.
if it does not exist.
841.
@return The <code>BPMServiceClientFactory</code>.
842.
*/
843.
protected
static
BPMServiceClientFactory getBPMServiceClientFactory() {
844.
845.
if
(bpmscf ==
null
) {
846.
MLog.log(
"MTaskList"
,
"Initialising the BPM Service Client Factory"
);
847.
848.
// set up connection properties
849.
properties =
new
850.
HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,java.lang.String>();
851.
852.
// create workflow service client
853.
wfsc = WorkflowServiceClientFactory.getWorkflowServiceClient(
854.
WorkflowServiceClientFactory.REMOTE_CLIENT, properties,
null
);
855.
856.
// get the bpm client service factory
857.
bpmscf = BPMServiceClientFactory.getInstance(properties,
null
,
null
);
858.
859.
}
860.
return
bpmscf;
861.
862.
}
863.
864.
}