コード例 #1
0
  /**
   * Parse Json Response from Alfresco REST API to create a process Definition Object.
   *
   * @param json : json response that contains data from the repository
   * @return ProcessDefinition Object
   */
  @SuppressWarnings("unchecked")
  public static Process parseJson(Map<String, Object> json) {
    ProcessImpl process = new ProcessImpl();

    // Public Properties
    process.identifier = JSONConverter.getString(json, OnPremiseConstant.ID_VALUE);
    String definitionIdentifier =
        JSONConverter.getString(json, OnPremiseConstant.DEFINITIONURL_VALUE);
    process.definitionIdentifier = definitionIdentifier.replace(SUFFIX_WORKFLOW_DEFINITION, "");
    process.key = JSONConverter.getString(json, OnPremiseConstant.NAME_VALUE);
    process.name = JSONConverter.getString(json, OnPremiseConstant.TITLE_VALUE);
    process.priority = JSONConverter.getInteger(json, OnPremiseConstant.PRIORITY_VALUE).intValue();
    process.description = JSONConverter.getString(json, OnPremiseConstant.MESSAGE_VALUE);

    // PARSE DATES
    String date = JSONConverter.getString(json, OnPremiseConstant.STARTDATE_VALUE);
    GregorianCalendar g = new GregorianCalendar();
    SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.FORMAT_3, Locale.getDefault());
    if (date != null) {
      g.setTime(DateUtils.parseDate(date, sdf));
      process.startedAt = g;
    }

    date = JSONConverter.getString(json, OnPremiseConstant.ENDDATE_VALUE);
    if (date != null) {
      g = new GregorianCalendar();
      g.setTime(DateUtils.parseDate(date, sdf));
      process.endedAt = g;
    }

    // PARSE INITIATOR
    Map<String, Object> initiator =
        (Map<String, Object>) json.get(OnPremiseConstant.INITIATOR_VALUE);
    Person p = PersonImpl.parseJson(initiator);
    process.initiatorIdentifier = p.getIdentifier();

    // EXTRA PROPERTIES
    process.data = new HashMap<String, Serializable>();
    process.data.put(OnPremiseConstant.INITIATOR_VALUE, p);

    date = JSONConverter.getString(json, OnPremiseConstant.DUEDATE_VALUE);
    if (date != null) {
      g = new GregorianCalendar();
      g.setTime(DateUtils.parseDate(date, sdf));
      process.dueAt = g;
    }
    process.data.put(OnPremiseConstant.DUEDATE_VALUE, g);

    process.data.put(
        OnPremiseConstant.DESCRIPTION_VALUE,
        JSONConverter.getString(json, OnPremiseConstant.DESCRIPTION_VALUE));
    process.data.put(
        OnPremiseConstant.ISACTIVE_VALUE,
        JSONConverter.getBoolean(json, OnPremiseConstant.ISACTIVE_VALUE));

    process.hasAllVariables = true;

    return process;
  }
コード例 #2
0
  public static Process parsePublicAPIJson(Map<String, Object> json) {
    ProcessImpl process = new ProcessImpl();

    process.identifier = JSONConverter.getString(json, PublicAPIConstant.ID_VALUE);
    process.definitionIdentifier =
        JSONConverter.getString(json, PublicAPIConstant.PROCESSDEFINITIONID_VALUE);
    process.key = JSONConverter.getString(json, PublicAPIConstant.PROCESSDEFINITIONKEY_VALUE);
    process.initiatorIdentifier =
        JSONConverter.getString(json, PublicAPIConstant.STARTUSERID_VALUE);

    GregorianCalendar g = new GregorianCalendar();
    SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.FORMAT_3, Locale.getDefault());

    String startedAt = JSONConverter.getString(json, PublicAPIConstant.STARTEDAT_VALUE);
    if (startedAt != null) {
      g.setTime(DateUtils.parseDate(startedAt, sdf));
      process.startedAt = g;
    }

    String endedAt = JSONConverter.getString(json, PublicAPIConstant.ENDEDAT_VALUE);
    if (endedAt != null) {
      g = new GregorianCalendar();
      g.setTime(DateUtils.parseDate(endedAt, sdf));
      process.endedAt = g;
    }

    process.hasAllVariables = false;

    // EXTRA PROPERTIES
    process.data = new HashMap<String, Serializable>();
    if (json.containsKey(PublicAPIConstant.DURATIONINMS_VALUE)) {
      process.data.put(
          PublicAPIConstant.DURATIONINMS_VALUE,
          JSONConverter.getInteger(json, PublicAPIConstant.DURATIONINMS_VALUE).intValue());
    }
    process.data.put(
        PublicAPIConstant.STARTACTIVITYID_VALUE,
        JSONConverter.getString(json, PublicAPIConstant.STARTACTIVITYID_VALUE));
    process.data.put(
        PublicAPIConstant.ENDACTIVITYID_VALUE,
        JSONConverter.getString(json, PublicAPIConstant.ENDACTIVITYID_VALUE));
    process.data.put(
        PublicAPIConstant.COMPLETED_VALUE,
        JSONConverter.getBoolean(json, PublicAPIConstant.COMPLETED_VALUE));
    process.data.put(
        PublicAPIConstant.DELETEREASON_VALUE,
        JSONConverter.getString(json, PublicAPIConstant.DELETEREASON_VALUE));

    if (json.containsKey(PublicAPIConstant.PROCESSVARIABLES_VALUE)) {
      ArrayList<Map<String, Object>> jo =
          (ArrayList<Map<String, Object>>) json.get(PublicAPIConstant.PROCESSVARIABLES_VALUE);

      for (Map<String, Object> item : jo) {
        if (item.containsKey(PublicAPIConstant.NAME_VALUE)
            && PROP_WORKFLOW_PRIORITY_ENCODED.equals(item.get(PublicAPIConstant.NAME_VALUE))) {
          process.priority = JSONConverter.getInteger(item, PublicAPIConstant.VALUE).intValue();
        }

        if (item.containsKey(PublicAPIConstant.NAME_VALUE)
            && PROP_WORKFLOW_DESCRIPTION_ENCODED.equals(item.get(PublicAPIConstant.NAME_VALUE))) {
          process.description = JSONConverter.getString(item, PublicAPIConstant.VALUE);
        }

        if (item.containsKey(PublicAPIConstant.NAME_VALUE)
            && PROP_WORKFLOW_DUE_DATE_ENCODED.equals(item.get(PublicAPIConstant.NAME_VALUE))) {
          String dueDateValue = JSONConverter.getString(item, PublicAPIConstant.VALUE);
          if (dueDateValue != null) {
            g = new GregorianCalendar();
            g.setTime(DateUtils.parseDate(dueDateValue, sdf));
            process.dueAt = g;
          }
        }
      }

      process.hasAllVariables = true;
    }

    return process;
  }