6 Replies Latest reply on Oct 12, 2012 2:12 PM by Ted Pan

    Unable to fire rules before and after human task using same rule flow group

    Sameer K Newbie

      Hi I am newbie to jbpm.

       

      I have a process as below

       

      start-->rule task1-->human task1-->rule task2-->human task2-->end

       

      I am using a knowledge session which is singleton(handled in code).

       

      I am adding AgendaEventListener to session and in afterRuleFlowGroupActivated method executing fireallrules.

       

      Also, I have added kcontext.getKnowledgeRuntime().insert(kcontext.getProcessInstance()); in human task1 on exit action.

       

      Now when i am executing the process and if i provide two different rule flow groups in human task 1 and human task 2 then both the rule task are getting executed.

       

      But when i use same rule flow group then process gets stuck on rule task, it doesnt move further as rules are not executed.

       

      Please throw some pointers on what needs to be done.

       

      Can i reactivate a rule flow group in any way?

       

      Also in same session i am unable to fire same rule flow group for second process as well, which means my rule flow group is executing only once.

       

      I know some prob from my end, any help would be appreciated.

       

      JFYI the rule doesnt contain any thing which will manipulate the flow, its a simple when then condition and in then condition i have added a println.

       

        • 1. Re: Unable to fire rules before and after human task using same rule flow group
          Mauricio Salatino Master

          Hi Sameer,

          What exactly are your rules evaluating?

          Did you turn on the console logger? to see what is happening?

          Are you sure that your rules are being activated (condition matched) by your facts?

           

          Cheers

          • 2. Re: Unable to fire rules before and after human task using same rule flow group
            Sameer K Newbie

            Hi Mauricio,

             

            Thanks for replying.

             

            Below is the rule which i am trying to execute.

             

            rule "Rule456"

            ruleflow-group "validate"

            dialect"mvel"

            no-loop true;
            when

            then
            System.out.println("Rule456 Executed");
            end

             

            There is no condition as such to match

             

            This rule needs to be fired everytime but its not happening, as posted above.

             

            Thanks.

            • 3. Re: Unable to fire rules before and after human task using same rule flow group
              Mauricio Salatino Master

              So that's your answer then..

              That rule will fire only once, because nothing has changed.

              That Rule WILL NOT FIRE multiple times.

              • 4. Re: Unable to fire rules before and after human task using same rule flow group
                Sameer K Newbie

                Hey thanks for prompt reply.

                 

                I am newbie to drools as well

                 

                Really Appreciate the thought process you putting on for my problem.

                 

                I tried updating the processInstance which i am using but still my rule is not fired second time from second rule task.

                 

                rule "Rule123"
                ruleflow-group "validate"
                no-loop
                when
                processInstance : WorkflowProcessInstance()
                then
                System.out.println("Rule123 Executed");
                processInstance.setVariable("abc","xyz");
                update(processInstance);
                end

                 

                Also, if i had to write some sort of validation rule and call it from both the rule task how can i do it?

                 

                For e.g if i want to check if businessName=="xyz" then log it to db/some file.

                 

                I need to check businessName before calling human task and after humantask as well....how can this be achieved?

                 

                Can we configure rules in such a way, that those set of rules will be called everytime/whenever we want them to be executed.

                 

                Like we make a call using rule task and those set of flow-group gets executed.

                 

                Thanks.

                 

                 

                 

                • 5. Re: Unable to fire rules before and after human task using same rule flow group
                  Sameer K Newbie

                  I am using the below rule.

                   

                  rule "RuleCheck"
                  ruleflow-group "validate"
                  no-loop
                  when
                  processInstance : WorkflowProcessInstance()
                  then
                  System.out.println("RuleCheck Executed="+processInstance.getId());
                  end

                   

                  The log for above rule when i use the same rule-flow-group for multiple rule task in same process i.e. the flow mentioned in first post above is:

                   

                  For 1st rule task

                   

                  BEFORE RULEFLOW GROUP ACTIVATED group:validate[size=1]
                  BEFORE ACTIVATION FIRED rule:RuleCheck activationId:RuleCheck [1] declarations: processInstance=WorkflowProcessInstance26 [processId=Flow123,state=1](1) ruleflow-group: validate

                  RuleCheck Executed=25

                   

                  For 2nd rule task

                  BEFORE RULEFLOW GROUP ACTIVATED group:validate[size=0] {I think this is the catch, might be wrong}

                   

                  I feel from above log is that rule-flowgroup needs to be reactivated again, so that we get the size.

                   

                  Can some one tell me how can we re-activate the rule flow group and then call fireallrules from afterRuleFlowGroupActivated method of AgendaEventListener.

                   

                  Or atleast provide some pointers on how the AgendaEventListener and its methods work.

                   

                  Thanks.

                   

                   

                   

                   

                   

                  • 6. Re: Unable to fire rules before and after human task using same rule flow group
                    Ted Pan Newbie

                    I know this post is 2-month old.  My answer may be useful for other people.

                     

                    as mentioned by Mauricio, the rule will be only fired once if there is nothing change.

                     

                    You can use a dumy object to re-activiate the rule, for example,

                    in human task 1's exit actions, add the following script:

                    kcontext.setVariable("TEST",System.currentTimeMillis());

                     

                    and then change your rule to add the following script to LHS

                    eval($processInstance.getVariable("TEST")!=null)