Exemple #1
0
  public Object execute(Map properties) {
    WorkflowAssignment wfAssignment = (WorkflowAssignment) properties.get("workflowAssignment");

    String jsonUrl = (String) properties.get("jsonUrl");
    GetMethod get = null;
    try {
      HttpClient client = new HttpClient();

      jsonUrl = WorkflowUtil.processVariable(jsonUrl, "", wfAssignment);

      jsonUrl = StringUtil.encodeUrlParam(jsonUrl);

      get = new GetMethod(jsonUrl);
      client.executeMethod(get);
      InputStream in = get.getResponseBodyAsStream();
      String jsonResponse = streamToString(in);

      Map object = PropertyUtil.getPropertiesValueFromJson(jsonResponse);

      storeToForm(wfAssignment, properties, object);
      storeToWorkflowVariable(wfAssignment, properties, object);

    } catch (Exception ex) {
      LogUtil.error(getClass().getName(), ex, "");
    } finally {
      if (get != null) {
        get.releaseConnection();
      }
    }

    return null;
  }
Exemple #2
0
  @Override
  public FormRowSet store(Element element, FormRowSet rows, FormData formData) {
    FormRowSet result = rows;
    if (rows != null && !rows.isEmpty()) {
      // store form data to DB
      result = super.store(element, rows, formData);

      // handle workflow variables
      if (!rows.isMultiRow()) {
        String activityId = formData.getActivityId();
        String processId = formData.getProcessId();
        if (activityId != null || processId != null) {
          WorkflowManager workflowManager =
              (WorkflowManager) WorkflowUtil.getApplicationContext().getBean("workflowManager");

          // recursively find element(s) mapped to workflow variable
          FormRow row = rows.iterator().next();
          Map<String, String> variableMap = new HashMap<String, String>();
          variableMap = storeWorkflowVariables(element, row, variableMap);

          if (activityId != null) {
            workflowManager.activityVariables(activityId, variableMap);
          } else {
            workflowManager.processVariables(processId, variableMap);
          }
        }
      }
    }
    return result;
  }
  /**
   * Returns the URL to the workflow web designer
   *
   * @param request
   * @return
   */
  public static String getDesignerWebBaseUrl() {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
    String designerwebBaseUrl =
        (request != null)
            ? request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            : "";
    if (WorkflowUtil.getSystemSetupValue("designerwebBaseUrl") != null
        && WorkflowUtil.getSystemSetupValue("designerwebBaseUrl").length() > 0) {
      designerwebBaseUrl = WorkflowUtil.getSystemSetupValue("designerwebBaseUrl");
    }
    if (designerwebBaseUrl.endsWith("/")) {
      designerwebBaseUrl = designerwebBaseUrl.substring(0, designerwebBaseUrl.length() - 1);
    }

    return designerwebBaseUrl;
  }
 protected String loginPageRedirection() {
   boolean isAnonymous = WorkflowUtil.isCurrentUserAnonymous();
   boolean hasCurrentPage = userview.getCurrent() != null;
   if ((!isAuthorized || !hasCurrentPage) && isAnonymous) {
     return "redirect:"
         + getLoginLink()
         + (request.getQueryString() == null
             ? ""
             : ("?" + StringUtil.decodeURL(request.getQueryString())));
   }
   return null;
 }
Exemple #5
0
  protected FormRow getRow(
      WorkflowAssignment wfAssignment,
      String multirowBaseObjectName,
      Integer rowNumber,
      Object[] fieldMapping,
      Map object) {
    FormRow row = new FormRow();

    for (Object o : fieldMapping) {
      Map mapping = (HashMap) o;
      String fieldName = mapping.get("field").toString();
      String jsonObjectName =
          WorkflowUtil.processVariable(
              mapping.get("jsonObjectName").toString(), null, wfAssignment, null, null);

      if (multirowBaseObjectName != null) {
        jsonObjectName =
            jsonObjectName.replace(
                multirowBaseObjectName, multirowBaseObjectName + "[" + rowNumber + "]");
      }

      String value = (String) getObjectFromMap(jsonObjectName, object);

      if (value == null) {
        value = jsonObjectName;
      }

      if (FormUtil.PROPERTY_ID.equals(fieldName)) {
        row.setId(value);
      } else {
        row.put(fieldName, value);
      }
    }

    if (row.getId() == null || (row.getId() != null && row.getId().trim().length() == 0)) {
      if (multirowBaseObjectName == null) {
        row.setId(wfAssignment.getProcessId());
      } else {
        row.setId(UuidGenerator.getInstance().getUuid());
      }
    }

    Date currentDate = new Date();
    row.setDateModified(currentDate);
    row.setDateCreated(currentDate);

    return row;
  }
Exemple #6
0
  @Override
  public String getJspPage() {
    try {
      // get data list
      DataList dataList = getDataList();

      if (dataList != null) {
        // overide datalist result to use userview result
        DataListActionResult ac = dataList.getActionResult();
        if (ac != null) {
          if (ac.getMessage() != null && !ac.getMessage().isEmpty()) {
            setAlertMessage(ac.getMessage());
          }
          if (ac.getType() != null
              && DataListActionResult.TYPE_REDIRECT.equals(ac.getType())
              && ac.getUrl() != null
              && !ac.getUrl().isEmpty()) {
            if ("REFERER".equals(ac.getUrl())) {
              HttpServletRequest request = WorkflowUtil.getHttpServletRequest();
              if (request != null && request.getHeader("Referer") != null) {
                setRedirectUrl(request.getHeader("Referer"));
              } else {
                setRedirectUrl("REFERER");
              }
            } else {
              setRedirectUrl(ac.getUrl());
            }
          }
        }

        // set data list
        setProperty("dataList", dataList);
      } else {
        setProperty("error", "Data List \"" + getPropertyString("datalistId") + "\" not exist.");
      }
    } catch (Exception ex) {
      StringWriter out = new StringWriter();
      ex.printStackTrace(new PrintWriter(out));
      String message = ex.toString();
      message += "\r\n<pre class=\"stacktrace\">" + out.getBuffer() + "</pre>";
      setProperty("error", message);
    }
    return "userview/plugin/datalist.jsp";
  }
Exemple #7
0
  @Override
  public FormRowSet load(Element element, String primaryKey, FormData formData) {
    // load form data from DB
    FormRowSet rows = super.load(element, primaryKey, formData);
    if (rows != null) {
      // handle workflow variables
      String activityId = formData.getActivityId();
      String processId = formData.getProcessId();
      WorkflowManager workflowManager =
          (WorkflowManager) WorkflowUtil.getApplicationContext().getBean("workflowManager");
      Collection<WorkflowVariable> variableList = null;
      if (activityId != null && !activityId.isEmpty()) {
        variableList = workflowManager.getActivityVariableList(activityId);
      } else if (processId != null && !processId.isEmpty()) {
        variableList = workflowManager.getProcessVariableList(processId);
      } else {
        variableList = new ArrayList<WorkflowVariable>();
      }

      if (variableList != null && !variableList.isEmpty()) {
        FormRow row = null;
        if (rows.isEmpty()) {
          row = new FormRow();
          rows.add(row);
        } else {
          row = rows.iterator().next();
        }

        Map<String, String> variableMap = new HashMap<String, String>();
        for (WorkflowVariable variable : variableList) {
          Object val = variable.getVal();
          if (val != null) {
            variableMap.put(variable.getId(), val.toString());
          }
        }
        loadWorkflowVariables(element, row, variableMap);
      }
    }
    return rows;
  }
  protected String loginRedirection() {
    boolean isAnonymous = WorkflowUtil.isCurrentUserAnonymous();
    if (!isAnonymous) {
      String url = getBaseLink();
      String menuId = userview.getParamString("menuId");
      // check current redirect url is exist, else redirect to home
      boolean isExist = false;
      if (menuId != null && !menuId.isEmpty()) {
        for (UserviewCategory c : userview.getCategories()) {
          for (UserviewMenu m : c.getMenus()) {
            if (menuId.equals(m.getPropertyString("id"))
                || menuId.equals(m.getPropertyString("customId"))) {
              isExist = true;
              break;
            }
          }
          if (isExist) {
            break;
          }
        }
      }
      if (isExist) {
        if (!userview.getParamString("menuId").isEmpty()) {
          url += menuId;
        }
        if (request.getQueryString() != null) {
          url += "?" + request.getQueryString();
        }
      } else {
        url += userview.getProperty("homeMenuId");
      }

      return "redirect:" + url;
    }
    return null;
  }
 /**
  * Convenience method to retrieve the current request context path
  *
  * @return
  */
 public static String getRequestContextPath() {
   HttpServletRequest request = WorkflowUtil.getHttpServletRequest();
   String url = (request != null) ? request.getContextPath() : "";
   return url;
 }
  @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";
      }
    }
  }
  @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";
  }
  public String getHtml() {
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("params", userview.getParams());
    data.put("userview", userview);
    data.put("is_login_page", isLoginPage);
    if (isLoginPage) {
      data.put("login_form_footer", DirectoryUtil.getLoginFormFooter());

      if (request.getSession() != null) {
        Throwable exception =
            (Throwable) request.getSession().getAttribute("SPRING_SECURITY_LAST_EXCEPTION");
        if (exception != null) {
          data.put("login_exception", exception.getMessage());
        }
      }
      data.put("login_error_classes", "form-errors alert alert-warning");
    }
    data.put("context_path", request.getContextPath());
    data.put("build_number", ResourceBundleUtil.getMessage("build.number"));
    String rightToLeft = WorkflowUtil.getSystemSetupValue("rightToLeft");
    data.put("right_to_left", "true".equalsIgnoreCase(rightToLeft));
    String locale = AppUtil.getAppLocale();
    data.put("locale", locale);
    data.put("embed", "true".equalsIgnoreCase(userview.getParamString("embed")));
    data.put("body_id", getBodyId());
    data.put("body_classes", getBodyClasses(rightToLeft, locale));
    data.put("base_link", request.getContextPath() + getBaseLink());
    data.put("home_page_link", request.getContextPath() + getHomePageLink());
    data.put("title", getTitle());
    data.put("hide_nav", false);
    data.put("nav_id", "navigation");
    data.put("nav_classes", "nav-collapse sidebar-nav");
    data.put("categories_container_id", "category-container");
    data.put("categories_container_classes", "nav nav-tabs nav-stacked main-menu");
    data.put("category_classes", "category");
    data.put("first_category_classes", "first");
    data.put("last_category_classes", "last");
    data.put("current_category_classes", "current-category active");
    data.put("combine_single_menu_category", false);
    data.put("menus_container_classes", "menu-container");
    data.put("menu_classes", "menu");
    data.put("first_menu_classes", "first");
    data.put("last_menu_classes", "last");
    data.put("current_menu_classes", "current active");
    data.put("main_container_id", "main");
    data.put("sidebar_id", "sidebar");
    data.put("content_id", "content");

    String username = WorkflowUtil.getCurrentUsername();
    boolean isLoggedIn = username != null && !WorkflowUserManager.ROLE_ANONYMOUS.equals(username);
    data.put("is_logged_in", isLoggedIn);
    if (isLoggedIn) {
      ExtDirectoryManager directoryManager =
          (ExtDirectoryManager) AppUtil.getApplicationContext().getBean("directoryManager");
      User user = directoryManager.getUserByUsername(username);
      data.put("username", username);
      data.put("user", user);
      data.put("logout_link", request.getContextPath() + "/j_spring_security_logout");
    } else {
      data.put("login_link", request.getContextPath() + getLoginLink());
    }

    data.put("content", getContent(data));

    String handleMenuResponse = handleMenuResponse();
    if (handleMenuResponse != null) {
      return handleMenuResponse;
    }

    data.put("metas", getMetas(data));
    data.put("joget_header", getJogetHeader());
    data.put("js_css_lib", getJsCssLib(data));
    data.put("fav_icon_link", getFavIconLink(data));
    data.put("js", getJs(data));
    data.put("css", getCss(data));
    data.put("head", getHead(data));
    if (!"true".equalsIgnoreCase(userview.getParamString("embed"))) {
      data.put("header", getHeader(data));
      if (isAuthorized) {
        data.put("menus", getMenus(data));
      }
      data.put("footer", getFooter(data));
    }
    data.put("joget_footer", getJogetFooter());
    data.put("content_container", getContentContainer(data));

    return getLayout(data);
  }