Skip to content

Commit 2e6f5db

Browse files
author
Simon Jingzhe Huang
committed
chore: examples optimization
1 parent 5ed269a commit 2e6f5db

File tree

5 files changed

+60
-45
lines changed

5 files changed

+60
-45
lines changed

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Currently, the following scenarios are included:
3131
`AvailabilityCalendarsQuickStartScenario.java`](src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java):
3232

3333
This example demonstrates how to use Availability Calendar api with simple search.
34-
In terms of how to get property Ids, you can refer to `QuotesQuickStartScenario.java`.
34+
In terms of how to get property ids, you can refer to `QuotesQuickStartScenario.java`.
3535

3636
We are continuously adding more scenarios to demonstrate the usage of other XAP APIs.
3737

examples/src/main/java/com/expediagroup/sdk/xap/examples/XapSdkDemoTestRun.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.expediagroup.sdk.xap.examples;
1818

1919
import com.expediagroup.sdk.xap.examples.scenarios.lodging.AvailabilityCalendarsQuickStartScenario;
20+
import com.expediagroup.sdk.xap.examples.scenarios.lodging.ListingsHotelIdsSearchScenario;
2021
import com.expediagroup.sdk.xap.examples.scenarios.lodging.ListingsQuickStartScenario;
2122
import com.expediagroup.sdk.xap.examples.scenarios.lodging.QuotesQuickStartScenario;
2223
import org.slf4j.Logger;
@@ -44,6 +45,10 @@ public static void main(String[] args) {
4445
ListingsQuickStartScenario listingsQuickStartScenario = new ListingsQuickStartScenario();
4546
listingsQuickStartScenario.run();
4647

48+
ListingsHotelIdsSearchScenario listingsHotelIdsSearchScenario =
49+
new ListingsHotelIdsSearchScenario();
50+
listingsHotelIdsSearchScenario.run();
51+
4752
QuotesQuickStartScenario quotesQuickStartScenario = new QuotesQuickStartScenario();
4853
quotesQuickStartScenario.run();
4954

examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/**
2929
* This example demonstrates how to use Availability Calendar api with simple search.
30-
* In terms of how to get property Ids, you can refer to {@link QuotesQuickStartScenario}.
30+
* In terms of how to get property ids, you can refer to {@link QuotesQuickStartScenario}.
3131
*
3232
* <p>Note: this is a Vrbo scenario. You need a key that is enabled for Vrbo brand to run this.
3333
*/
@@ -58,7 +58,7 @@ public void run() {
5858
GetLodgingAvailabilityCalendarsOperationParams.builder()
5959
.partnerTransactionId(PARTNER_TRANSACTION_ID)
6060
// Set of Expedia Property IDs.
61-
.propertyIds(new HashSet<>(Arrays.asList("87704892", "12410858")))
61+
.propertyIds(new HashSet<>(Arrays.asList("87704892", "36960201")))
6262
.build();
6363

6464
XapClient xapClient = createClient();

examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsHotelIdsSearchScenario.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ public class ListingsHotelIdsSearchScenario implements XapScenario {
4646
LoggerFactory.getLogger(ListingsHotelIdsSearchScenario.class);
4747

4848
/**
49-
* The property count to read from the file.
50-
* If the first 20 properties are not available when you run this example, it may end with
51-
* NO_RESULT_FOUND. In that case, you can adjust the property count to get more properties.
49+
* This field limits the number of line to read from the SDP DownloadURL API Listings file to
50+
* reduce time to run the example.
51+
* If the first 20 properties from the file are not accessible OR available when you run this
52+
* example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
53+
* you can adjust the property count to get more properties.
5254
*/
53-
private static final int PROPERTY_COUNT = 20;
55+
private static final int SAMPLE_ITEMS_RESTRICTION = 20;
5456

5557
/**
5658
* A property id to location map. This mocks a cache in this example to store the static content
@@ -84,7 +86,7 @@ public void run() {
8486
*/
8587
private List<String> getPropertyIdsFromDownloadUrl() {
8688
LOGGER.info(
87-
"====================== Executing getPropertyIdsFromDownloadUrl =====================");
89+
"==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
8890

8991
GetFeedDownloadUrlOperationParams getPropertyIdListParams =
9092
GetFeedDownloadUrlOperationParams.builder()
@@ -120,7 +122,7 @@ private List<String> getPropertyIdsFromDownloadUrl() {
120122
LOGGER.info("Accessible Property Ids: {}", propertyIds);
121123

122124
LOGGER.info(
123-
"======================= getPropertyIdsFromDownloadUrl Executed ======================");
125+
"==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
124126
return propertyIds;
125127
}
126128

@@ -131,7 +133,7 @@ private List<String> getPropertyIdsFromDownloadUrl() {
131133
*/
132134
private void cachePropertyLocationFromDownloadUrl(List<String> propertyIds) {
133135
LOGGER.info(
134-
"====================== Executing CachePropertyLocationFromDownloadUrl ==================");
136+
"=============== Executing Step II: CachePropertyLocationFromDownloadUrl ================");
135137
GetFeedDownloadUrlOperationParams getPropertyLocationParams =
136138
GetFeedDownloadUrlOperationParams.builder()
137139
// Use the type LOCATIONS to get the address of accessible properties.
@@ -157,7 +159,7 @@ private void cachePropertyLocationFromDownloadUrl(List<String> propertyIds) {
157159
cachePropertyLocationFromLocationsFile(locationsDownloadUrl, propertyIds);
158160

159161
LOGGER.info(
160-
"===================== CachePropertyLocationFromDownloadUrl Executed ====================");
162+
"================ Step II: CachePropertyLocationFromDownloadUrl Executed ================");
161163
}
162164

163165
/**
@@ -168,7 +170,7 @@ private void cachePropertyLocationFromDownloadUrl(List<String> propertyIds) {
168170
*/
169171
private HotelListingsResponse getPropertyPriceFromLodgingListings(List<String> propertyIds) {
170172
LOGGER.info(
171-
"===================== Executing GetPropertyPriceFromLodgingListings ====================");
173+
"================ Step III: Executing GetPropertyPriceFromLodgingListings ===============");
172174

173175
GetLodgingListingsOperationParams getLodgingListingsOperationParams =
174176
GetLodgingListingsOperationParams.builder()
@@ -191,7 +193,7 @@ private HotelListingsResponse getPropertyPriceFromLodgingListings(List<String> p
191193
.getData();
192194

193195
LOGGER.info(
194-
"===================== GetPropertyPriceFromLodgingListings Executed ====================");
196+
"================ Step III: GetPropertyPriceFromLodgingListings Executed ================");
195197
return hotelListingsResponse;
196198
}
197199

@@ -219,15 +221,16 @@ private List<String> getPropertyIdsFromListingsFile(String downloadUrl) {
219221
try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
220222
String line;
221223
ObjectMapper objectMapper = new ObjectMapper();
222-
while ((line = reader.readLine()) != null && propertyIds.size() < PROPERTY_COUNT) {
224+
while ((line = reader.readLine()) != null
225+
&& propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
223226
// Parse the property id from the json object
224227
// An example json line from the jsonl file:
225228
/*
226229
{
227230
"propertyId": {
228-
"expedia": "75032362",
229-
"hcom": "2402035584",
230-
"vrbo": "731.2068610.2244521"
231+
"expedia": "1234567",
232+
"hcom": "123456789",
233+
"vrbo": "123.1234567.7654321"
231234
},
232235
"bookable": {
233236
"expedia": true,
@@ -310,24 +313,24 @@ private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
310313
/*
311314
{
312315
"propertyId": {
313-
"expedia": "75032362",
314-
"hcom": "2402035584",
315-
"vrbo": "731.2068610.2244521"
316+
"expedia": "1234567",
317+
"hcom": "123456789",
318+
"vrbo": "123.1234567.7654321"
316319
},
317320
"propertyType": {
318321
"id": 16,
319322
"name": "Apartment"
320323
},
321-
"propertyName": "Pasteur : Charming 2 bedroom flat near the thermal baths",
324+
"propertyName": "Expedia Property Name",
322325
"address1": "",
323326
"address2": "",
324327
"city": "Bains-les-Bains",
325328
"province": "Grand Est",
326329
"country": "France",
327330
"postalCode": "88240",
328331
"geoLocation": {
329-
"latitude": "48.003323",
330-
"longitude": "6.264765",
332+
"latitude": "10.999999",
333+
"longitude": "-10.999999",
331334
"obfuscated": false
332335
},
333336
"locationAttribute": {
@@ -382,6 +385,7 @@ private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
382385
* @param hotelListingsResponse The response of the Lodging Listings API.
383386
*/
384387
private static void displayResult(HotelListingsResponse hotelListingsResponse) {
388+
LOGGER.info("======================= Executing Step IV: DisplayResult =======================");
385389
if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null
386390
|| hotelListingsResponse.getHotels().isEmpty()) {
387391
throw new IllegalStateException("No properties found.");
@@ -426,5 +430,6 @@ private static void displayResult(HotelListingsResponse hotelListingsResponse) {
426430
LOGGER.info(
427431
"==================================== Property End ====================================");
428432
});
433+
LOGGER.info("======================= Step IV: DisplayResult Executed ========================");
429434
}
430435
}

examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ public class QuotesQuickStartScenario implements VrboScenario {
4949
LoggerFactory.getLogger(QuotesQuickStartScenario.class);
5050

5151
/**
52-
* The property count to read from the file.
53-
* If the first 20 properties are not available when you run this example, it may end with
54-
* NO_RESULT_FOUND. In that case, you can adjust the property count to get more properties.
52+
* This field limits the number of line to read from the SDP DownloadURL API Listings file to
53+
* reduce time to run the example.
54+
* If the first 20 properties from the file are not accessible OR available when you run this
55+
* example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
56+
* you can adjust the property count to get more properties.
5557
*/
56-
private static final int PROPERTY_COUNT = 20;
58+
private static final int SAMPLE_ITEMS_RESTRICTION = 20;
5759

5860
/**
5961
* A property id to location map. This mocks a cache in this example to store the static content
@@ -82,7 +84,7 @@ public void run() {
8284

8385
private List<String> getPropertyIdsFromDownloadUrl() {
8486
LOGGER.info(
85-
"====================== Executing getPropertyIdsFromDownloadUrl =====================");
87+
"==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
8688

8789
GetFeedDownloadUrlOperationParams getPropertyIdListParams =
8890
GetFeedDownloadUrlOperationParams.builder()
@@ -119,7 +121,7 @@ private List<String> getPropertyIdsFromDownloadUrl() {
119121
LOGGER.info("Accessible Vrbo Property Ids: {}", propertyIds);
120122

121123
LOGGER.info(
122-
"======================= getPropertyIdsFromDownloadUrl Executed ======================");
124+
"==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
123125
return propertyIds;
124126
}
125127

@@ -130,7 +132,7 @@ private List<String> getPropertyIdsFromDownloadUrl() {
130132
*/
131133
private void cachePropertyLocationFromDownloadUrl(List<String> propertyIds) {
132134
LOGGER.info(
133-
"====================== Executing CachePropertyLocationFromDownloadUrl ==================");
135+
"================ Executing Step II: CachePropertyLocationFromDownloadUrl ===============");
134136
GetFeedDownloadUrlOperationParams getPropertyLocationParams =
135137
GetFeedDownloadUrlOperationParams.builder()
136138
// Use the type LOCATIONS to get the address of accessible properties.
@@ -156,7 +158,7 @@ private void cachePropertyLocationFromDownloadUrl(List<String> propertyIds) {
156158
cachePropertyLocationFromLocationsFile(locationsDownloadUrl, propertyIds);
157159

158160
LOGGER.info(
159-
"===================== CachePropertyLocationFromDownloadUrl Executed ====================");
161+
"================= Step II: CachePropertyLocationFromDownloadUrl Executed ===============");
160162
}
161163

162164
/**
@@ -167,7 +169,7 @@ private void cachePropertyLocationFromDownloadUrl(List<String> propertyIds) {
167169
*/
168170
private LodgingQuotesResponse getPropertyPriceFromLodgingQuotes(List<String> propertyIds) {
169171
LOGGER.info(
170-
"====================== Executing GetPropertyPriceFromLodgingQuotes =====================");
172+
"================= Executing Step III: GetPropertyPriceFromLodgingQuotes ================");
171173

172174
// Build the occupancy
173175
ArrayList<Room> rooms = new ArrayList<>();
@@ -195,7 +197,7 @@ private LodgingQuotesResponse getPropertyPriceFromLodgingQuotes(List<String> pro
195197
.getData();
196198

197199
LOGGER.info(
198-
"====================== GetPropertyPriceFromLodgingQuotes Executed =====================");
200+
"================= Step III: GetPropertyPriceFromLodgingQuotes Executed =================");
199201
return lodgingQuotesResponse;
200202
}
201203

@@ -223,15 +225,16 @@ private List<String> getPropertyIdsFromVacationRentalFile(String downloadUrl) {
223225
try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
224226
String line;
225227
ObjectMapper objectMapper = new ObjectMapper();
226-
while ((line = reader.readLine()) != null && propertyIds.size() < PROPERTY_COUNT) {
228+
while ((line = reader.readLine()) != null
229+
&& propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
227230
// Parse the property id from the json object
228231
// An example json line from the jsonl file:
229232
/*
230233
{
231234
"propertyId": {
232-
"expedia": "75032362",
233-
"hcom": "2402035584",
234-
"vrbo": "731.2068610.2244521"
235+
"expedia": "1234567",
236+
"hcom": "987654321",
237+
"vrbo": "123.1234567.7654321"
235238
},
236239
"country": "France",
237240
"propertySize": {
@@ -320,24 +323,24 @@ private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
320323
/*
321324
{
322325
"propertyId": {
323-
"expedia": "108502000",
324-
"hcom": "3473064000",
325-
"vrbo": "321.4176310.4750480"
326+
"expedia": "1234567",
327+
"hcom": "987654321",
328+
"vrbo": "123.1234567.1234567"
326329
},
327330
"propertyType": {
328331
"id": 16,
329332
"name": "Apartment"
330333
},
331-
"propertyName": "Pine Brook 416 I Corporate 1.5Br Apartment ! Pool",
334+
"propertyName": "Vrbo Property Name",
332335
"address1": "",
333336
"address2": "",
334337
"city": "Newark",
335338
"province": "Delaware",
336339
"country": "United States",
337340
"postalCode": "19711",
338341
"geoLocation": {
339-
"latitude": "39.694889",
340-
"longitude": "-75.749393",
342+
"latitude": "10.999999",
343+
"longitude": "-10.999999",
341344
"obfuscated": false
342345
},
343346
"locationAttribute": {
@@ -403,6 +406,7 @@ private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
403406
* @param lodgingQuotesResponse The response of the Lodging Quotes API.
404407
*/
405408
private static void displayResult(LodgingQuotesResponse lodgingQuotesResponse) {
409+
LOGGER.info("======================= Executing Step IV: DisplayResult =======================");
406410
if (lodgingQuotesResponse == null || lodgingQuotesResponse.getProperties() == null
407411
|| lodgingQuotesResponse.getProperties().isEmpty()) {
408412
throw new IllegalStateException("No properties found.");
@@ -452,12 +456,12 @@ private static void displayResult(LodgingQuotesResponse lodgingQuotesResponse) {
452456
roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
453457
}
454458
if (roomType.getLinks() != null) {
455-
// To get the deeplink to the Expedia Web Search Result Page
459+
// To get the deeplink to the website Search Result Page
456460
if (roomType.getLinks().getWebSearchResult() != null) {
457461
LOGGER.info("WebSearchResult Link: {}",
458462
roomType.getLinks().getWebSearchResult().getHref());
459463
}
460-
// To get the deeplink to the Expedia Web Details Page
464+
// To get the deeplink to the website Details Page
461465
if (roomType.getLinks().getWebDetails() != null) {
462466
LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
463467
}
@@ -466,5 +470,6 @@ private static void displayResult(LodgingQuotesResponse lodgingQuotesResponse) {
466470
LOGGER.info(
467471
"==================================== Property End ====================================");
468472
});
473+
LOGGER.info("======================= Step IV: DisplayResult Executed ========================");
469474
}
470475
}

0 commit comments

Comments
 (0)