Search in sources :

Example 1 with ConfigurationPropertiesException

use of org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesException 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));
    }
}
Also used : ResourceProvider(org.mule.runtime.config.api.dsl.model.ResourceProvider) Properties(java.util.Properties) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Optional.of(java.util.Optional.of) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) IOException(java.io.IOException) HashMap(java.util.HashMap) NoExtend(org.mule.api.annotation.NoExtend) FileInputStream(java.io.FileInputStream) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) ConfigurationPropertiesException(org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesException) String.format(java.lang.String.format) File(java.io.File) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) Yaml(org.yaml.snakeyaml.Yaml) List(java.util.List) String.join(java.lang.String.join) Map(java.util.Map) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) Optional(java.util.Optional) DefaultConfigurationProperty(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty) InputStream(java.io.InputStream) ConfigurationPropertiesException(org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesException) DefaultConfigurationProperty(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 String.format (java.lang.String.format)1 String.join (java.lang.String.join)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.of (java.util.Optional.of)1 Properties (java.util.Properties)1 NoExtend (org.mule.api.annotation.NoExtend)1 AbstractComponent (org.mule.runtime.api.component.AbstractComponent)1 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 Initialisable (org.mule.runtime.api.lifecycle.Initialisable)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ResourceProvider (org.mule.runtime.config.api.dsl.model.ResourceProvider)1 ConfigurationPropertiesException (org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesException)1