Search in sources :

Example 6 with Aircraft

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

Example 7 with 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());
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) BadRequestException(javax.ws.rs.BadRequestException) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces)

Example 8 with Aircraft

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;
}
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)

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

Example 10 with Aircraft

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());
    }
}
Also used : List(java.util.List) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft)

Aggregations

Aircraft (org.glassfish.jersey.examples.flight.model.Aircraft)11 List (java.util.List)5 Flight (org.glassfish.jersey.examples.flight.model.Flight)4 RolesAllowed (javax.annotation.security.RolesAllowed)3 BadRequestException (javax.ws.rs.BadRequestException)3 Form (javax.ws.rs.core.Form)3 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Detail (org.glassfish.jersey.examples.flight.filtering.Detail)2 AircraftType (org.glassfish.jersey.examples.flight.model.AircraftType)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 DELETE (javax.ws.rs.DELETE)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Location (org.glassfish.jersey.examples.flight.model.Location)1