use of org.glassfish.jersey.examples.flight.filtering.Detail in project jersey by jersey.
the class AircraftsResource method create.
@POST
@Consumes(APPLICATION_FORM_URLENCODED)
@RolesAllowed("admin")
@Detail
public Aircraft create(@FormParam("manufacturer") String manufacturer, @FormParam("type") String type, @FormParam("capacity") Integer capacity, @DefaultValue("0") @FormParam("x-pos") Integer x, @DefaultValue("0") @FormParam("y-pos") Integer y) {
if (manufacturer == null || type == null || capacity == null) {
throw new BadRequestException("Incomplete data.");
}
Aircraft aircraft = new Aircraft();
aircraft.setType(new AircraftType(manufacturer, type, capacity));
aircraft.setLocation(SimEngine.bound(new Location(x, y)));
if (!DataStore.addAircraft(aircraft)) {
throw new InternalServerErrorException("Unable to add new aircraft.");
}
return aircraft;
}
use of org.glassfish.jersey.examples.flight.filtering.Detail 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;
}
Aggregations