Search in sources :

Example 6 with Flight

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());
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) BadRequestException(javax.ws.rs.BadRequestException) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces)

Example 7 with Flight

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();
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 8 with Flight

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;
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) BadRequestException(javax.ws.rs.BadRequestException) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Detail(org.glassfish.jersey.examples.flight.filtering.Detail)

Example 9 with 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;
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 10 with Flight

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();
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces)

Aggregations

Flight (org.glassfish.jersey.examples.flight.model.Flight)11 RolesAllowed (javax.annotation.security.RolesAllowed)4 BadRequestException (javax.ws.rs.BadRequestException)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Aircraft (org.glassfish.jersey.examples.flight.model.Aircraft)4 List (java.util.List)3 POST (javax.ws.rs.POST)3 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Form (javax.ws.rs.core.Form)1 Detail (org.glassfish.jersey.examples.flight.filtering.Detail)1