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