Tuesday, February 28, 2012

Drools again, example for beginner

Who would foresee that I will get my hand dirty again with drools? Well, after 13 months, here I am, looking at drools, again... now with jbpm too.
Anyway, it was good. Got better understanding about it and yeah, as usual, share.

I successfully made this:

I am not posting the codes here, you can request for it if you want.

The first process flow (can be in .rf or .bpmn) shows how to use Script Tasks. In the "Question" script, I ran these:


System.out.println("Who is the smartest man in the world?");

java.io.BufferedReader br = new java.io.BufferedReader(new 
                         java.io.InputStreamReader(System.in));

String name = null;

try {
name = br.readLine();
} catch (java.io.IOException e) {
System.out.println("Error!");
}

kcontext.setVariable("smart_guy", name);


The gateway after the "Question" script I check for this:


return smart_guy.equals("frank");


The "Error message" script just print error message. I ran the process.


ksession.startProcess("interactiveJava");


It will keep on asking you who the question until you say "frank". Pretty basic but it gives you better understand about how things run.

Here is the sample output.

The learning issues here will be:

  • Define variable "smart_guy" in the flow/process.



  • In the "Question" script, we set the user input to the process variable. 



     kcontext.setVariable("smart_guy", name);




  • In the gateway constraint:


     return smart_guy.equals("frank");


For beginners, you should try it out your self.

Many thanks to Drools/jBPM development team and the community for their hard work. Many helpful resources are now available online compare to last year.

No comments: