Search in sources :

Example 41 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class MacroExpansionModuleModel method lookForOperation.

/**
 * Looks for an operation checking if it is defined within the scope of a {@link ConfigurationModel} or the
 * {@link ExtensionModel}.
 *
 * @param operationIdentifier element to look for in the current {@link #extensionModel}
 * @param prefix to check if the {@code operationIdentifier} namespace targets an operation of the <module/> (usually maps to
 *        the {@link ExtensionModel} prefix, or the {@link #TNS_PREFIX}.
 * @return an {@link OperationModel} if found, {@link Optional#empty()} otherwise.
 */
private Optional<OperationModel> lookForOperation(ComponentIdentifier operationIdentifier, String prefix) {
    Optional<OperationModel> result = Optional.empty();
    final String operationName = operationIdentifier.getName();
    if (operationIdentifier.getNamespace().equals(prefix)) {
        // As the operation can be inside the extension or the config, it has to be looked up in both elements.
        final HasOperationModels hasOperationModels = getConfigurationModel().map(configurationModel -> (HasOperationModels) configurationModel).orElse(extensionModel);
        result = hasOperationModels.getOperationModel(operationName);
    }
    // If the operation is not present, it might be a private one and it must be looked inside of the model property
    if (!result.isPresent() && extensionModel.getModelProperty(PrivateOperationsModelProperty.class).isPresent()) {
        result = extensionModel.getModelProperty(PrivateOperationsModelProperty.class).get().getOperationModel(operationName);
    }
    return result;
}
Also used : HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) IntStream(java.util.stream.IntStream) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) HashMap(java.util.HashMap) Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) CommonBeanDefinitionCreator(org.mule.runtime.config.internal.dsl.spring.CommonBeanDefinitionCreator) MODULE_OPERATION_CHAIN(org.mule.runtime.config.internal.model.ApplicationModel.MODULE_OPERATION_CHAIN) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) Map(java.util.Map) NAME_ATTRIBUTE(org.mule.runtime.config.internal.model.ApplicationModel.NAME_ATTRIBUTE) Collectors.toSet(java.util.stream.Collectors.toSet) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) Collections.emptyMap(java.util.Collections.emptyMap) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) VARS(org.mule.runtime.api.el.BindingContextUtils.VARS) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) MODULE_CONFIG_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONFIG_GLOBAL_ELEMENT_NAME) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 42 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class ModuleOperationMessageProcessorChainFactoryBean method getOperationModelOrFail.

private OperationModel getOperationModelOrFail(ExtensionModel extensionModel) {
    OperationSeeker operationSeeker = new OperationSeeker();
    operationSeeker.walk(extensionModel);
    final OperationModel operationModel = operationSeeker.operationModel.orElseGet(() -> extensionModel.getModelProperty(PrivateOperationsModelProperty.class).get().getOperationModel(moduleOperation).orElseThrow(() -> new IllegalArgumentException(format("Could not find any operation under the name of [%s] for the extension [%s]", moduleOperation, moduleName))));
    return operationModel;
}
Also used : OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 43 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class CoreExtensionModelTestCase method flowRef.

@Test
public void flowRef() {
    final OperationModel flowRefModel = coreExtensionModel.getOperationModel("flowRef").get();
    assertThat(flowRefModel.getStereotype(), is(PROCESSOR));
    assertAssociatedProcessorsChangeOutput(flowRefModel);
    assertThat(flowRefModel.getAllParameterModels(), hasSize(3));
    assertThat(flowRefModel.getAllParameterModels().get(0).getName(), is("name"));
    assertThat(flowRefModel.getAllParameterModels().get(0).getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(flowRefModel.getAllParameterModels().get(0).getType(), instanceOf(DefaultStringType.class));
    assertThat(flowRefModel.getAllParameterModels().get(0).isRequired(), is(true));
    assertTarget(flowRefModel.getAllParameterModels().get(1));
}
Also used : DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 44 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class DefaultExtensionSchemaGenerator method generate.

/**
 * {@inheritDoc}
 */
@Override
public String generate(ExtensionModel extensionModel, DslResolvingContext dslContext) {
    XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
    validate(extensionModel, xmlDslModel);
    SchemaBuilder schemaBuilder = SchemaBuilder.newSchema(extensionModel, xmlDslModel, dslContext);
    new IdempotentExtensionWalker() {

        @Override
        public void onConfiguration(ConfigurationModel model) {
            schemaBuilder.registerConfigElement(model);
        }

        @Override
        protected void onConstruct(ConstructModel model) {
            schemaBuilder.registerOperation(model);
        }

        @Override
        public void onOperation(OperationModel model) {
            schemaBuilder.registerOperation(model);
        }

        @Override
        public void onConnectionProvider(ConnectionProviderModel model) {
            schemaBuilder.registerConnectionProviderElement(model);
        }

        @Override
        public void onSource(SourceModel model) {
            schemaBuilder.registerMessageSource(model);
        }
    }.walk(extensionModel);
    schemaBuilder.registerEnums();
    // Make sure the XML libs use the container classloader internally
    return withContextClassLoader(DefaultExtensionSchemaGenerator.class.getClassLoader(), () -> renderSchema(schemaBuilder.build()));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) SchemaBuilder(org.mule.runtime.module.extension.internal.capability.xml.schema.builder.SchemaBuilder) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 45 with OperationModel

use of org.mule.runtime.api.meta.model.operation.OperationModel in project mule by mulesoft.

the class SoapOperationExecutor method execute.

/**
 * {@inheritDoc}
 */
@Override
public Publisher<Object> execute(ExecutionContext<OperationModel> context) {
    try {
        String serviceId = context.getParameter(SERVICE_PARAM);
        ForwardingSoapClient connection = (ForwardingSoapClient) connectionResolver.resolve(context).get();
        Map<String, String> customHeaders = connection.getCustomHeaders(serviceId, getOperation(context));
        SoapRequest request = getRequest(context, customHeaders);
        SoapClient soapClient = connection.getSoapClient(serviceId);
        SoapResponse response = connection.getExtensionsClientDispatcher(() -> new ExtensionsClientArgumentResolver(registry, policyManager).resolve(context).get()).map(d -> soapClient.consume(request, d)).orElseGet(() -> soapClient.consume(request));
        return justOrEmpty(response.getAsResult(streamingHelperArgumentResolver.resolve(context).get()));
    } catch (MessageTransformerException | TransformerException e) {
        return error(e);
    } catch (Exception e) {
        return error(soapExceptionEnricher.enrich(e));
    } catch (Throwable t) {
        return error(wrapFatal(t));
    }
}
Also used : HEADERS_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.HEADERS_PARAM) Exceptions.wrapFatal(org.mule.runtime.core.api.rx.Exceptions.wrapFatal) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) BindingContext(org.mule.runtime.api.el.BindingContext) MuleExpressionLanguage(org.mule.runtime.api.el.MuleExpressionLanguage) ComponentExecutor(org.mule.runtime.extension.api.runtime.operation.ComponentExecutor) ATTACHMENTS_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.ATTACHMENTS_PARAM) HashMap(java.util.HashMap) SoapRequestBuilder(org.mule.runtime.soap.api.message.SoapRequestBuilder) Inject(javax.inject.Inject) ExtensionsClientArgumentResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExtensionsClientArgumentResolver) ConnectionArgumentResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionArgumentResolver) MESSAGE_GROUP(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.MESSAGE_GROUP) SoapClient(org.mule.runtime.soap.api.client.SoapClient) Map(java.util.Map) SoapResponse(org.mule.runtime.soap.api.message.SoapResponse) Registry(org.mule.runtime.api.artifact.Registry) IOUtils(org.mule.runtime.core.api.util.IOUtils) PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) Mono.error(reactor.core.publisher.Mono.error) INPUT_STREAM(org.mule.runtime.api.metadata.DataType.INPUT_STREAM) BODY_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.BODY_PARAM) TransformationService(org.mule.runtime.api.transformation.TransformationService) ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) OPERATION_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.OPERATION_PARAM) DataType(org.mule.runtime.api.metadata.DataType) Publisher(org.reactivestreams.Publisher) SoapRequest(org.mule.runtime.soap.api.message.SoapRequest) Mono.justOrEmpty(reactor.core.publisher.Mono.justOrEmpty) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) SoapAttachment(org.mule.runtime.extension.api.soap.SoapAttachment) SERVICE_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.SERVICE_PARAM) TypedValue(org.mule.runtime.api.metadata.TypedValue) TRANSPORT_HEADERS_PARAM(org.mule.runtime.module.extension.soap.internal.loader.SoapInvokeOperationDeclarer.TRANSPORT_HEADERS_PARAM) StreamingHelperArgumentResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StreamingHelperArgumentResolver) ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) ExtensionsClient(org.mule.runtime.extension.api.client.ExtensionsClient) Optional(java.util.Optional) SoapExceptionEnricher(org.mule.runtime.soap.api.exception.error.SoapExceptionEnricher) InputStream(java.io.InputStream) SoapClient(org.mule.runtime.soap.api.client.SoapClient) ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) SoapRequest(org.mule.runtime.soap.api.message.SoapRequest) SoapResponse(org.mule.runtime.soap.api.message.SoapResponse) ExtensionsClientArgumentResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExtensionsClientArgumentResolver) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException)

Aggregations

OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)96 Test (org.junit.Test)68 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)29 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)27 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)15 SmallTest (org.mule.tck.size.SmallTest)14 Optional (java.util.Optional)13 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)12 MetadataType (org.mule.metadata.api.model.MetadataType)11 List (java.util.List)10 Set (java.util.Set)9 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)9 Optional.empty (java.util.Optional.empty)8 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)8 ObjectType (org.mule.metadata.api.model.ObjectType)7 OutputModel (org.mule.runtime.api.meta.model.OutputModel)7 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)7 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)7 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)7 OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)6