Examples of Aircraft


Examples of org.glassfish.jersey.examples.flight.model.Aircraft

        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());
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

            @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.");
        }
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

    public static Flight selectFlightByAircraft(Integer id) {
        if (id == null) {
            return  null;
        }

        final Aircraft aircraft = selectAircraft(id);
        if (aircraft == null || aircraft.isAvailable()) {
            return null;
        }

        for (Flight flight : DataStore.flights.values()) {
            if (flight.getAircraft().getId().equals(id)) {
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

    public static List<Aircraft> selectAvailableAircrafts() {
        final ArrayList<Aircraft> result = new ArrayList<Aircraft>(aircrafts.values());
        final Iterator<Aircraft> it = result.iterator();
        while (it.hasNext()) {
            Aircraft a = it.next();
            if (!a.isAvailable()) {
                it.remove();
            }
        }
        Collections.sort(result, AIRCRAFT_COMPARATOR);
        return result;
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

        return flight;
    }

    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;
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

        flights.clear();
        aircrafts.clear();

        LinkedList<Aircraft> planes = new LinkedList<Aircraft>();
        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);
            }
        }
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

    @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;
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

    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());
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

    public void _testCreateAircraft(String acceptType) {
        Form form = new Form("manufacturer", "Cesna")
                .param("type", "680")
                .param("capacity", "9");

        Aircraft aircraft = target("aircrafts").queryParam("user", "admin")
                .request(acceptType)
                .post(Entity.form(form), Aircraft.class);
        assertNotNull("Aircraft", aircraft);
        assertNotNull("Aircraft id", aircraft.getId());
        assertNotNull("Aircraft type", aircraft.getType());
        assertNotNull("Aircraft location", aircraft.getLocation());
        assertEquals("Aircraft location x pos.", 0, aircraft.getLocation().getX());
        assertEquals("Aircraft location y pos.", 0, aircraft.getLocation().getY());
        assertTrue("Aircraft not available", aircraft.isAvailable());

        final List<Aircraft> availableAircrafts = target("aircrafts/available")
                .request(acceptType)
                .get(new GenericType<List<Aircraft>>() {});

        for (Aircraft a : availableAircrafts) {
            if (aircraft.getId().equals(a.getId())) {
                // passed
                return;
            }
        }
        fail("New aircraft not found in the list of available aircrafts.");
View Full Code Here

Examples of org.glassfish.jersey.examples.flight.model.Aircraft

                .param("type", "750")
                .param("capacity", "12")
                .param("x-pos", "100")
                .param("y-pos", "200");

        Aircraft aircraft = target("aircrafts").queryParam("user", "admin")
                .request(acceptType)
                .post(Entity.form(form), Aircraft.class);
        assertNotNull("Aircraft", aircraft);
        assertNotNull("Aircraft id", aircraft.getId());
        assertNotNull("Aircraft type", aircraft.getType());
        assertNotNull("Aircraft location", aircraft.getLocation());
        assertEquals("Aircraft location x pos.", 100, aircraft.getLocation().getX());
        assertEquals("Aircraft location y pos.", 200, aircraft.getLocation().getY());
        assertTrue("Aircraft not available", aircraft.isAvailable());

        final List<Aircraft> availableAircrafts = target("aircrafts/available")
                .request(acceptType)
                .get(new GenericType<List<Aircraft>>() {});

        for (Aircraft a : availableAircrafts) {
            if (aircraft.getId().equals(a.getId())) {
                // passed
                return;
            }
        }
        fail("New aircraft not found in the list of available aircrafts.");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.