Moved tenant configuration functions to new management class

- moved fucntions to TenantConfigurationManagement, for better function capseling
- updated references
- updated references in tests, tests were succesfully

Signed-off-by: Nonnenmacher Fabian <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
Fabian Nonnenmacher
2016-01-27 17:00:39 +01:00
committed by Nonnenmacher Fabian
parent b56477191a
commit 6cef6aed1a
29 changed files with 466 additions and 373 deletions

View File

@@ -17,10 +17,11 @@ import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
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.TenantConfigurationManagement;
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;
@@ -53,6 +54,9 @@ public class SystemManagementResource {
@Autowired
private SystemManagement systemManagement;
@Autowired
private TenantConfigurationManagement tenantConfigurationManagement;
@Autowired
private CacheManager cacheManager;
@@ -141,9 +145,9 @@ public class SystemManagementResource {
*/
@RequestMapping(method = RequestMethod.PUT, value = "/conf/{key}")
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
public ResponseEntity<Void> addUpdateConfig(@RequestBody final AuthenticationConfigurationRest configuration,
public ResponseEntity<Void> addUpdateConfig(@RequestBody final TenantConfigurationRest configuration,
@PathVariable final String key) {
systemManagement.addOrUpdateConfiguration(new TenantConfiguration(key, configuration.getValue()));
tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(key, configuration.getValue()));
return ResponseEntity.ok().build();
}

View File

@@ -3,11 +3,11 @@ package org.eclipse.hawkbit.rest.resource;
import java.util.HashMap;
import java.util.Map;
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.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRest;
import org.eclipse.hawkbit.rest.resource.model.system.TenantConfigurationValueRest;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,25 +22,33 @@ final public class SystemMapper {
private static DurationHelper dh = new DurationHelper();
public static SystemConfigurationRest toResponse(final SystemManagement systemManagement) {
public static SystemConfigurationRest toResponse(
final TenantConfigurationManagement tenantConfigurationManagement) {
final SystemConfigurationRest sysconf = new SystemConfigurationRest();
final Map<String, Object> authconf = new HashMap<String, Object>();
final Map<String, TenantConfigurationValueRest> authconf = new HashMap<String, TenantConfigurationValueRest>();
for (final TenantConfigurationKey key : TenantConfigurationKey.values()) {
final Object value = systemManagement.getConfigurationValue(key);
final TenantConfigurationValueRest value = toResponse(
tenantConfigurationManagement.getConfigurationValue(key, key.getDataType()));
authconf.put(key.getKeyName(), value);
}
sysconf.setAuthenticationConfiguration(authconf);
sysconf.setConfiguration(authconf);
return sysconf;
}
public static TenantMetaData fromRequest(final SystemManagement systemManagement,
final SystemConfigurationRequestBodyPut systemConReq) {
public static TenantConfigurationValueRest toResponse(final TenantConfigurationValue<?> confValue) {
final TenantConfigurationValueRest response = new TenantConfigurationValueRest();
// TODO
return null;
response.setValue(confValue.getValue());
response.setGlobal(confValue.isGlobal());
response.setCreatedAt(confValue.getCreatedAt());
response.setCreatedBy(confValue.getCreatedBy());
response.setLastModifiedAt(confValue.getLastModifiedAt());
response.setLastModifiedBy(confValue.getLastModifiedBy());
return response;
}
}

View File

@@ -1,7 +1,7 @@
package org.eclipse.hawkbit.rest.resource;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut;
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRest;
import org.slf4j.Logger;
@@ -22,7 +22,7 @@ public class SystemResource {
private static final Logger LOGGER = LoggerFactory.getLogger(SystemResource.class);
@Autowired
private SystemManagement systemManagement;
private TenantConfigurationManagement tenantConfigurationManagement;
@Autowired
private DistributionSetManagement distributionSetManagement;
@@ -30,8 +30,7 @@ public class SystemResource {
@RequestMapping(method = RequestMethod.GET, value = "/conf", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<SystemConfigurationRest> getSystemConfiguration() {
return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK);
return new ResponseEntity<>(SystemMapper.toResponse(tenantConfigurationManagement), HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.PUT, value = "/conf", consumes = { "application/hal+json",
@@ -41,7 +40,7 @@ public class SystemResource {
// systemManagement.updateTenantConfiguration(systemConReq);
return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK);
return new ResponseEntity<>(SystemMapper.toResponse(tenantConfigurationManagement), HttpStatus.OK);
}
}