Skip to content

Commit e8487b4

Browse files
committed
Update Query Builder to handle collections
Previously the QueryBuilder would only work with arguments that were scalar values. This change updates the implementation to notice collections and render them as comma delimited strings.
1 parent d909d3a commit e8487b4

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

cloudfoundry-client-spring/src/main/java/org/cloudfoundry/reactor/client/QueryBuilder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import java.lang.reflect.Method;
2525
import java.util.Arrays;
26+
import java.util.Collection;
27+
import java.util.stream.Collectors;
2628

2729
/**
2830
* A builder for Cloud Foundry queries
@@ -52,7 +54,14 @@ public static void augment(UriComponentsBuilder builder, Object instance) {
5254
Object value = ReflectionUtils.invokeMethod(method, instance);
5355

5456
if (value != null) {
55-
builder.queryParam(queryParameter.value(), value);
57+
58+
if (value instanceof Collection) {
59+
builder.queryParam(queryParameter.value(), ((Collection<?>) value).stream()
60+
.map(Object::toString)
61+
.collect(Collectors.joining(",")));
62+
} else {
63+
builder.queryParam(queryParameter.value(), value);
64+
}
5665
}
5766
}
5867
}

cloudfoundry-client-spring/src/test/java/org/cloudfoundry/reactor/uaa/tokens/ReactorTokensTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ protected CheckTokenResponse getResponse() {
9797
protected CheckTokenRequest getValidRequest() {
9898
return CheckTokenRequest.builder()
9999
.token("f9f2f98d88e04ff7bb1f69041d3c0346")
100-
.scopes("password.write,scim.userids")
100+
.scope("password.write")
101+
.scope("scim.userids")
101102
.build();
102103
}
103104

cloudfoundry-client/src/main/java/org/cloudfoundry/uaa/tokens/AbstractCheckTokenRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.cloudfoundry.QueryParameter;
2121
import org.immutables.value.Value;
2222

23+
import java.util.List;
24+
2325
/**
2426
* The request payload for the check token operation
2527
*/
@@ -31,7 +33,7 @@ abstract class AbstractCheckTokenRequest {
3133
*/
3234
@QueryParameter("scopes")
3335
@Nullable
34-
abstract String getScopes();
36+
abstract List<String> getScopes();
3537

3638
/**
3739
* The token

0 commit comments

Comments
 (0)