Sunday, June 27, 2010

Implementing BPM logic in Cordys-BOP4


Introduction

Almost any Business Process has a conditional flow, which is determined by business logic. An example is to determine the approver for a purchase: In case the order amount does not exceed 50 dollars approval may not be required. However for amounts between 50 and 5000 euro the department-manager may need to approve. Above 5000 euros it may be the business line manager, and above 100000 euros even the CEO.
 
Cordys BOP-4 allows us to define Business Process logic in multiple ways. This flexibility is nice. However it raises the question: "When to use what"?
 

Considerations

There are several considerations to make before selecting one of the available alternatives:
 
Agility:
How frequent are the expected modifications? Should it be possible to perform them without restarting or redeploying the application?
 
Efficiency:
How much effort does it take to implement the rule?
 
Complexity/Maintanability:
How complex are the rules: How many steps and different conditions do they contain? Who should be able to perform the change: A business user or an IT engineer.
 
Functionality:
What functions and data do you need to be able to access? Do you need to be able to access database content? Perform difficult calculations or text operations?
 
Readability:
Should business be able to read and understand the logic to be able to grasp the business process.
 
Architecture:
It may be favorable to have your logic itself logically organized, for the following reasons so it is clear for business users and developers where to find certain logic, and to be able to package and deploy logic as much as possible in comprehensible units.
 
 
Lets first discuss the options:
 

Constructs to implement logic 

BOP-4 offers the following constructs to implement business logic:
(Note that most of the alternatives above may be used in conjunction with other alternatives.)
 
BPM Decision steps
The BPM modeling language BPMN allows to directly built logic into Business Process models using the construct "Decision". This step allows to select multiple alternative paths that may be chosen, based on a condition for each path. There may be one default condition that is executed when all other condition evaluate to false. The conditions are defined in "XPath".
 
+ The logic is visible in the process itself, which contributes to readability and architecture
- Complex logic may explode into an incomprehensible process model
- Changes should pass a complete DTAP cycle
- Advanced functionality will require knowledge of XPath
 
Recommended usage
 - Simple conditions in Business Process, e.g.:
 - Checking process inputs
 - Checking output from earlier steps
 
  
Example of  decision step
 
BPM Mappings
BPM mappings allows the assignment of values in steps in a BPM using Xpath. Xpath contains a number of functions that may be used to implement logic (e.g. Boolean functions, regular expressions and selection expressions).
 
+ The logic is stored in the BPM model. (Architecture)
- Changes should pass a complete DTAP cycle
- Logic is "hidden" in implementation details
- Limited functionality. More advanced functions require knowledge of XPath
- Logic is less visible / comprehensible to business users
 
Usage
 - Simple logic to influence attribute values
 
Example of mapping Xpath 
 
Transformation objects
Transformation object transform one data structure into another, using XSLT (which uses XPath underneath). Transformations may be used in BPM or turned into web services.
 
+ Supports complex logic
+ Reusable
- The logic is stored outside the BPM model. (Architecture)
- Changes should pass a complete DTAP cycle
- More complex logic requires XPath/XSL knowledge. 
- Logic is not visible / comprehensible to business users
 
Usage
 - More sophisticated logic used to transform a (business) object into another (business) object
 
 
Decision Tables
Decision Tables are a number of rules, containing one or more conditions and one or more (resulting) actions. The conditions use XPath-statements. These use the specified data interface, which is a predefined data structure. The actions concern assigning values to the data structure, or e.g. running a web service.
 
+ Supports complex logic
+ Reusable
+ The logic is stored in Business comprehensible (=maintainable?) objects.
+- Changes may be delivered in a staging packages, which allows online maintenance by business users. *)
- Best suitable for compact rules: More complexity or functionality may require XPath knowledge
 
Usage
 - More complex IF.. THEN conditions on the the same attributes
 - From 2 to 10+ different conditions
 - Rules that check values (e.g. amounts) against static numbers, that may be changed frequently (by business users?)
 
*) For advantages/disadvantages of staging packages, see:

https://wiki.cordys.com/pages/viewpage.action?pageId=164794477

 
Example of decision table 
 
Business Rules 
Business Rules are technically similar to decision tables, but are attached to events on business objects. (e.g. Insert in the database).
 
Usage
- Validations
- Triggering actions, comparable to stored procedures.
- Triggering BPM-s on specific events
 
 
 
Database queries
Logic may be implemented by executing SQL on the database e.g. via look-up tables, in order to retrieve specific values for specific objects. In order to use the queries with BPM they will have to exposed via a web service.
 
+ (Static) logic may be altered/extended during run-time. Screens may be offered to Business to alter the look-up tables.
+ May support large amounts of data. (E.g. customer bases)
- Logic is divided over 2 objects: data and query
- Logic is separated from business process.
 
Usage
 - Look-up actions of larger amounts of data
 - Logic that the user should be able to alter implicitly at run-time by changing the database content
  
Java
Java allows to write logic in java classes. In order to use it with BPM the java classes will have to be exposed via a WebService.
 
+ Maximum functionality offered. Suitable for complex rules
- Java requires more objects and more complex settings for deployment
- Changes should pass a complete DTAP cycle
- Require knowledge of Java
- Logic is not visible to business user
 
Usage
 - Complex manipulations of numeric, date or string values.
 - Complex logical structures (combined loops, nested IF..THEN-s, switch statements etc)
 
XForm/java script
Java script may be used in User Interfaces to react on user events and take appropriate actions. This may include validations or UI actions, but also invoking Web Services (which may include business processes and business rules).
 
 
Example of Java Script with XForms 
 
+ Directly usable in User Screens
- Not visible nor comprehensible for business users
- Requires java-script skills
- Executed in client, which may cause issues due to different browser types
 
 
Usage
 - Triggering actions from a User interface (e.g. starting a BPM by a press on a button)  
 - (Cross) field Validations
 
 
It is crucial to select the right option in order to meet the non-functional requirements as stated earlier in this blog.

Regards,
 
Harald van der Weel

Sunday, June 13, 2010

Evaluation of Rules and Decision Tabl...

Introduction

Cordys BOP-4 offers numerous ways to add logic to Business Processes.

One convenient way is to use Business Rules and Decision Tables. Business Rules apply to to business objects and are generally used to implement validations and logic that is often addressed at database level using stored procedures.

Decision Tables have no direct link to a business object. They implement logic that is mainly used for medium complex conditional behaviour in a Business Process. Using decision tables we may prevent complex sequences of conditions appearing in our BPM, blurring the real intentions of the business process.

Decision Tables


A decision table consists of a set of Rules, which each contain one or more conditions and actions. Conditions are evaluated to either true or false. Actions are executed if all conditions for a Rule evaluate to true. The schema fragment is the actual interface to the Decision Table. If used as a BPM activity it is exposed in the Message Map of the Business Rule modeler, and allows to specify input values and to retrieve output values after the step is completed. From the schema fragment attributes may be selected to use in conditions (e.g. for comparisons), and in actions (e.g. to assign values).


 Example of Decision Table, showing all concepts described above

Execution


Execution of a Decision Table-step in a BPM comprises the following:
  1. First the massage mapping on the Decision Table attributes is made. 
  2. Next the evaluation process is started: Every rule is evaluated separately in sequence, starting from left most, working to right.
  3. The values of the concerned condition attributes are used to evaluate the conditions of the rule. If each condition of a rule evaluates to true, the actions specified for that specific rule are executed, starting with the top-most, working down to the bottom.

Example

In case we have a Decision Table TD, containing 3 rules: R1, R2 and R3, each having 2 conditions (Cx.1 and Cx.2, where x is the rule number), and 2 actions (Ax.1 and Ax.2 where x is the rule number), the statement in terms of pseudo code code would be like:
IF ( C1.1 AND C1.2) THEN

    a1.1

    a1.2

END IF

IF ( C2.1 AND C2.2) THEN

    a2.1

    a2.2

END IF

IF ( C3.1 AND C3.2) THEN

    a3.1

    a3.2

END IF

Implications


The example shows three important implications:
  • Each rule is evaluated, even if its predecessor evaluates to true. (Hence: multiple rules may be executed)
  • There is no OTHERWISE or DEFAULT construct available. (Like in the java SWITCH..CASE statement)
  • The execution of an action of a certain rule may impact the result of the execution of one of the succeeding rules (e.g. by modifying values of attributes used in the conditions) 
So what if we want to perform a default action "a_def" in case none of the specified rules evaluate to true?


The solution would be to create an additional rule: R4.

R4 would contain 3 rules that are all the negations of the conditions of R1, R2 and R3:


In pseudo code:
IF ((NOT (C1.1 AND C1.2)) AND (NOT (C2.1 AND C2.2)) AND (NOT (C3.1 AND C3.2))) THEN

   a_def

END IF
One can imagine that this may be an time consuming and error prone activity if the Decision Table contains more rules and conditions.

An alternative may be using a flag, indicating if at least one of the rules has evaluated to true. This flag should be set initially to false. In case a rules evaluates to true, the flag should be set to true. (This implies that every rule would need an additional action that implements this!). In last (default) rule it just requires to check the value of the flag: If it is (still) false, the default action should be executed, otherwise not.


Note that the flag will have to be contained in the schema fragment of the Decision Table, and hence appears in its interface. Not the most elegant solution, but in certain cases a good trade off for the the possible complex conditions as described above.

Harald van der Weel

e-mail: haraldvanderweel@gmail.com