private final List<Map<String, String>> 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<PropertyDto> propertyDtoSetValues, @Nullable PropertyDefinition definition) {
+ private Setting(PropertyDto propertyDto, List<PropertyDto> propertyDtoSetValues, @Nullable PropertyDefinition definition) {
this.key = propertyDto.getKey();
this.value = propertyDto.getValue();
this.componentId = propertyDto.getResourceId();
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;
this.isDefault = true;
}
+ public static Setting createForDto(PropertyDto propertyDto, List<PropertyDto> 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;
}
List<PropertyDto> properties = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, keys);
List<PropertyDto> 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());
}
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;
}
return propertyDefinitions.getAll().stream()
.filter(definition -> keys.contains(definition.key()))
.filter(defaultProperty -> !isNullOrEmpty(defaultProperty.defaultValue()))
- .map(Setting::new)
+ .map(Setting::createForDefinition)
.collect(Collectors.toList());
}