Search in sources :

Example 1 with AircraftType

use of org.glassfish.jersey.examples.flight.model.AircraftType 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;
}
Also used : Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft) AircraftType(org.glassfish.jersey.examples.flight.model.AircraftType)

Example 2 with AircraftType

use of org.glassfish.jersey.examples.flight.model.AircraftType in project jersey by jersey.

the class DataStore method initAircraftTypes.

private static Set<AircraftType> initAircraftTypes() {
    Set<AircraftType> ats = new LinkedHashSet<>();
    // Airbus
    // Short-range
    ats.add(new AircraftType("Airbus", "A318-100", 107));
    ats.add(new AircraftType("Airbus", "A319-100", 124));
    ats.add(new AircraftType("Airbus", "A320-200", 150));
    ats.add(new AircraftType("Airbus", "A321-200", 185));
    ats.add(new AircraftType("Airbus", "A330-200", 253));
    ats.add(new AircraftType("Airbus", "A330-300", 295));
    ats.add(new AircraftType("Airbus", "A330-500", 222));
    ats.add(new AircraftType("Airbus", "A330-500", 222));
    // Medium-range
    ats.add(new AircraftType("Airbus", "A340-200", 240));
    ats.add(new AircraftType("Airbus", "A340-300", 295));
    ats.add(new AircraftType("Airbus", "A340-500", 313));
    ats.add(new AircraftType("Airbus", "A340-600", 380));
    // Long-range
    ats.add(new AircraftType("Airbus", "A350-800", 270));
    ats.add(new AircraftType("Airbus", "A350-900", 314));
    ats.add(new AircraftType("Airbus", "A350-1000", 350));
    ats.add(new AircraftType("Airbus", "A380-800", 525));
    // Boeing
    // Short-range
    ats.add(new AircraftType("Boeing", "737-200", 97));
    ats.add(new AircraftType("Boeing", "737-500", 146));
    ats.add(new AircraftType("Boeing", "737-900", 177));
    // Medium-range
    ats.add(new AircraftType("Boeing", "767-200", 181));
    ats.add(new AircraftType("Boeing", "767-300", 218));
    ats.add(new AircraftType("Boeing", "767-400", 245));
    // Long-range
    ats.add(new AircraftType("Boeing", "777-200", 314));
    ats.add(new AircraftType("Boeing", "777-300", 386));
    ats.add(new AircraftType("Boeing", "787-8", 242));
    ats.add(new AircraftType("Boeing", "787-9", 280));
    ats.add(new AircraftType("Boeing", "787-10", 323));
    return Collections.unmodifiableSet(ats);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AircraftType(org.glassfish.jersey.examples.flight.model.AircraftType)

Example 3 with AircraftType

use of org.glassfish.jersey.examples.flight.model.AircraftType 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

AircraftType (org.glassfish.jersey.examples.flight.model.AircraftType)3 Aircraft (org.glassfish.jersey.examples.flight.model.Aircraft)2 LinkedHashSet (java.util.LinkedHashSet)1 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 Location (org.glassfish.jersey.examples.flight.model.Location)1