Search in sources :

Example 1 with ValueProviderFactoryModelPropertyBuilder

use of org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.ValueProviderFactoryModelPropertyBuilder in project mule by mulesoft.

the class ValueProvidersParameterDeclarationEnricher method enrichParameter.

/**
 * Enriches a parameter that has an associated {@link ValueProvider}
 *
 * @param resolverClass           the class of the {@link ValueProvider}
 * @param paramDeclaration        {@link ParameterDeclaration} or {@link ParameterGroupDeclaration} paramDeclaration
 * @param containerParameterNames parameters container's names
 */
private void enrichParameter(OfValues resolverClass, BaseDeclaration paramDeclaration, Consumer<ValueProviderModel> valueProviderModelConsumer, Integer partOrder, Map<String, String> containerParameterNames, String name) {
    ValueProviderFactoryModelPropertyBuilder propertyBuilder = ValueProviderFactoryModelProperty.builder(resolverClass.value());
    ParameterizableTypeWrapper resolverClassWrapper = new ParameterizableTypeWrapper(resolverClass.value(), new DefaultExtensionsTypeLoaderFactory().createTypeLoader());
    List<ExtensionParameter> resolverParameters = resolverClassWrapper.getParametersAnnotatedWith(Parameter.class);
    resolverParameters.forEach(param -> propertyBuilder.withInjectableParameter(param.getName(), param.getType().asMetadataType(), param.isRequired()));
    Reference<Boolean> requiresConfiguration = new Reference<>(false);
    Reference<Boolean> requiresConnection = new Reference<>(false);
    enrichWithConnection(propertyBuilder, resolverClassWrapper).ifPresent(field -> requiresConnection.set(true));
    enrichWithConfiguration(propertyBuilder, resolverClassWrapper).ifPresent(field -> requiresConfiguration.set(true));
    paramDeclaration.addModelProperty(propertyBuilder.build());
    valueProviderModelConsumer.accept(new ValueProviderModel(getRequiredParametersAliases(resolverParameters, containerParameterNames), requiresConfiguration.get(), requiresConnection.get(), resolverClass.open(), partOrder, name));
}
Also used : ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ParameterizableTypeWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.ParameterizableTypeWrapper) Reference(org.mule.runtime.api.util.Reference) DefaultExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.DefaultExtensionsTypeLoaderFactory) ValueProviderFactoryModelPropertyBuilder(org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.ValueProviderFactoryModelPropertyBuilder) ValueProviderModel(org.mule.runtime.api.meta.model.parameter.ValueProviderModel)

Example 2 with ValueProviderFactoryModelPropertyBuilder

use of org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.ValueProviderFactoryModelPropertyBuilder in project mule by mulesoft.

the class ValueProviderModelValidatorTestCase method valueProviderShouldBeInstantiable.

@Test
public void valueProviderShouldBeInstantiable() {
    ValueProviderFactoryModelPropertyBuilder builder = ValueProviderFactoryModelProperty.builder(NonInstantiableProvider.class);
    when(operationParameter.getModelProperty(ValueProviderFactoryModelProperty.class)).thenReturn(Optional.of(builder.build()));
    validate();
    assertProblems("The Value Provider [NonInstantiableProvider] is not instantiable but it should");
}
Also used : ValueProviderFactoryModelPropertyBuilder(org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.ValueProviderFactoryModelPropertyBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ValueProviderFactoryModelPropertyBuilder (org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.ValueProviderFactoryModelPropertyBuilder)2 Test (org.junit.Test)1 ValueProviderModel (org.mule.runtime.api.meta.model.parameter.ValueProviderModel)1 Reference (org.mule.runtime.api.util.Reference)1 DefaultExtensionsTypeLoaderFactory (org.mule.runtime.extension.api.declaration.type.DefaultExtensionsTypeLoaderFactory)1 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)1 ParameterizableTypeWrapper (org.mule.runtime.module.extension.internal.loader.java.type.runtime.ParameterizableTypeWrapper)1 SmallTest (org.mule.tck.size.SmallTest)1