Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 477f3f1

Browse files
ilayaperumalgericbottard
authored andcommitted
Fix app registry list by type
- When paging is enabled, the `list()` by type requires explicit paging Resolves #1571
1 parent ef9fbaa commit 477f3f1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/controller/AppRegistryController.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import java.util.ArrayList;
2424
import java.util.Arrays;
2525
import java.util.Collections;
26-
import java.util.Iterator;
2726
import java.util.List;
2827
import java.util.Properties;
2928
import java.util.concurrent.ForkJoinPool;
29+
import java.util.stream.Collectors;
3030

3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
@@ -108,13 +108,19 @@ public PagedResources<? extends AppRegistrationResource> list(
108108
Pageable pageable,
109109
PagedResourcesAssembler<AppRegistration> pagedResourcesAssembler,
110110
@RequestParam(value = "type", required = false) ApplicationType type) {
111+
Page<AppRegistration> pagedRegistrations;
112+
if (type == null) {
113+
pagedRegistrations = appRegistry.findAll(pageable);
114+
}
115+
else {
116+
List<AppRegistration> appRegistrations = appRegistry.findAll().stream()
117+
.filter(ar -> ar.getType() == type)
118+
.collect(Collectors.toList());
119+
long count = appRegistrations.size();
120+
long to = Math.min(count, pageable.getOffset() + pageable.getPageSize());
111121

112-
Page<AppRegistration> pagedRegistrations = appRegistry.findAll(pageable);
113-
for (Iterator<AppRegistration> iterator = pagedRegistrations.iterator(); iterator.hasNext();) {
114-
ApplicationType applicationType = iterator.next().getType();
115-
if (type != null && applicationType != type) {
116-
iterator.remove();
117-
}
122+
pagedRegistrations = new PageImpl<>(appRegistrations.subList(pageable.getOffset(), (int) to), pageable,
123+
appRegistrations.size());
118124
}
119125
return pagedResourcesAssembler.toResource(pagedRegistrations, this.assembler);
120126

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AppRegistryControllerTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ public void testListApplications() throws Exception {
147147
.andExpect(jsonPath("content", hasSize(4)));
148148
}
149149

150+
@Test
151+
public void testListApplicationsByType() throws Exception {
152+
mockMvc.perform(get("/apps?type=task").accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk())
153+
.andExpect(jsonPath("content", hasSize(1)));
154+
}
155+
150156
@Test
151157
public void testFindNonExistentApp() throws Exception {
152158
mockMvc.perform(get("/apps/source/foo").accept(MediaType.APPLICATION_JSON)).andDo(print())

0 commit comments

Comments
 (0)