Writing Custom Logic

Warning

For the most part, you should think about writing custom logic using the beanshell scripts within the HL7 Comm. This custom logic is if you wanted to write and compile your own java classes to work with the Integrate Client Library.

Introduction

Being able to produce custom business logic and use it with an integration product is a key aspect of every integration system that I am aware of.  I’m a firm believer that Java is the premiere language for performing integration work because of its wide support for all kinds of enterprise technologies, from JMS to XMLRPC.  Because I would like the HL7 Comm and the Integrate engine to be as widely and generally useful as possible I’ve decided to extend them by allowing those using the programs to extend them however they like using a few simple APIs.

Business Logic Encapsulation

The key to working with the data inside of Integrate (and by extension HL7 Comm) is to extend the abstract LogicAgent (LA) class that’s part of the Integrate Client library.  The ProcessorAgent (PA) used by Integrate to move data between inbound and outbound clients (every message is sent to all outbound clients unless the logic indicates that the message is not accepted, in that case the inbound should roll back) passes every message to the logic agent.  Basically, as a message is passed to the PA through it’s dataTransfer(String msg) method (defined as part of the PA interface).  It then should call the loadMessage(String msg) method of the LA checking for a boolean return value.  Upon a true it will forward the message to all outbound clients, upon a false a false will also be returned to the inbound client through the return value of the dataTransfer call.  Assuming that the loadMessage is true, the PA then calls the getProcessed() method to get the data as it should be passed to the outbound clients.

It’s quite a bit easier than it all sounds.  Basically to start off your logic class you must extend the following:

/*
* LogicAgent.java
*
* Created on March 31, 2006, 2:44 PM
*
* Copyright (C) 2006 M Litherland
*/

package org.nule.integrateclient.common;

import java.util.*;

/**
*
* @author litherm
*/
public abstract class LogicAgent {

public static final String DESCRIPTION = "Please supply a description for this logic.";

/**
* Load a message into the agent for processing.  It returns true or false
* based upon whether or not the processing within the processor agent
* should continue.
*/
public abstract boolean loadMessage(String message);

/**
* Return the processed message for handing downstream.
*/
public abstract String getProcessed();

/**
* Pass the client properties to load during startup.
*/
public abstract void loadProperties(Properties p) throws IllegalArgumentException;

/**
* Return a list of mandatory properties.
*/
public static Properties getMandatory() {
return null;
}

/**
* Return a list of optional properties
*/
public static Properties getOptional() {
return null;
}

/**
* May return a list of default or recommended values.
*/
public static Properties getDefaults() {
return null;
}

/**
* Return a description of the type requested of each property.  For
* example string, integer, char, class, etc.
*/
public static Properties getTypes() {
return null;
}

/**
* Return a description of the property for assistance in filling out
* the configuration.
*/
public static Properties getDescriptions() {
return null;
}

}

Note that most of the code gives you the ability to configure the logic agent through the GUI that will be used to create configurations for Integrate (and which currently lets you configure HL7 Comm).  These can be ignored if you have no configuration information that must be passed to the LA.  The two abstract methods must be implemented for the class to compile and work properly.

One more important note – you should really do all your processing within loadMessage(String msg), as this is your only chance to cause the message to roll back.