use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ComponentMessageProcessor method createComponentExecutor.
private ComponentExecutor<T> createComponentExecutor() {
Map<String, Object> params = new HashMap<>();
LazyValue<Optional<ConfigurationInstance>> staticConfiguration = new LazyValue<>(this::getStaticConfiguration);
LazyValue<ValueResolvingContext> resolvingContext = new LazyValue<>(() -> {
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent();
return from(initialiserEvent, staticConfiguration.get());
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
});
componentModel.getParameterGroupModels().stream().forEach(group -> {
if (group.getName().equals(DEFAULT_GROUP_NAME)) {
group.getParameterModels().stream().filter(p -> p.getModelProperty(FieldOperationParameterModelProperty.class).isPresent()).forEach(p -> {
ValueResolver<?> resolver = resolverSet.getResolvers().get(p.getName());
if (resolver != null) {
try {
params.put(getMemberName(p), resolveValue(resolver, resolvingContext.get()));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
} else {
ParameterGroupDescriptor groupDescriptor = group.getModelProperty(ParameterGroupModelProperty.class).map(g -> g.getDescriptor()).orElse(null);
if (groupDescriptor == null) {
return;
}
List<ParameterModel> fieldParameters = getGroupsOfFieldParameters(group);
if (fieldParameters.isEmpty()) {
return;
}
ObjectBuilder groupBuilder = createFieldParameterGroupBuilder(groupDescriptor, fieldParameters);
try {
params.put(((Field) groupDescriptor.getContainer()).getName(), groupBuilder.build(resolvingContext.get()));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
return getOperationExecutorFactory(componentModel).createExecutor(componentModel, params);
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ValueProviderMediator method getValues.
/**
* Given the name of a parameter or parameter group, and if the parameter supports it, this will try to resolve
* the {@link Value values} for the parameter.
*
* @param parameterName the name of the parameter to resolve their possible {@link Value values}
* @param parameterValueResolver parameter resolver required if the associated {@link ValueProvider} requires
* the value of parameters from the same parameter container.
* @param connectionSupplier supplier of connection instances related to the container and used, if necessary, by the
* {@link ValueProvider}
* @param configurationSupplier supplier of connection instances related to the container and used, if necessary, by the
* {@link ValueProvider}
* @return a {@link Set} of {@link Value} correspondent to the given parameter
* @throws ValueResolvingException if an error occurs resolving {@link Value values}
*/
public Set<Value> getValues(String parameterName, ParameterValueResolver parameterValueResolver, Supplier<Object> connectionSupplier, Supplier<Object> configurationSupplier) throws ValueResolvingException {
List<ParameterModel> parameters = getParameters(parameterName);
if (parameters.isEmpty()) {
throw new ValueResolvingException(format("Unable to find model for parameter or parameter group with name '%s'.", parameterName), INVALID_VALUE_RESOLVER_NAME);
}
ParameterModel parameterModel = parameters.get(0);
ValueProviderFactoryModelProperty factoryModelProperty = parameterModel.getModelProperty(ValueProviderFactoryModelProperty.class).orElseThrow(() -> new ValueResolvingException(format("The parameter with name '%s' is not an Values Provider", parameterName), INVALID_VALUE_RESOLVER_NAME));
try {
return resolveValues(parameters, factoryModelProperty, parameterValueResolver, connectionSupplier, configurationSupplier);
} catch (Exception e) {
throw new ValueResolvingException(format("An error occurred trying to resolve the Values for parameter '%s' of component '%s'", parameterName, containerModel.getName()), UNKNOWN, e);
}
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method sourceWithReducedBackPressureStrategies.
@Test
public void sourceWithReducedBackPressureStrategies() {
ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
SourceModel source = extensionModel.getConfigurationModels().get(0).getSourceModel("ListenPayments").get();
ParameterModel parameter = source.getAllParameterModels().stream().filter(p -> BACK_PRESSURE_STRATEGY_PARAMETER_NAME.equals(p.getName())).findAny().orElseThrow(() -> new IllegalStateException("No backPressureStrategy parameter"));
assertThat(parameter.getType(), is(instanceOf(StringType.class)));
assertThat(parameter.getDefaultValue(), is(FAIL));
EnumAnnotation enumAnnotation = parameter.getType().getAnnotation(EnumAnnotation.class).orElseThrow(() -> new IllegalStateException("No enum annotation"));
assertThat(asList(enumAnnotation.getValues()), containsInAnyOrder(FAIL.name(), DROP.name()));
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method assertSinglePrimaryContentParameter.
private void assertSinglePrimaryContentParameter(ExtensionModel extensionModel, String operationName, String defaultValue) {
OperationModel appleOperation = aggressiveGet(extensionModel.getOperationModel(operationName));
List<ParameterModel> contentParameters = appleOperation.getAllParameterModels().stream().filter(ExtensionModelUtils::isContent).collect(toList());
assertThat(contentParameters, hasSize(1));
ParameterModel contentParameter = contentParameters.get(0);
assertThat(contentParameter.isRequired(), is(false));
assertThat(contentParameter.getDefaultValue(), is(defaultValue));
assertThat(contentParameter.getRole(), is(PRIMARY_CONTENT));
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method objectStoreParameters.
@Test
public void objectStoreParameters() {
ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
OperationModel operationModel = extensionModel.getOperationModel("storeMoney").get();
ParameterModel parameter = operationModel.getAllParameterModels().stream().filter(p -> "objectStore".equals(p.getName())).findFirst().get();
StereotypeModel stereotype = parameter.getAllowedStereotypes().stream().filter(s -> s.getType().equals(OBJECT_STORE.getType())).findFirst().get();
assertThat(stereotype.getNamespace(), equalTo(OBJECT_STORE.getNamespace()));
Optional<ImportedTypeModel> typeImport = extensionModel.getImportedTypes().stream().filter(i -> getTypeId(i.getImportedType()).map(id -> ObjectStore.class.getName().equals(id)).orElse(false)).findFirst();
assertThat(typeImport.isPresent(), is(true));
}
Aggregations