![]() |
![]() |
|
|
Managing Run-Time Tasks
Once you have started a workflow, as described in Manually Starting Workflows, you can manage the tasks associated with the running instance. This section describes how to manage run-time tasks, including the following topics:
For information about managing run-time tasks using Worklist, see Working with Tasks in Using the WebLogic Integration Worklist.
Getting a Task
To get a task, use the following com.bea.wlpi.server.worklist.Worklist method:
public com.bea.wlpi.common.TaskInfo getTask(
java.lang.String taskName,
java.lang.String instanceId,
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
The following table describes the parameters for the getTask() method for which you must specify values.
Table 21-1 getTask() Method Parameters
This method returns a com.bea.wlpi.common.TaskInfo object. To access information about the task, use the TaskInfo object methods described in TaskInfo Object.
For example, the following code gets the Task1 task for the specified workflow instance. In this example, worklist represents the EJBObject reference to the Worklist EJB.
TaskInfo task = worklist.getTask("Task1",instanceID);
For more information about the getTask() method, see the com.bea.wlpi.server.worklist.Worklist Javadoc.
Getting All Tasks
To get a list of tasks associated with a particular participant (user or role) and organization, use one of the following com.bea.wlpi.server.worklist.Worklist methods:
public java.util.List getTasks(
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
public java.util.List getTasks(
java.lang.String orgId,
java.lang.String assigneeId,
boolean isRole
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
The first method gets the tasks assigned to the user in the active organization that created the EJBObject reference to the Worklist EJB. The second method gets the tasks assigned to the specified organization and assignee (role or user).
The following table describes the parameters for the second getTasks() method for which you must specify values.
Table 21-2 getTasks() Method Parameters
Each method returns a list of com.bea.wlpi.common.TaskInfo objects. To access information about each task, use the TaskInfo object methods described in TaskInfo Object.
For example, the following code gets the tasks for the current user in the active organization. In this example, worklist represents the EJBObject reference to the Worklist EJB.
List taskList = worklist.getTasks();
The following code gets a list of the tasks for the ROLE1 role in the ORG1 organization (as the isRole parameter is set to true). In this example, worklist represents the EJBObject reference to the Worklist EJB.
List taskList = worklist.getTasks("ORG1", "ROLE1", true);
For more information about the getTasks() methods, see the com.bea.wlpi.server.worklist.Worklist Javadoc.
Getting Task Counts
To get the number of assigned and overdue tasks for the current user, use the following com.bea.wlpi.server.worklist.Worklist method:
public java.lang.String getTaskCounts(
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
The method returns a two-element array. The first element specifies the number of tasks assigned to the user; the second element specifies the number of those tasks that are overdue.
For example, the following code gets the counts for the assigned and overdue tasks for the current user, and stores the counts in the taskCounts[] array. In this example, worklist represents the EJBObject reference to the Worklist EJB.
int taskCounts[] = worklist.getTaskCounts();
Counts of assigned and overdue tasks are stored in the taskCounts[0] and taskCounts[1] elements, respectively.
For more information about the getTaskCounts() method, see the com.bea.wlpi.server.worklist.Worklist Javadoc.
Executing a Task
To execute a task, use one of the following com.bea.wlpi.server.worklist.Worklist methods:
public java.lang.String taskExecute(
java.lang.String taskName,
java.lang.String instanceId
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
public java.lang.String taskExecute(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String taskId
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
The following table describes the taskExecute() method parameters for which you must specify values.
Table 21-3 taskExecute() Method Parameters
This method results in the sequential execution of all the actions associated with the specified task's Executed event for the specified task. For information about defining the Executed event for a task, see Template Definition DTD.
This method returns an XML document that is compliant with the Client Request DTD, ClientReq.dtd, as described in Client Request DTD. The XML document contains information about the running instance, and can be accessed by parsing the document using an XML parser, such as a SAX (Simple API for XML) parser. For example implementations of a SAX parser, see Examples of Managing Run-Time Tasks.
For example, the following code executes the specified task and assigns the resulting XML to the clientReq string. In this example, worklist represents the EJBObject reference to the Worklist EJB.
String clientReq = worklist.taskExecute(
task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId()
);
The template definition, workflow instance, and task IDs are obtained using the methods associated with the com.bea.wlpi.common.TaskInfo object, task. The task object can be obtained using the methods described in Getting All Tasks.
For more information about the com.bea.wlpi.common.TaskInfo methods, see TaskInfo Object.
For more information about the taskExecute() methods, see the com.bea.wlpi.server.worklist.Worklist Javadoc.
Responding to a Client Request
When defining a workflow, you can establish a communication channel between the running instance (via the process engine) and the client program, by creating integration actions. These actions, typically Send XML to Client actions, send a request to a client through an XML document that is compliant with a standard or custom DTD. For example, the action of sending a request to a client may be implemented through a dialog box.
A response from the client is expected. The originating action typically uses the XPath function to extract the required values from the response. For information about XPath, see:
For information about defining integration actions within a workflow, see Template Definition DTD.
To respond to a request raised by a Send XML to Client action (ActionSendXMLToClient), use one of the following com.bea.wlpi.server.worklist.Worklist methods:
Method 1
public java.lang.String response(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String nodeId,
java.lang.Object data
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
Method 2
public java.lang.String response(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String nodeId,
java.lang.Object data,
java.lang.Object transactionId
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
Method 3
public java.lang.String response(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String nodeId,
java.lang.String xml
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
Method 4
public java.lang.String response(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String nodeId,
java.lang.String xml,
java.lang.Object transactionId
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
The following table describes the response() method parameters for which you must specify values.
Table 21-4 response() Method Parameters
The response() method sets the callback variables and sequentially executes all of the actions. For information about defining callback variables and actions, see Template Definition DTD.
This method returns an XML document that is compliant with the Client Request DTD, ClientReq.dtd, as described in Client Request DTD. The XML document contains information about the running instance, and can be accessed by parsing the document using an XML parser, such as a SAX (Simple API for XML) parser. For example implementations of a SAX parser, see Examples of Managing Run-Time Tasks.
For example, the following code sends a response to the server and stores the return value in the clientReq variable.
String clientReq = worklist.response( templateDefinitionId,
instanceId, actionId, response.toString() );
For a more complete example, see Responding to a Client Request. For more information about the response() methods, see the com.bea.wlpi.server.worklist.Worklist Javadoc.
Assigning a Task
To change the user or role to which a task is assigned or to revoke a task assignment, use one of the following com.bea.wlpi.server.worklist.Worklist methods:
Method 1
public java.lang.String taskAssign(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String taskId,
java.lang.String assigneeId,
boolean isRole,
boolean bLoadBalance
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
Method 2
public java.lang.String taskAssign(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String taskId,
java.lang.String assigneeId,
boolean isRole,
boolean bLoadBalance,
java.lang.Object transactionId
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
Method 3
public java.lang.String taskUnassign(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String taskId
) throws RemoteException, WorkflowException
The following table describes the parameters required by the taskAssign() and taskUnassign() methods for which you must specify values.
Table 21-5 taskAssign() and taskUnassign() Method Parameters
When selecting an assignee, consider the following:
These methods return an XML document that is compliant with the Client Request DTD, ClientReq.dtd, as described in Client Request DTD. The XML document contains information about the running instance, and can be accessed by parsing the document using an XML parser, such as a SAX (Simple API for XML) parser. For example implementations of a SAX parser, see Examples of Managing Run-Time Tasks.
For example, the following code assigns a task to the user joe, and assigns the resulting XML to the clientReq string. In this example, worklist represents the EJBObject reference to the Worklist EJB.
String clientReq = worklist.taskAssign(
task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId(),
"joe",
false,
false
);
The following code revokes the assignment for the same task.
String clientReq = worklist.taskUnassign(
task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId(),
"joe",
false,
false
);
The template definition, workflow instance, and task IDs are obtained using the methods associated with the com.bea.wlpi.common.TaskInfo object, task. The task object can be obtained using the methods described in Getting All Tasks.
For more information about the com.bea.wlpi.common.TaskInfo methods, see TaskInfo Object, or the com.bea.wlpi.common.TaskInfo Javadoc.
For more information about the taskAssign() and taskUnassign() methods, see the com.bea.wlpi.server.worklist.Worklist Javadoc.
Marking a Task as Complete or Incomplete
To mark a task as complete (done) or incomplete (undone), use one of the following com.bea.wlpi.server.worklist.Worklist methods:
Method 1
public java.lang.String taskMarkDone(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String taskId
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
Method 2
public java.lang.String taskMarkDone(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String taskId,
java.lang.Object transactionId
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
Method 3
public java.lang.String taskUnmarkDone(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String taskId
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
The following table describes the taskMarkDone() and taskMarkUndone() method parameters for which you must specify values.
Table 21-6 taskMarkDone() and taskMarkUndone() Method Parameters
The taskMarkDone() method sets the task Completed value to the current date and time, and initiates the sequential execution of all the actions associated with the Marked Done event for the specified task. The taskMarkDone() method, however, has no effect on a task that has already been marked complete. For information about defining the Marked Done event for a task, see Template Definition DTD.
The taskUnmarkDone() method clears the Completed date. The method does not execute the actions associated with the Activated event for the specified task.
This method returns an XML document that is compliant with the Client Request DTD, ClientReq.dtd, as described in Client Request DTD. The XML document contains information about the running instance, and can be accessed by parsing the document using an XML parser, such as a SAX (Simple API for XML) parser. For example implementations of a SAX parser, see Examples of Managing Run-Time Tasks.
For example, the following code marks the specified task as complete, sets the Completed value to the current date and time, executes the actions associated with the Marked Done event for the specified task, and assigns the resulting XML to the clientReq string. In this example, worklist represents the EJBObject reference to the Worklist EJB.
String clientReq = worklist.taskMarkDone(
task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId()
);
The following code marks the same task as incomplete, clears the Completed date, and assigns the resulting XML to the clientReq string.
String clientReq = worklist.taskMarkUndone(
task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId()
);
The template definition, workflow instance, and task IDs are obtained using the methods associated with the com.bea.wlpi.common.TaskInfo object, task. The task object can be obtained using the methods described in Getting All Tasks.
For more information about the com.bea.wlpi.common.TaskInfo methods, see TaskInfo Object, or the com.bea.wlpi.common.TaskInfo Javadoc.
For more information about the taskMarkDone() and taskMarkUndone() methods, see the com.bea.wlpi.server.worklist.Worklist Javadoc.
Setting Task Properties
To set task properties, use the following com.bea.wlpi.server.worklist.Worklist method:
public java.lang.String taskSetProperties(
java.lang.String templateDefinitionId,
java.lang.String instanceId,
java.lang.String taskId,
int priority,
boolean doneWithoutDoit,
boolean doitIfDone,
boolean unmarkDone,
boolean modifiable,
boolean reassignment
) throws java.rmi.RemoteException,
com.bea.wlpi.common.WorkflowException
The following table describes the taskSetProperties() method parameters for which you must specify values.
Table 21-7 taskSetProperties() Method Parameters
This method returns an XML document that is compliant with the Client Request DTD, ClientReq.dtd, as described in Client Request DTD. The XML document contains information about the running instance, and can be accessed by parsing the document using an XML parser, such as a SAX (Simple API for XML) parser. For example implementations of a SAX parser, see Examples of Managing Run-Time Tasks.
For example, the following code sets the default task priority to medium (1), enables (sets to true) all other task properties, and stores the resulting XML document in the clientReq variable. In this example, worklist represents the EJBObject reference to the Worklist EJB.
String clientReq = worklist.taskSetProperties(
task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId(),
1,
true,
true,
true,
true,
true
);
The template definition, workflow instance, and task IDs are obtained using the methods associated with the com.bea.wlpi.common.TaskInfo object, task. The task object can be obtained using the methods described in Getting All Tasks.
For more information about the com.bea.wlpi.common.TaskInfo methods, see TaskInfo Object, or the com.bea.wlpi.common.TaskInfo Javadoc.
For more information about the taskSetProperties() method, see the com.bea.wlpi.server.worklist.Worklist Javadoc.
Updating an Instance Variable
For information about updating workflow instance variables, see Monitoring Run-Time Variables.
Invoking an Exception Handler
For information about invoking an exception handler, see Invoking a Workflow Exception Handler.
Examples of Managing Run-Time Tasks
The following sections provide excerpts from the command-line and JSP worklist examples showing how to manage run-time tasks, including an implementation of the Xerces SAX parser.
Command-Line Worklist Example
This section provides excerpts from the command-line worklist example showing how to manage run-time tasks.
Note: For more information about the command-line worklist example, see Command-Line Worklist Example.
This example prompts the user to specify one of the following actions to perform:
The applicable sections of code are provided below, and the notable lines are shown in bold. In this example, worklist represents the EJBObject reference to the Worklist EJB.
In this example, an input stream is defined to communicate with the user, and the user is prompted to specify one of the following actions to be performed:
/* Create an input stream to communicate with the user */
stdIn = new BufferedReader( new InputStreamReader( System.in ) )
/* Display Tool Title */
System.out.print( "\n--- Command Line Worklist v1.2 ---" );
/* Display the main menu and interact with user */
while( true ) {
/* Display the menu */
System.out.println( "\n--- Main Menu ---" );
System.out.println( "\nEnter choice:" );
System.out.println( "1) Organizations" );
System.out.println( "2) Workflows" );
System.out.println( "3) Tasks" );
System.out.println( "Q) Quit" );
System.out.print( ">> " );
.
.
.
The mngTasks() method shows how to manage run-time tasks, interacting with the user to retrieve the information required.
public static void mngTasks( ) {
boolean isForCurrentUser;
boolean isRole, isUserInRole;
boolean isDoneWithoutDoit, isDoitIfDone, isUnmarkDone, isModifiable,
isReassignment;
int priority;
String answer;
String assigneeId, instanceId, orgId, taskId, templateDefId;
/* Create an input stream to communicate with the user */
BufferedReader stdIn = new BufferedReader(
new InputStreamReader( System.in ) );
try {
/* Display the main menu and interact with user */
while( true ) {
/* Display the menu */
System.out.println( "\n\n--- Tasks ---" );
System.out.println( "\nEnter choice:" );
System.out.println( "1) Get Tasks Count" );
System.out.println( "2) List Tasks" );
System.out.println( "3) Assign a Task" );
System.out.println( "4) Execute a Task" );
System.out.println( "5) Mark a Task as Done" );
System.out.println( "6) Set Task Properties" );
System.out.println( "7) Unassign a Task" );
System.out.println( "8) Unmark a Task as Done" );
System.out.println( "B) Back to previous menu" );
System.out.println( "Q) Quit" );
System.out.print( ">> " );
/* Get the user's selection */
String line = stdIn.readLine( );
/* User pressed enter without making a selection ? */
if( line.equals( "" ) )
continue;
/* User entered more than one char ? */
else if( line.length( ) > 1 ) {
System.out.println( "*** Invalid choice" );
continue;
}
/* Convert to uppercase and to char */
char choice = line.toUpperCase( ).charAt( 0 );
/* Process user's selection */
switch( choice ) {
.
.
.
Getting Task Counts
The following excerpt shows how to get task counts.
/* Get Tasks Count */
case '1' :
/* WLPI Public API Method */
/* NOTE: Would be nice to add code to capture any
* thrown exceptions */
/* Retrieve the task count for the current user in an array */
/* Array element 0 = Total tasks assigned */
/* Array element 1 = Tasks assigned that are overdue */
int taskCounts[] = worklist.getTaskCounts();
/* Any task assigned ? */
if( taskCounts[0] == 0 )
System.out.println( "\nNo task assigned" );
else {
System.out.println( "\nTasks count:" );
if( taskCounts[0] == 1 )
System.out.println( "- 1 task assigned" );
else
System.out.println( "- " + taskCounts[0] + " tasks assigned" );
/* Any overdue task ? */
if( taskCounts[1] == 0 )
System.out.println( "- No overdue task" );
else if( taskCounts[1] == 1 )
System.out.println( "- 1 overdue task" );
else
System.out.println( "- " + taskCounts[1] + " overdue tasks" );
}
break;
.
.
.
Getting All Tasks
The following excerpt shows how to get a list of all tasks.
/* List all tasks */
case '2' :
/* List the Task for the current user? */
if( ( answer = askQuestion(
"\nList Tasks for the current user (y/n)?" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Evaluate the answer */
isForCurrentUser = ( answer.equals( "y" ) || answer.equals( "Y" ) );
List taskList;
if( isForCurrentUser )
/* WLPI Public API Method */
/* NOTE: Would be nice to add code to capture any
* thrown exceptions */
/* Get Tasks list for the active user and the
* active organization. */
taskList = worklist.getTasks( );
else {
/* Get Organization ID */
if( ( orgId = askQuestion(
"\nEnter Organization ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Asignee ID */
if( ( assigneeId = askQuestion(
"Enter Assignee ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Is the Assignee a Role? */
if( ( answer = askQuestion(
"Is the Assignee a Role (y/n)?" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Evaluate the answer */
isRole = ( answer.equals( "y" ) || answer.equals( "Y" ) );
/* WLPI Public API Method */
/* NOTE: Would be nice to add code to capture any
* thrown exceptions */
/* Get Tasks list for the specified user and organization. */
taskList = worklist.getTasks( orgId, assigneeId, isRole );
}
/* Any task assigned ? */
if( taskList.size( ) == 0 )
System.out.println( "\nNo task assigned" );
else
System.out.print( "\nAssigned Tasks:" );
/* Process the list to display the tasks */
for( int i = 0; i < taskList.size( ); i++ ) {
/* Retrieve an element from the list */
TaskInfo taskInfo = ( TaskInfo )taskList.get( i );
/* WLPI Public API Methods */
/* Retrieve and display a sub-set of available attributes */
System.out.println( "\n- Name: " + taskInfo.getName( ) );
System.out.println( " Template Definition ID: " +
taskInfo.getTemplateDefinitionId( ) );
System.out.println( " Workflow Instance ID: " +
taskInfo.getInstanceId( ) );
System.out.println( " Task ID: " + taskInfo.getTaskId( ) );
System.out.print( " Status: " + taskInfo.getStatus( ) );
/* Retrieve and display the task status */
if( taskInfo.getStatus( ) == taskInfo.STATUS_PENDING )
System.out.println( " (Pending)" );
else if( taskInfo.getStatus( ) == taskInfo.STATUS_COMPLETE )
Assigning a Task
The following excerpt shows how to assign a task.
/* Assign a Task */
case '3' :
/* Get the Template Definition ID */
if( ( templateDefId = askQuestion(
"\nEnter Template Definition ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Workflow Instance ID */
if( ( instanceId = askQuestion(
"Enter Workflow Instance ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Task ID */
if( ( taskId = askQuestion( "Enter Task ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Assignee ID */
if( ( assigneeId = askQuestion( "Enter Assignee ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Is the Assignee a Role? */
if( ( answer = askQuestion( "Assign to a role (y/n)?" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Evaluate the answer */
isRole = ( answer.equals( "y" ) || answer.equals( "Y" ) );
/* If the Assignee a role, assign to user in this role? */
if( isRole ) {
if( ( answer = askQuestion(
"Assign to a user in this role (y/n)?" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Evaluate the answer */
isUserInRole = ( answer.equals( "y" ) || answer.equals( "Y" ) );
}
else
isUserInRole = false;
/* Assign the Task */
try {
/* WLPI Public API Method */
String clientReq = worklist.taskAssign(
templateDefId, instanceId, taskId, assigneeId,
isRole, isUserInRole );
/* Success (No exception thrown) */
System.out.println( "- Success" );
/* Parse the reply from the server to process client
* request (if any) */
parser.handleRequest( clientReq );
}
catch( Exception e ) {
System.out.println( "*** Failed to assign the task" );
System.err.println( e );
}
break;
.
.
.Executing a Task
The following excerpt shows how to execute a task.
/* Execute a Task */
case '4' :
/* Get the Template Definition ID */
if( ( templateDefId = askQuestion(
"\nEnter Template Definition ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Workflow Instance ID */
if( ( instanceId = askQuestion(
"Enter Workflow Instance ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Task ID */
if( ( taskId = askQuestion( "Enter Task ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Execute the Task */
try {
/* WLPI Public API Method */
String clientReq = worklist.taskExecute(
templateDefId, instanceId, taskId );
/* Success (No exception trown) */
System.out.println( "- Success" );
/* Parse the reply from the server to process client
* request (if any) */
parser.handleRequest( clientReq );
}
catch( Exception e ) {
System.out.println( "*** Failed to execute the task" );
System.err.println( e );
}
break;
.
.
.Marking a Task as Complete
The following excerpt shows how to mark a task as complete.
/* Mark a Task as done */
case '5' :
/* Get the Template Definition ID */
if( ( templateDefId = askQuestion(
"\nEnter Template Definition ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Workflow Instance ID */
if( ( instanceId = askQuestion(
"Enter Workflow Instance ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Task ID */
if( ( taskId = askQuestion( "Enter Task ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Mark the Task as Done */
try {
/* WLPI Public API Method */
String clientReq = worklist.taskMarkDone(
templateDefId, instanceId, taskId );
/* Success (No exception trown) */
System.out.println( "- Success" );
/* Parse the reply from the server to process client
* request (if any) */
parser.handleRequest( clientReq );
}
catch( Exception e ) {
System.out.println( "*** Failed to mark the task as done" );
System.err.println( e );
}
break;
.
.
.Setting the Task Properties
The following excerpt shows how to set task properties.
/* Set Task Properties */
case '6' :
/* Get the Template Definition ID */
if( ( templateDefId = askQuestion(
"\nEnter Template Definition ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Workflow Instance ID */
if( ( instanceId = askQuestion(
"Enter Workflow Instance ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Task ID */
if( ( taskId = askQuestion( "Enter Task ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get Task Priority */
if( ( answer = askQuestion(
"Enter the Priority (0=low, 1, 2=high)" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Parse the answer */
priority = Integer.parseInt( answer );
/* Get the "Marked done without executing" Property */
if( ( answer = askQuestion(
"Can it be marked done without executing (y/n)?" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Evaluate the answer */
isDoneWithoutDoit = ( answer.equals( "y" ) || answer.equals( "Y" ) );
/* Get the "Re-executed if marked done" Property */
if( ( answer = askQuestion(
"Can it be re-executed if marked done (y/n)?" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Evaluate the answer */
isDoitIfDone = ( answer.equals( "y" ) || answer.equals( "Y" ) );
/* Get the "Unmarked if marked done" Property */
if( ( answer = askQuestion(
"Can it be unmarked if marked done (y/n)?" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Evaluate the answer */
isUnmarkDone = ( answer.equals( "y" ) || answer.equals( "Y" ) );
// System.out.print( "Can the properties be modified
// at runtime (y/n) >> " );
/* Get the answer */
// answer = stdIn.readLine( );
/* User cancelled the operation? */
// if( answer.equals( "" ) )
// {
// System.out.println( "*** Cancelled" );
// break;
// }
/* Evaluate the answer */
// boolean isModifiable = (
// answer.equals( "y" ) || answer.equals( "Y" ) );
isModifiable = true;
/* Get the "Reassign" Property */
if( ( answer = askQuestion(
"Can it be reassigned (y/n)?" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
Unassigning a Task
The following excerpt shows how to revoke a task assignment.
/* Unassign a Task */
case '7' :
/* Get the Template Definition ID */
if( ( templateDefId = askQuestion(
"\nEnter Template Definition ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Workflow Instance ID */
if( ( instanceId = askQuestion(
"Enter Workflow Instance ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Task ID */
if( ( taskId = askQuestion( "Enter Task ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Unassign the Task */
try {
/* WLPI Public API Method */
worklist.taskUnassign( templateDefId, instanceId, taskId );
/* Success (No exception trown) */
System.out.println( "- Success" );
}
catch( Exception e ) {
System.out.println( "*** Failed to unassign the task" );
System.err.println( e );
}
break;
.
.
.Marking a Task as Incomplete
The following excerpt shows how to mark a task as incomplete.
/* Unmark a Task as done */
case '8' :
/* Get the Template Definition ID */
if( ( templateDefId = askQuestion(
"\nEnter Template Definition ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Workflow Instance ID */
if( ( instanceId = askQuestion(
"Enter Workflow Instance ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Get the Task ID */
if( ( taskId = askQuestion( "Enter Task ID" ) ) == null ) {
/* User cancelled the operation */
System.out.println( "*** Cancelled" );
break;
}
/* Unmark the Task as Done */
try {
/* WLPI Public API Method */
String clientReq = worklist.taskUnmarkDone(
templateDefId, instanceId, taskId );
/* Success (No exception trown) */
System.out.println( "- Success" );
/* Parse the reply from the server to process client
* request (if any) */
parser.handleRequest( clientReq );
}
catch( Exception e ) {
System.out.println( "*** Failed to unmark the task as done" );
System.err.println( e );
}
break;
/* Return to previous menu */
case 'B' :
return;
/* Exit tool */
case 'Q' :
/* Disconnect from the server */
disconnect( );
System.exit( 1 );
default:
System.out.println( "*** Invalid choice" );
}
}
}
/* "Unhandled" exceptions */
catch( Exception e ) {
System.err.println( e );
}
return;
}Command-Line SAX Parser Example
This section provides excerpts from the command-line SAX Parser showing how to set up the SAX parser and respond to a set-variables client request.
Note: For more information about the command-line SAX Parser example, see Command-Line SAX Parser Example.
For an example of how to respond to a message-box client request, see Parsing the Client Request.
The SAX parser is used by the command-line worklist to parse client requests. The example excerpts in this section show the following:
Notable lines are shown in bold.
Parsing the Client Request
The following excerpt shows how to use the Xerces SAX parser with a custom run-time management client. The handleRequest() method uses the Xerces SAX parser to parse the client requests received from the BPM server. The request string is an XML document conforming to the Client Request DTD, as described in Client Request DTD.
private static final String DEFAULT_PARSER =
"org.apache.xerces.parsers.SAXParser";
public void handleRequest( String request ) {
if( request == null )
return;
/* Get instance of handlers */
ContentHandler contentHandler = new CLContentHandler();
ErrorHandler errorHandler = new CLErrorHandler();
try {
/* Instantiate a parser */
XMLReader parser = XMLReaderFactory.createXMLReader(
DEFAULT_PARSER );
/* Register the content handler */
parser.setContentHandler( contentHandler );
/* Register the error handler */
parser.setErrorHandler( errorHandler );
/* Create a character stream */
Reader inReader = new StringReader( request );
/* Encapsulate the stream for the SAX Parser */
InputSource inputSource = new InputSource( inReader );
/* Parse the request */
parser.parse( inputSource );
}
catch( Exception e ) {
System.err.println( e );
}
}
}Responding to the Client Request
The following methods interact with the user to retrieve the set-variable client request, which is triggered by an ActionSendXMLToClient event, and to respond to the set-variable client request.
The following method retrieves the set-variable client request.
public void setVariables( List listVarInfo ) {
String varValue;
/* Process the list to display the prompt and
* retrieve the value */
for( int i = 0; i < listVarInfo.size( ); i++ ) {
/* Retrieve an element from the list */
VariableInfo varInfo = ( VariableInfo )listVarInfo.get( i );
/* Prompt user for the variable value */
if( ( varValue = askQuestion(
"- " + varInfo.getVarPrompt() ) ) != null ) {
/* User entered a value; so overwrite the stored value */
varInfo.setVarValue( varValue );
listVarInfo.set( i, ( VariableInfo )varInfo );
}
}
return;
}
.
.
.The following method responds to a set-variable client request.
private static String sendSetVariablesResponse(
String templateDefinitionId, String instanceId,
String actionId, List listVarInfo ) {
String clientReq = null;
/* Create a variable to store the XML clientResponse
* and add the document prolog */
StringBuffer response = new StringBuffer(
"<?xml version=\"1.0\"?>\r\n" );
/* Add the XML document root */
response.append( "<set-variables>\r\n" );
/* Process the list to retrieve the varriables
* name and value */
for( int i = 0; i < listVarInfo.size( ); i++ ) {
/* Add the variable element and the name attribute */
response.append( " <variable name=\"" );
/* Retrieve an element from the list */
VariableInfo varInfo = ( VariableInfo )listVarInfo.get( i );
/* Add the value for the name attribute */
response.append( varInfo.getVarName() + "\">" );
/* Add the value for the variable element */
response.append( XMLToString( varInfo.getVarValue() ) );
/* Add end tag */
response.append( "</variable>\r\n" );
}
/* Add root end tag to the XML document */
response.append( "</set-variables>" );
try {
/* WLPI Public API Method */
/* Send the client's response to the 'set-variables' client
* request */
clientReq = clWorklist.getWorklist().response(
templateDefinitionId, instanceId, actionId,
response.toString() );
/* Success (No exception trown) */
System.out.println( "\nResponse sent to server" );
}
catch( Exception e ) {
System.out.println( "\nFailed sending response to server" );
System.err.println( e );
}
return( clientReq );
}
.
.
.JSP Worklist Example
This section provides excerpts from the JSP worklist example showing how to manage run-time tasks.
Note: For more information about the JSP worklist example, see JSP Worklist Example.
The example excerpts illustrate the following features:
- Getting Tasks
- Executing a Task
- Parsing the Client Request
- Responding to a Client Request
- Assigning a Task
- Marking a Task as Complete or Incomplete
- Setting Task Properties
In the following examples, all noteable lines of code are shown in bold. worklist represents the EJBObject reference to the Worklist EJB.
Getting Tasks
The following code excerpt from the JSP worklist (worklist.jsp) shows how to get a list of tasks and use the com.bea.wlpi.common.TaskInfo methods to obtain information about those tasks.
To get a list of tasks, set the Display Options, as shown in the figure Main Interface to the JSP Worklist.
try {
List v = worklist.getTasks(currentOrg, currentRole, isRole);
session.putValue("tasklist", v);// Get item count
int numItems = 0;
for (int i = 0, n = v.size(); i < n; i++) {
TaskInfo task = (TaskInfo)v.get(i);
if (task.getStarted() != null) {
if (task.getCompleted() != null) {
if (!done)
continue;
}
else {
if (!pending)
continue;
}
}
else if (!inactive)
continue;
numItems++;
}
}
.
.
.For more information about the com.bea.wlpi.common.TaskInfo methods, see TaskInfo Object, or the com.bea.wlpi.common.TaskInfo Javadoc.
Executing a Task
The following code excerpt from the JSP worklist (worklist.jsp) shows how to execute a task.
A user can execute a task by selecting the Perform Task link, as shown in the figure Main Interface to the JSP Worklist, and selecting the task to execute.
try {
List vTaskList = (List)session.getValue("tasklist");
TaskInfo task = (TaskInfo)vTaskList.get(Integer.parseInt(cmd));
session.putValue("action", ACTION_DOIT);
if (action.equals(ACTION_DOIT)) {
System.out.println(worklist.taskExecute(task.getTemplateDefinitionId(),
task.getInstanceId(), task.getTaskId()));
responseParser.parse( worklist.taskExecute(
task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId() )
);
if (responseParser.isQuery()) {
pageContext.forward("query.jsp");
return;
}
if (responseParser.isMessage()) {
pageContext.forward("message.jsp");
return;
}
}
.
.
.The template definition, workflow instance, and task IDs are obtained using the methods associated with the com.bea.wlpi.common.TaskInfo object, task. The resulting XML document (which is compliant with the Client Request DTD, as described in Client Request DTD) is returned from the taskExecute() method call and passed to the response parser, ResponseParser, for parsing. For more information about the response parser, see Parsing the Client Request.
For more information about the com.bea.wlpi.common.TaskInfo methods, see TaskInfo Object, or the com.bea.wlpi.common.TaskInfo Javadoc.
Parsing the Client Request
The following excerpts from the JSP SAX Parser, ResponseParser, show how to set up the SAX parser and respond to a message-box client request. For an example of how to respond to a set-variables client request, see Parsing the Client Request, within the description of the command-line SAX parser.
package jsp_servlet._worklist;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import com.sun.xml.parser.Parser;
import org.xml.sax.*;
public class ResponseParser implements DocumentHandler {
.
.
.
public boolean isMessage() {
return message;
}
.
.
.
public String getMessageOption() {
return ((String)messageBox.getOption());
}
public String getMessageStyle() {
return ((String)messageBox.getStyle());
} .
.
.
public String generateMessageResponse(HttpServletRequest request) {
StringBuffer response = new StringBuffer();
response.append(
"<?xml version=\"1.0\"?>\r\n<message-box
option=\""+request.getParameter("option")+"\"/>");
System.out.println((String) response.toString());
return((String) response.toString());
}
.
.
.
public void parse(String xml) {
try {
parser = new Parser();
parser.setDocumentHandler(this);
parser.parse(new InputSource(new ByteArrayInputStream(
xml.getBytes())));
} catch (SAXParseException spe) {
} catch (Exception e) {
}
}
.
.
.Responding to a Client Request
This section provides two code examples, excerpted from the JSP worklist, that show how to respond to a client request.
The first excerpt is taken from the worklist.jsp file. The responseParser parses the XML document. If a set-variables request is encountered , the context is passed to the query.jsp file. If a message-box request is encountered, the context is passed to the message.jsp file. For more information about the response parser, see Parsing the Client Request.
if (action.equals(ACTION_DOIT)) {
responseParser.parse( worklist.taskExecute(
task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId() )
);
if (responseParser.isQuery()) {
pageContext.forward("query.jsp");
return;
}
if (responseParser.isMessage()) {
pageContext.forward("message.jsp");
return;
}
}
.
.
.The second excerpt provides the contents of the message.jsp file, illustrating the response() method call. The method makes use of the XML parser, responseParser, to parse the client request XML (obtaining the template definition ID, instance ID, and workflow object ID), and to generate a response based on the request. For more information about the response parser, see Parsing the Client Request.
<%@ page import="
javax.ejb.*,
java.rmi.RemoteException,
java.util.*,
java.text.*,
com.bea.wlpi.common.*
com.bea.wlpi.server.worklist.*
"%>
<jsp:usebean id="responseParser" class="jsp_servlet._worklist.ResponseParser" scope="session"/>
<%
Worklist worklist = null;
TaskInfo task = null;
String error = null;
String resp = null;
String messageOption = null;
worklist = (Worklist)session.getValue("worklist");
if (worklist != null) {
Hashtable h = new Hashtable();
h.put(javax.naming.Context.SECURITY_PRINCIPAL, session.getValue("name"));
h.put(javax.naming.Context.SECURITY_CREDENTIALS,
session.getValue("password"));
new javax.naming.InitialContext(h);
if (request.getParameter("option") != null) {
try {
System.out.println(responseParser.generateMessageResponse(request));
System.out.println(responseParser.getTemplateDefinitionId());
System.out.println(responseParser.getInstanceId());
System.out.println(responseParser.getActionId());resp = worklist.response(
responseParser.getTemplateDefinitionId(),
responseParser.getInstanceId(),
responseParser.getActionId(),
responseParser.generateMessageResponse(request)
);
pageContext.forward("worklist.jsp");
return;
} catch (Exception e) {
e.printStackTrace();
}
}
}
%>
<html>
<head>
<title>Message</title>
</head>
<body bgcolor=#ffffff>
<font face="Arial" size="4">
<form action="message.jsp" method="POST">
<table dir="ltr" border="0" cellpadding="1" cellspacing="1">
<tr>
<td><img src="logo.gif"></td>
<td><font color="red" size="7">
<strong><em>Weblogic</em></strong></font>
<font color="black" size="7">
<strong><em>Process Integrator</em></strong></font>
</td>
</tr>
<tr>
<td bgcolor="navy" valign="top">
<table dir="ltr" border="0" cellpadding="2" cellspacing="2">
<tr>
<td><font color="yellow">
<strong>Go ...</strong></font></td>
</tr>
<tr>
<td><a href="worklist.jsp">
<font color="white">Worklist</font></a></td>
</tr>
<tr>
<td><a href="startworkflow.jsp">
<font color="white">Start Workflow</font></a></td>
</tr>
<tr>
<td><a href="logoff.jsp">
<font color="white">Logoff</font></a></td>
</tr>
</table>
</td>
<td valign="top">
<table dir="ltr" border="0" cellpadding="2" cellspacing="2" valign="top">
<%
if (error != null) {
%>
<tr>
<td><font color="red size="4" face="Arial"><%=error%></td>
</tr>
<%
}
%>
<tr>
<td><font color="navy" size="4" face="Arial">
<%=responseParser.getHeader()%></font></td>
</tr>
<tr>
<td>
<table border="0" cellpadding="2" cellspacing="2">
<tr>
<td></td>
<%
messageOption = responseParser.getMessageOption();
if (messageOption.equals("ok")) {
%>
<td width="10%">
<input type="submit" name="option" value="ok"></td>
<td width="90%"> </td>
<%
}
%>
<%
if (messageOption.equals("ok_cancel")) {
%>
<td width="10%">
<input type="submit" name="option" value="ok"></td>
<td width="10%">
<input type="submit" name="option" value="cancel"></td>
<td width="80%"> </td>
<%
}
%>
<%
if (messageOption.equals("yes_no")) {
%>
<td width="10%">
<input type="submit" name="option" value="yes"></td>
<td width="10%">
<input type="submit" name="option" value="no"></Assigning a Task
This section provides four code examples, excerpted from the JSP worklist, that show how to assign a task to a different participant (user or role).
Users can change the assignment of a task to a different participant by selecting the Reassign link, as shown in the figure Main Interface to the JSP Worklist, selecting the task to reassign, and specifying the user, role, or user in role when prompted to whom you want to reassign the task.
In the following example, the Reassign link references the worklist.jsp file with the SetAction parameter set to 4, and a checkmark is added, as a visual cue, to the left of the selected action.
<tr>
<td><%=action.equals("4") ? "<img src=\"check.gif\">" : ""%></td>
<td><a href="worklist.jsp?SetAction=4">
<font color="white">Reassign</font></a></td>
</tr>The SetAction value is extracted and stored in the action variable, as follows:
if (worklist != null) {
String cmd = request.getParameter("SetFilter");
if (cmd != null) {
.
.
.
}
else if (request.getParameter("SetAction") != null)
{
action = request.getParameter("SetAction");
session.putValue("action", action);
}
.
.
.Based on the value of the action variable, the context gets passed to the reassign.jsp file, as shown in the following excerpt.
static final String ACTION_DOIT = "0";
static final String ACTION_MARKDONE = "1";
static final String ACTION_UNMARKDONE = "2";
static final String ACTION_TASKPROPERTIES = "3";
static final String ACTION_REASSIGN = "4";
.
.
.
try {
List vTaskList = (List)session.getValue("tasklist");
TaskInfo task = (TaskInfo)vTaskList.get(Integer.parseInt(cmd));
session.putValue("action", ACTION_DOIT);
if (action.equals(ACTION_DOIT)) {
.
.
.
}
else if (action.equals(ACTION_REASSIGN)) {
session.removeValue("error");
pageContext.forward("reassign.jsp?task= "+cmd);
return;
}
.
.
.The following code, taken from the contents of the reassign.jsp file, shows how to use the taskAssign() method to reassign a task. The template definition, workflow instance, and task IDs are obtained using the methods associated with the com.bea.wlpi.common.TaskInfo object, task. The task object can be obtained using the methods described in Getting All Tasks.
<%@ page import="
javax.ejb.*,
java.rmi.RemoteException,
java.util.*,
java.text.*,
com.bea.wlpi.common.*
com.bea.wlpi.server.worklist.*
com.bea.wlpi.server.principal.*
javax.naming.*
"%>
<%!
static final String TYPE_USER = "0";
static final String TYPE_USERINROLE = "1";
static final String TYPE_ROLE = "2";
%>
<%
Worklist worklist = null;
TaskInfo task = null;
String error = null;
String assignType = TYPE_USER;
worklist = (Worklist)session.getValue("worklist");
if (worklist != null) {
Hashtable h = new Hashtable();
h.put(javax.naming.Context.SECURITY_PRINCIPAL, session.getValue("name"));
h.put(javax.naming.Context.SECURITY_CREDENTIALS,
session.getValue("password"));
new javax.naming.InitialContext(h);
String cmd = request.getParameter("task");
if (cmd != null) {
try {
List vTaskList = (List)session.getValue("tasklist");
task = (TaskInfo)vTaskList.get(Integer.parseInt(cmd));
session.putValue("task", task);
} catch (Exception e) {
}
}
else
task = (TaskInfo)session.getValue("task");
}
if (request.getParameter("Set") != null)
assignType = request.getParameter("Type");
if (request.getParameter("Reassign") != null) {
// Set properties
try {
assignType = request.getParameter("Type");
boolean bRole = false;
boolean bUserInRole = false;
if (!assignType.equals(TYPE_USER)) {
bRole = true;
if (assignType.equals(TYPE_USERINROLE))
bUserInRole = true;
}
worklist.taskAssign(task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId(),
request.getParameter("Assignee"),
bRole,
bUserInRole
);
session.removeValue("task");
session.removeValue("error");
pageContext.forward("worklist.jsp");
return;
} catch (Exception e) {
error = e.getMessage();
}
}
if (task != null) {
%>
<html>
<head>
<title>Reassign Task</title>
</head>
<body bgcolor=#ffffff>
<font face="Arial" size="4">
<form action="reassign.jsp" method="POST">
<table dir="ltr" border="0" cellpadding="1" cellspacing="1">
<tr>
<td><img src="logo.gif"></td>
<td><font color="red" size="7"><strong><em>Weblogic</em></strong></font>
<font color="black" size="7"><strong><em>
Process Integrator</em></strong></font></td>
</tr>
<tr>
<td bgcolor="navy" valign="top">
<table dir="ltr" border="0" cellpadding="2" cellspacing="2" >
<tr>
<td><font color="yellow">
<strong>Go ...</strong></font></td>
</tr>
<tr>
<td><a href="worklist.jsp">
<font color="white">Worklist</font></a></td>
</tr>
<tr>
<td><a href="startworkflow.jsp">
<font color="white">Start Workflow</font></a></td>
</tr>
<tr>
<td><a href="logoff.jsp">
Marking a Task as Complete or Incomplete
The following code examples, excerpted from the JSP worklist, show how to mark a task as complete (done) or incomplete (undone).
Users can mark a task as complete or incomplete by selecting the Mark Done or Mark Undone links, as shown in the figure Main Interface to the JSP Worklist.
In the following examples, the Mark Done and Mark Undone links reference the worklist.jsp file with the SetAction parameter set to 1 and 2, respectively, and a checkmark, as a visual cue, is added to the left of the selected action.
<tr>
<td><%=action.equals("1") ? "<img src=\"check.gif\">" : ""%></td>
<td><a href="worklist.jsp?SetAction=1"><font color="white">
Mark Done</font></a>
</td>
</tr>
<tr>
<td><%=action.equals("2") ? "<img src=\"check.gif\">" : ""%></td>
<td><a href="worklist.jsp?SetAction=2"><font color="white">
Unmark Done</font></a>
</td>
</tr>The SetAction value is extracted and stored in the action variable, as follows:
if (worklist != null) {
String cmd = request.getParameter("SetFilter");
if (cmd != null) {
.
.
.
else if (request.getParameter("SetAction") != null) {
action = request.getParameter("SetAction");
session.putValue("action", action);
}The following code, taken from the worklist.jsp file, shows how to use the taskMarkDone() and taskUnmarkDone() methods to mark a task as complete or incomplete, respectively.
try {
List vTaskList = (List)session.getValue("tasklist");
TaskInfo task = (TaskInfo)vTaskList.get(Integer.parseInt(cmd));
session.putValue("action", ACTION_DOIT);
if (action.equals(ACTION_DOIT)) {
.
.
.
}
else if (action.equals(ACTION_MARKDONE))
worklist.taskMarkDone(task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId());
else if (action.equals(ACTION_UNMARKDONE))
worklist.taskUnmarkDone(task.getTemplateDefinitionId(),
task.getInstanceId(),
task.getTaskId());
.
.
.Setting Task Properties
This section provides several code excerpts from the JSP worklist that show how to set task properties.
Users can set the task properties by selecting the Task Properties link, as shown in the figure Main Interface to the JSP Worklist, selecting the task, and specifying the desired properties when prompted.
In this example, the Task Properties link references the worklist.jsp file with the SetAction parameter set to 3, and a checkmark, as a visual cue, is added to the left of the selected action.
<tr>
<td><%=action.equals("4") ? "<img src=\"check.gif\">" : ""%></td>
<td><a href="worklist.jsp?SetAction=3"><font color="white">
Task Properties</font></a></td>
</tr>Next, the SetAction value is extracted and stored in the action variable as follows:
if (worklist != null) {
String cmd = request.getParameter("SetFilter");
if (cmd != null) {
.
.
.
else if (request.getParameter("SetAction") != null) {
action = request.getParameter("SetAction");
session.putValue("action", action);
}
.
.
.Based on the value of the action variable, the context is passed to the taskproperties.jsp file, as follows:
static final String ACTION_DOIT = "0";
static final String ACTION_MARKDONE = "1";
static final String ACTION_UNMARKDONE = "2";
static final String ACTION_TASKPROPERTIES = "3";
static final String ACTION_REASSIGN = "4";
.
.
.
try {
List vTaskList = (List)session.getValue("tasklist");
TaskInfo task = (TaskInfo)vTaskList.get(Integer.parseInt(cmd));
session.putValue("action", ACTION_DOIT);
if (action.equals(ACTION_DOIT)) {
.
.
.
else if (action.equals(ACTION_TASKPROPERTIES)) {
session.removeValue("error");
pageContext.forward("taskproperties.jsp?task= "+cmd);;Finally, task properties must be set. The following code, taken from the taskproperties.jsp file, shows how to use the taskSetProperties() method to set task properties.
<%@ page import="
javax.ejb.*,
java.rmi.RemoteException,
java.util.*,
java.text.*,
com.bea.wlpi.common.*
com.bea.wlpi.server.worklist.*
"%>
<%!
DateFormat df = new SimpleDateFormat("MMM d, yyyy h:mm a");
%>
<%
Worklist worklist = null;
TaskInfo task = null;
String error = null;
worklist = (Worklist)session.getValue("worklist");
if (worklist != null) {
Hashtable h = new Hashtable();
h.put(javax.naming.Context.SECURITY_PRINCIPAL, session.getValue("name"));
h.put(javax.naming.Context.SECURITY_CREDENTIALS, session.getValue("password"));
new javax.naming.InitialContext(h);
String cmd = request.getParameter("task");
if (cmd != null) {
try {
List vTaskList = (List)session.getValue("tasklist");
task = (TaskInfo)vTaskList.get(Integer.parseInt(cmd));
} catch (Exception e) {
}
}
}
if (request.getParameter("Set") != null) {
// Set properties
task = (TaskInfo)session.getValue("task");
try {
worklist.taskSetProperties( task.getTemplateDefinitionId(),
task.getInstanceId(), task.getTaskId(),
Integer.parseInt(request.getParameter("Priority")),
request.getParameter("P0") != null,
request.getParameter("P1") != null,
request.getParameter("P2") != null,
request.getParameter("P3") != null,
request.getParameter("P4") != null);
session.removeValue("task");
session.removeValue("error");
pageContext.forward("worklist.jsp");
return;
} catch (Exception e) {
error = e.getMessage();
}
}
if (task != null) {
session.putValue("task", task);
%>
<html>
<head>
<title>Task Properties</title>
</head>
<body bgcolor=#ffffff>
<font face="Arial" size="4">
<form action="taskproperties.jsp" method="POST">
<table dir="ltr" border="0" cellpadding="1" cellspacing="1">
<tr>
<td><img src="logo.gif"></td>
<td>
<font color="red" size="7">
<strong><em>Weblogic</em></strong></font>
<font color="black" size="7">
<strong><em>Process Integrator</em></strong></font>
</td>
</tr>
<tr>
<td bgcolor="navy" valign="top">
<table dir="ltr" border="0" cellpadding="2" cellspacing="2" >
<tr>
<td><font color="yellow">
<strong>Go ...</strong></font>
</td>
</tr>
<tr>
<td><a href="worklist.jsp">
<font color="white">Worklist</font></a>
</td>
</tr>
<tr>
<td><a href="startworkflow.jsp">
<font color="white">Start Workflow</font></a>
</td>
</tr>
<tr>
<td><a href="logoff.jsp">
<font color="white">Logoff</font></a></td>
</tr>
</table>
</td>
<td valign="top">
<table dir="ltr" border="0" cellpadding="2" cellspacing="2" valign="top">
<%
if (error != null) {
%>
<tr>
<td><font color="red size="4" face="ArialThe template definition, instance, and task IDs, and current task properties are obtained using the methods associated with the com.bea.wlpi.common.TaskInfo object, task. The task object can be obtained using the methods described in Getting All Tasks.
![]()
![]()
![]()
Copyright © 2001 BEA Systems, Inc. All rights reserved.
Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.