Monday, May 14, 2012

BPM 11g Human task - Update Priority via API

Scenario - I have a BPM process as follows -


Sales task assigned to jcooper
Legal task assigned to mtwain
ProcessOwner is weblogic

The default priority for the human tasks is set to 3






Now I want to use the Java API to update the task priorities to 1.






Here is the code snippet -

    public String updatePriority4AllTasks(String user,
                                          String password) throws Exception {
        System.out.println("updatePriority4AllTasks() for " + user);
        Map properties = new HashMap();
        properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
                       "t3://localhost:7001");
        properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
                       "welcome1");
        properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
                       "weblogic");


        //Create JAVA WorkflowServiceClient
        IWorkflowServiceClient wfSvcClient =
            WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT,
                                                                  properties,
                                                                  null);

        //Get the task query service
        ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();

        //Login as user specified
        IWorkflowContext ctx =
            querySvc.authenticate(user, password.toCharArray(), null);

        //Set up list of columns to query
        List queryColumns = new ArrayList();
        queryColumns.add("TASKID");
        queryColumns.add("TASKNUMBER");
        queryColumns.add("TITLE");
        queryColumns.add("OUTCOME");

        /*
     * Query a list of tasks owned by the user
     * Note setting of AssignmentFilter.OWNER
    */

        List tasks =
            querySvc.queryTasks(ctx, queryColumns, null, //Do not query additional info
                ITaskQueryService.AssignmentFilter.OWNER, null, //No keywords
                null, //No custom predicate
                null, //No special ordering
                0, //Do not page the query result
                0);

        //Get the task service
        ITaskService taskSvc = wfSvcClient.getTaskService();
        ITaskQueryService itqs = wfSvcClient.getTaskQueryService();

        //Loop over the tasks, outputting task information,
        System.out.println("You are the owner of the following live tasks:");

        for (int i = 0; i < tasks.size(); i++) {


            Task task = (Task)tasks.get(i);

            int taskNumber = task.getSystemAttributes().getTaskNumber();
            String title = task.getTitle();
            String taskId = task.getSystemAttributes().getTaskId();
            String outcome = task.getSystemAttributes().getOutcome();
            String state = task.getSystemAttributes().getState();
            if (state.equalsIgnoreCase("ASSIGNED")) {
               /*
                * Build up the assignee list
                */
                List l = task.getSystemAttributes().getAssignees();
                String assignees = "";
                IdentityTypeImpl iti;
          
                for (int j = 0; j < l.size(); j++) {
                    iti = (IdentityTypeImpl)l.get(j);
                    assignees = assignees + " " + iti.getId();
                }

                System.out.println("Task ID#" + taskId + "Task Nr#" +
                                   taskNumber + " " + "(" + title + ")" +
                                   ". State is " + state + ". Assignees:" +
                                   assignees);

                Task t = itqs.getTaskDetailsById(ctx, taskId);
                //

                System.out.println("updating priority for taskNr " +
                                   taskNumber);
         
                t.setPriority(1);
                taskSvc.updateTask(ctx, t);

            }

        }


        return "done";
    }

Imports
---------------------

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import java.util.Map;

import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.query.ITaskQueryService;

import oracle.bpel.services.workflow.repos.TableConstants;
import oracle.bpel.services.workflow.task.ITaskService;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;

import oracle.bpel.services.workflow.repos.Predicate;
import oracle.bpel.services.workflow.task.ITaskAssignee;
import oracle.bpel.services.workflow.task.model.IdentityTypeImpl;

---------------------------

1 comment:

  1. Hi,

    Could you please let me know the step by step process of updating the priorites in BPM? How and where to call the java code API etc. Can I give different priorties to different tasks? Say, priority 1 to one task, priority 2 to other task etc??

    Thanks & Regards,
    Ravi.

    ReplyDelete