JBoss Community

Re: fail to fire a rule task~~ frustrated

created by Guo-Guang Chiou in jBPM - View the full discussion

hi, Francesco.

 

thanks for your reply.

 

Finally, I found a way to run rule task on jbpm-console.

 

here is my process definition..

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

<?xml version="1.0" encoding="UTF-8"?>

<definitions id="Definition"

             targetNamespace="http://www.jboss.org/drools"

             typeLanguage="http://www.java.com/javaTypes"

             expressionLanguage="http://www.mvel.org/2.0"

             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"

             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

             xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"

             xmlns:g="http://www.jboss.org/drools/flow/gpd"

             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"

             xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"

             xmlns:di="http://www.omg.org/spec/DD/20100524/DI"

             xmlns:tns="http://www.jboss.org/drools">

 

 

  <process processType="Private" isExecutable="true" id="testrule" name="TestRule" tns:packageName="defaultPackage" tns:version="16" >

 

 

    <extensionElements>

     <tns:import name="org.drools.event.*" />

    </extensionElements>

    <!-- nodes -->

    <startEvent id="_1" name="StartProcess" />

    <scriptTask id="_2" name="Script" scriptFormat="http://www.java.com/java" >

      <script>System.out.println("Before rule\n");

 

 

//java.util.Iterator itr = kcontext.getKnowledgeRuntime().getKnowledgeBase().getStatefulKnowledgeSessions().iterator();

//boolean called = false;

 

 

  org.drools.event.AgendaEventListener lis = new org.drools.event.AgendaEventListener(){

                                        public void activationCancelled(org.drools.event.ActivationCancelledEvent arg0,

                                                            org.drools.WorkingMemory arg1) {

                                        }

                                        public void activationCreated(org.drools.event.ActivationCreatedEvent arg0,

                                                            org.drools.WorkingMemory arg1) {

                                        }

                                        public void afterActivationFired(

                                                            org.drools.event.AfterActivationFiredEvent arg0, org.drools.WorkingMemory arg1) {

                                        }

                                        public void afterRuleFlowGroupActivated(

                                                            org.drools.event.RuleFlowGroupActivatedEvent arg0, org.drools.WorkingMemory arg1) {

                                                  System.out.println("firing all rules");

                                                  arg1.fireAllRules();

                                        }

                                        public void afterRuleFlowGroupDeactivated(

                                                            org.drools.event.RuleFlowGroupDeactivatedEvent arg0, org.drools.WorkingMemory arg1) {

                                        }

                                        public void agendaGroupPopped(org.drools.event.AgendaGroupPoppedEvent arg0,

                                                            org.drools.WorkingMemory arg1) {

                                        }

                                        public void agendaGroupPushed(org.drools.event.AgendaGroupPushedEvent arg0,

                                                            org.drools.WorkingMemory arg1) {

                                        }

                                        public void beforeActivationFired(

                                                            org.drools.event.BeforeActivationFiredEvent arg0, org.drools.WorkingMemory arg1) {

                                        }

                                        public void beforeRuleFlowGroupActivated(

                                                            org.drools.event.RuleFlowGroupActivatedEvent arg0, org.drools.WorkingMemory arg1) {

                                        }

                                        public void beforeRuleFlowGroupDeactivated(

                                                            org.drools.event.RuleFlowGroupDeactivatedEvent arg0, org.drools.WorkingMemory arg1) {

                                        }

                              };

           

//if(itr.hasNext())

//{

           System.out.println("casting..");

           org.drools.runtime.StatefulKnowledgeSession ksession = (org.drools.runtime.StatefulKnowledgeSession) kcontext.getKnowledgeRuntime();

          

            try{

           org.drools.impl.StatefulKnowledgeSessionImpl s = (org.drools.impl.StatefulKnowledgeSessionImpl)ksession;

           s.session.addEventListener(lis)  ;

           System.out.println("listener is added");

          //called = true;    

     }

     catch(Exception ex)

     {

             System.out.println("================================================================================================================");

               System.out.println(ex.getMessage());    

                       System.out.println("================================================================================================================");

     }

//}

//if(called==false)

//{

//          System.out.println("no session found");  

//}</script>

    </scriptTask>

    <businessRuleTask id="_3" name="Rule" g:ruleFlowGroup="validate" >

    </businessRuleTask>

    <endEvent id="_4" name="End" >

        <terminateEventDefinition/>

    </endEvent>

    <scriptTask id="_5" name="Script" scriptFormat="http://www.java.com/java" >

      <script>

System.out.println("Rule Task is done"); </script>

    </scriptTask>

 

 

    <!-- connections -->

    <sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />

    <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />

    <sequenceFlow id="_5-_4" sourceRef="_5" targetRef="_4" />

    <sequenceFlow id="_3-_5" sourceRef="_3" targetRef="_5" />

 

 

  </process>

 

 

  <bpmndi:BPMNDiagram>

    <bpmndi:BPMNPlane bpmnElement="testrule" >

      <bpmndi:BPMNShape bpmnElement="_1" >

        <dc:Bounds x="16" y="16" width="48" height="48" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="_2" >

        <dc:Bounds x="96" y="16" width="80" height="48" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="_3" >

        <dc:Bounds x="208" y="16" width="80" height="48" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="_4" >

        <dc:Bounds x="432" y="16" width="48" height="48" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape bpmnElement="_5" >

        <dc:Bounds x="320" y="16" width="80" height="48" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNEdge bpmnElement="_1-_2" >

        <di:waypoint x="40" y="40" />

        <di:waypoint x="136" y="40" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="_2-_3" >

        <di:waypoint x="136" y="40" />

        <di:waypoint x="248" y="40" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="_5-_4" >

        <di:waypoint x="360" y="40" />

        <di:waypoint x="456" y="40" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge bpmnElement="_3-_5" >

        <di:waypoint x="248" y="40" />

        <di:waypoint x="360" y="40" />

      </bpmndi:BPMNEdge>

    </bpmndi:BPMNPlane>

  </bpmndi:BPMNDiagram>

 

 

</definitions>

 

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

Reply to this message by going to Community

Start a new discussion in jBPM at Community