From 489f36d4456eb0e6e74001cfeaad8f30114c1352 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 25 Aug 2016 17:54:56 +0200 Subject: [PATCH] SONAR-7970 Create factoy methods to create Setting --- .../org/sonar/server/settings/ws/Setting.java | 18 ++++++++++-------- .../server/settings/ws/SettingsFinder.java | 4 ++-- .../sonar/server/settings/ws/ValuesAction.java | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/settings/ws/Setting.java b/server/sonar-server/src/main/java/org/sonar/server/settings/ws/Setting.java index 668ed30a2c2..757fe4ca325 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/settings/ws/Setting.java +++ b/server/sonar-server/src/main/java/org/sonar/server/settings/ws/Setting.java @@ -42,10 +42,7 @@ public class Setting { private final List> propertySets; private final boolean isDefault; - /** - * Use this constructor to create setting from a property dto, and that can have a definition or not - */ - Setting(PropertyDto propertyDto, List propertyDtoSetValues, @Nullable PropertyDefinition definition) { + private Setting(PropertyDto propertyDto, List propertyDtoSetValues, @Nullable PropertyDefinition definition) { this.key = propertyDto.getKey(); this.value = propertyDto.getValue(); this.componentId = propertyDto.getResourceId(); @@ -54,10 +51,7 @@ public class Setting { this.isDefault = false; } - /** - * Use this constructor to create setting for default value - */ - Setting(PropertyDefinition definition) { + private Setting(PropertyDefinition definition) { this.key = definition.key(); this.value = definition.defaultValue(); this.componentId = null; @@ -66,6 +60,14 @@ public class Setting { this.isDefault = true; } + public static Setting createForDto(PropertyDto propertyDto, List propertyDtoSetValues, @Nullable PropertyDefinition definition){ + return new Setting(propertyDto, propertyDtoSetValues, definition); + } + + public static Setting createForDefinition(PropertyDefinition definition){ + return new Setting(definition); + } + public String getKey() { return key; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/settings/ws/SettingsFinder.java b/server/sonar-server/src/main/java/org/sonar/server/settings/ws/SettingsFinder.java index e1501d8a951..e2ed8ffd35d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/settings/ws/SettingsFinder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/settings/ws/SettingsFinder.java @@ -56,7 +56,7 @@ public class SettingsFinder { List properties = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, keys); List propertySets = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, getPropertySetKeys(properties)); return properties.stream() - .map(property -> new Setting(property, getPropertySets(property.getKey(), propertySets, null), definitions.get(property.getKey()))) + .map(property -> Setting.createForDto(property, getPropertySets(property.getKey(), propertySets, null), definitions.get(property.getKey()))) .collect(Collectors.toList()); } @@ -77,7 +77,7 @@ public class SettingsFinder { String componentUuid = uuidsById.get(componentId); String propertyKey = propertyDto.getKey(); settingsByUuid.put(componentUuid, - new Setting(propertyDto, getPropertySets(propertyKey, propertySets, componentId), definitions.get(propertyKey))); + Setting.createForDto(propertyDto, getPropertySets(propertyKey, propertySets, componentId), definitions.get(propertyKey))); } return settingsByUuid; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java b/server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java index 47cd44ede70..5f34ecc58fb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java @@ -159,7 +159,7 @@ public class ValuesAction implements SettingsWsAction { return propertyDefinitions.getAll().stream() .filter(definition -> keys.contains(definition.key())) .filter(defaultProperty -> !isNullOrEmpty(defaultProperty.defaultValue())) - .map(Setting::new) + .map(Setting::createForDefinition) .collect(Collectors.toList()); } -- 2.39.5