use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class IntrospectionUtilsTestCase method assertList.
private void assertList(MetadataType metadataType, Class<?> listItemType) {
assertThat(metadataType, is(instanceOf(ArrayType.class)));
assertType(metadataType, List.class);
MetadataType itemMetadataType = ((ArrayType) metadataType).getType();
assertType(itemMetadataType, listItemType);
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class IntrospectionUtilsTestCase method assertVoidAttributesType.
private void assertVoidAttributesType(String method) throws Exception {
MetadataType attributesType = IntrospectionUtils.getMethodReturnAttributesType(getMethod(method));
assertThat(attributesType, is(instanceOf(VoidType.class)));
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method extractParameter.
private void extractParameter(ParameterizedDeclarer parameterizedDeclarer, ComponentModel param, ParameterRole role) {
Map<String, String> parameters = param.getParameters();
String receivedInputType = parameters.get(TYPE_ATTRIBUTE);
final LayoutModel.LayoutModelBuilder layoutModelBuilder = builder();
if (parseBoolean(parameters.get(PASSWORD))) {
layoutModelBuilder.asPassword();
}
layoutModelBuilder.order(getOrder(parameters.get(ORDER_ATTRIBUTE)));
layoutModelBuilder.tabName(getTab(parameters.get(TAB_ATTRIBUTE)));
final DisplayModel displayModel = getDisplayModel(param);
MetadataType parameterType = extractType(receivedInputType);
ParameterDeclarer parameterDeclarer = getParameterDeclarer(parameterizedDeclarer, parameters);
parameterDeclarer.describedAs(getDescription(param)).withLayout(layoutModelBuilder.build()).withDisplayModel(displayModel).withRole(role).ofType(parameterType);
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method getMetadataType.
private MetadataType getMetadataType(Optional<ComponentModel> outputAttributesComponentModel, Optional<MetadataType> declarationMetadataType) {
MetadataType metadataType;
// the calculated metadata has precedence over the one configured in the xml
if (declarationMetadataType.isPresent()) {
metadataType = declarationMetadataType.get();
} else {
// if tye element is absent, it will default to the VOID type
if (outputAttributesComponentModel.isPresent()) {
String receivedOutputAttributeType = outputAttributesComponentModel.get().getParameters().get(TYPE_ATTRIBUTE);
metadataType = extractType(receivedOutputAttributeType);
} else {
metadataType = BaseTypeBuilder.create(JAVA).voidType().build();
}
}
return metadataType;
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class DsqlQueryMetadataResolver method getOutputType.
/**
* Automatically resolves the output metadata for the {@link DsqlQuery}.
* <p>
* The base entity is resolved using the component {@link QueryEntityResolver} and assuming the key of the entity is the DSQL
* {@link DsqlQuery#getType() type}.
*
* @param context {@link MetadataContext} of the MetaData resolution
* @param query the {@link DsqlQuery} to resolve the output metadata from.
*/
@Override
public MetadataType getOutputType(MetadataContext context, Object query) throws MetadataResolvingException, ConnectionException {
if (query instanceof DsqlQuery) {
DsqlQuery dsqlQuery = (DsqlQuery) query;
MetadataType entityMetadata = entityResolver.getEntityMetadata(context, dsqlQuery.getType().getName());
BaseTypeBuilder builder = context.getTypeBuilder();
final List<Field> fields = dsqlQuery.getFields();
if (fields.size() == 1 && fields.get(0).getName().equals("*")) {
return entityMetadata;
}
entityMetadata.accept(new MetadataTypeVisitor() {
@Override
public void visitObject(ObjectType objectType) {
ObjectTypeBuilder objectTypeBuilder = builder.objectType();
objectType.getFields().stream().filter(p -> fields.stream().anyMatch(f -> f.getName().equalsIgnoreCase(p.getKey().getName().getLocalPart()))).forEach(p -> {
ObjectFieldTypeBuilder field = objectTypeBuilder.addField();
field.key(p.getKey().getName());
field.value(p.getValue());
});
}
});
return builder.build();
} else {
return nativeOutputResolver.getOutputType(context, query);
}
}
Aggregations