8 Replies Latest reply on Jul 24, 2014 1:38 PM by Jose Miguel Loor

    task data returns null after getTaskById

    Jose Miguel Loor Apprentice

      I have deployed a process in bpms 6; i can start the process with variables and the process reaches the task correctly, but when i try to get the data associated to the task, then i get a null in the task data:

       

      this is the code i am using:

      URL baseUrl = new URL("http://server:8080/business-central/");

      RemoteRestRuntimeFactory factory = new RemoteRestRuntimeFactory("com.enterprise:my-process:1.0.0",  baseUrl, "user", "password");

      RuntimeEngine engine = factory.newRuntimeEngine();

      TaskService service = engine.getTaskService();

      Task task = service.getTaskById(1);

      TaskData taskData = task.getTaskData(); >> here i get null instead of the taskData

       

      I need the taskData in order to get the contentId so i can then get the variables associated to the task

      I know the task has content, because this url:

      http://172.25.212.100:8080/business-central/rest/task/content/{contentId}

      and this url:

      http://172.25.212.100:8080/business-central/rest/task/{contentId}/content

      is giving me information about the variables i need

       

      What can be happening ?? why is the task data null ?? how else can i get the contentId associated to a task ??

        • 1. Re: task data returns null after getTaskById
          Maciej Swiderski Master

          that indeed should work. What version to you use? Do you mind attaching complete client code used for this operation so it gets validated?

           

          HTH

          • 2. Re: Re: task data returns null after getTaskById
            Jose Miguel Loor Apprentice

            Hi Maciej

            Thanks for your answer; i have installed the bpms with the jboss-bpms-installer-6.0.1.GA-redhat-4.jar installer

            I am attaching both the jar with the bpmn file that contains the process definition (bpm-listas-negras.zip) and the client application (mupi-listas-negras.zip).

            In the client application there is a class (com.ec.mutualistapichincha.listasnegras.process.GestorProcesosBpms) that uses the remote api to interact with the process.

            There is also a junit test (com.ec.mutualistapichincha.test.TasksTest)

             

            Thanks

            • 3. Re: task data returns null after getTaskById
              Maciej Swiderski Master

              thanks for detailed information, I'll try to look into it today and get back to you

              • 4. Re: Re: Re: task data returns null after getTaskById
                Maciej Swiderski Master

                alright, bit delayed but finally made the test of it. It all works well, though I used your process but created simple test case instead of using your client code:

                 

                RemoteRestRuntimeFactory factory = new RemoteRestRuntimeFactory( "org.jbpm:test:1.0", new URL("http://localhost:8080/kie-wb"), "user", "password" );
                RemoteRuntimeEngine runtimeEngine = factory.newRuntimeEngine();
                
                
                processVariables.put("identificacion", "1");
                processVariables.put("nombres", "2");
                processVariables.put("tipoIdentificacion", "3");
                processVariables.put("apellidos", "4");
                processVariables.put("basesAfectadas", "5");
                
                
                ProcessInstance processInstance = kieSession.startProcess("ListasNegras.ExcepcionListasNegras", processVariables);
                System.out.println("Process isntance started = " + processInstance.getId());
                
                
                List<Long> tasks = runtimeEngine.getTaskService().getTasksByProcessInstanceId(processInstance.getId());
                System.out.println("Found tasks " + tasks);
                
                
                        Task task = runtimeEngine.getTaskService().getTaskById(tasks.get(0));
                        assertNotNull(task);
                        assertNotNull(task.getTaskData());
                        assertNotNull(task.getTaskData().getDocumentContentId());
                        KieSession kieSession = runtimeEngine.getKieSession();
                        Map<String, Object> processVariables  = new HashMap<String, Object>();
                

                Although I tried not on exact 6.0.1.GA but more updated one that will become 6.0.2 so there is a chance it was a bug but was already fixed.

                 

                HTH

                • 5. Re: Re: Re: task data returns null after getTaskById
                  Jose Miguel Loor Apprentice

                  hi Maciej

                   

                  Thanks for your time and effort; unfortunately i cannot wait until 6.0.2.GA is released right now;

                  What i did is to get the task data via the REST endpoint directly (using http client)

                  If somebody else faces this same error i can provide some code

                  Cheers

                  • 6. Re: task data returns null after getTaskById
                    Jose Miguel Loor Apprentice

                    Hi Maciej

                    I am trying this with the bpms 6.0.2 installation (jboss-bpms-installer-6.0.2.GA-redhat-5.jar) and this is what i've found:

                    • i can retrieve the variables associated to a task in the way described originally in this post, but only if i use the 6.1.0.CR2 version of kie-services-client, with the latest stable version (6.0.1.Final) it wont work
                    • But i also found that this piece of code
                      List<TaskSummary> tasks = service.getTasksAssignedAsPotentialOwner(usuario, "en-UK");
                      does not work with that version of the kie-services-client. So, now i cannot retrieve the possible tasks for a user
                    • I also found that the format of this rest call http://localhost:8080/business-central/rest/task/4/content has changed. Now it retrieves me a serializedContent that i don't know how to translate, can you give a hint ??

                    thanks a lot

                    • 7. Re: task data returns null after getTaskById
                      Maciej Swiderski Master

                      best would be to actually rely on getTaskContent method in 6.0.2 that removes the burden of marshaling/unmarshaling task variables from the user, you'll get direct object instances in a map.

                      When it comes to the client version, best is to stick to exact same version of server side and client side to gain best support of features.

                       

                      Serialized content is Base64 bytes of a given content but when using getTaskContent you should not have that problem any more.

                       

                      HTH

                      1 of 1 people found this helpful
                      • 8. Re: task data returns null after getTaskById
                        Jose Miguel Loor Apprentice

                        Thanks Maciej, with the BASE64Decoder i could get the variables correctly

                        Its true that using the same version of client / server avoids most of the headaches; but i have found that using the rest api directly gives me a better performance

                        Cheers