linksList = new ArrayList<>();
+ linksList.add(GetCarsListingsOperationParams.Links.AD);
+ linksList.add(GetCarsListingsOperationParams.Links.WS);
+ linksList.add(GetCarsListingsOperationParams.Links.WD);
+
+ GetCarsListingsOperationParams getCarsListingsOperationParams =
+ GetCarsListingsOperationParams.builder().partnerTransactionId("EWSCar_Automation")
+ //Three letter code for the airport at which the customer would like to pick up the car.
+ //Supported values: standard 3 letter IATA Airport Code.
+ //Cannot coexist with other pickup parameters, only one pickup parameter is allowed per
+ //request.
+ .pickupAirport("MCO")
+ //Three letter code for the airport at which the customer would like to drop off the
+ //car.
+ //Supported values: standard 3 letter IATA Airport Code.
+ //Cannot coexist with other drop off parameters, only one drop off parameter is allowed
+ //per request.
+ //If no drop off location is specified, it is assumed that the customer will be dropping
+ //the car off at the same location at which they picked it up.
+ .dropOffAirport("MCO")
+ //Requested car pickup date and time.
+ //Date should be ISO8601 Date format.The supported search window is today to 330 days in
+ //the future.
+ //(Note that each rental counter has different hours of operation. If you select a time
+ //in the middle of the night there may be no inventory available as all locations may be
+ //closed.)
+ .pickupTime(LocalDateTime.now().plusDays(5))
+ //Requested car drop off date and time.
+ //Date should be ISO8601 Date format.The supported search window is today to 330 days in
+ //the future.
+ //The drop-off datetime should occur at least 2 hours after the pickup datetime.
+ .dropOffTime(LocalDateTime.now().plusDays(8))
+ //The maximum number of search results that will be returned by the query.
+ .limit(5).links(linksList).build();
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the CarListingsResponse
+ CarListingsResponse carListingsResponse =
+ xapClient.execute(new GetCarsListingsOperation(getCarsListingsOperationParams)).getData();
+ LOGGER.info(
+ "======================== GetCarsListingsOperation Executed ========================");
+
+ if (carListingsResponse == null || carListingsResponse.getCars() == null
+ || carListingsResponse.getCars().isEmpty()) {
+ throw new IllegalStateException("No cars found.");
}
- if (car.getLinks().get("WebSearch") != null) {
- LOGGER.info("WebSearch Link: {}", car.getLinks().get("WebSearch"));
- }
- if (car.getLinks().get("WebDetails") != null) {
- LOGGER.info("WebDetails Link: {}", car.getLinks().get("WebDetails"));
- }
- }
-
- // The rate detail information for a car offer.
- if (car.getRateDetails() != null) {
- LOGGER.info("Rate Details: {}", car.getRateDetails());
- }
-
- // Get the detailed pricing information for the rental of the car offer,
- LOGGER.info("Car Price: {}", car.getPrice());
-
- // Get a list of additional fees, including both mandatory and optional fees.
- if (car.getAdditionalFees() != null) {
- LOGGER.info("Additional Fees: {}", car.getAdditionalFees());
- }
-
- // Get the cancellation policy for the car offer,
- LOGGER.info("Cancellation Policy: {}", car.getCancellationPolicy());
-
- // Container for no show penalty element.
- if (car.getNoShowPenalty() != null) {
- LOGGER.info("No Show Penalty: {}", car.getNoShowPenalty());
- }
-
- LOGGER.info("======================== Property End ========================");
- });
- LOGGER.info(
- "======================== End CarListingsQuickStartScenario ========================");
- }
+ // The CarListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", carListingsResponse.getTransactionId());
+ // To get the total number of car found
+ LOGGER.info("Car Count: {}", carListingsResponse.getCarCount());
+
+ // To access the properties, iterate through the list of car properties
+ carListingsResponse.getCars().forEach(car -> {
+ LOGGER.info("======================== Car Properties Start ========================");
+
+ // Uniquely identifies a Car Offer.
+ LOGGER.info("Car Id: {}", car.getId());
+
+ // Specific information for a car.
+ LOGGER.info("Car VehicleDetails: {}", car.getVehicleDetails());
+
+ // The supplier of the car being offered.
+ LOGGER.info("Car Supplier: {}", car.getSupplier());
+
+ // Get Pickup information of the car.
+ LOGGER.info("Pick up Details: {}", car.getPickupDetails());
+
+ // Get Drop off information of the car.
+ LOGGER.info("Drop Off Details: {}", car.getDropOffDetails());
+
+ // Get the API details link, web search link, and web details link from the links collection.
+ if (!car.getLinks().isEmpty()) {
+ if (car.getLinks().get("ApiDetails") != null) {
+ LOGGER.info("ApiDetails Link: {}", car.getLinks().get("ApiDetails"));
+ }
+ if (car.getLinks().get("WebSearch") != null) {
+ LOGGER.info("WebSearch Link: {}", car.getLinks().get("WebSearch"));
+ }
+ if (car.getLinks().get("WebDetails") != null) {
+ LOGGER.info("WebDetails Link: {}", car.getLinks().get("WebDetails"));
+ }
+ }
+
+ // The rate detail information for a car offer.
+ if (car.getRateDetails() != null) {
+ LOGGER.info("Rate Details: {}", car.getRateDetails());
+ }
+
+ // Get the detailed pricing information for the rental of the car offer,
+ LOGGER.info("Car Price: {}", car.getPrice());
+
+
+ // Get a list of additional fees, including both mandatory and optional fees.
+ if (car.getAdditionalFees() != null) {
+ LOGGER.info("Additional Fees: {}", car.getAdditionalFees());
+ }
+
+ // Get the cancellation policy for the car offer,
+ LOGGER.info("Cancellation Policy: {}", car.getCancellationPolicy());
+
+ // Container for no show penalty element.
+ if (car.getNoShowPenalty() != null) {
+ LOGGER.info("No Show Penalty: {}", car.getNoShowPenalty());
+ }
+
+ LOGGER.info("======================== Property End ========================");
+ });
+ LOGGER.info(
+ "======================== End CarListingsQuickStartScenario ========================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/flight/FlightListingExample.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/flight/FlightListingExample.java
index 32286d5fa..ee7c5ad4e 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/flight/FlightListingExample.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/flight/FlightListingExample.java
@@ -19,333 +19,234 @@
import com.expediagroup.sdk.xap.client.XapClient;
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
import com.expediagroup.sdk.xap.models.FlightSearchResponse;
+import com.expediagroup.sdk.xap.models.GetFlightListingsOperationSegmentParam;
import com.expediagroup.sdk.xap.operations.GetFlightListingsOperation;
import com.expediagroup.sdk.xap.operations.GetFlightListingsOperationParams;
+
import java.time.LocalDate;
import java.util.Arrays;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This example demonstrates how to search for flight listings for a one-way,
- * round-trip & mutli-stop with adults, seniors, and childrens.
+ * round-trip & multi-stop with adults, seniors, and children.
*/
public class FlightListingExample implements XapScenario {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FlightListingExample.class);
- private static final Logger LOGGER =
- LoggerFactory.getLogger(FlightListingExample.class);
-
-
- public static void main(String[] args) {
- new FlightListingExample().run();
- System.exit(0);
- }
+ public static void main(String[] args) {
+ new FlightListingExample().run();
+ System.exit(0);
+ }
- @Override
+ @Override
public void run() {
- LOGGER.info(
- "========= Running FlightListingsQuickStartScenario =============");
-
- LOGGER.info(
- "============= Executing GetFlightListingsOperation (One-Way) =========");
+ LOGGER.info("========= Running FlightListingsQuickStartScenario =============");
+ LOGGER.info("============= Executing GetFlightListingsOperation (One-Way) =========");
+ LocalDate now = LocalDate.now();
- GetFlightListingsOperationParams getFlightListingsOperationParams =
- GetFlightListingsOperationParams.builder()
- .partnerTransactionID("txn-123-4")
- .segment1Origin("LAS")
- .segment1Destination("FLL")
- .segment1DepartureDate(LocalDate.of(2025, 5, 1))
- .adult(1)
- .senior(1)
- .childrenAges(Arrays.asList(4, 5))
- .build();
+ GetFlightListingsOperationParams getFlightListingsOperationParams = GetFlightListingsOperationParams.builder().partnerTransactionID("txn-123-4").segment1(GetFlightListingsOperationSegmentParam.builder().origin("LAS").destination("FLL").departureDate(now.plusDays(5)).build()).adult(1).senior(1).childrenAges(Arrays.asList(4, 5)).build();
- XapClient xapClient = createClient();
+ XapClient xapClient = createClient();
- FlightSearchResponse flightListingsResponse =
- xapClient.execute(new GetFlightListingsOperation(getFlightListingsOperationParams))
- .getData();
+ FlightSearchResponse flightListingsResponse = xapClient.execute(new GetFlightListingsOperation(getFlightListingsOperationParams)).getData();
- LOGGER.info("========= GetFlightListingsOperation (One-Way) Executed ========");
-
- if (flightListingsResponse == null || flightListingsResponse.getSegments() == null
- || flightListingsResponse.getSegments().isEmpty()) {
- throw new IllegalStateException("No flight found.");
- }
+ LOGGER.info("========= GetFlightListingsOperation (One-Way) Executed ========");
+ if (flightListingsResponse == null || flightListingsResponse.getSegments() == null || flightListingsResponse.getSegments().isEmpty()) {
+ throw new IllegalStateException("No flight found.");
+ }
- LOGGER.info("Transaction ID: {}", flightListingsResponse.getTransactionId());
-
- if (flightListingsResponse.getSegments() != null) {
- flightListingsResponse.getSegments().forEach(segment -> {
- LOGGER.info("======================== Flight Segment Start ========================");
- LOGGER.info("Segment ID: {}", segment.getSegmentId());
- LOGGER.info("Flight Duration: {}", segment.getFlightDuration());
- LOGGER.info("Total Stops: {}", segment.getTotalStops());
- LOGGER.info("Departure Arrival Day Difference: {}",
- segment.getDepartureArrivalDayDifference());
- LOGGER.info("Seats Left: {}", segment.getSeatsLeft());
- LOGGER.info("Fare Type: {}", segment.getFareType());
-
- if (segment.getLegs() != null) {
- segment.getLegs().forEach(leg -> {
- LOGGER.info("-------------------- Leg Start --------------------");
-
- if (leg.getDepartureAirport() != null) {
- LOGGER.info("Departure Airport Code: {}",
- leg.getDepartureAirport().getCode());
- LOGGER.info("Departure Airport Name: {}",
- leg.getDepartureAirport().getName());
- LOGGER.info("Departure City: {}",
- leg.getDepartureAirport().getCity());
- LOGGER.info("Departure Province: {}",
- leg.getDepartureAirport().getProvince());
- LOGGER.info("Departure Country: {}",
- leg.getDepartureAirport().getCountry());
- LOGGER.info("Departure Latitude: {}",
- leg.getDepartureAirport().getLatitude());
- LOGGER.info("Departure Longitude: {}",
- leg.getDepartureAirport().getLongitude());
- }
-
- if (leg.getArrivalAirport() != null) {
- LOGGER.info("Arrival Airport Code: {}",
- leg.getArrivalAirport().getCode());
- LOGGER.info("Arrival Airport Name: {}",
- leg.getArrivalAirport().getName());
- LOGGER.info("Arrival City: {}",
- leg.getArrivalAirport().getCity());
- LOGGER.info("Arrival Province: {}",
- leg.getArrivalAirport().getProvince());
- LOGGER.info("Arrival Country: {}",
- leg.getArrivalAirport().getCountry());
- LOGGER.info("Arrival Latitude: {}",
- leg.getArrivalAirport().getLatitude());
- LOGGER.info("Arrival Longitude: {}",
- leg.getArrivalAirport().getLongitude());
- }
- LOGGER.info("Departure Date Time: {}",
- leg.getDepartureDateTime());
- LOGGER.info("Arrival Date Time: {}",
- leg.getArrivalDateTime());
- LOGGER.info("Flight Number: {}",
- leg.getFlightNumber());
- LOGGER.info("Marketing Airline Code: {}",
- leg.getMarketingAirlineCode());
- LOGGER.info("Marketing Airline Name: {}",
- leg.getMarketingAirlineName());
- LOGGER.info("Equipment Code: {}",
- leg.getEquipmentCode());
- LOGGER.info("Flight On Time Percentage: {}",
- leg.getFlightOnTimePercentage());
- LOGGER.info("Equipment Name: {}",
- leg.getEquipmentName());
- LOGGER.info("Flight Duration (Leg): {}",
- leg.getFlightDuration());
-
- if (leg.getFlightDistance() != null) {
- LOGGER.info("Flight Distance Value: {}",
- leg.getFlightDistance().getValue());
- LOGGER.info("Flight Distance Unit: {}",
- leg.getFlightDistance().getUnit());
- }
- LOGGER.info("Booking Code: {}",
- leg.getBookingCode());
- LOGGER.info("Cabin Class: {}",
- leg.getCabinClass());
- LOGGER.info("Fare Basis Code: {}",
- leg.getFareBasisCode());
- LOGGER.info("Meal Options: {}",
- leg.getMealOptions());
- LOGGER.info("Amenities: {}",
- leg.getAmenities());
- LOGGER.info("---------- Leg End ----------");
- });
+ LOGGER.info("Transaction ID: {}", flightListingsResponse.getTransactionId());
+
+ if (flightListingsResponse.getSegments() != null) {
+ flightListingsResponse.getSegments().forEach(segment -> {
+ LOGGER.info("======================== Flight Segment Start ========================");
+ LOGGER.info("Segment ID: {}", segment.getSegmentId());
+ LOGGER.info("Flight Duration: {}", segment.getFlightDuration());
+ LOGGER.info("Total Stops: {}", segment.getTotalStops());
+ LOGGER.info("Departure Arrival Day Difference: {}", segment.getDepartureArrivalDayDifference());
+ LOGGER.info("Seats Left: {}", segment.getSeatsLeft());
+ LOGGER.info("Fare Type: {}", segment.getFareType());
+
+ if (segment.getLegs() != null) {
+ segment.getLegs().forEach(leg -> {
+ LOGGER.info("-------------------- Leg Start --------------------");
+
+ if (leg.getDepartureAirport() != null) {
+ LOGGER.info("Departure Airport Code: {}", leg.getDepartureAirport().getCode());
+ LOGGER.info("Departure Airport Name: {}", leg.getDepartureAirport().getName());
+ LOGGER.info("Departure City: {}", leg.getDepartureAirport().getCity());
+ LOGGER.info("Departure Province: {}", leg.getDepartureAirport().getProvince());
+ LOGGER.info("Departure Country: {}", leg.getDepartureAirport().getCountry());
+ LOGGER.info("Departure Latitude: {}", leg.getDepartureAirport().getLatitude());
+ LOGGER.info("Departure Longitude: {}", leg.getDepartureAirport().getLongitude());
+ }
+
+ if (leg.getArrivalAirport() != null) {
+ LOGGER.info("Arrival Airport Code: {}", leg.getArrivalAirport().getCode());
+ LOGGER.info("Arrival Airport Name: {}", leg.getArrivalAirport().getName());
+ LOGGER.info("Arrival City: {}", leg.getArrivalAirport().getCity());
+ LOGGER.info("Arrival Province: {}", leg.getArrivalAirport().getProvince());
+ LOGGER.info("Arrival Country: {}", leg.getArrivalAirport().getCountry());
+ LOGGER.info("Arrival Latitude: {}", leg.getArrivalAirport().getLatitude());
+ LOGGER.info("Arrival Longitude: {}", leg.getArrivalAirport().getLongitude());
+ }
+ LOGGER.info("Departure Date Time: {}", leg.getDepartureDateTime());
+ LOGGER.info("Arrival Date Time: {}", leg.getArrivalDateTime());
+ LOGGER.info("Flight Number: {}", leg.getFlightNumber());
+ LOGGER.info("Marketing Airline Code: {}", leg.getMarketingAirlineCode());
+ LOGGER.info("Marketing Airline Name: {}", leg.getMarketingAirlineName());
+ LOGGER.info("Equipment Code: {}", leg.getEquipmentCode());
+ LOGGER.info("Flight On Time Percentage: {}", leg.getFlightOnTimePercentage());
+ LOGGER.info("Equipment Name: {}", leg.getEquipmentName());
+ LOGGER.info("Flight Duration (Leg): {}", leg.getFlightDuration());
+
+ if (leg.getFlightDistance() != null) {
+ LOGGER.info("Flight Distance Value: {}", leg.getFlightDistance().getValue());
+ LOGGER.info("Flight Distance Unit: {}", leg.getFlightDistance().getUnit());
+ }
+
+ LOGGER.info("Booking Code: {}", leg.getBookingCode());
+ LOGGER.info("Cabin Class: {}", leg.getCabinClass());
+ LOGGER.info("Fare Basis Code: {}", leg.getFareBasisCode());
+ LOGGER.info("Meal Options: {}", leg.getMealOptions());
+ LOGGER.info("Amenities: {}", leg.getAmenities());
+ LOGGER.info("---------- Leg End ----------");
+ });
+ }
+ LOGGER.info("=========== Flight Segment End ============");
+ });
}
- LOGGER.info("=========== Flight Segment End ============");
- });
- }
- if (flightListingsResponse.getOffers() != null) {
- flightListingsResponse.getOffers().forEach(offer -> {
- LOGGER.info("======================== Flight Offer Start ========================");
+ if (flightListingsResponse.getOffers() != null) {
+ flightListingsResponse.getOffers().forEach(offer -> {
+ LOGGER.info("======================== Flight Offer Start ========================");
+
+ if (offer.getLinks() != null) {
+ offer.getLinks().forEach((key, value) -> LOGGER.info("Link [{}]: {}", key, value));
+ }
+
+ LOGGER.info("Segment IDs: {}", offer.getSegmentIds());
+
+ if (offer.getOfferPrice() != null) {
+
+ if (offer.getOfferPrice().getTotalPrice() != null) {
+ LOGGER.info("Total Price Value: {}", offer.getOfferPrice().getTotalPrice().getValue());
+ LOGGER.info("Total Price Currency: {}", offer.getOfferPrice().getTotalPrice().getCurrency());
+ }
+
+ if (offer.getOfferPrice().getBasePrice() != null) {
+ LOGGER.info("Base Price Value: {}", offer.getOfferPrice().getBasePrice().getValue());
+ LOGGER.info("Base Price Currency: {}", offer.getOfferPrice().getBasePrice().getCurrency());
+ }
+
+ if (offer.getOfferPrice().getTotalTaxes() != null) {
+ LOGGER.info("Total Taxes Value: {}", offer.getOfferPrice().getTotalTaxes().getValue());
+ LOGGER.info("Total Taxes Currency: {}", offer.getOfferPrice().getTotalTaxes().getCurrency());
+ }
+
+ if (offer.getOfferPrice().getTotalTaxesAndFees() != null) {
+ LOGGER.info("Total Taxes and Fees Value: {}", offer.getOfferPrice().getTotalTaxesAndFees().getValue());
+ LOGGER.info("Total Taxes and Fees Currency: {}", offer.getOfferPrice().getTotalTaxesAndFees().getCurrency());
+ }
+
+ if (offer.getOfferPrice().getAveragePricePerTicket() != null) {
+ LOGGER.info("Average Price Per Ticket Value: {}", offer.getOfferPrice().getAveragePricePerTicket().getValue());
+ LOGGER.info("Average Price Per Ticket Currency: {}", offer.getOfferPrice().getAveragePricePerTicket().getCurrency());
+ LOGGER.info("Average Price Per Ticket Count: {}", offer.getOfferPrice().getAveragePricePerTicket().getCount());
+ }
+
+ if (offer.getOfferPrice().getPricePerPassengerCategory() != null) {
+ offer.getOfferPrice().getPricePerPassengerCategory().forEach(categoryPrice -> {
+ LOGGER.info("---- Passenger Category Price Start ----");
+ LOGGER.info("Category: {}", categoryPrice.getCategory());
+ LOGGER.info("Count: {}", categoryPrice.getCount());
+
+ if (categoryPrice.getTotalPrice() != null) {
+ LOGGER.info("Total Price Value: {}", categoryPrice.getTotalPrice().getValue());
+ LOGGER.info("Total Price Currency: {}", categoryPrice.getTotalPrice().getCurrency());
+ }
+
+ if (categoryPrice.getBasePrice() != null) {
+ LOGGER.info("Base Price Value: {}", categoryPrice.getBasePrice().getValue());
+ LOGGER.info("Base Price Currency: {}", categoryPrice.getBasePrice().getCurrency());
+ }
+
+ if (categoryPrice.getTotalTaxes() != null) {
+ LOGGER.info("Total Taxes Value: {}", categoryPrice.getTotalTaxes().getValue());
+ LOGGER.info("Total Taxes Currency: {}", categoryPrice.getTotalTaxes().getCurrency());
+ }
+ LOGGER.info("---- Passenger Category Price End ----");
+ });
+ }
+ }
+
+
+ LOGGER.info("Ticket Type: {}", offer.getTicketType());
+ LOGGER.info("======================== Flight Offer End ========================");
+ });
+ }
- if (offer.getLinks() != null) {
- offer.getLinks().forEach((key, value) ->
- LOGGER.info("Link [{}]: {}", key, value));
+ if (flightListingsResponse.getSearchCities() != null) {
+ flightListingsResponse.getSearchCities().forEach(city -> {
+ LOGGER.info("======================== Search City Start ========================");
+ LOGGER.info("City Code: {}", city.getCode());
+ LOGGER.info("City Name: {}", city.getCity());
+ LOGGER.info("Province: {}", city.getProvince());
+ LOGGER.info("Country: {}", city.getCountry());
+ LOGGER.info("======================== Search City End ========================");
+ });
}
- LOGGER.info("Segment IDs: {}", offer.getSegmentIds());
-
- if (offer.getOfferPrice() != null) {
-
- if (offer.getOfferPrice().getTotalPrice() != null) {
- LOGGER.info("Total Price Value: {}",
- offer.getOfferPrice().getTotalPrice().getValue());
- LOGGER.info("Total Price Currency: {}",
- offer.getOfferPrice().getTotalPrice().getCurrency());
- }
-
- if (offer.getOfferPrice().getBasePrice() != null) {
- LOGGER.info("Base Price Value: {}",
- offer.getOfferPrice().getBasePrice().getValue());
- LOGGER.info("Base Price Currency: {}",
- offer.getOfferPrice().getBasePrice().getCurrency());
- }
-
- if (offer.getOfferPrice().getTotalTaxes() != null) {
- LOGGER.info("Total Taxes Value: {}",
- offer.getOfferPrice().getTotalTaxes().getValue());
- LOGGER.info("Total Taxes Currency: {}",
- offer.getOfferPrice().getTotalTaxes().getCurrency());
- }
-
- if (offer.getOfferPrice().getTotalTaxesAndFees() != null) {
- LOGGER.info("Total Taxes and Fees Value: {}",
- offer.getOfferPrice().getTotalTaxesAndFees().getValue());
- LOGGER.info("Total Taxes and Fees Currency: {}",
- offer.getOfferPrice().getTotalTaxesAndFees().getCurrency());
- }
-
- if (offer.getOfferPrice().getAveragePricePerTicket() != null) {
- LOGGER.info("Average Price Per Ticket Value: {}",
- offer.getOfferPrice().getAveragePricePerTicket().getValue());
- LOGGER.info("Average Price Per Ticket Currency: {}",
- offer.getOfferPrice().getAveragePricePerTicket().getCurrency());
- LOGGER.info("Average Price Per Ticket Count: {}",
- offer.getOfferPrice().getAveragePricePerTicket().getCount());
- }
-
- if (offer.getOfferPrice().getPricePerPassengerCategory() != null) {
- offer.getOfferPrice().getPricePerPassengerCategory()
- .forEach(categoryPrice -> {
- LOGGER.info("---- Passenger Category Price Start ----");
- LOGGER.info("Category: {}", categoryPrice.getCategory());
- LOGGER.info("Count: {}", categoryPrice.getCount());
-
- if (categoryPrice.getTotalPrice() != null) {
- LOGGER.info("Total Price Value: {}",
- categoryPrice.getTotalPrice().getValue());
- LOGGER.info("Total Price Currency: {}",
- categoryPrice.getTotalPrice().getCurrency());
- }
-
- if (categoryPrice.getBasePrice() != null) {
- LOGGER.info("Base Price Value: {}",
- categoryPrice.getBasePrice().getValue());
- LOGGER.info("Base Price Currency: {}",
- categoryPrice.getBasePrice().getCurrency());
- }
-
- if (categoryPrice.getTotalTaxes() != null) {
- LOGGER.info("Total Taxes Value: {}",
- categoryPrice.getTotalTaxes().getValue());
- LOGGER.info("Total Taxes Currency: {}",
- categoryPrice.getTotalTaxes().getCurrency());
- }
- LOGGER.info("---- Passenger Category Price End ----");
- });
- }
+ if (flightListingsResponse.getValidFormsOfPayment() != null) {
+ flightListingsResponse.getValidFormsOfPayment().forEach((key, value) -> {
+ LOGGER.info("================= Valid Forms of Payment Start [{}] ============", key);
+ value.forEach(payment -> {
+ LOGGER.info("---- Payment Method Start ----");
+ LOGGER.info("Payment Method: {}", payment.getPaymentMethod());
+ LOGGER.info("Name: {}", payment.getName());
+ LOGGER.info("Fee: {}", payment.getFee());
+ LOGGER.info("Currency: {}", payment.getCurrency());
+ LOGGER.info("---- Payment Method End ----");
+ });
+ LOGGER.info("========== Valid Forms of Payment End [{}] ============", key);
+ });
}
+ LOGGER.info("===================== End FlightListingsQuickStartScenario ====================");
- LOGGER.info("Ticket Type: {}", offer.getTicketType());
- LOGGER.info("======================== Flight Offer End ========================");
- });
- }
+ // --- Example for a Round Trip Search ---
+ LOGGER.info("\n======== Executing GetFlightListingsOperation (Round Trip) ========");
- if (flightListingsResponse.getSearchCities() != null) {
- flightListingsResponse.getSearchCities().forEach(city -> {
- LOGGER.info("======================== Search City Start ========================");
- LOGGER.info("City Code: {}", city.getCode());
- LOGGER.info("City Name: {}", city.getCity());
- LOGGER.info("Province: {}", city.getProvince());
- LOGGER.info("Country: {}", city.getCountry());
- LOGGER.info("======================== Search City End ========================");
- });
- }
+ GetFlightListingsOperationParams roundTripParams = GetFlightListingsOperationParams.builder().partnerTransactionID("txn-123-4").segment1(GetFlightListingsOperationSegmentParam.builder().origin("EWR").destination("LAX").departureDate(now.plusDays(10)).build()).segment2(GetFlightListingsOperationSegmentParam.builder().origin("LAX").destination("EWR").departureDate(now.plusDays(10)).build()).childrenAges(Arrays.asList(4, 5)).adult(1).senior(1).build();
- if (flightListingsResponse.getValidFormsOfPayment() != null) {
- flightListingsResponse.getValidFormsOfPayment().forEach((key, value) -> {
- LOGGER.info("================= Valid Forms of Payment Start [{}] ============", key);
- value.forEach(payment -> {
- LOGGER.info("---- Payment Method Start ----");
- LOGGER.info("Payment Method: {}", payment.getPaymentMethod());
- LOGGER.info("Name: {}", payment.getName());
- LOGGER.info("Fee: {}", payment.getFee());
- LOGGER.info("Currency: {}", payment.getCurrency());
- LOGGER.info("---- Payment Method End ----");
- });
- LOGGER.info("========== Valid Forms of Payment End [{}] ============", key);
- });
- }
+ FlightSearchResponse roundTripResponse = xapClient.execute(new GetFlightListingsOperation(roundTripParams)).getData();
- LOGGER.info(
- "===================== End FlightListingsQuickStartScenario ====================");
-
- // --- Example for a Round Trip Search ---
- LOGGER.info(
- "\n======== Executing GetFlightListingsOperation (Round Trip) ========");
-
- GetFlightListingsOperationParams roundTripParams =
- GetFlightListingsOperationParams.builder()
- .partnerTransactionID("txn-123-4")
- .segment1Origin("EWR")
- .segment1Destination("LAX")
- .segment1DepartureDate(LocalDate.of(2025, 5, 1))
- .segment2Origin("LAX")
- .segment2Destination("EWR")
- .segment2DepartureDate(LocalDate.of(2025, 5, 5))
- .childrenAges(Arrays.asList(4, 5))
- .adult(1)
- .senior(1)
- .build();
-
- FlightSearchResponse roundTripResponse =
- xapClient.execute(new GetFlightListingsOperation(roundTripParams)).getData();
-
- LOGGER.info(
- "========= GetFlightListingsOperation (Round Trip) Executed ==============");
-
- if (roundTripResponse != null && roundTripResponse.getSegments() != null
- && roundTripResponse.getSegments().size() == 2) {
- LOGGER.info("Round trip search returned {} segments.",
- roundTripResponse.getSegments().size());
- }
+ LOGGER.info("========= GetFlightListingsOperation (Round Trip) Executed ==============");
+
+ if (roundTripResponse != null && roundTripResponse.getSegments() != null && roundTripResponse.getSegments().size() == 2) {
+ LOGGER.info("Round trip search returned {} segments.", roundTripResponse.getSegments().size());
+ }
+
+ // --- Example for a Multi-Stop Search ---
+ LOGGER.info("\n========= Executing GetFlightListingsOperation (Multi-Stop) ==========");
+
+ GetFlightListingsOperationParams multiStopParams = GetFlightListingsOperationParams.builder().partnerTransactionID("txn-123-4").segment1(GetFlightListingsOperationSegmentParam.builder().origin("LAS").destination("ATL").departureDate(now.plusDays(5)).build()).segment2(GetFlightListingsOperationSegmentParam.builder().origin("ORD").destination("SEA").departureDate(now.plusDays(10)).build()).adult(1).senior(1).childrenAges(Arrays.asList(4, 5)).build();
- // --- Example for a Multi-Stop Search ---
- LOGGER.info(
- "\n========= Executing GetFlightListingsOperation (Multi-Stop) ==========");
-
- GetFlightListingsOperationParams multiStopParams =
- GetFlightListingsOperationParams.builder()
- .partnerTransactionID("txn-123-4")
- .segment1Origin("LAS")
- .segment1Destination("ATL")
- .segment1DepartureDate(LocalDate.of(2025, 5, 1))
- .segment2Origin("ORD")
- .segment2Destination("SEA")
- .segment2DepartureDate(LocalDate.of(2025, 5, 5))
- .adult(1)
- .senior(1)
- .childrenAges(Arrays.asList(4, 5))
- .build();
-
- FlightSearchResponse multiStopResponse =
- xapClient.execute(new GetFlightListingsOperation(multiStopParams)).getData();
-
- LOGGER.info(
- "============ GetFlightListingsOperation (Multi-Stop) Executed ===========");
-
- if (multiStopResponse != null && multiStopResponse.getSegments() != null
- && multiStopResponse.getSegments().size() == 3) {
- LOGGER.info("Multi-stop search returned {} segments.",
- multiStopResponse.getSegments().size());
+ FlightSearchResponse multiStopResponse = xapClient.execute(new GetFlightListingsOperation(multiStopParams)).getData();
+
+ LOGGER.info("============ GetFlightListingsOperation (Multi-Stop) Executed ===========");
+
+ if (multiStopResponse != null && multiStopResponse.getSegments() != null && multiStopResponse.getSegments().size() == 3) {
+ LOGGER.info("Multi-stop search returned {} segments.", multiStopResponse.getSegments().size());
+ }
}
- }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java
index fc645a330..7b848f6d6 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java
@@ -20,8 +20,10 @@
import com.expediagroup.sdk.xap.models.AvailabilityCalendarResponse;
import com.expediagroup.sdk.xap.operations.GetLodgingAvailabilityCalendarsOperation;
import com.expediagroup.sdk.xap.operations.GetLodgingAvailabilityCalendarsOperationParams;
+
import java.util.Arrays;
import java.util.HashSet;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,78 +34,61 @@
* Note: this is a Vrbo scenario. You need a key that is enabled for Vrbo brand to run this.
*/
public class AvailabilityCalendarsQuickStartScenario implements VrboScenario {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AvailabilityCalendarsQuickStartScenario.class);
- private static final Logger LOGGER =
- LoggerFactory.getLogger(AvailabilityCalendarsQuickStartScenario.class);
-
- public static void main(String[] args) {
- new AvailabilityCalendarsQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- // This example returns the availability of each day for a range of dates for given Expedia
- // lodging properties.
+ public static void main(String[] args) {
+ new AvailabilityCalendarsQuickStartScenario().run();
+ System.exit(0);
+ }
- LOGGER.info(
- "=================== Running AvailabilityCalendarsQuickStartScenario ===================");
+ @Override
+ public void run() {
+ // This example returns the availability of each day for a range of dates for given Expedia
+ // lodging properties.
- LOGGER.info(
- "================= Executing GetLodgingAvailabilityCalendars Operation ================");
+ LOGGER.info("=================== Running AvailabilityCalendarsQuickStartScenario ===================");
+ LOGGER.info("================= Executing GetLodgingAvailabilityCalendars Operation ================");
- // Build the query parameters with GetLodgingAvailabilityCalendarsOperationParams
- GetLodgingAvailabilityCalendarsOperationParams availabilityCalendarsOperationParams =
- GetLodgingAvailabilityCalendarsOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ // Build the query parameters with GetLodgingAvailabilityCalendarsOperationParams
+ GetLodgingAvailabilityCalendarsOperationParams availabilityCalendarsOperationParams = GetLodgingAvailabilityCalendarsOperationParams.builder().partnerTransactionId(PARTNER_TRANSACTION_ID)
// Set of Expedia Property IDs.
- .propertyIds(new HashSet<>(Arrays.asList("87704892", "36960201")))
- .build();
-
- XapClient xapClient = createClient();
-
- // Execute the operation and get the AvailabilityCalendarsResponse
- AvailabilityCalendarResponse availabilityCalendarResponse =
- xapClient.execute(new GetLodgingAvailabilityCalendarsOperation(
- availabilityCalendarsOperationParams)).getData();
-
- // If you want to use the async method, you can use the following code:
- // ---------------------------------------------------------------
- // CompletableFuture> completableFuture =
- // xapClient.executeAsync(
- // new GetLodgingAvailabilityCalendarsOperation(availabilityCalendarsOperationParams));
- // completableFuture.thenAccept(availCalendarResponse -> {
- // // Your code here
- // });
- // ---------------------------------------------------------------
-
- LOGGER.info(
- "================== GetLodgingAvailabilityCalendarsOperation Executed =================");
-
- if (availabilityCalendarResponse == null
- || availabilityCalendarResponse.getAvailabilityCalendars() == null
- || availabilityCalendarResponse.getAvailabilityCalendars().isEmpty()) {
- throw new IllegalStateException("No properties found.");
+ .propertyIds(new HashSet<>(Arrays.asList("87704892", "36960201"))).build();
+
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the AvailabilityCalendarsResponse
+ AvailabilityCalendarResponse availabilityCalendarResponse = xapClient.execute(new GetLodgingAvailabilityCalendarsOperation(availabilityCalendarsOperationParams)).getData();
+
+ // If you want to use the async method, you can use the following code:
+ // ---------------------------------------------------------------
+ // CompletableFuture> completableFuture =
+ // xapClient.executeAsync(
+ // new GetLodgingAvailabilityCalendarsOperation(availabilityCalendarsOperationParams));
+ // completableFuture.thenAccept(availCalendarResponse -> {
+ // // Your code here
+ // });
+ // ---------------------------------------------------------------
+
+ LOGGER.info("================== GetLodgingAvailabilityCalendarsOperation Executed =================");
+
+ if (availabilityCalendarResponse == null || availabilityCalendarResponse.getAvailabilityCalendars() == null || availabilityCalendarResponse.getAvailabilityCalendars().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
+ }
+
+ // The AvailabilityCalendarsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", availabilityCalendarResponse.getTransactionId());
+
+ // To access the properties, iterate through the list of properties
+ availabilityCalendarResponse.getAvailabilityCalendars().forEach(availCalendar -> {
+ LOGGER.info("========== Property:{} Start ==========", availCalendar.getPropertyId());
+
+ // Availability of property: A string of codes that shows property availability, one for every
+ // day in the specified date range.
+ // Valid values include Y (available) and N (unavailable).
+ LOGGER.info("Availability: {}", availCalendar.getAvailability());
+ LOGGER.info("==================================== Property End ===================================");
+ LOGGER.info("===================== End AvailabilityCalendarsQuickStartScenario ====================");
+ });
}
-
- // The AvailabilityCalendarsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", availabilityCalendarResponse.getTransactionId());
-
- // To access the properties, iterate through the list of properties
- availabilityCalendarResponse.getAvailabilityCalendars().forEach(availCalendar -> {
- LOGGER.info("========== Property:{} Start ==========", availCalendar.getPropertyId());
-
- // Availability of property: A string of codes that shows property availability, one for every
- // day in the specified date range.
- // Valid values include Y (available) and N (unavailable).
- LOGGER.info("Availability: {}", availCalendar.getAvailability());
-
- LOGGER.info(
- "==================================== Property End ===================================");
-
- LOGGER.info(
- "===================== End AvailabilityCalendarsQuickStartScenario ====================");
- });
- }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/HotelIdsSearchEndToEndScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/HotelIdsSearchEndToEndScenario.java
index c83875a16..73c308ec3 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/HotelIdsSearchEndToEndScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/HotelIdsSearchEndToEndScenario.java
@@ -29,6 +29,7 @@
import com.expediagroup.sdk.xap.operations.GetLodgingListingsOperationParams;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -43,6 +44,7 @@
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,150 +57,132 @@
* property id list, content and prices to improve respond time of your pages.
*/
public class HotelIdsSearchEndToEndScenario implements XapScenario {
+ private final XapClient client = createClient();
- private final XapClient client = createClient();
+ private static final Logger LOGGER = LoggerFactory.getLogger(HotelIdsSearchEndToEndScenario.class);
- private static final Logger LOGGER =
- LoggerFactory.getLogger(HotelIdsSearchEndToEndScenario.class);
+ /**
+ * This field limits the number of line to read from the SDP DownloadURL API Listings file to
+ * reduce time to run the example.
+ * If the first 20 properties from the file are not accessible OR available when you run this
+ * example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
+ * you can adjust the property count to get more properties.
+ */
+ private static final int SAMPLE_ITEMS_RESTRICTION = 20;
- /**
- * This field limits the number of line to read from the SDP DownloadURL API Listings file to
- * reduce time to run the example.
- * If the first 20 properties from the file are not accessible OR available when you run this
- * example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
- * you can adjust the property count to get more properties.
- */
- private static final int SAMPLE_ITEMS_RESTRICTION = 20;
+ public static void main(String[] args) {
+ new HotelIdsSearchEndToEndScenario().run();
+ System.exit(0);
+ }
- public static void main(String[] args) {
- new HotelIdsSearchEndToEndScenario().run();
- System.exit(0);
- }
+ @Override
+ public void run() {
+ LOGGER.info("======================== Running HotelIdsSearchEndToEndScenario =======================");
- @Override
- public void run() {
- LOGGER.info(
- "======================== Running HotelIdsSearchEndToEndScenario =======================");
+ List propertyIds = getPropertyIdsFromDownloadUrl();
+ HotelListingsResponse hotelListingsResponse = getPropertiesFromLodgingListings(propertyIds);
+ displayResult(hotelListingsResponse);
- List propertyIds = getPropertyIdsFromDownloadUrl();
- HotelListingsResponse hotelListingsResponse = getPropertiesFromLodgingListings(propertyIds);
- displayResult(hotelListingsResponse);
+ LOGGER.info("========================== End HotelIdsSearchEndToEndScenario =========================");
+ }
- LOGGER.info(
- "========================== End HotelIdsSearchEndToEndScenario =========================");
- }
+ /**
+ * Retrieve accessible property ids from SDP DownloadURL API.
+ *
+ * @return property ids
+ */
+ private List getPropertyIdsFromDownloadUrl() {
+ LOGGER.info("==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
- /**
- * Retrieve accessible property ids from SDP DownloadURL API.
- *
- * @return property ids
- */
- private List getPropertyIdsFromDownloadUrl() {
- LOGGER.info(
- "==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
+ GetFeedDownloadUrlOperationParams getPropertyIdListParams = GetFeedDownloadUrlOperationParams.builder()
+ // Use the type LISTINGS to get the list of accessible property ids.
+ .type(GetFeedDownloadUrlOperationParams.Type.LISTINGS)
+ // Without any filters, this operation will return the information of all lodging
+ // properties in en_US by default.
+ .build();
- GetFeedDownloadUrlOperationParams getPropertyIdListParams =
- GetFeedDownloadUrlOperationParams.builder()
- // Use the type LISTINGS to get the list of accessible property ids.
- .type(GetFeedDownloadUrlOperationParams.Type.LISTINGS)
- // Without any filters, this operation will return the information of all lodging
- // properties in en_US by default.
- .build();
+ Response downloadUrlListingsResponse = client.execute(new GetFeedDownloadUrlOperation(getPropertyIdListParams));
- Response downloadUrlListingsResponse =
- client.execute(new GetFeedDownloadUrlOperation(getPropertyIdListParams));
+ if (downloadUrlListingsResponse.getData() == null || downloadUrlListingsResponse.getData().getBestMatchedFile() == null) {
+ throw new IllegalStateException("No listings file found");
+ }
- if (downloadUrlListingsResponse.getData() == null
- || downloadUrlListingsResponse.getData().getBestMatchedFile() == null) {
- throw new IllegalStateException("No listings file found");
- }
+ // The download URL points to a zip file containing various jsonl files.
+ // Each line in the jsonl files contains a json object representing a property.
+ // For demonstration purposes, we will only read a few properties from the file without
+ // downloading the entire file.
+ String listingsDownloadUrl = downloadUrlListingsResponse.getData().getBestMatchedFile().getDownloadUrl();
+ LOGGER.info("Listings Download URL: {}", listingsDownloadUrl);
- // The download URL points to a zip file containing various jsonl files.
- // Each line in the jsonl files contains a json object representing a property.
- // For demonstration purposes, we will only read a few properties from the file without
- // downloading the entire file.
- String listingsDownloadUrl = downloadUrlListingsResponse.getData()
- .getBestMatchedFile()
- .getDownloadUrl();
- LOGGER.info("Listings Download URL: {}", listingsDownloadUrl);
+ // Read property ids from the file.
+ List propertyIds = getPropertyIdsFromListingsFile(listingsDownloadUrl);
- // Read property ids from the file.
- List propertyIds = getPropertyIdsFromListingsFile(listingsDownloadUrl);
+ if (propertyIds.isEmpty()) {
+ throw new IllegalStateException("No accessible property ids found.");
+ }
+ LOGGER.info("Accessible Property Ids: {}", propertyIds);
+ LOGGER.info("==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
- if (propertyIds.isEmpty()) {
- throw new IllegalStateException("No accessible property ids found.");
+ return propertyIds;
}
- LOGGER.info("Accessible Property Ids: {}", propertyIds);
-
- LOGGER.info(
- "==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
- return propertyIds;
- }
- /**
- * Get prices of the properties using the Lodging Listings API.
- *
- * @param propertyIds The property ids to get the prices.
- * @return The response of the Lodging Listings API.
- */
- private HotelListingsResponse getPropertiesFromLodgingListings(List propertyIds) {
- LOGGER.info(
- "================ Step II: Executing getPropertiesFromLodgingListings ===============");
+ /**
+ * Get prices of the properties using the Lodging Listings API.
+ *
+ * @param propertyIds The property ids to get the prices.
+ * @return The response of the Lodging Listings API.
+ */
+ private HotelListingsResponse getPropertiesFromLodgingListings(List propertyIds) {
+ LOGGER.info("================ Step II: Executing getPropertiesFromLodgingListings ===============");
- GetLodgingListingsOperationParams getLodgingListingsOperationParams =
- GetLodgingListingsOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
- // Use the property ids read from the file
- .ecomHotelIds(new HashSet<>(propertyIds))
- // The links to return, WEB includes WS (Web Search Result Page)
- // and WD (Web Details Page)
- .links(Collections.singletonList(GetLodgingListingsOperationParams.Links.WEB))
- // Check-in 5 days from now
- .checkIn(LocalDate.now().plusDays(5))
- // Check-out 10 days from now
- .checkOut(LocalDate.now().plusDays(10))
- // Filter the properties that are available only
- .availOnly(true)
- // Use the default occupancy: 2 adults in one room
- .build();
+ GetLodgingListingsOperationParams getLodgingListingsOperationParams = GetLodgingListingsOperationParams.builder().partnerTransactionId(PARTNER_TRANSACTION_ID)
+ // Use the property ids read from the file
+ .ecomHotelIds(new HashSet<>(propertyIds))
+ // The links to return, WEB includes WS (Web Search Result Page)
+ // and WD (Web Details Page)
+ .links(Collections.singletonList(GetLodgingListingsOperationParams.Links.WEB))
+ // Check-in 5 days from now
+ .checkIn(LocalDate.now().plusDays(5))
+ // Check-out 10 days from now
+ .checkOut(LocalDate.now().plusDays(10))
+ // Filter the properties that are available only
+ .availOnly(true)
+ // Use the default occupancy: 2 adults in one room
+ .build();
- HotelListingsResponse hotelListingsResponse =
- client.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams))
- .getData();
+ HotelListingsResponse hotelListingsResponse = client.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams)).getData();
+ LOGGER.info("================ Step II: getPropertiesFromLodgingListings Executed ================");
- LOGGER.info(
- "================ Step II: getPropertiesFromLodgingListings Executed ================");
- return hotelListingsResponse;
- }
+ return hotelListingsResponse;
+ }
- /**
- * Reads given number of property ids from the file pointed by the download URL.
- *
- * @param downloadUrl The download URL of the zip file containing the property information.
- * @return A list of property ids read from the file.
- */
- private List getPropertyIdsFromListingsFile(String downloadUrl) {
- List propertyIds = new ArrayList<>();
- HttpURLConnection connection = null;
- try {
- // Open a connection to the URL
- URL url = new URL(downloadUrl);
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("GET");
- connection.setDoInput(true);
+ /**
+ * Reads given number of property ids from the file pointed by the download URL.
+ *
+ * @param downloadUrl The download URL of the zip file containing the property information.
+ * @return A list of property ids read from the file.
+ */
+ private List getPropertyIdsFromListingsFile(String downloadUrl) {
+ List propertyIds = new ArrayList<>();
+ HttpURLConnection connection = null;
+ try {
+ // Open a connection to the URL
+ URL url = new URL(downloadUrl);
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setDoInput(true);
- try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
- ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
- if (entry.getName().endsWith(".jsonl")) {
- LOGGER.info("Reading property ids from file: {}", entry.getName());
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
- String line;
- ObjectMapper objectMapper = new ObjectMapper();
- while ((line = reader.readLine()) != null
- && propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
- // Parse the property id from the json object
- // An example json line from the jsonl file:
+ try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
+ ZipEntry entry;
+ while ((entry = zipStream.getNextEntry()) != null) {
+ if (entry.getName().endsWith(".jsonl")) {
+ LOGGER.info("Reading property ids from file: {}", entry.getName());
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
+ String line;
+ ObjectMapper objectMapper = new ObjectMapper();
+ while ((line = reader.readLine()) != null && propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
+ // Parse the property id from the json object
+ // An example json line from the jsonl file:
/*
{
"propertyId": {
@@ -227,126 +211,113 @@ private List getPropertyIdsFromListingsFile(String downloadUrl) {
}
}
*/
- JsonNode jsonNode = objectMapper.readTree(line);
- // Check if the property is accessible from Lodging Listings API
- // (Vrbo properties that are not instantBookable are not accessible for now)
- if (!jsonNode.get("propertyId").get("vrbo").asText().isEmpty()
- && jsonNode.has("vrboPropertyType")
- && !jsonNode.get("vrboPropertyType").get("instantBook").asBoolean()
- ) {
- // Skip the property if it is not an instant bookable Vrbo property
- continue;
- } else {
- // Get the Expedia property id for the Lodging Listings API
- propertyIds.add(jsonNode.get("propertyId").get("expedia").asText());
+ JsonNode jsonNode = objectMapper.readTree(line);
+ // Check if the property is accessible from Lodging Listings API
+ // (Vrbo properties that are not instantBookable are not accessible for now)
+ if (!jsonNode.get("propertyId").get("vrbo").asText().isEmpty() && jsonNode.has("vrboPropertyType") && !jsonNode.get("vrboPropertyType").get("instantBook").asBoolean()) {
+ // Skip the property if it is not an instant bookable Vrbo property
+ continue;
+ } else {
+ // Get the Expedia property id for the Lodging Listings API
+ propertyIds.add(jsonNode.get("propertyId").get("expedia").asText());
+ }
+ }
+ }
+ }
}
- }
}
- }
- }
- }
- } catch (IOException e) {
- LOGGER.error("Error reading property ids from download URL", e);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
+ } catch (IOException e) {
+ LOGGER.error("Error reading property ids from download URL", e);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return propertyIds;
}
- return propertyIds;
- }
- /**
- * Display the result of the operations.
- *
- * @param hotelListingsResponse The response of the Lodging Listings API.
- */
- private static void displayResult(HotelListingsResponse hotelListingsResponse) {
- LOGGER.info("====================== Executing Step III: DisplayResult =======================");
- if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null
- || hotelListingsResponse.getHotels().isEmpty()) {
- throw new IllegalStateException("No properties found.");
- }
+ /**
+ * Display the result of the operations.
+ *
+ * @param hotelListingsResponse The response of the Lodging Listings API.
+ */
+ private static void displayResult(HotelListingsResponse hotelListingsResponse) {
+ LOGGER.info("====================== Executing Step III: DisplayResult =======================");
+ if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null || hotelListingsResponse.getHotels().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
+ }
- // The HotelListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", hotelListingsResponse.getTransactionId());
+ // The HotelListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", hotelListingsResponse.getTransactionId());
- // To access the properties, iterate through the list of hotel properties
- hotelListingsResponse.getHotels().forEach(hotel -> {
- // Check if the property is available
- if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
- LOGGER.info("Property {} is not available.", hotel.getId());
- return;
- }
- LOGGER.info(
- "=================================== Property Start ===================================");
- // To get the property name
- if (StringUtils.isNotEmpty(hotel.getName())) {
- LOGGER.info("Property Name: {}", hotel.getName());
- }
- // To get the property address
- if (hotel.getLocation() != null) {
- LOGGER.info("Property Address: {}", hotel.getLocation().getAddress());
- }
- // To get the property thumbnail URL
- if (StringUtils.isNotEmpty(hotel.getThumbnailUrl())) {
- LOGGER.info("Thumbnail URL: {}", hotel.getThumbnailUrl());
- }
- // To get the star rating of the property. The value is between 1.0 and 5.0
- // in a 0.5 increment.
- if (hotel.getStarRating() != null) {
- LOGGER.info("Star Rating: {}", hotel.getStarRating().getValue());
- }
- // To get the guest rating of the property. The value is between 1.0 and 5.0
- // in a 0.1 increment.
- if (StringUtils.isNotEmpty(hotel.getGuestRating())) {
- LOGGER.info("Guest Rating: {}", hotel.getGuestRating());
- }
- // To get the total number of reviews for the property
- if (hotel.getGuestReviewCount() != null) {
- LOGGER.info("Review Count: {}", hotel.getGuestReviewCount());
- }
- if (hotel.getRoomTypes() != null && !hotel.getRoomTypes().isEmpty()) {
- // To get the first room type information
- RoomType roomType = hotel.getRoomTypes().get(0);
- if (StringUtils.isNotEmpty(roomType.getDescription())) {
- LOGGER.info("Room Type: {}", roomType.getDescription());
- }
- if (roomType.getPrice() != null) {
- // To get the total price of the room type
- if (roomType.getPrice().getTotalPrice() != null) {
- LOGGER.info("Price: {}, Currency: {}",
- roomType.getPrice().getTotalPrice().getValue(),
- roomType.getPrice().getTotalPrice().getCurrency());
- }
- // To get the average nightly rate of the room type
- if (roomType.getPrice().getAvgNightlyRate() != null) {
- LOGGER.info("Average Nightly Rate: {}, Currency: {}",
- roomType.getPrice().getAvgNightlyRate().getValue(),
- roomType.getPrice().getAvgNightlyRate().getCurrency());
- }
- }
- // To get the free cancellation flag of the selected room
- if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
- && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
- LOGGER.info("Free Cancellation: {}",
- roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
- }
- if (roomType.getLinks() != null) {
- // To get the deeplink to the Expedia Web Search Result Page
- if (roomType.getLinks().getWebSearchResult() != null) {
- LOGGER.info("WebSearchResult Link: {}",
- roomType.getLinks().getWebSearchResult().getHref());
- }
- // To get the deeplink to the Expedia Web Details Page
- if (roomType.getLinks().getWebDetails() != null) {
- LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
- }
- }
- }
- LOGGER.info(
- "==================================== Property End ====================================");
- });
- LOGGER.info("====================== Step III: DisplayResult Executed ========================");
- }
+ // To access the properties, iterate through the list of hotel properties
+ hotelListingsResponse.getHotels().forEach(hotel -> {
+ // Check if the property is available
+ if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
+ LOGGER.info("Property {} is not available.", hotel.getId());
+ return;
+ }
+ LOGGER.info("=================================== Property Start ===================================");
+ // To get the property name
+ if (StringUtils.isNotEmpty(hotel.getName())) {
+ LOGGER.info("Property Name: {}", hotel.getName());
+ }
+ // To get the property address
+ if (hotel.getLocation() != null) {
+ LOGGER.info("Property Address: {}", hotel.getLocation().getAddress());
+ }
+ // To get the property thumbnail URL
+ if (StringUtils.isNotEmpty(hotel.getThumbnailUrl())) {
+ LOGGER.info("Thumbnail URL: {}", hotel.getThumbnailUrl());
+ }
+ // To get the star rating of the property. The value is between 1.0 and 5.0
+ // in a 0.5 increment.
+ if (hotel.getStarRating() != null) {
+ LOGGER.info("Star Rating: {}", hotel.getStarRating().getValue());
+ }
+ // To get the guest rating of the property. The value is between 1.0 and 5.0
+ // in a 0.1 increment.
+ if (StringUtils.isNotEmpty(hotel.getGuestRating())) {
+ LOGGER.info("Guest Rating: {}", hotel.getGuestRating());
+ }
+ // To get the total number of reviews for the property
+ if (hotel.getGuestReviewCount() != null) {
+ LOGGER.info("Review Count: {}", hotel.getGuestReviewCount());
+ }
+ if (hotel.getRoomTypes() != null && !hotel.getRoomTypes().isEmpty()) {
+ // To get the first room type information
+ RoomType roomType = hotel.getRoomTypes().get(0);
+ if (StringUtils.isNotEmpty(roomType.getDescription())) {
+ LOGGER.info("Room Type: {}", roomType.getDescription());
+ }
+ if (roomType.getPrice() != null) {
+ // To get the total price of the room type
+ if (roomType.getPrice().getTotalPrice() != null) {
+ LOGGER.info("Price: {}, Currency: {}", roomType.getPrice().getTotalPrice().getValue(), roomType.getPrice().getTotalPrice().getCurrency());
+ }
+ // To get the average nightly rate of the room type
+ if (roomType.getPrice().getAvgNightlyRate() != null) {
+ LOGGER.info("Average Nightly Rate: {}, Currency: {}", roomType.getPrice().getAvgNightlyRate().getValue(), roomType.getPrice().getAvgNightlyRate().getCurrency());
+ }
+ }
+ // To get the free cancellation flag of the selected room
+ if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty() && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
+ LOGGER.info("Free Cancellation: {}", roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ }
+ if (roomType.getLinks() != null) {
+ // To get the deeplink to the Expedia Web Search Result Page
+ if (roomType.getLinks().getWebSearchResult() != null) {
+ LOGGER.info("WebSearchResult Link: {}", roomType.getLinks().getWebSearchResult().getHref());
+ }
+ // To get the deeplink to the Expedia Web Details Page
+ if (roomType.getLinks().getWebDetails() != null) {
+ LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
+ }
+ }
+ }
+ LOGGER.info("==================================== Property End ====================================");
+ });
+ LOGGER.info("====================== Step III: DisplayResult Executed ========================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java
index 4d1cb73fe..0c3ba0183 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java
@@ -24,9 +24,11 @@
import com.expediagroup.sdk.xap.models.RoomType;
import com.expediagroup.sdk.xap.operations.GetLodgingListingsOperation;
import com.expediagroup.sdk.xap.operations.GetLodgingListingsOperationParams;
+
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
+
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,45 +38,39 @@
* applied.
*/
public class ListingsQuickStartScenario implements XapScenario {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ListingsQuickStartScenario.class);
+
+ public static void main(String[] args) {
+ new ListingsQuickStartScenario().run();
+ System.exit(0);
+ }
- private static final Logger LOGGER = LoggerFactory.getLogger(ListingsQuickStartScenario.class);
-
- public static void main(String[] args) {
- new ListingsQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- // This example will search for properties with the following criteria:
- // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
- // in the second room;
- // 2. Properties located within 10 km of the Space Needle in Seattle;
- // 3. Check-in date 5 days from now, check-out date 10 days from now;
- // 4. Return web links to Expedia website;
- // 5. Limit the results to 5 properties;
- // 6. Order the results by price in ascending order.
-
- LOGGER.info(
- "========================== Running ListingsQuickStartScenario =========================");
-
- LOGGER.info(
- "======================== Executing GetLodgingListingsOperation =======================");
-
- // Build the occupancy
- ArrayList rooms = new ArrayList<>();
- // The first room, with 1 adult
- rooms.add(Room.builder().adults(1L).build());
- // The second room, with 2 adults and 2 children
- ArrayList childrenAges = new ArrayList<>();
- childrenAges.add(10L);
- childrenAges.add(12L);
- rooms.add(Room.builder().adults(2L).childAges(childrenAges).build());
-
- // Build the query parameters with GetLodgingListingsOperationParams
- GetLodgingListingsOperationParams getLodgingListingsOperationParams =
- GetLodgingListingsOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ @Override
+ public void run() {
+ // This example will search for properties with the following criteria:
+ // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
+ // in the second room;
+ // 2. Properties located within 10 km of the Space Needle in Seattle;
+ // 3. Check-in date 5 days from now, check-out date 10 days from now;
+ // 4. Return web links to Expedia website;
+ // 5. Limit the results to 5 properties;
+ // 6. Order the results by price in ascending order.
+
+ LOGGER.info("========================== Running ListingsQuickStartScenario =========================");
+ LOGGER.info("======================== Executing GetLodgingListingsOperation =======================");
+
+ // Build the occupancy
+ ArrayList rooms = new ArrayList<>();
+ // The first room, with 1 adult
+ rooms.add(Room.builder().adults(1L).build());
+ // The second room, with 2 adults and 2 children
+ ArrayList childrenAges = new ArrayList<>();
+ childrenAges.add(10L);
+ childrenAges.add(12L);
+ rooms.add(Room.builder().adults(2L).childAges(childrenAges).build());
+
+ // Build the query parameters with GetLodgingListingsOperationParams
+ GetLodgingListingsOperationParams getLodgingListingsOperationParams = GetLodgingListingsOperationParams.builder().partnerTransactionId(PARTNER_TRANSACTION_ID)
// The location keyword can be a city, address, airport or a landmark.
.locationKeyword("Space Needle, Seattle")
// The radius specifies the size of search area around the location keyword.
@@ -94,116 +90,100 @@ public void run() {
// Limit the results to 5 properties
.limit(5)
// Order the results by price in ascending order
- .sortType(GetLodgingListingsOperationParams.SortType.PRICE)
- .sortOrder(GetLodgingListingsOperationParams.SortOrder.ASC)
- .build();
-
- XapClient xapClient = createClient();
-
- // Execute the operation and get the HotelListingsResponse
- HotelListingsResponse hotelListingsResponse =
- xapClient.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams))
- .getData();
-
- // If you want to use the async method, you can use the following code:
- // ---------------------------------------------------------------
- // CompletableFuture> completableFuture =
- // xapClient.executeAsync(
- // new GetLodgingListingsOperation(getLodgingListingsOperationParams));
- // completableFuture.thenAccept(hotelListingsResponse -> {
- // // Your code here
- // });
- // ---------------------------------------------------------------
-
- LOGGER.info(
- "======================== GetLodgingListingsOperation Executed ========================");
-
- if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null
- || hotelListingsResponse.getHotels().isEmpty()) {
- throw new IllegalStateException("No properties found.");
- }
+ .sortType(GetLodgingListingsOperationParams.SortType.PRICE).sortOrder(GetLodgingListingsOperationParams.SortOrder.ASC).build();
- // The HotelListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", hotelListingsResponse.getTransactionId());
-
- // To access the properties, iterate through the list of hotel properties
- hotelListingsResponse.getHotels().forEach(hotel -> {
- // Check if the property is available
- if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
- LOGGER.info("Property {} is not available.", hotel.getId());
- return;
- }
- LOGGER.info(
- "=================================== Property Start ===================================");
- // To get the property name
- if (StringUtils.isNotEmpty(hotel.getName())) {
- LOGGER.info("Property Name: {}", hotel.getName());
- }
- // To get the property address
- if (hotel.getLocation() != null) {
- LOGGER.info("Property Address: {}", hotel.getLocation().getAddress());
- }
- // To get the property thumbnail URL
- if (StringUtils.isNotEmpty(hotel.getThumbnailUrl())) {
- LOGGER.info("Thumbnail URL: {}", hotel.getThumbnailUrl());
- }
- // To get the star rating of the property. The value is between 1.0 and 5.0
- // in a 0.5 increment.
- if (hotel.getStarRating() != null) {
- LOGGER.info("Star Rating: {}", hotel.getStarRating().getValue());
- }
- // To get the guest rating of the property. The value is between 1.0 and 5.0
- // in a 0.1 increment.
- if (StringUtils.isNotEmpty(hotel.getGuestRating())) {
- LOGGER.info("Guest Rating: {}", hotel.getGuestRating());
- }
- // To get the total number of reviews for the property
- if (hotel.getGuestReviewCount() != null) {
- LOGGER.info("Review Count: {}", hotel.getGuestReviewCount());
- }
- if (hotel.getRoomTypes() != null && !hotel.getRoomTypes().isEmpty()) {
- // To get the first room type information
- RoomType roomType = hotel.getRoomTypes().get(0);
- if (StringUtils.isNotEmpty(roomType.getDescription())) {
- LOGGER.info("Room Type: {}", roomType.getDescription());
- }
- if (roomType.getPrice() != null) {
- // To get the total price of the room type
- if (roomType.getPrice().getTotalPrice() != null) {
- LOGGER.info("Price: {}, Currency: {}",
- roomType.getPrice().getTotalPrice().getValue(),
- roomType.getPrice().getTotalPrice().getCurrency());
- }
- // To get the average nightly rate of the room type
- if (roomType.getPrice().getAvgNightlyRate() != null) {
- LOGGER.info("Average Nightly Rate: {}, Currency: {}",
- roomType.getPrice().getAvgNightlyRate().getValue(),
- roomType.getPrice().getAvgNightlyRate().getCurrency());
- }
- }
- // To get the free cancellation flag of the selected room
- if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
- && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
- LOGGER.info("Free Cancellation: {}",
- roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
- }
- if (roomType.getLinks() != null) {
- // To get the deeplink to the Expedia Web Search Result Page
- if (roomType.getLinks().getWebSearchResult() != null) {
- LOGGER.info("WebSearchResult Link: {}",
- roomType.getLinks().getWebSearchResult().getHref());
- }
- // To get the deeplink to the Expedia Web Details Page
- if (roomType.getLinks().getWebDetails() != null) {
- LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
- }
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the HotelListingsResponse
+ HotelListingsResponse hotelListingsResponse = xapClient.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams)).getData();
+
+ // If you want to use the async method, you can use the following code:
+ // ---------------------------------------------------------------
+ // CompletableFuture> completableFuture =
+ // xapClient.executeAsync(
+ // new GetLodgingListingsOperation(getLodgingListingsOperationParams));
+ // completableFuture.thenAccept(hotelListingsResponse -> {
+ // // Your code here
+ // });
+ // ---------------------------------------------------------------
+
+ LOGGER.info("======================== GetLodgingListingsOperation Executed ========================");
+
+ if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null || hotelListingsResponse.getHotels().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
}
- }
- LOGGER.info(
- "==================================== Property End ====================================");
- });
-
- LOGGER.info(
- "============================ End ListingsQuickStartScenario ===========================");
- }
+
+ // The HotelListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", hotelListingsResponse.getTransactionId());
+
+ // To access the properties, iterate through the list of hotel properties
+ hotelListingsResponse.getHotels().forEach(hotel -> {
+ // Check if the property is available
+ if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
+ LOGGER.info("Property {} is not available.", hotel.getId());
+ return;
+ }
+ LOGGER.info("=================================== Property Start ===================================");
+ // To get the property name
+ if (StringUtils.isNotEmpty(hotel.getName())) {
+ LOGGER.info("Property Name: {}", hotel.getName());
+ }
+ // To get the property address
+ if (hotel.getLocation() != null) {
+ LOGGER.info("Property Address: {}", hotel.getLocation().getAddress());
+ }
+ // To get the property thumbnail URL
+ if (StringUtils.isNotEmpty(hotel.getThumbnailUrl())) {
+ LOGGER.info("Thumbnail URL: {}", hotel.getThumbnailUrl());
+ }
+ // To get the star rating of the property. The value is between 1.0 and 5.0
+ // in a 0.5 increment.
+ if (hotel.getStarRating() != null) {
+ LOGGER.info("Star Rating: {}", hotel.getStarRating().getValue());
+ }
+ // To get the guest rating of the property. The value is between 1.0 and 5.0
+ // in a 0.1 increment.
+ if (StringUtils.isNotEmpty(hotel.getGuestRating())) {
+ LOGGER.info("Guest Rating: {}", hotel.getGuestRating());
+ }
+ // To get the total number of reviews for the property
+ if (hotel.getGuestReviewCount() != null) {
+ LOGGER.info("Review Count: {}", hotel.getGuestReviewCount());
+ }
+ if (hotel.getRoomTypes() != null && !hotel.getRoomTypes().isEmpty()) {
+ // To get the first room type information
+ RoomType roomType = hotel.getRoomTypes().get(0);
+ if (StringUtils.isNotEmpty(roomType.getDescription())) {
+ LOGGER.info("Room Type: {}", roomType.getDescription());
+ }
+ if (roomType.getPrice() != null) {
+ // To get the total price of the room type
+ if (roomType.getPrice().getTotalPrice() != null) {
+ LOGGER.info("Price: {}, Currency: {}", roomType.getPrice().getTotalPrice().getValue(), roomType.getPrice().getTotalPrice().getCurrency());
+ }
+ // To get the average nightly rate of the room type
+ if (roomType.getPrice().getAvgNightlyRate() != null) {
+ LOGGER.info("Average Nightly Rate: {}, Currency: {}", roomType.getPrice().getAvgNightlyRate().getValue(), roomType.getPrice().getAvgNightlyRate().getCurrency());
+ }
+ }
+ // To get the free cancellation flag of the selected room
+ if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty() && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
+ LOGGER.info("Free Cancellation: {}", roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ }
+ if (roomType.getLinks() != null) {
+ // To get the deeplink to the Expedia Web Search Result Page
+ if (roomType.getLinks().getWebSearchResult() != null) {
+ LOGGER.info("WebSearchResult Link: {}", roomType.getLinks().getWebSearchResult().getHref());
+ }
+ // To get the deeplink to the Expedia Web Details Page
+ if (roomType.getLinks().getWebDetails() != null) {
+ LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
+ }
+ }
+ }
+ LOGGER.info("==================================== Property End ====================================");
+ });
+
+ LOGGER.info("============================ End ListingsQuickStartScenario ===========================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java
index a4fa86f8b..ff7f1b704 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java
@@ -23,11 +23,13 @@
import com.expediagroup.sdk.xap.models.Room;
import com.expediagroup.sdk.xap.operations.GetLodgingQuotesOperation;
import com.expediagroup.sdk.xap.operations.GetLodgingQuotesOperationParams;
+
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,38 +39,32 @@
* Note: this is a Vrbo scenario. You need a key that is enabled for Vrbo brand to run this.
*/
public class QuotesQuickStartScenario implements VrboScenario {
+ private static final Logger LOGGER = LoggerFactory.getLogger(QuotesQuickStartScenario.class);
+
+ public static void main(String[] args) {
+ new QuotesQuickStartScenario().run();
+ System.exit(0);
+ }
- private static final Logger LOGGER = LoggerFactory.getLogger(QuotesQuickStartScenario.class);
-
- public static void main(String[] args) {
- new QuotesQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- // This example will get quotes response for mentioned Expedia properties with the following
- // criteria:
- // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
- // in the second room;
- // 3. Check-in date 5 days from now, check-out date 10 days from now;
- // 4. Return web links to Expedia website;
-
- LOGGER.info(
- "============================ Running QuotesQuickStartScenario ==========================");
-
- LOGGER.info(
- "========================= Executing GetLodgingQuotesOperation =========================");
-
- // Build the occupancy
- ArrayList rooms = new ArrayList<>();
- // The first room, with 2 adult
- rooms.add(Room.builder().adults(2L).childAges(null).build());
-
- // Build the query parameters with GetLodgingQuotesOperationParams
- GetLodgingQuotesOperationParams quotesOperationParams =
- GetLodgingQuotesOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ @Override
+ public void run() {
+ // This example will get quotes response for mentioned Expedia properties with the following
+ // criteria:
+ // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
+ // in the second room;
+ // 3. Check-in date 5 days from now, check-out date 10 days from now;
+ // 4. Return web links to Expedia website;
+
+ LOGGER.info("============================ Running QuotesQuickStartScenario ==========================");
+ LOGGER.info("========================= Executing GetLodgingQuotesOperation =========================");
+
+ // Build the occupancy
+ ArrayList rooms = new ArrayList<>();
+ // The first room, with 2 adult
+ rooms.add(Room.builder().adults(2L).childAges(null).build());
+
+ // Build the query parameters with GetLodgingQuotesOperationParams
+ GetLodgingQuotesOperationParams quotesOperationParams = GetLodgingQuotesOperationParams.builder().partnerTransactionId(PARTNER_TRANSACTION_ID)
// Check-in 5 days from now
.checkIn(LocalDate.now().plusDays(5))
// Check-out 10 days from now
@@ -77,85 +73,70 @@ public void run() {
.propertyIds(new HashSet<>(Arrays.asList("87704892", "36960201")))
// The links to return, WEB includes WS (Web Search Result Page) and
// WD (Web Details Page)
- .links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB))
- .rooms(rooms)
- .build();
-
- XapClient xapClient = createClient();
-
- // Execute the operation and get the QuotesResponse
- LodgingQuotesResponse quotesResponse =
- xapClient.execute(new GetLodgingQuotesOperation(quotesOperationParams)).getData();
-
- // If you want to use the async method, you can use the following code:
- // ---------------------------------------------------------------
- // CompletableFuture> completableFuture =
- // xapClient.executeAsync(
- // new GetLodgingQuotesOperation(quotesOperationParams));
- // completableFuture.thenAccept(quotesResponse -> {
- // // Your code here
- // });
- // ---------------------------------------------------------------
-
- LOGGER.info(
- "========================== GetLodgingQuotesOperation Executed =========================");
-
- if (quotesResponse == null || quotesResponse.getProperties() == null
- || quotesResponse.getProperties().isEmpty()) {
- throw new IllegalStateException("No properties found.");
- }
+ .links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB)).rooms(rooms).build();
- // The LodgingQuotesResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", quotesResponse.getTransactionId());
-
- // To access the properties, iterate through the list of properties
- quotesResponse.getProperties().forEach(quote -> {
- LOGGER.info("========== Property:{} Start ==========", quote.getId());
- if (Property.Status.AVAILABLE != quote.getStatus()) {
- LOGGER.info("Property is not available.");
- return;
- }
- if (quote.getRoomTypes() != null && !quote.getRoomTypes().isEmpty()) {
- // To get the first room type information
- LodgingRoomType roomType = quote.getRoomTypes().get(0);
-
- if (roomType.getPrice() != null) {
- // To get the total price of the room type
- if (roomType.getPrice().getTotalPrice() != null) {
- LOGGER.info("Price: {}, Currency: {}",
- roomType.getPrice().getTotalPrice().getValue(),
- roomType.getPrice().getTotalPrice().getCurrency());
- }
- // To get the average nightly rate of the room type
- if (roomType.getPrice().getAvgNightlyRate() != null) {
- LOGGER.info("Average Nightly Rate: {}, Currency: {}",
- roomType.getPrice().getAvgNightlyRate().getValue(),
- roomType.getPrice().getAvgNightlyRate().getCurrency());
- }
- }
- // To get the free cancellation flag of the selected room
- if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
- && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
- LOGGER.info("Free Cancellation: {}",
- roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
- }
- if (roomType.getLinks() != null) {
- // To get the deeplink to the Expedia Web Search Result Page
- if (roomType.getLinks().getWebSearchResult() != null) {
- LOGGER.info("WebSearchResult Link: {}",
- roomType.getLinks().getWebSearchResult().getHref());
- }
- // To get the deeplink to the Expedia Web Details Page
- if (roomType.getLinks().getWebDetails() != null) {
- LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
- }
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the QuotesResponse
+ LodgingQuotesResponse quotesResponse = xapClient.execute(new GetLodgingQuotesOperation(quotesOperationParams)).getData();
+
+ // If you want to use the async method, you can use the following code:
+ // ---------------------------------------------------------------
+ // CompletableFuture> completableFuture =
+ // xapClient.executeAsync(
+ // new GetLodgingQuotesOperation(quotesOperationParams));
+ // completableFuture.thenAccept(quotesResponse -> {
+ // // Your code here
+ // });
+ // ---------------------------------------------------------------
+
+ LOGGER.info("========================== GetLodgingQuotesOperation Executed =========================");
+
+ if (quotesResponse == null || quotesResponse.getProperties() == null || quotesResponse.getProperties().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
}
- }
- LOGGER.info(
- "=================================== Property End ===================================");
- });
-
- LOGGER.info(
- "============================= End QuotesQuickStartScenario ============================");
- }
+
+ // The LodgingQuotesResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", quotesResponse.getTransactionId());
+
+ // To access the properties, iterate through the list of properties
+ quotesResponse.getProperties().forEach(quote -> {
+ LOGGER.info("========== Property:{} Start ==========", quote.getId());
+ if (Property.Status.AVAILABLE != quote.getStatus()) {
+ LOGGER.info("Property is not available.");
+ return;
+ }
+ if (quote.getRoomTypes() != null && !quote.getRoomTypes().isEmpty()) {
+ // To get the first room type information
+ LodgingRoomType roomType = quote.getRoomTypes().get(0);
+
+ if (roomType.getPrice() != null) {
+ // To get the total price of the room type
+ if (roomType.getPrice().getTotalPrice() != null) {
+ LOGGER.info("Price: {}, Currency: {}", roomType.getPrice().getTotalPrice().getValue(), roomType.getPrice().getTotalPrice().getCurrency());
+ }
+ // To get the average nightly rate of the room type
+ if (roomType.getPrice().getAvgNightlyRate() != null) {
+ LOGGER.info("Average Nightly Rate: {}, Currency: {}", roomType.getPrice().getAvgNightlyRate().getValue(), roomType.getPrice().getAvgNightlyRate().getCurrency());
+ }
+ }
+ // To get the free cancellation flag of the selected room
+ if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty() && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
+ LOGGER.info("Free Cancellation: {}", roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ }
+ if (roomType.getLinks() != null) {
+ // To get the deeplink to the Expedia Web Search Result Page
+ if (roomType.getLinks().getWebSearchResult() != null) {
+ LOGGER.info("WebSearchResult Link: {}", roomType.getLinks().getWebSearchResult().getHref());
+ }
+ // To get the deeplink to the Expedia Web Details Page
+ if (roomType.getLinks().getWebDetails() != null) {
+ LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
+ }
+ }
+ }
+ LOGGER.info("=================================== Property End ===================================");
+ });
+ LOGGER.info("============================= End QuotesQuickStartScenario ============================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboPropertySearchEndToEndScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboPropertySearchEndToEndScenario.java
index 0d5ff3731..bfaff850a 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboPropertySearchEndToEndScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboPropertySearchEndToEndScenario.java
@@ -29,6 +29,7 @@
import com.expediagroup.sdk.xap.operations.GetLodgingQuotesOperationParams;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -43,6 +44,7 @@
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,144 +60,120 @@
* Note: this is a Vrbo scenario. You need a key that is enabled for Vrbo brand to run this.
*/
public class VrboPropertySearchEndToEndScenario implements VrboScenario {
+ private final XapClient client = createClient();
+ private static final Logger LOGGER = LoggerFactory.getLogger(VrboPropertySearchEndToEndScenario.class);
+
+ /**
+ * This field limits the number of line to read from the SDP DownloadURL API Listings file to
+ * reduce time to run the example.
+ * If the first 20 properties from the file are not accessible OR available when you run this
+ * example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
+ * you can adjust the property count to get more properties.
+ */
+ private static final int SAMPLE_ITEMS_RESTRICTION = 20;
+
+ /**
+ * A property id to location map. This mocks a cache in this example to store the static content
+ * of the properties.
+ */
+ private static final Map PROPERTY_ID_AND_LOCATION_CACHE = new HashMap<>();
+
+ public static void main(String[] args) {
+ new VrboPropertySearchEndToEndScenario().run();
+ System.exit(0);
+ }
+
+ @Override
+ public void run() {
+ LOGGER.info("====================== Running VrboPropertySearchEndToEndScenario ======================");
+
+ List propertyIds = getPropertyIdsFromDownloadUrl();
+ cachePropertyLocationFromDownloadUrl(propertyIds);
+ LodgingQuotesResponse lodgingQuotesResponse = getPropertyPriceFromLodgingQuotes(propertyIds);
+ displayResult(lodgingQuotesResponse);
+
+ LOGGER.info("======================= End VrboPropertySearchEndToEndScenario =========================");
+ }
+
+ private List getPropertyIdsFromDownloadUrl() {
+ LOGGER.info("==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
- private final XapClient client = createClient();
-
- private static final Logger LOGGER =
- LoggerFactory.getLogger(VrboPropertySearchEndToEndScenario.class);
-
- /**
- * This field limits the number of line to read from the SDP DownloadURL API Listings file to
- * reduce time to run the example.
- * If the first 20 properties from the file are not accessible OR available when you run this
- * example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
- * you can adjust the property count to get more properties.
- */
- private static final int SAMPLE_ITEMS_RESTRICTION = 20;
-
- /**
- * A property id to location map. This mocks a cache in this example to store the static content
- * of the properties.
- */
- private static final Map PROPERTY_ID_AND_LOCATION_CACHE = new HashMap<>();
-
- public static void main(String[] args) {
- new VrboPropertySearchEndToEndScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- LOGGER.info(
- "====================== Running VrboPropertySearchEndToEndScenario ======================");
-
- List propertyIds = getPropertyIdsFromDownloadUrl();
- cachePropertyLocationFromDownloadUrl(propertyIds);
- LodgingQuotesResponse lodgingQuotesResponse = getPropertyPriceFromLodgingQuotes(propertyIds);
- displayResult(lodgingQuotesResponse);
-
- LOGGER.info(
- "======================= End VrboPropertySearchEndToEndScenario =========================");
- }
-
- private List getPropertyIdsFromDownloadUrl() {
- LOGGER.info(
- "==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
-
- GetFeedDownloadUrlOperationParams getPropertyIdListParams =
- GetFeedDownloadUrlOperationParams.builder()
+ GetFeedDownloadUrlOperationParams getPropertyIdListParams = GetFeedDownloadUrlOperationParams.builder()
// Use the type VACATION_RENTAL to get the list of accessible Vrbo property ids.
.type(GetFeedDownloadUrlOperationParams.Type.VACATION_RENTAL)
// Without any filters, this operation will return the information of all Vrbo
// properties in en_US by default.
.build();
- Response downloadUrlListingsResponse =
- client.execute(new GetFeedDownloadUrlOperation(getPropertyIdListParams));
+ Response downloadUrlListingsResponse = client.execute(new GetFeedDownloadUrlOperation(getPropertyIdListParams));
- if (downloadUrlListingsResponse.getData() == null
- || downloadUrlListingsResponse.getData().getBestMatchedFile() == null) {
- throw new IllegalStateException("No vacation rental file found");
- }
+ if (downloadUrlListingsResponse.getData() == null || downloadUrlListingsResponse.getData().getBestMatchedFile() == null) {
+ throw new IllegalStateException("No vacation rental file found");
+ }
+
+ // The download URL points to a zip file containing various jsonl files.
+ // Each line in the jsonl files contains a json object representing a Vrbo property.
+ // For demonstration purposes, we will only read a few properties from the file without
+ // downloading the entire file.
+ String vacationRentalDownloadUrl = downloadUrlListingsResponse.getData().getBestMatchedFile().getDownloadUrl();
+ LOGGER.info("Vacation Rental Download URL: {}", vacationRentalDownloadUrl);
+
+ // Read property ids from the file.
+ List propertyIds = getPropertyIdsFromVacationRentalFile(vacationRentalDownloadUrl);
- // The download URL points to a zip file containing various jsonl files.
- // Each line in the jsonl files contains a json object representing a Vrbo property.
- // For demonstration purposes, we will only read a few properties from the file without
- // downloading the entire file.
- String vacationRentalDownloadUrl = downloadUrlListingsResponse.getData()
- .getBestMatchedFile()
- .getDownloadUrl();
- LOGGER.info("Vacation Rental Download URL: {}", vacationRentalDownloadUrl);
-
- // Read property ids from the file.
- List propertyIds = getPropertyIdsFromVacationRentalFile(vacationRentalDownloadUrl
- );
-
- if (propertyIds.isEmpty()) {
- throw new IllegalStateException("No accessible Vrbo property ids found.");
+ if (propertyIds.isEmpty()) {
+ throw new IllegalStateException("No accessible Vrbo property ids found.");
+ }
+ LOGGER.info("Accessible Vrbo Property Ids: {}", propertyIds);
+
+ LOGGER.info("==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
+ return propertyIds;
}
- LOGGER.info("Accessible Vrbo Property Ids: {}", propertyIds);
-
- LOGGER.info(
- "==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
- return propertyIds;
- }
-
- /**
- * Cache the location content from SDP DownloadURL API.
- *
- * @param propertyIds The property ids that need the location content.
- */
- private void cachePropertyLocationFromDownloadUrl(List propertyIds) {
- LOGGER.info(
- "================ Executing Step II: CachePropertyLocationFromDownloadUrl ===============");
- GetFeedDownloadUrlOperationParams getPropertyLocationParams =
- GetFeedDownloadUrlOperationParams.builder()
+
+ /**
+ * Cache the location content from SDP DownloadURL API.
+ *
+ * @param propertyIds The property ids that need the location content.
+ */
+ private void cachePropertyLocationFromDownloadUrl(List propertyIds) {
+ LOGGER.info("================ Executing Step II: CachePropertyLocationFromDownloadUrl ===============");
+ GetFeedDownloadUrlOperationParams getPropertyLocationParams = GetFeedDownloadUrlOperationParams.builder()
// Use the type LOCATIONS to get the address of accessible properties.
.type(GetFeedDownloadUrlOperationParams.Type.LOCATIONS)
// Filter the properties by brand.
- .brand(GetFeedDownloadUrlOperationParams.Brand.VRBO)
- .build();
+ .brand(GetFeedDownloadUrlOperationParams.Brand.VRBO).build();
+
+ Response downloadUrlLocationsResponse = client.execute(new GetFeedDownloadUrlOperation(getPropertyLocationParams));
+
+ if (downloadUrlLocationsResponse.getData() == null || downloadUrlLocationsResponse.getData().getBestMatchedFile() == null) {
+ throw new IllegalStateException("No location file found");
+ }
+
+ String locationsDownloadUrl = downloadUrlLocationsResponse.getData().getBestMatchedFile().getDownloadUrl();
+ LOGGER.info("Locations Download URL: {}", locationsDownloadUrl);
- Response downloadUrlLocationsResponse =
- client.execute(new GetFeedDownloadUrlOperation(getPropertyLocationParams));
+ // Read and cache property locations from the file.
+ cachePropertyLocationFromLocationsFile(locationsDownloadUrl, propertyIds);
- if (downloadUrlLocationsResponse.getData() == null
- || downloadUrlLocationsResponse.getData().getBestMatchedFile() == null) {
- throw new IllegalStateException("No location file found");
+ LOGGER.info("================= Step II: CachePropertyLocationFromDownloadUrl Executed ===============");
}
- String locationsDownloadUrl = downloadUrlLocationsResponse.getData()
- .getBestMatchedFile()
- .getDownloadUrl();
- LOGGER.info("Locations Download URL: {}", locationsDownloadUrl);
-
- // Read and cache property locations from the file.
- cachePropertyLocationFromLocationsFile(locationsDownloadUrl, propertyIds);
-
- LOGGER.info(
- "================= Step II: CachePropertyLocationFromDownloadUrl Executed ===============");
- }
-
- /**
- * Get prices of the properties using the Lodging Quotes API.
- *
- * @param propertyIds The property ids to get the prices.
- * @return The response of the Lodging Quotes API.
- */
- private LodgingQuotesResponse getPropertyPriceFromLodgingQuotes(List propertyIds) {
- LOGGER.info(
- "================= Executing Step III: GetPropertyPriceFromLodgingQuotes ================");
-
- // Build the occupancy
- ArrayList rooms = new ArrayList<>();
- // The first room, with 2 adult
- rooms.add(Room.builder().adults(2L).childAges(null).build());
-
- // Build the query parameters with GetLodgingQuotesOperationParams
- GetLodgingQuotesOperationParams quotesOperationParams =
- GetLodgingQuotesOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ /**
+ * Get prices of the properties using the Lodging Quotes API.
+ *
+ * @param propertyIds The property ids to get the prices.
+ * @return The response of the Lodging Quotes API.
+ */
+ private LodgingQuotesResponse getPropertyPriceFromLodgingQuotes(List propertyIds) {
+ LOGGER.info("================= Executing Step III: GetPropertyPriceFromLodgingQuotes ================");
+
+ // Build the occupancy
+ ArrayList rooms = new ArrayList<>();
+ // The first room, with 2 adult
+ rooms.add(Room.builder().adults(2L).childAges(null).build());
+
+ // Build the query parameters with GetLodgingQuotesOperationParams
+ GetLodgingQuotesOperationParams quotesOperationParams = GetLodgingQuotesOperationParams.builder().partnerTransactionId(PARTNER_TRANSACTION_ID)
// Check-in 5 days from now
.checkIn(LocalDate.now().plusDays(5))
// Check-out 10 days from now
@@ -204,47 +182,41 @@ private LodgingQuotesResponse getPropertyPriceFromLodgingQuotes(List pro
.propertyIds(new HashSet<>(propertyIds))
// The links to return, WEB includes WS (Web Search Result Page) and
// WD (Web Details Page)
- .links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB))
- .rooms(rooms)
- .build();
+ .links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB)).rooms(rooms).build();
+
+ LodgingQuotesResponse lodgingQuotesResponse = client.execute(new GetLodgingQuotesOperation(quotesOperationParams)).getData();
+
+ LOGGER.info("================= Step III: GetPropertyPriceFromLodgingQuotes Executed =================");
+ return lodgingQuotesResponse;
+ }
- LodgingQuotesResponse lodgingQuotesResponse =
- client.execute(new GetLodgingQuotesOperation(quotesOperationParams))
- .getData();
-
- LOGGER.info(
- "================= Step III: GetPropertyPriceFromLodgingQuotes Executed =================");
- return lodgingQuotesResponse;
- }
-
- /**
- * Reads given number of property ids from the file pointed by the download URL.
- *
- * @param downloadUrl The download URL of the zip file containing the property information.
- * @return A list of property ids read from the file.
- */
- private List getPropertyIdsFromVacationRentalFile(String downloadUrl) {
- List propertyIds = new ArrayList<>();
- HttpURLConnection connection = null;
- try {
- // Open a connection to the URL
- URL url = new URL(downloadUrl);
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("GET");
- connection.setDoInput(true);
-
- try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
- ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
- if (entry.getName().endsWith(".jsonl")) {
- LOGGER.info("Reading property ids from file: {}", entry.getName());
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
- String line;
- ObjectMapper objectMapper = new ObjectMapper();
- while ((line = reader.readLine()) != null
- && propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
- // Parse the property id from the json object
- // An example json line from the jsonl file:
+ /**
+ * Reads given number of property ids from the file pointed by the download URL.
+ *
+ * @param downloadUrl The download URL of the zip file containing the property information.
+ * @return A list of property ids read from the file.
+ */
+ private List getPropertyIdsFromVacationRentalFile(String downloadUrl) {
+ List propertyIds = new ArrayList<>();
+ HttpURLConnection connection = null;
+ try {
+ // Open a connection to the URL
+ URL url = new URL(downloadUrl);
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setDoInput(true);
+
+ try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
+ ZipEntry entry;
+ while ((entry = zipStream.getNextEntry()) != null) {
+ if (entry.getName().endsWith(".jsonl")) {
+ LOGGER.info("Reading property ids from file: {}", entry.getName());
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
+ String line;
+ ObjectMapper objectMapper = new ObjectMapper();
+ while ((line = reader.readLine()) != null && propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
+ // Parse the property id from the json object
+ // An example json line from the jsonl file:
/*
{
"propertyId": {
@@ -290,52 +262,50 @@ private List getPropertyIdsFromVacationRentalFile(String downloadUrl) {
"propertyLiveDate": "2022-05-31"
}
*/
- JsonNode jsonNode = objectMapper.readTree(line);
- propertyIds.add(jsonNode.get("propertyId").get("expedia").asText());
- }
+ JsonNode jsonNode = objectMapper.readTree(line);
+ propertyIds.add(jsonNode.get("propertyId").get("expedia").asText());
+ }
+ }
+ }
+ }
+ }
+
+ } catch (IOException e) {
+ LOGGER.error("Error reading property ids from download URL", e);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
}
- }
}
- }
-
- } catch (IOException e) {
- LOGGER.error("Error reading property ids from download URL", e);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
+ return propertyIds;
}
- return propertyIds;
- }
-
- /**
- * Caches the location content of the properties from the file pointed by the download URL.
- *
- * @param locationsDownloadUrl The download URL of the zip file containing the property locations.
- * @param propertyIds The property ids to get the location content.
- */
- private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
- List propertyIds) {
- HttpURLConnection connection = null;
- try {
- // Open a connection to the URL
- URL url = new URL(locationsDownloadUrl);
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("GET");
- connection.setDoInput(true);
-
- try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
- ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
- if (entry.getName().endsWith(".jsonl")) {
- LOGGER.info("Reading property locations from file: {}", entry.getName());
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
- String line;
- ObjectMapper objectMapper = new ObjectMapper();
- while ((line = reader.readLine()) != null
- && PROPERTY_ID_AND_LOCATION_CACHE.size() < propertyIds.size()) {
- // Parse the property location from the json object
- // An example json line from the jsonl file:
+
+ /**
+ * Caches the location content of the properties from the file pointed by the download URL.
+ *
+ * @param locationsDownloadUrl The download URL of the zip file containing the property locations.
+ * @param propertyIds The property ids to get the location content.
+ */
+ private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl, List propertyIds) {
+ HttpURLConnection connection = null;
+ try {
+ // Open a connection to the URL
+ URL url = new URL(locationsDownloadUrl);
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setDoInput(true);
+
+ try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
+ ZipEntry entry;
+ while ((entry = zipStream.getNextEntry()) != null) {
+ if (entry.getName().endsWith(".jsonl")) {
+ LOGGER.info("Reading property locations from file: {}", entry.getName());
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
+ String line;
+ ObjectMapper objectMapper = new ObjectMapper();
+ while ((line = reader.readLine()) != null && PROPERTY_ID_AND_LOCATION_CACHE.size() < propertyIds.size()) {
+ // Parse the property location from the json object
+ // An example json line from the jsonl file:
/*
{
"propertyId": {
@@ -386,106 +356,89 @@ private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
}
}
*/
- JsonNode jsonNode = objectMapper.readTree(line);
- // Check if the property id is in the list
- if (propertyIds.contains(jsonNode.get("propertyId").get("expedia").asText())) {
- // Get the location content of the property
- String location = jsonNode.get("propertyName").asText() + ", "
- + jsonNode.get("city").asText() + ", "
- + jsonNode.get("province").asText() + ", "
- + jsonNode.get("country").asText();
- // Store the location content in the cache
- PROPERTY_ID_AND_LOCATION_CACHE.put(
- jsonNode.get("propertyId")
- .get("expedia")
- .asText(),
- location);
+ JsonNode jsonNode = objectMapper.readTree(line);
+ // Check if the property id is in the list
+ if (propertyIds.contains(jsonNode.get("propertyId").get("expedia").asText())) {
+ // Get the location content of the property
+ String location = jsonNode.get("propertyName").asText() + ", " + jsonNode.get("city").asText() + ", " + jsonNode.get("province").asText() + ", " + jsonNode.get("country").asText();
+ // Store the location content in the cache
+ PROPERTY_ID_AND_LOCATION_CACHE.put(jsonNode.get("propertyId").get("expedia").asText(), location);
+ }
+ }
+ }
+ }
}
- }
}
- }
+
+ } catch (IOException e) {
+ LOGGER.error("Error reading property locations from download URL", e);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
}
- }
-
- } catch (IOException e) {
- LOGGER.error("Error reading property locations from download URL", e);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- /**
- * Display the result of the operations.
- *
- * @param lodgingQuotesResponse The response of the Lodging Quotes API.
- */
- private static void displayResult(LodgingQuotesResponse lodgingQuotesResponse) {
- LOGGER.info("======================= Executing Step IV: DisplayResult =======================");
- if (lodgingQuotesResponse == null || lodgingQuotesResponse.getProperties() == null
- || lodgingQuotesResponse.getProperties().isEmpty()) {
- throw new IllegalStateException("No properties found.");
}
- // The HotelListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", lodgingQuotesResponse.getTransactionId());
-
- // To access the properties, iterate through the list of hotel properties
- lodgingQuotesResponse.getProperties().forEach(property -> {
- // Check if the property is available
- if (Property.Status.AVAILABLE != property.getStatus()) {
- LOGGER.info("Property {} is not available.", property.getId());
- return;
- }
- LOGGER.info(
- "=================================== Property Start ===================================");
- String propertyId = property.getId();
-
- // Get the location content of the property from the cache
- LOGGER.info("Property Id: {}", propertyId);
- LOGGER.info("Cached Property Location: {}", PROPERTY_ID_AND_LOCATION_CACHE.get(propertyId));
-
- // Get the price of the property from the room type
- if (property.getRoomTypes() != null && !property.getRoomTypes().isEmpty()) {
- // To get the first room type information
- LodgingRoomType roomType = property.getRoomTypes().get(0);
-
- if (roomType.getPrice() != null) {
- // To get the total price of the room type
- if (roomType.getPrice().getTotalPrice() != null) {
- LOGGER.info("Price: {}, Currency: {}",
- roomType.getPrice().getTotalPrice().getValue(),
- roomType.getPrice().getTotalPrice().getCurrency());
- }
- // To get the average nightly rate of the room type
- if (roomType.getPrice().getAvgNightlyRate() != null) {
- LOGGER.info("Average Nightly Rate: {}, Currency: {}",
- roomType.getPrice().getAvgNightlyRate().getValue(),
- roomType.getPrice().getAvgNightlyRate().getCurrency());
- }
+ /**
+ * Display the result of the operations.
+ *
+ * @param lodgingQuotesResponse The response of the Lodging Quotes API.
+ */
+ private static void displayResult(LodgingQuotesResponse lodgingQuotesResponse) {
+ LOGGER.info("======================= Executing Step IV: DisplayResult =======================");
+ if (lodgingQuotesResponse == null || lodgingQuotesResponse.getProperties() == null || lodgingQuotesResponse.getProperties().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
}
- // To get the free cancellation flag of the selected room
- if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
- && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
- LOGGER.info("Free Cancellation: {}",
- roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
- }
- if (roomType.getLinks() != null) {
- // To get the deeplink to the website Search Result Page
- if (roomType.getLinks().getWebSearchResult() != null) {
- LOGGER.info("WebSearchResult Link: {}",
- roomType.getLinks().getWebSearchResult().getHref());
- }
- // To get the deeplink to the website Details Page
- if (roomType.getLinks().getWebDetails() != null) {
- LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
- }
- }
- }
- LOGGER.info(
- "==================================== Property End ====================================");
- });
- LOGGER.info("======================= Step IV: DisplayResult Executed ========================");
- }
+
+ // The HotelListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", lodgingQuotesResponse.getTransactionId());
+
+ // To access the properties, iterate through the list of hotel properties
+ lodgingQuotesResponse.getProperties().forEach(property -> {
+ // Check if the property is available
+ if (Property.Status.AVAILABLE != property.getStatus()) {
+ LOGGER.info("Property {} is not available.", property.getId());
+ return;
+ }
+ LOGGER.info("=================================== Property Start ===================================");
+ String propertyId = property.getId();
+
+ // Get the location content of the property from the cache
+ LOGGER.info("Property Id: {}", propertyId);
+ LOGGER.info("Cached Property Location: {}", PROPERTY_ID_AND_LOCATION_CACHE.get(propertyId));
+
+ // Get the price of the property from the room type
+ if (property.getRoomTypes() != null && !property.getRoomTypes().isEmpty()) {
+ // To get the first room type information
+ LodgingRoomType roomType = property.getRoomTypes().get(0);
+
+ if (roomType.getPrice() != null) {
+ // To get the total price of the room type
+ if (roomType.getPrice().getTotalPrice() != null) {
+ LOGGER.info("Price: {}, Currency: {}", roomType.getPrice().getTotalPrice().getValue(), roomType.getPrice().getTotalPrice().getCurrency());
+ }
+ // To get the average nightly rate of the room type
+ if (roomType.getPrice().getAvgNightlyRate() != null) {
+ LOGGER.info("Average Nightly Rate: {}, Currency: {}", roomType.getPrice().getAvgNightlyRate().getValue(), roomType.getPrice().getAvgNightlyRate().getCurrency());
+ }
+ }
+ // To get the free cancellation flag of the selected room
+ if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty() && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
+ LOGGER.info("Free Cancellation: {}", roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ }
+ if (roomType.getLinks() != null) {
+ // To get the deeplink to the website Search Result Page
+ if (roomType.getLinks().getWebSearchResult() != null) {
+ LOGGER.info("WebSearchResult Link: {}", roomType.getLinks().getWebSearchResult().getHref());
+ }
+ // To get the deeplink to the website Details Page
+ if (roomType.getLinks().getWebDetails() != null) {
+ LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
+ }
+ }
+ }
+ LOGGER.info("==================================== Property End ====================================");
+ });
+ LOGGER.info("======================= Step IV: DisplayResult Executed ========================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboScenario.java
index 6a523f5aa..994a2880e 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboScenario.java
@@ -25,20 +25,20 @@
*/
public interface VrboScenario extends XapScenario {
- /**
- * Create a client with Vrbo key and secret.
- *
- * @return XapClient
- */
- @Override
- default XapClient createClient() {
- String key = System.getProperty("com.expediagroup.xapjavasdk.vrbokey");
- String secret = System.getProperty("com.expediagroup.xapjavasdk.vrbosecret");
- return XapClient
- .builder()
- .key(key)
- .secret(secret)
- .build();
- }
+ /**
+ * Create a client with Vrbo key and secret.
+ *
+ * @return XapClient
+ */
+ @Override
+ default XapClient createClient() {
+ String key = System.getProperty("com.expediagroup.xapjavasdk.vrbokey");
+ String secret = System.getProperty("com.expediagroup.xapjavasdk.vrbosecret");
+
+ return XapClient.builder()
+ .key(key)
+ .secret(secret)
+ .build();
+ }
}