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:
committed by
Nonnenmacher Fabian
parent
c39753001e
commit
aee254244a
@@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class TenantConfigurationValueRequest {
|
public class TenantConfigurationValueRequest {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty(required = true)
|
||||||
private Object value;
|
private Object value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +24,7 @@ public class TenantConfigurationValueRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets teh TenantConfigurationValueRequest
|
* Sets the TenantConfigurationValueRequest
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
package org.eclipse.hawkbit.rest.resource.model.system;
|
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;
|
private Object value = null;
|
||||||
|
|
||||||
|
@JsonInclude(Include.ALWAYS)
|
||||||
private boolean isGlobal = true;
|
private boolean isGlobal = true;
|
||||||
|
|
||||||
private Long lastModifiedAt = null;
|
private Long lastModifiedAt = null;
|
||||||
private String lastModifiedBy = null;
|
private String lastModifiedBy = null;
|
||||||
private Long createdAt = null;
|
private Long createdAt = null;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.eclipse.hawkbit.rest.resource;
|
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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -30,7 +33,7 @@ final public class SystemMapper {
|
|||||||
|
|
||||||
for (final TenantConfigurationKey key : TenantConfigurationKey.values()) {
|
for (final TenantConfigurationKey key : TenantConfigurationKey.values()) {
|
||||||
configurationMap.put(key.getKeyName(),
|
configurationMap.put(key.getKeyName(),
|
||||||
toResponse(tenantConfigurationManagement.getConfigurationValue(key)));
|
toResponse(key.getKeyName(), tenantConfigurationManagement.getConfigurationValue(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return configurationMap;
|
return configurationMap;
|
||||||
@@ -44,7 +47,8 @@ final public class SystemMapper {
|
|||||||
* configuration value as repository model
|
* configuration value as repository model
|
||||||
* @return configuration value as RESTful 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();
|
final TenantConfigurationValueRest restConfValue = new TenantConfigurationValueRest();
|
||||||
|
|
||||||
restConfValue.setValue(repoConfValue.getValue());
|
restConfValue.setValue(repoConfValue.getValue());
|
||||||
@@ -54,6 +58,8 @@ final public class SystemMapper {
|
|||||||
restConfValue.setLastModifiedAt(repoConfValue.getLastModifiedAt());
|
restConfValue.setLastModifiedAt(repoConfValue.getLastModifiedAt());
|
||||||
restConfValue.setLastModifiedBy(repoConfValue.getLastModifiedBy());
|
restConfValue.setLastModifiedBy(repoConfValue.getLastModifiedBy());
|
||||||
|
|
||||||
|
restConfValue.add(linkTo(methodOn(SystemResource.class).getConfigurationValue(key)).withRel("self"));
|
||||||
|
|
||||||
return restConfValue;
|
return restConfValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.eclipse.hawkbit.rest.resource;
|
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 java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||||
@@ -10,6 +13,7 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.hateoas.ResourceSupport;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -35,10 +39,17 @@ public class SystemResource {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TenantConfigurationManagement tenantConfigurationManagement;
|
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.
|
* @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 })
|
MediaType.APPLICATION_JSON_VALUE })
|
||||||
public ResponseEntity<Map<String, TenantConfigurationValueRest>> getSystemConfiguration() {
|
public ResponseEntity<Map<String, TenantConfigurationValueRest>> getSystemConfiguration() {
|
||||||
return new ResponseEntity<>(SystemMapper.toResponse(tenantConfigurationManagement), HttpStatus.OK);
|
return new ResponseEntity<>(SystemMapper.toResponse(tenantConfigurationManagement), HttpStatus.OK);
|
||||||
@@ -54,7 +65,7 @@ public class SystemResource {
|
|||||||
* OK. In any failure the JsonResponseExceptionHandler is handling
|
* OK. In any failure the JsonResponseExceptionHandler is handling
|
||||||
* the response.
|
* 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 })
|
MediaType.APPLICATION_JSON_VALUE })
|
||||||
public ResponseEntity<Void> deleteConfigurationValue(@PathVariable final String keyName) {
|
public ResponseEntity<Void> deleteConfigurationValue(@PathVariable final String keyName) {
|
||||||
|
|
||||||
@@ -63,7 +74,7 @@ public class SystemResource {
|
|||||||
tenantConfigurationManagement.deleteConfiguration(configKey);
|
tenantConfigurationManagement.deleteConfiguration(configKey);
|
||||||
|
|
||||||
LOG.debug("{} config value deleted, return status {}", keyName, HttpStatus.OK);
|
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
|
* In any failure the JsonResponseExceptionHandler is handling the
|
||||||
* response.
|
* 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 })
|
MediaType.APPLICATION_JSON_VALUE })
|
||||||
public ResponseEntity<TenantConfigurationValueRest> getConfigurationValue(@PathVariable final String keyName) {
|
public ResponseEntity<TenantConfigurationValueRest> getConfigurationValue(@PathVariable final String keyName) {
|
||||||
|
|
||||||
final TenantConfigurationKey configKey = TenantConfigurationKey.fromKeyName(keyName);
|
final TenantConfigurationKey configKey = TenantConfigurationKey.fromKeyName(keyName);
|
||||||
|
|
||||||
LOG.debug("{} config value getted, return status {}", keyName, HttpStatus.OK);
|
LOG.debug("{} config value getted, return status {}", keyName, HttpStatus.OK);
|
||||||
return new ResponseEntity<>(
|
return new ResponseEntity<>(SystemMapper.toResponse(configKey.getKeyName(),
|
||||||
SystemMapper.toResponse(tenantConfigurationManagement.getConfigurationValue(configKey)), HttpStatus.OK);
|
tenantConfigurationManagement.getConfigurationValue(configKey)), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +110,7 @@ public class SystemResource {
|
|||||||
* In any failure the JsonResponseExceptionHandler is handling the
|
* In any failure the JsonResponseExceptionHandler is handling the
|
||||||
* response.
|
* 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 })
|
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||||
public ResponseEntity<TenantConfigurationValueRest> updateConfigurationValue(@PathVariable final String keyName,
|
public ResponseEntity<TenantConfigurationValueRest> updateConfigurationValue(@PathVariable final String keyName,
|
||||||
@RequestBody final TenantConfigurationValueRequest configurationValueRest) {
|
@RequestBody final TenantConfigurationValueRequest configurationValueRest) {
|
||||||
@@ -109,7 +120,7 @@ public class SystemResource {
|
|||||||
final TenantConfigurationValue<Object> updatedValue = tenantConfigurationManagement
|
final TenantConfigurationValue<Object> updatedValue = tenantConfigurationManagement
|
||||||
|
|
||||||
.addOrUpdateConfiguration(configKey, configurationValueRest.getValue());
|
.addOrUpdateConfiguration(configKey, configurationValueRest.getValue());
|
||||||
return new ResponseEntity<>(SystemMapper.toResponse(updatedValue), HttpStatus.OK);
|
return new ResponseEntity<>(SystemMapper.toResponse(keyName, updatedValue), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -61,8 +61,7 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
|
|||||||
private VerticalLayout detailLayout;
|
private VerticalLayout detailLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param configurationKey
|
* @param tenantConfigurationManagement
|
||||||
* @param systemManagement
|
|
||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
public GatewaySecurityTokenAuthenticationConfigurationItem(
|
public GatewaySecurityTokenAuthenticationConfigurationItem(
|
||||||
|
|||||||
Reference in New Issue
Block a user