{"id":94,"date":"2006-04-11T14:27:12","date_gmt":"2006-04-11T18:27:12","guid":{"rendered":"http:\/\/nule.org\/wp\/?page_id=94"},"modified":"2006-04-11T14:27:12","modified_gmt":"2006-04-11T18:27:12","slug":"writing-custom-business-logic","status":"publish","type":"page","link":"https:\/\/nule.org\/?page_id=94","title":{"rendered":"Writing Custom Logic"},"content":{"rendered":"<p><em>Warning<\/em><\/p>\n<p>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.<\/p>\n<p><strong>Introduction<\/strong><\/p>\n<p>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.\u00a0 I&#8217;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.\u00a0 Because I would like the HL7 Comm and the Integrate engine to be as widely and generally useful as possible I&#8217;ve decided to extend them by allowing those using the programs to extend them however they like using a few simple APIs.<\/p>\n<p><strong>Business Logic Encapsulation<\/strong><\/p>\n<p>The key to working with the data inside of Integrate (and by extension HL7 Comm) is to extend the abstract LogicAgent (LA) class that&#8217;s part of the Integrate Client library.\u00a0 The ProcessorAgent (PA) used by Integrate to move data between inbound and outbound clients (every message is sent to <em>all<\/em> 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.\u00a0 Basically, as a message is passed to the PA through it&#8217;s dataTransfer(String msg) method (defined as part of the PA interface).\u00a0 It then should call the loadMessage(String msg) method of the LA checking for a boolean return value.\u00a0 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.\u00a0 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.<\/p>\n<p>It&#8217;s quite a bit easier than it all sounds.\u00a0 Basically to start off your logic class you must extend the following:<\/p>\n<p><code><\/p>\n<p>\/*<br \/>\n* LogicAgent.java<br \/>\n*<br \/>\n* Created on March 31, 2006, 2:44 PM<br \/>\n*<br \/>\n* Copyright (C) 2006 M Litherland<br \/>\n*\/<\/p>\n<p>package org.nule.integrateclient.common;<\/p>\n<p>import java.util.*;<\/p>\n<p>\/**<br \/>\n*<br \/>\n* @author litherm<br \/>\n*\/<br \/>\npublic abstract class LogicAgent {<\/p>\n<p>public static final String DESCRIPTION = \"Please supply a description for this logic.\";<\/p>\n<p>\/**<br \/>\n* Load a message into the agent for processing.\u00a0 It returns true or false<br \/>\n* based upon whether or not the processing within the processor agent<br \/>\n* should continue.<br \/>\n*\/<br \/>\npublic abstract boolean loadMessage(String message);<\/p>\n<p>\/**<br \/>\n* Return the processed message for handing downstream.<br \/>\n*\/<br \/>\npublic abstract String getProcessed();<\/p>\n<p>\/**<br \/>\n* Pass the client properties to load during startup.<br \/>\n*\/<br \/>\npublic abstract void loadProperties(Properties p) throws IllegalArgumentException;<\/p>\n<p>\/**<br \/>\n* Return a list of mandatory properties.<br \/>\n*\/<br \/>\npublic static Properties getMandatory() {<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Return a list of optional properties<br \/>\n*\/<br \/>\npublic static Properties getOptional() {<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>\/**<br \/>\n* May return a list of default or recommended values.<br \/>\n*\/<br \/>\npublic static Properties getDefaults() {<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Return a description of the type requested of each property.\u00c2\u00a0 For<br \/>\n* example string, integer, char, class, etc.<br \/>\n*\/<br \/>\npublic static Properties getTypes() {<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Return a description of the property for assistance in filling out<br \/>\n* the configuration.<br \/>\n*\/<br \/>\npublic static Properties getDescriptions() {<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>}<\/p>\n<p><\/code><\/p>\n<p>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).\u00a0 These can be ignored if you have no configuration information that must be passed to the LA.\u00a0 The two abstract methods must be implemented for the class to compile and work properly.<\/p>\n<p>One more important note &#8211; you should really do all your processing within loadMessage(String msg), as this is your only chance to cause the message to roll back.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"parent":93,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-94","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/nule.org\/index.php?rest_route=\/wp\/v2\/pages\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nule.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/nule.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/nule.org\/index.php?rest_route=\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/nule.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":0,"href":"https:\/\/nule.org\/index.php?rest_route=\/wp\/v2\/pages\/94\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/nule.org\/index.php?rest_route=\/wp\/v2\/pages\/93"}],"wp:attachment":[{"href":"https:\/\/nule.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}