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