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;
}
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));
}
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;
}
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()));
}
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);
}
Aggregations