4 Replies Latest reply on Feb 19, 2013 10:32 AM by maq99

    JBPM 5.4.0-Final: Human Task variables mapping persistence problem.

    maq99

      Hallo,

       

      I have try to get help in simmilar topic https://community.jboss.org/thread/218281?start=15&tstart=0 but withou success. So I decide to create new one.

      My problem is that I cannot get access to process variable set as a result in HumanTask1 from HumanTask2

      This is my diagram:

      https://community.jboss.org/servlet/JiveServlet/showImage/2-792774-20169/Diagram.gif

      Short flow description:

      After process is started user:user1 pick object:wrapper (from external Wsdl) to edit, chenge its fields and confirm changes or reject it.

      Eddited object is about to be placed as HT result and stored as process variables.

      First gateway check if object have been placed (not null - go to commit) or changes have been rejected (is null - cancel & end process)

      At begininig next HT (approval) log script is called, then it calls my custom EscalatedDeadlineHandler and send email to user:approver (HT2 task owner).

      Approval base on object:wrapper from previous HT. Approval page display edited object:wrapper and shows changes made by user:user1

      As a result Boolean value isApproved has to be added to proces variables. Next gateway check isApproved = true then go to submit changes (send back to store edited object - external Wsdl) - else goes to end.

       

      Process is started correctly but I cannot see variables added at HT1 in database.

      I also have problem with load/ reload disposed session.

       

      I have seen and try:

      http://stackoverflow.com/questions/7120600/completing-a-task-fails-after-calling-statefulsession-dispose

      https://community.jboss.org/thread/201901

      https://community.jboss.org/thread/171181

      https://community.jboss.org/message/745526

      https://github.com/droolsjbpm/jbpm/blob/master/jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/session/VariablePersistenceStrategyTest.java

      (try both strategies - i prefer to store serializable object but tested entity object to - object have been persisted - but i have not found reference to it in db process data)

       

      Below test project sources can be found. Project base on Seam2.2 - required libs list (not attached) can be found in deployed-jars-ear.list & deployed-jars-war.list files

      I have changed data source name at persistence. Project use Jboss7.1.3 with deployed jbpm-human-task-war-5.4.0.Final-EE6.war (also with changed DS name)

        • 1. Re: JBPM 5.4.0-Final: Human Task variables mapping persistence problem.
          maq99

          Workaround for this problem - get variable at HT2 from task contetnt :

           

          public Object getProcessParameter(Long taskId, String key){

           

               TaskService taskService = getLocalTaskService();

               Task task = taskService.getTask(taskId);

               TaskData taskData = task.getTaskData();

               Long documentContentId = taskData.getDocumentContentId();

               Content content = taskService.getContent(documentContentId);

               Map<?, ?> variableMap = ((Map<?, ?>) ContentMarshallerHelper.unmarshall(content.getContent(), null));

               retObj = variableMap.get(key);

          }

           

          I don't know why it is not available as process variable.

          Regards

          1 of 1 people found this helpful
          • 2. Re: JBPM 5.4.0-Final: Human Task variables mapping persistence problem.
            joploya

            Hello,

             

            To access your variables you should use :

            /**

                       * Return the WorkflowProcessInstance associated to a Task

                       * This instance allow to access the map of variables

                       * @return WorkflowProcessInstance managed

                       */

                      public WorkflowProcessInstance getWorkflowProcessInstance(long processInstanceId){

                                return (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);

                      }

            kSession is a StatefullKnowledgeSession

             

            then you access your process variable like this : getWorkflowProcessInstance(task.getProcessInstanceId()).getVariable("formObject");

             

            Regards,

            • 3. Re: JBPM 5.4.0-Final: Human Task variables mapping persistence problem.
              maq99

              Sorry but You have not seen the attachment code.. the problem exist because at HT2 i have null variable aldow it have been set at HT1.. full code of getProcessParameter is:

               

              {code}  public Object getProcessParameter(StatefulKnowledgeSession ksession,

                          Long processInstanceId, Long taskId, String key) {

               

                      String paramInfo = "getProcessParameter sessionid: " + ksession.getId()

                              + "," + ksession.hashCode() + " processInstanceId: "

                              + processInstanceId + " taskId: " + taskId;

                      WorkflowProcessInstance workflowProcessInstance = (WorkflowProcessInstance) ksession

                              .getProcessInstance(processInstanceId);

                      Object retObj = null;

                        if (workflowProcessInstance == null

                              || workflowProcessInstance.getVariable(key) == null) {

               

                          TaskService taskService = getLocalTaskService();

                          Task task = taskService.getTask(taskId);

                          TaskData taskData = task.getTaskData();

                          Long documentContentId = taskData.getDocumentContentId();

                          Content content = taskService.getContent(documentContentId);

                          Map<?, ?> variableMap = ((Map<?, ?>) ContentMarshallerHelper

                                  .unmarshall(content.getContent(), null));

                          retObj = variableMap.get(key);

                          paramInfo = paramInfo + " From documentContent ";

                       } else {

                          paramInfo = paramInfo + " From workflowProcessInstance ";

                          retObj = workflowProcessInstance.getVariable(key);

                      }

                      paramInfo = paramInfo + " <" + key + "," + retObj + ">";

                      log.info(paramInfo);

                      return retObj;

                  }{code}

              Now at HT2 i have variable from documentContent but another problem ocures:

              I can not run flow after secont human task complete.

              I change flow to simplest one:

              normal.gif

              and change order of human tasks :

              reorder.gif

              each time second script is not called after second humanTask complete

              here is code used to resolv both human tasks:

               

              call after task start:

               

              {code}Map<String, Object> results = new HashMap<String, Object>();

                      results.put("result", wrapper);

                      resolvTask(results, "user1", taskId, ksession);{code}

               

              resolv method code:

               

               

              {code}public void resolvTask(Map<String, Object> result, String user,

                          Long taskId, StatefulKnowledgeSession ksession) {

               

                      log.info("resolv task user: " + user + " taskId: " + taskId);

               

                      TaskService taskService = getLocalTaskService();

                      if (result != null) {

                          log.info("result: ");

                          for (String key : result.keySet()) {

                              Object res = result.get(key);

                              log.info("<" + key + "," + res + ">");

                          }

                          taskService.completeWithResults(taskId, user, result);

                      } else {

                          taskService.complete(taskId, user, null);

                      }

                      ksession.fireAllRules();

                      log.info("FIRED");

                  }{code}

              • 4. Re: JBPM 5.4.0-Final: Human Task variables mapping persistence problem.
                maq99

                Problems with reading variables exist because human task on exit action should call :

                 

                {code}kcontext.getKnowledgeRuntime().insert(kcontext.getProcessInstance());{code}

                 

                To run the flow after reload session i made this: https://community.jboss.org/message/759786