Sunday, July 17, 2011

Getting BPM InitiableTasks and Initiating a Task

This is my third post on the series of post related to the Oracle BPM 11g Java API.
The class below demonstrate how to get the BPM initiable tasks and how to initiate a task. It also contains a testGetProcessMetadata() method which could be useful to initiate a predefined task.
package soadev.bpmclient;

import java.util.List;

import oracle.bpel.services.bpm.common.IBPMContext;

import oracle.bpel.services.workflow.task.impl.TaskUtil;
import oracle.bpel.services.workflow.task.model.Task;

import oracle.bpm.services.instancemanagement.IInstanceManagementService;
import oracle.bpm.services.processmetadata.IProcessMetadataService;
import oracle.bpm.services.processmetadata.ProcessMetadataSummary;

public class GetInitiableTasks {
    public static void main(String[] args) {
        GetInitiableTasks client = new GetInitiableTasks();
        client.testGetInitiatiableTasks();
        client.testInitiateTask();
        
    }
    public void testGetInitiatiableTasks() {
        System.out.println(">>> getting initiable tasks");
        try {
            IProcessMetadataService service =
                Fixture.getBPMServiceClient().getProcessMetadataService();
            IBPMContext bpmContext = 
                Fixture.getIBPMContext("pino", "password1");
            List<ProcessMetadataSummary> initiableTasks =  
                service.getInitiatableProcesses(bpmContext);
            for(ProcessMetadataSummary pms: initiableTasks){
                System.out.println(pms.getProjectName()+ "/" + pms.getProcessName());
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void testGetProcessMetadata(){
        try {
            String processName = "HelloWorldProcess";
            String compositeDN = "default/HelloWorldProject!1.0*soa_a164d265-e961-4afb-b44b-50ea95a06fa1";
            IBPMContext ctx = Fixture.getIBPMContext("pino", "password1");
            IProcessMetadataService service =
                Fixture.getBPMServiceClient().getProcessMetadataService();
            ProcessMetadataSummary pms = 
                service.getProcessMetadataSummary(ctx, compositeDN, processName);
            System.out.println("compositeDN: " + pms.getCompositeDN());
            System.out.println("processName: " + pms.getProcessName());
            System.out.println("compositeName: " + pms.getCompositeName());
        } catch (Exception e) {
            // TODO: Add catch code
            e.printStackTrace();
        } 
    }
    public void testInitiateTask(){
        System.out.println(">>> initiating a task");
        try {
            IProcessMetadataService service =
                Fixture.getBPMServiceClient().getProcessMetadataService();
            IBPMContext bpmContext = 
                Fixture.getIBPMContext("pino", "password1");
            List<ProcessMetadataSummary> initiableTasks =
                service.getInitiatableProcesses(bpmContext);
            //get the first initable task
            ProcessMetadataSummary pms = initiableTasks.get(0);
            IInstanceManagementService ims =
                Fixture.getBPMServiceClient().getInstanceManagementService();
            Task task = ims.createProcessInstanceTask(bpmContext, 
                                    pms.getCompositeDN()+"/"+pms.getProcessName());
            System.out.println(">>> task initiated");
            printTask(task);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private void printTask(Task task){
        System.out.println(TaskUtil.getInstance().toString(task));
    }

}

Run output...
C:\Oracle\11g\jdk160_24\bin\javaw.exe -client -classpath ...
>>> getting initiable tasks
EmployeeTransfersProject/EmployeeTransferProcess
HelloWorldProject/HelloWorldProcess
JobMasterProject/JobMasterCreationProcess
>>> initiating a task
>>> task initiated
<task xmlns="http://xmlns.oracle.com/bpel/workflow/task">
   <title>Request Employee Transfer</title>
   <creator>pino</creator>
   <ownerRole>EmployeeTransfersProject.ProcessOwner</ownerRole>
   <priority>3</priority>
   <processInfo/>
   <systemAttributes>
      <assignedDate>2011-07-17T00:33:15+03:00</assignedDate>
      <createdDate>2011-07-17T00:33:15+03:00</createdDate>
      <digitalSignatureRequired>false</digitalSignatureRequired>
      <displayInfo>
         <applicationName>worklist</applicationName>
         <hostname>hoitpino.al-naghi.com</hostname>
         <httpPort>8001</httpPort>
         <httpsPort>0</httpsPort>
         <uri>/workflow/HumanTaskForms/faces/adf.task-flow?_id=RequestEmployeeTransfer_TaskFlow&amp;_document=WEB-INF/RequestEmployeeTransfer_TaskFlow.xml</uri>
      </displayInfo>
      <fromUser>
         <type>user</type>
      </fromUser>
      <numberOfTimesModified>1</numberOfTimesModified>
      <state>ASSIGNED</state>
      <systemActions>
         <action>VIEW_TASK</action>
         <displayName>VIEW_TASK</displayName>
      </systemActions>
      <taskId>04d4a518-f444-4e04-8a70-b64c58e79b0a</taskId>
      <taskNumber>200381</taskNumber>
      <updatedBy>
         <id>pino</id>
         <type>user</type>
      </updatedBy>
      <updatedDate>2011-07-17T00:33:15+03:00</updatedDate>
      <version>1</version>
      <taskDefinitionId>default/EmployeeTransfersProject!1.0*soa_a8c4f842-6b05-406a-be83-4ceb27588928/RequestEmployeeTransfer</taskDefinitionId>
      <workflowPattern>Participant</workflowPattern>
      <participantName>default.DefaultPerformer</participantName>
      <assignees>
         <id>EmployeeTransfersProject.Requester</id>
         <displayName></displayName>
         <type>application_role</type>
      </assignees>
      <isPartialTask>true</isPartialTask>
   </systemAttributes>
   <systemMessageAttributes/>
   <callback/>
   <category>HR</category>
   <sca/>
   <applicationContext>OracleBPMProcessRolesApp</applicationContext>
   <taskDefinitionId>default/EmployeeTransfersProject!1.0*soa_a8c4f842-6b05-406a-be83-4ceb27588928/RequestEmployeeTransfer</taskDefinitionId>
   <mdsLabel>soa_a8c4f842-6b05-406a-be83-4ceb27588928</mdsLabel>
   <creatorDisplayName>pino</creatorDisplayName>
   <customAttributes/>
</task>
Process exited with exit code 0.

Please refer to the earlier post with regards to the Fixture class and the necessary BPM jars. You can access the sample application on this link.


Cheers!

2 comments:

  1. Hi Pino,

    where I can get the CompositeDN for my bpm process?

    I your example is String compositeDN = "default/HelloWorldProject!1.0*soa_a164d265-e961-4afb-b44b-50ea95a06fa1";

    Thanks in advance.

    Mariano

    ReplyDelete
  2. Hi Pino,

    I have a question, in my application I am fetching the list of tasks deployed using
    List initiableTasks =
    service.getInitiatableProcesses(bpmContext);

    Now, in my BPM workspace I have different versions of deployed workflows, for instance,
    RequestProject [1.1]
    RequestProject [1.2]

    And I want to list only the latest initiable tasks, not all the active tasks.

    Thanks in advance!

    ReplyDelete