Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONArray


    private boolean flightAlreadyBooked(String flightId, String userId) {
        JSONObject myFlightsObj = MyFlights.getInstance().getMyFlights(userId);
        if(myFlightsObj.has("myflights")) {
            try {
                JSONArray myFlights = myFlightsObj.getJSONArray("myflights");
                Iterator<JSONObject> iter = myFlights.iterator();
                while(iter.hasNext()) {
                    if(iter.next().getString(FLIGHT_ID).equals(flightId)) {
                        return true;
                    }
                }
View Full Code Here


      newFlight.put("Depart", depart);
      newFlight.put("Arrive", arrive);
      newFlight.put("Time", time);
      newFlight.put("FlightTime", flightTime);

      JSONArray flts = (JSONArray) flights.get("flights");
      flts.add(newFlight);

      flights.remove("flights");
      flights.put("flights", flights);

    } catch (Exception e) {
View Full Code Here

   *
   * @param flight
   */
  public void removeFlight(String flight) {
    try {
      JSONArray flts = (JSONArray) flights.get("flights");
      flts.remove(flight);

      flights.remove("flights");
      flights.put("flights", flights);

    } catch (Exception e) {
View Full Code Here

   * @return
   */
  public JSONObject getFlightsByID(String flight) {
    JSONObject res = null;
    try {
      JSONArray flts = (JSONArray) flights.get("flights");
     
      @SuppressWarnings("rawtypes")
      Iterator iter = flts.iterator();
      boolean found = false;
      while(iter.hasNext() && !found){
        JSONObject i = (JSONObject) iter.next();
        String flightId = i.getString("Flight");
        if(flightId.compareTo(flight)==0){
View Full Code Here

   * get message of the day
   */
  public JSONObject getRandomMessageOfTheDay() {
    JSONObject res = null;
    try {
      JSONArray msgs = (JSONArray) m.get("motd");
     
      long numMessages = (long) m.getInt("length");
     
      int index =  Long.valueOf(System.currentTimeMillis() % numMessages).intValue();
     
      @SuppressWarnings("rawtypes")
      Iterator iter = msgs.iterator();
      int i = 0;
      while(iter.hasNext() && i < index){
        iter.next();
        i++;
      }
View Full Code Here

   * @param reason
   */
  public void addMyFlight(String flightId, String userId, String approverId,
      String reason) {
    try {
      JSONArray flts = (JSONArray) myFlights.get("myflights");
      JSONObject o = new JSONObject();
      o.put("FlightId", flightId);
      o.put("UserId", userId);
      o.put("ApproverId", approverId);
      o.put("Reason", reason);
      o.put("state", "started");
      flts.put(o);
     
      myFlights.remove("myflights");
      myFlights.put("myflights", flts);

    } catch (Exception e) {
View Full Code Here

   * @param userId
   *            should be from the request.getUserPrincipal
   */
  public JSONObject getMyFlights(String userId) {
    JSONObject res = new JSONObject();
    JSONArray arr = new JSONArray();
    try {
      JSONArray flts = (JSONArray) myFlights.get("myflights");

      @SuppressWarnings("rawtypes")
      Iterator iter = flts.iterator();
      while (iter.hasNext()) {
        JSONObject o = (JSONObject) iter.next();
        String uId = o.getString("UserId");

        // Checks to see if the uid exists
View Full Code Here

     *
     * @param flightId
     *           
     */
    public JSONArray getUsers(String flightId) {
        JSONArray arr = new JSONArray();
        try {
            JSONArray flts = (JSONArray) myFlights.get("myflights");

            @SuppressWarnings("rawtypes")
            Iterator iter = flts.iterator();
            while (iter.hasNext()) {
                JSONObject o = (JSONObject) iter.next();
                String fId = o.getString("FlightId");

                // Checks to see if the fid exists
View Full Code Here

   * @param userId
   * @param flightId
   */
  public void removeMyFlights(String userId, String flightId) {
    try {
      JSONArray flts = (JSONArray) myFlights.get("myflights");

      @SuppressWarnings("rawtypes")
      Iterator iter = flts.iterator();
      while (iter.hasNext()) {
        JSONObject o = (JSONObject) iter.next();
        String fId = o.getString("UserId");
        String uId = o.getString("FlightId");

        // Checks to see if the flight id and uid exist
        if (fId.compareTo(flightId) == 0 && uId.compareTo(userId) == 0) {
          flts.remove(o);
        }

      }

      flts.remove(flightId);

      myFlights.remove("myflights");
      myFlights.put("myflights", flts);

    } catch (Exception e) {
View Full Code Here

   * @param approverId
   */
  public void approveMyFlight(String userId, String flightId,
      String approverId) {
    try {
      JSONArray flts = (JSONArray) myFlights.get("myflights");

      @SuppressWarnings("rawtypes")
      Iterator iter = flts.iterator();
      while (iter.hasNext()) {
        JSONObject o = (JSONObject) iter.next();
        String fId = o.getString("UserId");
        String uId = o.getString("FlightId");
        String aId = o.getString("ApproverId");

        // Checks to see if the flight id and uid and aId exist
        if (fId.compareTo(flightId) == 0 && uId.compareTo(userId) == 0
            && aId.compareTo(approverId) == 0) {
          flts.remove(o);
          o.put("state", "approved");
          flts.put(o);
        }

      }

      flts.remove(flightId);

      myFlights.remove("myflights");
      myFlights.put("myflights", flts);

    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.wink.json4j.JSONArray

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.