Search in sources :

Example 1 with ParameterValueDescriptor

use of eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor in project hale by halestudio.

the class ParameterBinding method getProperty.

@Override
public Object getProperty(String property) {
    boolean getAsList = true;
    final Optional<FunctionParameterDefinition> paramDef;
    if (function != null) {
        paramDef = function.getDefinedParameters().stream().filter(param -> Objects.equals(property, param.getName())).findFirst();
    } else {
        paramDef = Optional.empty();
    }
    if (paramDef.isPresent()) {
        if (paramDef.get().getMaxOccurrence() == 1) {
            getAsList = false;
        }
    }
    List<ParameterValue> values;
    if (cell != null && cell.getTransformationParameters() != null) {
        values = cell.getTransformationParameters().get(property);
    } else {
        values = Collections.emptyList();
    }
    if (getAsList) {
        // yield parameters as list
        return values.stream().map(value -> extractParameterValue(value, paramDef)).collect(Collectors.toList());
    } else {
        // yield parameter value or null if there is none
        if (values.isEmpty()) {
            if (paramDef.isPresent()) {
                ParameterValueDescriptor descriptor = paramDef.get().getValueDescriptor();
                if (descriptor != null && descriptor.getDefaultValue() != null) {
                    // use default value as parameter value
                    return extractParameterValue(new ParameterValue(descriptor.getDefaultValue()), paramDef);
                }
            }
            return null;
        } else {
            return extractParameterValue(values.get(0), paramDef);
        }
    }
}
Also used : Objects(java.util.Objects) List(java.util.List) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ParameterValueDescriptor(eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor) Optional(java.util.Optional) GroovyObjectSupport(groovy.lang.GroovyObjectSupport) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) ParameterValueDescriptor(eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)

Aggregations

FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)1 FunctionParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)1 ParameterValueDescriptor (eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor)1 GroovyObjectSupport (groovy.lang.GroovyObjectSupport)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1