Esempio n. 1
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;
  }
Esempio n. 2
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;
  }