Search in sources :

Example 11 with ComponentConfiguration

use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.

the class InfrastructureElementModelDelegate method createSchedulingStrategy.

private void createSchedulingStrategy(ParameterObjectValue value, ParameterModel parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement, DslResolvingContext context, DslSyntaxResolver dsl) {
    InternalComponentConfiguration.Builder schedulingWrapperConfig = InternalComponentConfiguration.builder().withIdentifier(builder().namespace(CORE_PREFIX).name(SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER).build());
    DslElementModel.Builder schedulingElement = DslElementModel.builder().withDsl(paramDsl).withModel(parameterModel);
    context.getTypeCatalog().getType(value.getTypeId()).ifPresent(strategyType -> {
        dsl.resolve(strategyType).ifPresent(strategyDsl -> {
            InternalComponentConfiguration.Builder strategyConfig = InternalComponentConfiguration.builder().withIdentifier(builder().namespace(CORE_PREFIX).name(strategyDsl.getElementName()).build());
            cloneParameters(value, strategyConfig);
            ComponentConfiguration strategy = strategyConfig.build();
            schedulingWrapperConfig.withNestedComponent(strategy);
            ComponentConfiguration schedulingWrapper = schedulingWrapperConfig.build();
            schedulingElement.withConfig(schedulingWrapper).containing(DslElementModel.builder().withModel(strategyType).withDsl(strategyDsl).withConfig(strategy).build());
            parentConfig.withNestedComponent(schedulingWrapper);
            parentElement.containing(schedulingElement.build());
        });
    });
}
Also used : ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration)

Example 12 with ComponentConfiguration

use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.

the class ApplicationModel method convertComponentConfiguration.

private ComponentModel convertComponentConfiguration(ComponentConfiguration componentConfiguration, boolean isRoot) {
    ComponentModel.Builder builder = new ComponentModel.Builder().setIdentifier(componentConfiguration.getIdentifier());
    if (isRoot) {
        builder.markAsRootComponent();
    }
    for (Map.Entry<String, String> parameter : componentConfiguration.getParameters().entrySet()) {
        builder.addParameter(parameter.getKey(), parameter.getValue(), false);
    }
    for (ComponentConfiguration childComponentConfiguration : componentConfiguration.getNestedComponents()) {
        builder.addChildComponentModel(convertComponentConfiguration(childComponentConfiguration, false));
    }
    componentConfiguration.getValue().ifPresent(builder::setTextContent);
    ComponentModel componentModel = builder.build();
    for (ComponentModel childComponent : componentModel.getInnerComponents()) {
        childComponent.setParent(componentModel);
    }
    return componentModel;
}
Also used : ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 13 with ComponentConfiguration

use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration 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"));
}
Also used : ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConfigurationElementDeclaration(org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) Test(org.junit.Test)

Example 14 with ComponentConfiguration

use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.

the class InfrastructureElementModelDelegate method createReconnectionConfig.

private void createReconnectionConfig(ParameterValue value, ParameterModel parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
    InternalComponentConfiguration.Builder config = InternalComponentConfiguration.builder().withIdentifier(builder().namespace(CORE_PREFIX).name(RECONNECTION_CONFIG_PARAMETER_NAME).build());
    final DslElementModel.Builder<Object> elementBuilder = DslElementModel.builder().withModel(parameterModel).withDsl(paramDsl);
    ((ParameterObjectValue) value).getParameters().forEach((name, fieldValue) -> fieldValue.accept(new ParameterValueVisitor() {

        @Override
        public void visitSimpleValue(ParameterSimpleValue text) {
            config.withParameter(name, text.getValue());
        }

        @Override
        public void visitObjectValue(ParameterObjectValue objectValue) {
            if (name.equals(RECONNECTION_STRATEGY_PARAMETER_NAME)) {
                createReconnectionStrategy(fieldValue, ((ObjectType) parameterModel.getType()).getFieldByName(RECONNECTION_STRATEGY_PARAMETER_NAME).get(), paramDsl.getContainedElement(RECONNECTION_STRATEGY_PARAMETER_NAME).get(), config, elementBuilder);
            }
        }
    }));
    final ComponentConfiguration result = config.build();
    parentConfig.withNestedComponent(result);
    parentElement.containing(elementBuilder.withConfig(result).build());
}
Also used : ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) ObjectType(org.mule.metadata.api.model.ObjectType) ParameterValueVisitor(org.mule.runtime.app.declaration.api.ParameterValueVisitor) ParameterSimpleValue(org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue) ParameterObjectValue(org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration)

Example 15 with ComponentConfiguration

use of org.mule.runtime.dsl.api.component.config.ComponentConfiguration in project mule by mulesoft.

the class ConfigurationBasedElementModelFactory method handleInfrastructure.

private void handleInfrastructure(final ParameterModel paramModel, final DslElementSyntax paramDsl, final Multimap<ComponentIdentifier, ComponentConfiguration> nested, final Map<String, String> parameters, final DslElementModel.Builder<ParameterGroupModel> groupElementBuilder) {
    switch(paramModel.getName()) {
        case RECONNECTION_CONFIG_PARAMETER_NAME:
            ComponentConfiguration reconnection = getSingleComponentConfiguration(nested, of(newIdentifier(RECONNECTION_CONFIG_PARAMETER_NAME, paramDsl.getPrefix())));
            if (reconnection != null) {
                groupElementBuilder.containing(newElementModel(paramModel, paramDsl, reconnection));
            }
            return;
        case RECONNECTION_STRATEGY_PARAMETER_NAME:
            ComponentIdentifier reconnectId = newIdentifier(RECONNECT_ELEMENT_IDENTIFIER, paramDsl.getPrefix());
            ComponentConfiguration config = nested.containsKey(reconnectId) ? getSingleComponentConfiguration(nested, of(reconnectId)) : getSingleComponentConfiguration(nested, of(newIdentifier(RECONNECT_FOREVER_ELEMENT_IDENTIFIER, paramDsl.getPrefix())));
            if (config != null) {
                groupElementBuilder.containing(newElementModel(paramModel, paramDsl, config));
            }
            return;
        case REDELIVERY_POLICY_PARAMETER_NAME:
            ComponentConfiguration redelivery = getSingleComponentConfiguration(nested, of(newIdentifier(REDELIVERY_POLICY_ELEMENT_IDENTIFIER, paramDsl.getPrefix())));
            if (redelivery != null) {
                groupElementBuilder.containing(newElementModel(paramModel, paramDsl, redelivery));
            }
            return;
        case EXPIRATION_POLICY_PARAMETER_NAME:
            ComponentConfiguration expiration = getSingleComponentConfiguration(nested, of(newIdentifier(EXPIRATION_POLICY_ELEMENT_IDENTIFIER, paramDsl.getPrefix())));
            if (expiration != null) {
                groupElementBuilder.containing(newElementModel(paramModel, paramDsl, expiration));
            }
            return;
        case POOLING_PROFILE_PARAMETER_NAME:
            ComponentConfiguration pooling = getSingleComponentConfiguration(nested, getIdentifier(paramDsl));
            if (pooling != null) {
                groupElementBuilder.containing(newElementModel(paramModel, paramDsl, pooling));
            }
            return;
        case STREAMING_STRATEGY_PARAMETER_NAME:
            Set<ComponentIdentifier> streaming = newHashSet(newIdentifier(NON_REPEATABLE_BYTE_STREAM_ALIAS, CORE_PREFIX), newIdentifier(REPEATABLE_IN_MEMORY_BYTES_STREAM_ALIAS, CORE_PREFIX), newIdentifier(REPEATABLE_FILE_STORE_BYTES_STREAM_ALIAS, EE_PREFIX), newIdentifier(REPEATABLE_IN_MEMORY_OBJECTS_STREAM_ALIAS, CORE_PREFIX), newIdentifier(REPEATABLE_FILE_STORE_OBJECTS_STREAM_ALIAS, EE_PREFIX), newIdentifier(NON_REPEATABLE_OBJECTS_STREAM_ALIAS, CORE_PREFIX));
            streaming.stream().filter(nested::containsKey).findFirst().ifPresent(s -> groupElementBuilder.containing(newElementModel(paramModel, paramDsl, getSingleComponentConfiguration(nested, of(s)))));
            return;
        case TLS_PARAMETER_NAME:
            ComponentConfiguration tls = getSingleComponentConfiguration(nested, getIdentifier(paramDsl));
            if (tls != null) {
                groupElementBuilder.containing(newElementModel(paramModel, paramDsl, tls));
            } else if (!isBlank(parameters.get(TLS_PARAMETER_NAME))) {
                groupElementBuilder.containing(DslElementModel.builder().withModel(paramModel).withDsl(paramDsl).withValue(parameters.get(TLS_PARAMETER_NAME)).build());
            }
            return;
        case SCHEDULING_STRATEGY_PARAMETER_NAME:
            ComponentConfiguration schedulingStrategyWrapper = getSingleComponentConfiguration(nested, of(ComponentIdentifier.builder().name(SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER).namespace(CORE_PREFIX).build()));
            if (schedulingStrategyWrapper != null) {
                DslElementModel.Builder wrapper = DslElementModel.builder().withModel(paramModel).withDsl(paramDsl).withConfig(schedulingStrategyWrapper);
                Iterator<ComponentConfiguration> nestedIt = schedulingStrategyWrapper.getNestedComponents().iterator();
                if (nestedIt.hasNext()) {
                    final ComponentConfiguration strategy = nestedIt.next();
                    final MetadataType type = CRON_STRATEGY_ELEMENT_IDENTIFIER.equals(strategy.getIdentifier().getName()) ? typeLoader.load(CronScheduler.class) : typeLoader.load(FixedFrequencyScheduler.class);
                    dsl.resolve(type).ifPresent(typeDsl -> wrapper.containing(DslElementModel.builder().withModel(type).withDsl(typeDsl).withConfig(strategy).build()));
                }
                groupElementBuilder.containing(wrapper.build());
            }
            return;
    }
}
Also used : InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) CronScheduler(org.mule.runtime.core.api.source.scheduler.CronScheduler) MetadataType(org.mule.metadata.api.model.MetadataType) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) FixedFrequencyScheduler(org.mule.runtime.core.api.source.scheduler.FixedFrequencyScheduler)

Aggregations

ComponentConfiguration (org.mule.runtime.dsl.api.component.config.ComponentConfiguration)21 DslElementModel (org.mule.runtime.config.api.dsl.model.DslElementModel)19 InternalComponentConfiguration (org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration)17 MetadataType (org.mule.metadata.api.model.MetadataType)11 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)11 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)10 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)10 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)10 List (java.util.List)9 Optional (java.util.Optional)9 Optional.empty (java.util.Optional.empty)9 ObjectType (org.mule.metadata.api.model.ObjectType)9 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)9 Reference (org.mule.runtime.api.util.Reference)9 Map (java.util.Map)8 ArrayType (org.mule.metadata.api.model.ArrayType)8 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)8 ComponentIdentifier.builder (org.mule.runtime.api.component.ComponentIdentifier.builder)8 Collectors.toList (java.util.stream.Collectors.toList)7 Stream.concat (java.util.stream.Stream.concat)7