/** * 跳转到任务执行页面 * * @param request * @return */ @RequestMapping(value = "/form.do") public String from( HttpServletRequest request, @RequestParam("taskId") String taskId, Model model) { List<Task> taskList = taskService.createTaskQuery().taskId(taskId).list(); Task task = taskList.get(0); // 获取表单数据 TaskFormData tfd = formService.getTaskFormData(taskId); List<FormProperty> fpList = tfd.getFormProperties(); Map map = runtimeService.getVariables(task.getExecutionId()); List<ActivityImpl> activityList = new ArrayList<ActivityImpl>(); try { // 查找所有可驳回的节点 activityList = processExtensionService.findBackActivity(taskId); // model.addAttribute("activityList",activityList); } catch (Exception e) { e.printStackTrace(); } // model.addAttribute("task",task); // model.addAttribute("fpList",fpList); // model.addAttribute("map",map); // model.addAttribute("taskId",taskId); request.setAttribute("task", task); request.setAttribute("fpList", fpList); request.setAttribute("map", map); request.setAttribute("taskId", taskId); request.setAttribute("activityList", activityList); return "/simple/form"; }
/** * 完成任务页面 * * @return */ public String prepareCompleteTask() { TaskService taskService = processEngine.getTaskService(); FormService formService = processEngine.getFormService(); taskFormData = formService.getTaskFormData(taskId); return "prepareCompleteTask"; }
@Test public void testBankTransferValidation() { TaskService taskService = processEngine.getTaskService(); FormService formService = processEngine.getFormService(); List<Task> tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); // Invalid bank data for (Task task : tasks) { assertNotNull(task); assertEquals("get bank transfer data", task.getName()); Map<String, String> formData = new HashMap<String, String>(); formData.put("bankName", "Bank austria"); // invalid bank-name formData.put("bankCode", "12000"); formData.put("accountNumber", "12345678901"); formData.put("holdersName", "Max Muster"); formService.submitTaskFormData(task.getId(), formData); } tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); // As of an error the form should be empty assertEquals(0, formService.getTaskFormData(tasks.get(0).getId()).getFormProperties().size()); // Valid bank data for (Task task : tasks) { assertNotNull(task); assertEquals("get bank transfer data", task.getName()); Map<String, String> formData = new HashMap<String, String>(); formData.put("bankName", "Bank Austria"); formData.put("bankCode", "12000"); formData.put("accountNumber", "12345678901"); formData.put("holdersName", "Max Muster"); formService.submitTaskFormData(task.getId(), formData); // Stack trace starts here } tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); assertEquals("get acknowledgement", tasks.get(0).getName()); }
@RequestMapping(value = "/complete-task/{taskId}") public String completeTask(@PathVariable String taskId, HttpServletRequest request) { TaskFormData taskFormData = formService.getTaskFormData(taskId); boolean hasFormKey = taskFormData.getFormKey() != null && taskFormData.getFormKey().length() > 0; List<FormProperty> formProperties = taskFormData.getFormProperties(); Map<String, String> formValues = generateFormValueMap(hasFormKey, formProperties, request); // 生成提交数据 formService.submitTaskFormData(taskId, formValues); return "redirect:/identity/user"; }
@RequestMapping(value = "/do-task/{taskId}") public ModelAndView doTask(@PathVariable String taskId) { ModelAndView mav = new ModelAndView("workflow/task-form"); Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); TaskFormData taskFormData = formService.getTaskFormData(taskId); boolean hasFormKey = taskFormData.getFormKey() != null && taskFormData.getFormKey().length() > 0; mav.addObject("task", task); mav.addObject("hasFormKey", hasFormKey); if (task.getFormKey() != null) { Object renderFormData = formService.getRenderedTaskForm(taskId); mav.addObject("taskFormData", renderFormData); } else { mav.addObject("taskFormData", taskFormData); } return mav; }
/** * 完成任务 * * @return */ public String completeTask() { HttpServletRequest request = ServletActionContext.getRequest(); IdentityService identityService = processEngine.getIdentityService(); identityService.setAuthenticatedUserId(SpringSecurityUtils.getCurrentUsername()); FormService formService = processEngine.getFormService(); TaskFormData taskFormData = formService.getTaskFormData(taskId); Map<String, String> map = new HashMap<String, String>(); for (FormProperty formProperty : taskFormData.getFormProperties()) { if (formProperty.isWritable()) { String name = formProperty.getId(); map.put(name, request.getParameter(name)); } } formService.submitTaskFormData(taskId, map); return RELOAD; }