From f3fa085c623ed182ea8a277d6071b2929ef29208 Mon Sep 17 00:00:00 2001 From: Fabian Nonnenmacher Date: Thu, 21 Jan 2016 15:29:10 +0100 Subject: [PATCH] First implemtation of REST-API Signed-off-by: Nonnenmacher Fabian --- .../hawkbit/exception/SpServerError.java | 13 ++ .../hawkbit/repository/SystemManagement.java | 31 +++ .../InvalidDistributionSetTypeException.java | 40 ++++ .../InvalidPollingTimeException.java | 35 ++++ .../hawkbit/rest/resource/RestConstants.java | 2 + ...a => AuthenticationConfigurationRest.java} | 2 +- .../SystemConfigurationRequestBodyPut.java | 105 ++++++++++ .../model/system/SystemConfigurationRest.java | 194 ++++++++++++++++++ .../resource/SystemManagementResource.java | 4 +- .../hawkbit/rest/resource/SystemMapper.java | 87 ++++++++ .../hawkbit/rest/resource/SystemResource.java | 47 +++++ 11 files changed, 557 insertions(+), 3 deletions(-) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidDistributionSetTypeException.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidPollingTimeException.java rename hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/{TenantConfigurationRest.java => AuthenticationConfigurationRest.java} (96%) create mode 100644 hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRequestBodyPut.java create mode 100644 hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRest.java create mode 100644 hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java create mode 100644 hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/SpServerError.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/SpServerError.java index cdf91f879..9ba75835d 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/SpServerError.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/exception/SpServerError.java @@ -65,6 +65,19 @@ public enum SpServerError { */ SP_REST_SORT_PARAM_INVALID_DIRECTION("hawkbit.server.error.rest.param.invalidDirection", "The given sort parameter direction does not exist"), + + /** + * + */ + SP_REST_CONFIG_POLLING_TIME_WRONG_FOMRATTED("hawkbit.server.error.rest.param.invalidFormat", + "The given overdue polling time or polling time parameter are not formatted correctly."), + + /** + * + */ + SP_REST_CONFIG_INVALID_DS_TYPE("hawkbit.server.error.rest.param.invalidFormat", + "The given default distribution set type does not exist."), + /** * */ diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 09b6025d3..bade114d1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.time.format.DateTimeParseException; import java.util.List; import java.util.stream.Collectors; @@ -20,10 +21,15 @@ import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetTypeException; +import org.eclipse.hawkbit.repository.exception.InvalidPollingTimeException; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantMetaData; +import org.eclipse.hawkbit.repository.model.helper.DurationHelper; +import org.eclipse.hawkbit.repository.specifications.DistributionSetTypeSpecification; +import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.persistence.config.PersistenceUnitProperties; @@ -461,4 +467,29 @@ public class SystemManagement implements EnvironmentAware { } + @Transactional + @Modifying + public void updateTenantConfiguration(SystemConfigurationRequestBodyPut systemConReq) { + + DurationHelper dh = new DurationHelper(); + + TenantMetaData tenantMetaData = getTenantMetadata(); + + String ddstypeKey = systemConReq.getDefaultDistributionSetType(); + + if (distributionSetTypeRepository.findAll(DistributionSetTypeSpecification.byKey(ddstypeKey)).isEmpty()) { + throw new InvalidDistributionSetTypeException( + String.format("The specified default distribution set type %s doe not exist.", ddstypeKey)); + } + + try { + tenantMetaData.setPollingOverdueTime(dh.formattedStringToDuration(systemConReq.getPollingOverdueTime())); + tenantMetaData.setPollingTime(dh.formattedStringToDuration(systemConReq.getPollingTime())); + } catch (DateTimeParseException ex) { + throw new InvalidPollingTimeException(ex); + } + + updateTenantMetadata(tenantMetaData); + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidDistributionSetTypeException.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidDistributionSetTypeException.java new file mode 100644 index 000000000..42fbe9c3c --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidDistributionSetTypeException.java @@ -0,0 +1,40 @@ +package org.eclipse.hawkbit.repository.exception; + +import org.eclipse.hawkbit.exception.SpServerError; +import org.eclipse.hawkbit.exception.SpServerRtException; + +/** + * This Exception is thrown, when the user wants to set a distribution set which + * does not exist, + * + */ +public class InvalidDistributionSetTypeException extends SpServerRtException { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates a new CancelActionNotAllowed with + * {@link SpServerError#SP_ACTION_NOT_CANCELABLE} error. + */ + public InvalidDistributionSetTypeException() { + super(SpServerError.SP_REST_CONFIG_INVALID_DS_TYPE); + } + + /** + * @param cause + * for the exception + */ + public InvalidDistributionSetTypeException(final Throwable cause) { + super(SpServerError.SP_REST_CONFIG_INVALID_DS_TYPE, cause); + } + + /** + * @param message + * of the error + */ + public InvalidDistributionSetTypeException(final String message) { + super(message, SpServerError.SP_REST_CONFIG_INVALID_DS_TYPE); + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidPollingTimeException.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidPollingTimeException.java new file mode 100644 index 000000000..818401563 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidPollingTimeException.java @@ -0,0 +1,35 @@ +package org.eclipse.hawkbit.repository.exception; + +import org.eclipse.hawkbit.exception.SpServerError; +import org.eclipse.hawkbit.exception.SpServerRtException; + +public class InvalidPollingTimeException extends SpServerRtException { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates a new CancelActionNotAllowed with + * {@link SpServerError#SP_ACTION_NOT_CANCELABLE} error. + */ + public InvalidPollingTimeException() { + super(SpServerError.SP_REST_CONFIG_POLLING_TIME_WRONG_FOMRATTED); + } + + /** + * @param cause + * for the exception + */ + public InvalidPollingTimeException(final Throwable cause) { + super(SpServerError.SP_REST_CONFIG_POLLING_TIME_WRONG_FOMRATTED, cause); + } + + /** + * @param message + * of the error + */ + public InvalidPollingTimeException(final String message) { + super(message, SpServerError.SP_REST_CONFIG_POLLING_TIME_WRONG_FOMRATTED); + } +} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/RestConstants.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/RestConstants.java index 706584a64..bde96f7a8 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/RestConstants.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/RestConstants.java @@ -116,6 +116,8 @@ public final class RestConstants { * The target URL mapping rest resource. */ public static final String TARGET_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/targets"; + + public static final String SYSTEM_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/system"; /** * The software module URL mapping rest resource. */ diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/AuthenticationConfigurationRest.java similarity index 96% rename from hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationRest.java rename to hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/AuthenticationConfigurationRest.java index 2d31d9f61..1808bbc59 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/TenantConfigurationRest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/AuthenticationConfigurationRest.java @@ -18,7 +18,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; */ @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) -public class TenantConfigurationRest { +public class AuthenticationConfigurationRest { private String key; private String value; diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRequestBodyPut.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRequestBodyPut.java new file mode 100644 index 000000000..c5a3c219a --- /dev/null +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRequestBodyPut.java @@ -0,0 +1,105 @@ +package org.eclipse.hawkbit.rest.resource.model.system; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A json annotated rest model for System Configuration for PUT. + */ +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class SystemConfigurationRequestBodyPut { + + @JsonProperty + private String pollingTime; + + @JsonProperty + private String pollingOverdueTime; + + @JsonProperty + private String defaultDistributionSetType; + + @JsonProperty + private Map authenticationConfiguration; + + /** + * Gets the polling time. + * + * @return the polling time + */ + public String getPollingTime() { + return pollingTime; + } + + /** + * Sets the polling time. + * + * @param pollingTime + * the new polling time + */ + public void setPollingTime(String pollingTime) { + this.pollingTime = pollingTime; + } + + /** + * Gets the polling overdue time. + * + * @return the polling overdue time + */ + public String getPollingOverdueTime() { + return pollingOverdueTime; + } + + /** + * Sets the polling overdue time. + * + * @param pollingOverdueTime + * the new polling overdue time + */ + public void setPollingOverdueTime(String pollingOverdueTime) { + this.pollingOverdueTime = pollingOverdueTime; + } + + /** + * Gets the default distribution set type. + * + * @return the default distribution set type + */ + public String getDefaultDistributionSetType() { + return defaultDistributionSetType; + } + + /** + * Sets the default distribution set type. + * + * @param defaultDistributionSetType + * the new default distribution set type + */ + public void setDefaultDistributionSetType(String defaultDistributionSetType) { + this.defaultDistributionSetType = defaultDistributionSetType; + } + + /** + * Gets the authentication configuration. + * + * @return the authentication configuration + */ + public Map getAuthenticationConfiguration() { + return authenticationConfiguration; + } + + /** + * Sets the authentication configuration. + * + * @param authenticationConfiguration + * the authentication configuration + */ + public void setAuthenticationConfiguration(Map authenticationConfiguration) { + this.authenticationConfiguration = authenticationConfiguration; + } + +} diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRest.java new file mode 100644 index 000000000..ee39027a3 --- /dev/null +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRest.java @@ -0,0 +1,194 @@ +package org.eclipse.hawkbit.rest.resource.model.system; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A json annotated rest model for SysteConfiguration to RESTful API + * representation. + * + */ +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class SystemConfigurationRest { + + @JsonProperty + private String pollingTime; + + @JsonProperty + private String pollingOverdueTime; + + @JsonProperty + private String defaultDistributionSetType; + + @JsonProperty + private String createdBy; + + @JsonProperty + private String lastModifiedBy; + + @JsonProperty + private Long createdAt; + + @JsonProperty + private Long lastModifiedAt; + + @JsonProperty + private Map authenticationConfiguration; + + /** + * Gets the polling time. + * + * @return the polling time + */ + public String getPollingTime() { + return pollingTime; + } + + /** + * Sets the polling time. + * + * @param pollingTime + * the new polling time + */ + public void setPollingTime(String pollingTime) { + this.pollingTime = pollingTime; + } + + /** + * Gets the polling overdue time. + * + * @return the polling overdue time + */ + public String getPollingOverdueTime() { + return pollingOverdueTime; + } + + /** + * Sets the polling overdue time. + * + * @param pollingOverdueTime + * the new polling overdue time + */ + public void setPollingOverdueTime(String pollingOverdueTime) { + this.pollingOverdueTime = pollingOverdueTime; + } + + /** + * Gets the default distribution set type. + * + * @return the default distribution set type + */ + public String getDefaultDistributionSetType() { + return defaultDistributionSetType; + } + + /** + * Sets the default distribution set type. + * + * @param defaultDistributionSetType + * the new default distribution set type + */ + public void setDefaultDistributionSetType(String defaultDistributionSetType) { + this.defaultDistributionSetType = defaultDistributionSetType; + } + + /** + * Gets the created by. + * + * @return the created by + */ + public String getCreatedBy() { + return createdBy; + } + + /** + * Sets the created by. + * + * @param createdBy + * the new created by + */ + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + /** + * Gets the last modified by. + * + * @return the last modified by + */ + public String getLastModifiedBy() { + return lastModifiedBy; + } + + /** + * Sets the last modified by. + * + * @param lastModifiedBy + * the new last modified by + */ + public void setLastModifiedBy(String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + /** + * Gets the created at. + * + * @return the created at + */ + public Long getCreatedAt() { + return createdAt; + } + + /** + * Sets the created at. + * + * @param createdAt + * the new created at + */ + public void setCreatedAt(Long createdAt) { + this.createdAt = createdAt; + } + + /** + * Gets the last modified at. + * + * @return the last modified at + */ + public Long getLastModifiedAt() { + return lastModifiedAt; + } + + /** + * Sets the last modified at. + * + * @param lastModifiedAt + * the new last modified at + */ + public void setLastModifiedAt(Long lastModifiedAt) { + this.lastModifiedAt = lastModifiedAt; + } + + /** + * Sets the authentication configuration. + * + * @param authenticationConfiguration + * the authentication configuration + */ + public void setAuthenticationConfiguration(Map authenticationConfiguration) { + this.authenticationConfiguration = authenticationConfiguration; + } + + /** + * Gets the authentication configuration. + * + * @return the authentication configuration + */ + public Map getAuthenticationConfiguration() { + return this.authenticationConfiguration; + } +} diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java index 7213eae6d..6c4d86586 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java @@ -18,9 +18,9 @@ import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.report.model.TenantUsage; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.model.TenantConfiguration; +import org.eclipse.hawkbit.rest.resource.model.system.AuthenticationConfigurationRest; import org.eclipse.hawkbit.rest.resource.model.system.CacheRest; import org.eclipse.hawkbit.rest.resource.model.system.SystemStatisticsRest; -import org.eclipse.hawkbit.rest.resource.model.system.TenantConfigurationRest; import org.eclipse.hawkbit.rest.resource.model.system.TenantSystemUsageRest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -141,7 +141,7 @@ public class SystemManagementResource { */ @RequestMapping(method = RequestMethod.PUT, value = "/conf/{key}") @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) - public ResponseEntity addUpdateConfig(@RequestBody final TenantConfigurationRest configuration, + public ResponseEntity addUpdateConfig(@RequestBody final AuthenticationConfigurationRest configuration, @PathVariable final String key) { systemManagement.addOrUpdateConfiguration(new TenantConfiguration(key, configuration.getValue())); return ResponseEntity.ok().build(); 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 new file mode 100644 index 000000000..47fa24b1b --- /dev/null +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java @@ -0,0 +1,87 @@ +package org.eclipse.hawkbit.rest.resource; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.model.TenantMetaData; +import org.eclipse.hawkbit.repository.model.helper.DurationHelper; +import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut; +import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRest; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final public class SystemMapper { + + private static final Logger LOG = LoggerFactory.getLogger(SystemMapper.class); + + private SystemMapper() { + // Utility class + } + + private static DurationHelper dh = new DurationHelper(); + + public static SystemConfigurationRest toResponse(SystemManagement systemManagement) { + + TenantMetaData tenantMetaData = systemManagement.getTenantMetadata(); + + SystemConfigurationRest sysconf = new SystemConfigurationRest(); + + sysconf.setDefaultDistributionSetType(tenantMetaData.getDefaultDsType().getKey()); + sysconf.setCreatedAt(tenantMetaData.getCreatedAt()); + sysconf.setCreatedBy(tenantMetaData.getCreatedBy()); + sysconf.setLastModifiedAt(tenantMetaData.getLastModifiedAt()); + sysconf.setLastModifiedBy(tenantMetaData.getLastModifiedBy()); + + sysconf.setPollingOverdueTime(dh.durationToFormattedString(tenantMetaData.getPollingOverdueTime())); + sysconf.setPollingTime(dh.durationToFormattedString(tenantMetaData.getPollingTime())); + + Map authconf = new HashMap(); + + for (TenantConfigurationKey key : TenantConfigurationKey.values()) { + Object value; + + switch (key) { + case AUTHENTICATION_MODE_HEADER_ENABLED: + case AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED: + case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED: + value = systemManagement.getConfigurationValue(key, Boolean.class); + break; + case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME: + case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY: + case AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME: + value = systemManagement.getConfigurationValue(key, String.class); + break; + default: + LOG.warn("There is no data type specified for TenantConfigurationKey {}.", key.getKeyName()); + value = systemManagement.getConfigurationValue(key, String.class); + } + authconf.put(key.getKeyName(), value); + } + + sysconf.setAuthenticationConfiguration(authconf); + + return sysconf; + } + + public static TenantMetaData fromRequest(SystemManagement systemManagement, + SystemConfigurationRequestBodyPut systemConReq, DistributionSetManagement distributionSetManagement) { + + TenantMetaData tenantMetaData = systemManagement.getTenantMetadata(); + + String ddstypeKey = systemConReq.getDefaultDistributionSetType(); + + if (distributionSetManagement.findDistributionSetTypeByKey(ddstypeKey) == null) { + throw new IllegalArgumentException( + String.format("The specified default distribution set type %s doe not exist.", ddstypeKey)); + } + + tenantMetaData.setPollingOverdueTime(dh.formattedStringToDuration(systemConReq.getPollingOverdueTime())); + tenantMetaData.setPollingTime(dh.formattedStringToDuration(systemConReq.getPollingTime())); + + return null; + + } +} 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 new file mode 100644 index 000000000..129261715 --- /dev/null +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java @@ -0,0 +1,47 @@ +package org.eclipse.hawkbit.rest.resource; + +import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut; +import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(RestConstants.SYSTEM_V1_REQUEST_MAPPING) +public class SystemResource { + + private static final Logger LOGGER = LoggerFactory.getLogger(SystemResource.class); + + @Autowired + private SystemManagement systemManagement; + + @Autowired + private DistributionSetManagement distributionSetManagement; + + @RequestMapping(method = RequestMethod.GET, value = "/conf", produces = { "application/hal+json", + MediaType.APPLICATION_JSON_VALUE }) + public ResponseEntity getSystemConfiguration() { + + return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK); + } + + @RequestMapping(method = RequestMethod.PUT, value = "/conf", consumes = { "application/hal+json", + MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) + public ResponseEntity updateSoftwareModuleType( + @RequestBody final SystemConfigurationRequestBodyPut systemConReq) { + + systemManagement.updateTenantConfiguration(systemConReq); + + return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK); + } + +}