Search in sources :

Example 1 with ParameterBinding

use of eu.esdihumboldt.hale.common.align.model.impl.mdexpl.ParameterBinding in project hale by halestudio.

the class CustomGroovyTransformation method createGroovyBinding.

private Binding createGroovyBinding(ListMultimap<String, PropertyValue> variables, Cell cell, Cell typeCell, InstanceBuilder builder, TransformationLog log, ExecutionContext executionContext, TypeDefinition targetInstanceType) {
    Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, executionContext, targetInstanceType);
    // create bindings for inputs
    for (DefaultCustomPropertyFunctionEntity source : customFunction.getSources()) {
        String varName = source.getName();
        boolean useInstanceVariable = useInstanceVariableForSource(source);
        List<PropertyValue> values = variables.get(varName);
        if (source.isEager() || source.getMaxOccurrence() > 1 || source.getMaxOccurrence() == ParameterDefinition.UNBOUNDED) {
            // multiple values
            InstanceAccessorArrayList<Object> valueList = new InstanceAccessorArrayList<>();
            for (PropertyValue value : values) {
                valueList.add(GroovyTransformation.getUseValue(value.getValue(), useInstanceVariable));
            }
            binding.setVariable(varName, valueList);
        } else {
            // single value
            if (values.isEmpty()) {
                // no value
                // -> use null value for missing variable
                binding.setVariable(varName, null);
            } else {
                // value
                binding.setVariable(varName, GroovyTransformation.getUseValue(values.get(0).getValue(), useInstanceVariable));
            }
        }
    }
    // create binding(s) for parameters
    binding.setVariable(BINDING_PARAMS, new ParameterBinding(cell, customFunction.getDescriptor()));
    return binding;
}
Also used : Binding(groovy.lang.Binding) ParameterBinding(eu.esdihumboldt.hale.common.align.model.impl.mdexpl.ParameterBinding) InstanceAccessorArrayList(eu.esdihumboldt.cst.functions.groovy.internal.InstanceAccessorArrayList) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) DefaultCustomPropertyFunctionEntity(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunctionEntity) ParameterBinding(eu.esdihumboldt.hale.common.align.model.impl.mdexpl.ParameterBinding)

Aggregations

InstanceAccessorArrayList (eu.esdihumboldt.cst.functions.groovy.internal.InstanceAccessorArrayList)1 DefaultCustomPropertyFunctionEntity (eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunctionEntity)1 ParameterBinding (eu.esdihumboldt.hale.common.align.model.impl.mdexpl.ParameterBinding)1 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)1 Binding (groovy.lang.Binding)1