Search in sources :

Example 1 with ComponentElementDeclarer

use of org.mule.runtime.app.declaration.api.fluent.ComponentElementDeclarer 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();
            }
        }
    };
}
Also used : HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ParameterListValue(org.mule.runtime.app.declaration.api.fluent.ParameterListValue) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) ParameterGroupElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ParameterGroupElementDeclarer) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ComponentElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ComponentElementDeclarer) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) HasConstructModels(org.mule.runtime.api.meta.model.construct.HasConstructModels) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ParameterObjectValue(org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 2 with ComponentElementDeclarer

use of org.mule.runtime.app.declaration.api.fluent.ComponentElementDeclarer in project mule by mulesoft.

the class DefaultXmlArtifactDeclarationLoader method declareComponentModel.

private Optional<ComponentElementDeclarer> declareComponentModel(final ConfigLine line, ComponentModel model, Function<String, ComponentElementDeclarer> declarerBuilder) {
    final DslElementSyntax elementDsl = resolvers.get(getNamespace(line)).resolve(model);
    if (elementDsl.getElementName().equals(line.getIdentifier())) {
        ComponentElementDeclarer declarer = declarerBuilder.apply(model.getName());
        if (line.getConfigAttributes().get(CONFIG_ATTRIBUTE_NAME) != null) {
            declarer.withConfig(line.getConfigAttributes().get(CONFIG_ATTRIBUTE_NAME).getValue());
        }
        declareParameterizedComponent(model, elementDsl, declarer, line.getConfigAttributes(), line.getChildren());
        declareComposableModel(model, elementDsl, line, declarer);
        return Optional.of(declarer);
    }
    return Optional.empty();
}
Also used : ComponentElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ComponentElementDeclarer) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)

Aggregations

ComponentElementDeclarer (org.mule.runtime.app.declaration.api.fluent.ComponentElementDeclarer)2 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)2 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)1 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)1 HasConstructModels (org.mule.runtime.api.meta.model.construct.HasConstructModels)1 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)1 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)1 HasSourceModels (org.mule.runtime.api.meta.model.source.HasSourceModels)1 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)1 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)1 ParameterGroupElementDeclarer (org.mule.runtime.app.declaration.api.fluent.ParameterGroupElementDeclarer)1 ParameterListValue (org.mule.runtime.app.declaration.api.fluent.ParameterListValue)1 ParameterObjectValue (org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue)1 DslSyntaxResolver (org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver)1