use of org.glassfish.jersey.examples.flight.model.Location in project jersey by jersey.
the class SimEngine method bound.
public static Location bound(final Location location) {
int x = location.getX();
int y = location.getY();
if (x >= X_BOUND) {
x = x % X_BOUND;
} else if (x < 0) {
x = X_BOUND + (x % X_BOUND);
}
if (y >= Y_BOUND) {
y = y % Y_BOUND;
} else if (y < 0) {
y = Y_BOUND + (y % Y_BOUND);
}
return (x != location.getX() || y != location.getY()) ? new Location(x, y) : location;
}
use of org.glassfish.jersey.examples.flight.model.Location 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;
}
Aggregations