4141import java .util .Map ;
4242import java .util .Objects ;
4343import lombok .Builder ;
44+ import lombok .extern .slf4j .Slf4j ;
4445
4546/**
4647 * Class representing the Fusion API, providing methods that correspond to available API endpoints
4748 */
49+ @ Slf4j
4850public class Fusion {
4951
5052 private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter .ofPattern ("yyyy-MM-dd" );
@@ -210,19 +212,27 @@ private Map<String, Map<String, Object>> callForMap(String url) {
210212 * @return aggregated JSON response containing all pages of data
211213 */
212214 private String callAPIWithPagination (String url , Integer pageSize ) {
215+ log .debug ("Starting paginated request to URL: {}" , url );
216+
213217 Map <String , String > headers = new HashMap <>();
214218 headers .put ("x-jpmc-paginate" , "true" );
215219 if (pageSize != null ) {
220+ log .debug ("Using page size: {}" , pageSize );
216221 headers .put ("x-jpmc-page-size" , String .valueOf (pageSize ));
217222 }
218223
219224 Gson gson = new Gson ();
220225 JsonArray aggregatedResources = new JsonArray ();
221226 String nextToken = null ;
227+ int pageCount = 0 ;
222228
223229 do {
230+ pageCount ++;
224231 if (nextToken != null ) {
225232 headers .put ("x-next-token" , nextToken );
233+ log .debug ("Fetching page {} with next token" , pageCount );
234+ } else {
235+ log .debug ("Fetching page {}" , pageCount );
226236 }
227237
228238 HttpResponse <String > response = this .api .callAPIWithResponse (url , headers );
@@ -231,13 +241,24 @@ private String callAPIWithPagination(String url, Integer pageSize) {
231241 JsonObject pageObject = JsonParser .parseString (pageJson ).getAsJsonObject ();
232242 if (pageObject .has ("resources" ) && pageObject .get ("resources" ).isJsonArray ()) {
233243 JsonArray pageResources = pageObject .getAsJsonArray ("resources" );
244+ int pageResourceCount = pageResources .size ();
234245 pageResources .forEach (aggregatedResources ::add );
246+ log .debug ("Retrieved {} resources from page {}" , pageResourceCount , pageCount );
235247 }
236248
237249 nextToken = getHeaderValue (response .getHeaders (), "x-next-token" );
238250
251+ if (nextToken != null && !nextToken .isEmpty ()) {
252+ log .debug ("Next token received, more pages available" );
253+ }
254+
239255 } while (nextToken != null && !nextToken .isEmpty ());
240256
257+ log .debug (
258+ "Pagination complete. Total pages fetched: {}, Total resources: {}" ,
259+ pageCount ,
260+ aggregatedResources .size ());
261+
241262 JsonObject result = new JsonObject ();
242263 result .add ("resources" , aggregatedResources );
243264 return gson .toJson (result );
@@ -348,7 +369,7 @@ public Map<String, DataProduct> listProducts() {
348369 */
349370 public Map <String , Dataset > listDatasets (String catalogName , String contains , boolean idContains ) {
350371 String url = String .format ("%1scatalogs/%2s/datasets" , this .rootURL , catalogName );
351- String json = callAPIWithPagination (url , null );
372+ String json = callAPIWithPagination (url , 500 );
352373 return filterDatasets (responseParser .parseDatasetResponse (json , catalogName ), contains , idContains );
353374 }
354375
0 commit comments