use of org.mule.runtime.api.meta.model.function.FunctionModel in project mule by mulesoft.
the class NameClashModelValidatorTestCase method differentFunctionNames.
@Test
public void differentFunctionNames() {
FunctionModel anotherFunctionModel = mock(FunctionModel.class);
when(anotherFunctionModel.getName()).thenReturn("another-" + FUNCTION_NAME);
when(anotherFunctionModel.getAllParameterModels()).thenReturn(emptyList());
when(extensionModel.getFunctionModels()).thenReturn(asList(functionModel, anotherFunctionModel));
validate();
}
use of org.mule.runtime.api.meta.model.function.FunctionModel in project mule by mulesoft.
the class ReflectiveFunctionExecutorFactory method createExecutor.
@Override
public FunctionExecutor createExecutor(FunctionModel functionModel, FunctionParameterDefaultValueResolverFactory defaultResolverFactory) {
DataType returnType = fromType(getType(functionModel.getOutput().getType()).orElseThrow(() -> new MuleRuntimeException(createStaticMessage(format("Failed to obtain the return type for function [%s]", functionModel.getName())))));
List<FunctionParameter> functionParameters = functionModel.getAllParameterModels().stream().map(p -> {
MetadataType paramType = p.getType();
DataType type = isTypedValue(paramType) ? fromType(TypedValue.class) : toDataType(paramType);
if (p.isRequired()) {
return new FunctionParameter(p.getName(), type);
}
Object defaultValue = p.getDefaultValue();
if (defaultValue == null) {
return new FunctionParameter(p.getName(), type, context -> Defaults.defaultValue(type.getType()));
}
return new FunctionParameter(p.getName(), type, defaultResolverFactory.create(defaultValue, type));
}).collect(toList());
return new ReflectiveExpressionFunctionExecutor(functionModel, returnType, functionParameters, method, getDelegateInstance());
}
use of org.mule.runtime.api.meta.model.function.FunctionModel in project mule by mulesoft.
the class ExtensionActivator method registerExpressionFunctions.
private void registerExpressionFunctions(Stream<FunctionModel> functions, ExpressionModule.Builder module) {
final FunctionParameterDefaultValueResolverFactory valueResolverFactory = (defaultValue, type) -> context -> {
ExtendedExpressionManager em = muleContext.getExpressionManager();
String value = String.valueOf(defaultValue);
return em.isExpression(value) ? em.evaluate(value, type, context) : new TypedValue<>(defaultValue, type);
};
functions.forEach(function -> function.getModelProperty(FunctionExecutorModelProperty.class).ifPresent(mp -> {
FunctionExecutor executor = mp.getExecutorFactory().createExecutor(function, valueResolverFactory);
lifecycleAwareElements.add(executor);
module.addBinding(function.getName(), new TypedValue<>(executor, fromFunction(executor)));
}));
}
use of org.mule.runtime.api.meta.model.function.FunctionModel in project mule by mulesoft.
the class NameClashModelValidatorTestCase method repeatedFunctionNames.
@Test
public void repeatedFunctionNames() {
exception.expect(IllegalModelDefinitionException.class);
FunctionModel anotherFunctionModel = mock(FunctionModel.class);
when(anotherFunctionModel.getName()).thenReturn(FUNCTION_NAME);
when(anotherFunctionModel.getAllParameterModels()).thenReturn(emptyList());
when(extensionModel.getFunctionModels()).thenReturn(asList(functionModel, anotherFunctionModel));
validate();
}
Aggregations