Skip to content

Commit b5a5dbf

Browse files
committed
remove BaseFilter generic type. Refactor other filters
1 parent 14cab1d commit b5a5dbf

15 files changed

Lines changed: 443 additions & 37 deletions

src/main/java/com/auth0/client/mgmt/filter/BaseFilter.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,8 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6-
public abstract class BaseFilter<T extends BaseFilter> {
7-
protected Map<String, Object> parameters;
8-
9-
protected BaseFilter() {
10-
parameters = new HashMap<>();
11-
}
12-
13-
/**
14-
* Only retrieve certain fields from the item.
15-
*
16-
* @param fields a list of comma separated fields to retrieve.
17-
* @param includeFields whether to include or exclude in the response the fields that were given.
18-
* @return this filter instance
19-
*/
20-
public T withFields(String fields, boolean includeFields) {
21-
parameters.put("fields", fields);
22-
parameters.put("include_fields", includeFields);
23-
return (T) this;
24-
}
6+
public abstract class BaseFilter {
7+
protected Map<String, Object> parameters = new HashMap<>();
258

269
public Map<String, Object> getAsMap() {
2710
return parameters;

src/main/java/com/auth0/client/mgmt/filter/ConnectionFilter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Class used to filter the results received when calling the Connections endpoint. Related to the {@link com.auth0.client.mgmt.ConnectionsEntity()} entity.
55
*/
6-
public class ConnectionFilter extends BaseFilter<ConnectionFilter> {
6+
public class ConnectionFilter extends FieldsFilter {
77

88
/**
99
* Filter by strategy
@@ -40,4 +40,9 @@ public ConnectionFilter withPage(int pageNumber, int amountPerPage) {
4040
return this;
4141
}
4242

43+
@Override
44+
public ConnectionFilter withFields(String fields, boolean includeFields) {
45+
super.withFields(fields, includeFields);
46+
return this;
47+
}
4348
}

src/main/java/com/auth0/client/mgmt/filter/DeviceCredentialsFilter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Class used to filter the results received when calling the Device Credentials endpoint. Related to the {@link com.auth0.client.mgmt.DeviceCredentialsEntity()} entity.
55
*/
6-
public class DeviceCredentialsFilter extends BaseFilter<DeviceCredentialsFilter> {
6+
public class DeviceCredentialsFilter extends FieldsFilter {
77

88
/**
99
* Filter by user id
@@ -35,4 +35,9 @@ public DeviceCredentialsFilter withType(String type) {
3535
return this;
3636
}
3737

38+
@Override
39+
public DeviceCredentialsFilter withFields(String fields, boolean includeFields) {
40+
super.withFields(fields, includeFields);
41+
return this;
42+
}
3843
}

src/main/java/com/auth0/client/mgmt/filter/FieldsFilter.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,18 @@
33
/**
44
* Class used to filter the results received when calling an Auth0 endpoint.
55
*/
6-
public class FieldsFilter extends BaseFilter<FieldsFilter> {
6+
public class FieldsFilter extends BaseFilter {
7+
8+
/**
9+
* Only retrieve certain fields from the item.
10+
*
11+
* @param fields a list of comma separated fields to retrieve.
12+
* @param includeFields whether to include or exclude in the response the fields that were given.
13+
* @return this filter instance
14+
*/
15+
public FieldsFilter withFields(String fields, boolean includeFields) {
16+
parameters.put("fields", fields);
17+
parameters.put("include_fields", includeFields);
18+
return this;
19+
}
720
}

src/main/java/com/auth0/client/mgmt/filter/LogEventFilter.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Class used to filter the results received when calling the Logs endpoint. Related to the {@link com.auth0.client.mgmt.LogEventsEntity()} entity.
55
*/
6-
public class LogEventFilter extends QueryFilter<LogEventFilter> {
6+
public class LogEventFilter extends QueryFilter {
77

88
/**
99
* Filter by checkpoint
@@ -18,4 +18,33 @@ public LogEventFilter withCheckpoint(String from, int take) {
1818
return this;
1919
}
2020

21+
@Override
22+
public LogEventFilter withTotals(boolean includeTotals) {
23+
super.withTotals(includeTotals);
24+
return this;
25+
}
26+
27+
@Override
28+
public LogEventFilter withQuery(String query) {
29+
super.withQuery(query);
30+
return this;
31+
}
32+
33+
@Override
34+
public LogEventFilter withSort(String sort) {
35+
super.withSort(sort);
36+
return this;
37+
}
38+
39+
@Override
40+
public LogEventFilter withPage(int pageNumber, int amountPerPage) {
41+
super.withPage(pageNumber, amountPerPage);
42+
return this;
43+
}
44+
45+
@Override
46+
public LogEventFilter withFields(String fields, boolean includeFields) {
47+
super.withFields(fields, includeFields);
48+
return this;
49+
}
2150
}
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.auth0.client.mgmt.filter;
22

3-
public abstract class QueryFilter<T extends QueryFilter> extends BaseFilter<T> {
3+
public class QueryFilter extends FieldsFilter {
44

55
/**
66
* Filter by a query
77
*
88
* @param query the query expression using the following syntax https://auth0.com/docs/api/management/v2/query-string-syntax.
99
* @return this filter instance
1010
*/
11-
public T withQuery(String query) {
11+
public QueryFilter withQuery(String query) {
1212
parameters.put("q", query);
13-
return (T) this;
13+
return this;
1414
}
1515

1616
/**
@@ -19,9 +19,9 @@ public T withQuery(String query) {
1919
* @param includeTotals whether to include or not the query summary.
2020
* @return this filter instance
2121
*/
22-
public T withTotals(boolean includeTotals) {
22+
public QueryFilter withTotals(boolean includeTotals) {
2323
parameters.put("include_totals", includeTotals);
24-
return (T) this;
24+
return this;
2525
}
2626

2727
/**
@@ -30,9 +30,9 @@ public T withTotals(boolean includeTotals) {
3030
* @param sort the field to use for sorting. Use 'field:order' where order is 1 for ascending and -1 for descending.
3131
* @return this filter instance
3232
*/
33-
public T withSort(String sort) {
33+
public QueryFilter withSort(String sort) {
3434
parameters.put("sort", sort);
35-
return (T) this;
35+
return this;
3636
}
3737

3838
/**
@@ -42,10 +42,16 @@ public T withSort(String sort) {
4242
* @param amountPerPage the amount of items per page to retrieve.
4343
* @return this filter instance
4444
*/
45-
public T withPage(int pageNumber, int amountPerPage) {
45+
public QueryFilter withPage(int pageNumber, int amountPerPage) {
4646
parameters.put("page", pageNumber);
4747
parameters.put("per_page", amountPerPage);
48-
return (T) this;
48+
return this;
49+
}
50+
51+
@Override
52+
public QueryFilter withFields(String fields, boolean includeFields) {
53+
super.withFields(fields, includeFields);
54+
return this;
4955
}
5056

5157
}

src/main/java/com/auth0/client/mgmt/filter/RulesFilter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Class used to filter the results received when calling the Rules endpoint. Related to the {@link com.auth0.client.mgmt.RulesEntity()} entity.
55
*/
6-
public class RulesFilter extends BaseFilter<RulesFilter> {
6+
public class RulesFilter extends FieldsFilter {
77

88
/**
99
* Filter by enabled value
@@ -15,4 +15,9 @@ public RulesFilter withEnabled(boolean enabled) {
1515
return this;
1616
}
1717

18+
@Override
19+
public RulesFilter withFields(String fields, boolean includeFields) {
20+
super.withFields(fields, includeFields);
21+
return this;
22+
}
1823
}

src/main/java/com/auth0/client/mgmt/filter/UserFilter.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,42 @@
33
/**
44
* Class used to filter the results received when calling the Users endpoint. Related to the {@link com.auth0.client.mgmt.UsersEntity()} entity.
55
*/
6-
public class UserFilter extends QueryFilter<UserFilter> {
6+
public class UserFilter extends QueryFilter {
77

88
/**
99
* Creates a new instance using the search engine 'v2'.
1010
*/
1111
public UserFilter() {
1212
parameters.put("search_engine", "v2");
1313
}
14+
15+
@Override
16+
public UserFilter withTotals(boolean includeTotals) {
17+
super.withTotals(includeTotals);
18+
return this;
19+
}
20+
21+
@Override
22+
public UserFilter withQuery(String query) {
23+
super.withQuery(query);
24+
return this;
25+
}
26+
27+
@Override
28+
public UserFilter withSort(String sort) {
29+
super.withSort(sort);
30+
return this;
31+
}
32+
33+
@Override
34+
public UserFilter withPage(int pageNumber, int amountPerPage) {
35+
super.withPage(pageNumber, amountPerPage);
36+
return this;
37+
}
38+
39+
@Override
40+
public UserFilter withFields(String fields, boolean includeFields) {
41+
super.withFields(fields, includeFields);
42+
return this;
43+
}
1444
}

src/test/java/com/auth0/net/ConnectionFilterTest.java renamed to src/test/java/com/auth0/client/mgmt/filter/ConnectionFilterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.auth0.net;
1+
package com.auth0.client.mgmt.filter;
22

33
import com.auth0.client.mgmt.filter.ConnectionFilter;
44
import org.hamcrest.Matchers;

src/test/java/com/auth0/net/DeviceCredentialsFilterTest.java renamed to src/test/java/com/auth0/client/mgmt/filter/DeviceCredentialsFilterTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package com.auth0.net;
1+
package com.auth0.client.mgmt.filter;
22

3-
import com.auth0.client.mgmt.filter.DeviceCredentialsFilter;
43
import org.hamcrest.Matchers;
54
import org.junit.Before;
65
import org.junit.Test;

0 commit comments

Comments
 (0)