From: Julien Lancelot Date: Thu, 25 Aug 2016 15:54:56 +0000 (+0200) Subject: SONAR-7970 Create factoy methods to create Setting X-Git-Tag: 6.1-RC1~290 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=489f36d4456eb0e6e74001cfeaad8f30114c1352;p=sonarqube.git SONAR-7970 Create factoy methods to create Setting --- 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()); }