question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pagination for Users/Groups

See original GitHub issue

I’m submitting a

  • feature request

Background info

I want to build pagination for Users/Groups on the UI, so in other words, I want to get any page, based on the page number. However, according to my understanding, the library provides wrappers i.e. users/groups - UserList, GroupList and these classes under the hood are using a custom implementation of Iterator ( called Page iterator), so they automatically obtain the next page based on the “Link” header during iteration.

So, to be able to get data from a particular page I need to use something like this: `final int SKIP_ELEMENTS = PAGE_LIMIT * PAGE_NUMBER;

final List<Group> groupList = client.getDataStore() .getResource(“/api/v1/groups?limit=” + PAGE_LIMIT, GroupList.class) .stream() .skip(SKIP_ELEMENTS) .limit(PAGE_LIMIT) .collect(Collectors.toList());`

So, my concern that to be able to get for example the third page, under the hood page iterator will obtain 2 previous pages and after that obtains the third. Am I right? and again when I try to obtain the fourth page, the iterating will start from scratch (from the first page)?

Expected behavior

to avoid obtain redundant elements (pages) and consider extending API to use page number.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
bdemerscommented, Mar 22, 2021

Hey @nmarshall23

This is untested, but It should provide more detail than my previous [mobile] message.

You will need to use the “Call other endpoints” technique to request each page.

So for the user endpoint, it should look something like this:


int pageSize = 10;

// For details on pagination params take a look at:
// https://developer.okta.com/docs/reference/api-overview/#pagination

UserList usersPage1 = client.http()
    .addQueryParameter("limit", pageSize)
    .get("/api/v1/users", UserList.class);

This would get you the first page, but when you iterate over the collection you would need to limit the stream, for example:

usersPage1.stream().limit(pageSize).forEach(user -> {
    log.debug("do something here", user);
})

To get the next page you would need to make a similar request as before, except change the to the “next page” URL (as @arvindkrishnakumar-okta mentioned it’s cursored, so you would need to remember this URL between page loads (if that applies to you)

Getting the URL should look something like this:

String nextPageUrl = usersPage1.getProperty("nextPage");

// now make another request using this URL:
UserList usersPage2 = client.http()
    .addQueryParameter("limit", pageSize)
    .get(nextPageUrl, UserList.class);

NOTE: you may need to cast usersPage1 to com.okta.sdk.impl.resource.AbstractCollectionResource This means you would need to change the scope of your dependency in your pom.xml (or gradle build) to a compile scope. We generally recommend against this, but assuming all of this works, we can make this more friendly in a future release (e.g. removing the cast and/or adding a getNextPageUrl() method.)

Once again, this is mostly from memory, and a little copy & pasting, so I didn’t test this out, please report back to us! If it works, we can move forward with a nicer fix for a future version, and if it doesn’t we will get you an actually tested code snippet 😄

0reactions
arvindkrishnakumar-oktacommented, Mar 29, 2021

Internal Ref: OKTA-382495

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination for Users/Groups - Okta Developer Community
Pagination for Users /Groups ... Hi there, I am using Okta SDK for java GitHub - okta/okta-sdk-java and I want to build page...
Read more >
Users' Pagination Preferences and "View All"
Pagination is a necessary evil when you have too many items to easily show them all on one screen. Linear content flows —...
Read more >
SCIM API pagination changes for Users and Groups | Slack
We're modernizing the GET /Users and GET /Groups methods of our SCIM user management API by putting a more reasonable upper bound on...
Read more >
Paginate By Group- FineReport Help Document
In pagination preview mode, FineReport will split the data beyond the page size to the next page, but this will cause the same...
Read more >
list-groups-for-user — CDP CLI 0.9.75 documentation
list-groups-for-user is a paginated operation. Multiple API calls may be issued in order to retrieve the entire data set of results.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found