Search in sources :

Example 6 with ListPropertyValue

use of org.alien4cloud.tosca.model.definitions.ListPropertyValue in project alien4cloud by alien4cloud.

the class FunctionEvaluator method getFromPath.

private static AbstractPropertyValue getFromPath(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, Map<String, AbstractPropertyValue> properties, String propertyPath) {
    if (propertyPath.contains(".")) {
        String propertyName = propertyPath.split("\\.")[0];
        AbstractPropertyValue propertyValue = properties.get(propertyName);
        if (!(propertyValue instanceof PropertyValue)) {
            // if the value is not a property value resolve it first
            propertyValue = tryResolveValue(evaluatorContext, targetTemplate, properties, propertyValue);
            if (propertyValue == null) {
                return null;
            }
        }
        // now it is a property value
        Object value = MapUtil.get(((PropertyValue) propertyValue).getValue(), propertyPath.substring(propertyName.length() + 1));
        if (value == null) {
            return null;
        } else if (value instanceof String) {
            return new ScalarPropertyValue((String) value);
        } else if (value instanceof List) {
            return new ListPropertyValue((List<Object>) value);
        } else if (value instanceof Map) {
            return new ComplexPropertyValue((Map<String, Object>) value);
        }
        throw new IllegalArgumentException("The value of a property must be a scalar, a list or a map.");
    }
    return safe(properties).get(propertyPath);
}
Also used : ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) 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) ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) List(java.util.List) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Map(java.util.Map)

Aggregations

ListPropertyValue (org.alien4cloud.tosca.model.definitions.ListPropertyValue)6 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)5 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)5 Map (java.util.Map)4 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)4 List (java.util.List)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 NotFoundException (alien4cloud.exception.NotFoundException)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)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 DataType (org.alien4cloud.tosca.model.types.DataType)1 PrimitiveDataType (org.alien4cloud.tosca.model.types.PrimitiveDataType)1 Test (org.junit.Test)1