|
| 1 | +package com.expediagroup.sdk.xap.examples.scenarios.car; |
| 2 | + |
| 3 | +import com.expediagroup.sdk.rest.model.Response; |
| 4 | +import com.expediagroup.sdk.xap.client.XapClient; |
| 5 | +import com.expediagroup.sdk.xap.examples.scenarios.XapScenario; |
| 6 | +import com.expediagroup.sdk.xap.models.CarDetails; |
| 7 | +import com.expediagroup.sdk.xap.models.CarDetailsResponse; |
| 8 | +import com.expediagroup.sdk.xap.models.CarListingsResponse; |
| 9 | +import com.expediagroup.sdk.xap.models.VehicleDetails; |
| 10 | +import com.expediagroup.sdk.xap.operations.GetCarDetailsOperation; |
| 11 | +import com.expediagroup.sdk.xap.operations.GetCarDetailsOperationParams; |
| 12 | +import com.expediagroup.sdk.xap.operations.GetCarsListingsOperation; |
| 13 | +import com.expediagroup.sdk.xap.operations.GetCarsListingsOperationParams; |
| 14 | +import java.time.LocalDateTime; |
| 15 | +import java.util.ArrayList; |
| 16 | +import java.util.List; |
| 17 | +import java.util.Objects; |
| 18 | +import org.slf4j.Logger; |
| 19 | +import org.slf4j.LoggerFactory; |
| 20 | + |
| 21 | +/** |
| 22 | + * This example demonstrates how to retrieve CarDetails information using the Car Details DeepLink |
| 23 | + * obtained from the car listing. |
| 24 | + */ |
| 25 | +public class CarDetailsQuickStartScenario implements XapScenario { |
| 26 | + |
| 27 | + private static final Logger LOGGER = LoggerFactory.getLogger(CarDetailsQuickStartScenario.class); |
| 28 | + |
| 29 | + /** |
| 30 | + * Summary: main function. |
| 31 | + */ |
| 32 | + public static void main(String[] args) { |
| 33 | + new CarListingsQuickStartScenario().run(); |
| 34 | + new CarDetailsQuickStartScenario().run(); |
| 35 | + System.exit(0); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Summary: split URL into components. |
| 40 | + */ |
| 41 | + public static String[] splitUrl(String url) { |
| 42 | + String[] parts = url.split("\\?"); |
| 43 | + String base = parts[0]; |
| 44 | + String query = parts[1]; |
| 45 | + |
| 46 | + String offerToken = base.substring(base.lastIndexOf("/") + 1); |
| 47 | + String[] queryParams = query.split("&"); |
| 48 | + String price = queryParams[0].split("=")[1]; |
| 49 | + String currency = queryParams[1].split("=")[1]; |
| 50 | + |
| 51 | + return new String[] {offerToken, price, currency}; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public void run() { |
| 56 | + LOGGER.info("========== Start QuickStartScenario =========="); |
| 57 | + |
| 58 | + LOGGER.info("========== Car Listing Start =========="); |
| 59 | + |
| 60 | + // This example demonstrates how to obtain the Car Details Deep Link from the CarListing. |
| 61 | + // For information on using car search, refer to |
| 62 | + // car/shopping/listings/ListingsQuickStartExample. |
| 63 | + List<GetCarsListingsOperationParams.Links> linksList = new ArrayList<>(); |
| 64 | + linksList.add(GetCarsListingsOperationParams.Links.AD); |
| 65 | + linksList.add(GetCarsListingsOperationParams.Links.WS); |
| 66 | + linksList.add(GetCarsListingsOperationParams.Links.WD); |
| 67 | + GetCarsListingsOperationParams getCarsListingsOperationParams = |
| 68 | + GetCarsListingsOperationParams.builder() |
| 69 | + .partnerTransactionId("EWSCar_Automation") |
| 70 | + .dropOffAirport("MCO") |
| 71 | + .pickupAirport("MCO") |
| 72 | + .pickupTime( |
| 73 | + LocalDateTime.now() |
| 74 | + .withNano(0) |
| 75 | + .withSecond(0) |
| 76 | + .withHour(10) |
| 77 | + .plusDays(10) |
| 78 | + .plusMonths(1) |
| 79 | + ) |
| 80 | + .dropOffTime( |
| 81 | + LocalDateTime.now() |
| 82 | + .withNano(0) |
| 83 | + .withSecond(0) |
| 84 | + .withHour(10) |
| 85 | + .plusDays(15) |
| 86 | + .plusMonths(1) |
| 87 | + ) |
| 88 | + .limit(1) |
| 89 | + .links(linksList) |
| 90 | + .build(); |
| 91 | + |
| 92 | + XapClient xapClient = createClient(); |
| 93 | + GetCarsListingsOperation getCarsListingsOperation = |
| 94 | + new GetCarsListingsOperation(getCarsListingsOperationParams); |
| 95 | + Response<CarListingsResponse> carListingsResponse = xapClient.execute(getCarsListingsOperation); |
| 96 | + |
| 97 | + LOGGER.info("========== Car Listing Property End =========="); |
| 98 | + |
| 99 | + // Iterate through the car listings and retrieve the Car Details Deep Link. |
| 100 | + LOGGER.info("========== Car Details Start =========="); |
| 101 | + Objects.requireNonNull(carListingsResponse.getData().getCars()).forEach(car -> { |
| 102 | + if (!car.getLinks().get("ApiDetails").getHref().isEmpty()) { |
| 103 | + // Retrieve the Car Details Deep Link from the car listing. |
| 104 | + LOGGER.info("Car Details Deep Link: " + car.getLinks().get("ApiDetails").getHref()); |
| 105 | + String[] strings = splitUrl(car.getLinks().get("ApiDetails").getHref()); |
| 106 | + |
| 107 | + // Retrieve the Car Details information using the Car Details Deep Link, which |
| 108 | + // includes (offerToken, price, currency) |
| 109 | + GetCarDetailsOperationParams getCarDetailsOperationParams = |
| 110 | + GetCarDetailsOperationParams.builder().partnerTransactionId("EWSCar_Automation") |
| 111 | + .offerToken(strings[0]).price(strings[1]).currency(strings[2]).build(); |
| 112 | + |
| 113 | + // Execute the operation and get the CarDetailsResponse |
| 114 | + LOGGER.info("========== Executing GetCarDetailsOperation =========="); |
| 115 | + CarDetailsResponse carDetailsResponse = xapClient.execute( |
| 116 | + new GetCarDetailsOperation(getCarDetailsOperationParams)).getData(); |
| 117 | + LOGGER.info("========== GetCarDetailsOperation Executed =========="); |
| 118 | + |
| 119 | + if (carDetailsResponse == null || carDetailsResponse.getLinks() == null) { |
| 120 | + throw new IllegalStateException("No car found."); |
| 121 | + } |
| 122 | + |
| 123 | + LOGGER.info("========== Car Properties Start =========="); |
| 124 | + |
| 125 | + // The CarDetailsResponse contains a transaction ID for troubleshooting |
| 126 | + LOGGER.info("Transaction ID: {}", carDetailsResponse.getTransactionId()); |
| 127 | + |
| 128 | + // List Container for warning messages |
| 129 | + if (carDetailsResponse.getWarnings() != null) { |
| 130 | + LOGGER.info("Warnings: {}", carDetailsResponse.getWarnings()); |
| 131 | + } |
| 132 | + |
| 133 | + // Details of requested car. |
| 134 | + // Details refer to the CarDetails Section table below. |
| 135 | + if (carDetailsResponse.getValidFormsOfPayment() != null) { |
| 136 | + LOGGER.info("Valid Forms Of Payment: {}", carDetailsResponse.getValidFormsOfPayment()); |
| 137 | + } |
| 138 | + |
| 139 | + // A map of links to other Car APIs. |
| 140 | + if (carDetailsResponse.getLinks() != null) { |
| 141 | + LOGGER.info("Links: {}", carDetailsResponse.getLinks()); |
| 142 | + } |
| 143 | + |
| 144 | + // Specific information for a car. |
| 145 | + CarDetails carDetails = carDetailsResponse.getCarDetails(); |
| 146 | + VehicleDetails vehicleDetails = carDetails.getVehicleDetails(); |
| 147 | + if (vehicleDetails.getMake() != null) { |
| 148 | + //Car manufacturer and model. |
| 149 | + LOGGER.info("Make: {}", vehicleDetails.getMake()); |
| 150 | + } |
| 151 | + |
| 152 | + // Car category and type. |
| 153 | + LOGGER.info("Car Class: {}", vehicleDetails.getCarClass()); |
| 154 | + |
| 155 | + // Minimal car door count. |
| 156 | + if (vehicleDetails.getMinDoors() != null) { |
| 157 | + LOGGER.info("Min Doors: {}", vehicleDetails.getMinDoors()); |
| 158 | + } |
| 159 | + |
| 160 | + // Maximum car door count. |
| 161 | + if (vehicleDetails.getMaxDoors() != null) { |
| 162 | + LOGGER.info("Max Doors: {}", vehicleDetails.getMaxDoors()); |
| 163 | + } |
| 164 | + |
| 165 | + // Car fuel information. |
| 166 | + if (vehicleDetails.getFuelLevel() != null) { |
| 167 | + // Fuel level of the car. |
| 168 | + LOGGER.info("Fuel Level: {}", vehicleDetails.getFuelLevel()); |
| 169 | + } |
| 170 | + |
| 171 | + // Car category. |
| 172 | + LOGGER.info("Car Category: {}", vehicleDetails.getCarCategory()); |
| 173 | + |
| 174 | + // Car type. |
| 175 | + LOGGER.info("Car Type: {}", vehicleDetails.getCarType()); |
| 176 | + |
| 177 | + // Car transmission and drive. |
| 178 | + LOGGER.info("Transmission Drive: {}", vehicleDetails.getTransmissionDrive()); |
| 179 | + |
| 180 | + // Car fuel type and whether Air Conditioning is included. |
| 181 | + LOGGER.info("Fuel AC: {}", vehicleDetails.getFuelAC()); |
| 182 | + |
| 183 | + // Capacity for car's properties, which include AdultCount, ChildCount, SmallLuggageCount |
| 184 | + // and LargeLuggageCount. |
| 185 | + if (vehicleDetails.getCapacity() != null) { |
| 186 | + LOGGER.info("Capacity: {}", vehicleDetails.getCapacity()); |
| 187 | + } |
| 188 | + |
| 189 | + // Car rental supplier. |
| 190 | + LOGGER.info(" : {}", carDetails.getSupplier()); |
| 191 | + |
| 192 | + // Pickup information |
| 193 | + LOGGER.info("Pickup Details: {}", carDetails.getPickupDetails()); |
| 194 | + |
| 195 | + // Drop off information, include drop off date time and drop off location information. |
| 196 | + LOGGER.info("Drop Off Details: {}", carDetails.getDropOffDetails()); |
| 197 | + |
| 198 | + // The rate information for a car product. |
| 199 | + LOGGER.info("Rate Details: {}", carDetails.getRateDetails()); |
| 200 | + |
| 201 | + // Base price per rate period. |
| 202 | + LOGGER.info("Price: {}", carDetails.getPrice()); |
| 203 | + |
| 204 | + // List of TaxesAndFees Details. |
| 205 | + if (carDetails.getTaxesAndFeesDetails() != null) { |
| 206 | + LOGGER.info("Taxes And Fees Details: {}", carDetails.getTaxesAndFeesDetails()); |
| 207 | + } |
| 208 | + |
| 209 | + // List of ExtraFeesDetails |
| 210 | + if (carDetails.getExtraFeesDetails() != null) { |
| 211 | + LOGGER.info("Extra Fees Details: {}", carDetails.getExtraFeesDetails()); |
| 212 | + } |
| 213 | + |
| 214 | + // ReferencePrice is the totalPrice for the comparable standalone car, when there is |
| 215 | + // a discounted car or need to show strike through pricing. |
| 216 | + if (carDetails.getReferencePrice() != null) { |
| 217 | + LOGGER.info("Reference Price: {}", carDetails.getReferencePrice()); |
| 218 | + } |
| 219 | + |
| 220 | + // List of additional fees including both mandatory and optional fees such as young driver |
| 221 | + // fee/drop off fee /CollisionDamageWaiver. |
| 222 | + if (carDetails.getAdditionalFees() != null) { |
| 223 | + LOGGER.info("Additional Fees: {}", carDetails.getAdditionalFees()); |
| 224 | + } |
| 225 | + |
| 226 | + // Description and costs of any optional special equipment that may be rented with the car. |
| 227 | + if (carDetails.getSpecialEquipments() != null) { |
| 228 | + LOGGER.info("Special Equipments: {}", carDetails.getSpecialEquipments()); |
| 229 | + } |
| 230 | + |
| 231 | + // Limitations that are part of this rental agreement. |
| 232 | + if (carDetails.getRentalLimits() != null) { |
| 233 | + LOGGER.info("Rental Limits: {}", carDetails.getRentalLimits()); |
| 234 | + } |
| 235 | + |
| 236 | + // Cancellation Policy Container. |
| 237 | + LOGGER.info("Cancellation Policy: {}", carDetails.getCancellationPolicy()); |
| 238 | + |
| 239 | + // Container for no show penalty |
| 240 | + if (carDetails.getNoShowPenalty() != null) { |
| 241 | + LOGGER.info("No Show Penalty: {}", carDetails.getNoShowPenalty()); |
| 242 | + } |
| 243 | + |
| 244 | + // A list of policies that apply to this car rental. |
| 245 | + if (carDetails.getCarPolicies() != null) { |
| 246 | + LOGGER.info("Policies: {}", carDetails.getCarPolicies()); |
| 247 | + } |
| 248 | + |
| 249 | + // List of image resources of the car product. |
| 250 | + if (carDetails.getImages() != null) { |
| 251 | + LOGGER.info("Images: {}", carDetails.getImages()); |
| 252 | + } |
| 253 | + |
| 254 | + LOGGER.info("========== Property End =========="); |
| 255 | + } |
| 256 | + |
| 257 | + }); |
| 258 | + |
| 259 | + LOGGER.info("========== End QuickStartExample =========="); |
| 260 | + } |
| 261 | + |
| 262 | +} |
0 commit comments