From aee254244afccec3df33f8684d1d9e9ba36b2dbd Mon Sep 17 00:00:00 2001 From: Fabian Nonnenmacher Date: Mon, 1 Feb 2016 15:31:56 +0100 Subject: [PATCH] Smaller Improvements of configuration REST-API * changed resource path to "rest/v1/system/configs" * added links to resources, to follow good practice recommendations * added GET methode for parent resource system/configs * fade out null values in json * marked some json properties as mandatory TMP Signed-off-by: Nonnenmacher Fabian --- .../TenantConfigurationValueRequest.java | 4 +-- .../system/TenantConfigurationValueRest.java | 14 +++++++++- .../hawkbit/rest/resource/SystemMapper.java | 10 +++++-- .../hawkbit/rest/resource/SystemResource.java | 27 +++++++++++++------ ...yTokenAuthenticationConfigurationItem.java | 3 +-- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationValueRequest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationValueRequest.java index f6be11c51..91a8820f1 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationValueRequest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationValueRequest.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class TenantConfigurationValueRequest { - @JsonProperty + @JsonProperty(required = true) private Object value; /** @@ -24,7 +24,7 @@ public class TenantConfigurationValueRequest { } /** - * Sets teh TenantConfigurationValueRequest + * Sets the TenantConfigurationValueRequest * * @param value */ diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationValueRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationValueRest.java index 78ebef8c3..cf4a487a4 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationValueRest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationValueRest.java @@ -1,9 +1,21 @@ package org.eclipse.hawkbit.rest.resource.model.system; -public class TenantConfigurationValueRest { +import org.springframework.hateoas.ResourceSupport; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class TenantConfigurationValueRest extends ResourceSupport { + + @JsonInclude(Include.ALWAYS) private Object value = null; + + @JsonInclude(Include.ALWAYS) private boolean isGlobal = true; + private Long lastModifiedAt = null; private String lastModifiedBy = null; private Long createdAt = null; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java index fc63e8bb1..1f6790921 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java @@ -1,5 +1,8 @@ package org.eclipse.hawkbit.rest.resource; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; + import java.util.HashMap; import java.util.Map; @@ -30,7 +33,7 @@ final public class SystemMapper { for (final TenantConfigurationKey key : TenantConfigurationKey.values()) { configurationMap.put(key.getKeyName(), - toResponse(tenantConfigurationManagement.getConfigurationValue(key))); + toResponse(key.getKeyName(), tenantConfigurationManagement.getConfigurationValue(key))); } return configurationMap; @@ -44,7 +47,8 @@ final public class SystemMapper { * configuration value as repository model * @return configuration value as RESTful model */ - public static TenantConfigurationValueRest toResponse(final TenantConfigurationValue repoConfValue) { + public static TenantConfigurationValueRest toResponse(final String key, + final TenantConfigurationValue repoConfValue) { final TenantConfigurationValueRest restConfValue = new TenantConfigurationValueRest(); restConfValue.setValue(repoConfValue.getValue()); @@ -54,6 +58,8 @@ final public class SystemMapper { restConfValue.setLastModifiedAt(repoConfValue.getLastModifiedAt()); restConfValue.setLastModifiedBy(repoConfValue.getLastModifiedBy()); + restConfValue.add(linkTo(methodOn(SystemResource.class).getConfigurationValue(key)).withRel("self")); + return restConfValue; } } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java index 716687b03..cd4a0fa1f 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java @@ -1,5 +1,8 @@ package org.eclipse.hawkbit.rest.resource; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; +import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; + import java.util.Map; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; @@ -10,6 +13,7 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.hateoas.ResourceSupport; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -35,10 +39,17 @@ public class SystemResource { @Autowired private TenantConfigurationManagement tenantConfigurationManagement; + @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + public ResponseEntity getSystem() { + final ResourceSupport resourceSupport = new ResourceSupport(); + resourceSupport.add(linkTo(methodOn(SystemResource.class).getSystemConfiguration()).withRel("configs")); + return ResponseEntity.ok(resourceSupport); + } + /** * @return a Map of all configuration values. */ - @RequestMapping(method = RequestMethod.GET, value = "/conf", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/configs", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity> getSystemConfiguration() { return new ResponseEntity<>(SystemMapper.toResponse(tenantConfigurationManagement), HttpStatus.OK); @@ -54,7 +65,7 @@ public class SystemResource { * OK. In any failure the JsonResponseExceptionHandler is handling * the response. */ - @RequestMapping(method = RequestMethod.DELETE, value = "/conf/{keyName}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity deleteConfigurationValue(@PathVariable final String keyName) { @@ -63,7 +74,7 @@ public class SystemResource { tenantConfigurationManagement.deleteConfiguration(configKey); LOG.debug("{} config value deleted, return status {}", keyName, HttpStatus.OK); - return new ResponseEntity<>(HttpStatus.OK); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } /** @@ -76,15 +87,15 @@ public class SystemResource { * In any failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.GET, value = "/conf/{keyName}", produces = { "application/hal+json", + @RequestMapping(method = RequestMethod.GET, value = "/configs/{keyName}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity getConfigurationValue(@PathVariable final String keyName) { final TenantConfigurationKey configKey = TenantConfigurationKey.fromKeyName(keyName); LOG.debug("{} config value getted, return status {}", keyName, HttpStatus.OK); - return new ResponseEntity<>( - SystemMapper.toResponse(tenantConfigurationManagement.getConfigurationValue(configKey)), HttpStatus.OK); + return new ResponseEntity<>(SystemMapper.toResponse(configKey.getKeyName(), + tenantConfigurationManagement.getConfigurationValue(configKey)), HttpStatus.OK); } /** @@ -99,7 +110,7 @@ public class SystemResource { * In any failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.PUT, value = "/conf/{keyName}", consumes = { "application/hal+json", + @RequestMapping(method = RequestMethod.PUT, value = "/configs/{keyName}", consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity updateConfigurationValue(@PathVariable final String keyName, @RequestBody final TenantConfigurationValueRequest configurationValueRest) { @@ -109,7 +120,7 @@ public class SystemResource { final TenantConfigurationValue updatedValue = tenantConfigurationManagement .addOrUpdateConfiguration(configKey, configurationValueRest.getValue()); - return new ResponseEntity<>(SystemMapper.toResponse(updatedValue), HttpStatus.OK); + return new ResponseEntity<>(SystemMapper.toResponse(keyName, updatedValue), HttpStatus.OK); } } \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java index 12bfae7c6..0d3f496ba 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java @@ -61,8 +61,7 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac private VerticalLayout detailLayout; /** - * @param configurationKey - * @param systemManagement + * @param tenantConfigurationManagement */ @Autowired public GatewaySecurityTokenAuthenticationConfigurationItem(