Pagination for Users/Groups
See original GitHub issueI’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:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
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:
This would get you the first page, but when you iterate over the collection you would need to limit the stream, for example:
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:
NOTE: you may need to cast
usersPage1
tocom.okta.sdk.impl.resource.AbstractCollectionResource
This means you would need to change the scope of your dependency in yourpom.xml
(or gradle build) to acompile
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 agetNextPageUrl()
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 😄
Internal Ref: OKTA-382495