5 Replies Latest reply on May 11, 2011 2:29 AM by Ayusman Dikshit

    How to use task and state in jbpm 4.4

    Ayusman Dikshit Newbie

      Hi All,I am trying to use jbpm 4.4 for a workflow solution where, the UI is provided by a web application.Here I am trying to assign a certain task to a user and expect him/her to perform certain action on it...

      like "Approve", "Reject" and "Approve with remarks"..

       

      All of these actions need to have separate processing.

      What I am not able to understand is,

      should I use a task element :  

      OR

      a state (wait state) element:  

       

      Idea is, I will let the user click on the  "Approve", "Reject" and "Approve with remarks" buttons in an jsp page and I want to convey this to the process engine, through jbpm APIs. When I use a task element, how can I signal the execution to move forward and take a path like, "Approve" or "Reject"

       

      Need some help/pointers on this.

       

       

      TIA

        • 1. How to use task and state in jbpm 4.4
          Samrat Roy Newbie

          you will definitely need to use the task .

           

          asignee are directly available with the task state.  another thing to note is .. jbpm api directly deals with the users, so you will have to expose the user details to the jbpm api .. as jbpm can directly delegate tasks to the users of your application without any translation.

           

          example :

           

           

          <task assignee="#{approver}" g="302,391,92,52" name="ApprovalDecision">

                <transition g="-85,-6" name="isLastApprover?" to="isLastApprover"/> 

             </task>

           

          here the name of the approver in assignee="#{approver}" is comming as a process variable.

          • 2. How to use task and state in jbpm 4.4
            Ayusman Dikshit Newbie

            Thanks Samrat.

            Though I have figured out this; my question remains un-answered.

            How do I track which action has been taken on the allocated task.

             

            How do I take different execution paths (assuming I can take different execution paths from a task element), i.e. when the user user clicks on the approve/reject button I want to take different outgoing paths.

             

            Is it possible?

             

            Thanks,

            Ayusman

            • 3. Re: How to use task and state in jbpm 4.4
              Samrat Roy Newbie

              There are multiple ways of doing it .. the way i have tackled it is :

               

              Here is some sample code from my project.. I thought the best way was sharing related code.

               

               

              // Controller code for .. notice approval or rejects comes from the same jsp in a parameter. :  The task Id is the is id of the task created for the user .. {lookup taskservice.. } you will need this taskid to track actions performed on a task ..

               

               

              protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException {

                      String requestId = request.getParameter("requestId");

                     String status = request.getParameter("status");     // approved OR rejected captured from JSP

                      String taskId = request.getParameter("taskId");

                      String taskType=request.getParameter("taskType");

                      LoginUser loginUser =(LoginUser)request.getSession().getAttribute(MasterUtil.LOGGED_USER);

                     lmsService.approval(requestId,status,taskId,taskType,loginUser.getUsername());   // service method

               

               

                      Map retMap = new HashMap();

                      try {

                      retMap.putAll(referenceData(request));

                      } catch (Exception e) {

                          // TODO Auto-generated catch block

                          e.printStackTrace();

                      }

                      //return new ModelAndView("redirect:/approveLeave.htm",retMap);

                      return new ModelAndView(getFormView(),retMap);

                  }

               

               

              // This is a method from lmsservice.. lmsService.approval() which takes care of the inputs from the controller.

               

              public void approval(String requestID, String status ,String taskId,String taskType,String userId) {

                      if(status.equals("rejected")){

                          ApproveLeaveModel aml =leaveModuleDao.getLeaveRequestbyId(requestID);

                          leaveModuleDao.manageLC(aml.getDays(),aml.getRequestorEmpCode(),aml.getDetails());

                      }

                      //leaveModuleDao.changeLeaveStatus(requestID, status);

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

                     variables.put("decision", status);                 // this is where you setup a variable in the process .. let a decision state decide on the //basis of this variable and take the appropriate route .. attached my jpdl image

                     taskService.setVariables(taskId, variables); // assign variable to the process instance.

                      if(taskType.equals("g")){

                          taskService.takeTask(taskId, userId);

                      }

                      taskService.completeTask(taskId);   // This completes a task marked by a  specific task id

                  }

              • 4. How to use task and state in jbpm 4.4
                Samrat Roy Newbie

                and this is how you get the task id's of the tasks allocated to a user  before you display them on a jsp ..

                 

                Keep the task id in a hidden field if you so desire.

                 

                public List<ApproveLeaveModel> getPersonalList(String username) {

                        List<ApproveLeaveModel> approvalList = new ArrayList<ApproveLeaveModel>();

                        List<Task> personalTaskList = taskService.findPersonalTasks(username);  // finds personal tasks alloted to a user.

                       

                        for(Task t : personalTaskList){

                            String tId = t.getId();

                            Set<String> variableNames = taskService.getVariableNames(tId);

                            Map<String,Object> variables = taskService.getVariables(tId, variableNames);

                            Integer reqId= (Integer)variables.get("requestId");

                            String requestId = reqId.toString();

                            if(requestId!=null){

                                ApproveLeaveModel alm  = leaveModuleDao.getLeaveRequestbyId(requestId);

                                alm.setTaskId(tId);

                                approvalList.add(alm);

                            }

                        }

                        return approvalList;

                    }

                • 5. How to use task and state in jbpm 4.4
                  Ayusman Dikshit Newbie

                  Thanks a lot Samrat.

                  This really helps. :-)