use of org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty in project mule by mulesoft.
the class DefaultConfigurationPropertiesProvider method createAttributesFromYamlObject.
protected void createAttributesFromYamlObject(String parentPath, Object parentYamlObject, Object yamlObject) {
if (yamlObject instanceof List) {
List list = (List) yamlObject;
if (list.get(0) instanceof Map) {
list.forEach(value -> createAttributesFromYamlObject(parentPath, yamlObject, value));
} else {
if (!(list.get(0) instanceof String)) {
throw new ConfigurationPropertiesException(createStaticMessage("List of complex objects are not supported as property values. Offending key is " + parentPath), this);
}
String[] values = new String[list.size()];
list.toArray(values);
String value = join(",", list);
configurationAttributes.put(parentPath, new DefaultConfigurationProperty(this, parentPath, value));
}
} else if (yamlObject instanceof Map) {
if (parentYamlObject instanceof List) {
throw new ConfigurationPropertiesException(createStaticMessage("Configuration properties does not support type a list of complex types. Complex type keys are: " + join(",", ((Map) yamlObject).keySet())), this);
}
Map<String, Object> map = (Map) yamlObject;
map.entrySet().stream().forEach(entry -> createAttributesFromYamlObject(createKey(parentPath, entry.getKey()), yamlObject, entry.getValue()));
} else {
if (!(yamlObject instanceof String)) {
throw new ConfigurationPropertiesException(createStaticMessage(format("YAML configuration properties only supports string values, make sure to wrap the value with \" so you force the value to be an string. Offending property is %s with value %s", parentPath, yamlObject)), this);
}
String resultObject = createValue(parentPath, (String) yamlObject);
configurationAttributes.put(parentPath, new DefaultConfigurationProperty(this, parentPath, resultObject));
}
}
use of org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty in project mule by mulesoft.
the class ApplicationModel method createProviderFromGlobalProperties.
private ConfigurationPropertiesProvider createProviderFromGlobalProperties(ArtifactConfig artifactConfig) {
final Map<String, ConfigurationProperty> globalProperties = new HashMap<>();
artifactConfig.getConfigFiles().stream().forEach(configFile -> {
configFile.getConfigLines().get(0).getChildren().stream().forEach(configLine -> {
if (GLOBAL_PROPERTY.equals(configLine.getIdentifier())) {
String key = configLine.getConfigAttributes().get("name").getValue();
String rawValue = configLine.getConfigAttributes().get("value").getValue();
globalProperties.put(key, new DefaultConfigurationProperty(format("global-property - file: %s - lineNumber %s", configFile.getFilename(), configLine.getLineNumber()), key, rawValue));
}
});
});
return new GlobalPropertyConfigurationPropertiesProvider(globalProperties);
}
use of org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty in project mule by mulesoft.
the class ApplicationModel method createConfigurationAttributeResolver.
private void createConfigurationAttributeResolver(ArtifactConfig artifactConfig, Optional<ConfigurationProperties> parentConfigurationProperties, Map<String, String> deploymentProperties) {
EnvironmentPropertiesConfigurationProvider environmentPropertiesConfigurationProvider = new EnvironmentPropertiesConfigurationProvider();
ConfigurationPropertiesProvider globalPropertiesConfigurationAttributeProvider = createProviderFromGlobalProperties(artifactConfig);
DefaultConfigurationPropertiesResolver localResolver = new DefaultConfigurationPropertiesResolver(of(new DefaultConfigurationPropertiesResolver(of(new DefaultConfigurationPropertiesResolver(empty(), environmentPropertiesConfigurationProvider)), globalPropertiesConfigurationAttributeProvider)), environmentPropertiesConfigurationProvider);
List<ConfigurationPropertiesProvider> configConfigurationPropertiesProviders = getConfigurationPropertiesProvidersFromComponents(artifactConfig, localResolver);
FileConfigurationPropertiesProvider externalPropertiesConfigurationProvider = new FileConfigurationPropertiesProvider(externalResourceProvider, "External files");
Optional<ConfigurationPropertiesResolver> parentConfigurationPropertiesResolver = of(localResolver);
if (parentConfigurationProperties.isPresent()) {
parentConfigurationPropertiesResolver = of(new DefaultConfigurationPropertiesResolver(empty(), new ConfigurationPropertiesProvider() {
@Override
public Optional<ConfigurationProperty> getConfigurationProperty(String configurationAttributeKey) {
return parentConfigurationProperties.get().resolveProperty(configurationAttributeKey).map(value -> new DefaultConfigurationProperty(parentConfigurationProperties, configurationAttributeKey, value));
}
@Override
public String getDescription() {
return "Domain properties";
}
}));
}
if (!configConfigurationPropertiesProviders.isEmpty()) {
CompositeConfigurationPropertiesProvider configurationAttributesProvider = new CompositeConfigurationPropertiesProvider(configConfigurationPropertiesProviders);
parentConfigurationPropertiesResolver = of(new DefaultConfigurationPropertiesResolver(parentConfigurationPropertiesResolver, configurationAttributesProvider));
}
DefaultConfigurationPropertiesResolver globalPropertiesConfigurationPropertiesResolver = new DefaultConfigurationPropertiesResolver(parentConfigurationPropertiesResolver, globalPropertiesConfigurationAttributeProvider);
DefaultConfigurationPropertiesResolver systemPropertiesResolver = new DefaultConfigurationPropertiesResolver(of(globalPropertiesConfigurationPropertiesResolver), environmentPropertiesConfigurationProvider);
DefaultConfigurationPropertiesResolver externalPropertiesResolver = new DefaultConfigurationPropertiesResolver(of(systemPropertiesResolver), externalPropertiesConfigurationProvider);
if (deploymentProperties.isEmpty()) {
this.configurationProperties = new PropertiesResolverConfigurationProperties(externalPropertiesResolver);
} else {
this.configurationProperties = new PropertiesResolverConfigurationProperties(new DefaultConfigurationPropertiesResolver(of(externalPropertiesResolver), new MapConfigurationPropertiesProvider(deploymentProperties, "Deployment properties")));
}
}
use of org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty in project mule by mulesoft.
the class PropertiesResolverConfigurationPropertiesResolverTestCase method createResolver.
@Before
public void createResolver() {
DefaultConfigurationPropertiesResolver parentResolver = new DefaultConfigurationPropertiesResolver(Optional.empty(), new ConfigurationPropertiesProvider() {
private List<ConfigurationProperty> attributes = ImmutableList.<ConfigurationProperty>builder().add(new DefaultConfigurationProperty(this, "parent-key1", "parent-value1")).add(new DefaultConfigurationProperty(this, "parent-key2", "parent-value2")).add(new DefaultConfigurationProperty(this, "parent-complex-key1", "parent-complex-${parent-key1}")).add(new DefaultConfigurationProperty(this, "parent-complex-key2", "${parent-key1}-${parent-complex-key3}")).add(new DefaultConfigurationProperty(this, "parent-complex-key3", "${parent-key2}")).add(new DefaultConfigurationProperty(this, "parent-key-referencing-child", "${child-key1}")).build();
@Override
public Optional<ConfigurationProperty> getConfigurationProperty(String configurationAttributeKey) {
return attributes.stream().filter(cf -> cf.getKey().equals(configurationAttributeKey)).findFirst();
}
@Override
public String getDescription() {
return PARENT_RESOLVER_DESCRIPTION;
}
});
resolver = new DefaultConfigurationPropertiesResolver(Optional.of(parentResolver), new ConfigurationPropertiesProvider() {
private List<ConfigurationProperty> attributes = ImmutableList.<ConfigurationProperty>builder().add(new DefaultConfigurationProperty(this, "child-key1", "child-value1")).add(new DefaultConfigurationProperty(this, "child-key2", "child-value2")).add(new DefaultConfigurationProperty(this, "child-complex-key1", "${child-key1}-${parent-complex-key1}")).add(new DefaultConfigurationProperty(this, "child-complex-key2", "${child-key1}-${parent-complex-key2}-${child-key2}")).add(new DefaultConfigurationProperty(this, "unresolved-nested-key", "${child-key1}-${child-key3}")).add(new DefaultConfigurationProperty(this, "invalid-key1", "${nonExistentKey}")).build();
@Override
public Optional<ConfigurationProperty> getConfigurationProperty(String configurationAttributeKey) {
return attributes.stream().filter(cf -> cf.getKey().equals(configurationAttributeKey)).findFirst();
}
@Override
public String getDescription() {
return CHILD_RESOLVER_DESCRIPTION;
}
});
}
use of org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty in project mule by mulesoft.
the class DefaultConfigurationPropertiesProvider method readAttributesFromFile.
protected void readAttributesFromFile(InputStream is) throws IOException {
if (fileLocation.endsWith(PROPERTIES_EXTENSION)) {
Properties properties = new Properties();
properties.load(is);
properties.keySet().stream().map(key -> {
Object rawValue = properties.get(key);
rawValue = createValue((String) key, (String) rawValue);
return new DefaultConfigurationProperty(of(this), (String) key, rawValue);
}).forEach(configurationAttribute -> {
configurationAttributes.put(configurationAttribute.getKey(), configurationAttribute);
});
} else {
Yaml yaml = new Yaml();
Iterable<Object> yamlObjects = yaml.loadAll(is);
yamlObjects.forEach(yamlObject -> {
createAttributesFromYamlObject(null, null, yamlObject);
});
}
}
Aggregations