use of org.glassfish.jersey.examples.flight.model.Aircraft in project jersey by jersey.
the class DataStore method generateAircraft.
private static Aircraft generateAircraft() {
final Aircraft aircraft = new Aircraft();
final Iterator<AircraftType> iterator = aircraftTypes.iterator();
int i = rnd.nextInt(aircraftTypes.size());
AircraftType type = null;
while (iterator.hasNext()) {
type = iterator.next();
if (--i < 0) {
break;
}
}
aircraft.setType(type);
aircraft.setLocation(generateLocation(SimEngine.X_BOUND, SimEngine.Y_BOUND));
return aircraft;
}
use of org.glassfish.jersey.examples.flight.model.Aircraft 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.Aircraft 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.model.Aircraft 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.Aircraft in project jersey by jersey.
the class FlightsDemoAppTest method _testAllAircrafts.
private void _testAllAircrafts(String acceptType) {
final List<Aircraft> aircrafts = target("aircrafts").request(acceptType).get(new GenericType<List<Aircraft>>() {
});
for (Aircraft aircraft : aircrafts) {
assertNotNull("Aircraft id", aircraft.getId());
assertNotNull("Aircraft type", aircraft.getType());
}
}
Aggregations