1414 * limitations under the License.
1515 */
1616
17- package com .expediagroup .sdk .xap .examples .scenarios .lodging . shopping . listings ;
17+ package com .expediagroup .sdk .xap .examples .scenarios .lodging ;
1818
19- import com .expediagroup .sdk .xap .examples .Constants ;
19+ import com .expediagroup .sdk .xap .examples .scenarios .XapScenario ;
20+ import com .expediagroup .sdk .xap .examples .services .LodgingService ;
2021import com .expediagroup .sdk .xap .models .Hotel ;
2122import com .expediagroup .sdk .xap .models .HotelListingsResponse ;
22- import com .expediagroup .sdk .xap .models .Room ;
2323import com .expediagroup .sdk .xap .models .RoomType ;
24- import com .expediagroup .sdk .xap .operations .GetLodgingListingsOperation ;
25- import com .expediagroup .sdk .xap .operations .GetLodgingListingsOperationParams ;
26- import java .time .LocalDate ;
27- import java .util .ArrayList ;
28- import java .util .Collections ;
2924import org .apache .commons .lang3 .StringUtils ;
3025import org .slf4j .Logger ;
3126import org .slf4j .LoggerFactory ;
3429 * This example demonstrates how to search for properties with a location keyword with filters
3530 * applied.
3631 */
37- public class ListingsQuickStartExample {
32+ public class GetListingsScenario implements XapScenario {
3833
39- private static final Logger LOGGER = LoggerFactory .getLogger (ListingsQuickStartExample .class );
34+ private static final Logger LOGGER = LoggerFactory .getLogger (GetListingsScenario .class );
4035
41- /**
42- * Summary: main function.
43- */
44- public static void main (String [] args ) {
45- LOGGER .info ("========== Start QuickStartExample ==========" );
36+ private final LodgingService lodgingService = new LodgingService ();
4637
38+ @ Override
39+ public void run () {
4740 // This example will search for properties with the following criteria:
4841 // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
4942 // in the second room;
@@ -53,58 +46,16 @@ public static void main(String[] args) {
5346 // 5. Limit the results to 5 properties;
5447 // 6. Order the results by price in ascending order.
5548
56- // Build the occupancy
57- ArrayList <Room > rooms = new ArrayList <>();
58- // The first room, with 1 adult
59- rooms .add (Room .builder ().adults (1L ).build ());
60- // The second room, with 2 adults and 2 children
61- ArrayList <Long > childrenAges = new ArrayList <>();
62- childrenAges .add (10L );
63- childrenAges .add (12L );
64- rooms .add (Room .builder ().adults (2L ).childAges (childrenAges ).build ());
49+ LOGGER .info (
50+ "============================= Running GetListingsScenario ============================" );
6551
66- // Build the query parameters with GetLodgingListingsOperationParams
67- GetLodgingListingsOperationParams getLodgingListingsOperationParams =
68- GetLodgingListingsOperationParams .builder ()
69- .partnerTransactionId (Constants .PARTNER_TRANSACTION_ID )
70- // The location keyword can be a city, address, airport or a landmark.
71- .locationKeyword ("Space Needle, Seattle" )
72- // The radius specifies the size of search area around the location keyword.
73- // The default value is 25.
74- .radius (10 )
75- // The unit specifies the unit of the radius. The default value is KM.
76- .unit (GetLodgingListingsOperationParams .Unit .KM )
77- // Check-in 5 days from now
78- .checkIn (LocalDate .now ().plusDays (5 ))
79- // Check-out 10 days from now
80- .checkOut (LocalDate .now ().plusDays (10 ))
81- // The occupancy
82- .rooms (rooms )
83- // The links to return, WEB includes WS (Web Search Result Page)
84- // and WD (Web Details Page)
85- .links (Collections .singletonList (GetLodgingListingsOperationParams .Links .WEB ))
86- // Limit the results to 5 properties
87- .limit (5 )
88- // Order the results by price in ascending order
89- .sortType (GetLodgingListingsOperationParams .SortType .PRICE )
90- .sortOrder (GetLodgingListingsOperationParams .SortOrder .ASC )
91- .build ();
52+ LOGGER .info (
53+ "======================== Executing GetLodgingListingsOperation =======================" );
9254
93- // Execute the operation and get the HotelListingsResponse
94- LOGGER .info ("========== Executing GetLodgingListingsOperation ==========" );
95- HotelListingsResponse hotelListingsResponse = Constants .XAP_CLIENT .execute (
96- new GetLodgingListingsOperation (getLodgingListingsOperationParams )).getData ();
97- // If you want to use the async method, you can use the following code:
98- // ---------------------------------------------------------------
99- // CompletableFuture<Response<HotelListingsResponse>> completableFuture =
100- // Constants.XAP_CLIENT.executeAsync(
101- // new GetLodgingListingsOperation(getLodgingListingsOperationParams));
102- // completableFuture.thenAccept(hotelListingsResponse -> {
103- // // Your code here
104- // });
105- // ---------------------------------------------------------------
55+ HotelListingsResponse hotelListingsResponse = lodgingService .getListings ();
10656
107- LOGGER .info ("========== GetLodgingListingsOperation Executed ==========" );
57+ LOGGER .info (
58+ "======================== GetLodgingListingsOperation Executed ========================" );
10859
10960 if (hotelListingsResponse == null || hotelListingsResponse .getHotels () == null
11061 || hotelListingsResponse .getHotels ().isEmpty ()) {
@@ -116,7 +67,8 @@ public static void main(String[] args) {
11667
11768 // To access the properties, iterate through the list of hotel properties
11869 hotelListingsResponse .getHotels ().forEach (hotel -> {
119- LOGGER .info ("========== Property Start ==========" );
70+ LOGGER .info (
71+ "=================================== Property Start ===================================" );
12072 // Check if the property is available
12173 if (Hotel .Status .AVAILABLE != hotel .getStatus ()) {
12274 LOGGER .info ("Property is not available." );
@@ -186,10 +138,11 @@ public static void main(String[] args) {
186138 }
187139 }
188140 }
189- LOGGER .info ("========== Property End ==========" );
141+ LOGGER .info (
142+ "==================================== Property End ====================================" );
190143 });
191144
192- LOGGER .info ("========== End QuickStartExample ==========" );
193- System . exit ( 0 );
145+ LOGGER .info (
146+ "=============================== End GetListingsScenario ==============================" );
194147 }
195148}
0 commit comments