Search in sources :

Example 76 with MetadataType

use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.

the class BackPressureDeclarationEnricher method addBackPressureParameter.

private void addBackPressureParameter(ExtensionDeclaration extensionDeclaration, SourceDeclaration sourceDeclaration, BackPressureStrategyModelProperty property) {
    ParameterDeclaration parameter = new ParameterDeclaration(BACK_PRESSURE_STRATEGY_PARAMETER_NAME);
    parameter.setDescription(BACK_PRESSURE_STRATEGY_PARAMETER_DESCRIPTION);
    parameter.setRequired(false);
    parameter.setDefaultValue(property.getDefaultMode());
    parameter.setExpressionSupport(NOT_SUPPORTED);
    parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB).build());
    MetadataType type = BaseTypeBuilder.create(JAVA).stringType().id(format("%s-%s-backPressureStrategy", extensionDeclaration.getName(), sourceDeclaration.getName())).with(new EnumAnnotation<>(property.getSupportedModes().stream().map(BackPressureMode::name).toArray(String[]::new))).build();
    parameter.setType(type, false);
    sourceDeclaration.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter);
}
Also used : EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) MetadataType(org.mule.metadata.api.model.MetadataType) BackPressureMode(org.mule.runtime.extension.api.runtime.source.BackPressureMode) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)

Example 77 with MetadataType

use of org.mule.metadata.api.model.MetadataType 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)

Example 78 with MetadataType

use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.

the class ExtensionWithCustomStaticTypesTestCase method assertXmlOrder.

private void assertXmlOrder(Typed typed) {
    MetadataType type = typed.getType();
    assertThat(typed.hasDynamicType(), is(false));
    assertThat(type.getMetadataFormat(), is(XML));
    assertThat(type.toString(), is("shiporder"));
}
Also used : MetadataType(org.mule.metadata.api.model.MetadataType)

Example 79 with MetadataType

use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.

the class ExtensionWithCustomStaticTypesTestCase method assertCustomJsonType.

private void assertCustomJsonType(Typed typed) {
    MetadataType type = typed.getType();
    assertThat(typed.hasDynamicType(), is(false));
    assertThat(type.getMetadataFormat(), is(JSON));
    assertThat(type.toString(), is("json-object"));
}
Also used : MetadataType(org.mule.metadata.api.model.MetadataType)

Example 80 with MetadataType

use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.

the class ExtensionWithCustomStaticTypesTestCase method customTypeOutput.

@Test
public void customTypeOutput() throws Exception {
    OperationModel o = getOperation("customTypeOutput");
    OutputModel output = o.getOutput();
    MetadataType type = output.getType();
    assertThat(output.hasDynamicType(), is(false));
    assertThat(type.getMetadataFormat(), is(CSV));
    assertThat(type.toString(), is("csv-object"));
}
Also used : MetadataType(org.mule.metadata.api.model.MetadataType) OutputModel(org.mule.runtime.api.meta.model.OutputModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Aggregations

MetadataType (org.mule.metadata.api.model.MetadataType)99 ObjectType (org.mule.metadata.api.model.ObjectType)36 ArrayType (org.mule.metadata.api.model.ArrayType)28 Test (org.junit.Test)26 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)21 Optional (java.util.Optional)20 MessageMetadataType (org.mule.metadata.message.api.MessageMetadataType)18 String.format (java.lang.String.format)17 List (java.util.List)17 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)17 StringType (org.mule.metadata.api.model.StringType)15 Map (java.util.Map)14 Collectors.toList (java.util.stream.Collectors.toList)14 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)14 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)14 Reference (org.mule.runtime.api.util.Reference)14 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)14 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)13 Set (java.util.Set)11 ParameterizedModel (org.mule.runtime.api.meta.model.parameter.ParameterizedModel)11