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);
}
}
}
Aggregations