Thursday, October 8, 2015

Oracle BPM 12c Subprocesses (Part 1 of 3): Reusable Subprocess

In this three part series we will explore an additional BPMN flow object, the subprocess. By definition, a subprocess is another type of process that can either reside within the main process or it is called by another process.

A subprocess, just like a normal process has its own start and end events and can accept data object, update data objects and return data objects. There are three types of subprocesses, “Reusable” subprocesses, “Embedded” subprocesses and “Event” subprocesses. In this first part we will dive into the “Resuable” process.

A “Resuable” processes, as the name implies is an independent process that is often used to group common and repeated flows (and activities) so that they can be reused (as opposed to re-implemented every time where needed) and which can be invoked by multiple parent processes within the same BPM project. And it’s imperative to stress here the last part, “within the same BPM project”, as a “Resuable” process cannot be used/invoked from other BPM projects. To achieve the latter you will need to use templates (feature that I will be blogging later).

As opposed to a normal process where can you use a variety of events to start and end a process (for example, message start event, timer start event, signal start event, message end event, signal end event, etc.), a “Reusable” subprocess can only start with a none start event and can only end with a none end event.

Furthermore, to invoke a “Reusable” subprocess from a main process, you will need to use a “Call” activity that by implementation allows you to call a reusable process synchronously. What this means is that when the parent process invokes a “Reusable” process it will wait until the “Reusable” child process completes execution before the parent continues its flow.

However, even though the token is passed from the parent process to the subprocess, the child subprocess does not share the parent context, meaning that the data objects of the parent process are not available to the “Reusable” child process.

So to pass data objects from the parent process to the “Reusable” child process (and vice versa), your subprocess will need to define data object of its own and using the data association mappings of the call activity you can pass data objects from the parent process to the subprocess and backwards. Data objects defined in a subprocess are only accessible within the subprocess.

Let’s see in practice how you can create a subprocess and how to invoke a subprocess from a main process. For the sake of simplicity and easiness we will build the “Quote” process depicted above but “Save Quote” service call.

Create the basic BPM application and BPM project with an asynchronous BPMN process that takes a simple string input argument (for example bidId) and returns a string argument (for example status).

Create two string process data objects to store the process input and output arguments for reference throughout the process.


Next assign the process input and output arguments to the respective process data objects. On the "Start Message" select "Properties", "Implementation", "Data Associations" and drag source argument (bidId) to target data object (pBidId). Do the same for the output argument, mapping status to pStatus.

Drag and drop two interactive human task activities onto the default transition line from start to end naming the first “Enter Quote Details” and the second one “Finalize Quote”. You process should look like below.
Notice how the human task activities are marked as incomplete. That’s because they haven’t been implemented yet. So let’s create a single human task definition to serve both human tasks.

Double click on the “Enter Quote Details” human task and from the “Properties” window go to the “Implementation” tab and click on the green “Add” button to create a new definition. Specify a name, (for example SingleOutcomeHT) and just select a single outcome, “OK”.

Open the properties of the second human task (“Finalize Quote”) and select the human task definition you created above. Both warnings should disappear since both human tasks have been implemented.

Let’s now create our reusable subprocess. This subprocess will just serve as a validation sub process and will include a single human task.

Right click the "BPMN Processes" folder and from the context menu select new "BPMN 2.0 Process" . Give your process a name and ensure you select "Reusable Process" from the process type selection list.

To demonstrate context isolation between the main process and the sub process let's create an input and an output argument (quoteId as an input string argument and an outcome as an output string argument).

Create two process data objects to store the input and output arguments for reference throughout the sub-process.

Next assign the sub-process input and output arguments to the respective sub-process data objects. On the "Start None" select "Properties", "Implementation", "Data Associations" and drag source argument (quoteId) to target data object (pQuoteId). Do the same for the output argument, mapping pOutcome to outcome.

Drag and drop an interactive human task activity onto the default transition line from start to end, name it "Validate Quote" and create a new definition for the interactive human task activity. Specify a name, (for example DualOutcomeHT) and ensure that both "APPROVE" and "REJECT" outcomes are selected.

In the human task title ensure that you use the sub-process input data object to see how data objects are passed (via assignments) from the parent process to the sub-process.

One last thing is to assign the human task outcome to the sub-process data object you've created to store the sub-process return argument (pOutcome). To do so open the interactive human task activity properties, go to the implementation tab and using the data associations ensure that you copy the human task outcome argument value to the pOutcome data object.

With the sub-process complete we can now go to the main (parent) process and call the "ValidateQuoteSubProcess". To invoke a reusable sub process from a main process you will need to use a "Call" activity.

Therefore drag and drop a "Call" activity just between the two interactive human task activities. Give your "Call" activity a name (for example "Call Validate Quote Sub Process") and from the implementation tab, in the process drop down list ensure you select your reusable sub process.

As already stated above, the main process does not share its context (therefore its data objects) with a reusable sub process. To pass data objects from the main process to a sub process you need to use data associations.

Therefore using the data associations of the "Call" activity ensure that, from the input tab, you copy the pBidId main process data object to the quoteId input argument of the reusable sub process and from the output tab you copy back the outcome from the reusable sub process back to the main process.

We are now ready to deploy and test our process (and sub process). From the EM (Enterprise Manager) invoke a new instance of your process and open on the flow trace. Your instance should be waiting at the first human task activity.

Go to the BPM Workspace and you should see a new task in your inbox (weblogic given that you mapped weblogic as the process owner). Submit the task and go back to the flow trace. You should see that your instance has invoked your reusable sub process and is waiting for review.

Approve (using the BPM Workspace) the new task that has been created and assigned and go back to the flow trace. You instance should have resumed execution of your main process and should be pending at the third step.

Approve the third and last step and your instance should be completed. If you inspect the audit trail of the end activity of your main process you should notice that review human task outcome from the reusable sub process has been passed back to the main process and copied to the return argument of the main process.

Download sample application: Reusable Subprocess

No comments:

Post a Comment