コード例 #1
0
  @RequestMapping("/client/app/(*:appId)/(~:version)/process/(*:processDefId)")
  public String clientProcessView(
      HttpServletRequest request,
      ModelMap model,
      @RequestParam("appId") String appId,
      @RequestParam(required = false) String version,
      @RequestParam String processDefId,
      @RequestParam(required = false) String recordId,
      @RequestParam(required = false) String start) {

    // clean process def
    processDefId = WorkflowUtil.getProcessDefIdWithoutVersion(processDefId);

    AppDefinition appDef = appService.getAppDefinition(appId, version);
    WorkflowProcess processDef =
        appService.getWorkflowProcessForApp(appId, appDef.getVersion().toString(), processDefId);

    // check for permission
    if (!workflowManager.isUserInWhiteList(processDef.getId())) {
      return "client/app/processUnauthorized";
    }

    // set app and process details
    model.addAttribute("appId", appId);
    model.addAttribute("appVersion", appDef.getVersion());
    model.addAttribute("appDefinition", appDef);
    model.addAttribute("process", processDef);
    model.addAttribute("queryString", request.getQueryString());

    // check for start mapped form
    FormData formData = new FormData();
    formData.setPrimaryKeyValue(recordId);
    String formUrl =
        "/web/client/app/"
            + appId
            + "/"
            + appDef.getVersion()
            + "/process/"
            + processDefId
            + "/start";
    if (recordId != null) {
      formUrl += "?recordId=" + recordId;
    }
    String formUrlWithContextPath = AppUtil.getRequestContextPath() + formUrl;
    PackageActivityForm startFormDef =
        appService.viewStartProcessForm(
            appId, appDef.getVersion().toString(), processDefId, formData, formUrlWithContextPath);
    if (startFormDef != null && startFormDef.getForm() != null) {
      Form startForm = startFormDef.getForm();

      // generate form HTML
      String formHtml = formService.retrieveFormHtml(startForm, formData);
      String formJson = formService.generateElementJson(startForm);

      // show form
      model.addAttribute("form", startForm);
      model.addAttribute("formJson", formJson);
      model.addAttribute("formHtml", formHtml);
      return "client/app/processFormStart";
    } else {
      if (Boolean.valueOf(start).booleanValue()) {
        // redirect to start URL
        return "redirect:" + formUrl;
      } else {
        // empty start page
        return "client/app/processStart";
      }
    }
  }
コード例 #2
0
  @RequestMapping("/client/app/(*:appId)/(~:version)/process/(*:processDefId)/start")
  public String clientProcessStart(
      HttpServletRequest request,
      ModelMap model,
      @RequestParam("appId") String appId,
      @RequestParam(required = false) String version,
      @RequestParam(required = false) String recordId,
      @RequestParam String processDefId) {

    // clean process def
    processDefId = WorkflowUtil.getProcessDefIdWithoutVersion(processDefId);

    // set app and process details
    AppDefinition appDef = appService.getAppDefinition(appId, version);
    WorkflowProcess processDef =
        appService.getWorkflowProcessForApp(appId, appDef.getVersion().toString(), processDefId);
    String processDefIdWithVersion = processDef.getId();
    model.addAttribute("appId", appId);
    model.addAttribute("appVersion", appDef.getVersion());
    model.addAttribute("appDefinition", appDef);
    model.addAttribute("process", processDef);

    // check for permission
    if (!workflowManager.isUserInWhiteList(processDef.getId())) {
      return "client/app/processUnauthorized";
    }

    // extract form values from request
    FormData formData = new FormData();
    formData.setPrimaryKeyValue(recordId);
    formData = formService.retrieveFormDataFromRequest(formData, request);

    // get workflow variables
    Map<String, String> variableMap = AppUtil.retrieveVariableDataFromRequest(request);
    String formUrl =
        AppUtil.getRequestContextPath()
            + "/web/client/app/"
            + appId
            + "/"
            + appDef.getVersion()
            + "/process/"
            + processDefId
            + "/start";
    if (recordId != null) {
      formUrl += "?recordId=" + recordId;
    }
    PackageActivityForm startFormDef =
        appService.viewStartProcessForm(
            appId, appDef.getVersion().toString(), processDefId, formData, formUrl);
    WorkflowProcessResult result =
        appService.submitFormToStartProcess(
            appId, version, processDefId, formData, variableMap, recordId, formUrl);
    if (startFormDef != null
        && (startFormDef.getForm() != null
            || PackageActivityForm.ACTIVITY_FORM_TYPE_EXTERNAL.equals(startFormDef.getType()))) {
      if (result == null) {
        // validation error, get form
        Form startForm = startFormDef.getForm();

        // generate form HTML
        String formHtml = formService.retrieveFormErrorHtml(startForm, formData);
        String formJson = formService.generateElementJson(startForm);

        // show form
        model.addAttribute("form", startForm);
        model.addAttribute("formJson", formJson);
        model.addAttribute("formHtml", formHtml);
        model.addAttribute("activityForm", startFormDef);
        return "client/app/processFormStart";
      }
    } else {
      // start process - TODO: handle process linking
      result =
          workflowManager.processStart(
              processDefIdWithVersion, null, variableMap, null, recordId, false);
    }

    // set result
    if (result != null) {
      WorkflowProcess process = result.getProcess();
      model.addAttribute("process", process);

      // redirect to next activity if available
      Collection<WorkflowActivity> activities = result.getActivities();
      if (activities != null && !activities.isEmpty()) {
        WorkflowActivity nextActivity = activities.iterator().next();
        String assignmentUrl =
            "/web/client/app/"
                + appId
                + "/"
                + appDef.getVersion()
                + "/assignment/"
                + nextActivity.getId()
                + "?"
                + request.getQueryString();
        return "redirect:" + assignmentUrl;
      }
    }

    return "client/app/processStarted";
  }