예제 #1
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;
  }
  @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;
  }