// 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");
}