Tuesday, December 10, 2013

#292 BPM 11g Human Task - Reassignment via API

Simple scenario:













Task is assigned to CSR role - jcooper is a member.

Create a test instance.
Validate in workspace.



Now I will reassign this task to wshake.















The actual Java API code is as follows -

    public String reassignTask(String taskName, String currentOwner,
                               String newOwner) {
        System.out.println("*** reassignTask() " + taskName + " from " +
                           currentOwner + " to " + newOwner);
        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");

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

            //Get the task query service
            ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
            //Login as jcooper
            IWorkflowContext ctx =
                querySvc.authenticate(currentOwner, "welcome1".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");

            Predicate pred =
                new Predicate(TableConstants.WFTASK_TITLE_COLUMN, Predicate.OP_EQ,
                              taskName);

            //Query a list of tasks assigned to jcooper
            List tasks =
                querySvc.queryTasks(ctx, queryColumns, null, //Do not query additional info
                    ITaskQueryService.AssignmentFilter.ALL, null, //No keywords
                    pred, //Custom predicate
                    null, //No special ordering
                    0, //Do not page the query result
                    0);
            //Get the task service
            ITaskService taskSvc = wfSvcClient.getTaskService();

            // create the newAssignee list - in our case only newOwner
            List assigneeList = new ArrayList();

            ITaskAssignee assignee = new TaskAssignee(newOwner, "user");
            assigneeList.add(assignee);
            //


            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();
                List taskAssigneeList =
                    task.getSystemAttributes().getAssigneeUsers();
                System.out.println("Found task " + title + " taskId is " +
                                   taskId);

                // do the Reassignment
                for (int j = 0; j < taskAssigneeList.size(); j++) {
                    IdentityType type = (IdentityType)taskAssigneeList.get(j);
                    String name = type.getId();
                    System.out.println("Currently assigned to " + name);
                }
                int taskNr = task.getSystemAttributes().getTaskNumber();

                if (title != null && title.equalsIgnoreCase(taskName)) {
                    System.out.println("Starting reassignment...");
                    Task task4Reassign =
                        querySvc.getTaskDetailsById(ctx, taskId);
                    System.out.println("Task title " +
                                       task4Reassign.getTitle());
                    System.out.println("Reassigning task to " + newOwner +
                                       " for taskNr " + taskNr);
                    taskSvc.reassignTask(ctx, task4Reassign, assigneeList);
                }


            }
        } catch (Exception e) {
            //Handle any exceptions raised here...
            System.out.println("Caught workflow exception: " + e.getMessage());
        }

        return "done";
    }

Run -










login to workspace as wshake









Java project available here

No comments:

Post a Comment