Package org.glassfish.jersey.examples.flight.model

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


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


    public static List<Flight> selectOpenFlights() {
        final List<Flight> result = new ArrayList<Flight>(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;
View Full Code Here

     */

    private static final Random rnd = new Random();

    private static Flight generateFlight() {
        final Flight flight = new Flight();
        flight.setId(String.format("FL-%04d", rnd.nextInt(10000)));

        return flight;
    }
View Full Code Here

            }
        }

        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

    @POST
    @Path("{id}/new-booking")
    @Produces(TEXT_PLAIN)
    public String book(@ValidFlightId @PathParam("id") String flightId) {
        final Flight flight = DataStore.selectFlight(flightId);

        if (!flight.isOpen()) {
            throw new BadRequestException("Flight closed.");
        }

        String ridString = "FAILED";
        final int nextRid = flight.nextReservationNumber();
        if (nextRid > 0) {
            ridString = String.format("%s-%03d", flight.getId(), nextRid);
        }
        return ridString;
    }
View Full Code Here

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

    @DELETE
    @Path("{id}")
    @Produces(TEXT_PLAIN)
    @RolesAllowed("admin")
    public String delete(@ValidFlightId @PathParam("id") String flightId) {
        Flight flight = DataStore.removeFlight(flightId);
        flight.getAircraft().marAvailable();
        return flight.getId();
    }
View Full Code Here

            status = Flight.Status.valueOf(newStatus);
        } catch (IllegalArgumentException e) {
            throw new BadRequestException("Unknown status.");
        }

        final Flight flight = DataStore.selectFlight(flightId);

        flight.setStatus(status);

        return status.name();
    }
View Full Code Here

                if (!started.get() || currentThread.isInterrupted()) {
                    cleanup();
                    return;
                }

                final Flight flight = flights.get(i);
                final Location vector = vectors.get(i);
                Location newLocation = new Location(
                        flight.getAircraft().getLocation().getX() + vector.getX(),
                        flight.getAircraft().getLocation().getY() + vector.getY()
                );
                newLocation = bound(newLocation);
                flight.getAircraft().setLocation(newLocation);

                final OutboundEvent flightMovedEvent = new OutboundEvent.Builder()
                        .mediaType(MediaType.APPLICATION_JSON_TYPE)
                        .data(new FlightLocation(flight.getId(), newLocation))
                        .build();

                broadcaster.broadcast(flightMovedEvent);
            }
View Full Code Here

                .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

TOP

Related Classes of org.glassfish.jersey.examples.flight.model.Flight

Copyright © 2018 www.massapicom. 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.