Пример #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;
  }
Пример #2
0
  protected void storeToForm(WorkflowAssignment wfAssignment, Map properties, Map object) {
    String formDefId = (String) properties.get("formDefId");
    if (formDefId != null && formDefId.trim().length() > 0) {
      ApplicationContext ac = AppUtil.getApplicationContext();
      AppService appService = (AppService) ac.getBean("appService");
      AppDefinition appDef = (AppDefinition) properties.get("appDef");

      Object[] fieldMapping = (Object[]) properties.get("fieldMapping");
      String multirowBaseObjectName = (String) properties.get("multirowBaseObject");

      FormRowSet rowSet = new FormRowSet();

      if (multirowBaseObjectName != null && multirowBaseObjectName.trim().length() > 0) {
        Object[] baseObjectArray = (Object[]) getObjectFromMap(multirowBaseObjectName, object);
        if (baseObjectArray != null && baseObjectArray.length > 0) {
          rowSet.setMultiRow(true);
          for (int i = 0; i < baseObjectArray.length; i++) {
            rowSet.add(getRow(wfAssignment, multirowBaseObjectName, i, fieldMapping, object));
          }
        }
      } else {
        rowSet.add(getRow(wfAssignment, null, null, fieldMapping, object));
      }

      if (rowSet.size() > 0) {
        appService.storeFormData(
            appDef.getId(), appDef.getVersion().toString(), formDefId, rowSet, null);
      }
    }
  }
Пример #3
0
  @Override
  public FormRowSet formatData(FormData formData) {
    FormRowSet rowSet = null;

    // get value
    String id = getPropertyString(FormUtil.PROPERTY_ID);
    if (id != null) {
      String[] values = FormUtil.getElementPropertyValues(this, formData);
      if (values != null && values.length > 0) {
        // check for empty submission via parameter
        String[] paramValues = FormUtil.getRequestParameterValues(this, formData);
        if ((paramValues == null || paramValues.length == 0)
            && FormUtil.isFormSubmitted(this, formData)) {
          values = new String[] {""};
        }

        // formulate values
        String delimitedValue = FormUtil.generateElementPropertyValues(values);

        // set value into Properties and FormRowSet object
        FormRow result = new FormRow();
        result.setProperty(id, delimitedValue);
        rowSet = new FormRowSet();
        rowSet.add(result);
      }
    }

    return rowSet;
  }
Пример #4
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;
  }