From 1d6b8bfbfb47dfc3b6c147a3442178e9d1324ac2 Mon Sep 17 00:00:00 2001 From: Nasser Anssari Date: Mon, 16 Dec 2024 16:30:36 +0300 Subject: [PATCH] chore: add PR check to verify examples --- .github/workflows/verify-examples.yaml | 33 + examples/pom.xml | 17 + .../sdk/rapid/examples/Constants.java | 17 +- .../examples/RapidSdkDemoApplication.java | 485 ++++++++------- .../DefaultRapidPartnerProfile.java | 20 +- .../RapidPartnerSalesProfile.java | 12 +- .../examples/scenarios/RapidScenario.java | 19 +- .../booking/AsyncSingleRoomBookScenario.java | 175 +++--- .../MultiRoomHoldAndResumeBookScenario.java | 156 +++-- .../booking/SingleRoomBookScenario.java | 106 ++-- ...tyContentInAdditionalLanguageScenario.java | 155 +++-- .../content/GetPropertyContentScenario.java | 77 ++- .../GetListOfRegionNamesScenario.java | 68 +- .../GetRegionByAncestorIdScenario.java | 81 ++- ...etRegionDetailsAndPropertyIdsScenario.java | 75 ++- .../ParseRegionAncestorsScenario.java | 73 ++- .../ParseRegionCategoriesScenario.java | 75 ++- .../ParseRegionCoordinatesScenario.java | 97 +-- .../ParseRegionDescendantsScenario.java | 84 +-- ...onWithMultiPolygonCoordinatesScenario.java | 89 +-- .../CancelHeldBookingScenario.java | 103 +-- .../ChangeRoomDetailsScenario.java | 161 ++--- .../managebooking/DeleteRoomScenario.java | 136 ++-- ...itionalAvailabilityOfPropertyScenario.java | 89 +-- .../GetPaymentOptionsOfRoomScenario.java | 119 ++-- .../rapid/examples/services/BookService.java | 586 ++++++++++++------ .../examples/services/ContentService.java | 108 +++- .../examples/services/GeographyService.java | 168 +++-- .../rapid/examples/services/RapidService.java | 22 +- .../rapid/examples/services/ShopService.java | 240 ++++--- 30 files changed, 2202 insertions(+), 1444 deletions(-) create mode 100644 .github/workflows/verify-examples.yaml diff --git a/.github/workflows/verify-examples.yaml b/.github/workflows/verify-examples.yaml new file mode 100644 index 0000000000..04ac549e4b --- /dev/null +++ b/.github/workflows/verify-examples.yaml @@ -0,0 +1,33 @@ +name: Verify Examples +on: + pull_request: + branches: + - 'main' +jobs: + detect-changes: + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + examples: ${{ steps.filter.outputs.examples }} + steps: + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + examples: + - 'examples/**' + + verify-examples: + needs: detect-changes + if: ${{ needs.detect-changes.outputs.examples == 'true' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + - name: verify examples + working-directory: examples + run: mvn clean install diff --git a/examples/pom.xml b/examples/pom.xml index 4cda18d536..92afe8ea25 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -49,6 +49,23 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.5.0 + + google_checks.xml + true + warning + + + + + check + + + + org.codehaus.mojo exec-maven-plugin diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/Constants.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/Constants.java index cf68d7f01a..d428d55cc1 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/Constants.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/Constants.java @@ -1,17 +1,20 @@ package com.expediagroup.sdk.rapid.examples; +/** + * Constants used throughout the application. + */ public class Constants { - public static final String TEST_PROPERTY_ID = "11775754"; + public static final String TEST_PROPERTY_ID = "11775754"; - public static final String TEST_REGION_ID = "178248"; + public static final String TEST_REGION_ID = "178248"; - public static final String TEST_REGION_ID_WITH_MULTIPOLYGON = "553248635740541470"; + public static final String TEST_REGION_ID_WITH_MULTIPOLYGON = "553248635740541470"; - public static final String TEST_ANCESTOR_ID = "602962"; + public static final String TEST_ANCESTOR_ID = "602962"; - public static final String CUSTOMER_IP = "5.5.5.5"; + public static final String CUSTOMER_IP = "5.5.5.5"; - public static final String SANDBOX_URL = "https://test.ean.com/"; + public static final String SANDBOX_URL = "https://test.ean.com/"; - public static final String CUSTOMER_SESSION_ID = "123455656565"; + public static final String CUSTOMER_SESSION_ID = "123455656565"; } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/RapidSdkDemoApplication.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/RapidSdkDemoApplication.java index 269e5998f8..45e6f2915a 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/RapidSdkDemoApplication.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/RapidSdkDemoApplication.java @@ -19,231 +19,272 @@ import com.expediagroup.sdk.rapid.examples.scenarios.managebooking.DeleteRoomScenario; import com.expediagroup.sdk.rapid.examples.scenarios.shopping.GetAdditionalAvailabilityOfPropertyScenario; import com.expediagroup.sdk.rapid.examples.scenarios.shopping.GetPaymentOptionsOfRoomScenario; +import java.util.concurrent.ExecutionException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.ExecutionException; - - +/** + * Main class to run the Rapid SDK demonstration. + */ public class RapidSdkDemoApplication { - private static final Logger logger = LoggerFactory.getLogger(RapidSdkDemoApplication.class); - - public static void main(String[] args) throws ExecutionException, InterruptedException { - - logger.info("======================================================================================="); - logger.info("======================================================================================="); - logger.info("== =="); - logger.info("== Howdy! This is a demonstration of Expedia Group RAPID SDK, Enjoy! =="); - logger.info("== =="); - logger.info("======================================================================================="); - logger.info("======================================================================================="); - - logger.info("=============================== Running Shopping Scenarios ============================"); - - /* Run Get Additional Availability Of Property Scenario using the default profile - This scenario demonstrates the following: - 1. Getting property availability for a test property - 2. Getting additional availability of the first property returned - */ - GetAdditionalAvailabilityOfPropertyScenario getAdditionalAvailabilityOfPropertyScenario = new GetAdditionalAvailabilityOfPropertyScenario(); - getAdditionalAvailabilityOfPropertyScenario.setProfile(new DefaultRapidPartnerProfile()); - getAdditionalAvailabilityOfPropertyScenario.run(); - - /* Run Get Payment Options Of Room Scenario using the default profile - This scenario demonstrates the following: - 1. Shopping for properties - 2. Checking room prices for the property - 3. Getting payment options of the first room in the property - */ - GetPaymentOptionsOfRoomScenario getPaymentOptionsOfRoomScenario = new GetPaymentOptionsOfRoomScenario(); - getPaymentOptionsOfRoomScenario.setProfile(new DefaultRapidPartnerProfile()); - getPaymentOptionsOfRoomScenario.run(); - - logger.info("=============================== End of Shopping Scenarios ============================="); - - logger.info("=============================== Running Booking Scenarios ============================="); - - /* Run Single Room Book Scenario using the default profile - This scenario demonstrates the following: - 1. Shopping for properties - 2. Checking room prices for the property - 3. Booking the property - */ - SingleRoomBookScenario singleRoomBookScenario = new SingleRoomBookScenario(); - singleRoomBookScenario.setProfile(new DefaultRapidPartnerProfile()); - singleRoomBookScenario.run(); - - /* Run Async Single Room Book Scenario using the default profile - This scenario demonstrates the following: - 1. Shopping for properties - 2. Checking room prices for the property - 3. Booking the property in asynchronous manner - */ - AsyncSingleRoomBookScenario asyncSingleRoomBookScenario = new AsyncSingleRoomBookScenario(); - asyncSingleRoomBookScenario.setProfile(new DefaultRapidPartnerProfile()); - asyncSingleRoomBookScenario.run(); - - /* Run Multiple Room Hold and Resume Book Scenario using the default profile - This scenario demonstrates the following: - 1. Shopping for properties with specifying multiple occupancy instances for multiple rooms - 2. Checking room prices for the property rooms. - 3. Hold the property rooms. - 4. Resume the booking process. - */ - MultiRoomHoldAndResumeBookScenario multiRoomHoldAndResumeBookScenario = new MultiRoomHoldAndResumeBookScenario(); - multiRoomHoldAndResumeBookScenario.setProfile(new DefaultRapidPartnerProfile()); - multiRoomHoldAndResumeBookScenario.run(); - - logger.info("=============================== End of Booking Scenarios =============================="); - - logger.info("=============================== Running Manage Booking Scenarios ==========================="); - - /* Run Change Room Details Scenario using the default profile - This scenario demonstrates the following: - 1. Shopping for properties - 2. Checking room prices for the property - 3. Booking a single room in the property - 4. Retrieve itinerary by itinerary id - 5. Change room details for first room in booking - 6. Retrieve updated itinerary - */ - ChangeRoomDetailsScenario changeRoomDetailsScenario = new ChangeRoomDetailsScenario(); - changeRoomDetailsScenario.setProfile(new DefaultRapidPartnerProfile()); - changeRoomDetailsScenario.run(); - - /* Run Cancel Held Booking Scenario using the default profile - This scenario demonstrates the following: - 1. Shopping for properties - 2. Checking room prices for the property - 3. Booking a room with hold in the property - 4. Cancelling the held booking - */ - CancelHeldBookingScenario cancelHeldBookingScenario = new CancelHeldBookingScenario(); - cancelHeldBookingScenario.setProfile(new DefaultRapidPartnerProfile()); - cancelHeldBookingScenario.run(); - - /* Run Delete Room Scenario using the default profile - This scenario demonstrates the following: - 1. Shopping for properties - 2. Checking room prices for the property - 3. Booking a room in the property - 4. Retrieve itinerary by itinerary id - 5. Deleting the first room in booking - 6. Retrieve updated itinerary - */ - DeleteRoomScenario deleteRoomScenario = new DeleteRoomScenario(); - deleteRoomScenario.setProfile(new DefaultRapidPartnerProfile()); - deleteRoomScenario.run(); - - logger.info("=============================== End of Manage Booking Scenarios ==========================="); - - logger.info("=============================== Running Property Content Scenarios ==========================="); - - /* Run Get Property Content Scenario using the default profile - This scenario demonstrates the following: - 1. Getting property content by property id - */ - GetPropertyContentScenario getPropertyContentScenario = new GetPropertyContentScenario(); - getPropertyContentScenario.setProfile(new DefaultRapidPartnerProfile()); - getPropertyContentScenario.run(); - - /* Run Get Property Content In Additional Language Scenario using the default profile - This scenario demonstrates the following: - 1. Getting property content by property id - 2. Getting property content in additional language - */ - GetPropertyContentInAdditionalLanguageScenario getPropertyContentInAdditionalLanguageScenario = new GetPropertyContentInAdditionalLanguageScenario(); - getPropertyContentInAdditionalLanguageScenario.setProfile(new DefaultRapidPartnerProfile()); - getPropertyContentInAdditionalLanguageScenario.run(); - - logger.info("=============================== End of Property Content Scenarios ==========================="); - - logger.info("=============================== Running Geography Scenarios ==========================="); - - /* Run Get List of Region Names Scenario using the default profile - This scenario demonstrates the following: - 1. Getting all regions with details in a paginated manner - 2. Filtering region names - */ - GetListOfRegionNamesScenario getListOfRegionNamesScenario = new GetListOfRegionNamesScenario(); - getListOfRegionNamesScenario.setProfile(new DefaultRapidPartnerProfile()); - getListOfRegionNamesScenario.run(); - - /* Run Get Region Name of Region Scenario using the default profile - This scenario demonstrates the following: - 1. Getting region details by region id - 2. Accessing region details - */ - GetRegionDetailsAndPropertyIdsScenario getRegionNameOfRegionScenario = new GetRegionDetailsAndPropertyIdsScenario(); - getRegionNameOfRegionScenario.setProfile(new DefaultRapidPartnerProfile()); - getRegionNameOfRegionScenario.run(); - - /* Run Get Region By Ancestor Id Scenario using the default profile - This scenario demonstrates the following: - 1. Getting paginated regions details by ancestor id - 2. Accessing region details - */ - GetRegionByAncestorIdScenario getRegionByAncestorIdScenario = new GetRegionByAncestorIdScenario(); - getRegionByAncestorIdScenario.setProfile(new DefaultRapidPartnerProfile()); - getRegionByAncestorIdScenario.run(); - - /* Run Get Region With MultiPolygon Coordinates Scenario using the default profile - This scenario demonstrates the following: - 1. Getting region details with multipolygon coordinates by region id - 2. Accessing region coordinates of type multipolygon - 3. Accessing every polygon list of coordinates. - */ - ParseRegionWithMultiPolygonCoordinatesScenario parseRegionWithMultiPolygonCoordinatesScenario = new ParseRegionWithMultiPolygonCoordinatesScenario(); - parseRegionWithMultiPolygonCoordinatesScenario.setProfile(new DefaultRapidPartnerProfile()); - parseRegionWithMultiPolygonCoordinatesScenario.run(); - - /* Run Parse Region Ancestors Scenario using the default profile - This scenario demonstrates the following: - 1. Getting region details with ancestors by region id - 2. Parsing region ancestors - */ - ParseRegionAncestorsScenario parseRegionAncestorsScenario = new ParseRegionAncestorsScenario(); - parseRegionAncestorsScenario.setProfile(new DefaultRapidPartnerProfile()); - parseRegionAncestorsScenario.run(); - - /* Run Parse Region Descendants Scenario using the default profile - This scenario demonstrates the following: - 1. Getting region details with descendants by region id - 2. Parsing region descendants - */ - ParseRegionDescendantsScenario parseRegionDescendantsScenario = new ParseRegionDescendantsScenario(); - parseRegionDescendantsScenario.setProfile(new DefaultRapidPartnerProfile()); - parseRegionDescendantsScenario.run(); - - /* Run Parse Region Coordinates Scenario using the default profile - This scenario demonstrates the following: - 1. Getting region details with coordinates by region id - 2. Parsing region coordinates - */ - ParseRegionCoordinatesScenario parseRegionCoordinatesScenario = new ParseRegionCoordinatesScenario(); - parseRegionCoordinatesScenario.setProfile(new DefaultRapidPartnerProfile()); - parseRegionCoordinatesScenario.run(); - - /* Run Parse Region Categories Scenario using the default profile - This scenario demonstrates the following: - 1. Getting region details with property ids by region id - 2. Parsing region categories - */ - ParseRegionCategoriesScenario parseRegionCategoriesScenario = new ParseRegionCategoriesScenario(); - parseRegionCategoriesScenario.setProfile(new DefaultRapidPartnerProfile()); - parseRegionCategoriesScenario.run(); - - logger.info("=============================== End of Geography Scenarios ==========================="); - - - logger.info("======================================================================================="); - logger.info("======================================================================================="); - logger.info("== =="); - logger.info("== That's all folks! That was the demonstration of RAPID SDK. =="); - logger.info("== =="); - logger.info("======================================================================================="); - logger.info("======================================================================================="); - System.exit(0); - } + private static final Logger logger = LoggerFactory.getLogger(RapidSdkDemoApplication.class); + + /** + * Main method to run the Rapid SDK demonstration. + * + * @param args The command line arguments. + * @throws ExecutionException If the execution fails. + * @throws InterruptedException If the execution is interrupted. + */ + public static void main(String[] args) throws ExecutionException, InterruptedException { + + logger.info( + "======================================================================================="); + logger.info( + "======================================================================================="); + logger.info( + "== =="); + logger.info( + "== Howdy! This is a demonstration of Expedia Group RAPID SDK, Enjoy! =="); + logger.info( + "== =="); + logger.info( + "======================================================================================="); + logger.info( + "======================================================================================="); + + logger.info( + "=============================== Running Shopping Scenarios ============================"); + + /* Run Get Additional Availability Of Property Scenario using the default profile + This scenario demonstrates the following: + 1. Getting property availability for a test property + 2. Getting additional availability of the first property returned + */ + GetAdditionalAvailabilityOfPropertyScenario getAdditionalAvailabilityOfPropertyScenario = + new GetAdditionalAvailabilityOfPropertyScenario(); + getAdditionalAvailabilityOfPropertyScenario.setProfile(new DefaultRapidPartnerProfile()); + getAdditionalAvailabilityOfPropertyScenario.run(); + + /* Run Get Payment Options Of Room Scenario using the default profile + This scenario demonstrates the following: + 1. Shopping for properties + 2. Checking room prices for the property + 3. Getting payment options of the first room in the property + */ + GetPaymentOptionsOfRoomScenario getPaymentOptionsOfRoomScenario = + new GetPaymentOptionsOfRoomScenario(); + getPaymentOptionsOfRoomScenario.setProfile(new DefaultRapidPartnerProfile()); + getPaymentOptionsOfRoomScenario.run(); + + logger.info( + "=============================== End of Shopping Scenarios ============================="); + + logger.info( + "=============================== Running Booking Scenarios ============================="); + + /* Run Single Room Book Scenario using the default profile + This scenario demonstrates the following: + 1. Shopping for properties + 2. Checking room prices for the property + 3. Booking the property + */ + SingleRoomBookScenario singleRoomBookScenario = new SingleRoomBookScenario(); + singleRoomBookScenario.setProfile(new DefaultRapidPartnerProfile()); + singleRoomBookScenario.run(); + + /* Run Async Single Room Book Scenario using the default profile + This scenario demonstrates the following: + 1. Shopping for properties + 2. Checking room prices for the property + 3. Booking the property in asynchronous manner + */ + AsyncSingleRoomBookScenario asyncSingleRoomBookScenario = new AsyncSingleRoomBookScenario(); + asyncSingleRoomBookScenario.setProfile(new DefaultRapidPartnerProfile()); + asyncSingleRoomBookScenario.run(); + + /* Run Multiple Room Hold and Resume Book Scenario using the default profile + This scenario demonstrates the following: + 1. Shopping for properties with specifying multiple occupancy instances for multiple rooms + 2. Checking room prices for the property rooms. + 3. Hold the property rooms. + 4. Resume the booking process. + */ + MultiRoomHoldAndResumeBookScenario multiRoomHoldAndResumeBookScenario = + new MultiRoomHoldAndResumeBookScenario(); + multiRoomHoldAndResumeBookScenario.setProfile(new DefaultRapidPartnerProfile()); + multiRoomHoldAndResumeBookScenario.run(); + + logger.info( + "=============================== End of Booking Scenarios =============================="); + + logger.info( + "=========================== Running Manage Booking Scenarios ==========================="); + + /* Run Change Room Details Scenario using the default profile + This scenario demonstrates the following: + 1. Shopping for properties + 2. Checking room prices for the property + 3. Booking a single room in the property + 4. Retrieve itinerary by itinerary id + 5. Change room details for first room in booking + 6. Retrieve updated itinerary + */ + ChangeRoomDetailsScenario changeRoomDetailsScenario = new ChangeRoomDetailsScenario(); + changeRoomDetailsScenario.setProfile(new DefaultRapidPartnerProfile()); + changeRoomDetailsScenario.run(); + + /* Run Cancel Held Booking Scenario using the default profile + This scenario demonstrates the following: + 1. Shopping for properties + 2. Checking room prices for the property + 3. Booking a room with hold in the property + 4. Cancelling the held booking + */ + CancelHeldBookingScenario cancelHeldBookingScenario = new CancelHeldBookingScenario(); + cancelHeldBookingScenario.setProfile(new DefaultRapidPartnerProfile()); + cancelHeldBookingScenario.run(); + + /* Run Delete Room Scenario using the default profile + This scenario demonstrates the following: + 1. Shopping for properties + 2. Checking room prices for the property + 3. Booking a room in the property + 4. Retrieve itinerary by itinerary id + 5. Deleting the first room in booking + 6. Retrieve updated itinerary + */ + DeleteRoomScenario deleteRoomScenario = new DeleteRoomScenario(); + deleteRoomScenario.setProfile(new DefaultRapidPartnerProfile()); + deleteRoomScenario.run(); + + logger.info( + "============================ End of Manage Booking Scenarios ==========================="); + + logger.info( + "========================== Running Property Content Scenarios =========================="); + + /* Run Get Property Content Scenario using the default profile + This scenario demonstrates the following: + 1. Getting property content by property id + */ + GetPropertyContentScenario getPropertyContentScenario = new GetPropertyContentScenario(); + getPropertyContentScenario.setProfile(new DefaultRapidPartnerProfile()); + getPropertyContentScenario.run(); + + /* Run Get Property Content In Additional Language Scenario using the default profile + This scenario demonstrates the following: + 1. Getting property content by property id + 2. Getting property content in additional language + */ + GetPropertyContentInAdditionalLanguageScenario getPropertyContentInAdditionalLanguageScenario = + new GetPropertyContentInAdditionalLanguageScenario(); + getPropertyContentInAdditionalLanguageScenario.setProfile(new DefaultRapidPartnerProfile()); + getPropertyContentInAdditionalLanguageScenario.run(); + + logger.info( + "========================== End of Property Content Scenarios ==========================="); + + logger.info( + "============================= Running Geography Scenarios ============================="); + + /* Run Get List of Region Names Scenario using the default profile + This scenario demonstrates the following: + 1. Getting all regions with details in a paginated manner + 2. Filtering region names + */ + GetListOfRegionNamesScenario getListOfRegionNamesScenario = new GetListOfRegionNamesScenario(); + getListOfRegionNamesScenario.setProfile(new DefaultRapidPartnerProfile()); + getListOfRegionNamesScenario.run(); + + /* Run Get Region Name of Region Scenario using the default profile + This scenario demonstrates the following: + 1. Getting region details by region id + 2. Accessing region details + */ + GetRegionDetailsAndPropertyIdsScenario getRegionNameOfRegionScenario = + new GetRegionDetailsAndPropertyIdsScenario(); + getRegionNameOfRegionScenario.setProfile(new DefaultRapidPartnerProfile()); + getRegionNameOfRegionScenario.run(); + + /* Run Get Region By Ancestor Id Scenario using the default profile + This scenario demonstrates the following: + 1. Getting paginated regions details by ancestor id + 2. Accessing region details + */ + GetRegionByAncestorIdScenario getRegionByAncestorIdScenario = + new GetRegionByAncestorIdScenario(); + getRegionByAncestorIdScenario.setProfile(new DefaultRapidPartnerProfile()); + getRegionByAncestorIdScenario.run(); + + /* Run Get Region With MultiPolygon Coordinates Scenario using the default profile + This scenario demonstrates the following: + 1. Getting region details with multipolygon coordinates by region id + 2. Accessing region coordinates of type multipolygon + 3. Accessing every polygon list of coordinates. + */ + ParseRegionWithMultiPolygonCoordinatesScenario parseRegionWithMultiPolygonCoordinatesScenario = + new ParseRegionWithMultiPolygonCoordinatesScenario(); + parseRegionWithMultiPolygonCoordinatesScenario.setProfile(new DefaultRapidPartnerProfile()); + parseRegionWithMultiPolygonCoordinatesScenario.run(); + + /* Run Parse Region Ancestors Scenario using the default profile + This scenario demonstrates the following: + 1. Getting region details with ancestors by region id + 2. Parsing region ancestors + */ + ParseRegionAncestorsScenario parseRegionAncestorsScenario = new ParseRegionAncestorsScenario(); + parseRegionAncestorsScenario.setProfile(new DefaultRapidPartnerProfile()); + parseRegionAncestorsScenario.run(); + + /* Run Parse Region Descendants Scenario using the default profile + This scenario demonstrates the following: + 1. Getting region details with descendants by region id + 2. Parsing region descendants + */ + ParseRegionDescendantsScenario parseRegionDescendantsScenario = + new ParseRegionDescendantsScenario(); + parseRegionDescendantsScenario.setProfile(new DefaultRapidPartnerProfile()); + parseRegionDescendantsScenario.run(); + + /* Run Parse Region Coordinates Scenario using the default profile + This scenario demonstrates the following: + 1. Getting region details with coordinates by region id + 2. Parsing region coordinates + */ + ParseRegionCoordinatesScenario parseRegionCoordinatesScenario = + new ParseRegionCoordinatesScenario(); + parseRegionCoordinatesScenario.setProfile(new DefaultRapidPartnerProfile()); + parseRegionCoordinatesScenario.run(); + + /* Run Parse Region Categories Scenario using the default profile + This scenario demonstrates the following: + 1. Getting region details with property ids by region id + 2. Parsing region categories + */ + ParseRegionCategoriesScenario parseRegionCategoriesScenario = + new ParseRegionCategoriesScenario(); + parseRegionCategoriesScenario.setProfile(new DefaultRapidPartnerProfile()); + parseRegionCategoriesScenario.run(); + + logger.info( + "=============================== End of Geography Scenarios ==========================="); + + logger.info( + "======================================================================================="); + logger.info( + "======================================================================================="); + logger.info( + "== =="); + logger.info( + "== That's all folks! That was the demonstration of RAPID SDK. =="); + logger.info( + "== =="); + logger.info( + "======================================================================================="); + logger.info( + "======================================================================================="); + System.exit(0); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/salesprofiles/DefaultRapidPartnerProfile.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/salesprofiles/DefaultRapidPartnerProfile.java index e104bb3efc..e51fbf12af 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/salesprofiles/DefaultRapidPartnerProfile.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/salesprofiles/DefaultRapidPartnerProfile.java @@ -1,12 +1,16 @@ package com.expediagroup.sdk.rapid.examples.salesprofiles; - +/** + * Default Rapid Partner Profile. + */ public final class DefaultRapidPartnerProfile extends RapidPartnerSalesProfile { - - public DefaultRapidPartnerProfile() { - this.billingTerms = null; - this.paymentTerms = null; - this.partnerPointOfSale = null; - this.platformName = null; - } + /** + * Default constructor. + */ + public DefaultRapidPartnerProfile() { + this.billingTerms = null; + this.paymentTerms = null; + this.partnerPointOfSale = null; + this.platformName = null; + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/salesprofiles/RapidPartnerSalesProfile.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/salesprofiles/RapidPartnerSalesProfile.java index c8cb6eb49b..e6177c1629 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/salesprofiles/RapidPartnerSalesProfile.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/salesprofiles/RapidPartnerSalesProfile.java @@ -1,14 +1,16 @@ package com.expediagroup.sdk.rapid.examples.salesprofiles; - +/** + * Rapid Partner Sales Profile. + */ public abstract class RapidPartnerSalesProfile { - public String billingTerms; + public String billingTerms; - public String paymentTerms; + public String paymentTerms; - public String partnerPointOfSale; + public String partnerPointOfSale; - public String platformName; + public String platformName; } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/RapidScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/RapidScenario.java index bd0483137d..18e6194bda 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/RapidScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/RapidScenario.java @@ -1,12 +1,25 @@ package com.expediagroup.sdk.rapid.examples.scenarios; import com.expediagroup.sdk.rapid.examples.salesprofiles.RapidPartnerSalesProfile; - import java.util.concurrent.ExecutionException; +/** + * Interface representing a scenario to be executed with a specific sales profile. + */ public interface RapidScenario { - void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile); + /** + * Sets the sales profile for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to be set + */ + void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile); - void run() throws ExecutionException, InterruptedException; + /** + * Executes the scenario. + * + * @throws ExecutionException if an error occurs during execution + * @throws InterruptedException if the execution is interrupted + */ + void run() throws ExecutionException, InterruptedException; } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/AsyncSingleRoomBookScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/AsyncSingleRoomBookScenario.java index 9e9e7f445e..4a4c2b7963 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/AsyncSingleRoomBookScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/AsyncSingleRoomBookScenario.java @@ -11,93 +11,124 @@ import com.expediagroup.sdk.rapid.models.Property; import com.expediagroup.sdk.rapid.models.PropertyAvailability; import com.expediagroup.sdk.rapid.models.RoomPriceCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Scenario for booking a single room asynchronously. + */ public class AsyncSingleRoomBookScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(AsyncSingleRoomBookScenario.class); - private ShopService shopService = new ShopService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = LoggerFactory.getLogger(AsyncSingleRoomBookScenario.class); + private ShopService shopService = new ShopService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to book a single room asynchronously. + */ + @Override + public void run() { + + logger.info( + "Running Book Single Room Scenario using the default profile in asynchronous manner..."); + + // Shopping for properties + logger.info("Async call - Getting property availability for test property: {}", + Constants.TEST_PROPERTY_ID); + + shopService.asyncGetSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile) + .thenApply(Response::getData) + .thenCompose(this::checkRoomPrices) + .thenCompose(this::bookRoom) + .thenCompose(this::getItinerary) + .thenAccept(itinerary -> { + if (itinerary == null) { + throw new IllegalStateException("Itinerary is null"); + } + logger.info("Itinerary: {}", itinerary.getItineraryId()); + }); + + } + + /** + * Retrieves the itinerary for the booking. + * + * @param itineraryCreation the itinerary creation details + * @return a CompletableFuture with the itinerary + */ + private CompletableFuture getItinerary(ItineraryCreation itineraryCreation) { + if (itineraryCreation == null) { + throw new IllegalStateException("ItineraryCreation is null"); } - @Override - public void run() { - - logger.info("Running Book Single Room Scenario using the default profile in asynchronous manner..."); - - // Shopping for properties - logger.info("Async call - Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); - - shopService.asyncGetSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile) - .thenApply(Response::getData) - .thenCompose(this::checkRoomPrices) - .thenCompose(this::bookRoom) - .thenCompose(this::getItinerary) - .thenAccept(itinerary -> { - if (itinerary == null) { - throw new IllegalStateException("Itinerary is null"); - } - logger.info("Itinerary: {}", itinerary.getItineraryId()); - }); - + logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId()); + + // Manage booking + logger.info("Getting itinerary by itinerary id..."); + BookService bookService = new BookService(); + return bookService.asyncGetReservation(itineraryCreation) + .thenApply(response -> response.getData()); + } + + /** + * Books a room based on the room price check. + * + * @param roomPriceCheck the room price check details + * @return a CompletableFuture with the itinerary creation details + */ + private CompletableFuture bookRoom(RoomPriceCheck roomPriceCheck) { + if (roomPriceCheck == null) { + throw new IllegalStateException("Room Price Check is null"); } - private CompletableFuture getItinerary(ItineraryCreation itineraryCreation) { - if (itineraryCreation == null) { - throw new IllegalStateException("ItineraryCreation is null"); - } - - logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId()); - - // Manage booking - logger.info("Getting itinerary by itinerary id..."); - BookService bookService = new BookService(); - return bookService.asyncGetReservation(itineraryCreation) - .thenApply(response -> response.getData()); + logger.info("Room Price Check: {}", roomPriceCheck.getStatus()); + + // Booking a single room in the property + logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID); + + BookService bookService = new BookService(); + return bookService.asyncCreateBooking(roomPriceCheck, Arrays.asList("2")) + .thenApply(response -> response.getData()); + } + + /** + * Checks the room prices for the available properties. + * + * @param propertyAvailabilityList the list of available properties + * @return a CompletableFuture with the room price check details + */ + private CompletableFuture checkRoomPrices( + List propertyAvailabilityList) { + if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { + throw new IllegalStateException("No property availability found for the test property."); } - private CompletableFuture bookRoom(RoomPriceCheck roomPriceCheck) { - if (roomPriceCheck == null) { - throw new IllegalStateException("Room Price Check is null"); - } - - logger.info("Room Price Check: {}", roomPriceCheck.getStatus()); + logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - // Booking a single room in the property - logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID); + // Checking room prices for the property + logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID); + Property property = propertyAvailabilityList.get(0); - BookService bookService = new BookService(); - return bookService.asyncCreateBooking(roomPriceCheck, Arrays.asList("2")) - .thenApply(response -> response.getData()); + if (!(property instanceof PropertyAvailability)) { + throw new IllegalStateException("Property is not an instance of PropertyAvailability"); } - private CompletableFuture checkRoomPrices(List propertyAvailabilityList) { - if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { - throw new IllegalStateException("No property availability found for the test property."); - } + PropertyAvailability propertyAvailability = (PropertyAvailability) property; + return shopService.asyncCheckRoomPrices(propertyAvailability, 0, 0) + .thenApply(response -> response.getData()); - logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - - // Checking room prices for the property - logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID); - Property property = propertyAvailabilityList.get(0); - - if (!(property instanceof PropertyAvailability)) { - throw new IllegalStateException("Property is not an instance of PropertyAvailability"); - } - - PropertyAvailability propertyAvailability = (PropertyAvailability) property; - return shopService.asyncCheckRoomPrices(propertyAvailability, 0, 0) - .thenApply(response -> response.getData()); - - } + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/MultiRoomHoldAndResumeBookScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/MultiRoomHoldAndResumeBookScenario.java index 73d340d5ee..8947c6ce22 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/MultiRoomHoldAndResumeBookScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/MultiRoomHoldAndResumeBookScenario.java @@ -12,78 +12,100 @@ import com.expediagroup.sdk.rapid.models.Property; import com.expediagroup.sdk.rapid.models.PropertyAvailability; import com.expediagroup.sdk.rapid.models.RoomPriceCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * This scenario demonstrates how to book multiple rooms with hold and resume functionality. + * The scenario performs the following steps: + * 1. Shopping for properties + * 2. Check room prices for the property + * 3. Book multiple rooms in the property with hold=true + * 4. Resume the booking process + * 5. Make a retrieve call to verify the booking has been resumed properly + */ public class MultiRoomHoldAndResumeBookScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(MultiRoomHoldAndResumeBookScenario.class); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - private ShopService shopService = new ShopService(); - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = + LoggerFactory.getLogger(MultiRoomHoldAndResumeBookScenario.class); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + private ShopService shopService = new ShopService(); + + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + @Override + public void run() { + + logger.info( + "Running Book Multiple Rooms with Hold and Resume Scenario using the default profile..."); + + // Shopping for properties + /* + * To request multiple rooms (of the same type), include one instance of occupancy for each room + * requested. + * Up to 8 rooms may be requested or booked at once. + */ + logger.info("Getting property availability for test property: [{}]", + Constants.TEST_PROPERTY_ID); + List occupancy = Arrays.asList("2", "2"); + List propertyAvailabilityList = + shopService.getPropertiesAvailability(occupancy, this.rapidPartnerSalesProfile).getData(); + + if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { + throw new IllegalStateException("No property availability found for the test property."); } - @Override - public void run() { - - logger.info("Running Book Multiple Rooms with Hold and Resume Scenario using the default profile..."); - - // Shopping for properties - /* - * To request multiple rooms (of the same type), include one instance of occupancy for each room requested. - * Up to 8 rooms may be requested or booked at once. - */ - logger.info("Getting property availability for test property: [{}]", Constants.TEST_PROPERTY_ID); - List occupancy = Arrays.asList("2", "2"); - List propertyAvailabilityList = shopService.getPropertiesAvailability(occupancy, this.rapidPartnerSalesProfile).getData(); - - if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { - throw new IllegalStateException("No property availability found for the test property."); - } - - logger.info("Property Availability found for property id: [{}] with status: [{}]", - propertyAvailabilityList.get(0).getPropertyId(), - propertyAvailabilityList.get(0).getStatus()); - - // Check room prices for the property - logger.info("Checking room prices for property id: [{}]...", Constants.TEST_PROPERTY_ID); - PropertyAvailability propertyAvailability = (PropertyAvailability) propertyAvailabilityList.get(0); - RoomPriceCheck roomPriceCheck = null; - - roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); - logger.info("Room price check status: [{}]", roomPriceCheck.getStatus()); - - /* - * Book multiple rooms in the property. - * The Booking link from your previous Price Check response expires after a short period. - * If you receive an HTTP 503 error upon your first attempt, the link has likely expired. - * Obtain a new link and attempt your booking again. - */ - logger.info("Booking 2 rooms with [hold=true] in test property: [{}]...", Constants.TEST_PROPERTY_ID); - BookService bookService = new BookService(); - ItineraryCreation itineraryCreation = bookService.createBookingWithHold(roomPriceCheck, occupancy).getData(); - logger.info("Booking with hold success. Itinerary id: [{}]. Link to resume booking: [{}]", - itineraryCreation.getItineraryId(), itineraryCreation.getLinks().getResume().getHref()); - - // Resume the booking process - logger.info("Resuming the booking process..."); - Response response = bookService.resumeBooking(itineraryCreation); - logger.info("Resume booking response status: [{}]", response.getStatusCode()); - - // Make a retrieve call to verify the booking has been resumed properly. - logger.info("Getting itinerary by itinerary id: [{}] to verify the booking has been resumed successfully...", - itineraryCreation.getItineraryId()); - Itinerary itinerary = bookService.getReservation(itineraryCreation).getData(); - - logger.info("Itinerary rooms status after resume booking:"); - itinerary.getRooms().forEach(room -> - logger.info("Room: [{}], Status: [{}]", room.getId(), room.getStatus()) - ); - } + logger.info("Property Availability found for property id: [{}] with status: [{}]", + propertyAvailabilityList.get(0).getPropertyId(), + propertyAvailabilityList.get(0).getStatus()); + + // Check room prices for the property + logger.info("Checking room prices for property id: [{}]...", Constants.TEST_PROPERTY_ID); + PropertyAvailability propertyAvailability = + (PropertyAvailability) propertyAvailabilityList.get(0); + RoomPriceCheck roomPriceCheck = null; + + roomPriceCheck = shopService.checkRoomPrices( + propertyAvailability, + 0, + 0 + ).getData(); + logger.info("Room price check status: [{}]", roomPriceCheck.getStatus()); + + /* + * Book multiple rooms in the property. + * The Booking link from your previous Price Check response expires after a short period. + * If you receive an HTTP 503 error upon your first attempt, the link has likely expired. + * Obtain a new link and attempt your booking again. + */ + logger.info("Booking 2 rooms with [hold=true] in test property: [{}]...", + Constants.TEST_PROPERTY_ID); + BookService bookService = new BookService(); + ItineraryCreation itineraryCreation = + bookService.createBookingWithHold(roomPriceCheck, occupancy).getData(); + logger.info("Booking with hold success. Itinerary id: [{}]. Link to resume booking: [{}]", + itineraryCreation.getItineraryId(), itineraryCreation.getLinks().getResume().getHref()); + + // Resume the booking process + logger.info("Resuming the booking process..."); + Response response = bookService.resumeBooking(itineraryCreation); + logger.info("Resume booking response status: [{}]", response.getStatusCode()); + + // Make a retrieve call to verify the booking has been resumed properly. + logger.info( + "Getting itinerary by itinerary id: [{}] to verify the booking has been resumed " + + "successfully...", + itineraryCreation.getItineraryId()); + Itinerary itinerary = bookService.getReservation(itineraryCreation).getData(); + + logger.info("Itinerary rooms status after resume booking:"); + itinerary.getRooms().forEach(room -> + logger.info("Room: [{}], Status: [{}]", room.getId(), room.getStatus()) + ); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/SingleRoomBookScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/SingleRoomBookScenario.java index b77ce652fb..7e602f0853 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/SingleRoomBookScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/SingleRoomBookScenario.java @@ -10,62 +10,76 @@ import com.expediagroup.sdk.rapid.models.Property; import com.expediagroup.sdk.rapid.models.PropertyAvailability; import com.expediagroup.sdk.rapid.models.RoomPriceCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * A scenario to book a single room in a property using the default profile in synchronous manner. + */ public class SingleRoomBookScenario implements RapidScenario { - - private static final Logger logger = LoggerFactory.getLogger(SingleRoomBookScenario.class); - private ShopService shopService = new ShopService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = LoggerFactory.getLogger(SingleRoomBookScenario.class); + private ShopService shopService = new ShopService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the profile to be used for the scenario. + * + * @param rapidPartnerSalesProfile the profile to be used for the scenario + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to book a single room in a property using the default profile in synchronous + * manner. + */ + @Override + public void run() { + + logger.info( + "Running Book Single Room Scenario using the default profile in synchronous manner..."); + + // Shopping for properties + logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); + + List propertyAvailabilityList = + shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile) + .getData(); + + if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { + throw new IllegalStateException("No property availability found for the test property."); } - @Override - public void run() { + logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - logger.info("Running Book Single Room Scenario using the default profile in synchronous manner..."); + // Checking room prices for the property + logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID); + Property property = propertyAvailabilityList.get(0); + RoomPriceCheck roomPriceCheck = null; - // Shopping for properties - logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); - - List propertyAvailabilityList = shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile).getData(); - - if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { - throw new IllegalStateException("No property availability found for the test property."); - } - - logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - - // Checking room prices for the property - logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID); - Property property = propertyAvailabilityList.get(0); - RoomPriceCheck roomPriceCheck = null; - - if (property instanceof PropertyAvailability) { - PropertyAvailability propertyAvailability = (PropertyAvailability) property; - roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); - logger.info("Room Price Check: {}", roomPriceCheck.getStatus()); - } + if (property instanceof PropertyAvailability) { + PropertyAvailability propertyAvailability = (PropertyAvailability) property; + roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); + logger.info("Room Price Check: {}", roomPriceCheck.getStatus()); + } - // Booking a single room in the property - logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID); + // Booking a single room in the property + logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID); - BookService bookService = new BookService(); - ItineraryCreation itineraryCreation = bookService.createBooking(roomPriceCheck, Arrays.asList("2")).getData(); + BookService bookService = new BookService(); + ItineraryCreation itineraryCreation = + bookService.createBooking(roomPriceCheck, Arrays.asList("2")).getData(); - logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId()); + logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId()); - // Manage booking - logger.info("Getting itinerary by itinerary id..."); - Itinerary itinerary = bookService.getReservation(itineraryCreation).getData(); - logger.info("Itinerary: {}", itinerary.getItineraryId()); - logger.info("Count of rooms booked: {}", itinerary.getRooms().size()); - } + // Manage booking + logger.info("Getting itinerary by itinerary id..."); + Itinerary itinerary = bookService.getReservation(itineraryCreation).getData(); + logger.info("Itinerary: {}", itinerary.getItineraryId()); + logger.info("Count of rooms booked: {}", itinerary.getRooms().size()); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/content/GetPropertyContentInAdditionalLanguageScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/content/GetPropertyContentInAdditionalLanguageScenario.java index d16e1bf520..06d54f8a60 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/content/GetPropertyContentInAdditionalLanguageScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/content/GetPropertyContentInAdditionalLanguageScenario.java @@ -6,79 +6,100 @@ import com.expediagroup.sdk.rapid.examples.services.ContentService; import com.expediagroup.sdk.rapid.models.PropertyContent; import com.expediagroup.sdk.rapid.operations.GetPropertyContentOperationLink; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Scenario to get property content in an additional language. + */ public class GetPropertyContentInAdditionalLanguageScenario implements RapidScenario { - - private static final Logger logger = LoggerFactory.getLogger(GetPropertyContentInAdditionalLanguageScenario.class); - private ContentService contentService = new ContentService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } - - @Override - public void run() { - - logger.info("Running Get Property Content In Additional Language Scenario..."); - - // Calling property content API - logger.info("Get property content by property id: [{}]...", Constants.TEST_PROPERTY_ID); - contentService.asyncGetPropertyContent(Arrays.asList(Constants.TEST_PROPERTY_ID), - "en-US", this.rapidPartnerSalesProfile).thenApply(propertyContentMap -> { - if (propertyContentMap.getData().isEmpty()) { - throw new IllegalStateException("No property content found for property id:" + Constants.TEST_PROPERTY_ID); - } - - logger.info("Property content in en-US language:"); - // Print property content - propertyContentMap.getData().forEach((key, value) -> { - logger.info("----Property id: [{}]----", key); - logger.info("Property name: [{}]", value.getName()); - logger.info("Property address: [{}]", value.getAddress()); - logger.info("Property category: [{}]", value.getCategory()); - - }); - - // Print available links to other languages - logger.info("Available links to property content in other languages:"); - Map selectedPropertyLinks = propertyContentMap.getData().entrySet().stream().findFirst().get() - .getValue().getAddress().getLocalized().getLinks(); - - if (selectedPropertyLinks.isEmpty()) { - throw new IllegalStateException("No links found to property content in other languages."); - } - - selectedPropertyLinks.forEach((language, link) -> logger.info("Language: [{}], Link: [{}]", language, link.getHref())); - return propertyContentMap.getData(); - + private static final Logger logger = + LoggerFactory.getLogger(GetPropertyContentInAdditionalLanguageScenario.class); + private ContentService contentService = new ContentService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the profile for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to get property content in an additional language. + */ + @Override + public void run() { + logger.info("Running Get Property Content In Additional Language Scenario..."); + + // Calling property content API + logger.info("Get property content by property id: [{}]...", Constants.TEST_PROPERTY_ID); + contentService.asyncGetPropertyContent(Arrays.asList(Constants.TEST_PROPERTY_ID), + "en-US", this.rapidPartnerSalesProfile).thenApply(propertyContentMap -> { + if (propertyContentMap.getData().isEmpty()) { + throw new IllegalStateException( + "No property content found for property id:" + Constants.TEST_PROPERTY_ID); + } + + logger.info("Property content in en-US language:"); + // Print property content + propertyContentMap.getData().forEach((key, value) -> { + logger.info("----Property id: [{}]----", key); + logger.info("Property name: [{}]", value.getName()); + logger.info("Property address: [{}]", value.getAddress()); + logger.info("Property category: [{}]", value.getCategory()); + }); + + // Print available links to other languages + logger.info("Available links to property content in other languages:"); + Map selectedPropertyLinks = + propertyContentMap.getData().entrySet().stream().findFirst().get().getValue() + .getAddress().getLocalized().getLinks(); + + if (selectedPropertyLinks.isEmpty()) { + throw new IllegalStateException( + "No links found to property content in other languages." + ); + } + + selectedPropertyLinks.forEach((language, link) -> logger.info( + "Language: [{}], Link: [{}]", + language, + link.getHref() + )); + + return propertyContentMap.getData(); }).thenCompose(propertyContentMap -> { - // Get property content in additional language - PropertyContent propertyContent = propertyContentMap.entrySet().iterator().next().getValue(); - return contentService.asyncGetPropertyContentInAdditionalLanguage(propertyContent, this.rapidPartnerSalesProfile); + // Get property content in additional language + PropertyContent propertyContent = + propertyContentMap.entrySet().iterator().next().getValue(); + + return contentService.asyncGetPropertyContentInAdditionalLanguage( + propertyContent, + this.rapidPartnerSalesProfile + ); }).thenApply(propertyContentMap -> { - if (propertyContentMap.getData().isEmpty()) { - throw new IllegalStateException("No property content found for property id:" + Constants.TEST_PROPERTY_ID); - } - - logger.info("Property content in additional language:"); - // Print property content - propertyContentMap.getData().forEach((key, value) -> { - logger.info("----Property id: [{}]----", key); - logger.info("Property name: [{}]", value.getName()); - logger.info("Property address: [{}]", value.getAddress()); - logger.info("Property category: [{}]", value.getCategory()); - - }); - - return propertyContentMap; + if (propertyContentMap.getData().isEmpty()) { + throw new IllegalStateException( + "No property content found for property id:" + Constants.TEST_PROPERTY_ID); + } + + logger.info("Property content in additional language:"); + // Print property content + propertyContentMap.getData().forEach((key, value) -> { + logger.info("----Property id: [{}]----", key); + logger.info("Property name: [{}]", value.getName()); + logger.info("Property address: [{}]", value.getAddress()); + logger.info("Property category: [{}]", value.getCategory()); + }); + + return propertyContentMap; }).join(); - } + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/content/GetPropertyContentScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/content/GetPropertyContentScenario.java index abf383cb5e..db8b0908dc 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/content/GetPropertyContentScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/content/GetPropertyContentScenario.java @@ -5,44 +5,55 @@ import com.expediagroup.sdk.rapid.examples.scenarios.RapidScenario; import com.expediagroup.sdk.rapid.examples.services.ContentService; import com.expediagroup.sdk.rapid.models.PropertyContent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Scenario to get property content using the ContentService. + */ public class GetPropertyContentScenario implements RapidScenario { - - private static final Logger logger = LoggerFactory.getLogger(GetPropertyContentScenario.class); - private ContentService contentService = new ContentService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = LoggerFactory.getLogger(GetPropertyContentScenario.class); + private ContentService contentService = new ContentService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the profile for the scenario. + * + * @param rapidPartnerSalesProfile the profile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to get property content. + */ + @Override + public void run() { + + logger.info("Running Get Property Content Scenario..."); + + // Calling property content API + logger.info("Get property content by property id: [{}]...", Constants.TEST_PROPERTY_ID); + Map propertyContentMap = + contentService.getPropertyContent(Arrays.asList(Constants.TEST_PROPERTY_ID), + "en-US", this.rapidPartnerSalesProfile).getData(); + + if (propertyContentMap.isEmpty()) { + throw new IllegalStateException( + "No property content found for property id:" + Constants.TEST_PROPERTY_ID); } - @Override - public void run() { - - logger.info("Running Get Property Content Scenario..."); - - // Calling property content API - logger.info("Get property content by property id: [{}]...", Constants.TEST_PROPERTY_ID); - Map propertyContentMap = contentService.getPropertyContent(Arrays.asList(Constants.TEST_PROPERTY_ID), - "en-US", this.rapidPartnerSalesProfile).getData(); + // Print property content + propertyContentMap.forEach((key, value) -> { + logger.info("----Property id: [{}]----", key); + logger.info("Property name: [{}]", value.getName()); + logger.info("Property address: [{}]", value.getAddress()); + logger.info("Property category: [{}]", value.getCategory()); - if (propertyContentMap.isEmpty()) { - throw new IllegalStateException("No property content found for property id:" + Constants.TEST_PROPERTY_ID); - } - - // Print property content - propertyContentMap.forEach((key, value) -> { - logger.info("----Property id: [{}]----", key); - logger.info("Property name: [{}]", value.getName()); - logger.info("Property address: [{}]", value.getAddress()); - logger.info("Property category: [{}]", value.getCategory()); - - }); - } + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetListOfRegionNamesScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetListOfRegionNamesScenario.java index d786a77baa..bc986499ee 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetListOfRegionNamesScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetListOfRegionNamesScenario.java @@ -4,37 +4,47 @@ import com.expediagroup.sdk.rapid.examples.scenarios.RapidScenario; import com.expediagroup.sdk.rapid.examples.services.GeographyService; import com.expediagroup.sdk.rapid.models.Region; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; - +/** + * Scenario for retrieving and logging the names of all regions with details. + */ public class GetListOfRegionNamesScenario implements RapidScenario { - - private static final Logger logger = LoggerFactory.getLogger(GetListOfRegionNamesScenario.class); - private GeographyService geographyService = new GeographyService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } - - @Override - public void run() { - - logger.info("Running Get List of Region Names Scenario..."); - - // Calling regions API with details - logger.info("Calling GET /regions API to get list of regions..."); - List> regions = geographyService.getAllRegionsWithDetails(this.rapidPartnerSalesProfile); - - // Filter regions names - logger.info("Regions names:"); - regions.forEach(regionList -> { - regionList.forEach(region -> { - logger.info(region.getNameFull()); - }); - }); - } + private static final Logger logger = LoggerFactory.getLogger(GetListOfRegionNamesScenario.class); + private GeographyService geographyService = new GeographyService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile to be used for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to use + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to retrieve and log the names of all regions with details. + */ + @Override + public void run() { + + logger.info("Running Get List of Region Names Scenario..."); + + // Calling regions API with details + logger.info("Calling GET /regions API to get list of regions..."); + List> regions = + geographyService.getAllRegionsWithDetails(this.rapidPartnerSalesProfile); + + // Filter regions names + logger.info("Regions names:"); + regions.forEach(regionList -> { + regionList.forEach(region -> { + logger.info(region.getNameFull()); + }); + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionByAncestorIdScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionByAncestorIdScenario.java index f49606ab2e..5ec6d44818 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionByAncestorIdScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionByAncestorIdScenario.java @@ -5,44 +5,59 @@ import com.expediagroup.sdk.rapid.examples.scenarios.RapidScenario; import com.expediagroup.sdk.rapid.examples.services.GeographyService; import com.expediagroup.sdk.rapid.models.Region; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; - +/** + * Scenario for retrieving and logging the details of regions by ancestor ID. + */ public class GetRegionByAncestorIdScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(GetRegionByAncestorIdScenario.class); - private GeographyService geographyService = new GeographyService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = LoggerFactory.getLogger(GetRegionByAncestorIdScenario.class); + private GeographyService geographyService = new GeographyService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile to be used for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to use + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to retrieve and log the details of regions by ancestor ID. + */ + @Override + public void run() { + + logger.info("Running Get Region By Ancestor Id Scenario..."); + + // Calling region API with details and property ids by Ancestor ID + logger.info( + "Calling GET /region API to get region details and property ids by ancestor id: [{}]...", + Constants.TEST_ANCESTOR_ID); + List> regionsPages = + geographyService.getRegionsByAncestor(Constants.TEST_ANCESTOR_ID, + this.rapidPartnerSalesProfile); + + if (regionsPages == null || regionsPages.isEmpty()) { + throw new IllegalStateException( + String.format("No regions found for the ancestor id: [%s].", Constants.TEST_ANCESTOR_ID)); } - @Override - public void run() { - - logger.info("Running Get Region By Ancestor Id Scenario..."); - - // Calling region API with details and property ids by Ancestor ID - logger.info("Calling GET /region API to get region details and property ids by ancestor id: [{}]...", Constants.TEST_ANCESTOR_ID); - List> regionsPages = geographyService.getRegionsByAncestor(Constants.TEST_ANCESTOR_ID, this.rapidPartnerSalesProfile); - - if (regionsPages == null || regionsPages.isEmpty()) { - throw new IllegalStateException(String.format("No regions found for the ancestor id: [%s].", Constants.TEST_ANCESTOR_ID)); - } - - logger.info("Regions found for the ancestor id: [{}]:", Constants.TEST_ANCESTOR_ID); - regionsPages.forEach(page -> { - page.forEach(region -> { - logger.info("---------------------------------"); - logger.info("Region Full Name: {}", region.getNameFull()); - logger.info("Region Type: {}", region.getType()); - logger.info("Region Country Code: {}", region.getCountryCode()); - logger.info("---------------------------------"); - }); - }); - } + logger.info("Regions found for the ancestor id: [{}]:", Constants.TEST_ANCESTOR_ID); + regionsPages.forEach(page -> { + page.forEach(region -> { + logger.info("---------------------------------"); + logger.info("Region Full Name: {}", region.getNameFull()); + logger.info("Region Type: {}", region.getType()); + logger.info("Region Country Code: {}", region.getCountryCode()); + logger.info("---------------------------------"); + }); + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionDetailsAndPropertyIdsScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionDetailsAndPropertyIdsScenario.java index e80e69a0ec..535959521f 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionDetailsAndPropertyIdsScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionDetailsAndPropertyIdsScenario.java @@ -5,39 +5,54 @@ import com.expediagroup.sdk.rapid.examples.scenarios.RapidScenario; import com.expediagroup.sdk.rapid.examples.services.GeographyService; import com.expediagroup.sdk.rapid.models.Region; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.stream.Collectors; - +/** + * Scenario for retrieving and logging the details of a region by region ID, including property IDs. + */ public class GetRegionDetailsAndPropertyIdsScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(GetRegionDetailsAndPropertyIdsScenario.class); - private GeographyService geographyService = new GeographyService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } - - @Override - public void run() { - - logger.info("Running Get Region Name of Region Scenario..."); - - // Calling region API with details and property ids - logger.info("Calling GET /region API to get region details and property ids by region id: [{}]...", Constants.TEST_REGION_ID); - Region region = geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", this.rapidPartnerSalesProfile); - - logger.info("Region Full Name: {}", region.getNameFull()); - logger.info("Region Type: {}", region.getType()); - logger.info("Region Country Code: {}", region.getCountryCode()); - - String result = region.getPropertyIds().stream() - .map(Object::toString) - .collect(Collectors.joining(",")); - logger.info("Region Property IDs: [{}]", result); - - } + private static final Logger logger = + LoggerFactory.getLogger(GetRegionDetailsAndPropertyIdsScenario.class); + private GeographyService geographyService = new GeographyService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile to be used for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to use + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to retrieve and log the details of a region by region ID, including property + * IDs. + */ + @Override + public void run() { + + logger.info("Running Get Region Name of Region Scenario..."); + + // Calling region API with details and property ids + logger.info( + "Calling GET /region API to get region details and property ids by region id: [{}]...", + Constants.TEST_REGION_ID); + Region region = + geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", + this.rapidPartnerSalesProfile); + + logger.info("Region Full Name: {}", region.getNameFull()); + logger.info("Region Type: {}", region.getType()); + logger.info("Region Country Code: {}", region.getCountryCode()); + + String result = region.getPropertyIds().stream() + .map(Object::toString) + .collect(Collectors.joining(",")); + logger.info("Region Property IDs: [{}]", result); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionAncestorsScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionAncestorsScenario.java index 0e4e009335..be3ff0a052 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionAncestorsScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionAncestorsScenario.java @@ -8,34 +8,51 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Scenario for retrieving and logging the details of a region by region ID, including its + * ancestors. + */ public class ParseRegionAncestorsScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(ParseRegionAncestorsScenario.class); - private GeographyService geographyService = new GeographyService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } - - @Override - public void run() { - - logger.info("Running Parse Region Ancestors Scenario..."); - - // Calling region API with details and property ids - logger.info("Calling GET /region API to get region details and property ids by region id: [{}]...", Constants.TEST_REGION_ID); - Region region = geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", this.rapidPartnerSalesProfile); - - logger.info("Region Full Name: {}", region.getNameFull()); - logger.info("Region Type: {}", region.getType()); - logger.info("Region Country Code: {}", region.getCountryCode()); - - logger.info("Region Ancestors:"); - region.getAncestors().stream().forEach(ancestor -> { - logger.info("Ancestor id: [{}], type: [{}]", ancestor.getId(), ancestor.getType()); - }); - - } + private static final Logger logger = LoggerFactory.getLogger(ParseRegionAncestorsScenario.class); + private GeographyService geographyService = new GeographyService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile to be used for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to use + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to retrieve and log the details of a region by region ID, including its + * ancestors. + */ + @Override + public void run() { + + logger.info("Running Parse Region Ancestors Scenario..."); + + // Calling region API with details and property ids + logger.info( + "Calling GET /region API to get region details and property ids by region id: [{}]...", + Constants.TEST_REGION_ID); + Region region = + geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", + this.rapidPartnerSalesProfile); + + logger.info("Region Full Name: {}", region.getNameFull()); + logger.info("Region Type: {}", region.getType()); + logger.info("Region Country Code: {}", region.getCountryCode()); + + logger.info("Region Ancestors:"); + region.getAncestors().stream().forEach(ancestor -> { + logger.info("Ancestor id: [{}], type: [{}]", ancestor.getId(), ancestor.getType()); + }); + + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionCategoriesScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionCategoriesScenario.java index e6bc44577d..d6fb72183b 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionCategoriesScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionCategoriesScenario.java @@ -8,33 +8,54 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Scenario for retrieving and logging the details of a region by region ID, including its + * categories. + */ public class ParseRegionCategoriesScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(ParseRegionCategoriesScenario.class); - private GeographyService geographyService = new GeographyService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } - - @Override - public void run() { - - logger.info("Running Parse Region Categories Scenario..."); - - // Calling region API with details and property ids - logger.info("Calling GET /region API to get region details and property ids by region id: [{}]...", Constants.TEST_REGION_ID); - Region region = geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", this.rapidPartnerSalesProfile); - - logger.info("Region full name: {}", region.getNameFull()); - logger.info("Region type: {}", region.getType()); - logger.info("Region country code: {}", region.getCountryCode()); - - logger.info("Region categories:"); - region.getCategories().forEach(category -> { - logger.info("Category key: [{}] value: [{}]", category.split(":")[0], category.split(":")[1]); - }); - } + private static final Logger logger = LoggerFactory.getLogger(ParseRegionCategoriesScenario.class); + private GeographyService geographyService = new GeographyService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile to be used for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to use + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to retrieve and log the details of a region by region ID, including its + * categories. + */ + @Override + public void run() { + + logger.info("Running Parse Region Categories Scenario..."); + + // Calling region API with details and property ids + logger.info( + "Calling GET /region API to get region details and property ids by region id: [{}]...", + Constants.TEST_REGION_ID); + Region region = + geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", + this.rapidPartnerSalesProfile); + + logger.info("Region full name: {}", region.getNameFull()); + logger.info("Region type: {}", region.getType()); + logger.info("Region country code: {}", region.getCountryCode()); + + logger.info("Region categories:"); + region.getCategories().forEach(category -> { + logger.info( + "Category key: [{}] value: [{}]", + category.split(":")[0], + category.split(":")[1] + ); + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionCoordinatesScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionCoordinatesScenario.java index afbc7c2b53..ca8abece54 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionCoordinatesScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionCoordinatesScenario.java @@ -7,59 +7,78 @@ import com.expediagroup.sdk.rapid.models.MultiPolygon; import com.expediagroup.sdk.rapid.models.Polygon; import com.expediagroup.sdk.rapid.models.Region; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Scenario to parse region coordinates. + */ public class ParseRegionCoordinatesScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(ParseRegionCoordinatesScenario.class); - private GeographyService geographyService = new GeographyService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; + private static final Logger logger = + LoggerFactory.getLogger(ParseRegionCoordinatesScenario.class); + private GeographyService geographyService = new GeographyService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } + /** + * Sets the profile for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } - @Override - public void run() { + /** + * Runs the scenario to parse region coordinates. + */ + @Override + public void run() { - logger.info("Running Parse Region Coordinates Scenario..."); + logger.info("Running Parse Region Coordinates Scenario..."); - // Calling region API with details and property ids - logger.info("Calling GET /region API to get region details and property ids by region id: [{}]...", Constants.TEST_REGION_ID); - Region region = geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", this.rapidPartnerSalesProfile); + // Calling region API with details and property ids + logger.info( + "Calling GET /region API to get region details and property ids by region id: [{}]...", + Constants.TEST_REGION_ID); + Region region = + geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", + this.rapidPartnerSalesProfile); - logger.info("Region full name: {}", region.getNameFull()); - logger.info("Region type: {}", region.getType()); - logger.info("Region country code: {}", region.getCountryCode()); - logger.info("Region center coordinates: lat:[{}], long:[{}]", - region.getCoordinates().getCenterLatitude(), region.getCoordinates().getCenterLongitude()); + logger.info("Region full name: {}", region.getNameFull()); + logger.info("Region type: {}", region.getType()); + logger.info("Region country code: {}", region.getCountryCode()); + logger.info("Region center coordinates: lat:[{}], long:[{}]", + region.getCoordinates().getCenterLatitude(), region.getCoordinates().getCenterLongitude()); - String regionCoordinatesType = region.getCoordinates().getBoundingPolygon().getType(); - logger.info("Region coordinates type: [{}]", regionCoordinatesType); + String regionCoordinatesType = region.getCoordinates().getBoundingPolygon().getType(); + logger.info("Region coordinates type: [{}]", regionCoordinatesType); - if (regionCoordinatesType.equals("POLYGON")) { - Polygon regionBoundingPolygon = (Polygon) region.getCoordinates().getBoundingPolygon(); - logger.info("Parse region coordinates: [{}]", regionBoundingPolygon.getCoordinates().get(0).stream() - .map(coordinate -> "[" + coordinate.get(0) + "," + coordinate.get(1) + "]") - .collect(Collectors.joining(","))); + if (regionCoordinatesType.equals("POLYGON")) { + Polygon regionBoundingPolygon = (Polygon) region.getCoordinates().getBoundingPolygon(); + logger.info("Parse region coordinates: [{}]", + regionBoundingPolygon.getCoordinates().get(0).stream() + .map(coordinate -> "[" + coordinate.get(0) + "," + coordinate.get(1) + "]") + .collect(Collectors.joining(","))); - } else if (regionCoordinatesType.equals("MultiPolygon")) { - MultiPolygon regionBoundingMultipolygons = (MultiPolygon) region.getCoordinates().getBoundingPolygon(); - logger.info("Number of bounding polygons in multipolygon region: [{}]", regionBoundingMultipolygons.getCoordinates().size()); + } else if (regionCoordinatesType.equals("MultiPolygon")) { + MultiPolygon regionBoundingMultipolygons = + (MultiPolygon) region.getCoordinates().getBoundingPolygon(); + logger.info("Number of bounding polygons in multipolygon region: [{}]", + regionBoundingMultipolygons.getCoordinates().size()); - AtomicInteger index = new AtomicInteger(); + AtomicInteger index = new AtomicInteger(); - regionBoundingMultipolygons.getCoordinates().forEach(polygon -> { - String coordinates = polygon.get(0).stream() - .map(coordinate -> "[" + coordinate.get(0) + "," + coordinate.get(1) + "]") - .collect(Collectors.joining(",")); - logger.info("Parse region polygon index: [{}] coordinates: [{}]", index.getAndIncrement(), coordinates); - }); - } + regionBoundingMultipolygons.getCoordinates().forEach(polygon -> { + String coordinates = polygon.get(0).stream() + .map(coordinate -> "[" + coordinate.get(0) + "," + coordinate.get(1) + "]") + .collect(Collectors.joining(",")); + logger.info("Parse region polygon index: [{}] coordinates: [{}]", index.getAndIncrement(), + coordinates); + }); } + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionDescendantsScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionDescendantsScenario.java index 4f863d7508..db139eba8b 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionDescendantsScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionDescendantsScenario.java @@ -5,44 +5,58 @@ import com.expediagroup.sdk.rapid.examples.scenarios.RapidScenario; import com.expediagroup.sdk.rapid.examples.services.GeographyService; import com.expediagroup.sdk.rapid.models.Region; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.stream.Collectors; - +/** + * Scenario to parse region descendants. + */ public class ParseRegionDescendantsScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(ParseRegionDescendantsScenario.class); - private GeographyService geographyService = new GeographyService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } - - @Override - public void run() { - - logger.info("Running Parse Region Descendants Scenario..."); - - // Calling region API with details and property ids - logger.info("Calling GET /region API to get region details and property ids by region id: [{}]...", Constants.TEST_REGION_ID); - Region region = geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", this.rapidPartnerSalesProfile); - - logger.info("Region Full Name: {}", region.getNameFull()); - logger.info("Region Type: {}", region.getType()); - logger.info("Region Country Code: {}", region.getCountryCode()); - - logger.info("Region Descendants:"); - region.getDescendants().entrySet().forEach(entry -> { - logger.info("Descendant key: [{}], value: [{}]", - entry.getKey(), - entry.getValue() - .stream() - .map(Object::toString) - .collect(Collectors.joining(","))); - }); - - } + private static final Logger logger = + LoggerFactory.getLogger(ParseRegionDescendantsScenario.class); + private GeographyService geographyService = new GeographyService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to parse region descendants. + */ + @Override + public void run() { + + logger.info("Running Parse Region Descendants Scenario..."); + + // Calling region API with details and property ids + logger.info( + "Calling GET /region API to get region details and property ids by region id: [{}]...", + Constants.TEST_REGION_ID); + Region region = + geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID, "en-US", + this.rapidPartnerSalesProfile); + + logger.info("Region Full Name: {}", region.getNameFull()); + logger.info("Region Type: {}", region.getType()); + logger.info("Region Country Code: {}", region.getCountryCode()); + + logger.info("Region Descendants:"); + region.getDescendants().entrySet().forEach(entry -> { + logger.info("Descendant key: [{}], value: [{}]", + entry.getKey(), + entry.getValue() + .stream() + .map(Object::toString) + .collect(Collectors.joining(","))); + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionWithMultiPolygonCoordinatesScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionWithMultiPolygonCoordinatesScenario.java index 8bc60bb506..4471b0f0f2 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionWithMultiPolygonCoordinatesScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/ParseRegionWithMultiPolygonCoordinatesScenario.java @@ -6,51 +6,68 @@ import com.expediagroup.sdk.rapid.examples.services.GeographyService; import com.expediagroup.sdk.rapid.models.MultiPolygon; import com.expediagroup.sdk.rapid.models.Region; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Scenario for retrieving and logging the details of a region by region ID, including its + * multipolygon coordinates. + */ public class ParseRegionWithMultiPolygonCoordinatesScenario implements RapidScenario { + private static final Logger logger = + LoggerFactory.getLogger(ParseRegionWithMultiPolygonCoordinatesScenario.class); + private GeographyService geographyService = new GeographyService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; - private static final Logger logger = LoggerFactory.getLogger(ParseRegionWithMultiPolygonCoordinatesScenario.class); - private GeographyService geographyService = new GeographyService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } - - @Override - public void run() { - - logger.info("Running Get Region With MultiPolygon Coordinates Scenario..."); + /** + * Sets the sales profile to be used for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to use + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } - // Calling region API with details and property ids - logger.info("Calling GET /region API to get region details of a region with multipolygon coordinates by region id: [{}]...", - Constants.TEST_REGION_ID_WITH_MULTIPOLYGON); - Region region = geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID_WITH_MULTIPOLYGON, - "en-US", this.rapidPartnerSalesProfile); + /** + * Runs the scenario to retrieve and log the details of a region by region ID, including its + * multipolygon coordinates. + */ + @Override + public void run() { + logger.info("Running Get Region With MultiPolygon Coordinates Scenario..."); - logger.info("Region Full Name: {}", region.getNameFull()); - logger.info("Region Type: {}", region.getType()); - logger.info("Region Country Code: {}", region.getCountryCode()); + // Calling region API with details and property ids + logger.info( + "Calling GET /region API to get region details of a region with multipolygon coordinates " + + "by region id: [{}]...", + Constants.TEST_REGION_ID_WITH_MULTIPOLYGON); + Region region = + geographyService.getRegionDetailsAndPropertyIds(Constants.TEST_REGION_ID_WITH_MULTIPOLYGON, + "en-US", this.rapidPartnerSalesProfile); - logger.info("Verify the returned region has multipolygon coordinates by checking coordinates type..."); - logger.info("Region coordinates type: [{}]", region.getCoordinates().getBoundingPolygon().getType()); + logger.info("Region Full Name: {}", region.getNameFull()); + logger.info("Region Type: {}", region.getType()); + logger.info("Region Country Code: {}", region.getCountryCode()); - MultiPolygon multiPolygonRegionCoordinates = (MultiPolygon) region.getCoordinates().getBoundingPolygon(); - logger.info("Number of bounding polygons in multipolygon region: [{}]", multiPolygonRegionCoordinates.getCoordinates().size()); + logger.info( + "Verify the returned region has multipolygon coordinates by checking coordinates type..."); + logger.info("Region coordinates type: [{}]", + region.getCoordinates().getBoundingPolygon().getType()); - AtomicInteger index = new AtomicInteger(); - multiPolygonRegionCoordinates.getCoordinates().forEach(polygon -> { - String coordinates = polygon.get(0).stream() - .map(coordinate -> "[" + coordinate.get(0) + "," + coordinate.get(1) + "]") - .collect(Collectors.joining(",")); - logger.info("Polygon index: [{}] coordinates: [{}]", index.getAndIncrement(), coordinates); - }); + MultiPolygon multiPolygonRegionCoordinates = + (MultiPolygon) region.getCoordinates().getBoundingPolygon(); + logger.info("Number of bounding polygons in multipolygon region: [{}]", + multiPolygonRegionCoordinates.getCoordinates().size()); - } + AtomicInteger index = new AtomicInteger(); + multiPolygonRegionCoordinates.getCoordinates().forEach(polygon -> { + String coordinates = polygon.get(0).stream() + .map(coordinate -> "[" + coordinate.get(0) + "," + coordinate.get(1) + "]") + .collect(Collectors.joining(",")); + logger.info("Polygon index: [{}] coordinates: [{}]", index.getAndIncrement(), coordinates); + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/CancelHeldBookingScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/CancelHeldBookingScenario.java index 15b12d0fa8..8f64db6bd1 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/CancelHeldBookingScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/CancelHeldBookingScenario.java @@ -9,60 +9,79 @@ import com.expediagroup.sdk.rapid.models.Property; import com.expediagroup.sdk.rapid.models.PropertyAvailability; import com.expediagroup.sdk.rapid.models.RoomPriceCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Scenario to cancel a held booking. + */ public class CancelHeldBookingScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(CancelHeldBookingScenario.class); - private final ShopService shopService = new ShopService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = LoggerFactory.getLogger(CancelHeldBookingScenario.class); + private final ShopService shopService = new ShopService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to cancel a held booking. + */ + @Override + public void run() { + + logger.info("Running Cancel Held Booking Scenario using the default profile..."); + + // Shopping for properties + logger.info("Getting property availability for test property: [{}]", + Constants.TEST_PROPERTY_ID); + + List propertyAvailabilityList = + shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile) + .getData(); + + if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { + throw new IllegalStateException("No property availability found for the test property."); } - @Override - public void run() { - - logger.info("Running Cancel Held Booking Scenario using the default profile..."); + logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - // Shopping for properties - logger.info("Getting property availability for test property: [{}]", Constants.TEST_PROPERTY_ID); + // Checking room prices for the property + logger.info("Checking room prices for the property: [{}]...", Constants.TEST_PROPERTY_ID); + Property property = propertyAvailabilityList.get(0); - List propertyAvailabilityList = shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile).getData(); - - if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { - throw new IllegalStateException("No property availability found for the test property."); - } - - logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - - // Checking room prices for the property - logger.info("Checking room prices for the property: [{}]...", Constants.TEST_PROPERTY_ID); - Property property = propertyAvailabilityList.get(0); - - if (!(property instanceof PropertyAvailability)) throw new IllegalStateException("Property is not of type PropertyAvailability"); - - PropertyAvailability propertyAvailability = (PropertyAvailability) property; - RoomPriceCheck roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); - logger.info("Room Price Check: [{}]", roomPriceCheck.getStatus()); + if (!(property instanceof PropertyAvailability)) { + throw new IllegalStateException("Property is not of type PropertyAvailability"); + } + PropertyAvailability propertyAvailability = (PropertyAvailability) property; + RoomPriceCheck roomPriceCheck = + shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); + logger.info("Room Price Check: [{}]", roomPriceCheck.getStatus()); - // Booking a room with hold in the property - logger.info("Booking a room with hold=true in test property: [{}]...", Constants.TEST_PROPERTY_ID); + // Booking a room with hold in the property + logger.info("Booking a room with hold=true in test property: [{}]...", + Constants.TEST_PROPERTY_ID); - BookService bookService = new BookService(); - ItineraryCreation itineraryCreation = bookService.createBookingWithHold(roomPriceCheck, Arrays.asList("2")).getData(); + BookService bookService = new BookService(); + ItineraryCreation itineraryCreation = + bookService.createBookingWithHold(roomPriceCheck, Arrays.asList("2")).getData(); - logger.info("Booking with hold success. Itinerary id: [{}]", itineraryCreation.getItineraryId()); + logger.info("Booking with hold success. Itinerary id: [{}]", + itineraryCreation.getItineraryId()); - // Cancel the held booking - logger.info("Cancelling the held booking with itinerary id: [{}]...", itineraryCreation.getItineraryId()); - bookService.cancelHeldReservation(itineraryCreation); - } + // Cancel the held booking + logger.info("Cancelling the held booking with itinerary id: [{}]...", + itineraryCreation.getItineraryId()); + bookService.cancelHeldReservation(itineraryCreation); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/ChangeRoomDetailsScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/ChangeRoomDetailsScenario.java index d11b519e58..0733c9c590 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/ChangeRoomDetailsScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/ChangeRoomDetailsScenario.java @@ -12,85 +12,100 @@ import com.expediagroup.sdk.rapid.models.Property; import com.expediagroup.sdk.rapid.models.PropertyAvailability; import com.expediagroup.sdk.rapid.models.RoomPriceCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Scenario to change room details for a booking. + */ public class ChangeRoomDetailsScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(ChangeRoomDetailsScenario.class); - private ShopService shopService = new ShopService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = LoggerFactory.getLogger(ChangeRoomDetailsScenario.class); + private ShopService shopService = new ShopService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to change room details for a booking. + */ + @Override + public void run() { + + logger.info("Running Change Room Details Scenario using the default profile..."); + + // Shopping for properties + logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); + + List propertyAvailabilityList = + shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile) + .getData(); + + if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { + throw new IllegalStateException("No property availability found for the test property."); } - @Override - public void run() { - - logger.info("Running Change Room Details Scenario using the default profile..."); - - // Shopping for properties - logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); - - List propertyAvailabilityList = shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile).getData(); - - if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { - throw new IllegalStateException("No property availability found for the test property."); - } - - logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - - // Checking room prices for the property - logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID); - Property property = propertyAvailabilityList.get(0); - RoomPriceCheck roomPriceCheck = null; - - if (property instanceof PropertyAvailability) { - PropertyAvailability propertyAvailability = (PropertyAvailability) property; - roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); - logger.info("Room Price Check: {}", roomPriceCheck.getStatus()); - } - - // Booking a single room in the property - logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID); - - BookService bookService = new BookService(); - ItineraryCreation itineraryCreation = bookService.createBooking(roomPriceCheck, Arrays.asList("2")).getData(); - - logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId()); - - // Manage booking - logger.info("Getting itinerary by itinerary id..."); - Itinerary itinerary = bookService.getReservation(itineraryCreation).getData(); - logger.info("Itinerary: {}", itinerary.getItineraryId()); - logger.info("Count of rooms booked: {}", itinerary.getRooms().size()); - logger.info("Room info before change:"); - itinerary.getRooms().forEach(room -> { - logger.info("----Room: [{}]----", room.getId()); - logger.info("Given name: [{}]", room.getGivenName()); - logger.info("Family name: [{}]", room.getFamilyName()); - logger.info("Smoking: [{}]", room.getSmoking()); - }); - - // Change room details for first room in booking - logger.info("Change room details for room [id:{}] in itinerary...", itinerary.getRooms().get(0).getId()); - Response response = bookService.changeRoomDetails(itinerary, 0); - logger.info("Change room details for room [id:{}] response status: [{}]", itinerary.getRooms().get(0).getId(), response.getStatusCode()); - - // Get updated itinerary - logger.info("Getting updated itinerary by itinerary id..."); - Itinerary updatedItinerary = bookService.getReservation(itineraryCreation).getData(); - logger.info("Itinerary rooms details after change room:"); - updatedItinerary.getRooms().forEach(room -> { - logger.info("----Room: [{}]----", room.getId()); - logger.info("Given name: [{}]", room.getGivenName()); - logger.info("Family name: [{}]", room.getFamilyName()); - logger.info("Smoking: [{}]", room.getSmoking()); - }); + logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); + + // Checking room prices for the property + logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID); + Property property = propertyAvailabilityList.get(0); + RoomPriceCheck roomPriceCheck = null; + + if (property instanceof PropertyAvailability) { + PropertyAvailability propertyAvailability = (PropertyAvailability) property; + roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); + logger.info("Room Price Check: {}", roomPriceCheck.getStatus()); } + + // Booking a single room in the property + logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID); + + BookService bookService = new BookService(); + ItineraryCreation itineraryCreation = + bookService.createBooking(roomPriceCheck, Arrays.asList("2")).getData(); + + logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId()); + + // Manage booking + logger.info("Getting itinerary by itinerary id..."); + Itinerary itinerary = bookService.getReservation(itineraryCreation).getData(); + logger.info("Itinerary: {}", itinerary.getItineraryId()); + logger.info("Count of rooms booked: {}", itinerary.getRooms().size()); + logger.info("Room info before change:"); + itinerary.getRooms().forEach(room -> { + logger.info("----Room: [{}]----", room.getId()); + logger.info("Given name: [{}]", room.getGivenName()); + logger.info("Family name: [{}]", room.getFamilyName()); + logger.info("Smoking: [{}]", room.getSmoking()); + }); + + // Change room details for first room in booking + logger.info("Change room details for room [id:{}] in itinerary...", + itinerary.getRooms().get(0).getId()); + Response response = bookService.changeRoomDetails(itinerary, 0); + logger.info("Change room details for room [id:{}] response status: [{}]", + itinerary.getRooms().get(0).getId(), response.getStatusCode()); + + // Get updated itinerary + logger.info("Getting updated itinerary by itinerary id..."); + Itinerary updatedItinerary = bookService.getReservation(itineraryCreation).getData(); + logger.info("Itinerary rooms details after change room:"); + updatedItinerary.getRooms().forEach(room -> { + logger.info("----Room: [{}]----", room.getId()); + logger.info("Given name: [{}]", room.getGivenName()); + logger.info("Family name: [{}]", room.getFamilyName()); + logger.info("Smoking: [{}]", room.getSmoking()); + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/DeleteRoomScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/DeleteRoomScenario.java index a6dc219015..6cb8fe98d4 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/DeleteRoomScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/managebooking/DeleteRoomScenario.java @@ -12,75 +12,89 @@ import com.expediagroup.sdk.rapid.models.Property; import com.expediagroup.sdk.rapid.models.PropertyAvailability; import com.expediagroup.sdk.rapid.models.RoomPriceCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Scenario to delete a room from a booking. + */ public class DeleteRoomScenario implements RapidScenario { - private static final Logger logger = LoggerFactory.getLogger(DeleteRoomScenario.class); - private ShopService shopService = new ShopService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = LoggerFactory.getLogger(DeleteRoomScenario.class); + private ShopService shopService = new ShopService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Sets the sales profile for the scenario. + * + * @param rapidPartnerSalesProfile the sales profile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Runs the scenario to delete a room from a booking. + */ + @Override + public void run() { + + logger.info("Running Delete Room Scenario using the default profile..."); + + // Shopping for properties + logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); + + List propertyAvailabilityList = + shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile) + .getData(); + + if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { + throw new IllegalStateException("No property availability found for the test property."); } - @Override - public void run() { - - logger.info("Running Delete Room Scenario using the default profile..."); - - // Shopping for properties - logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); - - List propertyAvailabilityList = shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile).getData(); + logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { - throw new IllegalStateException("No property availability found for the test property."); - } + // Checking room prices for the property + logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID); + Property property = propertyAvailabilityList.get(0); + RoomPriceCheck roomPriceCheck = null; - logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - - // Checking room prices for the property - logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID); - Property property = propertyAvailabilityList.get(0); - RoomPriceCheck roomPriceCheck = null; - - if (property instanceof PropertyAvailability) { - PropertyAvailability propertyAvailability = (PropertyAvailability) property; - roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); - logger.info("Room Price Check: {}", roomPriceCheck.getStatus()); - } - - // Booking a single room in the property - logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID); - - BookService bookService = new BookService(); - ItineraryCreation itineraryCreation = bookService.createBooking(roomPriceCheck, Arrays.asList("2")).getData(); - - logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId()); - - // Manage booking - logger.info("Getting itinerary by itinerary id..."); - Itinerary itinerary = bookService.getReservation(itineraryCreation).getData(); - logger.info("Itinerary: {}", itinerary.getItineraryId()); - logger.info("Count of rooms booked: {}", itinerary.getRooms().size()); - - // Delete first room in booking - logger.info("Deleting room [id:{}] in itinerary...", itinerary.getRooms().get(0).getId()); - Response response = bookService.deleteRoom(itinerary, 0); - logger.info("Delete room [id:{}] response status: [{}]", itinerary.getRooms().get(0).getId(), response.getStatusCode()); - - // Get updated itinerary - logger.info("Getting updated itinerary by itinerary id..."); - Itinerary updatedItinerary = bookService.getReservation(itineraryCreation).getData(); - logger.info("Itinerary rooms status after delete room:"); - updatedItinerary.getRooms().forEach(room -> - logger.info("Room: [{}], Status: [{}]", room.getId(), room.getStatus()) - ); + if (property instanceof PropertyAvailability) { + PropertyAvailability propertyAvailability = (PropertyAvailability) property; + roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData(); + logger.info("Room Price Check: {}", roomPriceCheck.getStatus()); } + + // Booking a single room in the property + logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID); + + BookService bookService = new BookService(); + ItineraryCreation itineraryCreation = + bookService.createBooking(roomPriceCheck, Arrays.asList("2")).getData(); + + logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId()); + + // Manage booking + logger.info("Getting itinerary by itinerary id..."); + Itinerary itinerary = bookService.getReservation(itineraryCreation).getData(); + logger.info("Itinerary: {}", itinerary.getItineraryId()); + logger.info("Count of rooms booked: {}", itinerary.getRooms().size()); + + // Delete first room in booking + logger.info("Deleting room [id:{}] in itinerary...", itinerary.getRooms().get(0).getId()); + Response response = bookService.deleteRoom(itinerary, 0); + logger.info("Delete room [id:{}] response status: [{}]", itinerary.getRooms().get(0).getId(), + response.getStatusCode()); + + // Get updated itinerary + logger.info("Getting updated itinerary by itinerary id..."); + Itinerary updatedItinerary = bookService.getReservation(itineraryCreation).getData(); + logger.info("Itinerary rooms status after delete room:"); + updatedItinerary.getRooms().forEach(room -> + logger.info("Room: [{}], Status: [{}]", room.getId(), room.getStatus()) + ); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetAdditionalAvailabilityOfPropertyScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetAdditionalAvailabilityOfPropertyScenario.java index abe760f2a5..eeff36c06a 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetAdditionalAvailabilityOfPropertyScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetAdditionalAvailabilityOfPropertyScenario.java @@ -7,54 +7,69 @@ import com.expediagroup.sdk.rapid.examples.services.ShopService; import com.expediagroup.sdk.rapid.models.Property; import com.expediagroup.sdk.rapid.models.PropertyAvailability; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * This scenario demonstrates how to get additional availability of a property. + * The scenario performs the following steps: + * 1. Shopping for properties + * 2. Get additional availability of the first property returned + */ public class GetAdditionalAvailabilityOfPropertyScenario implements RapidScenario { + private static final Logger logger = + LoggerFactory.getLogger(GetAdditionalAvailabilityOfPropertyScenario.class); + private final ShopService shopService = new ShopService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; - private static final Logger logger = LoggerFactory.getLogger(GetAdditionalAvailabilityOfPropertyScenario.class); - private final ShopService shopService = new ShopService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; + /** + * Set the RapidPartnerSalesProfile for the scenario. + * + * @param rapidPartnerSalesProfile the RapidPartnerSalesProfile to set + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; - } + /** + * Run the scenario. + */ + @Override + public void run() { + logger.info("Running Get Additional Availability Of Property Scenario..."); - @Override - public void run() { + // Shopping for properties + logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); - logger.info("Running Get Additional Availability Of Property Scenario..."); + List propertyAvailabilityList = + shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile) + .getData(); - // Shopping for properties - logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); - - List propertyAvailabilityList = shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile).getData(); - - if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { - throw new IllegalStateException("No property availability found for the test property."); - } - - logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); + if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { + throw new IllegalStateException("No property availability found for the test property."); + } - // Get additional availability of the first property returned - Property property = propertyAvailabilityList.get(0); - logger.info("Get additional availability of property id: {}...", property.getPropertyId()); + logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - PropertyAvailability propertyAvailability = (PropertyAvailability) property; - Response> additionalPropertyAvailability = shopService.getAdditionalAvailability(propertyAvailability); + // Get additional availability of the first property returned + Property property = propertyAvailabilityList.get(0); + logger.info("Get additional availability of property id: {}...", property.getPropertyId()); - // Log the additional availability - logger.info("Additional availability returned:"); - additionalPropertyAvailability.getData().forEach(additionalProperty -> { - logger.info("---------------------------------"); - logger.info("Property Id: {}", additionalProperty.getPropertyId()); - logger.info("Property Status: {}", additionalProperty.getStatus()); - logger.info("Property Rooms Count: {}", additionalProperty.getRooms() == null ? 0 : additionalProperty.getRooms().size()); - }); + PropertyAvailability propertyAvailability = (PropertyAvailability) property; + Response> additionalPropertyAvailability = + shopService.getAdditionalAvailability(propertyAvailability); - } + // Log the additional availability + logger.info("Additional availability returned:"); + additionalPropertyAvailability.getData().forEach(additionalProperty -> { + logger.info("---------------------------------"); + logger.info("Property Id: {}", additionalProperty.getPropertyId()); + logger.info("Property Status: {}", additionalProperty.getStatus()); + logger.info("Property Rooms Count: {}", + additionalProperty.getRooms() == null ? 0 : additionalProperty.getRooms().size()); + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetPaymentOptionsOfRoomScenario.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetPaymentOptionsOfRoomScenario.java index 68dd35c87b..fd55a4b979 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetPaymentOptionsOfRoomScenario.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetPaymentOptionsOfRoomScenario.java @@ -4,61 +4,82 @@ import com.expediagroup.sdk.rapid.examples.salesprofiles.RapidPartnerSalesProfile; import com.expediagroup.sdk.rapid.examples.scenarios.RapidScenario; import com.expediagroup.sdk.rapid.examples.services.ShopService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.Arrays; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * This scenario demonstrates how to get payment options of a room. + * The scenario performs the following steps: + * 1. Shopping for properties + * 2. Get payment options of a room + */ public class GetPaymentOptionsOfRoomScenario implements RapidScenario { - - private static final Logger logger = LoggerFactory.getLogger(GetPaymentOptionsOfRoomScenario.class); - private final ShopService shopService = new ShopService(); - private RapidPartnerSalesProfile rapidPartnerSalesProfile; - - @Override - public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + private static final Logger logger = + LoggerFactory.getLogger(GetPaymentOptionsOfRoomScenario.class); + private final ShopService shopService = new ShopService(); + private RapidPartnerSalesProfile rapidPartnerSalesProfile; + + /** + * Set the profile for the scenario. + * + * @param rapidPartnerSalesProfile The profile to be used for the scenario. + */ + @Override + public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) { + this.rapidPartnerSalesProfile = rapidPartnerSalesProfile; + } + + /** + * Run the scenario. + */ + @Override + public void run() { + + logger.info("Running Get Payment Options Of Room Scenario using the default profile..."); + + // Shopping for properties + logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); + + List propertyAvailabilityList = + shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile) + .getData(); + + if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { + throw new IllegalStateException("No property availability found for the test property."); } - @Override - public void run() { - - logger.info("Running Get Payment Options Of Room Scenario using the default profile..."); - - // Shopping for properties - logger.info("Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID); + logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - List propertyAvailabilityList = shopService.getPropertiesAvailability(Arrays.asList("2"), this.rapidPartnerSalesProfile).getData(); - - if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) { - throw new IllegalStateException("No property availability found for the test property."); - } - - logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus()); - - if (!(propertyAvailabilityList.get(0) instanceof com.expediagroup.sdk.rapid.models.PropertyAvailability)) { - throw new IllegalStateException("Property is not of type PropertyAvailability"); - } - - com.expediagroup.sdk.rapid.models.PropertyAvailability propertyAvailability = (com.expediagroup.sdk.rapid.models.PropertyAvailability) propertyAvailabilityList.get(0); - - com.expediagroup.sdk.rapid.models.RoomAvailability selectedRoomAvailability = propertyAvailability.getRooms().get(0); - logger.info("Asynchronously get payment options of room: [{}]...", selectedRoomAvailability.getId()); - - shopService.getPaymentOptions(selectedRoomAvailability, this.rapidPartnerSalesProfile) - .thenAccept(paymentOptionResponse -> { - com.expediagroup.sdk.rapid.models.PaymentOption paymentOption = paymentOptionResponse.getData(); - if (paymentOption.getAffiliateCollect() != null) { - logger.info("Payment option affiliate collect name: [{}]", paymentOption.getAffiliateCollect().getName()); - } - - if (paymentOption.getCreditCard() != null) { - logger.info("Payment option credit card options:"); - paymentOption.getCreditCard().getCardOptions().forEach(creditCardOption -> { - logger.info("Credit card option name: [{}]", creditCardOption.getName()); - }); - } - }); + if (!(propertyAvailabilityList.get( + 0) instanceof com.expediagroup.sdk.rapid.models.PropertyAvailability)) { + throw new IllegalStateException("Property is not of type PropertyAvailability"); } + + com.expediagroup.sdk.rapid.models.PropertyAvailability propertyAvailability = + (com.expediagroup.sdk.rapid.models.PropertyAvailability) propertyAvailabilityList.get(0); + + com.expediagroup.sdk.rapid.models.RoomAvailability selectedRoomAvailability = + propertyAvailability.getRooms().get(0); + logger.info("Asynchronously get payment options of room: [{}]...", + selectedRoomAvailability.getId()); + + shopService.getPaymentOptions(selectedRoomAvailability, this.rapidPartnerSalesProfile) + .thenAccept(paymentOptionResponse -> { + com.expediagroup.sdk.rapid.models.PaymentOption paymentOption = + paymentOptionResponse.getData(); + if (paymentOption.getAffiliateCollect() != null) { + logger.info("Payment option affiliate collect name: [{}]", + paymentOption.getAffiliateCollect().getName()); + } + + if (paymentOption.getCreditCard() != null) { + logger.info("Payment option credit card options:"); + paymentOption.getCreditCard().getCardOptions().forEach(creditCardOption -> { + logger.info("Credit card option name: [{}]", creditCardOption.getName()); + }); + } + }); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/BookService.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/BookService.java index 9d0d2e6165..0307f3cd4a 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/BookService.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/BookService.java @@ -16,245 +16,429 @@ import com.expediagroup.sdk.rapid.models.PaymentSessionsRequest; import com.expediagroup.sdk.rapid.models.PhoneRequest; import com.expediagroup.sdk.rapid.models.RoomPriceCheck; -import com.expediagroup.sdk.rapid.operations.*; - +import com.expediagroup.sdk.rapid.operations.ChangeRoomDetailsOperation; +import com.expediagroup.sdk.rapid.operations.ChangeRoomDetailsOperationContext; +import com.expediagroup.sdk.rapid.operations.ChangeRoomDetailsOperationLink; +import com.expediagroup.sdk.rapid.operations.CommitChangeOperation; +import com.expediagroup.sdk.rapid.operations.CommitChangeOperationLink; +import com.expediagroup.sdk.rapid.operations.DeleteHeldBookingOperation; +import com.expediagroup.sdk.rapid.operations.DeleteHeldBookingOperationContext; +import com.expediagroup.sdk.rapid.operations.DeleteHeldBookingOperationLink; +import com.expediagroup.sdk.rapid.operations.DeleteRoomOperation; +import com.expediagroup.sdk.rapid.operations.DeleteRoomOperationContext; +import com.expediagroup.sdk.rapid.operations.DeleteRoomOperationLink; +import com.expediagroup.sdk.rapid.operations.GetReservationByItineraryIdOperation; +import com.expediagroup.sdk.rapid.operations.GetReservationByItineraryIdOperationContext; +import com.expediagroup.sdk.rapid.operations.GetReservationByItineraryIdOperationLink; +import com.expediagroup.sdk.rapid.operations.PostItineraryOperation; +import com.expediagroup.sdk.rapid.operations.PostItineraryOperationContext; +import com.expediagroup.sdk.rapid.operations.PostItineraryOperationLink; +import com.expediagroup.sdk.rapid.operations.PostPaymentSessionsOperation; +import com.expediagroup.sdk.rapid.operations.PostPaymentSessionsOperationContext; +import com.expediagroup.sdk.rapid.operations.PostPaymentSessionsOperationLink; +import com.expediagroup.sdk.rapid.operations.PutCompletePaymentSessionOperation; +import com.expediagroup.sdk.rapid.operations.PutCompletePaymentSessionOperationContext; +import com.expediagroup.sdk.rapid.operations.PutCompletePaymentSessionOperationLink; +import com.expediagroup.sdk.rapid.operations.PutResumeBookingOperation; +import com.expediagroup.sdk.rapid.operations.PutResumeBookingOperationContext; +import com.expediagroup.sdk.rapid.operations.PutResumeBookingOperationLink; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; +/** + * Service class for handling booking operations. + */ public class BookService extends RapidService { - public Response createBooking(RoomPriceCheck roomPriceCheck, List occupancy) { - - // In the Book request, include corresponding separate instances of room in the rooms array for each room you wish to book. */ - List rooms = Collections.nCopies(occupancy.size(), createRoom()); - - CreateItineraryRequest createItineraryRequest = CreateItineraryRequest.builder() - .affiliateReferenceId(UUID.randomUUID().toString().substring(0, 28)) - .hold(false) - .email("john@example.com") - .phone(phone()) - .rooms(rooms) - .payments(payments()) - .affiliateMetadata("data_point_1:123|data_point2:This is data.") - .taxRegistrationNumber("12345678910") - .travelerHandlingInstructions("Please use the card provided for payment. Avoid cancellation as this is for a corporate traveler. Contact traveler if any issues.") - .build(); - - PostItineraryOperationLink bookLink = roomPriceCheck.getLinks().getBook(); - if (bookLink == null) throw new IllegalStateException("Book link not found"); - - PostItineraryOperationContext postItineraryOperationContext = - PostItineraryOperationContext.builder().customerIp("127.0.0.1").build(); - - PostItineraryOperation operation = new PostItineraryOperation(bookLink, postItineraryOperationContext, createItineraryRequest); - return rapidClient.execute(operation); + /** + * Creates a booking for the given room price check. + * + * @param roomPriceCheck the room price check containing the book link + * @param occupancy the list of occupancy details + * @return a response containing the itinerary creation + * @throws IllegalStateException if the book link is not found + */ + public Response createBooking(RoomPriceCheck roomPriceCheck, + List occupancy) { + + // In the Book request, include corresponding separate instances of room in the rooms array for + // each room you wish to book. + List rooms = Collections.nCopies(occupancy.size(), createRoom()); + + CreateItineraryRequest createItineraryRequest = CreateItineraryRequest.builder() + .affiliateReferenceId(UUID.randomUUID().toString().substring(0, 28)) + .hold(false) + .email("john@example.com") + .phone(phone()) + .rooms(rooms) + .payments(payments()) + .affiliateMetadata("data_point_1:123|data_point2:This is data.") + .taxRegistrationNumber("12345678910") + .travelerHandlingInstructions( + "Please use the card provided for payment. Avoid cancellation as this is for " + + "a corporate traveler. Contact traveler if any issues.") + .build(); + + PostItineraryOperationLink bookLink = roomPriceCheck.getLinks().getBook(); + + if (bookLink == null) { + throw new IllegalStateException("Book link not found"); } - public CompletableFuture> asyncCreateBooking(RoomPriceCheck roomPriceCheck, List occupancy) { - - // In the Book request, include corresponding separate instances of room in the rooms array for each room you wish to book. */ - List rooms = Collections.nCopies(occupancy.size(), createRoom()); - - CreateItineraryRequest createItineraryRequest = CreateItineraryRequest.builder() - .affiliateReferenceId(UUID.randomUUID().toString().substring(0, 28)) - .hold(false) - .email("john@example.com") - .phone(phone()) - .rooms(rooms) - .payments(payments()) - .affiliateMetadata("data_point_1:123|data_point2:This is data.") - .taxRegistrationNumber("12345678910") - .travelerHandlingInstructions("Please use the card provided for payment. Avoid cancellation as this is for a corporate traveler. Contact traveler if any issues.") - .build(); - - PostItineraryOperationLink bookLink = roomPriceCheck.getLinks().getBook(); - if (bookLink == null) throw new IllegalStateException("Book link not found"); - - PostItineraryOperationContext postItineraryOperationContext = - PostItineraryOperationContext.builder().customerIp("127.0.0.1").build(); - - PostItineraryOperation operation = new PostItineraryOperation(bookLink, postItineraryOperationContext, createItineraryRequest); - - return rapidClient.executeAsync(operation); + PostItineraryOperationContext postItineraryOperationContext = + PostItineraryOperationContext.builder().customerIp("127.0.0.1").build(); + + PostItineraryOperation operation = + new PostItineraryOperation(bookLink, postItineraryOperationContext, createItineraryRequest); + + return rapidClient.execute(operation); + } + + /** + * Asynchronously creates a booking for the given room price check. + * + * @param roomPriceCheck the room price check containing the book link + * @param occupancy the list of occupancy details + * @return a CompletableFuture containing the response with the itinerary creation + * @throws IllegalStateException if the book link is not found + */ + public CompletableFuture> asyncCreateBooking( + RoomPriceCheck roomPriceCheck, List occupancy) { + + // In the Book request, include corresponding separate instances of room in the rooms array for + // each room you wish to book. + List rooms = Collections.nCopies(occupancy.size(), createRoom()); + + CreateItineraryRequest createItineraryRequest = CreateItineraryRequest.builder() + .affiliateReferenceId(UUID.randomUUID().toString().substring(0, 28)) + .hold(false) + .email("john@example.com") + .phone(phone()) + .rooms(rooms) + .payments(payments()) + .affiliateMetadata("data_point_1:123|data_point2:This is data.") + .taxRegistrationNumber("12345678910") + .travelerHandlingInstructions( + "Please use the card provided for payment. Avoid cancellation as this is for " + + "a corporate traveler. Contact traveler if any issues.") + .build(); + + PostItineraryOperationLink bookLink = roomPriceCheck.getLinks().getBook(); + + if (bookLink == null) { + throw new IllegalStateException("Book link not found"); } - public Response createBookingWithHold(RoomPriceCheck roomPriceCheck, List occupancy) { - - // In the Book request, include corresponding separate instances of room in the rooms array for each room you wish to book. */ - List rooms = Collections.nCopies(occupancy.size(), createRoom()); - - // Create a booking with hold, set hold to true in the request - CreateItineraryRequest createItineraryRequest = CreateItineraryRequest.builder() - .affiliateReferenceId(UUID.randomUUID().toString().substring(0, 28)) - .hold(true) - .email("john@example.com") - .phone(phone()) - .rooms(rooms) - .payments(payments()) - .affiliateMetadata("data_point_1:123|data_point2:This is data.") - .taxRegistrationNumber("12345678910") - .travelerHandlingInstructions("Please use the card provided for payment. Avoid cancellation as this is for a corporate traveler. Contact traveler if any issues.") - .build(); - - PostItineraryOperationLink bookLink = roomPriceCheck.getLinks().getBook(); - if (bookLink == null) throw new IllegalStateException("Book link not found"); - - - PostItineraryOperationContext postItineraryOperationContext = - PostItineraryOperationContext.builder().customerIp("127.0.0.1").build(); - - PostItineraryOperation operation = new PostItineraryOperation(bookLink, postItineraryOperationContext, createItineraryRequest); - return rapidClient.execute(operation); + PostItineraryOperationContext postItineraryOperationContext = + PostItineraryOperationContext.builder().customerIp("127.0.0.1").build(); + + PostItineraryOperation operation = + new PostItineraryOperation(bookLink, postItineraryOperationContext, createItineraryRequest); + + return rapidClient.executeAsync(operation); + } + + /** + * Creates a booking with hold for the given room price check. + * + * @param roomPriceCheck the room price check containing the book link + * @param occupancy the list of occupancy details + * @return a response containing the itinerary creation + * @throws IllegalStateException if the book link is not found + */ + public Response createBookingWithHold(RoomPriceCheck roomPriceCheck, + List occupancy) { + + // In the Book request, include corresponding separate instances of room in the rooms array for + // each room you wish to book. + List rooms = Collections.nCopies(occupancy.size(), createRoom()); + + // Create a booking with hold, set hold to true in the request + CreateItineraryRequest createItineraryRequest = CreateItineraryRequest.builder() + .affiliateReferenceId(UUID.randomUUID().toString().substring(0, 28)) + .hold(true) + .email("john@example.com") + .phone(phone()) + .rooms(rooms) + .payments(payments()) + .affiliateMetadata("data_point_1:123|data_point2:This is data.") + .taxRegistrationNumber("12345678910") + .travelerHandlingInstructions( + "Please use the card provided for payment. Avoid cancellation as this is for " + + "a corporate traveler. Contact traveler if any issues.") + .build(); + + PostItineraryOperationLink bookLink = roomPriceCheck.getLinks().getBook(); + + if (bookLink == null) { + throw new IllegalStateException("Book link not found"); } - public Response resumeBooking(ItineraryCreation itineraryCreation) { - ItineraryCreationLinks itineraryCreationLinks = itineraryCreation.getLinks(); - if (itineraryCreationLinks == null) throw new IllegalStateException("itineraryCreationLinks not found"); - PutResumeBookingOperationLink resumeLink = itineraryCreationLinks.getResume(); - if (resumeLink == null) throw new IllegalStateException("Resume link not found"); + PostItineraryOperationContext postItineraryOperationContext = + PostItineraryOperationContext.builder().customerIp("127.0.0.1").build(); - PutResumeBookingOperationContext putResumeBookingOperationContext = - PutResumeBookingOperationContext.builder().customerIp("127.0.0.1").build(); - - return rapidClient.execute(new PutResumeBookingOperation(resumeLink, putResumeBookingOperationContext)); - } + PostItineraryOperation operation = + new PostItineraryOperation(bookLink, postItineraryOperationContext, createItineraryRequest); + return rapidClient.execute(operation); + } - public Response getReservation(ItineraryCreation itineraryCreation) { - GetReservationByItineraryIdOperationLink retrieveLink = itineraryCreation.getLinks().getRetrieve(); - if (retrieveLink == null) throw new IllegalStateException("Retrieve link not found"); + /** + * Resumes a booking for the given itinerary creation. + * + * @param itineraryCreation the itinerary creation containing the resume link + * @return a response indicating the result of the resume booking operation + * @throws IllegalStateException if the itinerary creation links or resume link is not found + */ + public Response resumeBooking(ItineraryCreation itineraryCreation) { + ItineraryCreationLinks itineraryCreationLinks = itineraryCreation.getLinks(); - GetReservationByItineraryIdOperationContext getReservationByItineraryIdOperationContext = - GetReservationByItineraryIdOperationContext.builder().customerIp("127.0.0.1").build(); - - return rapidClient.execute(new GetReservationByItineraryIdOperation(retrieveLink, getReservationByItineraryIdOperationContext )); + if (itineraryCreationLinks == null) { + throw new IllegalStateException("itineraryCreationLinks not found"); } - public Response cancelHeldReservation(ItineraryCreation itineraryCreation) { - ItineraryCreationLinks itineraryCreationLinks = itineraryCreation.getLinks(); - if (itineraryCreationLinks == null) throw new RuntimeException(); - - DeleteHeldBookingOperationLink cancelLink = itineraryCreationLinks.getCancel(); - if (cancelLink == null) throw new IllegalStateException("Cancel link not found"); - - DeleteHeldBookingOperationContext deleteHeldBookingOperationContext = - DeleteHeldBookingOperationContext.builder().customerIp("127.0.0.1").build(); + PutResumeBookingOperationLink resumeLink = itineraryCreationLinks.getResume(); - return rapidClient.execute(new DeleteHeldBookingOperation(cancelLink, deleteHeldBookingOperationContext)); + if (resumeLink == null) { + throw new IllegalStateException("Resume link not found"); } - public Response deleteRoom(Itinerary itinerary, int roomIndex) { - DeleteRoomOperationLink cancelRoomLink = itinerary.getRooms().get(roomIndex).getLinks().getCancel(); - - if (cancelRoomLink == null) throw new IllegalStateException("Cancel room link not found"); - - DeleteRoomOperation deleteRoomOperation = new DeleteRoomOperation(cancelRoomLink, - DeleteRoomOperationContext.builder().customerIp("127.0.0.1").build()); - - return rapidClient.execute(deleteRoomOperation); + PutResumeBookingOperationContext putResumeBookingOperationContext = + PutResumeBookingOperationContext.builder().customerIp("127.0.0.1").build(); + + return rapidClient.execute( + new PutResumeBookingOperation(resumeLink, putResumeBookingOperationContext)); + } + + /** + * Retrieves the reservation details for the given itinerary creation. + * + * @param itineraryCreation the itinerary creation containing the retrieve link + * @return a response containing the itinerary details + * @throws IllegalStateException if the retrieve link is not found + */ + public Response getReservation(ItineraryCreation itineraryCreation) { + GetReservationByItineraryIdOperationLink retrieveLink = + itineraryCreation.getLinks().getRetrieve(); + + if (retrieveLink == null) { + throw new IllegalStateException("Retrieve link not found"); } - public Response changeRoomDetails(Itinerary itinerary, int roomIndex) { - ChangeRoomDetailsOperationLink changeRoomDetailsLink = itinerary.getRooms().get(roomIndex).getLinks().getChange(); - - if (changeRoomDetailsLink == null) throw new IllegalStateException("Change room link not found"); - - ChangeRoomDetailsOperation changeRoomDetailsOperation = new ChangeRoomDetailsOperation(changeRoomDetailsLink, - ChangeRoomDetailsOperationContext.builder().customerIp("127.0.0.1").build(), - ChangeRoomDetailsRequest.builder() - .givenName("Jane") - .familyName("Doe") - .build()); - - return rapidClient.execute(changeRoomDetailsOperation); + GetReservationByItineraryIdOperationContext getReservationByItineraryIdOperationContext = + GetReservationByItineraryIdOperationContext.builder().customerIp("127.0.0.1").build(); + + return rapidClient.execute(new GetReservationByItineraryIdOperation(retrieveLink, + getReservationByItineraryIdOperationContext)); + } + + /** + * Cancels a held reservation for the given itinerary creation. + * + * @param itineraryCreation the itinerary creation containing the cancel link + * @return a response indicating the result of the delete held booking operation + * @throws RuntimeException if the itinerary creation links are not found + * @throws IllegalStateException if the cancel link is not found + */ + public Response cancelHeldReservation(ItineraryCreation itineraryCreation) { + ItineraryCreationLinks itineraryCreationLinks = itineraryCreation.getLinks(); + + if (itineraryCreationLinks == null) { + throw new RuntimeException(); } - public CompletableFuture> asyncGetReservation(ItineraryCreation itineraryCreation) { - - GetReservationByItineraryIdOperationLink retrieveLink = itineraryCreation.getLinks().getRetrieve(); - if (retrieveLink == null) throw new IllegalStateException("Retrieve link not found"); + DeleteHeldBookingOperationLink cancelLink = itineraryCreationLinks.getCancel(); - GetReservationByItineraryIdOperationContext getReservationByItineraryIdOperationContext = - GetReservationByItineraryIdOperationContext.builder().customerIp("127.0.0.1").build(); - - return rapidClient.executeAsync(new GetReservationByItineraryIdOperation(retrieveLink, getReservationByItineraryIdOperationContext)); + if (cancelLink == null) { + throw new IllegalStateException("Cancel link not found"); } - public Response completePaymentSession(ItineraryCreation itineraryCreation) { - PutCompletePaymentSessionOperationLink putCompletePaymentSessionLink = itineraryCreation.getLinks().getCompletePaymentSession(); - if (putCompletePaymentSessionLink == null) throw new IllegalStateException("Complete payment session link not found"); - - PutCompletePaymentSessionOperationContext putCompletePaymentSessionOperationContext = - PutCompletePaymentSessionOperationContext.builder().customerIp("127.0.0.1").build(); - - return rapidClient.execute(new PutCompletePaymentSessionOperation(putCompletePaymentSessionLink, - putCompletePaymentSessionOperationContext)); + DeleteHeldBookingOperationContext deleteHeldBookingOperationContext = + DeleteHeldBookingOperationContext.builder().customerIp("127.0.0.1").build(); + + return rapidClient.execute( + new DeleteHeldBookingOperation(cancelLink, deleteHeldBookingOperationContext)); + } + + /** + * Deletes a room from the given itinerary. + * + * @param itinerary the itinerary containing the room to be deleted + * @param roomIndex the index of the room to be deleted + * @return a response indicating the result of the delete room operation + * @throws IllegalStateException if the cancel room link is not found + */ + public Response deleteRoom(Itinerary itinerary, int roomIndex) { + DeleteRoomOperationLink cancelRoomLink = + itinerary.getRooms().get(roomIndex).getLinks().getCancel(); + + if (cancelRoomLink == null) { + throw new IllegalStateException("Cancel room link not found"); } - public Response postPaymentSession(RoomPriceCheck roomPriceCheck) { - PostPaymentSessionsOperationLink postPaymentSessionLink = roomPriceCheck.getLinks().getPaymentSession(); - if (postPaymentSessionLink == null) throw new IllegalStateException("Post payment session link not found"); - - PostPaymentSessionsOperationContext postPaymentSessionOperationContext = - PostPaymentSessionsOperationContext.builder().customerIp("127.0.0.1").build(); - - return rapidClient.execute(new PostPaymentSessionsOperation(postPaymentSessionLink, - postPaymentSessionOperationContext, PaymentSessionsRequest.builder().build())); + DeleteRoomOperation deleteRoomOperation = new DeleteRoomOperation(cancelRoomLink, + DeleteRoomOperationContext.builder().customerIp("127.0.0.1").build()); + + return rapidClient.execute(deleteRoomOperation); + } + + /** + * Changes the room details for a specific room in the given itinerary. + * + * @param itinerary the itinerary containing the room to be changed + * @param roomIndex the index of the room to be changed + * @return a response indicating the result of the change room details operation + * @throws IllegalStateException if the change room link is not found + */ + public Response changeRoomDetails(Itinerary itinerary, int roomIndex) { + ChangeRoomDetailsOperationLink changeRoomDetailsLink = + itinerary.getRooms().get(roomIndex).getLinks().getChange(); + + if (changeRoomDetailsLink == null) { + throw new IllegalStateException("Change room link not found"); } - public Response commitChange(CommitChangeOperationLink commitChangeLink) { - return rapidClient.execute(new CommitChangeOperation(commitChangeLink, null, null)); - } + ChangeRoomDetailsOperation changeRoomDetailsOperation = + new ChangeRoomDetailsOperation(changeRoomDetailsLink, + ChangeRoomDetailsOperationContext.builder().customerIp("127.0.0.1").build(), + ChangeRoomDetailsRequest.builder() + .givenName("Jane") + .familyName("Doe") + .build()); - /* Helper methods */ - private CreateItineraryRequestRoom createRoom() { - return CreateItineraryRequestRoom.builder() - .givenName("John") - .familyName("Smith") - .smoking(false) - .specialRequest("Please provide a room with a view of the ocean.") - .build(); + return rapidClient.execute(changeRoomDetailsOperation); + } + + /** + * Asynchronously retrieves the reservation details for the given itinerary creation. + * + * @param itineraryCreation the itinerary creation containing the retrieve link + * @return a CompletableFuture containing the response with the itinerary details + * @throws IllegalStateException if the retrieve link is not found + */ + public CompletableFuture> asyncGetReservation( + ItineraryCreation itineraryCreation + ) { + + GetReservationByItineraryIdOperationLink retrieveLink = + itineraryCreation.getLinks().getRetrieve(); + if (retrieveLink == null) { + throw new IllegalStateException("Retrieve link not found"); } - /* Helper methods */ - private PhoneRequest phone() { - return PhoneRequest.builder() - .countryCode("1") - .areaCode("487") - .number("5550077") - .build(); + GetReservationByItineraryIdOperationContext getReservationByItineraryIdOperationContext = + GetReservationByItineraryIdOperationContext.builder().customerIp("127.0.0.1").build(); + + return rapidClient.executeAsync(new GetReservationByItineraryIdOperation(retrieveLink, + getReservationByItineraryIdOperationContext)); + } + + /** + * Completes the payment session for the given itinerary creation. + * + * @param itineraryCreation the itinerary creation containing the complete payment session link + * @return a response containing the completed payment session + * @throws IllegalStateException if the complete payment session link is not found + */ + public Response completePaymentSession( + ItineraryCreation itineraryCreation) { + PutCompletePaymentSessionOperationLink putCompletePaymentSessionLink = + itineraryCreation.getLinks().getCompletePaymentSession(); + + if (putCompletePaymentSessionLink == null) { + throw new IllegalStateException("Complete payment session link not found"); } - /* Helper methods */ - private List payments() { - BillingContactRequestAddress address = - BillingContactRequestAddress.builder() - .line1("555 1st St") - .line2("10th Floor") - .line3("Unit 12") - .city("Seattle") - .stateProvinceCode("WA") - .countryCode("US") - .postalCode("98121") - .build(); - - BillingContactRequest billingContact = BillingContactRequest.builder() - .givenName("John") - .familyName("Smith") - .address(address) - .build(); - - return Arrays.asList(PaymentRequest.builder() - .type(PaymentRequest.Type.CUSTOMER_CARD) - .number("4111111111111111") - .securityCode("123") - .expirationMonth("08") - .expirationYear("2025") - .billingContact(billingContact) - .enrollmentDate("2018-09-15") - .build()); + PutCompletePaymentSessionOperationContext putCompletePaymentSessionOperationContext = + PutCompletePaymentSessionOperationContext.builder().customerIp("127.0.0.1").build(); + + return rapidClient.execute(new PutCompletePaymentSessionOperation(putCompletePaymentSessionLink, + putCompletePaymentSessionOperationContext)); + } + + /** + * Posts a payment session for the given room price check. + * + * @param roomPriceCheck the room price check containing the payment session link + * @return a response containing the payment sessions + * @throws IllegalStateException if the payment session link is not found + */ + public Response postPaymentSession(RoomPriceCheck roomPriceCheck) { + PostPaymentSessionsOperationLink postPaymentSessionLink = + roomPriceCheck.getLinks().getPaymentSession(); + + if (postPaymentSessionLink == null) { + throw new IllegalStateException("Post payment session link not found"); } + + PostPaymentSessionsOperationContext postPaymentSessionOperationContext = + PostPaymentSessionsOperationContext.builder().customerIp("127.0.0.1").build(); + + return rapidClient.execute(new PostPaymentSessionsOperation(postPaymentSessionLink, + postPaymentSessionOperationContext, PaymentSessionsRequest.builder().build())); + } + + /** + * Commits a change operation. + * + * @param commitChangeLink the link to commit the change + * @return a response indicating the result of the commit operation + */ + public Response commitChange(CommitChangeOperationLink commitChangeLink) { + return rapidClient.execute( + new CommitChangeOperation(commitChangeLink, null, null) + ); + } + + /* Helper methods */ + private CreateItineraryRequestRoom createRoom() { + return CreateItineraryRequestRoom.builder() + .givenName("John") + .familyName("Smith") + .smoking(false) + .specialRequest("Please provide a room with a view of the ocean.") + .build(); + } + + /* Helper methods */ + private PhoneRequest phone() { + return PhoneRequest.builder() + .countryCode("1") + .areaCode("487") + .number("5550077") + .build(); + } + + /* Helper methods */ + private List payments() { + BillingContactRequestAddress address = + BillingContactRequestAddress.builder() + .line1("555 1st St") + .line2("10th Floor") + .line3("Unit 12") + .city("Seattle") + .stateProvinceCode("WA") + .countryCode("US") + .postalCode("98121") + .build(); + + BillingContactRequest billingContact = BillingContactRequest.builder() + .givenName("John") + .familyName("Smith") + .address(address) + .build(); + + return Arrays.asList(PaymentRequest.builder() + .type(PaymentRequest.Type.CUSTOMER_CARD) + .number("4111111111111111") + .securityCode("123") + .expirationMonth("08") + .expirationYear("2025") + .billingContact(billingContact) + .enrollmentDate("2018-09-15") + .build()); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/ContentService.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/ContentService.java index 74197483e9..0a55a08a9b 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/ContentService.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/ContentService.java @@ -7,54 +7,96 @@ import com.expediagroup.sdk.rapid.operations.GetPropertyContentOperationContext; import com.expediagroup.sdk.rapid.operations.GetPropertyContentOperationLink; import com.expediagroup.sdk.rapid.operations.GetPropertyContentOperationParams; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Service class for handling property content operations. + */ public class ContentService extends RapidService { - Logger logger = LoggerFactory.getLogger(ContentService.class); + Logger logger = LoggerFactory.getLogger(ContentService.class); - public Response> getPropertyContent(List propertyIds, String language, RapidPartnerSalesProfile rapidPartnerSalesProfile) { - GetPropertyContentOperationParams params = GetPropertyContentOperationParams.builder() - .propertyId(propertyIds) - .supplySource("expedia") - .language(language) - .build(); + /** + * Synchronously retrieves property content for the given property IDs and language. + * + * @param propertyIds List of property IDs to retrieve content for. + * @param language Language code for the content. + * @param rapidPartnerSalesProfile Sales profile for the rapid partner. + * @return Response containing a map of property IDs to their content. + */ + public Response> getPropertyContent( + List propertyIds, + String language, + RapidPartnerSalesProfile rapidPartnerSalesProfile + ) { + GetPropertyContentOperationParams params = GetPropertyContentOperationParams.builder() + .propertyId(propertyIds) + .supplySource("expedia") + .language(language) + .build(); - GetPropertyContentOperation operation = new GetPropertyContentOperation(params); + GetPropertyContentOperation operation = new GetPropertyContentOperation(params); - return rapidClient.execute(operation); - } + return rapidClient.execute(operation); + } - public CompletableFuture>> asyncGetPropertyContent(List propertyIds, String language, RapidPartnerSalesProfile rapidPartnerSalesProfile) { - GetPropertyContentOperationParams params = GetPropertyContentOperationParams.builder() - .propertyId(propertyIds) - .supplySource("expedia") - .language(language) - .build(); + /** + * Asynchronously retrieves property content for the given property IDs and language. + * + * @param propertyIds List of property IDs to retrieve content for. + * @param language Language code for the content. + * @param rapidPartnerSalesProfile Sales profile for the rapid partner. + * @return CompletableFuture containing a response with a map of property IDs to their content. + */ + public CompletableFuture>> asyncGetPropertyContent( + List propertyIds, + String language, + RapidPartnerSalesProfile rapidPartnerSalesProfile + ) { + GetPropertyContentOperationParams params = GetPropertyContentOperationParams.builder() + .propertyId(propertyIds) + .supplySource("expedia") + .language(language) + .build(); - GetPropertyContentOperation operation = new GetPropertyContentOperation(params); + GetPropertyContentOperation operation = new GetPropertyContentOperation(params); - return rapidClient.executeAsync(operation); - } + return rapidClient.executeAsync(operation); + } - public CompletableFuture>> asyncGetPropertyContentInAdditionalLanguage(PropertyContent propertyContent, RapidPartnerSalesProfile rapidPartnerSalesProfile) { - String language = propertyContent.getAddress().getLocalized() - .getLinks().keySet().iterator().next(); - logger.info("Get property content in additional language from returned link, language: [{}]...", language); + /** + * Asynchronously retrieves property content in an additional language from the provided property + * content. + * + * @param propertyContent Property content containing the link to the additional language content. + * @param rapidPartnerSalesProfile Sales profile for the rapid partner. + * @return CompletableFuture containing a response with a map of property IDs to their content. + * @throws IllegalStateException if no link is found for the additional language. + */ + public CompletableFuture>> + asyncGetPropertyContentInAdditionalLanguage( + PropertyContent propertyContent, + RapidPartnerSalesProfile rapidPartnerSalesProfile + ) { + String language = propertyContent.getAddress().getLocalized() + .getLinks().keySet().iterator().next(); + logger.info("Get property content in additional language from returned link, language: [{}]...", + language); - GetPropertyContentOperationLink propertyContentLink = propertyContent.getAddress().getLocalized().getLinks().get(language); + GetPropertyContentOperationLink propertyContentLink = + propertyContent.getAddress().getLocalized().getLinks().get(language); - if (propertyContentLink == null) { - throw new IllegalStateException("No link found for fr-FR language"); - } + if (propertyContentLink == null) { + throw new IllegalStateException("No link found for fr-FR language"); + } - GetPropertyContentOperation operation = new GetPropertyContentOperation(propertyContentLink, new GetPropertyContentOperationContext()); + GetPropertyContentOperation operation = new GetPropertyContentOperation(propertyContentLink, + new GetPropertyContentOperationContext()); - return rapidClient.executeAsync(operation); - } + return rapidClient.executeAsync(operation); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/GeographyService.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/GeographyService.java index 357bcaee75..3adfa2c40a 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/GeographyService.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/GeographyService.java @@ -8,14 +8,13 @@ import com.expediagroup.sdk.rapid.operations.GetRegionOperationParams; import com.expediagroup.sdk.rapid.operations.GetRegionsOperation; import com.expediagroup.sdk.rapid.operations.GetRegionsOperationParams; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This shows how to consume the rapid geography apis using the rapid java sdk to: @@ -25,69 +24,102 @@ */ public class GeographyService extends RapidService { - private static final Logger logger = LoggerFactory.getLogger(GeographyService.class); - - public List> getAllRegionsWithDetails(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - - logger.info("------------- Calling getRegions paginated results with no ancestor ID and include=details to get all regions:"); - - GetRegionsOperationParams params = GetRegionsOperationParams.builder() - .include(Collections.singletonList(GetRegionsOperationParams.Include.DETAILS)) - .language("en-US") - .customerSessionId(Constants.CUSTOMER_SESSION_ID) - .limit(BigDecimal.valueOf(10)) - .area("50,37.227924,-93.310036") - .supplySource("expedia") - .countryCode(Collections.singletonList("US")) - .build(); - - ResponsePaginator> responsePaginator = rapidClient.getPaginator(new GetRegionsOperation(params)); - - List> pages = new ArrayList<>(); - - logger.info("Paginator total results count: {}", responsePaginator.getPaginationTotalResults()); - - responsePaginator.forEachRemaining(page -> pages.add(page.getData())); - - return pages; - } - - public List> getRegionsByAncestor(String ancestorId, RapidPartnerSalesProfile rapidPartnerSalesProfile) { - logger.info("------------- Calling getRegionsPaginator by ancestor ID: [{}]", ancestorId); - - GetRegionsOperationParams params = GetRegionsOperationParams.builder() - .include(Collections.singletonList(GetRegionsOperationParams.Include.DETAILS)) - .language("en-US") - .customerSessionId(Constants.CUSTOMER_SESSION_ID) - .limit(BigDecimal.valueOf(10)) - .supplySource("expedia") - .countryCode(Collections.singletonList("US")) - .ancestorId(ancestorId) - .build(); - - ResponsePaginator> responsePaginator = rapidClient.getPaginator(new GetRegionsOperation(params)); - - List> pages = new ArrayList<>(); - - logger.info("Paginator total results count: {}", responsePaginator.getPaginationTotalResults()); - - responsePaginator.forEachRemaining(page -> pages.add(page.getData())); - - return pages; - } - - public Region getRegionDetailsAndPropertyIds(String regionId, String language, RapidPartnerSalesProfile rapidPartnerSalesProfile) { - logger.info("------------- Calling GetRegion:"); - - GetRegionOperationParams params = GetRegionOperationParams.builder() - .include(Arrays.asList(GetRegionOperationParams.Include.DETAILS, GetRegionOperationParams.Include.PROPERTY_IDS)) - .language(language) - .regionId(regionId) - .customerSessionId(Constants.CUSTOMER_SESSION_ID) - .supplySource("expedia") - .build(); - - return rapidClient.execute(new GetRegionOperation(params)).getData(); - } - + private static final Logger logger = LoggerFactory.getLogger(GeographyService.class); + + /** + * Retrieves all regions with detailed information. + * + * @param rapidPartnerSalesProfile the sales profile to use for the operation + * @return a list of lists containing region details + */ + public List> getAllRegionsWithDetails( + RapidPartnerSalesProfile rapidPartnerSalesProfile) { + + logger.info( + "------------- Calling getRegions paginated results with no ancestor ID and " + + "include=details to get all regions:"); + + GetRegionsOperationParams params = GetRegionsOperationParams.builder() + .include(Collections.singletonList(GetRegionsOperationParams.Include.DETAILS)) + .language("en-US") + .customerSessionId(Constants.CUSTOMER_SESSION_ID) + .limit(BigDecimal.valueOf(10)) + .area("50,37.227924,-93.310036") + .supplySource("expedia") + .countryCode(Collections.singletonList("US")) + .build(); + + ResponsePaginator> responsePaginator = + rapidClient.getPaginator(new GetRegionsOperation(params)); + + List> pages = new ArrayList<>(); + + logger.info("Paginator total results count: {}", responsePaginator.getPaginationTotalResults()); + + responsePaginator.forEachRemaining(page -> pages.add(page.getData())); + + return pages; + } + + /** + * Retrieves all regions within a specific larger region. + * + * @param ancestorId the ancestor region id + * @param rapidPartnerSalesProfile the sales profile to use for the operation + * @return a list of lists containing region details + */ + public List> getRegionsByAncestor( + String ancestorId, + RapidPartnerSalesProfile rapidPartnerSalesProfile + ) { + logger.info("------------- Calling getRegionsPaginator by ancestor ID: [{}]", ancestorId); + + GetRegionsOperationParams params = GetRegionsOperationParams.builder() + .include(Collections.singletonList(GetRegionsOperationParams.Include.DETAILS)) + .language("en-US") + .customerSessionId(Constants.CUSTOMER_SESSION_ID) + .limit(BigDecimal.valueOf(10)) + .supplySource("expedia") + .countryCode(Collections.singletonList("US")) + .ancestorId(ancestorId) + .build(); + + ResponsePaginator> responsePaginator = + rapidClient.getPaginator(new GetRegionsOperation(params)); + + List> pages = new ArrayList<>(); + + logger.info("Paginator total results count: {}", responsePaginator.getPaginationTotalResults()); + + responsePaginator.forEachRemaining(page -> pages.add(page.getData())); + + return pages; + } + + /** + * Retrieves one region definition and properties mappings within this region. + * + * @param regionId the region id + * @param language the language + * @param rapidPartnerSalesProfile the sales profile to use for the operation + * @return the region details + */ + public Region getRegionDetailsAndPropertyIds( + String regionId, + String language, + RapidPartnerSalesProfile rapidPartnerSalesProfile + ) { + logger.info("------------- Calling GetRegion:"); + + GetRegionOperationParams params = GetRegionOperationParams.builder() + .include(Arrays.asList(GetRegionOperationParams.Include.DETAILS, + GetRegionOperationParams.Include.PROPERTY_IDS)) + .language(language) + .regionId(regionId) + .customerSessionId(Constants.CUSTOMER_SESSION_ID) + .supplySource("expedia") + .build(); + + return rapidClient.execute(new GetRegionOperation(params)).getData(); + } } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/RapidService.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/RapidService.java index 9f7e3864e5..0aedf2019a 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/RapidService.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/RapidService.java @@ -3,14 +3,18 @@ import com.expediagroup.sdk.rapid.client.RapidClient; import com.expediagroup.sdk.rapid.examples.Constants; +/** + * Abstract class representing a service that interacts with the Rapid API. + */ public abstract class RapidService { - - protected static final RapidClient rapidClient = RapidClient - .builder() - .key(System.getProperty("com.expediagroup.rapidsdkjava.apikey", "your_api_key")) - .secret(System.getProperty("com.expediagroup.rapidsdkjava.apisecret", "your_api_secret")) - .endpoint(Constants.SANDBOX_URL) // remove to connect to the production environment - .requestTimeout(10000) - .build(); - + /** + * The RapidClient instance used to execute operations. + */ + protected static final RapidClient rapidClient = RapidClient + .builder() + .key(System.getProperty("com.expediagroup.rapidsdkjava.apikey", "your_api_key")) + .secret(System.getProperty("com.expediagroup.rapidsdkjava.apisecret", "your_api_secret")) + .endpoint(Constants.SANDBOX_URL) // remove to connect to the production environment + .requestTimeout(10000) + .build(); } diff --git a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/ShopService.java b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/ShopService.java index 65e236133a..069f5ac340 100644 --- a/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/ShopService.java +++ b/examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/ShopService.java @@ -18,97 +18,169 @@ import com.expediagroup.sdk.rapid.operations.GetPaymentOptionsOperationLink; import com.expediagroup.sdk.rapid.operations.PriceCheckOperation; import com.expediagroup.sdk.rapid.operations.PriceCheckOperationLink; - import java.math.BigDecimal; import java.time.LocalDate; import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; +/** + * Service class for interacting with the Rapid API. + */ public class ShopService extends RapidService { - public Response> getPropertiesAvailability(List occupancy, RapidPartnerSalesProfile rapidPartnerSalesProfile) { - GetAvailabilityOperationParams params = GetAvailabilityOperationParams.builder() - .customerIp(Constants.CUSTOMER_IP) - .checkin(LocalDate.now().plusDays(14).toString()) - .checkout(LocalDate.now().plusDays(15).toString()) - .currency("USD") - .countryCode("US") - .language("en-US") - .occupancy(occupancy) - .propertyId(Arrays.asList(Constants.TEST_PROPERTY_ID)) - .salesChannel("website") - .salesEnvironment("hotel_only") - .ratePlanCount(BigDecimal.ONE) - .build(); - - GetAvailabilityOperation operation = new GetAvailabilityOperation(params); - - return rapidClient.execute(operation); - } - - public CompletableFuture>> asyncGetSingleRoomPropertiesAvailability(RapidPartnerSalesProfile rapidPartnerSalesProfile) { - GetAvailabilityOperationParams params = GetAvailabilityOperationParams.builder() - .customerIp(Constants.CUSTOMER_IP) - .checkin(LocalDate.now().plusDays(14).toString()) - .checkout(LocalDate.now().plusDays(15).toString()) - .currency("USD") - .countryCode("US") - .language("en-US") - .occupancy(Arrays.asList("2")) - .propertyId(Arrays.asList(Constants.TEST_PROPERTY_ID)) - .salesChannel("website") - .salesEnvironment("hotel_only") - .ratePlanCount(BigDecimal.ONE) - .build(); - - GetAvailabilityOperation operation = new GetAvailabilityOperation(params); - - return rapidClient.executeAsync(operation); - } - - public Response checkRoomPrices(PropertyAvailability propertyAvailability, int selectedRoomIndex, int selectedRateIndex) { - - PriceCheckOperationLink priceCheckLink = propertyAvailability.getRooms().get(selectedRoomIndex).getRates().get(selectedRateIndex).getBedGroups().entrySet() - .stream().findFirst().get().getValue().getLinks().getPriceCheck(); - - PriceCheckOperation operation = new PriceCheckOperation(priceCheckLink, null); - return rapidClient.execute(operation); - } - - public Response> getAdditionalAvailability(PropertyAvailability propertyAvailability) { - GetAdditionalAvailabilityOperationLink additionalRatesLink = propertyAvailability.getLinks().getAdditionalRates(); - - return rapidClient.execute(new GetAdditionalAvailabilityOperation(additionalRatesLink, null)); + /** + * Retrieves the availability of properties based on the given occupancy. + * + * @param occupancy the occupancy to check availability for + * @param rapidPartnerSalesProfile the sales profile to use for the operation + * @return the response containing the list of properties with availability + */ + public Response> getPropertiesAvailability( + List occupancy, + RapidPartnerSalesProfile rapidPartnerSalesProfile + ) { + GetAvailabilityOperationParams params = GetAvailabilityOperationParams.builder() + .customerIp(Constants.CUSTOMER_IP) + .checkin(LocalDate.now().plusDays(14).toString()) + .checkout(LocalDate.now().plusDays(15).toString()) + .currency("USD") + .countryCode("US") + .language("en-US") + .occupancy(occupancy) + .propertyId(Arrays.asList(Constants.TEST_PROPERTY_ID)) + .salesChannel("website") + .salesEnvironment("hotel_only") + .ratePlanCount(BigDecimal.ONE) + .build(); + + GetAvailabilityOperation operation = new GetAvailabilityOperation(params); + + return rapidClient.execute(operation); + } + + /** + * Retrieves the availability of properties based on the given occupancy asynchronously. + * + * @param rapidPartnerSalesProfile the sales profile to use for the operation + * @return the future response containing the list of properties with availability + */ + public CompletableFuture>> asyncGetSingleRoomPropertiesAvailability( + RapidPartnerSalesProfile rapidPartnerSalesProfile) { + GetAvailabilityOperationParams params = GetAvailabilityOperationParams.builder() + .customerIp(Constants.CUSTOMER_IP) + .checkin(LocalDate.now().plusDays(14).toString()) + .checkout(LocalDate.now().plusDays(15).toString()) + .currency("USD") + .countryCode("US") + .language("en-US") + .occupancy(Arrays.asList("2")) + .propertyId(Arrays.asList(Constants.TEST_PROPERTY_ID)) + .salesChannel("website") + .salesEnvironment("hotel_only") + .ratePlanCount(BigDecimal.ONE) + .build(); + + GetAvailabilityOperation operation = new GetAvailabilityOperation(params); + + return rapidClient.executeAsync(operation); + } + + /** + * Checks the room prices for a given property availability. + * + * @param propertyAvailability the property availability to check prices for + * @param selectedRoomIndex the index of the selected room + * @param selectedRateIndex the index of the selected rate + * @return the response containing the room price check + */ + public Response checkRoomPrices(PropertyAvailability propertyAvailability, + int selectedRoomIndex, int selectedRateIndex) { + + PriceCheckOperationLink priceCheckLink = + propertyAvailability.getRooms().get(selectedRoomIndex).getRates().get(selectedRateIndex) + .getBedGroups().entrySet() + .stream().findFirst().get().getValue().getLinks().getPriceCheck(); + + PriceCheckOperation operation = new PriceCheckOperation(priceCheckLink, null); + return rapidClient.execute(operation); + } + + /** + * Retrieves the additional availability for a given property availability. + * + * @param propertyAvailability the property availability to get additional availability for + * @return the response containing the list of properties with additional availability + */ + public Response> getAdditionalAvailability( + PropertyAvailability propertyAvailability) { + GetAdditionalAvailabilityOperationLink additionalRatesLink = + propertyAvailability.getLinks().getAdditionalRates(); + + return rapidClient.execute(new GetAdditionalAvailabilityOperation(additionalRatesLink, null)); + } + + /** + * Retrieves the additional availability for a given property availability based on the new + * check-in and check-out dates. + * + * @param additionalRatesLink the link to the additional rates operation + * @param newCheckin the new check-in date + * @param newCheckout the new check-out date + * @return the response containing the list of properties with additional availability + */ + public Response> getAdditionalAvailabilityForChange( + GetAdditionalAvailabilityOperationLink additionalRatesLink, String newCheckin, + String newCheckout) { + GetAdditionalAvailabilityOperationParams params = GetAdditionalAvailabilityOperationParams + .builder() + .checkin(newCheckin) + .checkout(newCheckout) + .build(); + + // we should be able to send params here + return rapidClient.execute(new GetAdditionalAvailabilityOperation(additionalRatesLink, null)); + } + + /** + * Asynchronously checks the room prices for a given property availability. + * + * @param propertyAvailability the property availability to check prices for + * @param selectedRoomIndex the index of the selected room + * @param selectedRateIndex the index of the selected rate + * @return the future response containing the room price check + */ + public CompletableFuture> asyncCheckRoomPrices( + PropertyAvailability propertyAvailability, int selectedRoomIndex, int selectedRateIndex) { + + PriceCheckOperationLink priceCheckLink = + propertyAvailability.getRooms().get(selectedRoomIndex).getRates().get(selectedRateIndex) + .getBedGroups().entrySet() + .stream().findFirst().get().getValue().getLinks().getPriceCheck(); + + PriceCheckOperation operation = new PriceCheckOperation(priceCheckLink, null); + + return rapidClient.executeAsync(operation); + } + + /** + * Asynchronously retrieves the payment options for a given room availability. + * + * @param roomAvailability the room availability to get payment options for + * @param rapidPartnerSalesProfile the sales profile to use for the operation + * @return the future response containing the payment options + * @throws IllegalStateException if no payment options link is found for the room + */ + public CompletableFuture> getPaymentOptions( + RoomAvailability roomAvailability, RapidPartnerSalesProfile rapidPartnerSalesProfile) { + GetPaymentOptionsOperationLink paymentOptionsLink = + roomAvailability.getRates().get(0).getLinks().getPaymentOptions(); + if (paymentOptionsLink == null) { + throw new IllegalStateException( + "No payment options link found for room: " + roomAvailability.getId()); } - public Response> getAdditionalAvailabilityForChange(GetAdditionalAvailabilityOperationLink additionalRatesLink, String newCheckin, String newCheckout) { - GetAdditionalAvailabilityOperationParams params = GetAdditionalAvailabilityOperationParams - .builder() - .checkin(newCheckin) - .checkout(newCheckout) - .build(); - - // we should be able to send params here - return rapidClient.execute(new GetAdditionalAvailabilityOperation(additionalRatesLink, null)); - } - - public CompletableFuture> asyncCheckRoomPrices(PropertyAvailability propertyAvailability, int selectedRoomIndex, int selectedRateIndex) { - - PriceCheckOperationLink priceCheckLink = propertyAvailability.getRooms().get(selectedRoomIndex).getRates().get(selectedRateIndex).getBedGroups().entrySet() - .stream().findFirst().get().getValue().getLinks().getPriceCheck(); - - PriceCheckOperation operation = new PriceCheckOperation(priceCheckLink, null); - - return rapidClient.executeAsync(operation); - } - - public CompletableFuture> getPaymentOptions(RoomAvailability roomAvailability, RapidPartnerSalesProfile rapidPartnerSalesProfile) { - GetPaymentOptionsOperationLink paymentOptionsLink = roomAvailability.getRates().get(0).getLinks().getPaymentOptions(); - if (paymentOptionsLink == null) { - throw new IllegalStateException("No payment options link found for room: " + roomAvailability.getId()); - } - - return rapidClient.executeAsync(new GetPaymentOptionsOperation(paymentOptionsLink, new GetPaymentOptionsOperationContext())); - } -} \ No newline at end of file + return rapidClient.executeAsync(new GetPaymentOptionsOperation(paymentOptionsLink, + new GetPaymentOptionsOperationContext())); + } +}