11package com .expediagroup .sdk .rapid .examples .services ;
22
3- import com .expediagroup .sdk .core .model .paging .Paginator ;
3+ import com .expediagroup .sdk .core .model .paging .ResponsePaginator ;
44import com .expediagroup .sdk .rapid .examples .Constants ;
55import com .expediagroup .sdk .rapid .examples .salesprofiles .RapidPartnerSalesProfile ;
66import com .expediagroup .sdk .rapid .models .Region ;
7+ import com .expediagroup .sdk .rapid .operations .GetRegionOperation ;
8+ import com .expediagroup .sdk .rapid .operations .GetRegionOperationParams ;
9+ import com .expediagroup .sdk .rapid .operations .GetRegionsOperation ;
10+ import com .expediagroup .sdk .rapid .operations .GetRegionsOperationParams ;
711import org .slf4j .Logger ;
812import org .slf4j .LoggerFactory ;
913
@@ -24,86 +28,69 @@ public class GeographyService extends RapidService {
2428
2529 public List <List <Region >> getAllRegionsWithDetails (RapidPartnerSalesProfile rapidPartnerSalesProfile ) {
2630
27- logger .info ("------------- Calling getRegionsPaginator with no ancestor ID and include=details to get all regions:" );
28- Paginator <List <Region >> paginator = rapidClient .getRegionsPaginator (
29- Arrays .asList ("details" ),
30- "en-US" ,
31- Constants .CUSTOMER_SESSION_ID ,
32- null ,
33- null ,
34- null ,
35- null ,
36- null ,
37- BigDecimal .valueOf (10 ),
38- "expedia" ,
39- Arrays .asList ("country" ),
40- rapidPartnerSalesProfile .billingTerms ,
41- rapidPartnerSalesProfile .paymentTerms ,
42- rapidPartnerSalesProfile .partnerPointOfSale ,
43- rapidPartnerSalesProfile .platformName
44- );
31+ logger .info ("------------- Calling getRegions paginated results with no ancestor ID and include=details to get all regions:" );
4532
46- List <List <Region >> pages = new ArrayList <>();
33+ GetRegionsOperationParams params = GetRegionsOperationParams .builder ()
34+ .include (Arrays .asList ("details" ))
35+ .language ("en-US" )
36+ .customerSessionId (Constants .CUSTOMER_SESSION_ID )
37+ .limit (BigDecimal .valueOf (10 ))
38+ .area ("50,37.227924,-93.310036" )
39+ .supplySource ("expedia" )
40+ .countryCode (Arrays .asList ("US" ))
41+ .build ();
42+
43+ ResponsePaginator <List <Region >> responsePaginator = rapidClient .getPaginator (new GetRegionsOperation (params ));
4744
48- logger . info ( "Paginator total results count: {}" , paginator . getPaginationTotalResults () );
45+ List < List < Region >> pages = new ArrayList <>( );
4946
50- while (paginator .hasNext ()) {
51- List <Region > page = paginator .next ();
52- pages .add (page );
47+ logger .info ("Paginator total results count: {}" , responsePaginator .getPaginationTotalResults ());
5348
54- break ; // remove to iterate over all pages.
55- }
49+ responsePaginator .forEachRemaining (page -> {
50+ pages .add (page .getData ());
51+ });
5652
5753 return pages ;
5854 }
5955
6056 public List <List <Region >> getRegionsByAncestor (String ancestorId , RapidPartnerSalesProfile rapidPartnerSalesProfile ) {
6157 logger .info ("------------- Calling getRegionsPaginator by ancestor ID: [{}]" , ancestorId );
62- Paginator <List <Region >> paginator = rapidClient .getRegionsPaginator (
63- Arrays .asList ("details" ),
64- "en-US" ,
65- Constants .CUSTOMER_SESSION_ID ,
66- ancestorId ,
67- null ,
68- null ,
69- null ,
70- null ,
71- BigDecimal .valueOf (10 ),
72- "expedia" ,
73- null ,
74- rapidPartnerSalesProfile .billingTerms ,
75- rapidPartnerSalesProfile .paymentTerms ,
76- rapidPartnerSalesProfile .partnerPointOfSale ,
77- rapidPartnerSalesProfile .platformName
78- );
58+
59+ GetRegionsOperationParams params = GetRegionsOperationParams .builder ()
60+ .include (Arrays .asList ("details" ))
61+ .language ("en-US" )
62+ .customerSessionId (Constants .CUSTOMER_SESSION_ID )
63+ .limit (BigDecimal .valueOf (10 ))
64+ .supplySource ("expedia" )
65+ .countryCode (Arrays .asList ("US" ))
66+ .ancestorId (ancestorId )
67+ .build ();
68+
69+ ResponsePaginator <List <Region >> responsePaginator = rapidClient .getPaginator (new GetRegionsOperation (params ));
7970
8071 List <List <Region >> pages = new ArrayList <>();
8172
82- while (paginator .hasNext ()) {
83- List <Region > page = paginator .next ();
84- pages .add (page );
73+ logger .info ("Paginator total results count: {}" , responsePaginator .getPaginationTotalResults ());
8574
86- break ; // remove to iterate over all pages.
87- }
75+ responsePaginator .forEachRemaining (page -> {
76+ pages .add (page .getData ());
77+ });
8878
8979 return pages ;
9080 }
9181
9282 public Region getRegionDetailsAndPropertyIds (String regionId , String language , RapidPartnerSalesProfile rapidPartnerSalesProfile ) {
9383 logger .info ("------------- Calling GetRegion:" );
94- Region region = rapidClient .getRegion (
95- regionId ,
96- language ,
97- Arrays .asList ("details" ,"property_ids" ),
98- Constants .CUSTOMER_SESSION_ID ,
99- rapidPartnerSalesProfile .billingTerms ,
100- rapidPartnerSalesProfile .paymentTerms ,
101- rapidPartnerSalesProfile .partnerPointOfSale ,
102- rapidPartnerSalesProfile .platformName ,
103- "expedia"
104- );
105-
106- return region ;
84+
85+ GetRegionOperationParams params = GetRegionOperationParams .builder ()
86+ .include (Arrays .asList ("details" , "property_ids" ))
87+ .language (language )
88+ .regionId (regionId )
89+ .customerSessionId (Constants .CUSTOMER_SESSION_ID )
90+ .supplySource ("expedia" )
91+ .build ();
92+
93+ return rapidClient .execute (new GetRegionOperation (params )).getData ();
10794 }
10895
10996}
0 commit comments