@Test
  public void testAcknowledgement() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get acknowledgement", tasks.get(0).getName());

    for (Task task : tasks) {
      Map<String, String> formData = new HashMap<String, String>();
      formService.submitTaskFormData(task.getId(), formData); // Stack trace starts here
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(0, tasks.size());
  }
Пример #2
0
  /**
   * 发起流程页面(启动一个流程实例)内置流程表单方式
   *
   * @return
   */
  public String prepareStartProcessInstance() {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    FormService formService = processEngine.getFormService();
    startFormData = formService.getStartFormData(processDefinitionId);

    return "prepareStartProcessInstance";
  }
  @Test
  public void testCouponValidation() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());

    /** Invalid coupon hash */
    for (Task task : tasks) {
      assertNotNull(task);
      assertEquals("get coupon", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("hash", "abc");
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());

    /** Valid coupon hash */
    for (Task task : tasks) {
      assertNotNull(task);
      assertEquals("get coupon", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("hash", "abcd");
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    // check if the price was reduced correctly
    Object price = runtimeService.getVariable(processInstance.getId(), "price");
    assertNotNull(price);
    assertEquals(new Double(130), price);

    // 'get bank transfer data' should be next on the list
    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get bank transfer data", tasks.get(0).getName());
  }
Пример #4
0
  /**
   * 完成任务页面
   *
   * @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";
 }
  @Test
  public void testRemindCustomer() {
    createNewProcess();
    runtimeService.setVariable(pid, "RemainderAmount", "0");
    Task nextTask = taskService.createTaskQuery().singleResult();
    HashMap<String, String> map = new HashMap<String, String>();
    formService.submitTaskFormData(nextTask.getId(), map);

    Task nextTask2 = taskService.createTaskQuery().singleResult();
    formService.submitTaskFormData(nextTask2.getId(), map);

    Task nextTask3 = taskService.createTaskQuery().singleResult();
    formService.submitTaskFormData(nextTask3.getId(), map);

    Task lastTasks = taskService.createTaskQuery().singleResult();
  }
 @Test
 public void testMail() {
   createNewProcess();
   Task nextTask = taskService.createTaskQuery().singleResult();
   HashMap<String, String> map = new HashMap<String, String>();
   formService.submitTaskFormData(nextTask.getId(), map);
 }
  /**
   * 跳转到任务执行页面
   *
   * @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";
  }
 @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;
 }
Пример #11
0
  /**
   * 发起流程
   *
   * @return
   */
  public String startProcessInstance() {
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(SpringSecurityUtils.getCurrentUsername());

    FormService formService = processEngine.getFormService();
    StartFormData startFormData = formService.getStartFormData(processDefinitionId);
    HttpServletRequest request = ServletActionContext.getRequest();
    Map<String, String> map = new HashMap<String, String>();

    for (FormProperty formProperty : startFormData.getFormProperties()) {
      String name = formProperty.getId();
      map.put(name, request.getParameter(name));
    }

    formService.submitStartFormData(processDefinitionId, map);

    return RELOAD;
  }
Пример #12
0
  /**
   * 完成任务
   *
   * @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;
  }
  @RequestMapping(value = "/start-process-instance/{processDefinitionId}")
  public String startProcessInstance(
      @PathVariable String processDefinitionId, HttpSession session, HttpServletRequest request) {
    String url = "";
    Object obj = session.getAttribute(SessionVar.AUTHENTICATED_USER);
    if (obj != null) {
      User user = (User) obj;
      // identityService.setAuthenticatedUserId(user.getId());//登录时已经执行过,20150905测试代码:有时StartUserID=null,导致任务无法继续处理
      System.out.println("注意观察StartUserID=空的情况,会导致任务无法处理");
      StartFormData formData = formService.getStartFormData(processDefinitionId);
      List<FormProperty> formProperties = formData.getFormProperties();
      boolean hasFormKey = formData.getFormKey() != null && formData.getFormKey().length() > 0;
      Map<String, String> formValues = generateFormValueMap(hasFormKey, formProperties, request);
      formService.submitStartFormData(processDefinitionId, formValues); // 生成提交数据

      url = "redirect:/workflow/process-list";
    } else {
      System.out.println("当前没有登陆的用户");
      url = "redirect:/identity/user";
    }
    return url;
  }
  @Test
  public void testPaymentModality() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(2, tasks.size());
    List<String> expected = new ArrayList<String>();
    expected.add("get payment modalities");
    expected.add("get coupon");
    assertTrue(expected.contains(tasks.get(0).getName()));
    assertTrue(expected.contains(tasks.get(1).getName()));

    for (Task task : tasks) {
      assertNotNull(task);
      if (task.getName().equals("get payment modalities")) {
        Map<String, String> formData = new HashMap<String, String>();
        formData.put("paymentMethod", "bankTransferMethod");
        formService.submitTaskFormData(task.getId(), formData);

        break;
      }
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get coupon", tasks.get(0).getName());
  }
 @RequestMapping(value = "/start-process/{processDefinitionId}")
 public ModelAndView readStartForm(
     @PathVariable("processDefinitionId") String processDefinitionId) {
   ProcessDefinition processDefinition =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionId(processDefinitionId)
           .singleResult();
   boolean hasStartFormKey = processDefinition.hasStartFormKey();
   ModelAndView mav = new ModelAndView("workflow/start-process-form");
   // 根据是否有formkey属性判断使用哪个展示层
   // 判断是否有formkey属性
   if (hasStartFormKey) {
     Object renderedStartForm = formService.getRenderedStartForm(processDefinitionId);
     mav.addObject("startFormData", renderedStartForm);
   } else { // 动态表单字段
     StartFormData startFormData = formService.getStartFormData(processDefinitionId);
     mav.addObject("startFormData", startFormData);
   }
   mav.addObject("processDefinition", processDefinition);
   mav.addObject("hasStartFormKey", hasStartFormKey);
   return mav;
 }
  @Test
  public void testAddressValidation() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    // Verify kermit can now retrieve the task
    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get address", tasks.get(0).getName());

    /** Invalid address */
    for (Task task : tasks) {
      assertEquals("get address", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("firstName", "Max");
      formData.put("lastName", "Muster");
      formData.put("street", "Mustergasse 2");
      formData.put("zip", "1080"); // wrong zip-code!
      formData.put("city", "Wien");
      formData.put("country", "Austria");
      formData.put("telNo", "1234567");
      formData.put("mailAddress", this.yourEMail);
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    // There should only be one task available at this stage
    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get address", tasks.get(0).getName());

    /** Valid address */
    for (Task task : tasks) {
      assertEquals("get address", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("firstName", "Max");
      formData.put("lastName", "Muster");
      formData.put("street", "Mustergasse 2");
      formData.put("zip", "1090");
      formData.put("city", "Wien");
      formData.put("country", "Austria");
      formData.put("telNo", "1234567");
      formData.put("mailAddress", this.yourEMail);
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    // check if the customer was set correctly
    Customer customer = (Customer) runtimeService.getVariable(processInstance.getId(), "customer");
    assertNotNull(customer);
    assertEquals("Max", customer.getFirstName());
    assertEquals("Muster", customer.getLastName());
    assertEquals("Mustergasse 2", customer.getAddress().getStreet());

    // There should now be 2 tasks available
    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(2, tasks.size());
    List<String> expected = new ArrayList<String>();
    expected.add("get payment modalities");
    expected.add("get coupon");
    assertTrue(expected.contains(tasks.get(0).getName()));
    assertTrue(expected.contains(tasks.get(1).getName()));
  }