11 Replies Latest reply on Jan 12, 2013 8:09 AM by Dmitry Erkin

    Can not fire a rule

    Dmitry Erkin Newbie

      Hello!

       

      Here is my first JBPM sample process whose purpose is to fire the simple rule:

       

      <process processType="Private" isExecutable="true" id="com.sample.bpmn" name="Sample Process" tns:packageName="defaultPackage" >

       

          <extensionElements>

           <tns:import name="defaultPackage.Person" />

          </extensionElements>

          <!-- process variables -->

          <property id="p" itemSubjectRef="_pItem"/>

       

          <!-- nodes -->

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

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

              <terminateEventDefinition />

          </endEvent>

          <scriptTask id="_4" name="Create new person" scriptFormat="http://www.java.com/java" >

            <script>p = new Person("john", 19);</script>

          </scriptTask>

          <scriptTask id="_6" name="Add the fact that new person is created" scriptFormat="http://www.java.com/java" >

            <script>kcontext.getKnowledgeRuntime().insert(p);

      </script>

          </scriptTask>

          <businessRuleTask id="_7" name="Fire rules" g:ruleFlowGroup="test" >

          </businessRuleTask>

       

          <!-- connections -->

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

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

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

          <sequenceFlow id="_6-_7" sourceRef="_6" targetRef="_7" />

       

        </process>

       

       

      Here is the simple rule which is supposed to be fired:

       

      package defaultPackage

       

      rule "test.Rule1"

       

      ruleflow-group "test"

       

          when

              $p : Person()

          then

              System.out.println( "Person " + $p );

       

      end

       

       

      Nothing hapens when I start an instance of my sample process. I mean the server log does not have "Person " string.

      What is wrong with my sample?

       

      Are the rules from the defaultPackade included into the KnowledgeBase which is prepared by JBPM console to execute the process from the same defaultPackade?

       

       

      Regards,

      Dmitry Erkin

        • 1. Re: Can not fire a rule
          Maciej Swiderski Master

          depends how you deploy your processes and rules. If you simply use jbpm.console.directory then only processes are read from that location and rules are not. You could use Guvnor for that and import both process and rule there. That will make both rules and processes available for the runtime inside console.

           

          HTH

          • 2. Re: Can not fire a rule
            Dmitry Erkin Newbie

            Hello, Maciej

             

            Thanks for your answer! My sample process is stored in Guvnor in the same package as the sample rule. And I invoke that process from JBPM-console. So according to what you have said the rule has to be available for the runtime.

             

             

            Regards,

            Dmitry Erkin

            • 3. Re: Can not fire a rule
              Maciej Swiderski Master

              Have you tried to build the package in guvnor?  Another check point, did you place the model (that includes Person class) on console's classpath?

               

              Would be good to verify if all nodes are executed properly via log history. When you run this instance does it complete?

               

              Cheers

              • 4. Re: Can not fire a rule
                Dmitry Erkin Newbie

                Hello, Maciej !

                 

                That is the point!

                I cannot see an instance of Sample process as completed in JBPM-console although it allows me to start a new one and does not show any errors.

                It says "All: 0 instances of Sample process".

                Person class is on the path, I suppose: d:\jbpm\dependencies\Person.jar

                I did that after I put Person.jar in d:\jbpm\dependencies:

                ant clean.demo

                ant install.demo.noeclipse

                And I checked Person class by simple test scenario then.

                the defaultPackade is built.

                 

                 

                But there are not other messages in server.log while I am starting an instance except those:

                 

                21:42:29,359 WARN  [org.drools.guvnor.server.repository.RulesRepositoryManager] (http-localhost-127.0.0.1-8080-30) Creating RulesRepository with default username.
                21:42:29,369 INFO  [stdout] (http-localhost-127.0.0.1-8080-30) =============== session-guest-520

                 

                21:42:29,369 INFO  [org.drools.guvnor.server.security.DemoAuthenticator] (http-localhost-127.0.0.1-8080-30) Demo login for user (admin) succeeded.
                21:42:29,379 INFO  [org.drools.guvnor.server.files.AuthorizationHeaderChecker] (http-localhost-127.0.0.1-8080-30) admin authenticated for rest api
                21:42:29,379 INFO  [org.drools.guvnor.server.files.PackageDeploymentServlet] (http-localhost-127.0.0.1-8080-30) PackageName: defaultPackage
                21:42:29,379 INFO  [org.drools.guvnor.server.files.PackageDeploymentServlet] (http-localhost-127.0.0.1-8080-30) PackageVersion: LATEST
                21:42:29,389 INFO  [org.drools.guvnor.server.files.PackageDeploymentServlet] (http-localhost-127.0.0.1-8080-30) PackageIsLatest: true
                21:42:29,389 INFO  [org.drools.guvnor.server.files.PackageDeploymentServlet] (http-localhost-127.0.0.1-8080-30) PackageIsSource: false
                21:42:29,389 INFO  [stdout] (http-localhost-127.0.0.1-8080-30) =============== session-guest-520

                 

                 

                So I am in doubt is an instance created or not?

                 

                 

                Regards,

                Dmitry Erkin

                • 5. Re: Can not fire a rule
                  doboss Newbie

                  Not sure if this helps, but I would debug it by putting some script tasks in your process which just print something like "Got here" so you at least know the process is being run. If the process is being run, but you are not seeing the "Person " part, then you know it's something with the rule or the way you are calling the rule.

                   

                  HTH.

                  1 of 1 people found this helpful
                  • 6. Re: Can not fire a rule
                    Maciej Swiderski Master

                    +1 doboss

                     

                    alternatively you can take a look at data base tables (nodeinstanelog)

                     

                    I think that the instance is created and since it has no wait state it finishes in the same thread it was started so console won't show it as active.

                     

                    Just looked at the process again, I think what happens is that the process you insert is null. And this is bacause you set p (which is a process variable) in the script but that is only assigning the value but does not set it as process variable. if you replace the first script with following lines I think the rule will be fired:

                    p = new Person("john", 19);

                    kcontext.getProcessInstance().setVariable("p", p);

                     

                    HTH

                    1 of 1 people found this helpful
                    • 7. Re: Can not fire a rule
                      Dmitry Erkin Newbie

                      Hello!

                       

                      +1 Maciej

                      +1 doboss

                       

                      Your answers are very helpful!

                       

                      One question left is that kcontext.getProcessInstance() returns a reference to Interface ProcessInstance not to Interface WorkflowProcessInstance.

                      Is it safe to cast ProcessInstance to WorkflowProcessInstance? How to set a jar where WorkflowProcessInstance is located on Guvnor path?

                       

                      Regards,

                      Dmitry Erkin

                      • 8. Re: Can not fire a rule
                        doboss Newbie

                        I don't know about the casting, but I don't think the jar needs to be in the Guvnor path, as the Guvnor is just a repository. I think you want to make sure the jar is in the path of the application running the process...

                        • 9. Re: Can not fire a rule
                          Dmitry Erkin Newbie

                          It says: "Process Compilation error WorkflowProcessInstance cannot be resolved to a type" when I try to build a package in Guvnor.

                           

                          the import is set up:

                           

                          <extensionElements>

                               <tns:import name="defaultPackage.Person" />

                               <tns:import name="org.drools.runtime.process.WorkflowProcessInstance" />

                          </extensionElements>

                           

                          this cast is used: "((WorkflowProcessInstance)kcontext.getProcessInstance())"

                           

                          so probably I need to set up Guvnor path

                          • 10. Re: Can not fire a rule
                            Maciej Swiderski Master

                            I am not sure you need casting there, but if Guvnor complains when building the package you could try to declare FQN in the case rather than use import.

                             

                            HTH

                            • 11. Re: Can not fire a rule
                              Dmitry Erkin Newbie

                              Thank you very much Maciej