Search in sources :

Example 11 with OperationDeclarer

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

the class MuleExtensionModelDeclarer method declareSetPayload.

private void declareSetPayload(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    OperationDeclarer setPayload = extensionDeclarer.withOperation("setPayload").describedAs("A transformer that sets the payload with the provided value.");
    setPayload.withOutput().ofType(typeLoader.load(void.class));
    setPayload.withOutputAttributes().ofType(typeLoader.load(void.class));
    setPayload.onDefaultParameterGroup().withOptionalParameter("encoding").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The encoding of the value assigned to the payload.");
    setPayload.onDefaultParameterGroup().withRequiredParameter("value").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The value to be set on the payload. Supports expressions.");
    setPayload.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 12 with OperationDeclarer

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

the class MuleExtensionModelDeclarer method declareParseTemplate.

private void declareParseTemplate(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    OperationDeclarer parseTemplate = extensionDeclarer.withOperation("parseTemplate").describedAs("Parses a template defined inline.");
    parseTemplate.withOutput().ofType(typeLoader.load(String.class));
    parseTemplate.withOutputAttributes().ofType(typeLoader.load(void.class));
    parseTemplate.onDefaultParameterGroup().withOptionalParameter("content").ofType(typeLoader.load(String.class)).withRole(ParameterRole.PRIMARY_CONTENT).withExpressionSupport(SUPPORTED).describedAs("Template to be processed.");
    parseTemplate.onDefaultParameterGroup().withOptionalParameter("location").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The location of the template. The order in which the transformer will attempt to load the file are: from the file system, from a URL, then from the classpath.");
}
Also used : OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer)

Example 13 with OperationDeclarer

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

the class XmlExtensionLoaderDelegate method extractOperationExtension.

private void extractOperationExtension(HasOperationDeclarer declarer, ComponentModel operationModel, DirectedGraph<String, DefaultEdge> directedGraph, XmlDslModel xmlDslModel) {
    String operationName = operationModel.getNameAttribute();
    OperationDeclarer operationDeclarer = declarer.withOperation(operationName);
    ComponentModel bodyComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_BODY_IDENTIFIER)).findFirst().orElseThrow(() -> new IllegalArgumentException(format("The operation '%s' is missing the <body> statement", operationName)));
    directedGraph.addVertex(operationName);
    fillGraphWithTnsReferences(directedGraph, operationName, bodyComponentModel.getInnerComponents());
    operationDeclarer.withModelProperty(new OperationComponentModelModelProperty(operationModel, bodyComponentModel));
    operationDeclarer.describedAs(getDescription(operationModel));
    operationDeclarer.getDeclaration().setDisplayModel(getDisplayModel(operationModel));
    extractOperationParameters(operationDeclarer, operationModel);
    extractOutputType(operationDeclarer.withOutput(), OPERATION_OUTPUT_IDENTIFIER, operationModel, getDeclarationOutputFor(operationName));
    extractOutputType(operationDeclarer.withOutputAttributes(), OPERATION_OUTPUT_ATTRIBUTES_IDENTIFIER, operationModel, getDeclarationOutputAttributesFor(operationName));
    declareErrorModels(operationDeclarer, xmlDslModel, operationName, operationModel);
}
Also used : HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)

Example 14 with OperationDeclarer

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

the class OperationModelLoaderDelegate method processNonBlockingOperation.

static void processNonBlockingOperation(OperationDeclarer operation, MethodElement operationMethod, boolean allowStreaming) {
    List<ExtensionParameter> callbackParameters = operationMethod.getParameters().stream().filter(p -> p.getType().isSameType(CompletionCallback.class)).collect(toList());
    checkDefinition(!callbackParameters.isEmpty(), format("Operation '%s' does not declare a '%s' parameter. One is required for a non-blocking operation", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
    checkDefinition(callbackParameters.size() <= 1, format("Operation '%s' defines more than one %s parameters. Only one is allowed", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
    checkDefinition(isVoid(operationMethod), format("Operation '%s' has a parameter of type %s but is not void. " + "Non-blocking operations have to be declared as void and the " + "return type provided through the callback", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
    ExtensionParameter callbackParameter = callbackParameters.get(0);
    List<MetadataType> genericTypes = callbackParameter.getType().getGenerics().stream().map(generic -> generic.getConcreteType().asMetadataType()).collect(toList());
    if (genericTypes.isEmpty()) {
        // This is an invalid state, but is better to fail when executing the Extension Model Validators
        genericTypes.add(ANY_TYPE);
        genericTypes.add(ANY_TYPE);
    }
    operation.withOutput().ofType(genericTypes.get(0));
    operation.withOutputAttributes().ofType(genericTypes.get(1));
    operation.blocking(false);
    if (allowStreaming) {
        handleByteStreaming(operationMethod, operation, genericTypes.get(0));
    } else {
        operation.supportsStreaming(false);
    }
}
Also used : TypeGeneric(org.mule.runtime.module.extension.api.loader.java.type.TypeGeneric) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) AnyType(org.mule.metadata.api.model.AnyType) CompletionCallback(org.mule.runtime.extension.api.runtime.process.CompletionCallback) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) HashMap(java.util.HashMap) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) JAVA(org.mule.metadata.java.api.JavaTypeLoader.JAVA) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) OperationElement(org.mule.runtime.module.extension.api.loader.java.type.OperationElement) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) ModelLoaderUtils.isScope(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isScope) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) WithOperationContainers(org.mule.runtime.module.extension.api.loader.java.type.WithOperationContainers) Map(java.util.Map) Method(java.lang.reflect.Method) ModelLoaderUtils.isNonBlocking(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isNonBlocking) Execution(org.mule.runtime.extension.api.annotation.execution.Execution) PagedOperationModelProperty(org.mule.runtime.extension.internal.property.PagedOperationModelProperty) String.format(java.lang.String.format) ModelLoaderUtils.isRouter(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isRouter) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ModelLoaderUtils.isAutoPaging(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isAutoPaging) IntrospectionUtils.isVoid(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isVoid) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty) TransactionalConnection(org.mule.runtime.extension.api.connectivity.TransactionalConnection) OperationContainerElement(org.mule.runtime.module.extension.api.loader.java.type.OperationContainerElement) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) IllegalOperationModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalOperationModelDefinitionException) ModelLoaderUtils.handleByteStreaming(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.handleByteStreaming) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) MetadataType(org.mule.metadata.api.model.MetadataType)

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