use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class DefaultXmlDslElementModelConverter method populateEETransform.
private Element populateEETransform(DslElementModel<?> elementModel) {
Element transform = createElement(elementModel.getDsl());
elementModel.getConfiguration().ifPresent(c -> c.getParameters().forEach((name, value) -> elementModel.findElement(name).filter(DslElementModel::isExplicitInDsl).ifPresent(e -> transform.setAttribute(name, value))));
// write set-payload and set-attributes
elementModel.findElement(buildFromStringRepresentation("ee:set-payload")).filter(DslElementModel::isExplicitInDsl).ifPresent(message -> {
Element messageElement = createElement(elementModel.getDsl(), "message");
transform.appendChild(messageElement);
elementModel.findElement(buildFromStringRepresentation("ee:set-payload")).ifPresent(setPayload -> setPayload.getConfiguration().ifPresent(c -> messageElement.appendChild(createTransformTextElement(c))));
elementModel.findElement(buildFromStringRepresentation("ee:set-attributes")).ifPresent(setAttributes -> setAttributes.getConfiguration().ifPresent(c -> messageElement.appendChild(createTransformTextElement(c))));
});
// write set-variable
elementModel.findElement(buildFromStringRepresentation("ee:set-variables")).ifPresent(variables -> {
Element variablesList = createElement(elementModel.getDsl(), "variables");
transform.appendChild(variablesList);
variables.getContainedElements().forEach(variable -> variable.getConfiguration().ifPresent(c -> {
Element var = createTransformTextElement((ComponentConfiguration) c);
var.setAttribute("variableName", ((ComponentConfiguration) c).getParameters().get("variableName"));
variablesList.appendChild(var);
}));
});
return transform;
}
use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class DeclarationElementModelFactoryTestCase method testConfigDeclarationToElement.
@Test
public void testConfigDeclarationToElement() {
ElementDeclarer ext = ElementDeclarer.forExtension(EXTENSION_NAME);
ConfigurationElementDeclaration declaration = ext.newConfiguration(CONFIGURATION_NAME).withRefName("sample").withConnection(ext.newConnection(CONNECTION_PROVIDER_NAME).withParameterGroup(newParameterGroup().withParameter(CONTENT_NAME, "#[{field: value}]").withParameter(BEHAVIOUR_NAME, "additional").withParameter(LIST_NAME, newListValue().withValue("additional").build()).getDeclaration()).getDeclaration()).getDeclaration();
DslElementModel<ConfigurationModel> element = create(declaration);
assertThat(element.getModel(), is(configuration));
assertThat(element.getContainedElements().size(), is(1));
DslElementModel connectionElement = element.getContainedElements().get(0);
assertThat(connectionElement.getContainedElements().size(), is(3));
assertThat(element.findElement(LIST_NAME).isPresent(), is(true));
DslElementModel<Object> listModel = element.findElement(LIST_NAME).get();
assertThat(listModel.getContainedElements().size(), is(1));
assertThat(listModel.getContainedElements().get(0).getDsl().getElementName(), is("list-name-item"));
DslElementModel<Object> itemModel = listModel.getContainedElements().get(0);
assertThat(itemModel.getContainedElements().get(0).getDsl().getAttributeName(), is(VALUE_ATTRIBUTE_NAME));
assertThat(itemModel.getContainedElements().get(0).getValue().get(), is("additional"));
assertThat(element.findElement(CONNECTION_PROVIDER_NAME).isPresent(), is(true));
assertThat(element.findElement(CONTENT_NAME).get().getConfiguration().get().getValue().get(), is("#[{field: value}]"));
assertThat(((ComponentConfiguration) connectionElement.getConfiguration().get()).getParameters().get(BEHAVIOUR_NAME), is("additional"));
}
use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class DefaultXmlDslElementModelConverter method writeApplicationElement.
private void writeApplicationElement(Element element, DslElementModel<?> elementModel, Element parentNode) {
populateInfrastructureConfiguration(element, elementModel);
if (elementModel.getContainedElements().isEmpty() && elementModel.getValue().isPresent()) {
setTextContentElement(element, elementModel, parentNode);
return;
}
elementModel.getContainedElements().stream().filter(c -> !isInfrastructure(c)).forEach(inner -> {
DslElementSyntax innerDsl = inner.getDsl();
Reference<Boolean> configured = new Reference<>(false);
if (innerDsl.supportsAttributeDeclaration() && inner.getValue().isPresent()) {
getCustomizedValue(inner).ifPresent(value -> {
configured.set(true);
element.setAttribute(innerDsl.getAttributeName(), value);
});
}
if (!configured.get() && innerDsl.supportsChildDeclaration() && inner.isExplicitInDsl()) {
Element childElement = createElement(innerDsl, inner.getConfiguration());
if (isEETransform(childElement)) {
element.appendChild(populateEETransform(inner));
} else {
writeApplicationElement(childElement, inner, element);
}
}
});
if (parentNode != element) {
parentNode.appendChild(element);
}
}
use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method addElementParameter.
private void addElementParameter(Multimap<ComponentIdentifier, ComponentConfiguration> innerComponents, Map<String, String> parameters, DslElementSyntax groupDsl, DslElementModel.Builder<ParameterGroupModel> groupElementBuilder, ParameterModel paramModel) {
groupDsl.getContainedElement(paramModel.getName()).ifPresent(paramDsl -> {
if (isInfrastructure(paramModel)) {
handleInfrastructure(paramModel, paramDsl, innerComponents, parameters, groupElementBuilder);
return;
}
ComponentConfiguration paramComponent = getSingleComponentConfiguration(innerComponents, getIdentifier(paramDsl));
if (paramDsl.isWrapped()) {
resolveWrappedElement(groupElementBuilder, paramModel, paramDsl, paramComponent);
return;
}
String value = paramDsl.supportsAttributeDeclaration() ? parameters.get(paramDsl.getAttributeName()) : null;
Optional<String> defaultValue = getDefaultValue(paramModel);
if (paramComponent != null || !isBlank(value) || defaultValue.isPresent()) {
DslElementModel.Builder<ParameterModel> paramElementBuilder = DslElementModel.<ParameterModel>builder().withModel(paramModel).withDsl(paramDsl);
if (paramComponent != null && !isContent(paramModel)) {
paramElementBuilder.withConfig(paramComponent);
paramModel.getType().accept(new MetadataTypeVisitor() {
@Override
public void visitArrayType(ArrayType arrayType) {
MetadataType itemType = arrayType.getType();
paramDsl.getGeneric(itemType).ifPresent(itemdsl -> {
ComponentIdentifier itemIdentifier = getIdentifier(itemdsl).get();
paramComponent.getNestedComponents().forEach(c -> {
if (c.getIdentifier().equals(itemIdentifier)) {
itemType.accept(getComponentChildVisitor(paramElementBuilder, c, itemType, VALUE_ATTRIBUTE_NAME, itemdsl, defaultValue, new ArrayDeque<>()));
}
});
});
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
populateMapEntries(objectType, paramDsl, paramElementBuilder, paramComponent);
return;
}
populateObjectFields(objectType, paramComponent, paramDsl, paramElementBuilder, new ArrayDeque<>());
}
});
} else {
if (isBlank(value)) {
if (paramComponent != null && paramComponent.getValue().isPresent() && !isBlank(paramComponent.getValue().get())) {
value = paramComponent.getValue().get().trim();
} else if (defaultValue.isPresent()) {
value = defaultValue.get();
paramElementBuilder.isExplicitInDsl(false);
}
}
paramElementBuilder.withValue(value);
}
groupElementBuilder.containing(paramElementBuilder.build());
}
});
}
use of org.mule.runtime.config.api.dsl.model.DslElementModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method populateComposableElements.
private void populateComposableElements(ComposableModel model, DslElementSyntax elementDsl, DslElementModel.Builder builder, ComponentConfiguration configuration) {
configuration.getNestedComponents().forEach(nestedComponentConfig -> {
DslElementModel nestedElement = createIdentifiedElement(nestedComponentConfig);
if (nestedElement != null) {
builder.containing(nestedElement);
} else {
model.getNestedComponents().stream().filter(nestedModel -> nestedModel instanceof NestedRouteModel).filter(nestedModel -> elementDsl.getContainedElement(nestedModel.getName()).map(nestedDsl -> getIdentifier(nestedDsl).map(id -> nestedComponentConfig.getIdentifier().equals(id)).orElse(false)).orElse(false)).findFirst().ifPresent(nestedModel -> {
DslElementSyntax routeDsl = elementDsl.getContainedElement(nestedModel.getName()).get();
DslElementModel.Builder<? extends NestableElementModel> routeBuilder = DslElementModel.<NestableElementModel>builder().withModel(nestedModel).withDsl(routeDsl).withConfig(nestedComponentConfig).isExplicitInDsl(true);
populateParameterizedElements((ParameterizedModel) nestedModel, routeDsl, routeBuilder, nestedComponentConfig);
nestedComponentConfig.getNestedComponents().forEach(routeElement -> {
DslElementModel nestableElementModel = createIdentifiedElement(routeElement);
if (nestableElementModel != null) {
routeBuilder.containing(nestableElementModel);
}
});
builder.containing(routeBuilder.build());
});
}
});
}
Aggregations