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 <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
Fabian Nonnenmacher
2016-02-01 15:31:56 +01:00
committed by Nonnenmacher Fabian
parent c39753001e
commit aee254244a
5 changed files with 43 additions and 15 deletions

View File

@@ -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
*/

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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<ResourceSupport> 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<Map<String, TenantConfigurationValueRest>> 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<Void> 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<TenantConfigurationValueRest> 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<TenantConfigurationValueRest> updateConfigurationValue(@PathVariable final String keyName,
@RequestBody final TenantConfigurationValueRequest configurationValueRest) {
@@ -109,7 +120,7 @@ public class SystemResource {
final TenantConfigurationValue<Object> updatedValue = tenantConfigurationManagement
.addOrUpdateConfiguration(configKey, configurationValueRest.getValue());
return new ResponseEntity<>(SystemMapper.toResponse(updatedValue), HttpStatus.OK);
return new ResponseEntity<>(SystemMapper.toResponse(keyName, updatedValue), HttpStatus.OK);
}
}

View File

@@ -61,8 +61,7 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
private VerticalLayout detailLayout;
/**
* @param configurationKey
* @param systemManagement
* @param tenantConfigurationManagement
*/
@Autowired
public GatewaySecurityTokenAuthenticationConfigurationItem(