• No results found

Enterprise Informatization LECTURE

N/A
N/A
Protected

Academic year: 2021

Share "Enterprise Informatization LECTURE"

Copied!
47
0
0

Loading.... (view fulltext now)

Full text

(1)

Enterprise Informatization

LECTURE

Piotr Zabawa, PhD. Eng.

IBM/Rational Certified Consultant

e-mail: [email protected]

(2)

Lecture 2

Business Process Modeling

with the aid of BPMN

in Jboss Drools environment

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(3)

Literature

Software Engineering Section

This lecture (Lecture 2) was created on the basis of the following books:

Bali M., Drools JBoss Rules 5.0. Developers Guide, Packt Publishing 2009.

Browne P., JBoss Drools Business Rules, Packt Publishing 2009.

(4)

BPMN2 diagram elements

• Only the elements of BPMN2 available in JBossDrools 5.1 will be presented here in order to make Drools learning curve more steep. • Next part of the lecture is dedicated to configuration of Drools in

Eclipse. Simple projects creation is also explained.

• The more advanced example – a banking case-study is also elaborated to illustrate all practical problems specific for working with Drools as well as their solutions.

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(5)

Start/End

Software Engineering Section

Start – the only process or sub-process starting point. No entry point, exactly one exit point.

End – one of possibly many process or sub-process

(6)

Gateways

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

Software Engineering Section

Diverge (Split) – the place of process splitting into many paths (flows, branches).

AND – flow into all branches at the same time OR – flow into all branches recognized as true XOR – only one branch must be chosen

Converge (Join) – place of joining many branches into one

AND – continuation after finishing all branches XOR – continuation after finishing the first branch

(7)

Tasks

Software Engineering Section

Rule – covers the group of business rules for exetution during this task

Script – a code block for execution during this task

User Task – task that requires manual business process handling by a business worker

Subprocess – the process element used for

(8)

Service Tasks

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

Software Engineering Section

Log - built into Drools file logging service

Email – built into Drools e-mail notification service

(9)

Events

Software Engineering Section

Timer – event triggered by timer

Error – event triggered by an error

(10)

Sub-Process

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

Software Engineering Section

Sub-Process – used for modeling subprocesses embeded in a

process. Subprocess has access to all its parent process data but not vice-versa. Like a process it must have one starting point and may have many end points.

(11)

Multiple Instances

Software Engineering Section

Multiple Instances – used to mark multiple execution of a subprocess placed in this container.

(12)

Advanced model sample

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(13)

Advanced model sample

(14)

Advanced model sample

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(15)

Disadvantages of traditional approach

Disadvantages of traditional approach:

if (customer.getLevel() == Level.Gold){ // coś dla Gold

}

else if (customer.getLevel==Level.Silver){ if (customer.getAccounts()==null){

// coś dla Silver, który nnie ma rachunku??? }

else{

for(Account account : customer.getAccounts()) if (account.getBalance<0){

// coś dla Silver mającego konto z debetem }

else if (account.getBalance>=0 and account.getBalance()<=1000){} else if (account.getBalance>1000 and account.getBalance()<=100000){} else if (account.getBalance>100000 and account.getBalance()<=500000){} // …

} }

How to handle business logic changes in such a structural code?

(16)

Solution of the problem

It is better to decompose the structural problem into a set of independent conditions:

if Customer(level==Level.Silver) and no Account

if Customer(level==Level.Silver) and has Account debit

if Customer(level==Level.Silver) and has Account less then 1000 //…

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(17)

Motivation for business rules

• Advantages • Disadvantages

• When not to apply

(18)

Business rules - advantages

• Easy for understanding by business analyst and new developer

• Easy to focus on the problem’s essence – what not how • Ease of introduction, deletion of rules

• Ease of change introduction to the rules • High algorithm efficiency

• Ease of transformation of business analysts requirements into rules

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(19)

Business rules - advantages

• Ease of unified mechanism usage while adding orthogonal business responsibilities (compare to Aspect Oriented

Programming) – for example audit, reporting, event logging

• Ease of reuse (the same rule in many processes)

• Independence of sequential processing of rules (in contrast to imperative languages like C++/Java/C#)

• Ease of rules exectution from processes and/or execution of processes from rules (Drools)

(20)

Business rules - advantages

• Independent lifecycles. Rules and processes are extracted from object-oriented software into separate frequently changing artifacts. Independent change management processes.

• Ease of embedding Drools in applications

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(21)

Business rules - disadvantages

• Mental problems among the programmers – different way of thinking in case of declarative languages

• Difficulties in finding and elimination of errors in rules/processes

• Diffilulties in full debugging of rules without deep knowledge of business rules engine’s detailed way of working

(22)

Business rules - advantages

• High memory resources requirement

• Theoretical danger of recursion (especially in case of modeling to-be) in case of changing common data by at

least two rules. In such case we do not know what is wrong – process design or rule implementation.

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(23)

Business rules

– when not?

• If less then 20 rules

• If business logic changes rarely

• If business rules are simple and/or are working on one object ony

• If in pseudo-code the nesting level of conditional instructions is less then 3

• If software is created temporarely and will not evolve • If there are not enough resources to handle business rules

(24)

Drools

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

Software Engineering Section

This software is BLiP (Business Logic integration Platform).

We will be using only three of them:

• Drools Expert – silnik reguł biznesowych

• Drools Flow – silnik procesów biznesowych

(25)

Drools IDE installation

The installation steps of the whole JBossTools IDE

containing Drools plugins as well as Java EE WTP platform are desribed on:

www.pk.edu.pl/~pzabawa/en/business

Drools configuration is described in the following document:

Konfiguracja środowiska developerskiego Drools

(26)

Konfiguracja środowiska

developerskiego Drools

Opisana w pliku:

JBossDrools_01_RuntimeSetting.pdf

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(27)

Drools_HelloWorld samples

That are the most simplified samples jst to start with

Drools designed to show some useful mechanisms available in Drools engines. Some of them are related to different

problems of greetings. They could constitute a base for

making experiments with development environment as well as modeling business processes.

Futher these introductory mechanisms will be extendet into more complex examples referring to banking systems.

(28)

Drools_HelloWorld samples

quick overview and start

HelloWorld01_ProcessOnly – created with the aid of wizard; contains a process with an action and runner class • HelloWorld02_RuleOnly – created with the aid of

wizard; contains rules and runner class

HelloWorld03_ProcessAndRule – created manualy on the basis of previous two samples; contains both process and rules as well as changed runner class

HelloWorld04_ProcessAndDSLRule – previous sample adapted to business analysts expectations via application of DSL (Domain-Specific Language)

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(29)

Drools_HelloWorld samples

events and statistical analysis

HelloWorld05_RulesAndEvents – simple programm showing how to write an event-driven greeting

HelloWorld06_StatefullSession – more complex sample showing how to make statistical analysis of facts located in knowledge base with the aid of Drools query

HelloWorld07_DroolsTypeDeclaration – quite complex sample which contains statistical analysis of business

events (no time frames)

HelloWorld08_DRL2JavaPropagation – previous

sample enriched by access to native Drools class with the aid of Java reflection

(30)

Drools_HelloWorld samples

events in time axe (CEP)

HelloWorld09_?

uzupełnić!

HelloWorld10_?

uzupełnić!

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(31)

Przykłady Drools_HelloWorld

architektura

HelloWorld11_BusinessRulesEngine – przykład

pokazujący jak w sposób nie naiwny korzystać w aplikacji z silnika reguł biznesowych ukrytego za interfejsem

uzupełnić!

HelloWorld12_BusinessProcessEngine – przykład ilustrujący możliwość ukrycia przed aplikacją procesu biznesowego za interfejsem

uzupełnić!

(32)

New project creation instructions

The way of creation of a new project containing a process is described in the file:

JBossDrools_02_ProjectCreationWizard.pdf

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(33)

Drools_HelloWorld samples

The way of execution of a sample containing a process is described in the following file:

JBossDrools_03_ProjectWorkflowExecution.pdf

(34)

Business rules engine concept

Sample – simple business rule:

package droolsbook; rule „basic rule”

when // condition(s) albo LHS Account ( balanace < 100 ) then // consequence albo RHS

System.out.println(„Account balance is less then 100”); end

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(35)

Business rules engine concept

Sample cont. – fact as a Java (POJO) bean:

package droolsbook; public class Account{

private long balance;

public long getBalance(){ return balance; } public void setBalance(long balance){

this.balance = balance; }

@Override

public boolean equals(final Object other){//…}

@Override

public int hashCode(){//…}

@Override

public String toString(){//…} }

(36)

Business rules engine concept

Description based on the previous sample. The client class performs the following steps: • Creates knowledge base object

• Places resources in this object (business rules in this case) • Creates session object (statefull or stateless)

• Creates an object of Account class

• Places Account class object in session object • Runs rules

Builder design pattern is used for Drools objects creation. More detailed information can be found in

Drools_HelloWorld samples.

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(37)

Business rules engine concept

Description of Drools engine reation:

Drools tries to fit each fact (Accoun here) placed in

knowledge base session to each condition of each rule located in knowledge base in such a way that these facts fulfill these rules. This process is called pattern matching. If a particular fact fulfills all conditions of a particular rule, then the

consequence of this rule is executed for this fact. This way the functionality of a fact is moved from application business logic to the business rule. We can say that we controll objects functionality from oustide.

(38)

Business rules engine concept

Description of Drools engine reation cont.:

If there is more facts and rule conditions of a particular rule are related to more then one fact, then business rules engine fits fact sets in such a way that it finds all

combinations of facts that fulfill the rule conditions as a

whole facts set. Then the consequence of this rule is executed for each set of facts that fullfilled the rule condition.

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(39)

Business rules engine concept

Rules consequences execution order:

The order of rule consequences execution for particluar fats set is not

determined – the rule engine makes such a decision for us (compare to remarks related to engine disadvantages). There are however some

mechanisms in Drools that haelp to influence in some extent to the execution order:

• Agenda

– Rule priorities (salience) – Rules grouping

• (activation-group) or (agenda-group)

• Ruleflow (ruleflow-group)

(40)

Business rules language

• A rule may contain many conditions

Account ( balance == 200) Customer (name == „John”)

• A rule can declare variables (declaration only – the engine substitutes data)

$account : Account ( $type : type )

• A rule can use declared variable (for each Account class object we find all Customer class objects with the acount field being previously found Account class object)

$account : Account()

Customer ( account == $account )

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(41)

Business rules language

• Native Java types and other – String – Regular expression – Date – Boolean – Enum • Comments – Single line # or // – /* block */

• Packages and import

(42)

Business rules language

• Global variables (declaration, passing to session, consumption in rule)

• Dialects

– Java – default

– mvel – useful due to shortened notation of rules

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(43)

Business rules language

• Operators in rule conditions – And

– Or – Not – Exists – Eval

– return value restriction (fact method call surrounded by elipses)

– Inline eval

– Nested accessors

(44)

Business rules language

• Operators in rules conditions cont. – This – Queues actions • Contains • Not contains • Member of • Not member of • from

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(45)

Business rules language

• Methods in rule consequences

– Modify (modifies a fact in a session) – Insert (places a anew fact in a session) – Retract (removes a fact from a session)

(46)

Business rules language

• Rule attributes – salience – no-loop – dialect

Piotr Zabawa, PhD. Eng. Institute of Computer Science Department of Physics, Mathematics and Computer Science

(47)

The end

References

Related documents

He found that the degree of uncertainty (unemployment risk, transitory and permanent income shocks) and the coefficient of relative risk aversion have a strong influence,

Taking into account that AhR expression promotes differentiation in different cell types ( Esser and Rannug, 2015; Mulero-Navarro and Fernandez-Salguero, 2016 ), and

We commenced training by introducing Dandelion traineeship with the building blocks of a Software Testing lifecycle such as Methodologies, Terminology, and

The two methods for determining azimuth from the sun are methods for determining azimuth from the sun are the the hour angle method and the altitude method.. hour angle method and

A rule is also called a fuzzy implication “x is A” is called the antecedent or premise “y is B” is called the consequence or

But have a long experience of breeding beef cattle farmers do not make it will increase the number of business scale maintained by the breeder, but farmers

Animals at high risk of developing colon cancer were given probiotics and the researchers looked for the appearance of tumours, or early signs of damage to the intestinal

BPM Changes BPM Market Operations, BPM Market Instruments, BPM Market Settlements External Business Requirements TBD Technical Specifications N/A Draft Configuration Guides