Search in sources :

Example 6 with MetadataType

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

the class SchemaBuilder method createAttribute.

private Attribute createAttribute(final String name, String description, final MetadataType type, Object defaultValue, boolean required, final ExpressionSupport expressionSupport) {
    final Attribute attribute = new Attribute();
    attribute.setUse(required ? USE_REQUIRED : USE_OPTIONAL);
    attribute.setAnnotation(createDocAnnotation(description));
    if ((defaultValue instanceof String && isNotBlank(defaultValue.toString())) || defaultValue instanceof Enum) {
        attribute.setDefault(defaultValue.toString());
    }
    type.accept(new MetadataTypeVisitor() {

        @Override
        public void visitString(StringType stringType) {
            Optional<EnumAnnotation> enumAnnotation = stringType.getAnnotation(EnumAnnotation.class);
            if (enumAnnotation.isPresent()) {
                visitEnum(stringType);
            } else {
                defaultVisit(stringType);
            }
        }

        private void visitEnum(StringType enumType) {
            attribute.setName(name);
            String typeName = getTypeId(enumType);
            if (OperationTransactionalAction.class.getName().equals(typeName)) {
                attribute.setType(MULE_OPERATION_TRANSACTIONAL_ACTION_TYPE);
            } else if (TransactionType.class.getName().equals(typeName)) {
                attribute.setType(MULE_TRANSACTION_TYPE);
                attribute.setDefault(LOCAL.name());
            } else {
                attribute.setType(new QName(schema.getTargetNamespace(), sanitizeName(typeName) + ENUM_TYPE_SUFFIX));
                registeredEnums.add(enumType);
            }
        }

        @Override
        protected void defaultVisit(MetadataType metadataType) {
            attribute.setName(name);
            attribute.setType(SchemaTypeConversion.convertType(type, expressionSupport));
        }
    });
    return attribute;
}
Also used : TransactionType(org.mule.runtime.api.tx.TransactionType) Optional(java.util.Optional) Attribute(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Attribute) StringType(org.mule.metadata.api.model.StringType) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) QName(javax.xml.namespace.QName) MetadataType(org.mule.metadata.api.model.MetadataType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor)

Example 7 with MetadataType

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

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

the class MetadataOperationTestCase method operationReceivesListOfObjects.

@Test
public void operationReceivesListOfObjects() throws Exception {
    location = Location.builder().globalName("objectListAsInput").addProcessorsPart().addIndexPart(0).build();
    MetadataResult<ComponentMetadataDescriptor<OperationModel>> operationMetadata = metadataService.getOperationMetadata(location);
    MetadataType objects = getParameter(operationMetadata.get().getModel(), "objects").getType();
    assertThat(objects, is(instanceOf(ArrayType.class)));
    assertThat(((ArrayType) objects).getType(), is(personType));
}
Also used : MetadataType(org.mule.metadata.api.model.MetadataType) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor) Test(org.junit.Test)

Example 9 with MetadataType

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

the class MetadataOperationTestCase method operationWhichReturnsDynamicListOfObjects.

@Test
public void operationWhichReturnsDynamicListOfObjects() throws Exception {
    location = Location.builder().globalName("dynamicListOfObjects").addProcessorsPart().addIndexPart(0).build();
    MetadataType param = getResolvedTypeFromList();
    assertExpectedType(((ArrayType) param).getType(), personType);
}
Also used : MetadataType(org.mule.metadata.api.model.MetadataType) Test(org.junit.Test)

Example 10 with MetadataType

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

the class MetadataOperationTestCase method getResolvedTypeFromList.

private MetadataType getResolvedTypeFromList() {
    final MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = metadataService.getOperationMetadata(location);
    assertSuccessResult(result);
    ComponentMetadataDescriptor<OperationModel> descriptor = result.get();
    MetadataType param = descriptor.getModel().getOutput().getType();
    assertThat(param, is(instanceOf(ArrayType.class)));
    assertThat(getId(param).get(), is(List.class.getName()));
    return param;
}
Also used : MetadataType(org.mule.metadata.api.model.MetadataType) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

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