BusLogicDemoGrails is a simple (but not trivial) application, which demonstrates the use of some of the basic concepts in ABL's transactional logic engine in a Grails environment.  This page explains how to load and run the demo.  

Other downloads of interest:
  • To load the entire product (with samples and documentation), see the downloads page.

  • This page describes a completely built project.  You can also run the Tutorial to build a project from scratch.

Pre-requisites

The only absolute prerequisite to run this demo is Grails 2.0.3 or later, which must be installed and running properly. It is available at the Grails website.

STS Installation

Installs can be tricky.  You can view the procedures we use to install STS and Grails.

You may also consider using SpringSource Tool Suite, which is a special edition of Eclipse with all kinds of facilities for Grails. The integration is well done, and it's a much more powerful environment than just a text editor and the command line. However, it is not required for this demo.  

If you do use STS, make sure that you have 

Installation

This sample project comes as a pre-configured project, which is ready to run.

Start by downloading the demo archive from ABL's web site:


Extract that archive -- this should yield a directory named BusLogicDemoGrails.



If you are using "naked" Grails, e.g. the command-line interface:
  1. cd to the BusLogicDemoGrails directory
  2. execute grails run-app (this may take a minute as the dependencies are resolved)
  3. connect to the demo URL: http://localhost:8080/BusLogicDemoGrails


If you are using STS:
  1. Create a Workspace (e.g., BusLogicDemoGrailsWS)
    1. Important: use Preferences > Groovy > Grails to ensure that the workspace is pre-configured for your version of Grails 2.0.  We have seen issues where workspaces configured for earlier versions failed to properly reconfigure for Grails 2.0 during project import (click the thumbnail to the right)
  2. File > Import > Existing Project the BusLogicDemoGrails project into a workspace (this will usually take a minute because of the dependencies)
  3. Run it as Grails command (run-app)
  4. Connect to the demo URL using the link provided in the console


Once you have tried out this interface, you can also use the Grails-generated default views at the URL http://localhost:8080/BusLogicDemoGrails/index, but it's (obviously) not as intuitive as the default UI.

If everything is looking good, you can skip ahead to the What to do in the app section

Known Issues


Grails 2.0.3 Upgrade

The demo project was built under Grails 2.0.  The upgrade to 2.0.3 succeeds, but raises a "Reloading agent exited via exception" when run (logged issue 9069).  Nonetheless, the app runs successfully.


What to do in the app

Once you are in the app, we suggest that you do the following to exercise the business logic:

Edit a customer's credit limit

Change the credit limit for Alpha and Sons to something less than the current balance. This will violate a constraint, which will roll back the transaction and display a message.

Mark an order as paid

If you mark any order as paid, the customer's balance will be decreased by that order's amount.

Change a line item's product

Using the drop-down, change a line item's product. Notice how:
    1. the unit price is updated (copied from the new product)
    2. the amount is recomputed
    3. the order's total is recomputed
    4. the customer's balance is recomputed (assuming the order is not paid)
    5. if the customer's new balance exceeds the credit limit, an error message appears 

While this may all seem simple, there is actually quite a bit going on here. In this particular case, the following rules were involved:

@ParentCopy("product.price")
public void deriveProductPrice() { }
 The product's price was copied to the order item's productPrice.
@Formula("productPrice * qtyOrdered")
public void deriveAmount() { }
The order item's amount was then be recomputed, since productPrice had changed.
@Sum("lineitems.amount")
public void deriveAmountTotal() { }
The order's amountTotal was then be recomputed, since one of its items' amount had changed.
@Sum("purchaseorders.amountTotal where paid = false")
public void deriveBalance() { }
If the order is not paid, then the customer's balance was recomputed, since one of the unpaid orders' amountTotal had changed.
@Constraint(value="balance <= creditLimit",
errorMessage="Balance exceeds credit limit")

public void constraintCreditLimit() { }
Finally, the customer's freshly-updated balance was compared to the credit limit, and, if it exceeded it, the transaction was rolled back.


Notice that we never specifically invoked any of these rules. They were invoked automatically as part of the commit process. And they were invoked in the correct order, because the logic engine understands the dependencies between them.
This means that the application doesn't have to know (or care) about the rules, and can just focus on the task at hand (allowing the user to manipulate data), rather than worry about enforcing the underlying business logic.

Visualizing the rules

If you select the Show events checkbox at the bottom of the page, any changes you make to the data will result in the display of all the rules that were executed within the transaction.

Run Integration Tests

Grails provides very attractive testing services.  The sample application has an example you can run as shown in the thumbnail.

Where to go from here

We hope this very brief introduction to declarative business logic has been worth your time. This demo is a very simple example, but the same concepts can be used to create very sophisticated transactional applications. Please visit the rest of this web site for more information, and don't hesitate to drop us a line: we always love to hear from you.

Click this to see more information on the demo, including how it was built, and testing with Grails.  See the home page for general product information and background.