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());
});
});
}
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;
}
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"));
}
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());
}
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;
}
}
Aggregations