Search in sources :

Example 1 with NotSupportedException

use of alien4cloud.paas.exception.NotSupportedException in project alien4cloud by alien4cloud.

the class FunctionEvaluator method getPropertyValue.

private static AbstractPropertyValue getPropertyValue(Map<String, AbstractPropertyValue> properties, Map<String, PropertyDefinition> propertyDefinitions, String propertyAccessPath) {
    if (properties == null || !properties.containsKey(propertyAccessPath)) {
        String propertyName = PropertyUtil.getPropertyNameFromComplexPath(propertyAccessPath);
        if (propertyName == null) {
            // Non complex
            return PropertyUtil.getDefaultFromPropertyDefinitions(propertyAccessPath, propertyDefinitions);
        } else {
            // Complex
            PropertyDefinition propertyDefinition = propertyDefinitions.get(propertyName);
            AbstractPropertyValue rawValue;
            if (propertyDefinition == null) {
                return null;
            } else if (ToscaTypes.isSimple(propertyDefinition.getType())) {
                // It's a complex path (with '.') but the type in definition is finally simple
                return null;
            } else if (properties != null && (rawValue = properties.get(propertyName)) != null) {
                if (!(rawValue instanceof PropertyValue)) {
                    throw new NotSupportedException("Only support static value in a get_property");
                }
                Object value = MapUtil.get(((PropertyValue) rawValue).getValue(), propertyAccessPath.substring(propertyName.length() + 1));
                return new ScalarPropertyValue(PropertyUtil.serializePropertyValue(value));
            } else {
                return null;
            }
        }
    } else {
        return properties.get(propertyAccessPath);
    }
}
Also used : ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) NotSupportedException(alien4cloud.paas.exception.NotSupportedException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

NotSupportedException (alien4cloud.paas.exception.NotSupportedException)1 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)1 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)1 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)1 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)1 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)1 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)1