1 2 Previous Next 20 Replies Latest reply on May 2, 2014 1:43 AM by swiderski.maciej Go to original post
      • 15. Re: Re: Having both ActorId and GroupId for HumanTask
        arif.mohammed

        Yes I did like that Please find the attachment of screenshots. For sake of avoiding name collision I renamed to in_owner but still the rule is not triggered. Also I noticed that the POEPLEASSIGNMENT_POTOWNERS is having only one entry(i.e, only 1 entry for GroupID)  though I have mapped both GroupID(mapped from process variable) and ActorID(mapped from task variable) this clearly tells that there is some thing wrong with task input variable in_owner. What Iam doing wrong here ? Somewhere I read that in order to refer task variable we need to use ${var_name} I did that aswell but no change in behaviour.

         

          when

            $task : Task()

            $params : HashMap(this["in_owner"] !=null)

        then

            ....

         

          And Regarding group tasks : I need to get all Tasks no matter in which state they are(specifically Ready,Reserved,InProgress) for the specified group. And also no matter to which user the task is assigned. Iam only interested in a particular group task without any relation to a particular user. How can I get them ?

        • 16. Re: Re: Re: Having both ActorId and GroupId for HumanTask
          arif.mohammed

          Hi Maciej,

            Input variable(in_owner) is mapped correctly as you can see from the attached debug window(Capture3.PNG) @ AbstractHTWorkItemHandler.createTaskContentBasedOnWorkItemParams

           

            I guess there is some issue with serialization of HashMap of parameters, I have added toString method in org.jbpm.services.task.impl.model.ContentDataImpl and added the following piece of code in TaskRuleServiceImpl.executeRules and it gives junk characters string in my case but where as if I run the test case LifeCycleLocalWithRuleServiceTest it gives proper SOP as "***************** Recieved params :{manager=John}". Is there any thing I need to do ?

           

                      if (params != null) {

                          System.out.println("***************** Recieved params :"+params);

                          session.insert(params);

                      }

          • 17. Re: Re: Re: Having both ActorId and GroupId for HumanTask
            arif.mohammed

            Hi Maciej. Can you please help me what is wrong with this ? Do I need to do something with marshalling strategy ?

            • 18. Re: Re: Re: Re: Having both ActorId and GroupId for HumanTask
              swiderski.maciej

              Arif, you're right task variables are already converted to ContentData and thus not available as Map. I'll fix that soon and for the time being please give a try with this rule:

              package defaultPackage
              
              
              //list any import classes here.
              import org.kie.api.task.model.Task;
              import org.kie.api.task.model.User;
              import org.kie.api.task.model.Status;
              import org.kie.api.task.model.PeopleAssignments;
              import org.jbpm.services.task.rule.TaskServiceRequest;
              import org.kie.internal.task.api.model.InternalTaskData;
              import org.kie.internal.task.api.ContentMarshallerContext;
              import org.jbpm.services.task.impl.TaskContentRegistry;
              import org.jbpm.services.task.utils.ContentMarshallerHelper;
              import org.kie.internal.task.api.model.ContentData;
              
              
              import org.jbpm.services.task.impl.model.*;
              import org.jbpm.services.task.internals.lifecycle.*;
              
              
              import java.util.HashMap;
              import java.util.List;
              
              
              
              
              //declare any global variables here
              global TaskServiceRequest request;
              
              
              
              
              rule "Exclude john"
              
              
                  when
                      $task : Task()
                      $data : ContentData()
                eval(validate($task, $data))
                  then
                      System.out.println("Conditions met, changing vlaues" );
                      // put your consequence here....
              end
              
              
              function boolean validate(Task task, ContentData data) {
                ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task);
                HashMap params = (HashMap) ContentMarshallerHelper.unmarshall(((ContentData) data).getContent(), ctx.getEnvironment(), ctx.getClassloader());
                // put your condition here....
                if (params.get("ActorId").equals("john")) {
                   return true;
                }
              
                return false;
              }
              

              HTH

              • 19. Re: Re: Re: Re: Re: Having both ActorId and GroupId for HumanTask
                arif.mohammed

                Awesome it works as below couple of points just for clarification

                 

                  1) Is it going to be a very costly operation since for every task created a rule will be fired and also a session will be created for execution of the rule ?

                  2) I saw you are using AssignmentService and TaskServiceRequest in the test case. I can't import AssignmentService not sure what is the reason as it was giving some rule compilation error. And regarding TaskServiceRequest : How is this different than directly changing Task object like how you did for "Assign to mary"

                    It is such an important feature and so It would be great if it could be documented with details about the usage.

                3) Lastly can you please help me about retrieving group tasks specific to a group as discussed above in this thread ?

                 

                 

                package defaultPackage
                
                //list any import classes here.
                import org.kie.api.task.model.Task;     
                import org.kie.api.task.model.User;
                import org.kie.api.task.model.Status;
                import org.kie.api.task.model.PeopleAssignments;
                import org.jbpm.services.task.rule.TaskServiceRequest;
                import org.kie.internal.task.api.model.InternalTaskData;
                import org.kie.internal.task.api.ContentMarshallerContext;  
                import org.jbpm.services.task.impl.TaskContentRegistry;  
                import org.jbpm.services.task.utils.ContentMarshallerHelper;  
                import org.kie.internal.task.api.model.ContentData;  
                
                import org.jbpm.services.task.impl.model.*;
                import org.jbpm.services.task.internals.lifecycle.*;
                
                import java.util.HashMap;
                import java.util.List;
                
                //declare any global variables here
                global TaskServiceRequest request;
                
                rule "Auto Assign To Owner If there exist only 1 owner and 1 or more groups" 
                
                    when
                        $task : Task()
                        $data : ContentData()  
                        eval(validate($task, $data))
                    then
                        ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext($task);  
                        HashMap params = (HashMap) ContentMarshallerHelper.unmarshall(((ContentData) $data).getContent(), ctx.getEnvironment(), ctx.getClassloader());  
                        String actorId = (String)params.get("ActorId");
                        ((TaskDataImpl)$task.getTaskData()).setActualOwner(new UserImpl(actorId));
                        ((TaskDataImpl)$task.getTaskData()).setStatus(Status.Reserved);
                    end
                
                 function boolean validate(Task task, ContentData data) {  
                   ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task);  
                   HashMap params = (HashMap) ContentMarshallerHelper.unmarshall(((ContentData) data).getContent(), ctx.getEnvironment(), ctx.getClassloader());  
                   if (params.get("ActorId")!=null && params.get("GroupId")!=null && ((String)params.get("ActorId")).split(",").length==1  ) {  
                     return true;  
                   }    
                   return false;  
                 }  
                
                • 20. Re: Having both ActorId and GroupId for HumanTask
                  swiderski.maciej

                  Arif Mohammed wrote:

                   

                  Awesome it works as below couple of points just for clarification

                   

                    1) Is it going to be a very costly operation since for every task created a rule will be fired and also a session will be created for execution of the rule ?

                  no, it won't be costly as the ksession used for rule evaluation is in memory only and creation of such session is very lightweight. kbase is created only once and then reused.

                   

                  Arif Mohammed wrote:

                   

                    2) I saw you are using AssignmentService and TaskServiceRequest in the test case. I can't import AssignmentService not sure what is the reason as it was giving some rule compilation error. And regarding TaskServiceRequest : How is this different than directly changing Task object like how you did for "Assign to mary"

                      It is such an important feature and so It would be great if it could be documented with details about the usage.

                  AssignmentService was only for test purpose to validate the use of globals for the task rule service so you shouldn't rely on that one although you might want to create similar to simplify the logic in rule itself. TaskServiceRequest is more of a way to communicate to the engine that task did not fulfill requirements to be created/completed for example when someone who has no rights to create a task attempts to do so.

                  Feel free to submit pull request with some documentation as well since you tried it, it's always good to have contributions from community members.

                   

                  Arif Mohammed wrote:

                   

                  3) Lastly can you please help me about retrieving group tasks specific to a group as discussed above in this thread ?

                   

                  see other post for details

                   

                  HTH

                  1 2 Previous Next