Thursday, November 8, 2012

Open a Workflow Task or Instance Trail from Oracle BAM 11g

An interesting requirement that I have recently seen a lot of clients demanding in their BAM dashboards is the ability to action or monitor process instances. Oracle BAM 11g typically provide means to create real time dashboard for process metrics to business process stakeholders. However a lot of organizations are beginning to prefer to also use it as a starting point to get more insight into instance details (such as in-flight status, flow trail, fault information, etc.). One of my reputing requirement in the past was so much as to provide a mechanism to open actionable task forms directly from BAM. And then sometime back I had the same question asked again as how to open a process instance trail directly from Oracle BAM 11g to view its fault details. This is a natural demand for process owners typically in the support role who are alerted of fault notifications from BAM and would not like to go through the trouble of going back and forth the BAM dashboard and the Enterprise Manager console to correlate instances together. This eventually led me to believe that, it is in fact a sought after requirement and hence this article will aim to provide a detailed and step by step guide to define and implement this use case.

In a nutshell, this article will demonstrate creation of actionable links in a BAM dashboard to view and instance trail of a composite instance and from there dig into its audit trail or flow trace. Another useful feature demonstrated will be the use of Action Buttons in Oracle BAM 11g dashboard to launch instances of human workflow tasks of a BPMN composites awaiting to be actioned from designated process users. When such an instance is clicked the user is taken to the BPM workspace UI and take an action on the selected task.
This allows business users to seamlessly monitor business applications and processes and be able to correlate them with instances appearing across different UI’s of the Oracle SOA Suite 11g product suite such as BPM Workspace and EM Fusion Middleware Control console. It is essentially useful for organizations that intend to use Oracle BAM as an operational dashboard for process users in addition to it being used as a real time business metrics monitoring and alerting dashboard.

Take a Sneak Peak at the Use Case
The following video will show a sneak peak of the use case intended to be demonstrated in the course of this article.

During the course of implementing the use case, the article will also describe the following activities in detail:
  • An Overview of creating and assigning values to a business indicator and publishing it to Oracle BAM data objects at runtime.
  • Configuration changes involved in sending the process metrics data from a BPM process to BAM data objects such as activating sampling points, enabling data targets, configuring the OracleBAMAdapter and altering BPMN engine MBeans .
  • Create Streaming Action Lists in an Oracle BAM reporting view to track in-flight instances of a composite that are assigned to process owners, waiting to be actioned. and a list of completed instances.
  • Create an action list of completed instances and define an action to launch their audit trail in the Enterprise Manager console. This concept is useful as this can be extended/customized to instead create a list of faulted instances for users to gain detailed insight into the fault details from the Enterprise Manager Fusion Middleware Console.
  • Configure External Data Objects and create lookup fields in BAM.
  • Create and configure action buttons in Oracle BAM to open an external URL and pass the value(s) of a column in an action list for a selected instance to the URL term.
To gather process metrics and activity instance data in BAM to be able to build the reports, an existing BPMN based composite will be used. The composite project can be downloaded from the example demonstrated in an earlier BPM post on event based gateways. The article also describes the use case the project tries to address in details.
The download link for the application workspace is provided in the aforementioned article. The soapui project to create sample instances and thus populate the BAM reports is provided at the end of this article.
Prerequisite(s)
The modelling workspace and the version of Oracle BPM and BAM Suite used in this demonstration is 11gR1PS5 i.e 11.1.1.6 although the concepts discussed are generic and applicable to all versions.
Creating the Business Indicator(s)
Import the application workbench consisting of the modelled process in JDeveloper. To begin with the article describes adding a business indicator to capture the credit card approval status as the instance progresses through multiple activities.
In the JDeveloper menu click on View > BPM Project Navigator and open the AccountOpeningProcess business process. You will notice a Structure pane visible in the bottom left hand side of the editor. If the structure pane is missing then click on View > Structure to be able to see it. Expand Business Indicators > Dimension and right click on it to be able to add a new dimension of type String. Name the dimension as cardApplicationStatus. For simplicity this article just has a single business indicator, though in real business processes you may end up having multiple KPI collecting indicators.

image

Once an indicator has been defined, it has to be assigned a certain value to depict a business friendly state of the process instance is currently in. Have a look at the red information rectangles for the AccountOpeningProcess as depicted in the screenshot below. They may well represent the various business friendly stages of the application status. For example, when a New Application request is received  by the process the business indicator may be set to “PPLICATION IN PROGRESS indicating that it is being currently processed upon. If the customer for any reasons wants to terminate his application midway while his initial request is in-flight, the application status may be transitioned to “REQUESTED CANCELLATION”. Similarly there may be other intermediate statuses that can be captured in a long running business processes and be presented to business stakeholders or process owners.

image

Populating a business indicator with a pre-determined value is straightforward. It is in a similar way as a value is assigned to any other process variable. Double click on the New Application start message event and then on the Data Associations link. Simply drag the Expression icon on the cardApplicationStatus metric variable under OnlineAccountOpenin>DataObjects on the right hand side of the Data Association wizard and assign it a static value of “APPLICATION IN PROGRESS”.

image

Similarly, double click the Cancel Application intermediate event and then assign REQUEST FOR CANCELLATION to the same business indicator from the Data Associations link. When the business processes receives an intermediate request for cancellation while the task is still in progress, the cancel application intermediate event is invoked and the latest status of the process instance (determined by the cardApplicationStatus business indicator) is replaced. Use the same technique to assign other possible approval states to the business indicator for other activities.

image

Configuring Sampling Points and Data Targets

Now that the business indicators are assigned appropriate values describing meaningful process states, the next thing is to publish these indicators to BAM. Readers familiar with Oracle SOA Suite will know that sensors can be defined for the BPEL engine to automatically publish their data to BAM data objects in real time as soon as their values in the business process changes. Unfortunately as of now, sensors cannot be defined in Oracle BPM Suite. Instead there is a concept of Sampling points.  The BPMN Service Engine uses the defined sampling point configuration to decide when and where to publish process analytics information. Process analytics sampling points can be created for all activities, just interactive activities or disabled altogether. The process metrics can be published internally to the in-built cube star tables in the SOAINFRA schema or externally to BAM data objects. The process sampling points can be configured by right clicking on the BPM process from the BPM Project Navigator view and then clicking Project Preferences . This article needs sampling points to be generated for all activities in the business process, hence Generate for All activities from the Project Sampling Points radio options is selected. Sampling points capture a host of other information in addition to capturing the values of defined business indicators such as performance and workload metrics. Also note that choosing Generate for All Activities will generate a lot of data to be published to BAM. More information about Process Analytics and Sampling points can be read at the official Oracle documentation site at
By default the sampling point only publishes process metrics to the internal CUBE_* tables in the SOAINFRA schema. To publish these analytics data externally to BAM click on the Data Targets tab and check Enable BAM option. Also change the default Data Object Path to something like /Customer/AccountInitiation. This ensures that all data objects pertaining to a project are created in the folder hierarchy entered in the data object path field.  This external publishing of the BPMN engine data to BAM data objects in the active data cache is taken care by the OracleBAMAdapter. This adapter has two predefined connection factories. It allows either publishing the data to the BAM engine either through a RMI interface or through a web service interface.  The BAM Adapter JNDI name for these interfaces is either eis/bam/rmi or eis/bam/soap respectively. The eis/bam/rmi provides a better performance as this doesn’t employ the BAM web service interface and used preferably if the BAM and BPMN engine reside in the same JVM.

image

Configuring the OracleBAMAdapter

The integration glue that binds and permeates instance metrics information to pass from the BPMN engine to the BAM active data cache is the OracleBAMAdapter. The  BAM adapter needs to have the same JNDI (one that was selected in the previous step) configured that is pointing to the correct instance of the BAM active data server. Oracle Weblogic Server administration server console provides the mechanism to view and edit BAM adapter configuration properties. Login to the administration and navigate to Summary of deployments > OracleBamAdapter > Configuration > Outbound Connection Pools and click on the eis/bam/rmi connection pool to view its default configuration properties. These properties may have to be changed to point to the correct instance of the BAM active data cache server. It is also important to note that any change in these adapter properties are applicable only when they are saved and the adapter configuration is updated. This typically happens when the adapter is either redeployed with the changes in the plan file or updated with  the saved changes.  Proper configuration of all of the above settings is important for the BPMN engine to be able to plug with the BAM server.

image

On an Oracle BPM Suite 11g PS3 and above, with only these changes in place, simply deploying the BPM project will create the necessary data objects in the BAM active data cache. Open the Oracle BAM console and click on the BAM Architect view to be able to see the list of data objects existing in the BAM active data cache server. Notice the AccountInitiation subfolder created under DataObjects > Customer folder. Under this hierarchy will be the data objects containing the instance metrics data published from the BPMN engine. Later parts of this article will show how these data objects will be used to create interactive reporting view in BAM.

image

BPMN Engine MBean configuration Alteration to Allow the engine to post data to BAM

As discussed earlier, the above set of configuration changes are sufficient to create the data objects when the business process composite is deployed to the application server. Now when an instance is created and executed it is expected that these data objects will have process metrics value populated at near real time. However the contents of the data objects are not be populated unless a certain disable action to supress process measurements to be sent to the BAM engine is turned off. Login to Oracle Enterprise Manager Fusion Middleware console and navigate to soa-infra > SOA Administration > BPMN Properties > More BPMN Configuration Properties to view the configurable BPMN engine MBean properties. Scroll down the list to see the DisableActions property. The default value for this property is BAMCommand, which supresses measurement actions to be sent to BAM. Clear this field (leaving it blank) and save the settings. If another instance of the BPMN process is now executed, the BAM data objects will being to be populated with measurements obtained for the  various process activities.

image

Creating the Reporting Dashboard in BAM

With the data objects being able to receive measurement data from the business processes, the next thing to do would be to create the BAM reporting dashboard. The dashboard to be developed in this article will have two horizontal regions each displaying a streaming action list of its own. The idea is to have one of the horizontal view displaying recently completed instances and have a hyperlink defined to launch its detailed audit trail in a pop-up while displaying the list of in-flight instances in another. The view showing the in-flight instances will also provide an action button to launch the approval task form for the the selected instance.  As a desirable feature a similar  streaming list of displaying the faulted instances can also be created that leads process users enlisted as support stakeholders to the flow trail to know the exact point and reason of failure.
Login to the Oracle BAM 11g console and from the landing page click on Active Studio (this is where reports and alerts are create in BAM). Click on the Create a New Report link to open the tiled report template selection screen. Select the template titled Two equal horizontal tiles with thin separator. From the list of various report types in each of the horizontal tiles select Action List and  title the report as Credit Card Approval Scoreboard. Each of the report views will prompt for a data object to be selected from which the view will sources its data content.
The upper horizontal tile is used to display a list of completed instances. For this view select BI_default_OnlineAccountOpening_AccountOpeningProcess as the data object and then click on the Fields tab. This lists all the fields in the data object. From a reporting standpoint, it may not necessarily make sense to display all the fields in the data objects but only a few important ones.  For the report in this article, the selected fields are COMPOSITE_INSTANCE_ID,  BI_NAME, COMPONENT_START_TIME, COMPONENT_END_TIME, COMPONENT_INSTNANCE_STATUS, COMPOSITE_NAME, COMPOSITE_REVISION, DOMAIN_NAME and METRIC_cardApplicationStatus. These fields however will appear in the report in their alphabetical order. To change this check the select-boxes corresponding to these fields and use the Arrange icon to rearrange them to be displayed in a custom order. Optionally the report can also be pre-sorted based on values a particular field by moving the field under the Sorted Fields panel in the Sort tab.

image

Another important thing worth mentioning here that if the view configuration is left just as it, a whole lot of duplicate instances will appear in the list. They are not necessarily duplicate as the process measurement data is published for every activity. Therefore the same composite instance will have as many rows in the data object as the number of activities in the original business process. There will however be only one row with the latest snapshot of the process. In order to show only the unique and non duplicated list of composite instances in the streaming list the Filter tab can be used to and add a filter expression to discard the non-latest snapshot of an instance. Add a new filter entry and for the filter expression select the field as LATEST from the data object fields, the comparison type as is equal to and equate it to a value of Y. For the report in this article, yet another filter is added to display only the approved instances by adding a filter expression to equate the METRIC_cardApplicationStatus field to a value of APPROVED. The list can be narrowed further by adding more filters to the list.

image

The Properties tab allows to change the view name, fonts and other visual aspect of the streaming list.The final streaming list view should resemble something as shown in the below screenshot.

image

Hyperlinking a Column in the Report with an Action

Well, the teaser video above showed that the composite instances in the view were hyperlinked which when clicked pops up the audit trail (as seen from the composite dashboard of Enterprise Manager Fusion Middleware Console) for the selected instance. Now for the creamy part of this article, it will be described to create and implement action buttons in Oracle BAM and how they can be used in a report. Select the Completed Instances streaming list report tile and then click on the Change Report Properties link under the report Actions menu. This opens the Report Properties popup dialog. Click the Actions tab and then the New button to create and configure a new action for the report. Provide a name and optional description for the action name and hit Next.

image

The Action Type lists various action that can be performed on data in a report such as executing a read/write action on data input, selections from that action list or form, open an external URL etc. From the options in the select the Open a URL radio box and then click on Next to open the Action Editor. The action editor provide a very convenient feature to construct a URL by creating a combination of terms term which can be concatenated in the end to form the final URL. These terms can be configured to either have constant values or represent dynamic columnar values from any selected view in a report.

image

Before being able to configure the URL term, it is required to know how to open the link to the audit trail of an instance. The audit trail of any composite instance can be directly viewed in the browser by using the link below.
http://<hostname>:<portName>/em/faces/ai/soa/messageFlow?target=/Farm_<domain_name>/<domain_name>/soa_server1/<partition>/<composite_name>%20[<version>]&type=oracle_soa_composite&soaContext=<partition>/<composite_name>!<version>/<instance_id>
The link, however is made up of a lot of instance specific information such as the host, port and partition of the soa server where the composite is deployed to, its version and the instance id. Interestingly all but the host name, port name and the domain name (Weblogic server domain name) can be figured out from the default data object itself. They can either be hard coded for each instance of the BAM server to have the corresponding value of the SOA server or the other ingenious way is to create a table in the database and read the values from it. The instance specific information can be directly derived as values of the selected row from the view list. There are other ingenious ways to do it if you dont want to hard code these values. Entering constant values for a URL term is pretty simple. Simply choose the Mapping Type as Constant Value to be able to enter the hard coded part of the URL.

image

The dynamic part of the URL value can be added in a two step process. First select the choose Value from a List View radio buttonin the Mapping Type and then select the view from the report skeleton containing the streaming list to populate a drop down of the data object columns used in the list. Select the appropriate column value that is needed in the URL. For instance, the COMPOSITE_NAME, COMPOSITE_REVISION, DOMAIN_NAME (this is the partition contrary to the Weblogic domain name) and COMPOSITE_INSTANCE_ID may be required as dynamic values in the URL. There is no restriction on the number of terms that can be created as a combination of constant and lookup values to form the complete URL.

image

The final Open a URL configuration screen will contain multiple entries that are a combination of constant hard coded values and dynamic values from the list. These are concatenated together to form the actual URL for the hyperlink to be launched when the composite instance column is clicked in the list view. The wizard also allows editing the features of the popup. Click on the Click here to edit Windows features link and choose Full screen for both the width and height of the popup window to display it in full screen mode.

image

Now that the action is defined the last remaining bit is to configure the action button itself. Click on Next to be presented to the Button Formatting screen. Select the Display the button in a view radio button and from the visual empty report  skeleton select the streaming list view to which the URL action needs to be added. As a hyperlink is desired on the composite instance id column for the view check the Display as a column of formatted links in the selected view option and from the Column to format dropdown choose COMPOSITE_INSTANCE_ID. Click OK on all the screens to save the changed report properties.  With this the configuration changes required for the Completed Instances view of the reporting dashboard is complete. The article will shortly demonstrate how the final view looks like and what does the configured action list do.

image

Adding the SOAINFRA Schema as an External Data Source

In the following part of the article, another interesting aspect of the use case that is to view the task form of an instance that is awaiting an action from a process user will be demonstrated. But before going ahead with creating the report view there is something else that has to be taken care of. In order to open a task form corresponding to a particular instance id, its taskId is required. Unfortunately the default business indicator metrics data object does not contain the task id. The easiest way to lookup taskId for a composite instance is to query the WFTASK table in the SOAINFRA schema.
select taskid,state from wftask where compositeinstanceid=?;
However the problem is that composite instance id and taskId share a one to many relationship. The query to retrieve taskdId from compositeInstanceId my return more than one row and not all of them can be used to open the task form. Another important thing to know would be that only the taskId row that has the value of the state column as ASSIGNED indicates the current task(s) that are pending actioning from process users. This is achieved by simply appending a filter on the state column.
select taskid,instanceid,ecid from wftask where compositeinstanceid=? and state=’ASSIGNED’;
It is therefore required that there is some sort of mechanism available in BAM to lookup these required field from the database table. This is facilitated in Oracle BAM using external data sources. To begin with open the BAM Architect view from the landing page and click on External Data Sources. Click Create to configure an external data source, provide a suitable name, say SOA_INFRA and connect to the [PREFIX]_SOAINFRA schema. Check out the screenshot below to see as how to provide the schema name, password and the connection string. Verify that the connection to the schema is established by clicking the Test button at the bottom.

image

Creating an External Data Object with the WFTASK table

The external data source can now be used to create an external data object. Browse to the AccountInititation subfolder and click on the Create Data Object link to create a new data object. Name it as TaskDetails. Check the option box beside External Data Object  indicating that this data object sources its content from a database table instead. Select the external data source that was created in the previous step and then select WFTASK from the dropdown under External Table Name. The columns of this database table are now available to be added as fields for the data object by clicking on the Add a field link. The fields that are added from database table are COMPOSITEINSTANCEID,TASKID,PROCESSDUEDATE,ACCQUIREDBY,ASSIGNEES,ASSIGNEEUSERS,CREATOR,STATE,INSTANCEID,ECID. Note that only a few of these fields will be needed to configure the report view. After the fields are added click on Save Changes to save the data object. View the Contents tab of this data object to see the selected columns for all the rows in the database.

image

Adding Lookup Fields in the Business Indicator Data Object from the External Data Object

As discussed earlier the streaming action list view to display the in-flight composite instances with human tasks will need to source its reporting data from the BI_default_OnlineAccountOpening_AccountOpeningProcess data object. But somehow this data object would need the additionally  required fields too such as the TASKID, STATE. These fields can be looked up from the TaskDetails data object. This is straight forward as Oracle BAM data objects allows creating look up fields that can be created to look up data from different data objects. Open the BI_default_OnlineAccountOpening_AccountOpeningProcess data object and click on Layout > Edit Layout to be able to add lookup fields to it. Once in the edit mode, click on the Add one or more lookup fields link at the bottom to open the lookup field definition popup. Select the TaskDetails data object and from the list of Lookup Fields click on the TASKID field. This lookup however will be based on some common fields in both these data objects. Select COMPOSITEINSTANCEID from the list under Fields to match from Lookup Data Object  and COMPOSITE_INSTANCE_ID from the list under Fields to match from this Data Object. Click Add to define the lookup criterion. More than one such lookup criterions can be added if needed be. Similarly add another lookup field i.e the STATE from the TaskDetails data object. Keep the lookup criterions based on the COMPOSITE_INSTANCE_ID and COMPONENT_INSTANCE_ID. Now the  BI_default_OnlineAccountOpening_AccountOpeningProcess will also have the values for TASKID and STATE for a given composite instance.

image

Configuring the Streaming Action List for Inflight Instances
Make sure everything is saved for the moment. Edit the  original report template and for the next horizontal tile too select the view type as Action List. The streaming list view will have to be now configured to show the relevant in-flight live instances. Open the report in the Edit mode. For the data object field select the same data object as used in the previous view i.e BI_default_OnlineAccountOpening_AccountOpeningProcess. Go to the Fields tab to select and arrange the following fields in their order: COMPOSITE_INSTANCE_ID, BI_NAME, COMPONENT_NAME, METRIC_cardApplicationStatus, STATE, TASKID. From the Sort tab add BI_NAME and METRIC_cardApplicationStatus under the Sorted Fields.

image

As stated earlier if no filters are applied to this data object list, it will end up displaying all the instances against all executed activities in the business process. In order to view non-duplicated composite instances only the ones that are latest are to be filtered out. and just those that are assigned to process users. Having such filters is easy. Click on the Filter tab and click on Add Entry. This opens the Filter Expression wizard. Add a filter for the STATE field having a value of ASSIGNED. Similarly add another filter for the LATEST field to have a value of Y. This would do the work.

image

The display settings of a report are configured from the menu tabs under for the Properties button. Click on the Properties button and under the General tab enter Live Instances for the View Title. By default the streaming action list shows checkboxes against all the rows in the report. Change these to radio buttons so that only an instance is selected at a time. Go to the Actions tab and select Single Select (radio buttons) options.

image

Once these settings are applied and saved the streaming list will show the in-flight instances along with their task identifier and the pending action. Optionally, the task creators, assignees, task expiration time, priorities etc. can also be shown in this list to have a better visibility as to which tasks are assigned to which process and which tasks needs urgent attention. Also note that the column titles displayed in the screenshot below is different from the data objects fields. This can be done by overriding their default names from the Text and Align tab under the Properties button.

image

Define an Action Button for the selected instances of the List
The final piece in the hook is to define an action button for a selected row in the report view. What is desired here is that when a row is selected the action button should take the users to the approval form for the selected instance. This would effectively mean launching the business process workspace view of the task form allowing it to be actioned if needed be. Opening the task approval form is easy. The URL to be used to launch the task form simply needs the HOST and PORT on which the business process workspace is running and the task id of the composite instance (which is obtained already and displayed in the list).
http://HOST:PORT/integration/worklistapp/faces/home.jspx?taskId=TASKID
The same set of steps that were discussed earlier to create an action button can be executed once again to create another action button. Open the report once again in the Edit mode, select the view and click on Change Report Properties.  Click on the Actions tab and then the New button to open a new action editor wizard. Name this action button as View Approval Page. In the next screen define the type of action as Open a URL. The URL for the action button can be configured by adding constant or dynamic strings (here referred to as Terms) which when concatenated will give the complete URL string.

image
Create a New Term with constant value by passing the entire URL string except the TASKID in it. Be sure to replace the value of the HOST and PORT with that of the server instance running the business process workspace user interface. Add another New Term but this time choose Value from a List View from the mapping type action list. The next screen displays the report skeleton from where select the live instances view in the report. This will show all the selected data object fields configured for the list as dropdowns under Select a column from this view column. Select TASKID and then click OK. 

image
In the following Button Formatting screen simply select the Display the button in a view radio button under the Button Location panel. This will add the action button in the same view. For rest of the screens simply click on OK to save the report property changes.

image

Appreciating the End Result
Well, that’s it! After all these changes your BAM users will be able to see two streaming lists of completed/historical instances and in-flight instances. The users will also be able to view the instance audit trail by clicking on an instance in the list and if they happen to be process users then also action in-flight instances by selecting it and clicking the View Approval Page action button. This also allows you to create a seamlessly correlated view of instances across the multiple dashboards that Oracle SOA Suite 11g has to offer. It is important to note that not everyone in the organization will be able to view the task-form for the instance. Only users who are assigned to the process roles to action the task will be able to do so. This ensures that the security aspects of this implementation methodology is also covered
image
Downloadable Resources for the Project
You can import these data objects and reports into your BAM server by running the ICommand utility. The easiest way is to copy all the dataobjects and reports in the DataObjects.zip file to the <MIDDLEAWARE_HOME>\Oracle_SOA1\bam\bin directory and then run  icommand –cmdfile import.xml in the command line. Before running the Icommand utility make sure that the BAMIcommandConfig.xml file under the <MIDDLEAWARE_HOME>\Oracle_SOA1\bam\config directory is configured to point to the correct instance of the BAM server. A detailed explanation of working with the ICommand utility can be read here at http://docs.oracle.com/cd/E14571_01/integration.1111/e10224/bam_app_icommand.htm
Feel free to post comments and suggestions, and possible improvements and I will be glad to incorporate them here. If you have a similar requirement and are struggling to re-create a reporting dashboard similar to what is proposed, send us a message.
 

Saturday, May 12, 2012

Understanding Event Based Gateways in Oracle BPM Suite 11g

In my previous blog post I had covered an example and use case to use Complex Gateways in Oracle BPM Suite 11g. Complex Gateways allows you to implement a special type of dead path elimination modelling and may be very useful in scenarios where it is required to synchronize N paths from M incoming transitions. The full post can be accessed at the link here : http://blog.rubiconred.com/2012/03/using-complex-gateways-in-oracle-bpm-11g.html
In this post, I will try to provide a pattern, example, use case and practical demonstration to use an Event Based Gateway, which is yet another important modelling concept in BPMN based process. Apart from the usual stuff I would also share a few interesting observations on Interrupting events that may be useful among other things.
Knowhows of an Event Based Gateway
Event based gateways are a special case of deferred choice pattern where the process chooses a specific sequence and branch depending on the interaction with an external environment thereby allowing for true dynamicity. This is different from the exclusive gateway in the sense that it allows a branching point where alternative paths are determined based on intermediate events coming from external systems. The message flow waits at the event based gateway waiting for a token to arrive from any of its branches. The token can be a receipt of an event message, a time cycle or a receive task. The first event triggers one of the alternative to the exclusion of any other path from the gateway. Essentially, the Event “pulls” the Token from the Gateway, where it will continue down the sequence flow that leaves the Event.
Introducing the Use Case
The use case explained here in this blog is that of a simple banking process to automate online opening of Bank Accounts. The process initiates with an application request being received from an Online Portal and verifying if a customer has already made an application earlier. If a similar request is already in process it is rejected and an appropriate notification is sent to the customer. Otherwise the process generates a provisional Account/Application Id and initiates a process to mail the account starter and contract kit to the address received from the customer. The customer is additionally sent an email with the necessary details and asking him to send back the proof of identity related documents and a signed copy of the contract within 7 days. This is where the process waits to receive documents from customer or remind him again after 7 days. The event based gateway branches into two sequence; 1) an intermediate event that receives an acknowledgement of customer documents being received and 2) a timer based event that waits for 7 days, sends a reminder email to the customer and loops back into the gateway.
image
Notice the illustration of the BPMN process for AccountOpeningProcess above has two event based gateways.
  1. Process Online Application
  2. Receive Supporting Documents
The Process Online Application gateway is a gateway of instantiating type meaning that it doesn’t need any incoming sequence flow. This kind of a gateway is useful if there are multiple types of messages or events that can start a business process. To demonstrate this use case follow the Event subprocess for cancelling in-flight applications. Whenever a cancellation event is received intermittently within a process an exclusive gateway decides whether a CustomerExperienceExecutive should make a personal call and deter the cancellation. If a resolution is reached i.e by means of changing the account type, account charges and privileges, the main process is re-initiated. Thus the process ends up having multiple start events, one that is for new applicants and one that is for re-applicants for whom the CheckCustomerSummary step may be skipped.
On the other hand the Receive Supporting Documents gateway is non-instantiating type and hence has both incoming and multiple mutually exclusive outgoing sequence flows. The event based gateway after the task indicates that the process actually waits for two different events that could happen next: Either the acknowledgement is received from the process handling document acknowledgements from the customer, as indicated with the Supporting Documents Received message event, or there is no acknowledgement for 7 days after which a reminder is sent to the customer.
It is important to know that Event based gateways with one outgoing Event/Receive Task and one timer event can be modelled in a different way as well, thereby completing the need to have a gateway at all. The timer boundary event can be used on the Receive task as shown under. But anyways the idea here is to show how event based gateways work in real life use cases.
image 
Prerequisite(s)
The modelling workspace and the version of Oracle BPM Suite 11g used in this demonstration is 11gR1PS5 i.e 11.1.1.6.
Modelling the Process
Follow the BPMN model explained in the use case and recreate it in JDeveloper BPM Studio. Else the modelled process can be downloaded from the link here.
image
For the sake of reusability I created a reusable process to send email notifications that can be invoked from multiple places in the main process using a Call Activity.
A Call Activity identifies a point in the Process where a reusable global Process is used. The Call Activity acts as a wrapper for the invocation of the reusable process by transferring the control to the called reusable process. A Reusable Process on the other hand is a reusable, atomic process definition that can be called from within any Main Processes by a Call Activity. The reusable process in this example determines the content and subject of the customer notification by using a rule activity and sends an email notification accordingly.
image

Implementing the Process
Open the downloaded application workspace for the project or if you have created a one of your one, then double click on the Process Online Application event based gateway and in the Implementation tab check the Instantiate checkbox.
image
The first thing required is to add all the Request and Response types from the schemas in the xsd folder as business objects in the business catalog of the process. The two message events sequences for new applications and reapplications are based NewAccountRequest type and the Send Application Status end event is based on the AccountApprovalResponse type.
image
Take a close look at the three events intermediate events in the process:
  1. Supporting Documents Received
  2. Cancel Application
  3. Reapply
All of these intermediate events receive some form of communication in the middle of the process and hence has to correlate with the actual instance of the main process. If a correlation is not defined then two things can happen. Either a mid-process receive will create its own instance or there will be an error in the process due to conflicting receive. Hence the message start events has to initiate a correlation and these intermediate events need to use them.
For the purpose of this example, the taxNumber of the applicant is used as the correlation key as it is assumed that this should be unique.
image
And similarly in the intermediate message receive events, the same correlation key needs to be used to relate the incoming request to existing instances. So when an external system sends the acknowledgement when supporting documents from the customer has been received the message is correlated back to the original instance.
image
The rest of the process is easy to implement. Activities that cannot be implemented may marked as draft and the exclusive gateways can have conditions that favour the happy path of the process. All the Call Activities invoke a reusable process that run a business rule to populate the Email subject and body and sends an email. Creating reusable processes is an attractive pattern and should be widely adopted as this allows to keep fragments of common functionalities globally that are accessible for multiple processes.  A sub-process or an event sub-process on the other hand may contain functionality that is common in a particular process and may be accessed from multiple process points.
image
The implemented process and the JDeveloper workspace can downloaded from here in case you want to spare yourself from the work and go straight to test and see results.
Testing the Process and Seeing Results
New Application Request
Deploy the implemented process to a BPM domain. The process has an event gateway of instantiation type that waits for either a new application request or a reapplication event message to arrive. A business process that has a message start event like this, has a service endpoint and can be invoked as a standard soap based service. Use any SOAP testing tool (SOAPUI for instance) to invoke the business process operation that accepts new account opening application request.
image
The Process Online Application event gateway initiates the sequence that has the New Application message event and the instance stalls at the Receive Supporting Documents event gateway. The instance status will be Running and the token will stay here until an acknowledgement is received from a support process or the waiting time exceeds seven days.
image
The process Flow trail gives another diagrammatic view of the sequence of activities executed for this instance.
image
Now for the sake of testing the intermediate event based gateway, the Supporting Documents Received message is sent to the process with the same taxNumber as the original request and the event will correlate it with the running instance.
image
Executing the above request will result in another instance ID being generated in the BPMN service engine but this instance correlates with the already in flight one. Since the documents are successfully received within the given time frame the token moves from the event based gateway to the Supporting Documents Received message event and consequently completing the instance.
image
Check out the flow view to see a graphical trail to see how the instance executes forward from the event based gateway and completes.
image
Cancel Application Leading to Reapplication
The above example show how an intermediate event based gateway behaves. Now let me demonstrate how an event based gateway of instantiation type works. For this example, I will again invoke the process with a new application request, but while the process is waiting to receive documents from the applicant, a Cancel Application event will be fired. This is picked up by the Cancellation Event Subprocess and correlated to the running instance. The subprocess evaluates the reason for cancellation and if required creates a task for a CustomerExperienceExecutive role to personally call the customer and seek a resolution. If a settlement is reached i.e by altering the account charges, privileges or type etc., the instance is sent back for reapplication. The Process Online Application at the beginning of the main process has a sequence flow that waits for this kind of event that picks up the message and continues the process flow, only this time there is no check performed to check client history.  The first step is to create a new request once more and then invoke the cancellationRequest operation.
image
In the Composite dashboard, there will be two instance of the process now, one that has completed (original) and one that is running (reapplication).
image
The first instance is marked as Completed as the Cancel Application Event is an intermediate event of Interrupting Type and hence when it reaches an End activity the actual instance itself is marked as completed.
image
The audit flow shown below gives a better picture of what happens to the instance in this case.
image
Now inspect the other instance that is marked as Running. This spawns from the Reapply intermediate event and this time the gateway branches to the sequence that has the Reapplication Event Message type.
image
The flow trace exactly reveals this behaviour where a new instance is created, only this time with a different message types and executes upto the next gateway.
image
I made some following interesting observations while implementing and verifying the test results for this process that I would like to share.
  1. If the Cancel Application throw intermediate event in the Event Subprocess is of non-interrupting type and the end event is of Terminate type, the process behaviour should ideally be the same. But it is not. While a new instance spawns up correctly but the original instance is marked as faulted.
  2. Since there is a process service call being made from the Reapply throw event that is caught by the Reapplication message catch event, it is not necessary to create a correlation between these events. If a correlation is not defined, the engine should mark the original instance as completed (as it flows to the End event) and create a new independent instance from the Process Online Application gateway. But there is a little deviation here. In this case both the instance states are marked as Completed in the dashboard view but when drilled down to the audit trail, the process instance is shown to be running and waiting at the Receive Supporting Documents gateway.
This article comes to a conclusion here and hopefully it was able to provide an insight into how Event based gateways can be used in Oracle BPM Suite 11g and also some thoughts on intermediate events. Event based gateways are extremely handy while designing loosely coupled business processes using a deferred choice pattern.
The JDeveloper workspace and sample requests to execute this Oracle JDeveloper/SOA Suite 11.1.1.6 is available to download from here.
Feel free to provide comments, suggestions and feedback for this post and we will be happy to do respond back.

Wednesday, March 14, 2012

Using Complex Gateways in Oracle BPM 11g

Starting here and in some of the forthcoming blog posts I will try to cover some basic and advanced gateway patterns in Oracle BPM Suite 11g.
This post shows how and in which scenarios do we need to use a Complex Gateway in a business processes modeled with BPMN techniques.
The Knowhow
Complex Gateways are required to synchronize N paths from M incoming transitions.  This gateway is a point in the process where M parallel (or inclusive) branches converge into it and the following activity is enabled once N incoming branches have been triggered (or their outcomes met). The result of the rest of the M minus N branches is ignored. The merge is blocked till the M incoming branches have been triggered and unblocked when their execution is completed.
Complex Gateways are rare in business process modeling but very essential to realize some very common workflow patterns. Consider for example a widely used modeling technique that supports explicit skipping of activities. Imagine how you use an OR gate to write conditions to negate the sequences that you don’t want to be executed.This is commonly referred to as dead path elimination. However, the OR join cannot be applied in all cases of dead path eliminations. The complex gateway is intended to model complex synchronization behavior. In general,firing behavior of the complex gateway is specified using an activation expression which is evaluated with the reception of every token. It might reference separate token counters for each of the directly preceding sequences. Once the activation expression evaluates to true, a token is created on the normal output flow. The gateway is also capable of aborting all pending flows and finally resets by creating a token on the optional reset output flow.
The Use Case
To process a security clearance application, a business process needs to check concurrently whether the applicant has a criminal record, is a natural citizen, and has sound credit history. The outcomes of these checks is to be evaluated in such a way that as soon as two of these checks pass and the applicant doesn’t have any criminal history, a clearance is granted, and the third check is aborted. This pattern, a special case of the N/M join.
Complex Gateway
The Security Clearance Process has three sub processes Criminal Record Check, Natural Citizen Check, and Credit History Check that are run in parallel (having been launched by the AND parallel split from Initiate Security Checks). There is also a special complex gateway element (diamond with an asterisk) to evaluate the outcome of responses coming from each of the sub processes. This is a typical example of a 2 of 3 join with one precise condition to be met.
Prerequisite(s)
The prerequisite to create and use the business process explained in this post you would need Oracle SOA Suite 11g PS4 or higher.
Modeling the Process
Let me begin with trying to model the business process as shown above in JDeveloper BPM Studio. It involves creating a composite project with BPMN extension and then creating a BPMN process with an asynchronous interface. The start event is a message start type that accepts personal information header to be able to process security clearance for an individual.
image
The next step involves creating a gateway of complex type in the business process and changing its type to “Parallel and Complex”. From the parallel arm create three sub processes that converge to the gateway merge.
image
Each of the sub processes are implemented to invoke a service that takes in the personal information of an individual and returns a corresponding response. For example, there is a criminal check service that returns the crime history and all available crime records for an individual based on his SSN. These services are mocked to be able to execute the process and are packaged in a WAR file (Complex Gateway Services).
The way i chose to implement each of the sub process is decouple them from the validation services totally.  Raise an event to check an individual’s crime history and then let another process subscribe to it (implemented with BPEL). The BPEL process then invokes any number of services to gather the crime records and finally publishes a status event by itself too.  The original sub process then have an intermediate mid process receive event that subscribes to the validation status, correlates and ends. Don’t worry too much if you do not get what is explained. You can import the process (application) being discussed from the link here.
image
The GetCrimeHistory mock service is returns a list of criminal records (if they exists) and a Boolean flag called recordExists (true if SSN begins with 1, false otherwise).
The other two sub processes are implemented in the exact way, only they invoke a different set of services to check the status of citizenship and  obtain a credit history for an applicant.
What is of typical importance is the Gateway Merge point that evaluates the outcome/results of these sub processes. Now as per the use case, there are two checks to be evaluated to go ahead further down the process, 1.) confirm whether there is any record of crime existing for the applicant 2.) get a valid approval check response from either the credit history check or citizenship status check sub processes.
The first condition is enforced with the expression crimeSummary.recordExists==false. The logic for the second condition is provided by checking the value of the activationCount variable (predefined). This variable holds the value of tokens being received at the merge gateway. As per the expression below, if at least two tokens are received then the process is good to move ahead. The checkbox to Abort pending flows ensures that when the flow control moves ahead after receiving the required tokens, all pending sequence flows are abruptly cancelled (This can be perceived as dead path elimination without writing a negation condition on any of the sequence flows).
image
Executing the Process
Deploy the completed process to the BPM infrastructure as a composite application. From the Enterprise Manager console navigate to the deployed composite dashboard. Since the business process had a message start event, it can be exposed as a standard service. The Test button on the composite dashboard can be used to test the composite application.
Test 1 : Criminal Record is Present
Create a test request for the composite operation so that the criminal record status flag is returned to be true(Value of input SSN to begin with 1). Invoke the service and wait to let the execution complete. Lunch the audit trail to analyze what happens and how does the gateway evaluates the sequences.
image
The process executes in entirety and is successfully completed. However to examine the behavior of the gateway we would need to see the instance flow trace of the BPMN component.
The Intiate Security Checks gateway is denoted as a parallel splitter and spawns three independent threads to executes sequences originating from it concurrently. The event status of each of the thread is Thread Completed. Wonder why all the three threads executed when the gateway merge was supposed to get going even when two tokens were sufficient? Well this is because the gateway expected a true value of crime summary flag. Since the flag returned was false, it lets all sequences complete in the hope that it may receive a true flag from may be some other sequence.
Lesson Learnt : It is important to design your Complex Gateways effectively in order for them to function in a true N/M way. If you put more restricting conditions, it might as well behave as a normal split-join one.  
Expand the merge gateway marked as Clearance Checks and see the XML payload. Every time a sequence flow is executed and it reaches the gateway merge the gateway exit expression is evaluated.
The first evaluation has to always fail since the merge needs at least two tokens. If the second token arrives from the Crime Check sequence, the merge gateway is again evaluated. The first condition is met as two tokens have arrived but since the a criminal record exists, the expression again evaluates to false. The flow cannot move forward since another sequence is still being executed (which eventually again will not meet the second condition in the expression).
image
Test 2 : Criminal Record is Absent
Now assuming if the process is tested in such a way this time that the response of the Criminal Check sub process evaluates to a false (SSN value not starting with 1), the execution trace of the instance will be starkly different from the case above. Look into the BPMN flow trace, and this time you may very well find that the merge gateway goes ahead just after getting tokens from any two sequence flows. And the pending sequence is cancelled as the gateway expression has evaluated to true. In the instance execution trace being shown below carefully examine how the Credit Check thread is marked as Cancelled as the flow result evaluates to true. This is pretty neat as the process was able to successfully implement a N/M dead path elimination using a complex gateway (depending on sequence execution outcome).
image
This concludes this article that explains the usage of complex gateways in Oracle BPM Suite 11g. In the forthcoming posts, I shall describe other patterns and usage of Event based gateways.
More Relevant Use Cases
Now if you are wondering whether the example used in this post is too hypothetical and there would seldom be a case or a need in your business process to have a complex gateway that eliminates dead paths depending upon outcomes rather than negation logic in the flow sequences. Perhaps it is time to think over.
Order Complex Gateway
Imagine the scenario explained above, arising when a business process is trying to orchestrate Order booking. The process is initiated with order headers and the business it needs to fetch customer data and order details to continue processing. The customer information may be available in an intermediate cache or certainly in the master customer data hub.
See how again using a complex gateway in this scenario is helpful!
The Source Code and Relevant Files
The JDeveloper application used in the article can be downloaded from the link contained here.