Drools ruleflow: Rule inside business task does not get executed. (v 6.2)

177 views
Skip to first unread message

hari prasad

unread,
Aug 3, 2015, 9:27:35 AM8/3/15
to Drools Usage
Hello All,
I created a ruleflow which includes a script and a businessrule task. On execution, my input data is not visible in rules and eventually rule is not getting executed. 
Can any one help please?

PFB my drl data:
==========================================================
package com.sample
import com.sample.DroolsTest.Message;
import java.lang.Number;

rule "Hello World"
ruleflow-group "Group1"
    when
        m : Message( status == Message.HELLO, myMessage : message )
    then
    System.out.println( "Inside rules" );
        System.out.println( myMessage );
        m.setMessage( "Goodbye cruel world" );
        m.setStatus( Message.GOODBYE );
        update( m );
end
==============================================
PFB my ruleflow file:
(The actual file is in the attachment, however for quick view purpose, I placing only the important part of it below).

<bpmn2:resource id="Actor" name="Human Actor"/>
  <bpmn2:process id="com.sample.MyRuleFlow" tns:version="1.0" tns:packageName="com.sample" name="Sample Process" isExecutable="false">
    <bpmn2:extensionElements>
      <tns:import name="com.sample.DroolsTest.Message"/>
    </bpmn2:extensionElements>
    <bpmn2:property id="ProcVar_Message" itemSubjectRef="ItemDefinition_218" name="ProcVar_Message"/>
    <bpmn2:startEvent id="_1" g:x="16" g:y="16" g:width="48" g:height="48" name="StartProcess">
      <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:businessRuleTask id="BusinessRuleTask_1" tns:ruleFlowGroup="Group1" name="Business Rule Task 1">
      <bpmn2:extensionElements>
        <tns:onEntry-script scriptFormat="http://www.java.com/java">
          <tns:script>System.out.println(&quot;The data entered is: &quot;+ProcVar_Message.getMessage());</tns:script>
        </tns:onEntry-script>
      </bpmn2:extensionElements>
      <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_4</bpmn2:outgoing>
      <bpmn2:ioSpecification id="InputOutputSpecification_2">
        <bpmn2:dataInput id="DataInput_2" itemSubjectRef="ItemDefinition_218" name="DataInput_2"/>
        <bpmn2:dataOutput id="DataOutput_2" itemSubjectRef="ItemDefinition_218" name="DataOutput_2"/>
        <bpmn2:inputSet id="_InputSet_2" name="Input Set 2">
          <bpmn2:dataInputRefs>DataInput_2</bpmn2:dataInputRefs>
        </bpmn2:inputSet>
        <bpmn2:outputSet id="OutputSet_1" name="Output Set 1">
          <bpmn2:dataOutputRefs>DataOutput_2</bpmn2:dataOutputRefs>
        </bpmn2:outputSet>
      </bpmn2:ioSpecification>
      <bpmn2:dataInputAssociation id="DataInputAssociation_2">
        <bpmn2:sourceRef>ProcVar_Message</bpmn2:sourceRef>
        <bpmn2:targetRef>DataInput_2</bpmn2:targetRef>
      </bpmn2:dataInputAssociation>
      <bpmn2:dataOutputAssociation id="DataOutputAssociation_2">
        <bpmn2:sourceRef>DataOutput_2</bpmn2:sourceRef>
        <bpmn2:targetRef>ProcVar_Message</bpmn2:targetRef>
      </bpmn2:dataOutputAssociation>
    </bpmn2:businessRuleTask>
    <bpmn2:sequenceFlow id="SequenceFlow_1" tns:priority="1" sourceRef="_1" targetRef="BusinessRuleTask_1"/>
    <bpmn2:scriptTask id="ScriptTask_1" name="Script Task 1">
      <bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_5</bpmn2:outgoing>
      <bpmn2:script>System.out.println(&quot;The data in message is&quot;);</bpmn2:script>
    </bpmn2:scriptTask>
    <bpmn2:sequenceFlow id="SequenceFlow_4" tns:priority="1" sourceRef="BusinessRuleTask_1" targetRef="ScriptTask_1"/>
    <bpmn2:endEvent id="EndEvent_2" name="End Event 2">
      <bpmn2:incoming>SequenceFlow_5</bpmn2:incoming>
    </bpmn2:endEvent>
    <bpmn2:sequenceFlow id="SequenceFlow_5" tns:priority="1" sourceRef="ScriptTask_1" targetRef="EndEvent_2"/>
  </bpmn2:process>

==================================================================

PFB the java class used to execute the rule flow.

package com.sample;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.sample.DroolsTest.Message;

import org.kie.api.KieServices;
import org.kie.api.logger.KieRuntimeLogger;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;


/**
 * This is a sample file to launch a process.
 */
public class ProcessTest {

    public static final void main(String[] args) {
    try {
    KieServices ks = KieServices.Factory.get();
       KieContainer kContainer = ks.getKieClasspathContainer();
       KieSession kSession = kContainer.newKieSession("ksession-process");
       
       Message ProcVar_Message = new Message();
       ProcVar_Message.setMessage("Hello World");
       ProcVar_Message.setStatus(Message.HELLO);
       KieRuntimeLogger logger = ks.getLoggers().newFileLogger( kSession, "./helloworld" );
       kSession.insert(ProcVar_Message);
       Map<String, Object> params = new HashMap<String, Object>();
        params.put("ProcVar_Message",ProcVar_Message);
       kSession.startProcess("com.sample.MyRuleFlow", params);
       kSession.fireAllRules();
       logger.close();
       kSession.dispose();
       
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

}



MyRuleFlow.bpmn

Abhijit Humbe

unread,
Aug 4, 2015, 3:24:18 AM8/4/15
to drools...@googlegroups.com
Hi,
I tried with same scenario at my end and its working fine.  Did you see any exception while executing class file ?

Abhijit Humbe

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/849aaf63-e839-46b9-a2f4-4fe92fae125a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hari prasad

unread,
Aug 4, 2015, 4:41:28 AM8/4/15
to abhiji...@gmail.com, drools...@googlegroups.com
Hello Abhijit,
First, thanks a lot for taking time and looking into this issue.
One thing from your message I understand is that, at least what I have done is correct in Drools rulesflow :) and that's a relief.
I did not get any error or exception. The object is simply not visible in the ruleflow, and a rule with only sysout in 'then' condition is also not getting printed. I have attached the project PI as well. 

Could there be any dependency that I am missing here? Even if I am missing a dependency, I am unsure as to what would it be, as i am getting no error during design/runtime for a missing dependency.

Regards,
Hari

--
You received this message because you are subscribed to a topic in the Google Groups "Drools Usage" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-usage/o1F-QOdwjZE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.
Issue.zip

Abhijit Humbe

unread,
Aug 4, 2015, 7:42:38 AM8/4/15
to hari prasad, drools...@googlegroups.com
hi,
Rule is not executed because its not added into classpath.

 "kContainer.newKieSession("ksession-process");"

 here you are adding all assets from "process" package into ksession. But .drl file is in different package. Can you move drl file from "rules" package to "process" package and then try to execute process instance.
Hope it helps..


Abhijit Humbe
Reply all
Reply to author
Forward
0 new messages