Friday, October 16, 2015

Oracle BPM 12c Subprocesses (Part 2 of 3): Embedded Subprocess

In this second blog on sub-processes we will explore the embedded sub-processes, also referred to as inline sub-processes and as the name implies this is a sub-process type that consists of a series of activities (for example tasks, gateways, events, etc.) that resides within the parent process.

An embedded sub-process has certain distinct characteristics such as they always begin with a none start event and end with a non end event, they do not contain swimlanes and most importantly they share their parent's context, meaning they can access parent process data which simplifies things since you are not required to define input and output parameters and pass them as data objects. If required you can defined data objects that are local to your embedded sub-process.

An embedded sub-process is mainly used to simplify the process model by grouping activities together into an embedded sub-process that can be collapsed or expanded to hide and show the implementation details.

Another common use of the embedded sub-process is to define loops which will be the case with the sample process that we will implement as part of this blog post.

We will be implementing a very simple process which will make use of the embedded sub-process to loop through a list of order items for review.

Create the basic BPM application and BPM project (i named it OracleBPM12cEmbeddedSubProcessDemoApp and OracleBPM12cEmbeddedSubProcessDemo respectively) and choose "Empty Composite" in step 3 of the "Create BPM Application" wizard since we will first create the the XSD schema file to describe our process's input and output parameters.

Next we will create the XSD schema file where we will describe our "Order" definition that will serve as our process's input parameter. On the "Schemas" folder, right click and select "New" from the context menu and from the "New Gallery" select "XML" from the Categories" and "XML Schema" from the "Items" section.

In the "Create XML Schema" window provide a name for your schema (for example Order.xsd), a target namespace (in my example I've defined it to http://www.antonis-antoniou.blogspot.com/order) and an optional prefix (for example, ord).

Define an order element with a nested order id element and a nested list of order items where each order item has an order item id, a quantity and a price. My order element definition is as follows.

Now we are ready to define the our process. Open the composite and drag and drop a BPMN Process component onto the components section of the composite. Give your process a name, for example OrderProcess and select the "Asynchronous" message pattern.

In the second step of the "BPMN 2.0 Process" wizard, with the "Input" tab selected click on the green plus icon to add a new input argument. Give your input argument a name, for example order, and in the type click on "Browse". We need to first create a business object from the schema we've created above. So click on the "Business Object" button next to the "Find" search field to create a new business object.

We will create a business object for the order element, so give your business object a meaningful name, for example OrderBO and choose an appropriate destination module to store your business object (i create a new module called "Data"). Base your business object on your order external schema (and order element).

Click "OK" to complete the creation of the business object. You newly created business object should feature in the "Browse Types" list. Select it and click "OK". Your input argument should look as follow.

For the purpose of this demo we will not need an output argument so click "Finish" to complete the creation of your process.

Create an "Order" type process data objects to store the process input argument for reference throughout the process.

Next assign the order process input argument to the order process data objects. On the "Start Message" select "Properties", "Implementation", "Data Associations" and drag source argument (Order) to target data object (order).

Drag and drop a sub-process activity between the start and end message activities and place an interactive human task activity into the embedded sub-process. You process should look like below.

Double click on the sub-process to define the loop characteristics. In the loop characteristics select "MultiInstance", select "Parallel" mode to have the review performed in parallel and in the loop cardinality select "XPath" and click on the XPath expression button to define the cardinality.

As you can see from the screenshot below I have used the count function to define the number of iterations to be equal to the number of order items defined in the request message.

Click "OK" to apply the sub-process loop definitions.

Notice how the human task activity is marked as incomplete. That’s because it hasn’t been implemented yet. So let’s create a human task definition.

Double click on the “Review Order” 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 ReviewOrderHT) and leave the rest on defaults. 

Based on the above definitions, our Order process will create a human task for each order item (in parallel). To better identify each task let's personalise the human task title to include the order item id.

To simplify the assignment of tasks, open the human task definition file and in the task assignments switch from lane participants to "Names and Expressions" and define "weblogic" as the user to be assigned our order item tasks.

We are now ready to deploy and test our process (and embedded sub-process). From the EM (Enterprise Manager) invoke a new instance of your process using two order items and open on the flow trace. Your instance should have spawn two human task activities.

Go to the BPM Workspace, login as weblogic and you should see two human tasks requiring your attention.

Approve (or reject) both tasks and go back to the flow trace. You instance should have resumed execution of your main process, and because there aren't any more activities in the main flow it should have finished its execution.

Download sample application: Embedded Subprocess

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

Friday, October 2, 2015

Suppress Approval Controls from BPM Workspace 12c - Hidden Feature

I recently came across a very interesting discussion on the Oracle BPM forum which stimulated my interest for investigation; how to suppress the human task custom outcomes from the action bar in the BPM Workspace application in 12c!

When you deploy a BPM process or a BPEL service that includes a human task component, the BPM Workspace will automatically include in its action bar the custom outcomes that you have defined on your human task.

In the image above it's assumed that a composite has been deployed that includes a human task component that defines a custom outcome "Submit".

There are cases though that you might want to suppress this default behavior and not have your custom actions appearing in the actions list but just have them displayed in the task details.

In 11g this was "officially" supported with a checkbox option ("Show approval controls in task details only") in the advanced human task properties.

Such option is not anymore available in 12c human task editor. However I discovered that the human task engine still "unofficially" supports this feature. And even though there is no way to define this option via the human task editor, you can define it in source view.

So go to your human task definition file (.task file), switch to source view and insert into the "preActionMandatoryUserSteps" element the following  

<preActionMandatoryUserStep>
      <userStep>VIEW_DETAILS</userStep>
      <outcome></outcome>
</preActionMandatoryUserStep>

Your human task definition should look like below.