示例#1
0
  public JSONObject getParseData() {
    JSONObject parseData = new JSONObject();

    for (String key : operations.keySet()) {
      ParseFieldOperation operation = (ParseFieldOperation) operations.get(key);
      if (operation instanceof SetFieldOperation) {
        parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
      } else if (operation instanceof IncrementFieldOperation) {
        parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
      } else if (operation instanceof DeleteFieldOperation) {
        parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
      } else if (operation instanceof RelationOperation) {
        parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
      } else {
        // here we deal will sub objects like ParseObject;
        Object obj = data.get(key);
        if (obj instanceof ParseObject) {
          ParseObject pob = (ParseObject) obj;
          parseData.put(key, pob.getParseData());
        }
      }
    }

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("parseData-> " + parseData);
    }

    return parseData;
  }
示例#2
0
  public JSONObject toREST() {
    JSONObject params = new JSONObject();
    try {
      params.put("className", this.className);

      if (this.where.size() > 0) {
        params.put("where", ParseEncoder.encode(this.where, PointerEncodingStrategy.get()));
      }

      if (this.limit >= 0) {
        params.put("limit", this.limit);
      }

      if (this.skip > 0) {
        params.put("skip", this.skip);
      }

      if (this.order != null) {
        params.put("order", this.order);
      }

      if (!this.include.isEmpty()) {
        params.put("include", Parse.join(this.include, ","));
      }

      if (this.selectedKeys != null) {
        params.put("keys", Parse.join(this.selectedKeys, ","));
      }

      if (this.trace) {
        params.put("trace", "1");
      }

      for (String key : this.extraOptions.keySet())
        params.put(
            key, ParseEncoder.encode(this.extraOptions.get(key), PointerEncodingStrategy.get()));

    } catch (JSONException e) {
      LOGGER.error("Error parsing json", e);
      throw new RuntimeException(e);
    }

    return params;
  }