Search in sources :

Example 6 with OperationDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.

the class OperationModelLoaderDelegate method declareOperations.

void declareOperations(ExtensionDeclarer extensionDeclarer, HasOperationDeclarer ownerDeclarer, OperationContainerElement methodOwnerClass, List<OperationElement> operations, boolean supportsConfig) {
    for (OperationElement operationMethod : operations) {
        OperationContainerElement methodOwner = operationMethod.getEnclosingType();
        OperationContainerElement enclosingType = methodOwnerClass != null ? methodOwnerClass : methodOwner;
        checkOperationIsNotAnExtension(methodOwner);
        final Optional<ExtensionParameter> configParameter = loader.getConfigParameter(operationMethod);
        final Optional<ExtensionParameter> connectionParameter = loader.getConnectionParameter(operationMethod);
        if (isScope(operationMethod)) {
            scopesDelegate.declareScope(extensionDeclarer, ownerDeclarer, enclosingType, operationMethod, configParameter, connectionParameter);
            continue;
        } else if (isRouter(operationMethod)) {
            routersDelegate.declareRouter(extensionDeclarer, ownerDeclarer, enclosingType, operationMethod, configParameter, connectionParameter);
            continue;
        }
        checkDefinition(!loader.isInvalidConfigSupport(supportsConfig, configParameter, connectionParameter), format("Operation '%s' is defined at the extension level but it requires a config. " + "Remove such parameter or move the operation to the proper config", operationMethod.getName()));
        HasOperationDeclarer actualDeclarer = selectDeclarer(extensionDeclarer, (Declarer) ownerDeclarer, operationMethod, configParameter, connectionParameter);
        if (operationDeclarers.containsKey(operationMethod)) {
            actualDeclarer.withOperation(operationDeclarers.get(operationMethod));
            continue;
        }
        final OperationDeclarer operationDeclarer = actualDeclarer.withOperation(operationMethod.getAlias());
        operationDeclarer.withModelProperty(new ExtensionOperationDescriptorModelProperty(operationMethod));
        Optional<Method> method = operationMethod.getMethod();
        Optional<Class<?>> declaringClass = enclosingType.getDeclaringClass();
        if (method.isPresent() && declaringClass.isPresent()) {
            operationDeclarer.withModelProperty(new ImplementingMethodModelProperty(method.get())).withModelProperty(new ComponentExecutorModelProperty(new ReflectiveOperationExecutorFactory<>(declaringClass.get(), method.get())));
        }
        loader.addExceptionEnricher(operationMethod, operationDeclarer);
        final List<ExtensionParameter> fieldParameters = methodOwner.getParameters();
        processComponentConnectivity(operationDeclarer, operationMethod, operationMethod);
        if (isNonBlocking(operationMethod)) {
            processNonBlockingOperation(operationDeclarer, operationMethod, true);
        } else {
            processBlockingOperation(supportsConfig, operationMethod, operationDeclarer);
        }
        addExecutionType(operationDeclarer, operationMethod);
        ParameterDeclarationContext declarationContext = new ParameterDeclarationContext(OPERATION, operationDeclarer.getDeclaration());
        processMimeType(operationDeclarer, operationMethod);
        declareParameters(operationDeclarer, operationMethod.getParameters(), fieldParameters, declarationContext);
        operationDeclarers.put(operationMethod, operationDeclarer);
    }
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) OperationElement(org.mule.runtime.module.extension.api.loader.java.type.OperationElement) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) OperationContainerElement(org.mule.runtime.module.extension.api.loader.java.type.OperationContainerElement) Method(java.lang.reflect.Method) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)

Example 7 with OperationDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.

the class ScopeModelLoaderDelegate method declareScope.

void declareScope(ExtensionDeclarer extensionDeclarer, HasOperationDeclarer ownerDeclarer, OperationContainerElement enclosingType, OperationElement scopeMethod, Optional<ExtensionParameter> configParameter, Optional<ExtensionParameter> connectionParameter) {
    HasOperationDeclarer actualDeclarer = (HasOperationDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) ownerDeclarer, configParameter, connectionParameter);
    checkDefinition(!configParameter.isPresent(), format("Scope '%s' requires a config, but that is not allowed, remove such parameter", scopeMethod.getName()));
    checkDefinition(!connectionParameter.isPresent(), format("Scope '%s' requires a connection, but that is not allowed, remove such parameter", scopeMethod.getName()));
    checkDefinition(isNonBlocking(scopeMethod), format("Scope '%s' does not declare a '%s' parameter. One is required for all operations " + "that receive and execute a Chain of other components", scopeMethod.getAlias(), CompletionCallback.class.getSimpleName()));
    if (operationDeclarers.containsKey(scopeMethod)) {
        actualDeclarer.withOperation(operationDeclarers.get(scopeMethod));
        return;
    }
    final OperationDeclarer scope = actualDeclarer.withOperation(scopeMethod.getAlias());
    scope.withModelProperty(new ExtensionOperationDescriptorModelProperty(scopeMethod));
    Optional<Method> method = scopeMethod.getMethod();
    Optional<Class<?>> declaringClass = enclosingType.getDeclaringClass();
    if (method.isPresent() && declaringClass.isPresent()) {
        scope.withModelProperty(new ImplementingMethodModelProperty(method.get())).withModelProperty(new ComponentExecutorModelProperty(new ReflectiveOperationExecutorFactory<>(declaringClass.get(), method.get())));
    }
    processMimeType(scope, scopeMethod);
    processNonBlockingOperation(scope, scopeMethod, false);
    List<ExtensionParameter> processorChain = scopeMethod.getParameters().stream().filter(ModelLoaderUtils::isProcessorChain).collect(toList());
    checkDefinition(processorChain.size() <= 1, format("Scope '%s' declares too many parameters of type '%s', only one input of this kind is supported." + "Offending parameters are: %s", scopeMethod.getAlias(), Chain.class.getSimpleName(), processorChain.stream().map(ExtensionParameter::getName).collect(toList())));
    declareParameters(scope, scopeMethod.getParameters(), scopeMethod.getEnclosingType().getParameters(), new ParameterDeclarationContext(SCOPE, scope.getDeclaration()));
    loader.addExceptionEnricher(scopeMethod, scope);
    operationDeclarers.put(scopeMethod, scope);
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) Method(java.lang.reflect.Method) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)

Example 8 with OperationDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.

the class XmlExtensionLoaderDelegate method declareErrorModels.

private void declareErrorModels(OperationDeclarer operationDeclarer, XmlDslModel xmlDslModel, String operationName, ComponentModel operationModel) {
    Optional<ComponentModel> optionalParametersComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_ERRORS_IDENTIFIER)).findAny();
    optionalParametersComponentModel.ifPresent(componentModel -> componentModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_ERROR_IDENTIFIER)).forEach(param -> {
        final String namespace = xmlDslModel.getPrefix().toUpperCase();
        final String typeName = param.getParameters().get(ERROR_TYPE_ATTRIBUTE);
        if (StringUtils.isBlank(typeName)) {
            throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> with an empty 'type' attribute", operationName));
        }
        if (typeName.contains(NAMESPACE_SEPARATOR)) {
            throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> [%s] that contains a reserved character [%s]", operationName, typeName, NAMESPACE_SEPARATOR));
        }
        operationDeclarer.withErrorModel(ErrorModelBuilder.newError(typeName, namespace).withParent(ErrorModelBuilder.newError(ANY).build()).build());
    }));
}
Also used : PRIMITIVE_TYPES(org.mule.metadata.catalog.api.PrimitiveTypesTypeLoader.PRIMITIVE_TYPES) BEHAVIOUR(org.mule.runtime.api.meta.model.parameter.ParameterRole.BEHAVIOUR) ErrorModelBuilder(org.mule.runtime.api.meta.model.error.ErrorModelBuilder) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) Optional.of(java.util.Optional.of) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) StreamResult(javax.xml.transform.stream.StreamResult) Thread.currentThread(java.lang.Thread.currentThread) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) Collections.singletonList(java.util.Collections.singletonList) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) Document(org.w3c.dom.Document) Map(java.util.Map) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) IllegalParameterModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalParameterModelDefinitionException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) DisplayModel(org.mule.runtime.api.meta.model.display.DisplayModel) IOUtils(org.apache.commons.io.IOUtils) DeclarationOperation(org.mule.runtime.extension.api.loader.xml.declaration.DeclarationOperation) MacroExpansionModulesModel.getUsedNamespaces(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel.getUsedNamespaces) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) XmlModelUtils.createXmlLanguageModel(org.mule.runtime.extension.api.util.XmlModelUtils.createXmlLanguageModel) Category(org.mule.runtime.api.meta.Category) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) LayoutModel(org.mule.runtime.api.meta.model.display.LayoutModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) DirectedGraph(org.jgrapht.DirectedGraph) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) Optional.empty(java.util.Optional.empty) TransformerException(javax.xml.transform.TransformerException) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) TreeSet(java.util.TreeSet) Placement(org.mule.runtime.extension.api.annotation.param.display.Placement) String.join(java.lang.String.join) LayoutModel.builder(org.mule.runtime.api.meta.model.display.LayoutModel.builder) CycleDetector(org.jgrapht.alg.CycleDetector) DefaultEdge(org.jgrapht.graph.DefaultEdge) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) ANY(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.ANY) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) IOException(java.io.IOException) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConnectionManagementType(org.mule.runtime.api.meta.model.connection.ConnectionManagementType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) NoReconnectionStrategyModelProperty(org.mule.runtime.extension.internal.property.NoReconnectionStrategyModelProperty) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) TransformerFactory(javax.xml.transform.TransformerFactory) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MacroExpansionModulesModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel) URL(java.net.URL) NamedObject(org.mule.runtime.api.meta.NamedObject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) ByteArrayInputStream(java.io.ByteArrayInputStream) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) MacroExpansionModuleModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel) ComponentModelReader(org.mule.runtime.config.internal.dsl.model.ComponentModelReader) XmlConfigurationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) List(java.util.List) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) NoOpXmlErrorHandler(org.mule.runtime.config.internal.util.NoOpXmlErrorHandler) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashMap(java.util.HashMap) HashSet(java.util.HashSet) TypeResolverException(org.mule.metadata.catalog.api.TypeResolverException) TNS_PREFIX(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel.TNS_PREFIX) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) TypeResolver(org.mule.metadata.catalog.api.TypeResolver) DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) Optional.ofNullable(java.util.Optional.ofNullable) ParameterizedDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclarer) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader) XMLNS_ATTRIBUTE(javax.xml.XMLConstants.XMLNS_ATTRIBUTE) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OutputDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OutputDeclarer) Collections(java.util.Collections) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel)

Example 9 with OperationDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.

the class MuleExtensionModelDeclarer method declareSetVariable.

private void declareSetVariable(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    OperationDeclarer setVariable = extensionDeclarer.withOperation("setVariable").describedAs("A processor that adds variables.");
    setVariable.withOutput().ofType(typeLoader.load(void.class));
    setVariable.withOutputAttributes().ofType(typeLoader.load(void.class));
    setVariable.onDefaultParameterGroup().withOptionalParameter("variableName").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The variable name.");
    setVariable.onDefaultParameterGroup().withRequiredParameter("value").ofType(typeLoader.load(String.class)).withExpressionSupport(SUPPORTED).describedAs("The variable value.");
    setVariable.onDefaultParameterGroup().withOptionalParameter("encoding").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The encoding of the value assigned to the payload.");
    setVariable.onDefaultParameterGroup().withOptionalParameter("mimeType").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The mime type, e.g. text/plain or application/json");
}
Also used : OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer)

Example 10 with OperationDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.

the class MuleExtensionModelDeclarer method declareRaiseError.

private void declareRaiseError(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    OperationDeclarer raiseError = extensionDeclarer.withOperation("raiseError").describedAs("Throws an error with the specified type and description.");
    raiseError.withOutput().ofType(typeLoader.load(void.class));
    raiseError.withOutputAttributes().ofType(typeLoader.load(void.class));
    raiseError.onDefaultParameterGroup().withRequiredParameter("type").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The error type to raise.");
    raiseError.onDefaultParameterGroup().withOptionalParameter("description").ofType(typeLoader.load(String.class)).describedAs("The description of this error.");
}
Also used : OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer)

Aggregations

OperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer)14 HasOperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer)5 ComponentExecutorModelProperty (org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)4 Method (java.lang.reflect.Method)3 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)3 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)3 ImplementingMethodModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty)3 ExtensionOperationDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty)3 ParameterDeclarationContext (org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)3 ReflectiveOperationExecutorFactory (org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory)3 String.format (java.lang.String.format)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1