use of org.mule.runtime.module.extension.internal.loader.java.property.QueryParameterModelProperty in project mule by mulesoft.
the class ExtensionDefinitionParser method parseParameters.
/**
* Parsers the given {@code parameters} and generates matching definitions
*
* @param parameters a list of {@link ParameterModel}
*/
protected void parseParameters(List<ParameterModel> parameters) {
parameters.forEach(parameter -> {
final DslElementSyntax paramDsl = dslResolver.resolve(parameter);
final boolean isContent = isContent(parameter);
parameter.getType().accept(new MetadataTypeVisitor() {
@Override
protected void defaultVisit(MetadataType metadataType) {
if (!parseAsContent(metadataType)) {
parseAttributeParameter(parameter);
}
}
@Override
public void visitString(StringType stringType) {
if (paramDsl.supportsChildDeclaration()) {
parseFromTextExpression(parameter, paramDsl, () -> {
Optional<QueryParameterModelProperty> query = parameter.getModelProperty(QueryParameterModelProperty.class);
return value -> {
ValueResolver<String> resolver = resolverOf(parameter.getName(), stringType, value, parameter.getDefaultValue(), parameter.getExpressionSupport(), parameter.isRequired(), parameter.getModelProperties(), acceptsReferences(parameter));
return query.map(p -> (ValueResolver<String>) new NativeQueryParameterValueResolver(resolver, p.getQueryTranslator())).orElse(resolver);
};
});
} else {
defaultVisit(stringType);
}
}
@Override
public void visitObject(ObjectType objectType) {
if (parseAsContent(objectType)) {
return;
}
if (isMap(objectType)) {
parseMapParameters(parameter, objectType, paramDsl);
return;
}
if (!parsingContext.isRegistered(paramDsl.getElementName(), paramDsl.getPrefix())) {
if (!paramDsl.supportsTopLevelDeclaration() && paramDsl.supportsChildDeclaration()) {
parsingContext.registerObjectType(paramDsl.getElementName(), paramDsl.getPrefix(), objectType);
}
parseObjectParameter(parameter, paramDsl);
} else {
parseObject(getKey(parameter), parameter.getName(), objectType, parameter.getDefaultValue(), parameter.getExpressionSupport(), parameter.isRequired(), acceptsReferences(parameter), paramDsl, parameter.getModelProperties());
}
}
@Override
public void visitArrayType(ArrayType arrayType) {
if (!parseAsContent(arrayType)) {
parseCollectionParameter(parameter, arrayType, paramDsl);
}
}
private boolean parseAsContent(MetadataType type) {
if (isContent) {
parseFromTextExpression(parameter, paramDsl, () -> value -> resolverOf(parameter.getName(), type, value, parameter.getDefaultValue(), parameter.getExpressionSupport(), parameter.isRequired(), parameter.getModelProperties(), acceptsReferences(parameter)));
return true;
}
return false;
}
});
});
}
use of org.mule.runtime.module.extension.internal.loader.java.property.QueryParameterModelProperty in project mule by mulesoft.
the class MetadataKeyIdObjectResolverTestCase method resolveDsql.
@Test
public void resolveDsql() throws MetadataResolvingException {
ParameterModel queryParam = mock(ParameterModel.class);
when(queryParam.getModelProperty(QueryParameterModelProperty.class)).thenReturn(Optional.of(new QueryParameterModelProperty(QueryTranslator.class)));
mockMetadataKeyModelProp(queryParam, 1);
setParameters(queryParam);
setMetadataKeyIdModelProperty(String.class);
MetadataKey dsqlKey = newKey("dsql:SELECT id FROM Circle WHERE (diameter < 18)").build();
keyIdObjectResolver = new MetadataKeyIdObjectResolver(componentModel);
final Object resolvedKey = keyIdObjectResolver.resolve(dsqlKey);
assertThat(resolvedKey, is(instanceOf(DsqlQuery.class)));
DsqlQuery query = (DsqlQuery) resolvedKey;
assertThat(query.getFields(), hasSize(1));
assertThat(query.getType().getName(), is("Circle"));
}
Aggregations