Package org.parse4j.command

Examples of org.parse4j.command.ParseResponse


   
    ParsePostCommand command = new ParsePostCommand(getClassName());
    JSONObject parseData = getParseData();
    parseData.put("password", password);
    command.setData(parseData);
    ParseResponse response = command.perform();
    if(!response.isFailed()) {
      JSONObject jsonResponse = response.getJsonObject();
      if (jsonResponse == null) {
        LOGGER.error("Empty response");
        throw response.getException();
      }
      try {
        setObjectId(jsonResponse.getString(ParseConstants.FIELD_OBJECT_ID));
        sessionToken = jsonResponse.getString(ParseConstants.FIELD_SESSION_TOKEN);
        String createdAt = jsonResponse.getString(ParseConstants.FIELD_CREATED_AT);
        setCreatedAt(Parse.parseDate(createdAt));
        setUpdatedAt(Parse.parseDate(createdAt));
      }catch (JSONException e) {
        LOGGER.error("Although Parse reports object successfully saved, the response was invalid.");
        throw new ParseException(
            ParseException.INVALID_JSON,
            "Although Parse reports object successfully saved, the response was invalid.",
            e);
      }
    }
    else {
      LOGGER.error("Request failed.");
      throw response.getException();
    }
   
  }
View Full Code Here


   
    ParseGetCommand command = new ParseGetCommand("login");
    command.addJson(false);
    command.put("username", username);
      command.put("password", password);
    ParseResponse response = command.perform();
    if(!response.isFailed()) {
      JSONObject jsonResponse = response.getJsonObject();
      if (jsonResponse == null) {
        LOGGER.error("Empty response.");
        throw response.getException();
      }
      try {
        ParseUser parseUser = new ParseUser();
        parseUser.setObjectId(jsonResponse.getString(ParseConstants.FIELD_OBJECT_ID));
        parseUser.setSessionToken(jsonResponse.getString(ParseConstants.FIELD_SESSION_TOKEN));
        String createdAt = jsonResponse.getString(ParseConstants.FIELD_CREATED_AT);
        String updatedAt = jsonResponse.getString(ParseConstants.FIELD_UPDATED_AT);
        parseUser.setCreatedAt(Parse.parseDate(createdAt));
        parseUser.setUpdatedAt(Parse.parseDate(updatedAt));
        jsonResponse.remove(ParseConstants.FIELD_OBJECT_ID);
        jsonResponse.remove(ParseConstants.FIELD_CREATED_AT);
        jsonResponse.remove(ParseConstants.FIELD_UPDATED_AT);
        jsonResponse.remove(ParseConstants.FIELD_SESSION_TOKEN);
        parseUser.setData(jsonResponse);
        return parseUser;
       
      }catch (JSONException e) {
        LOGGER.error("Although Parse reports object successfully saved, the response was invalid.");
        throw new ParseException(
            ParseException.INVALID_JSON,
            "Although Parse reports object successfully saved, the response was invalid.",
            e);
      }
    }
    else {
      LOGGER.error("Request failed.");
      throw response.getException();
    }
   
  }
View Full Code Here

    ParsePostCommand command = new ParsePostCommand("requestPasswordReset");
    JSONObject data = new JSONObject();
    data.put("email", email);
    command.setData(data);
    ParseResponse response = command.perform();
    if (!response.isFailed()) {
      JSONObject jsonResponse = response.getJsonObject();
      if (jsonResponse == null) {
        LOGGER.error("Empty response.");
        throw response.getException();
      }
    } else {
      LOGGER.error("Request failed.");
      throw response.getException();
    }

  }
View Full Code Here

      throws ParseException {

    T result = null;
    ParsePostCommand command = new ParsePostCommand("functions", name);
    command.setData(new JSONObject(params));
    ParseResponse response = command.perform();
   
    if(!response.isFailed()) {
      JSONObject jsonResponse = response.getJsonObject();
      result = (T) jsonResponse.get("result");
      return result;
    }
    else {
      LOGGER.debug("Request failed.");
      throw response.getException();
    }
   
  }
View Full Code Here

        if(dimensions != null && dimensions.size() > 0) {
          data.put("dimentions", ParseEncoder.encode(dimensions, null));
        }
        command.setData(data);
        try {
          ParseResponse response = command.perform();
          if (response.isFailed()) {
            throw response.getException();
          }
          else {
            System.out.println("done");
          }
        } catch (ParseException pe) {
View Full Code Here

        if(dimensions != null && dimensions.size() > 0) {
          data.put("dimentions", ParseEncoder.encode(dimensions, null));
        }
        command.setData(data);
        try {
          ParseResponse response = command.perform();
          if (response.isFailed()) {
            throw response.getException();
          }
          else {
            System.out.println("done");
          }
        } catch (ParseException pe) {
View Full Code Here

      command.setContentType(contentType);
    }
    else {
      command.setContentType(getContentType());
    }
    ParseResponse response = command.perform();
    if(!response.isFailed()) {
      JSONObject jsonResponse = response.getJsonObject();
      System.out.println(jsonResponse);
      if (jsonResponse == null) {
        LOGGER.error("Empty response.");
        throw response.getException();
      }
     
      this.name = jsonResponse.getString("name");
      this.url = jsonResponse.getString("url");
      this.dirty = false;
      this.uplodated = true;
     
    }
    else {
      LOGGER.error("Request failed.");
      throw response.getException();
    }

  }
View Full Code Here

    }

    ParseGetCommand command = new ParseGetCommand(endPoint);
    query.remove("className");
    command.setData(query);
    ParseResponse response = command.perform();
    List<T> results = null;
    if(!response.isFailed()) {
      if(response.getJsonObject() == null) {
        LOGGER.debug("Empty response.");
        throw response.getException();
      }
      try {
        JSONObject json = response.getJsonObject();
        JSONArray objs = json.getJSONArray("results");
        if(objs.length() == 0) {
          return null;
        }
       
        if(trace) {
          strTrace = json.getString("trace");
          if(LOGGER.isDebugEnabled()) {
            LOGGER.debug(strTrace);
          }
        }
       
        results = new ArrayList<T>();
        for(int i = 0; i < objs.length(); i++) {
          Class<?> clazz = ParseRegistry.getParseClass(getClassName());
          if(clazz != null) {
            T po = (T) clazz.newInstance();
            JSONObject obj = (JSONObject) objs.get(i);
            
            /*
            We disable some checks while setting data in objects during fetch because
            those checks are useful only when setting data from client
            code. The "true" argument disables such checks.
            */
            po.setData(obj, true);
            results.add((T) po);
          }
          else {
            ParseObject po = new ParseObject(getClassName());
            JSONObject obj = (JSONObject) objs.get(i);
            // see above for the "true" argument
            po.setData(obj, true);
            results.add((T) po);
          }
        }

        return results;
      }
      catch (JSONException e) {
        LOGGER.error(
            "Although Parse reports object successfully saved, the response was invalid.",
            e);
        throw new ParseException(
            ParseException.INVALID_JSON,
            "Although Parse reports object successfully saved, the response was invalid.",
            e);
      } catch (InstantiationException e) {
        LOGGER.error("Error while instantiating class. Did you register your subclass?", e);
        throw new ParseException(
          ParseException.INVALID_JSON,
          "Although Parse reports object successfully saved, the response was invalid.",
          e);
      } catch (IllegalAccessException e) {
        LOGGER.error("Error while instantiating class. Did you register your subclass?",e);
        throw new ParseException(
          ParseException.INVALID_JSON,
          "Although Parse reports object successfully saved, the response was invalid.",
          e);
      }
    }
    else {
      LOGGER.debug("Request failed.");
      throw response.getException();
    }
  }
View Full Code Here

    JSONObject query = toREST();
    query.put("count", 1);
    query.put("limit", 0);
    query.remove("className");
    command.setData(query);
    ParseResponse response = command.perform();
    if(!response.isFailed()) {
      if(response.getJsonObject() == null) {
        LOGGER.debug("Empty response.");
        throw response.getException();
      }
      try {
        JSONObject json = response.getJsonObject();
        int count = json.getInt("count");
        return count;
      }
      catch (JSONException e) {
        LOGGER.error(
            "Although Parse reports object successfully saved, the response was invalid.",
            e);
        throw new ParseException(
            ParseException.INVALID_JSON,
            "Although Parse reports object successfully saved, the response was invalid.",
            e);
      }
    }
    else {
      LOGGER.debug("Request failed.");
      throw response.getException();
    }
   
  }
View Full Code Here

 
  public void send() throws ParseException {
    ParsePostCommand command = new ParsePostCommand("push");
                JSONObject requestData = getJSONData();
    command.setData(requestData);
    ParseResponse response = command.perform();
    if(response.isFailed()) {
      throw response.getException();
   
  } 
View Full Code Here

TOP

Related Classes of org.parse4j.command.ParseResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.