5 Replies Latest reply on Oct 16, 2015 8:12 AM by jizuzqui

    jBPM6 - HumanTask's status doesn't change after being started nor completed

    jizuzqui

      Hi,

       

      I'm trying to execute a simple workflow as a Java Application with jBPM 6.2.0-Final. The workflow is as it follows:

       

      workflow.PNG

      The first HumanTask is assigned to an actor called "tecnico1". After "tecnico1" completes his task, the second task is assigned to a second actor, "aprobador". Here is the java code for this workflow:

       

        // Task 1: Product Definition

        List<TaskSummary> listaActor1 = taskService.getTasksAssignedAsPotentialOwner(actor1, "");

       

        System.out.println(actor1 + " has " + listaActor1.size() + " assigned tasks");

        TaskSummary task = listaActor1.get(listaActor1.size() - 1);

        System.out.println(actor1 + " claims the task " + task.getName() + ". The task status is " + task.getStatus().name());

        taskService.claim(task.getId(), actor1);

        System.out.println(actor1 + " has received the task " + task.getName() + ". The task status is " + task.getStatus().name());

        taskService.start(task.getId(), actor1);

        System.out.println(actor1 + " has started the task " + task.getName() + ". The task status is " + task.getStatus().name());

        taskService.complete(task.getId(), actor1, null);

        System.out.println(actor1 + " has completed the task " + task.getName()

        + ". The task status is " + task.getStatus().name() + ". The task owner is "

        + task.getActualOwnerId());

       

        // Task 2: Product Approval

        List<TaskSummary> listaActor2 = taskService.getTasksAssignedAsPotentialOwner(actor2, "");

        System.out.println(actor2 + " has " + listaActor2.size() + " assigned tasks");

        task = listaActor2.get(listaActor2.size() - 1);

        System.out.println(actor2 + " has received the task " + task.getName() + ". The task status is " + task.getStatus().name());

        taskService.start(task.getId(), actor2);

        System.out.println(actor2 + " has started the task " + task.getName() + ". The task status is " + task.getStatus().name());

        taskService.complete(task.getId(), actor2, null);

        System.out.println(actor2 + " has completed the task " + task.getName()

        + ". The task status is " + task.getStatus().name() + ". The task owner is "

        + task.getActualOwnerId());

       

        ksession.fireAllRules();



      Here is the output log:

      tecnico1 has 1 assigned tasks

      tecnico1 claims the task Definicion producto. The task status is Ready

      tecnico1 has received the task Definicion producto. The task status is Ready

      tecnico1 has started the task Definicion producto. The task status is Ready

      tecnico1 has completed the task Definicion producto. The task status is Ready. The task owner is null

      aprobador has 1 assigned tasks

      aprobador has received the task Aprobacion Producto. The task status is Reserved

      aprobador has started the task Aprobacion Producto. The task status is Reserved

      aprobador has completed the task Aprobacion Producto. The task status is Reserved. The task owner is aprobador

       

      ¿Is it correct? I thought that task status should change...

       

      Source project is attached.

       

      Thank you!

        • 1. Re: jBPM6 - HumanTask's status doesn't change after being started nor completed
          jimmy001

          Hi,

           

          probably you must reload the task after every action. Give it a try.

          You are right, status should change

          • 2. Re: jBPM6 - HumanTask's status doesn't change after being started nor completed
            salaboy21

            +1 to jimmy001,

            You need to refresh the task, because the status is changed but in the server, also.. are you using the RuntimeManager? I strongly recommend you using it so the task service gets configured accordingly.

            • 3. Re: jBPM6 - HumanTask's status doesn't change after being started nor completed
              jizuzqui

              Hi,

               

              what do you mean with "refresh the task"?  How can I do that? I think I'm using RuntimeManager, but I'm not sure if I'm using it correctly. This is the code executed before retrieving and starting the tasks:

               

                KieServices ks = KieServices.Factory.get();

                KieContainer kContainer = ks.getKieClasspathContainer();

                KieBase kbase = kContainer.getKieBase("TallerProductosKB");

               

                Server server = Server.createTcpServer(new String[0]);

                server.start();

               

                 Properties properties = new Properties();

                 properties.load(ProcessMain.class.getResourceAsStream("/jBPM.properties"));

               

                  // Configuring datasource

                  PoolingDataSource pds = new PoolingDataSource();

                  pds.setUniqueName(properties.getProperty("persistence.datasource.name", "jdbc/jbpm-ds"));

                  pds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");

                  pds.setMaxPoolSize(5);

                  pds.setAllowLocalTransactions(true);

                  pds.getDriverProperties().put("user", properties.getProperty("persistence.datasource.user", "sa"));

                  pds.getDriverProperties().put("password", properties.getProperty("persistence.datasource.password", ""));

                  pds.getDriverProperties().put("url", properties.getProperty("persistence.datasource.url", "jdbc:h2:tcp://localhost/~/jbpm-db;MVCC=TRUE"));

                  pds.getDriverProperties().put("driverClassName", properties.getProperty("persistence.datasource.driverClassName", "org.h2.Driver"));

                  pds.init();

               

                // Creating RuntimeManager

                // Actors definition

                properties = new Properties();

                properties.setProperty(actor1_1, "admins,managers,users,PM");

                properties.setProperty(actor1_2, "admins,managers,users,PM");

                properties.setProperty(actor2, "admins,managers,users,PM");

               

                UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);

               

                EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

                RuntimeEnvironmentBuilder builder =

              RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback) .knowledgeBase(kbase);

               

                RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(builder.get(), "");

                RuntimeEngine engine = manager.getRuntimeEngine(null);

                KieSession ksession = engine.getKieSession();

                TaskService taskService = engine.getTaskService();

               

                ProcessInstance instancia = ksession.startProcess("TallerProductos");

                System.out.println("Instancia creada: " + instancia.getId());

               

                ksession.fireAllRules();

              • 4. Re: jBPM6 - HumanTask's status doesn't change after being started nor completed
                salaboy21

                Call this method again after calling the claim method:


                listaActor1 = taskService.getTasksAssignedAsPotentialOwner(actor1, "");


                And you should be able to see that the task was updated.

                • 5. Re: jBPM6 - HumanTask's status doesn't change after being started nor completed
                  jizuzqui

                  Yeah, that's was I did. Thank you all!