use of org.glassfish.jersey.examples.flight.model.Flight in project jersey by jersey.
the class AircraftsResource method delete.
@DELETE
@Path("{id}")
@Produces(TEXT_PLAIN)
@RolesAllowed("admin")
public String delete(@ValidAircraftId @PathParam("id") Integer id) {
Flight flight = DataStore.selectFlightByAircraft(id);
if (flight != null) {
throw new BadRequestException("Aircraft assigned to a flight.");
}
Aircraft aircraft = DataStore.removeAircraft(id);
return String.format("%03d", aircraft.getId());
}
use of org.glassfish.jersey.examples.flight.model.Flight in project jersey by jersey.
the class FlightsResource method updateStatus.
@POST
@Path("{id}/status")
@Consumes(APPLICATION_FORM_URLENCODED)
@Produces(TEXT_PLAIN)
@RolesAllowed("admin")
public String updateStatus(@ValidFlightId @PathParam("id") String flightId, @FormParam("status") String newStatus) {
Flight.Status status;
try {
status = Flight.Status.valueOf(newStatus);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Unknown status.");
}
final Flight flight = DataStore.selectFlight(flightId);
flight.setStatus(status);
return status.name();
}
use of org.glassfish.jersey.examples.flight.model.Flight in project jersey by jersey.
the class FlightsResource method create.
@POST
@Consumes(APPLICATION_FORM_URLENCODED)
@RolesAllowed("admin")
@Detail
public Flight create(@ValidAircraftId @FormParam("aircraftId") Integer aircraftId) {
final Aircraft aircraft = DataStore.selectAircraft(aircraftId);
if (!aircraft.marAssigned()) {
throw new BadRequestException("Aircraft already assigned.");
}
Flight flight = new Flight(null, aircraft);
if (!DataStore.addFlight(flight)) {
aircraft.marAvailable();
throw new BadRequestException("Flight already exists.");
}
return flight;
}
use of org.glassfish.jersey.examples.flight.model.Flight in project jersey by jersey.
the class FlightsResource method book.
@POST
@Path("{id}/new-booking")
@Produces(TEXT_PLAIN)
public String book(@ValidFlightId @PathParam("id") String flightId) {
final Flight flight = DataStore.selectFlight(flightId);
if (!flight.isOpen()) {
throw new BadRequestException("Flight closed.");
}
String ridString = "FAILED";
final int nextRid = flight.nextReservationNumber();
if (nextRid > 0) {
ridString = String.format("%s-%03d", flight.getId(), nextRid);
}
return ridString;
}
use of org.glassfish.jersey.examples.flight.model.Flight in project jersey by jersey.
the class FlightsResource method delete.
@DELETE
@Path("{id}")
@Produces(TEXT_PLAIN)
@RolesAllowed("admin")
public String delete(@ValidFlightId @PathParam("id") String flightId) {
Flight flight = DataStore.removeFlight(flightId);
flight.getAircraft().marAvailable();
return flight.getId();
}
Aggregations