Search in sources :

Example 1 with Location

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;
}
Also used : FlightLocation(org.glassfish.jersey.examples.flight.model.FlightLocation) Location(org.glassfish.jersey.examples.flight.model.Location)

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

Aggregations

Location (org.glassfish.jersey.examples.flight.model.Location)2 RolesAllowed (javax.annotation.security.RolesAllowed)1 BadRequestException (javax.ws.rs.BadRequestException)1 Consumes (javax.ws.rs.Consumes)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 POST (javax.ws.rs.POST)1 Detail (org.glassfish.jersey.examples.flight.filtering.Detail)1 Aircraft (org.glassfish.jersey.examples.flight.model.Aircraft)1 AircraftType (org.glassfish.jersey.examples.flight.model.AircraftType)1 FlightLocation (org.glassfish.jersey.examples.flight.model.FlightLocation)1