Friday, May 28, 2010

JRules: Getting Started in 3 minutes (aka JRules for Dummies)

Installation is easy, anyway here
http://www.jaceklaskowski.pl/docs/GettingStartedWithIBMWebSphereILOGJRules7.0.2Trial-installation.pdf

you have some instructions.

After you complete installation, run  IBM WebSphere ILOG JRules V7.0.2/Samples Console

It will take a couple of minutes to start Tomcat. When you see
28-05-2010 09:36:15 org.apache.catalina.startup.Catalina start
INFO: Server startup in 138229 ms

open a browser, Rule Team Server console is:
http://localhost:8080/teamserver
rtsUser1/rtsUser1
rtsConfig/rtsConfig
rtsAdmin/rtsAdmin


and Rule Execution Server console is:
http://localhost:8080/res
resAdmin/resAdmin
resMonitor/resMonitor
resDeployer/resDeployer

Some acronyms:
ILR = ILOG Rule Language
XU = Execution Unit
XOM = XML Object Model


Now, in Eclipse Studio right click, new Rule Project, select Hello World Rule Project. I will call it JRulesPVHelloWorld.
Right click, export Ruleset Archive, ruleProject=/JRulesPVHelloWorld, save to C:\temp\greetings.jar


This will create a IRL, META-INF and RESOURCES directories, with some irl etc files:


main-rfl.irl file:

flowtask main {
  property mainflowtask = true;
  body {
    main#helloworld;
  }
};

ruletask main#helloworld {
  algorithm = default;
  ordering = dynamic;
  body {
    helloworld.*
  }
};



greetings-brl.irl file:

package helloworld {
   rule greetings {
      property status = "new";
      when {
         IlrContext() from ?context;
         evaluate (helloworld.Clock.currentTime.compareTo(new ilog.rules.brl.Time(ilog.rules.brl.IlrDateUtil.getLocalTime(1970, 0, 1, 0, 0, 0, 0, 1))) < 0);
      } then {
         ilog.rules.brl.System.printMessage("Good morning!");
      } else {
         ilog.rules.brl.System.printMessage("Good afternoon!");
      }
   }
}

plus a descriptor file with all the BOM and XOM and METADATA. The b2x files contain some horrendous XML to map Java code into functions that JRules engine can use.... XML! Mothers, keep your childer home, XML is around!


Anyway.... log into http://localhost:8080/res , add RuleApp (I call it PVRuleApp), add Ruleset, I call it PVGreetingsRuleset, and choose as archive the JAR exported from Eclipse...


Click on the WSDL, copy the URL, open SoapUI, create a new project and give it the WSDL url.... and off you go, you are ready to invoke the rule via WS!


Here you can find a more complete presentation, including how to pass parameters to a Ruleset



No comments: