-
1. How to use task and state in jbpm 4.4
whizkid.samrat May 10, 2011 4:44 AM (in response to ayusman_dikshit)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 May 10, 2011 5:11 AM (in response to whizkid.samrat)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
whizkid.samrat May 10, 2011 5:42 AM (in response to ayusman_dikshit)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
}
-
ApproverFlow.png 30.9 KB
-
-
4. How to use task and state in jbpm 4.4
whizkid.samrat May 10, 2011 5:54 AM (in response to whizkid.samrat)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 May 11, 2011 2:29 AM (in response to whizkid.samrat)Thanks a lot Samrat.
This really helps. :-)