Search in sources :

Example 1 with Booking

use of com.liferay.faces.demos.dto.Booking in project liferay-faces-bridge-impl by liferay.

the class BookingServiceMockImpl method postConstruct.

@PostConstruct
public void postConstruct() {
    allBookings = new ArrayList<Booking>();
    // Bookings for Brian Green
    long customerId = CustomerServiceMockImpl.ID_BRIAN_GREEN;
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_RENTAL_CAR, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_HOTEL, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_AIRFARE, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_THEME_PARK, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_PLAY, customerId));
    // Bookings for Elizabeth Kessler
    customerId = CustomerServiceMockImpl.ID_LIZ_KESSLER;
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_HOTEL, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_AIRFARE, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_THEME_PARK, customerId));
    // Bookings for Rich Shearer
    customerId = CustomerServiceMockImpl.ID_RICH_SHEARER;
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_AIRFARE, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_RENTAL_CAR, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_PLAY, customerId));
    allBookings.add(new Booking(BookingTypeServiceMockImpl.TYPE_ID_HOTEL, customerId));
    allBookings = Collections.unmodifiableList(allBookings);
}
Also used : Booking(com.liferay.faces.demos.dto.Booking) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Booking

use of com.liferay.faces.demos.dto.Booking in project liferay-faces-bridge-impl by liferay.

the class BookingsModelBean method postConstruct.

@PostConstruct
public void postConstruct() {
    logger.trace("@PostConstruct annotation worked");
    customer = new Customer();
    customer.setBookings(new ArrayList<Booking>(5));
}
Also used : Customer(com.liferay.faces.demos.dto.Customer) Booking(com.liferay.faces.demos.dto.Booking) PostConstruct(javax.annotation.PostConstruct)

Example 3 with Booking

use of com.liferay.faces.demos.dto.Booking in project liferay-faces-bridge-impl by liferay.

the class FlightServiceMockImpl method searchDirect.

@Override
public List<Booking> searchDirect(long departureAirportId, Date departureDate, long arrivalAirportId) {
    DateFormat dateFormat = new SimpleDateFormat();
    List<Booking> searchResults = new ArrayList<Booking>();
    Airport departureAirport = airportService.findById(departureAirportId);
    double departureLatitude = departureAirport.getLatitude();
    double departureLongitude = departureAirport.getLongitude();
    LatLng departureLatLong = new LatLng(departureLatitude, departureLongitude);
    Airport arrivalAirport = airportService.findById(arrivalAirportId);
    double arrivalLatitude = arrivalAirport.getLatitude();
    double arrivalLongitude = arrivalAirport.getLongitude();
    LatLng arrivalLatLong = new LatLng(arrivalLatitude, arrivalLongitude);
    double distanceInKilometers = LatLngTool.distance(departureLatLong, arrivalLatLong, LengthUnit.KILOMETER);
    double durationInHours = distanceInKilometers / AVG_SPEED_KM_PER_HOUR;
    double priceUSD = distanceInKilometers * PRICE_USD_PER_KM;
    Calendar departureCalendar = new GregorianCalendar();
    departureCalendar.setTime(departureDate);
    departureCalendar.set(Calendar.HOUR_OF_DAY, 6);
    Random random = new Random();
    while (departureCalendar.get(Calendar.HOUR_OF_DAY) < 18) {
        Calendar arrivalCalendar = (Calendar) departureCalendar.clone();
        arrivalCalendar.add(Calendar.HOUR_OF_DAY, (int) Math.round(durationInHours));
        Booking flight = new Booking();
        Date flightDepartureDate = departureCalendar.getTime();
        flight.setDepartureDate(flightDepartureDate);
        flight.setArrivalId(arrivalAirportId);
        Date flightArrivalDate = arrivalCalendar.getTime();
        flight.setArrivalDate(flightArrivalDate);
        flight.setDistance(distanceInKilometers);
        flight.setDuration(durationInHours);
        flight.setBookingId(Math.abs(random.nextLong()));
        String flightNumber = Integer.toString(Math.abs(random.nextInt()));
        flight.setLabel(flightNumber);
        StringBuilder description = new StringBuilder();
        description.append("Flight#");
        description.append(flightNumber);
        description.append(" departing from ");
        description.append(departureAirport.getCity());
        description.append(" (");
        description.append(departureAirport.getCode());
        description.append(") on ");
        description.append(dateFormat.format(flightDepartureDate));
        description.append(" arriving at ");
        description.append(arrivalAirport.getCity());
        description.append("(");
        description.append(arrivalAirport.getCode());
        description.append(") on ");
        description.append(dateFormat.format(flightArrivalDate));
        flight.setDescription(description.toString());
        BigDecimal price = new BigDecimal(priceUSD);
        price.setScale(2, BigDecimal.ROUND_HALF_UP);
        flight.setPrice(price);
        departureCalendar.add(Calendar.MINUTE, 90);
        searchResults.add(flight);
    }
    return searchResults;
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) Booking(com.liferay.faces.demos.dto.Booking) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Random(java.util.Random) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Airport(com.liferay.faces.demos.dto.Airport) LatLng(com.javadocmd.simplelatlng.LatLng) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with Booking

use of com.liferay.faces.demos.dto.Booking in project liferay-faces-bridge-impl by liferay.

the class BookingFlowBackingBean method removeBooking.

public void removeBooking(long bookingId) {
    List<Booking> cartBookings = bookingFlowModelBean.getCartBookings();
    Booking bookingToRemove = null;
    for (Booking cartBooking : cartBookings) {
        if (cartBooking.getBookingId() == bookingId) {
            bookingToRemove = cartBooking;
            break;
        }
    }
    if (bookingToRemove != null) {
        cartBookings.remove(bookingToRemove);
    }
}
Also used : Booking(com.liferay.faces.demos.dto.Booking)

Example 5 with Booking

use of com.liferay.faces.demos.dto.Booking in project liferay-faces-bridge-impl by liferay.

the class CartModelBean method getTotalPrice.

public BigDecimal getTotalPrice() {
    if (totalPrice == null) {
        totalPrice = new BigDecimal(0L);
        totalPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
        List<Booking> cartBookings = bookingFlowModelBean.getCartBookings();
        for (Booking booking : cartBookings) {
            totalPrice = totalPrice.add(booking.getPrice());
        }
    }
    return totalPrice;
}
Also used : Booking(com.liferay.faces.demos.dto.Booking) BigDecimal(java.math.BigDecimal)

Aggregations

Booking (com.liferay.faces.demos.dto.Booking)5 BigDecimal (java.math.BigDecimal)2 PostConstruct (javax.annotation.PostConstruct)2 LatLng (com.javadocmd.simplelatlng.LatLng)1 Airport (com.liferay.faces.demos.dto.Airport)1 Customer (com.liferay.faces.demos.dto.Customer)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 Random (java.util.Random)1