Showing posts with label Human task. Show all posts
Showing posts with label Human task. Show all posts

(WID/WPS) Group Work Items (Human Task)

In some scenarios it is necessary to assign a piece of work to a group of users, or to grant a particular privilege to a group of users. A well-known way to implement this behavior is to define appropriate groups in the staff repository and use appropriate people assignment criteria in the component which assigns tasks and authorizations to particular users.


The WPS offers 3 different people assignment criteria definitions which can be used to take advantage of groups predefined in the underlying staff repository. These verbs are:
  • Group Members
  • Group Search
  • Group
The Group Members verb implements a simple version of group resolution. As a parameter, the user of this verb must provide the group id of the group to be resolved, and a flag whether nested groups should be expanded recursively. At runtime, this verb triggers a lookup operation in the underlying staff repository and generates the explicit list of userids that are members of the specified group.




Scenario : Here the group name 'sellers' which has 2 users 'SellerA' & 'SellerB'. In real time when this task is created the Potential Owners in the Details tab of the task would be SellerA ,SellerB.


The Group Search verb offers a more advanced version of group resolution. Besides specifying the group id of the group to be resolved, the user of this verb may use other attributes of the group instead, like Manager of the group, Geographic Location, Business Category, etc. In addition, this verb allows to use wildcard symbols in parameters. For example, by using the pattern us012* as group id, this verb will create a query which, at runtime, will concatenate the users of all groups where the group id starts with "us012". Like the Group Members verb described above, at runtime the Group Search verb triggers a lookup operation in the underlying staff repository and generates the explicit list of userids that are members of the specified group.




The Group people assignment criteria definition uses a different approach to realize group resolution. This verb takes advantage of the WebSphere mechanism performed during login: Whenever a user authenticates against WebSphere, for example, by entering userid and password in a login dialog, all groups are automatically determined of which the user is a member, and this information is associated safely with the actual session.




In this case Potential Owners in the Details tab of the task would be cn=sellers,o=defaultWIMFileBasedRealm.


In contrast to the two verbs described above, no access to the underlying staff repository is performed at runtime for the Group verb, and no explicit list of userids is generated at any time. This allows to specify huge groups containing a large number of users without performance impact.

(WID/WPS) HumanTask API (Create/Claim/CompleteTask)

This post gives the code for creating, claiming & completing the task.


LocalHumanTaskManager taskManager = null;
String name = null;
QueryResultSet instances = null;
try {
Context context = new javax.naming.InitialContext();
System.out.println("Lookup...started");


LocalHumanTaskManagerHome taskHome = (LocalHumanTaskManagerHome) context.lookup("java:comp/env/ejb/LocalHumanTaskManagerHome");


LocalHumanTaskManagerHome taskHome = (LocalHumanTaskManagerHome) context.lookup("local:ejb/com/ibm/task/api/HumanTaskManagerHome");


System.out.println("Lookup...success");
taskManager = taskHome.create();
System.out.println("Accessing local interface...success");
//String taskName = "MyHumanTask"; // Invocation Task
String taskName = "StandAloneHT"; // To-doTask
String taskNamespace = "http://HTModule";
TKIID tkiid = taskManager.createTask(taskName, taskNamespace);
Task task = taskManager.getTask(tkiid);
ClientObjectWrapper cow = taskManager.createInputMessage(tkiid);
DataObject dataObject = (DataObject) cow.getObject();

dataObject.setString("input1","<<Your Input>>");
taskManager.startTask(tkiid, cow, null);
//Signature of the startTask method :
//void startTask(TKIID tkiid, ClientObjectWrapper input, ReplyHandlerWrapper replyHandler) 
 //Asynchronously executes a previously created task using the task instance ID.
//Task can be of any type.


//Alternate way of calling a task :
//ClientObjectWrapper  cow2= taskManager.callTask(tkiid, cow);
// Signature of the callTask method :
//ClientObjectWrapper callTask(TKIID tkiid, ClientObjectWrapper input) 
//Synchronously executes a previously created invocation task instance using the task instance ID.
//Task should not be of To-Do type.
System.out.println("TKIID : "+tkiid);


//Claiming the task :
taskManager.claim(tkiid);
System.out.println("Claimed the task");


//Creating output for completing the task :
ClientObjectWrapper output =  taskManager.createOutputMessage(tkiid);
DataObject outDataObject = (DataObject) output.getObject();
outDataObject.setString("output1","909090");
taskManager.complete(tkiid,  output); 
System.out.println("Completed the task");

//System.out.println("OUTPUT : "+((DataObject)cow2.getObject()).getString("output1")); If called Synchronously.
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getClass());
}


Lookup in Green is used in a JSP while in Red is used in Java component.


Red Scenario :






In the above example "MyHumanTask" is an Invocation Task (Human----Service) & "StandAloneHT" is a To-Do Task.


 Assembly Diagram


Interface (Used as an interface for Todo Task & as a reference for Invocation Task)

(WID/WPS) Configuring EventHandler for an Escalation (WPS)

If an escalation occurs during the execution of a human task, you may want to notify an event handler within the application environment.
To configure an event and add it to your business application model, follow these instructions.

Declare a notification event handler for your task as described here:
  • In the human task editor click the Details tab. 
  • In the Event handler name field, enter a name for your notification event handler. {This name is not the name of the implementation class.}
  • Click Save. 
Add your plugin to your application:
  • Switch to the Resource perspective. 
  • In the Navigator, expand your business integration project. 
  • In the META-INF folder, create a new folder services. 
  • Right-click the services folder and select New > File . 
  • In the File name field of the New File wizard, , enter com.ibm.task.spi.EventHandlerNameNotificationEventHandlerPlugin Where EventHandlerName is the event handler name you have specified for your task. 
  • Click Finish. 
  • In the above file, write the fully qualified name of the event handler class.(For example : bpc.samples.plugin.EscalationNotificationPlugin)
Implementing the Event Handler Class:

EscalationNotificationPlugin.java

package bpc.samples.plugin;
import com.ibm.task.api.Escalation;
import com.ibm.task.api.TKIID;
import com.ibm.task.api.Task;
import com.ibm.task.spi.NotificationEventHandlerPlugin;

public class EscalationNotificationPlugin implements
NotificationEventHandlerPlugin {

public void escalationNotification(Task task, Escalation escalation) {
System.out.println("Entering method");
if(task != null && escalation != null)
{
System.out.println("Task template name: " + task.getTaskTemplateName());
System.out.println("Task name: " + task.getName());
System.out.println("Task state: " + task.getState());
System.out.println("Event handler name: " + task.getEventHandlerName());
System.out.println("Is escalated: " + task.isEscalated());
System.out.println("Escalation name: " + escalation.getName());
TKIID tkId = task.getID();
System.out.println("Task Id : " + tkId);
}

}

}

Specify an escalation with a notification type Event:
  • Switch to the Business Integration perspective and open your task in the human task editor. 
  • In the Escalation settings section, select the escalation. 
  • Click the Details tab. 
  • Configure the escalation as needed. For Notification type, choose Event from the list of available options. 
  • Save your work.