Search in sources :

Example 1 with DefaultExtensionsTypeLoaderFactory

use of org.mule.runtime.extension.api.declaration.type.DefaultExtensionsTypeLoaderFactory 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 DefaultExtensionsTypeLoaderFactory

use of org.mule.runtime.extension.api.declaration.type.DefaultExtensionsTypeLoaderFactory in project mule by mulesoft.

the class OperationMessageProcessorTestCase method setUpOperationReturning.

private void setUpOperationReturning(Object payload, Type type) throws InitialisationException {
    messageProcessor = createOperationMessageProcessor();
    MetadataType mapType = new DefaultExtensionsTypeLoaderFactory().createTypeLoader().load(type);
    when(operationModel.getOutput()).thenReturn(new ImmutableOutputModel("desc", mapType, false, emptySet()));
    initialiseIfNeeded(messageProcessor, muleContext);
    when(operationExecutor.execute(any(ExecutionContext.class))).thenReturn(just(payload));
}
Also used : ImmutableOutputModel(org.mule.runtime.extension.api.model.ImmutableOutputModel) ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) DefaultExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.DefaultExtensionsTypeLoaderFactory) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionsTestUtils.toMetadataType(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.toMetadataType)

Aggregations

DefaultExtensionsTypeLoaderFactory (org.mule.runtime.extension.api.declaration.type.DefaultExtensionsTypeLoaderFactory)2 MetadataType (org.mule.metadata.api.model.MetadataType)1 ValueProviderModel (org.mule.runtime.api.meta.model.parameter.ValueProviderModel)1 Reference (org.mule.runtime.api.util.Reference)1 ImmutableOutputModel (org.mule.runtime.extension.api.model.ImmutableOutputModel)1 ExecutionContext (org.mule.runtime.extension.api.runtime.operation.ExecutionContext)1 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)1 ValueProviderFactoryModelPropertyBuilder (org.mule.runtime.module.extension.internal.loader.java.property.ValueProviderFactoryModelProperty.ValueProviderFactoryModelPropertyBuilder)1 ParameterizableTypeWrapper (org.mule.runtime.module.extension.internal.loader.java.type.runtime.ParameterizableTypeWrapper)1 ExtensionsTestUtils.toMetadataType (org.mule.test.module.extension.internal.util.ExtensionsTestUtils.toMetadataType)1