use of org.mule.runtime.app.declaration.api.fluent.ParameterGroupElementDeclarer in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareChildParameters.
private void declareChildParameters(ParameterizedModel model, DslElementSyntax modelDsl, List<ConfigLine> children, ParameterizedElementDeclarer declarer) {
model.getParameterGroupModels().forEach(group -> {
if (group.isShowInDsl()) {
modelDsl.getChild(group.getName()).ifPresent(groupDsl -> children.stream().filter(c -> c.getIdentifier().equals(groupDsl.getElementName())).findFirst().ifPresent(groupConfig -> declareInlineGroup(group, groupDsl, groupConfig, declarer)));
} else {
ParameterGroupElementDeclarer groupDeclarer = newParameterGroup(group.getName());
group.getParameterModels().forEach(param -> modelDsl.getChild(param.getName()).ifPresent(paramDsl -> {
if (isInfrastructure(param)) {
handleInfrastructure(param, children, declarer);
} else {
children.stream().filter(c -> c.getIdentifier().equals(paramDsl.getElementName())).findFirst().ifPresent(paramConfig -> param.getType().accept(getParameterDeclarerVisitor(paramConfig, paramDsl, value -> groupDeclarer.withParameter(param.getName(), value))));
}
}));
if (!groupDeclarer.getDeclaration().getParameters().isEmpty()) {
declarer.withParameterGroup(groupDeclarer.getDeclaration());
}
}
});
}
use of org.mule.runtime.app.declaration.api.fluent.ParameterGroupElementDeclarer in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareInlineGroup.
private void declareInlineGroup(ParameterGroupModel model, DslElementSyntax dsl, ConfigLine config, ParameterizedElementDeclarer groupContainer) {
ParameterGroupElementDeclarer groupDeclarer = newParameterGroup(model.getName());
copyExplicitAttributes(config.getConfigAttributes(), groupDeclarer);
declareComplexParameterValue(model, dsl, config.getChildren(), groupDeclarer);
groupContainer.withParameterGroup(groupDeclarer.getDeclaration());
}
use of org.mule.runtime.app.declaration.api.fluent.ParameterGroupElementDeclarer in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method getComponentDeclaringWalker.
private ExtensionWalker getComponentDeclaringWalker(final Consumer<ComponentElementDeclaration> declarationConsumer, final ConfigLine line, final ElementDeclarer extensionElementsDeclarer) {
final DslSyntaxResolver dsl = resolvers.get(getNamespace(line));
return new ExtensionWalker() {
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
if (!model.getName().equals(TRANSFORM_IDENTIFIER)) {
declareComponentModel(line, model, extensionElementsDeclarer::newOperation).ifPresent(declarer -> {
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
} else {
declareTransform(model);
}
}
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
declareComponentModel(line, model, extensionElementsDeclarer::newSource).ifPresent(declarer -> {
final DslElementSyntax elementDsl = dsl.resolve(model);
model.getSuccessCallback().ifPresent(cb -> declareParameterizedComponent(cb, elementDsl, declarer, line.getConfigAttributes(), line.getChildren()));
model.getErrorCallback().ifPresent(cb -> declareParameterizedComponent(cb, elementDsl, declarer, line.getConfigAttributes(), line.getChildren()));
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
}
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
declareComponentModel(line, model, extensionElementsDeclarer::newConstruct).ifPresent(declarer -> {
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
}
private void declareTransform(ComponentModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
if (model.getName().equals(TRANSFORM_IDENTIFIER) && elementDsl.getElementName().equals(line.getIdentifier())) {
ComponentElementDeclarer transform = extensionElementsDeclarer.newOperation(TRANSFORM_IDENTIFIER);
line.getChildren().stream().filter(c -> c.getIdentifier().equals("message")).findFirst().ifPresent(messageConfig -> {
ParameterGroupElementDeclarer messageGroup = newParameterGroup("Message");
messageConfig.getChildren().stream().filter(c -> c.getIdentifier().equals("set-payload")).findFirst().ifPresent(payloadConfig -> {
ParameterObjectValue.Builder payload = newObjectValue();
populateTransformScriptParameter(payloadConfig, payload);
messageGroup.withParameter("setPayload", payload.build());
});
messageConfig.getChildren().stream().filter(c -> c.getIdentifier().equals("set-attributes")).findFirst().ifPresent(attributesConfig -> {
ParameterObjectValue.Builder attributes = newObjectValue();
populateTransformScriptParameter(attributesConfig, attributes);
messageGroup.withParameter("setAttributes", attributes.build());
});
transform.withParameterGroup(messageGroup.getDeclaration());
});
line.getChildren().stream().filter(c -> c.getIdentifier().equals("variables")).findFirst().ifPresent(variablesConfig -> {
ParameterGroupElementDeclarer variablesGroup = newParameterGroup("Set Variables");
ParameterListValue.Builder variables = newListValue();
variablesConfig.getChildren().forEach(variableConfig -> {
ParameterObjectValue.Builder variable = newObjectValue();
variable.withParameter(TRANSFORM_VARIABLE_NAME, variableConfig.getConfigAttributes().get(TRANSFORM_VARIABLE_NAME).getValue());
populateTransformScriptParameter(variableConfig, variable);
variables.withValue(variable.build());
});
transform.withParameterGroup(variablesGroup.withParameter("setVariables", variables.build()).getDeclaration());
});
line.getConfigAttributes().values().forEach(a -> transform.withCustomParameter(a.getName(), a.getValue()));
declarationConsumer.accept((ComponentElementDeclaration) transform.getDeclaration());
stop();
}
}
};
}
Aggregations