@@ -332,14 +332,48 @@ public Map<String, Object> fetchAccessSettingsEnabledCoursesForCategory(String c
332332 req .put (Constants .FILTERS , filters );
333333 req .put (Constants .LIMIT , searchLimit );
334334 req .put (Constants .OFFSET , searchOffset );
335- List <String > fields = Collections .singletonList (Constants .IDENTIFIER );
336- req .put (Constants .FIELDS , fields );
335+ req .put (Constants .FIELDS , Collections .singletonList (Constants .IDENTIFIER ));
337336 reqBody .put (Constants .REQUEST , req );
338-
339337 Map <String , Object > compositeSearchRes = outboundRequestHandlerService .fetchResultUsingPost (
340- sbSearchServiceHost + sbCompositeV4Search , reqBody ,
341- null );
342-
338+ sbSearchServiceHost + sbCompositeV4Search , reqBody , null );
339+ if (MapUtils .isEmpty (compositeSearchRes )) {
340+ return compositeSearchRes ;
341+ }
342+ Map <String , Object > result = (Map <String , Object >) compositeSearchRes .get (Constants .RESULT );
343+ if (result == null || !result .containsKey (Constants .COUNT )) {
344+ return compositeSearchRes ;
345+ }
346+ int totalCount = ((Number ) result .get (Constants .COUNT )).intValue ();
347+ if (totalCount <= searchLimit ) {
348+ return compositeSearchRes ;
349+ }
350+ log .info ("Total count {} exceeds search limit {}. Fetching remaining pages..." , totalCount , searchLimit );
351+ List <Map <String , Object >> allContent = new ArrayList <>(totalCount );
352+ List <Map <String , Object >> initialContent = (List <Map <String , Object >>) result .get (Constants .CONTENT );
353+ if (initialContent != null ) {
354+ allContent .addAll (initialContent );
355+ }
356+ int currentOffset = searchLimit ;
357+ while (currentOffset < totalCount ) {
358+ req .put (Constants .OFFSET , currentOffset );
359+ Map <String , Object > nextPageRes = outboundRequestHandlerService .fetchResultUsingPost (
360+ sbSearchServiceHost + sbCompositeV4Search , reqBody , null );
361+
362+ if (MapUtils .isNotEmpty (nextPageRes )) {
363+ Map <String , Object > nextResult = (Map <String , Object >) nextPageRes .get (Constants .RESULT );
364+ if (nextResult != null ) {
365+ List <Map <String , Object >> nextContent = (List <Map <String , Object >>) nextResult .get (Constants .CONTENT );
366+ if (nextContent != null && !nextContent .isEmpty ()) {
367+ allContent .addAll (nextContent );
368+ } else {
369+ break ;
370+ }
371+ }
372+ }
373+ currentOffset += searchLimit ;
374+ }
375+ result .put (Constants .CONTENT , allContent );
376+ log .info ("Successfully fetched all {} items across multiple pages" , allContent .size ());
343377 return compositeSearchRes ;
344378 }
345379
0 commit comments