Search in sources :

Example 1 with EnumAnnotation

use of org.mule.metadata.api.annotation.EnumAnnotation 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 2 with EnumAnnotation

use of org.mule.metadata.api.annotation.EnumAnnotation in project mule by mulesoft.

the class MimeTypeParametersDeclarationEnricherTestCase method enumTypeOperation.

@Test
public void enumTypeOperation() {
    StringType type = builder.stringType().with(new EnumAnnotation<>(new String[] { "val" })).build();
    mockOutput(operation, type);
    enricher.enrich(extensionLoadingContext);
    assertThat(getGroupParameters(operation), hasSize(0));
}
Also used : StringType(org.mule.metadata.api.model.StringType) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with EnumAnnotation

use of org.mule.metadata.api.annotation.EnumAnnotation in project mule by mulesoft.

the class SchemaBuilder method createEnumSimpleType.

private LocalSimpleType createEnumSimpleType(MetadataType enumType) {
    LocalSimpleType enumValues = new LocalSimpleType();
    Restriction restriction = new Restriction();
    enumValues.setRestriction(restriction);
    restriction.setBase(STRING);
    EnumAnnotation<String> enumAnnotation = enumType.getAnnotation(EnumAnnotation.class).orElseThrow(() -> new IllegalArgumentException("Cannot obtain enum values for the given type"));
    for (String value : enumAnnotation.getValues()) {
        NoFixedFacet noFixedFacet = objectFactory.createNoFixedFacet();
        noFixedFacet.setValue(value);
        JAXBElement<NoFixedFacet> enumeration = objectFactory.createEnumeration(noFixedFacet);
        enumValues.getRestriction().getFacets().add(enumeration);
    }
    return enumValues;
}
Also used : Restriction(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Restriction) LocalSimpleType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalSimpleType) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) NoFixedFacet(org.mule.runtime.module.extension.internal.capability.xml.schema.model.NoFixedFacet)

Example 4 with EnumAnnotation

use of org.mule.metadata.api.annotation.EnumAnnotation in project mule by mulesoft.

the class DefaultExtensionModelFactoryTestCase method sourceWithReducedBackPressureStrategies.

@Test
public void sourceWithReducedBackPressureStrategies() {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    SourceModel source = extensionModel.getConfigurationModels().get(0).getSourceModel("ListenPayments").get();
    ParameterModel parameter = source.getAllParameterModels().stream().filter(p -> BACK_PRESSURE_STRATEGY_PARAMETER_NAME.equals(p.getName())).findAny().orElseThrow(() -> new IllegalStateException("No backPressureStrategy parameter"));
    assertThat(parameter.getType(), is(instanceOf(StringType.class)));
    assertThat(parameter.getDefaultValue(), is(FAIL));
    EnumAnnotation enumAnnotation = parameter.getType().getAnnotation(EnumAnnotation.class).orElseThrow(() -> new IllegalStateException("No enum annotation"));
    assertThat(asList(enumAnnotation.getValues()), containsInAnyOrder(FAIL.name(), DROP.name()));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 5 with EnumAnnotation

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

Aggregations

EnumAnnotation (org.mule.metadata.api.annotation.EnumAnnotation)5 Test (org.junit.Test)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 StringType (org.mule.metadata.api.model.StringType)2 SmallTest (org.mule.tck.size.SmallTest)2 Optional (java.util.Optional)1 QName (javax.xml.namespace.QName)1 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1 ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)1 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)1 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)1 TransactionType (org.mule.runtime.api.tx.TransactionType)1 BackPressureMode (org.mule.runtime.extension.api.runtime.source.BackPressureMode)1 Attribute (org.mule.runtime.module.extension.internal.capability.xml.schema.model.Attribute)1 LocalSimpleType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalSimpleType)1 NoFixedFacet (org.mule.runtime.module.extension.internal.capability.xml.schema.model.NoFixedFacet)1 Restriction (org.mule.runtime.module.extension.internal.capability.xml.schema.model.Restriction)1