Search in sources :

Example 6 with ValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver in project mule by mulesoft.

the class DefaultExtensionsClient method createProcessor.

/**
 * Creates a new {@link OperationMessageProcessor} for the required operation and parses all the parameters passed by the client
 * user.
 */
private OperationMessageProcessor createProcessor(String extensionName, String operationName, OperationParameters parameters) {
    ExtensionModel extension = findExtension(extensionName);
    OperationModel operation = findOperation(extension, operationName);
    ConfigurationProvider config = parameters.getConfigName().map(this::findConfiguration).orElse(null);
    Map<String, ValueResolver> resolvedParams = resolveParameters(parameters.get(), getEvent());
    try {
        OperationMessageProcessor processor = new OperationMessageProcessorBuilder(extension, operation, policyManager, muleContext, registry).setConfigurationProvider(config).setParameters(resolvedParams).build();
        initialiseIfNeeded(processor, muleContext);
        processor.start();
        return processor;
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage("Could not create Operation Message Processor"), e);
    }
}
Also used : OperationMessageProcessorBuilder(org.mule.runtime.module.extension.internal.runtime.operation.OperationMessageProcessorBuilder) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) ExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionValueResolver) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) OperationMessageProcessor(org.mule.runtime.module.extension.internal.runtime.operation.OperationMessageProcessor) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 7 with ValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver in project mule by mulesoft.

the class OAuthConnectionProviderObjectBuilder method buildOAuthObjectStoreConfig.

private Optional<OAuthObjectStoreConfig> buildOAuthObjectStoreConfig(CoreEvent event) throws MuleException {
    final ValueResolver resolver = resolverSet.getResolvers().get(OAUTH_STORE_CONFIG_GROUP_NAME);
    if (resolver == null) {
        return empty();
    }
    Map<String, Object> map = (Map<String, Object>) resolver.resolve(from(event));
    return map != null ? of(new OAuthObjectStoreConfig((String) map.get(OBJECT_STORE_PARAMETER_NAME))) : empty();
}
Also used : MapValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.MapValueResolver) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with ValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver in project mule by mulesoft.

the class MuleExtensionUtils method toMap.

public static Map<String, Object> toMap(ResolverSet resolverSet, CoreEvent event) throws MuleException {
    final ValueResolvingContext ctx = from(event);
    ImmutableMap.Builder<String, Object> map = ImmutableMap.builder();
    for (Entry<String, ValueResolver<?>> entry : resolverSet.getResolvers().entrySet()) {
        Object value = entry.getValue().resolve(ctx);
        if (value != null) {
            map.put(entry.getKey(), value);
        }
    }
    return map.build();
}
Also used : ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) ValueResolvingContext(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with ValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver in project mule by mulesoft.

the class DefaultObjectBuilderTestCase method getResolver.

private ValueResolver getResolver(Object value, boolean dynamic) throws Exception {
    ValueResolver resolver = ExtensionsTestUtils.getResolver(value, resolvingContext, dynamic);
    resolvers.add(resolver);
    return resolver;
}
Also used : ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver)

Example 10 with ValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver in project mule by mulesoft.

the class ExtensionsTestUtils method getResolver.

public static ValueResolver getResolver(Object value, ValueResolvingContext context, boolean dynamic, Class<?>... extraInterfaces) throws Exception {
    ValueResolver resolver;
    if (isEmpty(extraInterfaces)) {
        resolver = mock(ValueResolver.class);
    } else {
        resolver = mock(ValueResolver.class, withSettings().extraInterfaces(extraInterfaces));
    }
    when(resolver.resolve(context != null ? same(context) : any(ValueResolvingContext.class))).thenReturn(value);
    when(resolver.isDynamic()).thenReturn(dynamic);
    return resolver;
}
Also used : ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver)

Aggregations

ValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver)18 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)6 StaticValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver)6 HashMap (java.util.HashMap)5 MuleException (org.mule.runtime.api.exception.MuleException)5 ExpressionBasedParameterResolverValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver)4 ExpressionTypedValueValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver)4 NativeQueryParameterValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver)4 ProcessorChainValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver)4 StaticLiteralValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver)4 TypeSafeExpressionValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver)4 Map (java.util.Map)3 Optional (java.util.Optional)3 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2