Package acme.dataapp

Examples of acme.dataapp.MyFlights


                resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "There is no flight booked for user " + userId +
                        " with the flight number " + flightId + ".");
                return;
            }
            try {
                MyFlights myFlights = MyFlights.getInstance();
                JSONObject updatedFlight = new JSONObject(putBody);
                JSONObject currentFlight = myFlights.getFlight(userId, flightId);
                String approverId = updatedFlight.has(APPROVER_ID) ? updatedFlight.getString(APPROVER_ID) :
                    currentFlight.getString(APPROVER_ID);
                String reason = updatedFlight.has(REASON) ? updatedFlight.getString(REASON) :
                    currentFlight.optString(REASON);
                String state = updatedFlight.has(STATE) ? updatedFlight.getString(STATE) : currentFlight.getString(STATE);
                JSONObject responseFlight = myFlights.updateMyFlight(userId, flightId, approverId, reason, state);
                writeJsonObjectResponse(responseFlight, resp);
                resp.flushBuffer();
            } catch (JSONException e) {
                resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                return;
View Full Code Here


        // gets flights for users
        Principal prin = request.getUserPrincipal();
        if (prin != null) {
          String userId = prin.getName();

          MyFlights mf = MyFlights.getInstance();
          res = mf.getMyFlights(userId);

          res.put("result", "success");
        } else {
          res.put("result", "notloggedin");
        }

      } else if (path.contains("/api/allflightrequests")) {
        // gets all flight requests
        Principal prin = request.getUserPrincipal();

        if (prin != null) {
          String flightId = request.getParameter("flightId");
          if (flightId != null) {
            MyFlights mf = MyFlights.getInstance();
            res = mf.getCustomersByFlight(flightId);
          } else {
            if (request.isUserInRole("admin")) {
              MyFlights mf = MyFlights.getInstance();
              res = mf.getAll();

            } else {
              res.put("result", "not in admin role");
            }
          }

        } else {
          res.put("result", "notloggedin");
        }

      } else if (path.contains("/api/myflightreason")) {
        // gets the reason for travel for a selected user and flight
        Principal prin = request.getUserPrincipal();

        if (prin != null) {
          String flightId = request.getParameter("flightId");
          String userId = request.getParameter("userId");

          if (flightId != null && userId != null) {
            MyFlights mf = MyFlights.getInstance();
            res = mf.getReasonForTravel(userId, flightId);
          } else {

            res.put("result", "no parameters");

          }
View Full Code Here

          String userId = prin.getName();
          JSONObject o = new JSONObject(request.getInputStream());
          String flightId = o.getString("FlightId");
          String approverId = o.getString("ApproverId");
          String reason = o.getString("Reason");
          MyFlights mf = MyFlights.getInstance();
          mf.addMyFlight(flightId, userId, approverId, reason);
          res.put("result", "success");
        } else {
          res.put("result", "notloggedin");
        }

      } else if (path.contains("/api/approveflight/")) {
        // approves a flight
        Principal prin = request.getUserPrincipal();
        if (prin != null) {
          String approverId = prin.getName();
          JSONObject o = new JSONObject(request.getInputStream());
          String userId = o.getString("userId");
          String flightId = o.getString("flightId");
          MyFlights mf = MyFlights.getInstance();
          mf.approveMyFlight(userId, flightId, approverId);
          res.put("result", "success");
        } else {
          res.put("result", "notloggedin");
        }
View Full Code Here

      } else if (path.contains("/api/myflights/")) {
        // gets all flight requests
        Principal prin = request.getUserPrincipal();

        if (prin != null) {
          MyFlights mf = MyFlights.getInstance();
          JSONObject o = new JSONObject(request.getInputStream());
          String userId = o.getString("userId");
          String flightId = o.getString("flightId");
          mf.removeMyFlights(userId, flightId);
          res.put("result", "flightremoved");

        } else {
          res.put("result", "notloggedin");
        }
View Full Code Here

          JSONObject o = new JSONObject(request.getInputStream());
          String flightId = o.getString("FlightId");
          String approverId = o.getString("ApproverId");
          String reason = o.getString("Reason");
          String state = o.getString("state");
          MyFlights mf = MyFlights.getInstance();
          mf.updateMyFlight(userId, flightId, approverId, reason,
              state);
          res.put("result", "success");
        } else {
          res.put("result", "notloggedin");
        }
View Full Code Here

TOP

Related Classes of acme.dataapp.MyFlights

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.