0 Replies Latest reply on Aug 27, 2013 2:17 AM by Peng Wang

    [jBPM5.4] I can not get Human Task by using getTasksAssignedAsPotentialOwner(String userId, String language)

    Peng Wang Newbie

      Hi , I am trying to get Human Tasks by using "getTasksAssignedAsPotentialOwner(String userId, String language)" function, but the result is Empty.

      I can not figure out why,  can anybody help me please? Thanks a lot!

       

      Here are the codes:

       

      HumanTask.java

      package com.sample;

       

       

      import java.util.HashMap;

      import java.util.List;

      import java.util.Map;

       

       

      import org.drools.KnowledgeBase;

      import org.drools.builder.KnowledgeBuilder;

      import org.drools.builder.KnowledgeBuilderFactory;

      import org.drools.builder.ResourceType;

      import org.drools.io.ResourceFactory;

      import org.drools.logger.KnowledgeRuntimeLogger;

      import org.drools.logger.KnowledgeRuntimeLoggerFactory;

      import org.drools.runtime.StatefulKnowledgeSession;

      import org.jbpm.task.TaskService;

      import org.jbpm.task.query.TaskSummary;

      import org.jbpm.task.service.SyncTaskServiceWrapper;

      import org.jbpm.task.service.hornetq.AsyncHornetQTaskClient;

       

       

      public class HumanTask {

       

        public static final void main(String[] args) {

        try {

        // load up the knowledge base

        KnowledgeBase kbase = readKnowledgeBase();

        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

        KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);

        MyWorkItemHandler handler = new MyWorkItemHandler();

                  ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);

       

       

        // start a new process instance

                  Map<String, Object> params = new HashMap<String, Object>();

                  params.put("userId", "wp");

       

       

        ksession.startProcess("process", params);

       

       

        TaskService taskClient = new SyncTaskServiceWrapper(new AsyncHornetQTaskClient("HumanTaskExample-testClient"));

       

       

        taskClient.connect("127.0.0.1", 5153);

       

       

        Thread.sleep(1000);

       

        List<TaskSummary> tasks = taskClient.getTasksAssignedAsPotentialOwner("wp", "en-UK"); // Here the tasks is EMPTY!

       

        TaskSummary task1 = tasks.get(0);

       

        System.out.println("wp executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");

       

        taskClient.start(task1.getId(), "wp");

       

        taskClient.complete(task1.getId(), "wp", null);

       

        Thread.sleep(2000);

        taskClient.disconnect();

       

       

        logger.close();

        ksession.dispose();

        System.exit(0);

        } catch (Throwable t) {

        t.printStackTrace();

        }

        }

       

       

        private static KnowledgeBase readKnowledgeBase() throws Exception {

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory

        .newKnowledgeBuilder();

        kbuilder.add(ResourceFactory.newClassPathResource("human-task.bpmn"),

        ResourceType.BPMN2);

        return kbuilder.newKnowledgeBase();

        }

      }

       

      MyWorkItemHandler.java

      package com.sample;

       

       

      import org.drools.runtime.process.WorkItem;

      import org.drools.runtime.process.WorkItemHandler;

      import org.drools.runtime.process.WorkItemManager;

       

       

      public class MyWorkItemHandler implements WorkItemHandler{

       

       

        @Override

        public void abortWorkItem(WorkItem wi, WorkItemManager wim) {

        System.out.println("WorkItemHandler abortWorkItem");

        System.out.println("WorkItemManager : " + wim);

        System.out.println("WorkItem : " + wi);

        }

       

       

        @Override

        public void executeWorkItem(WorkItem wi, WorkItemManager wim) {

        System.out.println("WorkItemHandler executeWorkItem");

        System.out.println("WorkItemManager : " + wim);

        System.out.println("WorkItem : " + wi);

        }

       

       

      }

       

      human-task.bpmn

      1.JPG

       

       

      <?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">

       

       

        <itemDefinition id="_userIdItem" />

       

       

        <itemDefinition id="_5-userIdItem" />

       

       

        <process processType="Private" isExecutable="true" id="process" name="HumanTask" tns:packageName="defaultPackage" >

       

       

          <!-- process variables -->

          <property id="userId" itemSubjectRef="_userIdItem"/>

       

       

          <!-- nodes -->

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

          <scriptTask id="_2" name="Script" >

            <script>System.out.println("Before human task");</script>

          </scriptTask>

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

              <terminateEventDefinition />

          </endEvent>

          <scriptTask id="_4" name="Script" >

            <script>System.out.println("After human task");</script>

          </scriptTask>

          <userTask id="_5" name="User Task" >

            <ioSpecification>

              <dataInput id="_5_TaskNameInput" name="TaskName" />

              <inputSet>

                <dataInputRefs>_5_TaskNameInput</dataInputRefs>

              </inputSet>

              <outputSet>

              </outputSet>

            </ioSpecification>

            <dataInputAssociation>

              <targetRef>_5_TaskNameInput</targetRef>

              <assignment>

                <from xsi:type="tFormalExpression">Wp Task</from>

                <to xsi:type="tFormalExpression">_5_TaskNameInput</to>

              </assignment>

            </dataInputAssociation>

            <potentialOwner>

              <resourceAssignmentExpression>

                <formalExpression>#{userId}</formalExpression>

              </resourceAssignmentExpression>

            </potentialOwner>

          </userTask>

       

       

          <!-- connections -->

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

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

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

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

       

       

        </process>

       

       

        <bpmndi:BPMNDiagram>

          <bpmndi:BPMNPlane bpmnElement="process" >

            <bpmndi:BPMNShape bpmnElement="_1" >

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

            </bpmndi:BPMNShape>

            <bpmndi:BPMNShape bpmnElement="_2" >

              <dc:Bounds x="163" y="86" width="80" height="48" />

            </bpmndi:BPMNShape>

            <bpmndi:BPMNShape bpmnElement="_3" >

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

            </bpmndi:BPMNShape>

            <bpmndi:BPMNShape bpmnElement="_4" >

              <dc:Bounds x="611" y="85" width="80" height="48" />

            </bpmndi:BPMNShape>

            <bpmndi:BPMNShape bpmnElement="_5" >

              <dc:Bounds x="380" y="84" width="100" height="48" />

            </bpmndi:BPMNShape>

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

              <di:waypoint x="69" y="111" />

              <di:waypoint x="203" y="110" />

            </bpmndi:BPMNEdge>

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

              <di:waypoint x="651" y="109" />

              <di:waypoint x="760" y="111" />

            </bpmndi:BPMNEdge>

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

              <di:waypoint x="430" y="108" />

              <di:waypoint x="651" y="109" />

            </bpmndi:BPMNEdge>

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

              <di:waypoint x="203" y="110" />

              <di:waypoint x="430" y="108" />

            </bpmndi:BPMNEdge>

          </bpmndi:BPMNPlane>

        </bpmndi:BPMNDiagram>

       

       

      </definitions>