use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class SchemaBuilder method getSortedParameterModels.
/**
* Sorts the given {@code parameterModels} so that infrastructure ones are firsts and the rest maintain their relative order. If
* more than one infrastructure parameter is found, the subgroup is sorted alphabetically.
* <p>
* The {@link InfrastructureParameterModelProperty} is used to identify those parameters which are infrastructure
*
* @param parameterModels a {@link Collection} of {@link ParameterModel parameter models}
* @return a sorted {@link List}
*/
private List<ParameterModel> getSortedParameterModels(Collection<ParameterModel> parameterModels) {
List<ParameterModel> sortedParameters = new ArrayList<>(parameterModels);
sortedParameters.sort(new ParameterModelComparator(true));
return sortedParameters;
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class SourceSchemaDelegate method registerSourceType.
private void registerSourceType(String name, SourceModel sourceModel, DslElementSyntax dslSyntax, boolean hasImplicitConfig) {
final ExtensionType sourceType = createExecutableType(name, MULE_ABSTRACT_MESSAGE_SOURCE_TYPE, dslSyntax, hasImplicitConfig);
initialiseSequence(sourceType);
ExplicitGroup sequence = sourceType.getSequence();
builder.addInfrastructureParameters(sourceType, sourceModel, sequence);
List<ParameterModel> visitedParameters = new LinkedList<>();
sourceModel.getParameterGroupModels().forEach(group -> {
registerParameterGroup(sourceType, group);
visitedParameters.addAll(group.getParameterModels());
});
sourceModel.getSuccessCallback().map(ParameterizedModel::getParameterGroupModels).ifPresent(groups -> groups.forEach(group -> registerCallbackParameters(sourceType, visitedParameters, group)));
sourceModel.getErrorCallback().map(ParameterizedModel::getParameterGroupModels).ifPresent(groups -> groups.forEach(group -> registerCallbackParameters(sourceType, visitedParameters, group)));
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ExtensionDefinitionParser method parseMapParameters.
/**
* Registers a definition for a {@link ParameterModel} which represents an open {@link ObjectType}
*
* @param key the key that the parsed value should have on the parsed parameter's map
* @param name the parameter's name
* @param dictionaryType the parameter's open {@link ObjectType}
* @param defaultValue the parameter's default value
* @param expressionSupport the parameter's {@link ExpressionSupport}
* @param required whether the parameter is required
*/
protected void parseMapParameters(String key, String name, ObjectType dictionaryType, Object defaultValue, ExpressionSupport expressionSupport, boolean required, DslElementSyntax paramDsl, Set<ModelProperty> modelProperties) {
parseAttributeParameter(key, name, dictionaryType, defaultValue, expressionSupport, required, modelProperties);
Class<? extends Map> mapType = getType(dictionaryType);
if (ConcurrentMap.class.equals(mapType)) {
mapType = ConcurrentHashMap.class;
} else if (Map.class.equals(mapType)) {
mapType = LinkedHashMap.class;
}
final MetadataType valueType = dictionaryType.getOpenRestriction().orElse(typeLoader.load(Object.class));
final Class<?> valueClass = getType(valueType);
final MetadataType keyType = typeLoader.load(String.class);
final Class<?> keyClass = String.class;
final String mapElementName = paramDsl.getElementName();
addParameter(getChildKey(key), fromChildMapConfiguration(String.class, valueClass).withWrapperIdentifier(mapElementName).withDefaultValue(defaultValue));
addDefinition(baseDefinitionBuilder.withIdentifier(mapElementName).withTypeDefinition(fromType(mapType)).build());
Optional<DslElementSyntax> mapValueChildDsl = paramDsl.getGeneric(valueType);
if (!mapValueChildDsl.isPresent()) {
return;
}
DslElementSyntax valueDsl = mapValueChildDsl.get();
valueType.accept(new MetadataTypeVisitor() {
@Override
protected void defaultVisit(MetadataType metadataType) {
String parameterName = paramDsl.getAttributeName();
addDefinition(baseDefinitionBuilder.withIdentifier(valueDsl.getElementName()).withTypeDefinition(fromMapEntryType(keyClass, valueClass)).withKeyTypeConverter(value -> resolverOf(parameterName, keyType, value, null, expressionSupport, true, emptySet(), false)).withTypeConverter(value -> resolverOf(parameterName, valueType, value, null, expressionSupport, true, emptySet(), false)).build());
}
@Override
public void visitObject(ObjectType objectType) {
defaultVisit(objectType);
Optional<DslElementSyntax> containedElement = valueDsl.getContainedElement(VALUE_ATTRIBUTE_NAME);
if (isMap(objectType) || !containedElement.isPresent()) {
return;
}
DslElementSyntax valueChild = containedElement.get();
if ((valueChild.supportsTopLevelDeclaration() || (valueChild.supportsChildDeclaration() && !valueChild.isWrapped())) && !parsingContext.isRegistered(valueChild.getElementName(), valueChild.getPrefix())) {
try {
parsingContext.registerObjectType(valueChild.getElementName(), valueChild.getPrefix(), objectType);
new ObjectTypeParameterParser(baseDefinitionBuilder, objectType, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(definition -> addDefinition(definition));
} catch (ConfigurationException e) {
throw new MuleRuntimeException(createStaticMessage("Could not create parser for map complex type"), e);
}
}
}
@Override
public void visitArrayType(ArrayType arrayType) {
defaultVisit(arrayType);
Optional<DslElementSyntax> valueListGenericDsl = valueDsl.getGeneric(arrayType.getType());
if (valueDsl.supportsChildDeclaration() && valueListGenericDsl.isPresent()) {
arrayType.getType().accept(new BasicTypeMetadataVisitor() {
@Override
protected void visitBasicType(MetadataType metadataType) {
String parameterName = paramDsl.getAttributeName();
addDefinition(baseDefinitionBuilder.withIdentifier(valueListGenericDsl.get().getElementName()).withTypeDefinition(fromType(getType(metadataType))).withTypeConverter(value -> resolverOf(parameterName, metadataType, value, getDefaultValue(metadataType), getExpressionSupport(metadataType), false, emptySet())).build());
}
@Override
protected void defaultVisit(MetadataType metadataType) {
addDefinition(baseDefinitionBuilder.withIdentifier(valueListGenericDsl.get().getElementName()).withTypeDefinition(fromType(ValueResolver.class)).withObjectFactoryType(TopLevelParameterObjectFactory.class).withConstructorParameterDefinition(fromFixedValue(arrayType.getType()).build()).withConstructorParameterDefinition(fromFixedValue(getContextClassLoader()).build()).build());
}
});
}
}
});
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ExtensionDescriptionDocumenterTestCase method assertDescriptionsSingleConfig.
private void assertDescriptionsSingleConfig(ExtensionModel extensionModel) {
assertThat(extensionModel.getConfigurationModels(), hasSize(1));
assertThat(extensionModel.getOperationModels(), hasSize(1));
OperationModel withParameterGroup = extensionModel.getOperationModels().get(0);
assertDescription(withParameterGroup, "Operation with parameter group");
List<ParameterModel> operationParams = withParameterGroup.getAllParameterModels();
assertDescription(operationParams.get(0), "value param description");
assertDescription(operationParams.get(1), "First Description");
assertDescription(operationParams.get(2), "Second Description");
ConfigurationModel config = extensionModel.getConfigurationModels().get(0);
assertDescription(extensionModel, "Test Extension Description with single config");
assertDescription(config, DEFAULT_CONFIG_DESCRIPTION);
assertDescription(config.getAllParameterModels().get(0), "Config parameter");
assertDescription(config.getAllParameterModels().get(1), "Config Parameter with an Optional value");
assertThat(config.getOperationModels(), hasSize(1));
assertDescription(config.getOperationModels().get(0), "Operation with description");
ConnectionProviderModel provider = config.getConnectionProviders().get(0);
assertDescription(provider, "Provider description");
assertDescription(provider.getAllParameterModels().get(0), "Connection Param Description");
assertDescription(provider.getAllParameterModels().get(1), "First Description");
assertDescription(provider.getAllParameterModels().get(2), "Second Description");
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ExtensionDescriptionDocumenterTestCase method assertDescriptionsMultipleConfigs.
private void assertDescriptionsMultipleConfigs(ExtensionModel declaration) {
List<ConfigurationModel> configurations = declaration.getConfigurationModels();
assertDescription(declaration, "Test Extension Description");
assertThat(configurations, hasSize(2));
ConfigurationModel first = configurations.get(1);
assertDescription(first, "This is some Config documentation.");
assertDescription(first.getConnectionProviders().get(0), "Another Provider Documentation");
assertDescription(first.getConnectionProviders().get(1), "Provider Documentation");
ConfigurationModel second = configurations.get(0);
assertDescription(second, "This is some Another Config documentation.");
assertDescription(second.getConnectionProviders().get(0), "Another Provider Documentation");
List<ParameterModel> params = first.getAllParameterModels();
assertDescription(params.get(0), "Config parameter");
assertDescription(params.get(1), "Config Parameter with an Optional value");
assertDescription(params.get(2), EXPIRATION_POLICY_DESCRIPTION);
assertDescription(params.get(3), "Group parameter 1");
assertDescription(params.get(4), "Group parameter 2");
assertDescription(params.get(5), "Param with alias");
List<OperationModel> operations = declaration.getOperationModels();
OperationModel operation = getOperationByName(operations, "operation");
assertDescription(operation, "Test Operation");
assertDescription(operation.getAllParameterModels().get(0), "test value");
OperationModel inheritedOperation = getOperationByName(operations, "inheritedOperation");
assertDescription(inheritedOperation, "Inherited Operation Documentation");
assertDescription(inheritedOperation.getAllParameterModels().get(0), "parameter documentation for an inherited operation.");
OperationModel greetFriend = getOperationByName(operations, "greetFriend");
assertDescription(greetFriend, "This method greets a friend");
assertDescription(greetFriend.getAllParameterModels().get(0), "This is one of my friends");
assertDescription(greetFriend.getAllParameterModels().get(1), "Some other friend");
List<OperationModel> connectedOperations = first.getOperationModels();
OperationModel connectedOpe = connectedOperations.get(0);
assertDescription(connectedOpe, "Test Operation with blank parameter description");
assertDescription(connectedOpe.getAllParameterModels().get(0), "");
}
Aggregations