Protect against possible NullPointerException when building collections

This commit is contained in:
Roy Clarkson
2019-03-29 10:20:33 -04:00
committed by Roy Clarkson
parent d9d81c5a75
commit 769d65f009
22 changed files with 325 additions and 155 deletions

View File

@@ -24,6 +24,9 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.springframework.util.CollectionUtils;
@SuppressWarnings("PMD.GodClass")
public class BackingApplication {
private static final String VALUE_HIDDEN = "<value hidden>";
@@ -36,26 +39,6 @@ public class BackingApplication {
private List<ParametersTransformerSpec> parametersTransformers;
private List<CredentialProviderSpec> credentialProviders;
public BackingApplication(BackingApplication backingApplicationToCopy) {
this.name = backingApplicationToCopy.name;
this.path = backingApplicationToCopy.path;
this.properties = backingApplicationToCopy.properties == null
? new HashMap<>()
: new HashMap<>(backingApplicationToCopy.properties);
this.environment = backingApplicationToCopy.environment == null
? new HashMap<>()
: new HashMap<>(backingApplicationToCopy.environment);
this.services = backingApplicationToCopy.services == null
? new ArrayList<>()
: backingApplicationToCopy.services.stream().map(ServicesSpec::new).collect(Collectors.toList());
this.parametersTransformers = backingApplicationToCopy.parametersTransformers == null
? new ArrayList<>()
: backingApplicationToCopy.parametersTransformers.stream().map(ParametersTransformerSpec::new).collect(Collectors.toList());
this.credentialProviders = backingApplicationToCopy.credentialProviders == null
? new ArrayList<>()
: backingApplicationToCopy.credentialProviders.stream().map(CredentialProviderSpec::new).collect(Collectors.toList());
}
private BackingApplication() {
}
@@ -193,16 +176,51 @@ public class BackingApplication {
public static class BackingApplicationBuilder {
private String name;
private String path;
private final Map<String, String> properties = new HashMap<>();
private final Map<String, Object> environment = new HashMap<>();
private final List<ServicesSpec> services = new ArrayList<>();
private final List<ParametersTransformerSpec> parameterTransformers = new ArrayList<>();
private final List<CredentialProviderSpec> credentialProviders = new ArrayList<>();
BackingApplicationBuilder() {
}
public BackingApplicationBuilder backingApplication(BackingApplication backingApplication) {
this.name(backingApplication.getName())
.path(backingApplication.getPath())
.properties(backingApplication.getProperties())
.environment(backingApplication.getEnvironment());
if (!CollectionUtils.isEmpty(backingApplication.getServices())) {
this.services(backingApplication.getServices().stream()
.map(spec -> ServicesSpec.builder()
.spec(spec)
.build())
.collect(Collectors.toList()));
}
if (!CollectionUtils.isEmpty(backingApplication.getParametersTransformers())) {
this.parameterTransformers(backingApplication.getParametersTransformers().stream()
.map(spec -> ParametersTransformerSpec.builder()
.spec(spec)
.build())
.collect(Collectors.toList()));
}
if (!CollectionUtils.isEmpty(backingApplication.getCredentialProviders())) {
this.credentialProviders(backingApplication.getCredentialProviders().stream()
.map(spec -> CredentialProviderSpec.builder()
.spec(spec)
.build())
.collect(Collectors.toList()));
}
return this;
}
public BackingApplicationBuilder name(String name) {
this.name = name;
return this;
@@ -214,37 +232,72 @@ public class BackingApplication {
}
public BackingApplicationBuilder property(String key, String value) {
this.properties.put(key, value);
if (key != null && value != null) {
this.properties.put(key, value);
}
return this;
}
public BackingApplicationBuilder properties(Map<String, String> properties) {
this.properties.putAll(properties);
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
return this;
}
public BackingApplicationBuilder environment(String key, String value) {
this.environment.put(key, value);
if (key != null && value != null) {
this.environment.put(key, value);
}
return this;
}
public BackingApplicationBuilder environment(Map<String, String> environment) {
this.environment.putAll(environment);
public BackingApplicationBuilder environment(Map<String, Object> environment) {
if (!CollectionUtils.isEmpty(environment)) {
this.environment.putAll(environment);
}
return this;
}
public BackingApplicationBuilder services(List<ServicesSpec> services) {
if (!CollectionUtils.isEmpty(services)) {
this.services.addAll(services);
}
return this;
}
public BackingApplicationBuilder services(ServicesSpec... services) {
this.services.addAll(Arrays.asList(services));
if (services != null) {
this.services(Arrays.asList(services));
}
return this;
}
public BackingApplicationBuilder parameterTransformers(List<ParametersTransformerSpec> parameterTransformers) {
if (!CollectionUtils.isEmpty(parameterTransformers)) {
this.parameterTransformers.addAll(parameterTransformers);
}
return this;
}
public BackingApplicationBuilder parameterTransformers(ParametersTransformerSpec... parameterTransformers) {
this.parameterTransformers.addAll(Arrays.asList(parameterTransformers));
if (parameterTransformers != null) {
this.parameterTransformers(Arrays.asList(parameterTransformers));
}
return this;
}
public BackingApplicationBuilder credentialProviders(List<CredentialProviderSpec> credentialProviders) {
if (!CollectionUtils.isEmpty(credentialProviders)) {
this.credentialProviders.addAll(credentialProviders);
}
return this;
}
public BackingApplicationBuilder credentialProviders(CredentialProviderSpec... credentialProviders) {
this.credentialProviders.addAll(Arrays.asList(credentialProviders));
if (credentialProviders != null) {
this.credentialProviders(Arrays.asList(credentialProviders));
}
return this;
}

View File

@@ -31,11 +31,6 @@ public class BackingApplications extends ArrayList<BackingApplication> {
super.addAll(backingApplications);
}
public BackingApplications(BackingApplications backingApplicationsToCopy) {
backingApplicationsToCopy.forEach(backingApplicationToCopy ->
this.add(new BackingApplication(backingApplicationToCopy)));
}
public static BackingApplicationsBuilder builder() {
return new BackingApplicationsBuilder();
}
@@ -44,13 +39,17 @@ public class BackingApplications extends ArrayList<BackingApplication> {
private final List<BackingApplication> backingApplications = new ArrayList<>();
public BackingApplicationsBuilder backingApplication(BackingApplication backingApplication) {
this.backingApplications.add(backingApplication);
if (backingApplication != null) {
this.backingApplications.add(backingApplication);
}
return this;
}
public BackingApplicationsBuilder backingApplications(List<BackingApplication> backingApplications) {
if (!CollectionUtils.isEmpty(backingApplications)) {
this.backingApplications.addAll(backingApplications);
backingApplications.forEach(backingApplication -> this.backingApplication(BackingApplication.builder()
.backingApplication(backingApplication)
.build()));
}
return this;
}

View File

@@ -23,6 +23,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.springframework.util.CollectionUtils;
public class BackingService {
private String serviceInstanceName;
@@ -52,22 +54,6 @@ public class BackingService {
this.rebindOnUpdate = rebindOnUpdate;
}
BackingService(BackingService backingServiceToCopy) {
this.serviceInstanceName = backingServiceToCopy.serviceInstanceName;
this.name = backingServiceToCopy.name;
this.plan = backingServiceToCopy.plan;
this.parameters = backingServiceToCopy.parameters == null
? new HashMap<>()
: new HashMap<>(backingServiceToCopy.parameters);
this.properties = backingServiceToCopy.properties == null
? new HashMap<>()
: new HashMap<>(backingServiceToCopy.properties);
this.parametersTransformers = backingServiceToCopy.parametersTransformers == null
? new ArrayList<>()
: new ArrayList<>(backingServiceToCopy.parametersTransformers);
this.rebindOnUpdate = backingServiceToCopy.rebindOnUpdate;
}
public String getServiceInstanceName() {
return serviceInstanceName;
}
@@ -171,14 +157,24 @@ public class BackingService {
private String serviceInstanceName;
private String name;
private String plan;
private Map<String, Object> parameters = new HashMap<>();
private Map<String, String> properties = new HashMap<>();
private final Map<String, Object> parameters = new HashMap<>();
private final Map<String, String> properties = new HashMap<>();
private final List<ParametersTransformerSpec> parameterTransformers = new ArrayList<>();
private boolean rebindOnUpdate;
BackingServiceBuilder() {
}
public BackingServiceBuilder backingService(BackingService backingService) {
return this.serviceInstanceName(backingService.getServiceInstanceName())
.name(backingService.getName())
.plan(backingService.getPlan())
.parameters(backingService.getParameters())
.properties(backingService.getProperties())
.parameterTransformers(backingService.getParametersTransformers())
.rebindOnUpdate(backingService.isRebindOnUpdate());
}
public BackingServiceBuilder serviceInstanceName(String serviceInstanceName) {
this.serviceInstanceName = serviceInstanceName;
return this;
@@ -195,17 +191,30 @@ public class BackingService {
}
public BackingServiceBuilder parameters(Map<String, Object> parameters) {
this.parameters = parameters;
if (!CollectionUtils.isEmpty(parameters)) {
this.parameters.putAll(parameters);
}
return this;
}
public BackingServiceBuilder properties(Map<String, String> properties) {
this.properties = properties;
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
return this;
}
public BackingServiceBuilder parameterTransformers(List<ParametersTransformerSpec> parameterTransformers) {
if (!CollectionUtils.isEmpty(parameterTransformers)) {
this.parameterTransformers.addAll(parameterTransformers);
}
return this;
}
public BackingServiceBuilder parameterTransformers(ParametersTransformerSpec... parameterTransformers) {
this.parameterTransformers.addAll(Arrays.asList(parameterTransformers));
if (parameterTransformers != null) {
this.parameterTransformers(Arrays.asList(parameterTransformers));
}
return this;
}

View File

@@ -19,6 +19,8 @@ package org.springframework.cloud.appbroker.deployer;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.CollectionUtils;
public class BackingServices extends ArrayList<BackingService> {
private static final long serialVersionUID = 1L;
@@ -30,11 +32,6 @@ public class BackingServices extends ArrayList<BackingService> {
super.addAll(backingServices);
}
public BackingServices(BackingServices backingServicesToCopy) {
backingServicesToCopy.forEach(backingServiceToCopy ->
this.add(new BackingService(backingServiceToCopy)));
}
public static BackingServicesBuilder builder() {
return new BackingServicesBuilder();
}
@@ -44,7 +41,18 @@ public class BackingServices extends ArrayList<BackingService> {
private final List<BackingService> backingServices = new ArrayList<>();
public BackingServicesBuilder backingService(BackingService backingService) {
this.backingServices.add(backingService);
if (backingService != null) {
this.backingServices.add(backingService);
}
return this;
}
public BackingServicesBuilder backingServices(BackingServices backingServices) {
if (!CollectionUtils.isEmpty(backingServices)) {
backingServices.forEach(backingService -> this.backingService(BackingService.builder()
.backingService(backingService)
.build()));
}
return this;
}

View File

@@ -18,6 +18,8 @@ package org.springframework.cloud.appbroker.deployer;
import java.util.Objects;
import org.springframework.util.CollectionUtils;
public class BrokeredService {
private String serviceName;
@@ -132,12 +134,20 @@ public class BrokeredService {
}
public BrokeredServiceBuilder apps(BackingApplications backingApplications) {
this.backingApplications = backingApplications;
if (!CollectionUtils.isEmpty(backingApplications)) {
this.backingApplications = BackingApplications.builder()
.backingApplications(backingApplications)
.build();
}
return this;
}
public BrokeredServiceBuilder services(BackingServices backingServices) {
this.backingServices = backingServices;
if (!CollectionUtils.isEmpty(backingServices)) {
this.backingServices = BackingServices.builder()
.backingServices(backingServices)
.build();
}
return this;
}

View File

@@ -19,6 +19,8 @@ package org.springframework.cloud.appbroker.deployer;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.CollectionUtils;
public class BrokeredServices extends ArrayList<BrokeredService> {
private static final long serialVersionUID = 6303127383252611352L;
@@ -37,7 +39,16 @@ public class BrokeredServices extends ArrayList<BrokeredService> {
private final List<BrokeredService> brokeredServices = new ArrayList<>();
public BrokeredServicesBuilder service(BrokeredService brokeredService) {
this.brokeredServices.add(brokeredService);
if (brokeredService != null) {
this.brokeredServices.add(brokeredService);
}
return this;
}
public BrokeredServicesBuilder services(BrokeredServices brokeredServices) {
if (!CollectionUtils.isEmpty(brokeredServices)) {
this.brokeredServices.addAll(brokeredServices);
}
return this;
}

View File

@@ -19,6 +19,8 @@ package org.springframework.cloud.appbroker.deployer;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class CredentialProviderSpec {
private String name;
@@ -32,11 +34,6 @@ public class CredentialProviderSpec {
this.args = args;
}
CredentialProviderSpec(CredentialProviderSpec credentialProviderSpecToClone) {
this.name = credentialProviderSpecToClone.name;
this.args = credentialProviderSpecToClone.args;
}
public String getName() {
return name;
}
@@ -60,23 +57,33 @@ public class CredentialProviderSpec {
public static class CredentialProviderSpecBuilder {
private String name;
private final Map<String, Object> args = new LinkedHashMap<>();
CredentialProviderSpecBuilder() {
}
public CredentialProviderSpecBuilder spec(CredentialProviderSpec spec) {
return this.name(spec.getName())
.args(spec.getArgs());
}
public CredentialProviderSpecBuilder name(String name) {
this.name = name;
return this;
}
public CredentialProviderSpecBuilder arg(String key, Object value) {
this.args.put(key, value);
if (key != null && value != null) {
this.args.put(key, value);
}
return this;
}
public CredentialProviderSpecBuilder args(Map<String, Object> args) {
this.args.putAll(args);
if (!CollectionUtils.isEmpty(args)) {
this.args.putAll(args);
}
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +19,12 @@ package org.springframework.cloud.appbroker.deployer;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class ParametersTransformerSpec {
private String name;
private Map<String, Object> args;
private ParametersTransformerSpec() {
@@ -31,11 +35,6 @@ public class ParametersTransformerSpec {
this.args = args;
}
ParametersTransformerSpec(ParametersTransformerSpec parametersTransformerSpecToClone) {
this.name = parametersTransformerSpecToClone.name;
this.args = parametersTransformerSpecToClone.args;
}
public String getName() {
return name;
}
@@ -57,24 +56,35 @@ public class ParametersTransformerSpec {
}
public static class ParametersTransformerSpecBuilder {
private String name;
private final Map<String, Object> args = new LinkedHashMap<>();
ParametersTransformerSpecBuilder() {
}
public ParametersTransformerSpecBuilder spec(ParametersTransformerSpec spec) {
return this.name(spec.getName())
.args(spec.getArgs());
}
public ParametersTransformerSpecBuilder name(String name) {
this.name = name;
return this;
}
public ParametersTransformerSpecBuilder arg(String key, Object value) {
this.args.put(key, value);
if (key != null && value != null) {
this.args.put(key, value);
}
return this;
}
public ParametersTransformerSpecBuilder args(Map<String, Object> args) {
this.args.putAll(args);
if (!CollectionUtils.isEmpty(args)) {
this.args.putAll(args);
}
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,10 +23,6 @@ public class ServicesSpec {
private ServicesSpec() {
}
ServicesSpec(ServicesSpec servicesSpecToClone) {
this.serviceInstanceName = servicesSpecToClone.serviceInstanceName;
}
ServicesSpec(String serviceInstanceName) {
this.serviceInstanceName = serviceInstanceName;
}
@@ -50,7 +46,11 @@ public class ServicesSpec {
ServicesSpecBuilder() {
}
ServicesSpecBuilder serviceInstanceName(String serviceInstanceName) {
public ServicesSpecBuilder spec(ServicesSpec spec) {
return this.serviceInstanceName(spec.getServiceInstanceName());
}
public ServicesSpecBuilder serviceInstanceName(String serviceInstanceName) {
this.serviceInstanceName = serviceInstanceName;
return this;
}

View File

@@ -27,10 +27,6 @@ public class TargetSpec {
this.name = name;
}
TargetSpec(TargetSpec targetSpecToClone) {
this.name = targetSpecToClone.name;
}
public String getName() {
return name;
}

View File

@@ -19,6 +19,8 @@ package org.springframework.cloud.appbroker.extensions.targets;
import java.util.HashMap;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class ArtifactDetails {
private final String name;
@@ -55,10 +57,9 @@ public class ArtifactDetails {
}
public ArtifactDetailsBuilder properties(Map<String, String> properties) {
if (properties == null) {
return this;
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
this.properties.putAll(properties);
return this;
}

View File

@@ -29,6 +29,7 @@ import org.springframework.cloud.appbroker.deployer.BrokeredServices;
import org.springframework.cloud.appbroker.deployer.TargetSpec;
import org.springframework.cloud.servicebroker.model.catalog.Plan;
import org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition;
import org.springframework.util.CollectionUtils;
class AppDeploymentInstanceWorkflow {
@@ -63,15 +64,25 @@ class AppDeploymentInstanceWorkflow {
private BackingApplications findBackingApplications(ServiceDefinition serviceDefinition,
Plan plan) {
BrokeredService brokeredService = findBrokeredService(serviceDefinition, plan);
return brokeredService == null ? null : new BackingApplications(brokeredService.getApps());
BackingApplications backingApplications = null;
if (brokeredService != null) {
backingApplications = BackingApplications.builder()
.backingApplications(brokeredService.getApps())
.build();
}
return backingApplications;
}
private BackingServices findBackingServices(ServiceDefinition serviceDefinition,
Plan plan) {
BrokeredService brokeredService = findBrokeredService(serviceDefinition, plan);
return brokeredService == null || brokeredService.getServices() == null
? null
: new BackingServices(brokeredService.getServices());
BackingServices backingServices = null;
if (brokeredService != null && !CollectionUtils.isEmpty(brokeredService.getServices())) {
backingServices = BackingServices.builder()
.backingServices(brokeredService.getServices())
.build();
}
return backingServices;
}
private BrokeredService findBrokeredService(ServiceDefinition serviceDefinition,

View File

@@ -135,7 +135,7 @@ class DeployerClientTest {
// given
setupAppDeployer();
Map<String, String> environment = new HashMap<String, String>() {{
Map<String, Object> environment = new HashMap<String, Object>() {{
put("ENV_VAR_1", "value1");
put("ENV_VAR_2", "value2");
}};
@@ -305,7 +305,7 @@ class DeployerClientTest {
private ArgumentMatcher<DeployApplicationRequest> matchesRequest(String appName, String appArchive,
Map<String, String> properties,
Map<String, String> environment,
Map<String, Object> environment,
List<String> services) {
return request ->
request.getName().equals(appName) &&

View File

@@ -19,6 +19,8 @@ package org.springframework.cloud.appbroker.deployer;
import java.util.HashMap;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class CreateServiceInstanceRequest {
private final String serviceInstanceName;
@@ -90,23 +92,23 @@ public class CreateServiceInstanceRequest {
}
public CreateServiceInstanceRequestBuilder parameters(String key, String value) {
this.parameters.put(key, value);
if (key != null && value != null) {
this.parameters.put(key, value);
}
return this;
}
public CreateServiceInstanceRequestBuilder parameters(Map<String, Object> parameters) {
if (parameters == null) {
return this;
if (!CollectionUtils.isEmpty(parameters)) {
this.parameters.putAll(parameters);
}
this.parameters.putAll(parameters);
return this;
}
public CreateServiceInstanceRequestBuilder properties(Map<String, String> properties) {
if (properties == null) {
return this;
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
this.properties.putAll(properties);
return this;
}

View File

@@ -16,8 +16,11 @@
package org.springframework.cloud.appbroker.deployer;
import java.util.HashMap;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class DeleteServiceInstanceRequest {
private final String serviceInstanceName;
@@ -43,7 +46,7 @@ public class DeleteServiceInstanceRequest {
public static class DeleteServiceInstanceRequestBuilder {
private String serviceInstanceName;
private Map<String, String> properties;
private final Map<String, String> properties = new HashMap<>();
DeleteServiceInstanceRequestBuilder() {
}
@@ -54,7 +57,9 @@ public class DeleteServiceInstanceRequest {
}
public DeleteServiceInstanceRequestBuilder properties(Map<String, String> properties) {
this.properties = properties;
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
return this;
}

View File

@@ -21,6 +21,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class DeployApplicationRequest {
private final String name;
@@ -97,38 +99,44 @@ public class DeployApplicationRequest {
}
public DeployApplicationRequestBuilder property(String key, String value) {
this.properties.put(key, value);
if (key != null && value != null) {
this.properties.put(key, value);
}
return this;
}
public DeployApplicationRequestBuilder properties(Map<String, String> properties) {
if (properties == null) {
return this;
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
this.properties.putAll(properties);
return this;
}
public DeployApplicationRequestBuilder environment(String key, String value) {
this.environment.put(key, value);
if (key != null && value != null) {
this.environment.put(key, value);
}
return this;
}
public DeployApplicationRequestBuilder environment(Map<String, Object> environment) {
if (environment == null) {
return this;
if (!CollectionUtils.isEmpty(environment)) {
this.environment.putAll(environment);
}
this.environment.putAll(environment);
return this;
}
public DeployApplicationRequestBuilder service(String service) {
this.services.add(service);
if (service != null) {
this.services.add(service);
}
return this;
}
public DeployApplicationRequestBuilder services(List<String> services) {
this.services.addAll(services);
if (!CollectionUtils.isEmpty(services)) {
this.services.addAll(services);
}
return this;
}

View File

@@ -16,8 +16,11 @@
package org.springframework.cloud.appbroker.deployer;
import java.util.HashMap;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class UndeployApplicationRequest {
private final String name;
@@ -43,7 +46,7 @@ public class UndeployApplicationRequest {
public static class UndeployApplicationRequestBuilder {
private String name;
private Map<String, String> properties;
private final Map<String, String> properties = new HashMap<>();
UndeployApplicationRequestBuilder() {
}
@@ -54,7 +57,9 @@ public class UndeployApplicationRequest {
}
public UndeployApplicationRequestBuilder properties(Map<String, String> properties) {
this.properties = properties;
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
return this;
}

View File

@@ -21,6 +21,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class UpdateApplicationRequest {
private final String name;
@@ -97,38 +99,44 @@ public class UpdateApplicationRequest {
}
public UpdateApplicationRequestBuilder property(String key, String value) {
this.properties.put(key, value);
if (key != null && value != null) {
this.properties.put(key, value);
}
return this;
}
public UpdateApplicationRequestBuilder properties(Map<String, String> properties) {
if (properties == null) {
return this;
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
this.properties.putAll(properties);
return this;
}
public UpdateApplicationRequestBuilder environment(String key, String value) {
this.environment.put(key, value);
if (key != null && value != null) {
this.environment.put(key, value);
}
return this;
}
public UpdateApplicationRequestBuilder environment(Map<String, Object> environment) {
if (environment == null) {
return this;
if (!CollectionUtils.isEmpty(environment)) {
this.environment.putAll(environment);
}
this.environment.putAll(environment);
return this;
}
public UpdateApplicationRequestBuilder service(String service) {
this.services.add(service);
if (service != null) {
this.services.add(service);
}
return this;
}
public UpdateApplicationRequestBuilder services(List<String> services) {
this.services.addAll(services);
if (!CollectionUtils.isEmpty(services)) {
this.services.addAll(services);
}
return this;
}

View File

@@ -19,6 +19,8 @@ package org.springframework.cloud.appbroker.deployer;
import java.util.HashMap;
import java.util.Map;
import org.springframework.util.CollectionUtils;
public class UpdateServiceInstanceRequest {
private final String serviceInstanceName;
@@ -72,23 +74,23 @@ public class UpdateServiceInstanceRequest {
}
public UpdateServiceInstanceRequestBuilder parameters(String key, String value) {
this.parameters.put(key, value);
if (key != null && value != null) {
this.parameters.put(key, value);
}
return this;
}
public UpdateServiceInstanceRequestBuilder parameters(Map<String, Object> parameters) {
if (parameters == null) {
return this;
if (!CollectionUtils.isEmpty(parameters)) {
this.parameters.putAll(parameters);
}
this.parameters.putAll(parameters);
return this;
}
public UpdateServiceInstanceRequestBuilder properties(Map<String, String> properties) {
if (properties == null) {
return this;
if (!CollectionUtils.isEmpty(properties)) {
this.properties.putAll(properties);
}
this.properties.putAll(properties);
return this;
}

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.appbroker.oauth2;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -124,9 +125,9 @@ public class CreateOAuth2ClientRequest {
private String clientId;
private String clientSecret;
private String clientName;
private List<String> scopes;
private List<String> authorities;
private List<String> grantTypes;
private final List<String> scopes = new ArrayList<>();
private final List<String> authorities = new ArrayList<>();
private final List<String> grantTypes = new ArrayList<>();
private String identityZoneSubdomain;
private String identityZoneId;
@@ -149,17 +150,23 @@ public class CreateOAuth2ClientRequest {
}
public CreateOAuth2ClientRequestBuilder scopes(String... scopes) {
this.scopes = Arrays.asList(scopes);
if (scopes != null) {
this.scopes.addAll(Arrays.asList(scopes));
}
return this;
}
public CreateOAuth2ClientRequestBuilder authorities(String... authorities) {
this.authorities = Arrays.asList(authorities);
if (authorities != null) {
this.authorities.addAll(Arrays.asList(authorities));
}
return this;
}
public CreateOAuth2ClientRequestBuilder grantTypes(String... grantTypes) {
this.grantTypes = Arrays.asList(grantTypes);
if (grantTypes != null) {
this.grantTypes.addAll(Arrays.asList(grantTypes));
}
return this;
}

View File

@@ -16,9 +16,12 @@
package org.springframework.cloud.appbroker.oauth2;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.springframework.util.CollectionUtils;
public class CreateOAuth2ClientResponse {
private final String clientId;
@@ -97,9 +100,9 @@ public class CreateOAuth2ClientResponse {
public static class CreateOAuth2ClientResponseBuilder {
private String clientId;
private String clientName;
private List<String> scopes;
private List<String> authorities;
private List<String> grantTypes;
private final List<String> scopes = new ArrayList<>();
private final List<String> authorities = new ArrayList<>();
private final List<String> grantTypes = new ArrayList<>();
CreateOAuth2ClientResponseBuilder() {
}
@@ -115,17 +118,23 @@ public class CreateOAuth2ClientResponse {
}
public CreateOAuth2ClientResponseBuilder scopes(List<String> scopes) {
this.scopes = scopes;
if (scopes != null) {
this.scopes.addAll(scopes);
}
return this;
}
public CreateOAuth2ClientResponseBuilder authorities(List<String> authorities) {
this.authorities = authorities;
if (!CollectionUtils.isEmpty(authorities)) {
this.authorities.addAll(authorities);
}
return this;
}
public CreateOAuth2ClientResponseBuilder grantTypes(List<String> grantTypes) {
this.grantTypes = grantTypes;
if (!CollectionUtils.isEmpty(grantTypes)) {
this.grantTypes.addAll(grantTypes);
}
return this;
}

View File

@@ -16,9 +16,12 @@
package org.springframework.cloud.appbroker.oauth2;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.springframework.util.CollectionUtils;
public class DeleteOAuth2ClientResponse {
private final String clientId;
private final String clientName;
@@ -95,9 +98,9 @@ public class DeleteOAuth2ClientResponse {
public static class DeleteOAuth2ClientResponseBuilder {
private String clientId;
private String clientName;
private List<String> scopes;
private List<String> authorities;
private List<String> grantTypes;
private final List<String> scopes = new ArrayList<>();
private final List<String> authorities = new ArrayList<>();
private final List<String> grantTypes = new ArrayList<>();
DeleteOAuth2ClientResponseBuilder() {
}
@@ -113,17 +116,23 @@ public class DeleteOAuth2ClientResponse {
}
public DeleteOAuth2ClientResponseBuilder scopes(List<String> scopes) {
this.scopes = scopes;
if (!CollectionUtils.isEmpty(scopes)) {
this.scopes.addAll(scopes);
}
return this;
}
public DeleteOAuth2ClientResponseBuilder authorities(List<String> authorities) {
this.authorities = authorities;
if (!CollectionUtils.isEmpty(authorities)) {
this.authorities.addAll(authorities);
}
return this;
}
public DeleteOAuth2ClientResponseBuilder grantTypes(List<String> grantTypes) {
this.grantTypes = grantTypes;
if (!CollectionUtils.isEmpty(grantTypes)) {
this.grantTypes.addAll(grantTypes);
}
return this;
}