-
Notifications
You must be signed in to change notification settings - Fork 133
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
Support pagination on the Clients entity #124
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/auth0/client/mgmt/filter/ClientFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.auth0.client.mgmt.filter; | ||
|
||
/** | ||
* Class used to filter the results received when calling the Clients endpoint. Related to the {@link com.auth0.client.mgmt.ClientsEntity} entity. | ||
*/ | ||
public class ClientFilter extends FieldsFilter { | ||
|
||
/** | ||
* Include the query summary | ||
* | ||
* @param includeTotals whether to include or not the query summary. | ||
* @return this filter instance | ||
*/ | ||
public ClientFilter withTotals(boolean includeTotals) { | ||
parameters.put("include_totals", includeTotals); | ||
return this; | ||
} | ||
|
||
/** | ||
* Filter by page | ||
* | ||
* @param pageNumber the page number to retrieve. | ||
* @param amountPerPage the amount of items per page to retrieve. | ||
* @return this filter instance | ||
*/ | ||
public ClientFilter withPage(int pageNumber, int amountPerPage) { | ||
parameters.put("page", pageNumber); | ||
parameters.put("per_page", amountPerPage); | ||
return this; | ||
} | ||
|
||
/** | ||
* Filter by global clients | ||
* | ||
* @param isGlobal whether the client should or not be global | ||
* @return this filter instance | ||
*/ | ||
public ClientFilter withIsGlobal(boolean isGlobal) { | ||
parameters.put("is_global", isGlobal); | ||
return this; | ||
} | ||
|
||
/** | ||
* Filter by first party clients | ||
* | ||
* @param isFirstParty whether the client should or not be first party | ||
* @return this filter instance | ||
*/ | ||
public ClientFilter withIsFirstParty(boolean isFirstParty) { | ||
parameters.put("is_first_party", isFirstParty); | ||
return this; | ||
} | ||
|
||
/** | ||
* Filter by application type | ||
* | ||
* @param appType A comma separated list of application types used to filter the returned clients (native, spa, regular_web, non_interactive) | ||
* @return this filter instance | ||
*/ | ||
public ClientFilter withAppType(String appType) { | ||
parameters.put("app_type", appType); | ||
return this; | ||
} | ||
|
||
@Override | ||
public ClientFilter withFields(String fields, boolean includeFields) { | ||
super.withFields(fields, includeFields); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.auth0.json.mgmt; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.type.CollectionType; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public abstract class PageDeserializer<T, U> extends StdDeserializer<T> { | ||
|
||
private String itemsPropertyName; | ||
private Class<U> uClazz; | ||
|
||
protected PageDeserializer(Class<U> clazz, String arrayName) { | ||
super(Object.class); | ||
this.uClazz = clazz; | ||
this.itemsPropertyName = arrayName; | ||
} | ||
|
||
@Override | ||
public T deserialize(JsonParser p, DeserializationContext ctx) throws IOException { | ||
JsonNode node = p.getCodec().readTree(p); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
if (node.isArray()) { | ||
return createPage(getArrayElements((ArrayNode) node, mapper)); | ||
} | ||
|
||
Integer start = getIntegerValue(node.get("start")); | ||
Integer length = getIntegerValue(node.get("length")); | ||
Integer total = getIntegerValue(node.get("total")); | ||
Integer limit = getIntegerValue(node.get("limit")); | ||
ArrayNode array = (ArrayNode) node.get(itemsPropertyName); | ||
|
||
return createPage(start, length, total, limit, getArrayElements(array, mapper)); | ||
} | ||
|
||
protected abstract T createPage(List<U> items); | ||
|
||
protected abstract T createPage(Integer start, Integer length, Integer total, Integer limit, List<U> items); | ||
|
||
private Integer getIntegerValue(JsonNode node) { | ||
if (node == null || node.isNull()) { | ||
return null; | ||
} else { | ||
return node.intValue(); | ||
} | ||
} | ||
|
||
private List<U> getArrayElements(ArrayNode array, ObjectMapper mapper) throws IOException { | ||
CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, uClazz); | ||
return mapper.readerFor(type).readValue(array); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.auth0.json.mgmt.client; | ||
|
||
import com.auth0.json.mgmt.Page; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Class that represents a given page of Clients. Related to the {@link com.auth0.client.mgmt.ClientsEntity} entity. | ||
*/ | ||
@SuppressWarnings({"unused", "WeakerAccess"}) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonDeserialize(using = ClientsPageDeserializer.class) | ||
public class ClientsPage extends Page<Client> { | ||
|
||
public ClientsPage(List<Client> items) { | ||
super(items); | ||
} | ||
|
||
public ClientsPage(Integer start, Integer length, Integer total, Integer limit, List<Client> items) { | ||
super(start, length, total, limit, items); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/auth0/json/mgmt/client/ClientsPageDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.auth0.json.mgmt.client; | ||
|
||
import com.auth0.json.mgmt.PageDeserializer; | ||
|
||
import java.util.List; | ||
|
||
@SuppressWarnings({"unused", "WeakerAccess"}) | ||
class ClientsPageDeserializer extends PageDeserializer<ClientsPage, Client> { | ||
|
||
ClientsPageDeserializer() { | ||
super(Client.class, "clients"); | ||
} | ||
|
||
@Override | ||
protected ClientsPage createPage(List<Client> items) { | ||
return new ClientsPage(items); | ||
} | ||
|
||
@Override | ||
protected ClientsPage createPage(Integer start, Integer length, Integer total, Integer limit, List<Client> items) { | ||
return new ClientsPage(start, length, total, limit, items); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 9 additions & 40 deletions
49
src/main/java/com/auth0/json/mgmt/logevents/LogEventsPageDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,23 @@ | ||
package com.auth0.json.mgmt.logevents; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.type.CollectionType; | ||
import com.auth0.json.mgmt.PageDeserializer; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@SuppressWarnings({"unused", "WeakerAccess"}) | ||
class LogEventsPageDeserializer extends StdDeserializer<LogEventsPage> { | ||
LogEventsPageDeserializer(JavaType valueType) { | ||
super(valueType); | ||
} | ||
class LogEventsPageDeserializer extends PageDeserializer<LogEventsPage, LogEvent> { | ||
|
||
LogEventsPageDeserializer() { | ||
this(null); | ||
protected LogEventsPageDeserializer() { | ||
super(LogEvent.class, "logs"); | ||
} | ||
|
||
@Override | ||
public LogEventsPage deserialize(JsonParser p, DeserializationContext ctx) throws IOException { | ||
JsonNode node = p.getCodec().readTree(p); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
if (node.isArray()) { | ||
return new LogEventsPage(getArrayElements((ArrayNode) node, mapper)); | ||
} | ||
|
||
Integer start = getIntegerValue(node.get("start")); | ||
Integer length = getIntegerValue(node.get("length")); | ||
Integer total = getIntegerValue(node.get("total")); | ||
Integer limit = getIntegerValue(node.get("limit")); | ||
ArrayNode array = (ArrayNode) node.get("logs"); | ||
|
||
return new LogEventsPage(start, length, total, limit, getArrayElements(array, mapper)); | ||
protected LogEventsPage createPage(List<LogEvent> items) { | ||
return new LogEventsPage(items); | ||
} | ||
|
||
private Integer getIntegerValue(JsonNode node) { | ||
if (node == null || node.isNull()) { | ||
return null; | ||
} else { | ||
return node.intValue(); | ||
} | ||
} | ||
|
||
private List<LogEvent> getArrayElements(ArrayNode array, ObjectMapper mapper) throws IOException { | ||
CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, LogEvent.class); | ||
return mapper.readerFor(type).readValue(array); | ||
@Override | ||
protected LogEventsPage createPage(Integer start, Integer length, Integer total, Integer limit, List<LogEvent> items) { | ||
return new LogEventsPage(start, length, total, limit, items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 8 additions & 38 deletions
46
src/main/java/com/auth0/json/mgmt/users/UsersPageDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,24 @@ | ||
package com.auth0.json.mgmt.users; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.type.CollectionType; | ||
import com.auth0.json.mgmt.PageDeserializer; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@SuppressWarnings({"unused", "WeakerAccess"}) | ||
class UsersPageDeserializer extends StdDeserializer<UsersPage> { | ||
UsersPageDeserializer(JavaType valueType) { | ||
super(valueType); | ||
} | ||
class UsersPageDeserializer extends PageDeserializer<UsersPage, User> { | ||
|
||
UsersPageDeserializer() { | ||
this(null); | ||
super(User.class, "users"); | ||
} | ||
|
||
@Override | ||
public UsersPage deserialize(JsonParser p, DeserializationContext ctx) throws IOException { | ||
JsonNode node = p.getCodec().readTree(p); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
if (node.isArray()) { | ||
return new UsersPage(getArrayElements((ArrayNode) node, mapper)); | ||
} | ||
|
||
Integer start = getIntegerValue(node.get("start")); | ||
Integer length = getIntegerValue(node.get("length")); | ||
Integer total = getIntegerValue(node.get("total")); | ||
Integer limit = getIntegerValue(node.get("limit")); | ||
ArrayNode array = (ArrayNode) node.get("users"); | ||
|
||
return new UsersPage(start, length, total, limit, getArrayElements(array, mapper)); | ||
protected UsersPage createPage(List<User> items) { | ||
return new UsersPage(items); | ||
} | ||
|
||
private Integer getIntegerValue(JsonNode node) { | ||
if (node == null || node.isNull()) { | ||
return null; | ||
} else { | ||
return node.intValue(); | ||
} | ||
@Override | ||
protected UsersPage createPage(Integer start, Integer length, Integer total, Integer limit, List<User> items) { | ||
return new UsersPage(start, length, total, limit, items); | ||
} | ||
|
||
private List<User> getArrayElements(ArrayNode array, ObjectMapper mapper) throws IOException { | ||
CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, User.class); | ||
return mapper.readerFor(type).readValue(array); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this logical? If you pick fields surely you would want to include them? Otherwise why include them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cocojoe a Client has a huge number of properties. The endpoint accepts a
fields
value so you can filter them. When you pass a list of fields, you can also say whether you want those fields included (whitelist) or excluded (blacklist) from the response.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok, that makes more sense, I miss interpreted it 👍