Skip to content

Commit 950e950

Browse files
Add pageStart extension to case management pagination (#3656)
1 parent da842b8 commit 950e950

40 files changed

+203
-63
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75976,6 +75976,7 @@ paths:
7597675976
x-pagination:
7597775977
limitParam: page[size]
7597875978
pageParam: page[number]
75979+
pageStart: 1
7597975980
resultsPath: data
7598075981
post:
7598175982
description: Create a Case

.generator/src/generator/templates/Api.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public class {{ name }} {
148148
String valueGetterPath = "";
149149
String valueSetterPath = "{%- if getters|length > 1 %}{{ ".".join(getters[:getters|length-1]) }}.{%- endif %}{{ setters[getters|length-1] }}";
150150
Boolean valueSetterParamOptional = {{ optional|lower }};
151-
parameters.{% if getters|length > 1 %}{{ ".".join(getters[:getters|length-1]) }}.{%- endif %}{{ setters[getters|length-1] }}({{ 0|format_value(schema=paramSchema['schema']) }});
151+
parameters.{% if getters|length > 1 %}{{ ".".join(getters[:getters|length-1]) }}.{%- endif %}{{ setters[getters|length-1] }}({{ (pagination.pageStart | default(0))|format_value(schema=paramSchema['schema']) }});
152152
{%- endif %}
153153

154154
{#- Limit param field #}
@@ -205,7 +205,7 @@ public class {{ name }} {
205205
args.put("optionalParams", parameters);
206206
{%- endif %}
207207

208-
PaginationIterable iterator = new PaginationIterable(this, "{{ operationId }}", resultsPath, valueGetterPath, valueSetterPath, valueSetterParamOptional, {% if pagination.pageParam %}false{% else %}true{% endif %}, limit, args);
208+
PaginationIterable iterator = new PaginationIterable(this, "{{ operationId }}", resultsPath, valueGetterPath, valueSetterPath, valueSetterParamOptional, {% if pagination.pageParam %}false{% else %}true{% endif %}, limit, args, {{ pagination.pageStart | default(0) }});
209209

210210
return iterator;
211211
{%- endmacro %}

.generator/src/generator/templates/PaginationIterable.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class PaginationIterable<T> implements Iterable<T> {
1414
Boolean offsetPageIncrement;
1515
Object limit;
1616
LinkedHashMap<String, Object> args;
17+
int pageStart;
1718

1819
public PaginationIterable(
1920
Object requestClass,
@@ -24,7 +25,8 @@ public class PaginationIterable<T> implements Iterable<T> {
2425
Boolean valueSetterParamOptional,
2526
Boolean offsetPageIncrement,
2627
Object limit,
27-
LinkedHashMap<String, Object> args) {
28+
LinkedHashMap<String, Object> args,
29+
int pageStart) {
2830

2931
this.requestClass = requestClass;
3032
this.requestName = requestName;
@@ -41,6 +43,7 @@ public class PaginationIterable<T> implements Iterable<T> {
4143
this.offsetPageIncrement = offsetPageIncrement;
4244
this.limit = limit;
4345
this.args = args;
46+
this.pageStart = pageStart;
4447
}
4548

4649
@Override

.generator/src/generator/templates/PaginationIterator.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ public class PaginationIterator<T> implements Iterator<T> {
8080
value = value.getClass().getMethod(path).invoke(value);
8181
}
8282
} else {
83-
// fallback to pageOffset = totalCount;
83+
// fallback to pageOffset = pageStart + totalCount;
8484
// We cast the type based on the setterMethod parameter type
8585
String pType = setterMethod.getParameterTypes()[0].getSimpleName();
8686
if ("Long".equals(pType)) {
87-
value = (long) this.totalCount;
87+
value = (long) (this.iterable.pageStart + this.totalCount);
8888
} else {
89-
value = this.totalCount;
89+
value = this.iterable.pageStart + this.totalCount;
9090
}
9191
}
9292

examples/v2/case-management/SearchCases_3433960044.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.datadog.api.client.ApiClient;
44
import com.datadog.api.client.PaginationIterable;
55
import com.datadog.api.client.v2.api.CaseManagementApi;
6+
import com.datadog.api.client.v2.api.CaseManagementApi.SearchCasesOptionalParameters;
67
import com.datadog.api.client.v2.model.Case;
78

89
public class Example {
@@ -11,7 +12,9 @@ public static void main(String[] args) {
1112
CaseManagementApi apiInstance = new CaseManagementApi(defaultClient);
1213

1314
try {
14-
PaginationIterable<Case> iterable = apiInstance.searchCasesWithPagination();
15+
PaginationIterable<Case> iterable =
16+
apiInstance.searchCasesWithPagination(
17+
new SearchCasesOptionalParameters().pageSize(2L).filter("status:closed"));
1518

1619
for (Case item : iterable) {
1720
System.out.println(item);

src/main/java/com/datadog/api/client/PaginationIterable.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class PaginationIterable<T> implements Iterable<T> {
1818
Boolean offsetPageIncrement;
1919
Object limit;
2020
LinkedHashMap<String, Object> args;
21+
int pageStart;
2122

2223
public PaginationIterable(
2324
Object requestClass,
@@ -28,7 +29,8 @@ public PaginationIterable(
2829
Boolean valueSetterParamOptional,
2930
Boolean offsetPageIncrement,
3031
Object limit,
31-
LinkedHashMap<String, Object> args) {
32+
LinkedHashMap<String, Object> args,
33+
int pageStart) {
3234

3335
this.requestClass = requestClass;
3436
this.requestName = requestName;
@@ -45,6 +47,7 @@ public PaginationIterable(
4547
this.offsetPageIncrement = offsetPageIncrement;
4648
this.limit = limit;
4749
this.args = args;
50+
this.pageStart = pageStart;
4851
}
4952

5053
@Override

src/main/java/com/datadog/api/client/PaginationIterator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ private void setNextPageValue(Object response)
8585
value = value.getClass().getMethod(path).invoke(value);
8686
}
8787
} else {
88-
// fallback to pageOffset = totalCount;
88+
// fallback to pageOffset = pageStart + totalCount;
8989
// We cast the type based on the setterMethod parameter type
9090
String pType = setterMethod.getParameterTypes()[0].getSimpleName();
9191
if ("Long".equals(pType)) {
92-
value = (long) this.totalCount;
92+
value = (long) (this.iterable.pageStart + this.totalCount);
9393
} else {
94-
value = this.totalCount;
94+
value = this.iterable.pageStart + this.totalCount;
9595
}
9696
}
9797

src/main/java/com/datadog/api/client/v1/api/DashboardsApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,8 @@ public PaginationIterable<DashboardSummaryDefinition> listDashboardsWithPaginati
15441544
valueSetterParamOptional,
15451545
true,
15461546
limit,
1547-
args);
1547+
args,
1548+
0);
15481549

15491550
return iterator;
15501551
}

src/main/java/com/datadog/api/client/v1/api/MonitorsApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,8 @@ public PaginationIterable<Monitor> listMonitorsWithPagination(
13301330
valueSetterParamOptional,
13311331
false,
13321332
limit,
1333-
args);
1333+
args,
1334+
0);
13341335

13351336
return iterator;
13361337
}

src/main/java/com/datadog/api/client/v1/api/NotebooksApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,8 @@ public PaginationIterable<NotebooksResponseData> listNotebooksWithPagination(
691691
valueSetterParamOptional,
692692
true,
693693
limit,
694-
args);
694+
args,
695+
0);
695696

696697
return iterator;
697698
}

0 commit comments

Comments
 (0)