-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pagination is not automatic #787
Comments
btw, where is the source code for EDIT:
which, for some reason, isn't indented: okta-sdk-java/api/src/main/resources/custom_templates/api.mustache Lines 374 to 397 in 8be490d
|
these 2 lines from the mustache template ^^^ look problematic. what if the url itself contains "next" or "self"? if (link.contains("next")) {
// ...
if (link.contains("self")) { eg, this fetches the same url over and over again in an endless loop: String filter = "profile.lastName eq \"next\""; something like this would be more robust if (link.contains("rel=\"next\"")) {
// ...
if (link.contains("rel=\"self\"")) { |
actually, ^^^ is really redundant, also, too, as well. why not something like this: PagedList pagedList = new PagedList();
pagedList.addItems(Arrays.asList(responseEntity.getBody()));
HttpHeaders headers = responseEntity.getHeaders();
List<String> linkHeaders = headers.get("link");
for (String link : linkHeaders) {
String[] parts = link.split("; *");
String url = parts[0]
.replaceAll("<", "")
.replaceAll(">", "");
String rel = parts[1];
if (rel.equals("rel=\"next\"")) {
pagedList.setNextPage(url);
} else if (rel.equals("rel=\"self\"")) {
pagedList.setSelf(url);
}
}
return pagedList; again, i'm not a Java programmer, so there might be a better (or more idiomatic) way to write this. EDIT:
|
@gabrielsroka thanks for posting! Apologies for the delayed response. Let me review this in detail and get back to you shortly. |
or, use a regex to parse the link header import java.util.regex.Matcher;
import java.util.regex.Pattern;
// ...
String pattern = "<(.*)>; *rel=\"(.*)\"";
Pattern r = Pattern.compile(pattern);
// ...
for (String link : linkHeaders) {
Matcher m = r.matcher(link);
if (m.find()) {
String url = m.group(1);
String rel = m.group(2);
if (rel.equals("next")) {
pagedList.setNextPage(url);
} else if (rel.equals("self")) {
pagedList.setSelf(url);
}
}
} |
@gabrielsroka Thanks for your suggestions! I did review the present pagination implementation and realized that the templates need to be reworked to omit redundant code. Your suggestions are noted and will be factored (fixed) in the next revision. |
@gabrielsroka merged PR to master, will cut a release soon. Please check it out and reopen this issue or open a new one if needed. |
Released 10.2.0 |
I was reading through the doc as well and it is not clear if the SDK does go through all pages automatically. In the example of the doc it says "Loop through all of them". What does that mean? All of them in the first page or all of them as in all existing users?
Let's say there are 10 existing users. Then, is the expected output two info logs (one for each of the 2 users in page 1 because limit is set to 2 users per page) or is it 10 info logs (i.e pagination is done automatically)? |
@sdrissi my expectation/understanding is that it should give you all users. that said, it was broken in 10.0, but should be fixed in 10.2. did you try it? (i have not) @arvindkrishnakumar-okta , keep me honest here... |
@gabrielsroka thanks for your reply. I did not try it yet. Would be great if @arvindkrishnakumar-okta could validate that this is the expected behavior. Will let you know once I upgrade to 10.2. |
Describe the bug?
i was able to get this working, but i don't know if it's correct. is there a better/shorter way? does the SDK do some of this for me? (i'm not a Java programmer.)
https://replit.com/@gabrielsroka/okta-sdk-java#Main.java
parts of ^^ were stolen from
okta-sdk-java/integration-tests/src/test/groovy/com/okta/sdk/tests/it/UsersIT.groovy
Lines 874 to 880 in cb0a648
after
below should be the 2nd argument, not the 1st:okta-sdk-java/README.md
Lines 423 to 427 in cb0a648
same with
okta-sdk-java/examples/quickstart/src/main/java/quickstart/ReadmeSnippets.java
Lines 282 to 286 in cb0a648
q
to paginate users or groups, because the API doesn't return link headers when usingq
, so this:returns this exception
Note that apps, authorizationServers, idps, logs, etc. do return link headers with
q
, but users, groups, etc. don't.okta-sdk-java/README.md
Lines 184 to 185 in cb0a648
same with
okta-sdk-java/examples/quickstart/src/main/java/quickstart/ReadmeSnippets.java
Lines 103 to 104 in cb0a648
it'd need to be one of these:
What is expected to happen?
automatic pagination
What is the actual behavior?
it doesn't paginate. i had to write the code to figure out
after
and add the loop.Reproduction Steps?
see above
Additional Information?
No response
Java Version
openjdk version "17.0.3"
SDK Version
10.0
OS version
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
The text was updated successfully, but these errors were encountered: