Search in sources :

Example 1 with ParameterGroupDeclarer

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

the class SoapInvokeOperationDeclarer method declareRequestParameters.

/**
 * Given the Invoke Operation Declarer declares the parameters for the soap request.
 *
 * @param operation the invoke operation declarer.
 * @param loader    a {@link ClassTypeLoader} to load some parameters types.
 */
private void declareRequestParameters(OperationDeclarer operation, ClassTypeLoader loader) {
    ParameterGroupDeclarer message = operation.onParameterGroup(MESSAGE_GROUP).withDslInlineRepresentation(true).withLayout(getLayout(1));
    MetadataType binaryType = loader.load(InputStream.class);
    ObjectType attachments = TYPE_BUILDER.objectType().openWith(TYPE_BUILDER.binaryType().id(InputStream.class.getName()).with(new TypedValueTypeAnnotation())).with(new TypeIdAnnotation(Map.class.getName())).build();
    message.withOptionalParameter(BODY_PARAM).ofDynamicType(binaryType).withRole(PRIMARY_CONTENT).defaultingTo(PAYLOAD).withLayout(getLayout(3)).withDisplayModel(DisplayModel.builder().summary("The XML body to include in the SOAP message, with all the required parameters.").build());
    message.withOptionalParameter(HEADERS_PARAM).ofDynamicType(binaryType).withRole(CONTENT).withLayout(getLayout(4)).withDisplayModel(DisplayModel.builder().displayName(HEADERS_DISPLAY_NAME).summary("The XML headers to include in the SOAP message.").build());
    message.withOptionalParameter(ATTACHMENTS_PARAM).ofDynamicType(attachments).withRole(CONTENT).withLayout(getLayout(5)).withDisplayModel(DisplayModel.builder().summary("The attachments to include in the SOAP request.").build());
    operation.onParameterGroup(TRANSPORT_GROUP).withLayout(getLayout(2)).withOptionalParameter(TRANSPORT_HEADERS_PARAM).ofType(TYPE_BUILDER.objectType().openWith(loader.load(String.class)).with(new TypeIdAnnotation(Map.class.getName())).build()).withDsl(ParameterDslConfiguration.getDefaultInstance()).withLayout(LayoutModel.builder().order(2).tabName(TRANSPORT).build()).withDisplayModel(DisplayModel.builder().displayName(HEADERS_DISPLAY_NAME).summary("The headers to set in the transport configuration.").build());
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) InputStream(java.io.InputStream) TypedValueTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.TypedValueTypeAnnotation) MetadataType(org.mule.metadata.api.model.MetadataType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer) TypeIdAnnotation(org.mule.metadata.api.annotation.TypeIdAnnotation)

Example 2 with ParameterGroupDeclarer

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

the class ParameterModelsLoaderDelegate method declare.

public List<ParameterDeclarer> declare(HasParametersDeclarer component, List<? extends ExtensionParameter> parameters, ParameterDeclarationContext declarationContext, ParameterGroupDeclarer parameterGroupDeclarer) {
    List<ParameterDeclarer> declarerList = new ArrayList<>();
    checkAnnotationsNotUsedMoreThanOnce(parameters, Connection.class, Config.class, MetadataKeyId.class);
    boolean supportsNestedElements = component instanceof HasNestedComponentsDeclarer;
    for (ExtensionParameter extensionParameter : parameters) {
        // Both nested components and parameters are declared using the @Parameter annotation in order to simplify the API
        if (supportsNestedElements && declaredAsNestedComponent((HasNestedComponentsDeclarer) component, extensionParameter)) {
            continue;
        }
        if (!extensionParameter.shouldBeAdvertised()) {
            continue;
        }
        if (isParameterGroup(extensionParameter)) {
            List<ParameterDeclarer> groupParams = declaredAsGroup(component, declarationContext, extensionParameter);
            declarerList.addAll(groupParams);
            continue;
        }
        ParameterGroupDeclarer groupDeclarer = parameterGroupDeclarer != null ? parameterGroupDeclarer : component.onDefaultParameterGroup();
        ParameterDeclarer parameter;
        if (extensionParameter.isRequired()) {
            parameter = groupDeclarer.withRequiredParameter(extensionParameter.getAlias());
        } else {
            parameter = groupDeclarer.withOptionalParameter(extensionParameter.getAlias()).defaultingTo(extensionParameter.defaultValue().isPresent() ? extensionParameter.defaultValue().get() : null);
        }
        parameter.ofType(extensionParameter.getType().asMetadataType()).describedAs(extensionParameter.getDescription());
        parseParameterRole(extensionParameter, parameter);
        parseExpressionSupport(extensionParameter, parameter);
        parseConfigOverride(extensionParameter, parameter);
        parseNullSafe(extensionParameter, parameter);
        parseLayout(extensionParameter, parameter);
        parseExclusiveOptional(extensionParameter, groupDeclarer, parameter);
        parameter.withModelProperty(new ExtensionParameterDescriptorModelProperty(extensionParameter));
        extensionParameter.getDeclaringElement().ifPresent(element -> addImplementingTypeModelProperty(element, parameter));
        parseParameterDsl(extensionParameter, parameter);
        contributors.forEach(contributor -> contributor.contribute(extensionParameter, parameter, declarationContext));
        declarerList.add(parameter);
    }
    return declarerList;
}
Also used : ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) HasNestedComponentsDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasNestedComponentsDeclarer) ArrayList(java.util.ArrayList) ExtensionParameterDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionParameterDescriptorModelProperty) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)

Example 3 with ParameterGroupDeclarer

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

the class SoapInvokeOperationDeclarer method declareMetadataKeyParameters.

/**
 * Given the Invoke Operation Declarer declares all the parameters that the operation has.
 *
 * @param operation the invoke operation declarer.
 */
private void declareMetadataKeyParameters(OperationDeclarer operation, ClassTypeLoader loader, ReflectionCache reflectionCache) {
    TypeWrapper keyType = new TypeWrapper(WebServiceTypeKey.class, loader);
    ParameterGroupDeclarer group = operation.onParameterGroup(KEYS_GROUP).withModelProperty(new ParameterGroupModelProperty(new ParameterGroupDescriptor(KEYS_GROUP, keyType)));
    StringType stringType = TYPE_BUILDER.stringType().build();
    group.withRequiredParameter(SERVICE_PARAM).withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, SERVICE_PARAM, reflectionCache).get())).ofType(stringType).withModelProperty(new MetadataKeyPartModelProperty(1)).withLayout(getLayout(1));
    group.withRequiredParameter(OPERATION_PARAM).ofType(stringType).withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, OPERATION_PARAM, reflectionCache).get())).withModelProperty(new MetadataKeyPartModelProperty(2)).withLayout(getLayout(2));
}
Also used : DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) TypeWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.TypeWrapper) StringType(org.mule.metadata.api.model.StringType) WebServiceTypeKey(org.mule.runtime.extension.api.soap.WebServiceTypeKey) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) MetadataKeyPartModelProperty(org.mule.runtime.extension.api.property.MetadataKeyPartModelProperty) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)

Example 4 with ParameterGroupDeclarer

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

the class ParameterModelsLoaderDelegate method declaredAsGroup.

private List<ParameterDeclarer> declaredAsGroup(HasParametersDeclarer component, ParameterDeclarationContext declarationContext, ExtensionParameter groupParameter) throws IllegalParameterModelDefinitionException {
    ParameterGroup groupAnnotation = groupParameter.getAnnotation(ParameterGroup.class).orElse(null);
    if (groupAnnotation == null) {
        return emptyList();
    }
    final String groupName = groupAnnotation.name();
    if (DEFAULT_GROUP_NAME.equals(groupName)) {
        throw new IllegalParameterModelDefinitionException(format("%s '%s' defines parameter group of name '%s' which is the default one. " + "@%s cannot be used with the default group name", getComponentDeclarationTypeName(((Declarer) component).getDeclaration()), ((NamedDeclaration) ((Declarer) component).getDeclaration()).getName(), groupName, ParameterGroup.class.getSimpleName()));
    }
    final Type type = groupParameter.getType();
    final List<FieldElement> nestedGroups = type.getAnnotatedFields(ParameterGroup.class);
    if (!nestedGroups.isEmpty()) {
        throw new IllegalParameterModelDefinitionException(format("Class '%s' is used as a @%s but contains fields which also hold that annotation. Nesting groups is not allowed. " + "Offending fields are: [%s]", type.getName(), ParameterGroup.class.getSimpleName(), nestedGroups.stream().map(element -> element.getName()).collect(joining(","))));
    }
    if (groupParameter.isAnnotatedWith(org.mule.runtime.extension.api.annotation.param.Optional.class)) {
        throw new IllegalParameterModelDefinitionException(format("@%s can not be applied alongside with @%s. Affected parameter is [%s].", org.mule.runtime.extension.api.annotation.param.Optional.class.getSimpleName(), ParameterGroup.class.getSimpleName(), groupParameter.getName()));
    }
    ParameterGroupDeclarer declarer = component.onParameterGroup(groupName);
    if (declarer.getDeclaration().getModelProperty(ParameterGroupModelProperty.class).isPresent()) {
        throw new IllegalParameterModelDefinitionException(format("Parameter group '%s' has already been declared on %s '%s'", groupName, getComponentDeclarationTypeName(((Declarer) component).getDeclaration()), ((NamedDeclaration) ((Declarer) component).getDeclaration()).getName()));
    } else {
        declarer.withModelProperty(new ParameterGroupModelProperty(new ParameterGroupDescriptor(groupName, type, groupParameter.getType().asMetadataType(), // TODO: Eliminate dependency to Annotated Elements
        groupParameter.getDeclaringElement().orElse(null), groupParameter)));
    }
    final List<FieldElement> annotatedParameters = type.getAnnotatedFields(Parameter.class);
    type.getAnnotation(ExclusiveOptionals.class).ifPresent(annotation -> {
        Set<String> optionalParamNames = annotatedParameters.stream().filter(f -> !f.isRequired()).map(WithAlias::getAlias).collect(toSet());
        declarer.withExclusiveOptionals(optionalParamNames, annotation.isOneRequired());
    });
    declarer.withDslInlineRepresentation(groupAnnotation.showInDsl());
    groupParameter.getAnnotation(DisplayName.class).ifPresent(displayName -> declarer.withDisplayModel(DisplayModel.builder().displayName(displayName.value()).build()));
    parseLayoutAnnotations(groupParameter, LayoutModel.builder()).ifPresent(declarer::withLayout);
    declarer.withModelProperty(new ExtensionParameterDescriptorModelProperty(groupParameter));
    if (!annotatedParameters.isEmpty()) {
        return declare(component, annotatedParameters, declarationContext, declarer);
    } else {
        return declare(component, getFieldsWithGetters(type), declarationContext, declarer);
    }
}
Also used : FieldElement(org.mule.runtime.module.extension.api.loader.java.type.FieldElement) MuleExtensionAnnotationParser.parseLayoutAnnotations(org.mule.runtime.module.extension.internal.loader.java.MuleExtensionAnnotationParser.parseLayoutAnnotations) ImplementingParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingParameterModelProperty) NameUtils.getComponentDeclarationTypeName(org.mule.runtime.extension.api.util.NameUtils.getComponentDeclarationTypeName) HasParametersDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasParametersDeclarer) NullSafeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.NullSafeModelProperty) DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) ArrayType(org.mule.metadata.api.model.ArrayType) DisplayName(org.mule.runtime.extension.api.annotation.param.display.DisplayName) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ParameterDsl(org.mule.runtime.extension.api.annotation.dsl.xml.ParameterDsl) ParameterDeclarerContributor(org.mule.runtime.module.extension.internal.loader.java.contributor.ParameterDeclarerContributor) Collectors.toSet(java.util.stream.Collectors.toSet) ParameterDslConfiguration(org.mule.runtime.api.meta.model.ParameterDslConfiguration) IntrospectionUtils.getFieldsWithGetters(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldsWithGetters) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) IllegalParameterModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalParameterModelDefinitionException) ObjectType(org.mule.metadata.api.model.ObjectType) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ExclusiveParametersModel(org.mule.runtime.api.meta.model.parameter.ExclusiveParametersModel) Collections.emptyList(java.util.Collections.emptyList) WithAlias(org.mule.runtime.module.extension.api.loader.java.type.WithAlias) Connection(org.mule.runtime.extension.api.annotation.param.Connection) ExclusiveOptionals(org.mule.runtime.extension.api.annotation.param.ExclusiveOptionals) Set(java.util.Set) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) DisplayModel(org.mule.runtime.api.meta.model.display.DisplayModel) List(java.util.List) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer) NullSafe(org.mule.runtime.extension.api.annotation.param.NullSafe) LayoutModel(org.mule.runtime.api.meta.model.display.LayoutModel) Annotation(java.lang.annotation.Annotation) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionParameterDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionParameterDescriptorModelProperty) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) Expression(org.mule.runtime.extension.api.annotation.Expression) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) AnnotatedElement(java.lang.reflect.AnnotatedElement) ConfigOverride(org.mule.runtime.extension.api.annotation.param.ConfigOverride) HasNestedComponentsDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasNestedComponentsDeclarer) MetadataKeyId(org.mule.runtime.extension.api.annotation.metadata.MetadataKeyId) DefaultImplementingTypeModelProperty(org.mule.runtime.extension.api.property.DefaultImplementingTypeModelProperty) Config(org.mule.runtime.extension.api.annotation.param.Config) ArrayList(java.util.ArrayList) ExtensionModelUtils.roleOf(org.mule.runtime.extension.api.util.ExtensionModelUtils.roleOf) ImmutableExclusiveParametersModel(org.mule.runtime.extension.api.model.parameter.ImmutableExclusiveParametersModel) Content(org.mule.runtime.extension.api.annotation.param.Content) IntrospectionUtils.getExpressionSupport(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getExpressionSupport) DEFAULT_GROUP_NAME(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME) BasicTypeMetadataVisitor(org.mule.metadata.api.visitor.BasicTypeMetadataVisitor) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) ParameterGroup(org.mule.runtime.extension.api.annotation.param.ParameterGroup) ExclusiveOptionalModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ExclusiveOptionalModelProperty) ModelLoaderUtils.isProcessorChain(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isProcessorChain) NamedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.NamedDeclaration) ExclusiveParametersDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExclusiveParametersDeclaration) Field(java.lang.reflect.Field) Collectors.toList(java.util.stream.Collectors.toList) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) ExclusiveOptionals(org.mule.runtime.extension.api.annotation.param.ExclusiveOptionals) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) FieldElement(org.mule.runtime.module.extension.api.loader.java.type.FieldElement) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) ExtensionParameterDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionParameterDescriptorModelProperty) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) ArrayType(org.mule.metadata.api.model.ArrayType) ObjectType(org.mule.metadata.api.model.ObjectType) MetadataType(org.mule.metadata.api.model.MetadataType) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) ParameterGroup(org.mule.runtime.extension.api.annotation.param.ParameterGroup) DisplayName(org.mule.runtime.extension.api.annotation.param.display.DisplayName) NamedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.NamedDeclaration) IllegalParameterModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalParameterModelDefinitionException) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)

Example 5 with ParameterGroupDeclarer

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

the class TestConfigPropertiesExtensionLoadingDelegate method accept.

@Override
public void accept(ExtensionDeclarer extensionDeclarer, ExtensionLoadingContext context) {
    ConfigurationDeclarer configurationDeclarer = extensionDeclarer.named(EXTENSION_NAME).describedAs("Crafted Config Properties Extension").onVersion("1.0.0").withCategory(COMMUNITY).fromVendor("Mulesoft").withConfig("secure-configuration-properties");
    ParameterGroupDeclarer defaultParameterGroup = configurationDeclarer.onDefaultParameterGroup();
    defaultParameterGroup.withRequiredParameter("file").ofType(BaseTypeBuilder.create(JAVA).stringType().build());
    ParameterGroupDeclarer parameterGroupDeclarer = configurationDeclarer.onParameterGroup("encrypt").withDslInlineRepresentation(true);
    parameterGroupDeclarer.withRequiredParameter("algorithm").ofType(BaseTypeBuilder.create(JAVA).stringType().build());
    parameterGroupDeclarer.withRequiredParameter("mode").ofType(BaseTypeBuilder.create(JAVA).stringType().build());
}
Also used : ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)

Aggregations

ParameterGroupDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)5 ArrayList (java.util.ArrayList)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 ObjectType (org.mule.metadata.api.model.ObjectType)2 HasNestedComponentsDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasNestedComponentsDeclarer)2 ParameterDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer)2 ParameterGroupDescriptor (org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor)2 DeclaringMemberModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty)2 ParameterGroupModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 InputStream (java.io.InputStream)1 String.format (java.lang.String.format)1 Annotation (java.lang.annotation.Annotation)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Field (java.lang.reflect.Field)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.joining (java.util.stream.Collectors.joining)1