Search in sources :

Example 1 with Flight

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

the class DataStore method selectOpenFlights.

public static List<Flight> selectOpenFlights() {
    final List<Flight> result = new ArrayList<>(DataStore.flights.values());
    final Iterator<Flight> it = result.iterator();
    while (it.hasNext()) {
        final Flight flight = it.next();
        if (!flight.isOpen()) {
            it.remove();
        }
    }
    Collections.sort(result, FLIGHT_COMPARATOR);
    return result;
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) ArrayList(java.util.ArrayList)

Example 2 with Flight

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

the class FlightsDemoAppTest method _testAllFlights.

private void _testAllFlights(String acceptType) {
    final List<Flight> flights = target("flights").request(acceptType).get(new GenericType<List<Flight>>() {
    });
    for (Flight flight : flights) {
        assertNotNull("Flight id", flight.getId());
        assertFalse("Flight id empty", flight.getId().isEmpty());
        assertFalse("Aircraft not assigned to flight", flight.getAircraft().isAvailable());
    }
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) List(java.util.List)

Example 3 with Flight

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

the class FlightsDemoAppTest method _testCreateFlight.

public void _testCreateFlight(String acceptType) {
    final List<Aircraft> availableAircrafts = target("aircrafts/available").request(acceptType).get(new GenericType<List<Aircraft>>() {
    });
    final Aircraft aircraft = availableAircrafts.get(0);
    final Form flightForm = new Form("aircraftId", aircraft.getId().toString());
    Flight flight = target("flights").queryParam("user", "admin").request(acceptType).post(Entity.form(flightForm), Flight.class);
    assertNotNull("Flight", flight);
    assertNotNull("Flight.id", flight.getId());
    assertNotNull("Flight.aircraft", flight.getAircraft());
    assertEquals("Aircraft IDs do not match", aircraft.getId(), flight.getAircraft().getId());
    assertFalse("Aircraft not assigned", flight.getAircraft().isAvailable());
}
Also used : Form(javax.ws.rs.core.Form) Flight(org.glassfish.jersey.examples.flight.model.Flight) List(java.util.List) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft)

Example 4 with Flight

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

the class DataStore method generateData.

public static void generateData() {
    flights.clear();
    aircrafts.clear();
    LinkedList<Aircraft> planes = new LinkedList<>();
    while (planes.size() < MAX_GEN_AIRCRAFTS) {
        Aircraft a = generateAircraft();
        if (addAircraft(a)) {
            planes.add(a);
        }
    }
    int count = 0;
    while (count < MAX_GEN_FLIGHTS) {
        final Flight flight = generateFlight();
        if (addFlight(flight)) {
            count++;
            final Aircraft aircraft = planes.remove(rnd.nextInt(planes.size()));
            aircraft.marAssigned();
            flight.setAircraft(aircraft);
        }
    }
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft) LinkedList(java.util.LinkedList)

Example 5 with Flight

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

the class DataStore method generateFlight.

private static Flight generateFlight() {
    final Flight flight = new Flight();
    flight.setId(String.format("FL-%04d", rnd.nextInt(10000)));
    return flight;
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight)

Aggregations

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