use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method resolveWrappedElement.
private void resolveWrappedElement(DslElementModel.Builder<ParameterGroupModel> groupElementBuilder, ParameterModel p, DslElementSyntax pDsl, ComponentConfiguration paramComponent) {
if (paramComponent != null) {
DslElementModel.Builder<ParameterModel> paramElement = DslElementModel.<ParameterModel>builder().withModel(p).withDsl(pDsl).withConfig(paramComponent);
if (paramComponent.getNestedComponents().size() > 0) {
ComponentConfiguration wrappedComponent = paramComponent.getNestedComponents().get(0);
this.create(wrappedComponent).ifPresent(paramElement::containing);
}
groupElementBuilder.containing(paramElement.build());
}
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createWrappedObject.
private void createWrappedObject(ParameterObjectValue objectValue, ParameterModel parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
DslElementModel.Builder<ParameterModel> wrapperElement = DslElementModel.<ParameterModel>builder().withModel(parameterModel).withDsl(paramDsl);
InternalComponentConfiguration.Builder wrapperConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(paramDsl));
Reference<DslSyntaxResolver> customDsl = new Reference<>(dsl);
ObjectType nestedElementType;
if (objectValue.getTypeId() == null || objectValue.getTypeId().trim().isEmpty() || getId(parameterModel.getType()).map(id -> id.equals(objectValue.getTypeId())).orElse(false)) {
nestedElementType = (ObjectType) parameterModel.getType();
} else {
nestedElementType = lookupType(objectValue);
context.getTypeCatalog().getDeclaringExtension(objectValue.getTypeId()).ifPresent(owner -> context.getExtension(owner).ifPresent(extensionModel -> customDsl.set(resolvers.get(extensionModel))));
}
customDsl.get().resolve(nestedElementType).ifPresent(typeDsl -> createObject(objectValue, typeDsl, nestedElementType, nestedElementType, wrapperConfig, wrapperElement));
ComponentConfiguration result = wrapperConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(wrapperElement.withConfig(result).build());
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class MacroExpansionModuleModel method extractParameters.
/**
* Iterates over the collection of {@link ParameterModel}s making a clear distinction between {@link ParameterRole#BEHAVIOUR}
* and {@link ParameterRole#CONTENT} or {@link ParameterRole#PRIMARY_CONTENT} roles, where the former maps to simple attributes
* while the latter are child elements.
* <p/>
* If the value of the parameter is missing, then it will try to pick up a default value (also from the
* {@link ParameterModel#getDefaultValue()})
*
* @param componentModel to look for the values
* @param parameters collection of parameters to look for in the parametrized {@link ComponentModel}
* @return a {@link Map} with the values to be macro expanded in the final mule application
*/
private Map<String, String> extractParameters(ComponentModel componentModel, List<ParameterModel> parameters) {
Map<String, String> valuesMap = new HashMap<>();
for (ParameterModel parameterExtension : parameters) {
String paramName = parameterExtension.getName();
String value = null;
switch(parameterExtension.getRole()) {
case BEHAVIOUR:
if (componentModel.getParameters().containsKey(paramName)) {
value = componentModel.getParameters().get(paramName);
}
break;
case CONTENT:
case PRIMARY_CONTENT:
final Optional<ComponentModel> childComponentModel = componentModel.getInnerComponents().stream().filter(cm -> paramName.equals(cm.getIdentifier().getName())).findFirst();
if (childComponentModel.isPresent()) {
value = childComponentModel.get().getTextContent();
}
break;
}
if (value == null && (parameterExtension.getDefaultValue() != null)) {
value = String.valueOf(parameterExtension.getDefaultValue());
}
if (value != null) {
valuesMap.put(paramName, value);
}
}
return valuesMap;
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method flow.
@Test
public void flow() {
final ConstructModel flow = coreExtensionModel.getConstructModel("flow").get();
assertThat(flow.getStereotype().getType(), is(FLOW.getType()));
assertThat(flow.allowsTopLevelDeclaration(), is(true));
final List<ParameterModel> paramModels = flow.getAllParameterModels();
assertThat(paramModels, hasSize(2));
ParameterModel initialState = paramModels.get(0);
assertThat(initialState.getName(), is("initialState"));
assertThat(initialState.getDefaultValue(), is("started"));
ParameterModel maxConcurrency = paramModels.get(1);
assertThat(maxConcurrency.getName(), is("maxConcurrency"));
List<? extends NestableElementModel> nestedComponents = flow.getNestedComponents();
assertThat(nestedComponents, hasSize(3));
NestableElementModel source = nestedComponents.get(0);
assertThat(source.getName(), is("source"));
assertThat(source.isRequired(), is(false));
assertThat(source, instanceOf(NestedComponentModel.class));
assertThat(((NestedComponentModel) source).getAllowedStereotypes(), contains(SOURCE));
NestableElementModel chain = nestedComponents.get(1);
assertThat(chain.getName(), is("processors"));
assertThat(chain.isRequired(), is(true));
assertThat(chain, instanceOf(NestedChainModel.class));
assertThat(((NestedChainModel) chain).getAllowedStereotypes().stream().anyMatch(s -> s.getType().equals(PROCESSOR.getType())), is(true));
NestableElementModel errorHandler = nestedComponents.get(2);
assertThat(errorHandler.getName(), is("errorHandler"));
assertThat(errorHandler.isRequired(), is(false));
assertThat(errorHandler, instanceOf(NestedComponentModel.class));
assertThat(((NestedComponentModel) errorHandler).getAllowedStereotypes(), contains(ERROR_HANDLER));
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method untilSuccessful.
@Test
public void untilSuccessful() {
final ConstructModel tryModel = coreExtensionModel.getConstructModel("untilSuccessful").get();
List<ParameterModel> allParameterModels = tryModel.getAllParameterModels();
assertThat(allParameterModels, hasSize(2));
ParameterModel action = allParameterModels.get(0);
assertThat(action.getName(), is("maxRetries"));
assertThat(action.getType(), is(instanceOf(DefaultNumberType.class)));
assertThat(action.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(action.getDefaultValue(), is(5));
assertThat(action.isRequired(), is(false));
ParameterModel type = allParameterModels.get(1);
assertThat(type.getName(), is("millisBetweenRetries"));
assertThat(type.getType(), is(instanceOf(DefaultNumberType.class)));
assertThat(type.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(type.getDefaultValue(), is(60000));
assertThat(type.isRequired(), is(false));
}
Aggregations