abltutorial Logic Classes

You can implement the required @Logic annotations in either of two ways:

 Unzip and paste logic
  1. Download the src.grovy.businesslogic.zip file
  2. Unzip it
  3. Paste the contents into the ablroodemo.businesslogic package as shown above
 Enter logic manually 

Alternatively, you can simulate the normal development process by creating logic files for PurchaseOrder and LineItem.

You can find the logic for pasting here.


You can manually enter the logic classes from the information below.




BizLogicBase

Optionally, your logic files can utilize standard Object Oriented inheritance.  Our base class is very simple:

package ablroodemo.businesslogic;

import com.autobizlogic.abl.annotations.Constraint;
import com.autobizlogic.abl.annotations.LogicContextObject;
import com.autobizlogic.abl.logic.LogicContext;
import com.autobizlogic.abl.util.LogicLogger;
import com.autobizlogic.abl.util.LogicLogger.LoggerName;

/**
 * A trivial superclass for logic objects, demonstrating how logic can be inherited.
 */
public class BizLogicBase {
/**
 * rarely enabled, just included here to illustrate debug options
 */
public static final LogicLogger _sysLog = LogicLogger.getLogger(LoggerName.SYSDEBUG);

@LogicContextObject
public LogicContext logicContext;

/**
 * shows old/new values etc.
 */
@Override
public String toString() {
return logicContext.toString();
}
}


CustomerLogic

The following class replaces the simple CustomerLogic specified earlier, and includes some commented out code we will use later:

package businesslogic


import abltutorial.Customer

import abltutorial.CustomerAudit


import com.autobizlogic.abl.annotations.*

import com.autobizlogic.abl.logic.LogicContext

import com.autobizlogic.abl.logic.Verb

// import com.autobizlogic.abl.businesslogic.InsertIntoFrom


public class CustomerLogic extends BizLogicBase {


@Sum("purchaseOrders.amountTotal where paid = false and ready = true")

public void deriveBalance() { }


@Constraint(value="balance <= creditLimit", errorMessage="Customer {name} exceeds credit limit")

public void checkBalance() { }

/* BEGIN COMMENTED OUT CODE

 

  @CurrentBean

Customer customer // injected by BusLogicEngine

@OldBean

Customer customerOld

/**

* Insert row into child EmployeeAudit on salary change.

*  COMMENTED OUT CODE (terminate the javadoc here)

@Action

public void actionAuditCustomer() {

if (logicContext.getInitialVerb() == Verb.UPDATE && customer.creditLimit != customerOld.creditLimit)  {

if (_sysLog.isDebugEnabled())  _sysLog.debug("Audit Customer Action performing audit")

CustomerAudit audit = InsertIntoFrom.insertChildFrom({new CustomerAudit()}, logicContext)

}

}  END COMMENTED OUT CODE  */

}



PurchaseOrderLogic

This class specifies how the PurchaseOrder Amount is derived:

package businesslogic;


import com.autobizlogic.abl.annotations.*

public class PurchaseOrderLogic {


@Sum("lineItems.amount")

public void deriveAmountTotal() { }

}


Note the chaining:
  • Customer.balance references PurchaseOrder.amountTotal
  • PurchaseOrder.amountTotal references LineItem.amount

LineItemLogic

This class specifies how the LineItem amount is derived:

package businesslogic;


import com.autobizlogic.abl.annotations.*



public class LineItemLogic {

@Formula("productPrice * qtyOrdered")

public BigDecimal deriveAmount() { } 


@ParentCopy("product.price")

public void deriveProductPrice() { }

}



CustomerLogic for auditing


To complete the last step of the Tutorial, add this at the end of CustomerLogic:

@CurrentBean
Customer customer // injected by BusLogicEngine

@OldBean
Customer customerOld

/**

* Insert row into child EmployeeAudit on salary change.

*/

@Action

public void actionAuditCustomer() {

if (logicContext.getInitialVerb() == Verb.UPDATE && customer.creditLimit != customerOld.creditLimit)  {

if (_sysLog.isDebugEnabled())  _sysLog.debug("Audit Customer Action performing audit")

CustomerAudit audit = InsertIntoFrom.insertChildFrom({new CustomerAudit()}, logicContext)

}

}


You will probably wish to align the code (Ctl + A, Ctl + I), and you will need to uncomment the import statement.

Comments