Exemplo n.º 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;
  }
Exemplo n.º 2
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;
  }