Saturday, November 21, 2015

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

In this third and last part of a three part series on subprocesses we will explore a special type of subprocess referred to as an “Event” subprocess.

This type of subprocess is triggered by an event that can occur anytime during the execution of a process flow that allows you to interrupt the normal flow of an instance.

Such capability can be applicable in various use cases. For example, an error might occur in the process, or you can very well define various service level agreements to delineate execution times or you can even have a business requirement to cancel a flow (for example cancel an order).

You can use the “Event” subprocess to implement such requirements (i.e. handle system and business exceptions).

“Event” subprocesses posses various unique characteristics. One of them is that, by configuration, you can have an “Event” subprocess either as interrupting, that is interrupting the normal process flow execution or have an “Event” subprocess running in parallel (concurrently) to the main flow of your process.

Another really nice and useful characteristics of an “Event” subprocess is that it shares the same context as the main flow of the process, meaning that from the “Event” subprocess you can have access to all the data objects that are used by the main process (and of course update their state).

An “Event” subprocess resembles like an embedded subprocess (except that it’s displayed in a dashed-line boarder), however an “Event” subprocess cannot have outgoing or incoming sequence flows. And just as with the other types of subprocesses an “Event” subprocess can define data objects that are local to its scope.

We will implement a very simple process that will make use of the event sub-process to simulate the functional use case depicted by the image above; the scenario is straightforward, you can cancel an order as long as it’s not shipped.

Create the basic BPM application and BPM project (I named it OracleBPM12cEventSubProcessDemoApp and OracleBPM12cEventSubProcessDemo respectively) and choose "Compsite with BPMN Process" in step 3 of the "Create BPM Application" and click “Finish”.

This will bring up the “BPMN 2.0 Process Wizard”. Give your process a name (for example “OrderProcess” and select the “Asynchronous Service” message pattern. In the second step of the wizard I will define a single input string argument that I will name “OrderId”. For the purpose of this demo I will not create any output arguments.

The first thing that I will do is to create a corresponding string process data object to pass the “OrderId” process input argument for reference throughout the process.

I will also create a Boolean process data object that I will use later to define whether an order cancellation can be performed or not.

Next assign the “OrderId” process input argument to the “orderId” process data objects and set the “orderCancellationAllowed” data object to true (since it’s the start of the process and a cancellation is allowed).

Drag and drop two interactive human task activities onto the sequence flow that connects the message start and message end components. In the first human task we will simulate the order submission while in the second human task we will simulate the dispatch of the order.

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 interactive activities..

Double click on the “Place 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 DemoHT) and leave the rest on defaults.

Before closing the properties of the first human task activity make sure you specify a title it (just as you would like it to appear in the BPM Workspace task inbox; I named it “Place Order”).

Just to keep things simple I will make use of the same human task definition for the second interactive activity that I have in my process (don’t forget to define a title).

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.

Next I will add a “Script” activity between the two human tasks to update the “orderCancellationAllowed” process data object and set it to false (since I don’t want an order to be cancelled once it has been placed.

Now it’s time to use the “Event” sub-process to allow but also control the cancellation of an order. Drag and drop an “Event” sub-process activity just below your order definition (in the same swimlane).

Interrupting event subprocesses can start with a message, timer, signal or error activity. The default start activity is a message that we will also use.

Also notice how the message start activity of the event sub-process is marked with a warning; that’s because it has no implementation defined. So double click on the message start activity, go to the “Implementation” tab and from the “Type” drop down select “Define Interface”.
Now here is the trick; the event sub-process will invoke a request for cancelling an order. However, we will need a way to associate the request for cancellation with the initiated order. To achieve such functionality we will use a custom correlation that needs to rely on a common identifier. This will be the order id. Therefore I will create an event sub-process “OrderId” string argument.

Click on the “Correlations” link to define our custom correlation and click on the “New Correlation Property” button. Define a name for the correlation property and ensure “STRING” is selected as the correlation property type.

Using the expression builder map the “OrderId” event sub-process argument to the correlation property you just created and click “OK” to dismiss the “Correlation Definition” window.

The “Start” properties window should still be open. Please notice, just below the “Implementation Type”, the two options for configuring your event sub-process; “Interrupting Event” to basically forcibly stop the execution of your process flow and “Suspending Event” (with the options pause and resume the process flow). Ensure you selected “Suspending Event”.

There is one thing left to enable our custom correlation to work and that is to define the same correlation logic to the message start component of the main process. Since this will be the “parent” process you need to make sure you select the “Initiates” checkbox.

We have configured the event sub-process to be a suspending sub-process, meaning that it will pause the normal execution of the parent process flow. This option has a really nice feature that you can instruct the BPMN engine to resume the execution of the parent flow based on specific conditions (in our case this will be the “orderCancellationAllowed” data object.

Therefore drag and drop an exclusive gateway inside the event sub-process on the default sequence that connects the event sub-process start and end components (named it “Order Cancellation Allowed?”).

To define the resume functionality described above we will need to use a “Script” activity and use the “action” predefined variable and assign it the value “resume” (using “Data Associations”).

 Add a conditional sequence flow from the exclusive gateway to the script task and a default sequence flow from the script task to the end component.

In the properties of the conditional sequence flow define a condition that should enable that branch of the exclusive gateway only if the “orderCancellationAllowed” data object value is false (hint: you will have to negate the data object value using the “not” logical operator).

Your process should look like below.

We are finally ready to deploy and test our process (and event sub-process). From the EM (Enterprise Manager) invoke a new instance of your process (ensure you are using the “start” operation which maps to the message start event of the core process).

Go to the BPM Workspace and you should see a task in the weblogic user’s inbox.

Without submitting the task, go back to the Enterprise Manager console and invoke a cancellation request. Make sure that you use the same order id as you used for initiating your previous order request instance (because we are correlating requests from the event sub-process to the main process via the order id).

Go to the BPM Workspace and refresh your inbox. The previously task should be removed.

Initiate a new order request but this time submit the “Place Order” task. You should get another task in your inbox (“Ship Order”). Go back to the Enterprise Manager console and invoke a cancellation request (for the same order id). If you go to the BPM Workspace you should notice that the “Ship Order” task is still in your inbox. That’s because the main process has passed the acceptable cancellation threshold that we’ve defined.

Download sample application: Event Subprocess








Sunday, November 8, 2015

Running Business Processes in the Cloud

My article on Oracle Process Cloud Service has just been published by OTech Magazine in its Fall 2015 "OpenWorld Special" edition.

Oracle has been releasing a number of different cloud products, including Oracle Process Cloud Service (PCS) as an addition to its on-premise Oracle BPM Suite offering. This article briefly explains what PCS is about.

Read the complete article here.



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.


Thursday, August 20, 2015

Oracle ACE Director Confirmation!

Oracle ACE Director Confirmation!

Finally, the coveted email arrived.

"I’m pleased to inform you that your Oracle ACE Director nomination has been accepted."

I cannot be more happy and proud to be part of such an elite group, I feel really honored.

I would like to take this opportunity to express my heartfelt thanks to the ACE Program and everyone who supported me into this wonderful journey, which I can say with certainty that it’s only the beginning.

Special thanks go to my sponsor, Bob Rhubart, an incredible person and an inspiring mentor, which without his support I wouldn’t have made it.

My Oracle ACE Director profile is available here.

Friday, August 14, 2015

Using ADF BC Declarative Built-in Rules (Part 10 of 10): Method validator

The last part of my tenth part series on declarative build-int rules is on the "Method" validator, an option where you can write more complex validation rules on your business domain layer.

Method validators can be defined at either the entity level or at the individual attribute level and are coded using the Java programming language that are called automatically during the validation cycle.

Method validators have three unique characteristics; they must be defined as public, they must return a boolean value and the method name must begin with the keyword "validate", for example, "validateDepartmentManager".

Let's see this validator type in an example. In the demo that will follow I will implement a validation constraint on the HR.Departments table to ensure that an employee cannot be defined as a manager of more than two (2) department.

I have created an ADF Fusion Web Application and created the basic business components that I will be using in this demo; an entity object based on the Departments HR table, a default view object for the departments entity object and a default application module.

Because my validation rule will have to count the number of departments a specific employee is a manager of, I will create a view criteria in the DepartmentsView view object to filter departments using an employee id that will be passed as a parameter.

Next let’s define an entity level validation. From the “Business Rules” tab of the Departments entity object, click the green plus button. Give a meaningful name to your validation rule (for example, "DepartmentsManagersValidationRule") and select "Method" from the "Type" drop down.

Ensure that the "Create and Select Method" check box is selected and if needed you can customize the method name. Please make sure that your customized method name begins with the keyword "validate".


Go to the "Failure Handling" tab and define your failure message. In my example I have used a message token expression to construct a dynamic error message, passing to the failure message the department id.

When you click "OK" you should get a popup message, informing you that the entity java file does not exist and whether you want to create a default java file for the selected entity object. Click "Yes".

Before we go into the entity implementation class and define the logic for our method validator, we need to create a view accessor. Why do we need this? Well, do you recall the view criteria we created above, "findDepartmentsByManagerIdViewCriteria"? We will use this to count the number of departments a manager is assigned to.

From the "Departments" entity object, go to "View Accessors" and click on the green plus button to create a new accessor. From the available view objects select the "DepartmentsView" view object and shuttle it to the right pane.

Ensure that the "DepartmentsView" view object is selected in the right pane and click on the "Edit" button to edit the view object's accessor. Move the "findDepartmentsByManagerIdViewCriteria" view criteria to the selected pane and map the "ManagerId" attribute to the "pManagerId" bind parameter.

Click "OK" to apply your changes and close the windows. Now we are nearly ready to implement our custom validator.

Go to the "Java" tab of the "Departments" entity object and click on the edit pencil icon to edit the implementation class that was automatically generated for you when you defined your custom method validator and select the "Accessors" check box. This will generate accessors for all entity attributes and view accessors into your entity implementation class which we will use in a bit.

Now we are ready to implement our validation logic. Click on the entity implementation link to open the Java class and at the end of the class you should locate your custom method validator method. The logic should look like below:

    public boolean validateDepartmentManager() {
        RowSet departmentsView = this.getDepartmentsView();
        if (departmentsView.getRowCount() > 2) {
            return false;
        } else {
            return true;
        }
    }

I am using the view accessor defined on the Departments entity object to get a hold of the view criteria to fetch the number of departments the currently selected manager is assigned to.

Run the Application module to test the "Method" validator. Open the "DepartmentsView" view object and create a new department, assigning it one of the existing managers, for example manager with manager id 200. The record should be validated successfully.

Now try creating another department using the same manager id. The method validator should return false now and you should get your custom error displayed.

Download sample application: Method Validator