Added validation before saving TenantConfiguration and updated tests

* run the validation methodes inside the storing methode, to make sure that only
  valid values are written inside the database
* updated TenantConfigurationManagementTest to match the validation
* added new Tests to test all validators

Signed-off-by: Nonnenmacher Fabian <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
Fabian Nonnenmacher
2016-01-28 18:16:31 +01:00
committed by Nonnenmacher Fabian
parent d83286c94a
commit 4be880587a
9 changed files with 193 additions and 74 deletions

View File

@@ -18,11 +18,11 @@ 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.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.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -147,7 +147,20 @@ public class SystemManagementResource {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
public ResponseEntity<Void> addUpdateConfig(@RequestBody final TenantConfigurationRest configuration,
@PathVariable final String key) {
tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(key, configuration.getValue()));
// TODO Quick and dirty to stay compatible, but these rest interface
// won't be necessary in future
Object value;
if (configuration.getValue().equals(Boolean.TRUE)) {
value = true;
} else if (configuration.getValue().equals(Boolean.FALSE)) {
value = false;
} else {
value = configuration.getValue();
}
tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.fromKeyName(key), value);
return ResponseEntity.ok().build();
}