Automating the Connection of Business Rules in Object-Oriented Applications using AOP

Type: Thesis and Apprenticeship Project

Assistants: María Agustina Cibrán,Maja D'Hondt
Supervisor: Viviane Jonckers

Part of Thesis and/or Apprenticeship Projects 2004-2005

Student

fabriceosteaux.jpg
Fabrice Osteaux
Program: 4th year Applied Computer Science
E-mail: faosteau@vub.ac.be
Mobile: +32-(0)486504424

Description

Business Rules ought to be loosely coupled from the core application they relate to, and could be created and managed by non technically-skilled people, to achieve this:

  • an easy to use, high-level business rules language will be specified
  • a business model will be introduced, allowing loose coupling between business rules and the core application
  • a mapping from this language to a concrete object structure will be implemented
  • automatic linking of the BRs (with the core application) will be provided, using AOP technology (linking by event from the business model without references to concrete code)

To achieve this, the ideas of 1) (language specification and BR linking wizard) will be used

Current Status

Completed

  • Preliminary study of other available high level BR languages (Completed)
  • Defining a high level business rule language (OK)
  • Implementation of a High Level Business Rule Translator (OK)
    • Working Functionality and improvements over previous versions:
      • Works with a Domain (previously Business) model.
      • Business Rule Validation and error reporting.
      • Structural improvements, more Object-Oriented Code.
      • Supports indirect references to java entities, through a domain model layer.
      • Parse tree processor, building a BREntity object, semantically validating the rule by querying the domain model, and typechecking it.
      • Code generator, producing java code for the class implementing the business rule.
    • Limitations:
      • Needs a link with the core application to work (core classes must reside in the classpath when running the translator)
      • Doesn't have a user interface.
      • It is impossible to use or refer to core methods throwing exceptions
      • The Domain Model is defined at run-time and lacks a permanent storage facility for its definition
      • Method lookup is simplistic: parameter types must match exactly
    • Todo:
      • Add TRUE / FALSE literals
      • Package specification problem: add option to use specific package.
      • Allow use of class attributes in BR (e.g. attribute assignment, possible with domain model ?
      • The WHERE clause must also be usable to extract information from the “PROPS” variables.
      • Change translation process to include the linking.
      • Implement the MATCHING construct to be able to restrict a rule to one particular object.
    • Domain Model (Business Model):
      • The current working release includes aliases for classes and their attributes and methods.
      • It will include supoort for unanticipated attributes.
      • It now contains an extra mapping layer, allowing DM entities to be loosely coupled to the core application

In Progress

  • Domain Model: extension: support for non-core attributes and methods (Busy (Agustina))
  • Domain Model: integration of Business Rules as Domain Model entities (OK)
  • Minor improvements in translator (see above).
  • Automatic connection of BRs with core application, including: (Busy)
    • High level linking language: referring to BR and event where the BR should be triggered, and capture points for unavailable information.
    • High-level Events Specification as domain model entities.
    • Allow linking language to optionally specify a mapping between Business Objects required in BR and information coming from Events and Capture Points, if there is a 1:1 relationshio between BR entry points and captured information, mapping can be done automatically.
    • Translation from linking language to Jasco AspectBean.

Open Issues

  • Linking language specification (Draft):
CONNECT <BR NAME> AT <EVENT> [WHERE <EVENT CONTEXT ITEM NAME> [IS <LOCALNAME>]]
[ CAPTURE AT <EVENT> [WHERE <EVENT CONTEXT ITEM NAME> AS <LOCALNAME>],
          ...]
[ MAPPING <LOCALNAME> TO <BRNAME> ]

Having a Capturespecifier is not really adequate: it breaks the high-level abstraction offered by the domain model entities (events, business rules, …) by using a low-level specification of the capture point, which should be avoided. Possible alternatives are:

  1. (Define capture points entities stored in DM)
  2. Add semantic to context entities associated with an event (choose and names event's available context items (parameter, returnvalue, …)

After a first discussion on the issue, it has been decided to select, and add names to context objects available at events, this being added to the domain model.

Example of Business Rule translation

The following Business rule:

If a cutomer has bought more than a certain quantity of products or a certain amount of money, then he gets a discount and becomes a frequent customer.

translated in high level language:

BR FrequentCustomer

PROPS double AS targetamount,
      int    AS minquantity,
      double AS discount,
      String AS newstatus

USING Shop           AS store,   
      Customer       AS targetcustomer,
      ShoppingBasket AS basket
 
WHERE accounts       IS store.getShopAccounts(),
      shopaccount    IS accounts.getShopAccount(accounts.findShopAccount(targetcustomer)),
      amountspent    IS shopaccount.getAmountSpent(),
      boughtproducts IS shopaccount.getBoughtProducts()

IF    amountspent >= targetamount
      OR boughtproducts >= minquantity
     
THEN  basket.setDiscountRate(discount) 
      AND shopaccount.becomeFrequent()
      AND targetcustomer.setCustomerName(newstatus)

Running the translator generates the following java code:

//Automatically Generated Business Rule
public class FrequentCustomer
{
  //Properties
  double targetamount;
  int minquantity;
  double discount;
  java.lang.String newstatus;
 
  //Business Objects
  ecommerce.Shop store;
  ecommerce.Customer targetcustomer;
  ecommerce.ShoppingBasket basket;
 
  //Business Objects Attributes/Properties
  ecommerce.ShopAccounts accounts;
  ecommerce.ShopAccount shopaccount;
  int amountspent;
  int boughtproducts;
 
  //Constructor
  public FrequentCustomer(double targetamount, int minquantity, double discount, java.lang.String newstatus)
  {
    this.targetamount = targetamount;
    this.minquantity = minquantity;
    this.discount = discount;
    this.newstatus = newstatus;
  }
 
  //Fires the BR
  public void applyRule(ecommerce.Shop store, ecommerce.Customer targetcustomer, ecommerce.ShoppingBasket basket)
  {
    //initialize bo data members
    this.store = store;
    this.targetcustomer = targetcustomer;
    this.basket = basket;
    //initialize bo attributes aliases
    this.accounts = store.getShopAccounts() ;
    this.shopaccount = accounts.getShopAccount(accounts.findShopAccount(targetcustomer)) ;
    this.amountspent = shopaccount.getAmountSpent() ;
    this.boughtproducts = shopaccount.getBoughtProducts() ;
 
    if (condition())
    {
      action();
    }
  }
 
  private boolean condition()
  {
    return ( ( amountspent >= targetamount ) || ( boughtproducts >= minquantity ) );
  }
 
  private void action()
  {
    basket.setDiscountRate(discount);
    shopaccount.becomeFrequent();
    targetcustomer.setCustomerName(newstatus);
  }
}

Apprenticeship Documents

Links

1) Tool support for linking Business Rules to OO applications using AOP, J. Elsocht, 2004 (Thesis)
 
teaching/thesis0405/aop3a.txt · Last modified: 25/08/2005 13:28 (external edit)
 

© 2003-2010 • System and Software Engineering Lab • Submit comments and bugs to our Bugzilla or to the webmaster