Skip to content

Commit b158614

Browse files
committed
Immutables Shared CF V3 Types
This change updates all of the types in shared CF V3 to use Immutables.
1 parent e8487b4 commit b158614

File tree

26 files changed

+605
-507
lines changed

26 files changed

+605
-507
lines changed

cloudfoundry-client-spring/src/main/java/org/cloudfoundry/reactor/client/v3/AbstractClientV3Operations.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.cloudfoundry.reactor.client.v3;
1818

1919
import com.fasterxml.jackson.databind.ObjectMapper;
20-
import org.cloudfoundry.Validatable;
2120
import org.cloudfoundry.reactor.client.CloudFoundryExceptionBuilder;
2221
import org.cloudfoundry.reactor.client.QueryBuilder;
2322
import org.cloudfoundry.reactor.util.AbstractReactorOperations;
@@ -41,37 +40,37 @@ protected AbstractClientV3Operations(AuthorizationProvider authorizationProvider
4140
super(authorizationProvider, httpClient, objectMapper, root);
4241
}
4342

44-
protected final <REQ extends Validatable, RSP> Mono<RSP> delete(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
43+
protected final <REQ, RSP> Mono<RSP> delete(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
4544
return doDelete(request, responseType, getUriAugmenter(uriTransformer), function((outbound, validRequest) -> outbound))
4645
.otherwise(ExceptionUtils.replace(HttpException.class, CloudFoundryExceptionBuilder::build));
4746
}
4847

49-
protected final <REQ extends Validatable, RSP> Mono<RSP> get(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
48+
protected final <REQ, RSP> Mono<RSP> get(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
5049
return doGet(request, responseType, getUriAugmenter(uriTransformer), function((outbound, validRequest) -> outbound))
5150
.otherwise(ExceptionUtils.replace(HttpException.class, CloudFoundryExceptionBuilder::build));
5251
}
5352

54-
protected final <REQ extends Validatable> Mono<HttpInbound> get(REQ request, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
53+
protected final <REQ> Mono<HttpInbound> get(REQ request, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
5554
return doGet(request, getUriAugmenter(uriTransformer), function((outbound, validRequest) -> outbound))
5655
.otherwise(ExceptionUtils.replace(HttpException.class, CloudFoundryExceptionBuilder::build));
5756
}
5857

59-
protected final <REQ extends Validatable, RSP> Mono<RSP> patch(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
58+
protected final <REQ, RSP> Mono<RSP> patch(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
6059
return doPatch(request, responseType, getUriAugmenter(uriTransformer), function((outbound, validRequest) -> outbound))
6160
.otherwise(ExceptionUtils.replace(HttpException.class, CloudFoundryExceptionBuilder::build));
6261
}
6362

64-
protected final <REQ extends Validatable, RSP> Mono<RSP> post(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
63+
protected final <REQ, RSP> Mono<RSP> post(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
6564
return doPost(request, responseType, getUriAugmenter(uriTransformer), function((outbound, validRequest) -> outbound))
6665
.otherwise(ExceptionUtils.replace(HttpException.class, CloudFoundryExceptionBuilder::build));
6766
}
6867

69-
protected final <REQ extends Validatable, RSP> Mono<RSP> put(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
68+
protected final <REQ, RSP> Mono<RSP> put(REQ request, Class<RSP> responseType, Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
7069
return doPut(request, responseType, getUriAugmenter(uriTransformer), function((outbound, validRequest) -> outbound))
7170
.otherwise(ExceptionUtils.replace(HttpException.class, CloudFoundryExceptionBuilder::build));
7271
}
7372

74-
private static <REQ extends Validatable> Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> getUriAugmenter(
73+
private static <REQ> Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> getUriAugmenter(
7574
Function<Tuple2<UriComponentsBuilder, REQ>, UriComponentsBuilder> uriTransformer) {
7675

7776
return function((builder, validRequest) -> {

cloudfoundry-client-spring/src/test/java/org/cloudfoundry/reactor/client/v3/applications/ReactorApplicationsV3Test.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.cloudfoundry.client.v3.applications.ListApplicationTasksResponse;
4848
import org.cloudfoundry.client.v3.applications.ListApplicationsRequest;
4949
import org.cloudfoundry.client.v3.applications.ListApplicationsResponse;
50+
import org.cloudfoundry.client.v3.applications.Relationships;
5051
import org.cloudfoundry.client.v3.applications.ScaleApplicationRequest;
5152
import org.cloudfoundry.client.v3.applications.ScaleApplicationResponse;
5253
import org.cloudfoundry.client.v3.applications.StartApplicationRequest;
@@ -58,8 +59,8 @@
5859
import org.cloudfoundry.client.v3.applications.UpdateApplicationResponse;
5960
import org.cloudfoundry.client.v3.processes.AbstractProcessStatistics.PortMapping;
6061
import org.cloudfoundry.client.v3.processes.HealthCheck;
61-
import org.cloudfoundry.client.v3.processes.Type;
6262
import org.cloudfoundry.client.v3.processes.ProcessUsage;
63+
import org.cloudfoundry.client.v3.processes.Type;
6364
import org.cloudfoundry.client.v3.tasks.Task;
6465
import org.cloudfoundry.client.v3.tasks.TaskResource;
6566
import org.cloudfoundry.reactor.InteractionContext;
@@ -251,12 +252,6 @@ protected InteractionContext getInteractionContext() {
251252
.build();
252253
}
253254

254-
@Override
255-
protected CreateApplicationRequest getInvalidRequest() {
256-
return CreateApplicationRequest
257-
.builder().build();
258-
}
259-
260255
@Override
261256
protected CreateApplicationResponse getResponse() {
262257
return CreateApplicationResponse.builder()
@@ -313,8 +308,10 @@ protected CreateApplicationRequest getValidRequest() throws Exception {
313308
.type("buildpack")
314309
.data("buildpack", "name-2443")
315310
.build())
316-
.relationship("space", Relationship.builder()
317-
.id("48989e6d-bb23-480d-94da-dae7c20e7af3")
311+
.relationships(Relationships.builder()
312+
.space(Relationship.builder()
313+
.id("48989e6d-bb23-480d-94da-dae7c20e7af3")
314+
.build())
318315
.build())
319316
.build();
320317
}

cloudfoundry-client-spring/src/test/java/org/cloudfoundry/reactor/client/v3/servicebindings/ReactorServiceBindingsV3Test.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
import org.cloudfoundry.client.v3.Link;
2020
import org.cloudfoundry.client.v3.Relationship;
2121
import org.cloudfoundry.client.v3.servicebindings.CreateServiceBindingRequest;
22-
import org.cloudfoundry.client.v3.servicebindings.CreateServiceBindingRequest.Relationships;
2322
import org.cloudfoundry.client.v3.servicebindings.CreateServiceBindingResponse;
23+
import org.cloudfoundry.client.v3.servicebindings.Data;
2424
import org.cloudfoundry.client.v3.servicebindings.DeleteServiceBindingRequest;
2525
import org.cloudfoundry.client.v3.servicebindings.GetServiceBindingRequest;
2626
import org.cloudfoundry.client.v3.servicebindings.GetServiceBindingResponse;
2727
import org.cloudfoundry.client.v3.servicebindings.ListServiceBindingsRequest;
2828
import org.cloudfoundry.client.v3.servicebindings.ListServiceBindingsResponse;
29+
import org.cloudfoundry.client.v3.servicebindings.Relationships;
2930
import org.cloudfoundry.reactor.InteractionContext;
3031
import org.cloudfoundry.reactor.TestRequest;
3132
import org.cloudfoundry.reactor.TestResponse;
@@ -63,12 +64,6 @@ protected InteractionContext getInteractionContext() {
6364
.build();
6465
}
6566

66-
@Override
67-
protected CreateServiceBindingRequest getInvalidRequest() {
68-
return CreateServiceBindingRequest.builder()
69-
.build();
70-
}
71-
7267
@Override
7368
protected CreateServiceBindingResponse getResponse() {
7469
return CreateServiceBindingResponse.builder()
@@ -92,7 +87,7 @@ protected CreateServiceBindingResponse getResponse() {
9287
@Override
9388
protected CreateServiceBindingRequest getValidRequest() throws Exception {
9489
return CreateServiceBindingRequest.builder()
95-
.data(CreateServiceBindingRequest.Data.builder()
90+
.data(Data.builder()
9691
.parameters(Collections.singletonMap("some_object_id", "for_the_service_broker"))
9792
.build())
9893
.relationships(Relationships.builder()

cloudfoundry-client/src/main/lombok/org/cloudfoundry/client/v3/Lifecycle.java renamed to cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/AbstractBuildpackData.java

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,25 @@
1717
package org.cloudfoundry.client.v3;
1818

1919
import com.fasterxml.jackson.annotation.JsonProperty;
20-
import lombok.Builder;
21-
import lombok.Data;
22-
import lombok.Getter;
23-
import lombok.Singular;
20+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import org.cloudfoundry.Nullable;
22+
import org.immutables.value.Value;
2423

25-
import java.util.Map;
26-
27-
/**
28-
* Represents the lifecycle of an application
29-
*/
30-
@Data
31-
public final class Lifecycle {
24+
@JsonDeserialize
25+
@Value.Immutable
26+
abstract class AbstractBuildpackData implements Data {
3227

3328
/**
34-
* The datas
35-
*
36-
* @param datas the datas
37-
* @return the datas
29+
* The buildpack
3830
*/
39-
@Getter(onMethod = @__(@JsonProperty("data")))
40-
private final Map<String, String> datas;
31+
@JsonProperty("buildpack")
32+
@Nullable
33+
abstract String getBuildpack();
4134

4235
/**
43-
* The type
44-
*
45-
* @param type the type
46-
* @return the type
36+
* The stack
4737
*/
48-
@Getter(onMethod = @__(@JsonProperty("type")))
49-
private final String type;
50-
51-
@Builder
52-
Lifecycle(@JsonProperty("data") @Singular Map<String, String> datas,
53-
@JsonProperty("type") String type) {
54-
this.datas = datas;
55-
this.type = type;
56-
}
38+
@JsonProperty("stack")
39+
abstract String getStack();
5740

5841
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3;
18+
19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20+
import org.immutables.value.Value;
21+
22+
/**
23+
* The data for a docker lifecycle
24+
*/
25+
@JsonDeserialize
26+
@Value.Immutable
27+
abstract class AbstractDockerData implements Data {
28+
29+
}

cloudfoundry-client/src/main/lombok/org/cloudfoundry/client/v3/Hash.java renamed to cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/AbstractHash.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,24 @@
1616

1717
package org.cloudfoundry.client.v3;
1818

19-
import com.fasterxml.jackson.annotation.JsonProperty;
20-
import lombok.Builder;
21-
import lombok.Data;
19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20+
import org.immutables.value.Value;
2221

2322
/**
2423
* A hash payload
2524
*/
26-
@Data
27-
public final class Hash {
25+
@JsonDeserialize
26+
@Value.Immutable
27+
abstract class AbstractHash {
2828

2929
/**
3030
* The type
31-
*
32-
* @param type the type
33-
* @return the type
3431
*/
35-
private final String type;
32+
abstract String getType();
3633

3734
/**
3835
* The value
39-
*
40-
* @param value the value
41-
* @return the value
4236
*/
43-
private final String value;
44-
45-
@Builder
46-
Hash(@JsonProperty("type") String type,
47-
@JsonProperty("value") String value) {
48-
this.type = type;
49-
this.value = value;
50-
}
37+
abstract String getValue();
5138

5239
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2013-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.core.JsonParser;
21+
import com.fasterxml.jackson.databind.DeserializationContext;
22+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
23+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
24+
import org.immutables.value.Value;
25+
26+
import java.io.IOException;
27+
28+
/**
29+
* Represents the lifecycle of an application
30+
*/
31+
@JsonDeserialize
32+
@Value.Immutable
33+
abstract class AbstractLifecycle {
34+
35+
/**
36+
* The datas
37+
*/
38+
@JsonDeserialize(using = DataDeserializer.class)
39+
@JsonProperty("data")
40+
abstract Data getData();
41+
42+
/**
43+
* The type
44+
*/
45+
@JsonProperty("type")
46+
abstract String getType();
47+
48+
static final class DataDeserializer extends StdDeserializer<Data> {
49+
50+
private static final long serialVersionUID = -8299189647244106624L;
51+
52+
DataDeserializer() {
53+
super(Data.class);
54+
}
55+
56+
@SuppressWarnings("deprecation")
57+
@Override
58+
public Data deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
59+
Lifecycle.Json lifecycle = (Lifecycle.Json) p.getParsingContext().getParent().getCurrentValue();
60+
61+
switch (lifecycle.type.toLowerCase()) {
62+
case "buildpack":
63+
return p.readValueAs(BuildpackData.class);
64+
case "docker":
65+
return p.readValueAs(DockerData.class);
66+
default:
67+
throw new IllegalArgumentException(String.format("Unknown lifecycle type: %s", lifecycle.type));
68+
}
69+
}
70+
}
71+
72+
}

cloudfoundry-client/src/main/lombok/org/cloudfoundry/client/v3/Link.java renamed to cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/AbstractLink.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,28 @@
1717
package org.cloudfoundry.client.v3;
1818

1919
import com.fasterxml.jackson.annotation.JsonProperty;
20-
import lombok.Builder;
21-
import lombok.Data;
20+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import org.cloudfoundry.Nullable;
22+
import org.immutables.value.Value;
2223

2324
/**
2425
* A link payload. By default it uses {@code GET} for the {@code method}
2526
*/
26-
@Data
27-
public final class Link {
27+
@JsonDeserialize
28+
@Value.Immutable
29+
abstract class AbstractLink {
2830

2931
/**
3032
* The href
31-
*
32-
* @param href the href
33-
* @return the href
3433
*/
35-
private final String href;
34+
@JsonProperty("href")
35+
abstract String getHref();
3636

3737
/**
3838
* The method
39-
*
40-
* @param method the method
41-
* @return the method
4239
*/
43-
private final String method;
44-
45-
@Builder
46-
Link(@JsonProperty("href") String href,
47-
@JsonProperty("method") String method) {
48-
this.href = href;
49-
this.method = method;
50-
}
40+
@JsonProperty("method")
41+
@Nullable
42+
abstract String getMethod();
5143

5244
}

0 commit comments

Comments
 (0)