Search in sources :

Example 1 with ConfigurationElementDeclaration

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

the class DeclarationBasedElementModelFactory method create.

public <T> Optional<DslElementModel<T>> create(ElementDeclaration declaration) {
    setupCurrentExtensionContext(declaration.getDeclaringExtension());
    final Function<NamedObject, Boolean> equalsName = (named) -> named.getName().equals(declaration.getName());
    if (declaration instanceof TopLevelParameterDeclaration) {
        return createFromType((TopLevelParameterDeclaration) declaration);
    }
    Reference<DslElementModel> elementModel = new Reference<>();
    new ExtensionWalker() {

        @Override
        protected void onConfiguration(ConfigurationModel model) {
            if (equalsName.apply(model) && declaration instanceof ConfigurationElementDeclaration) {
                elementModel.set(createConfigurationElement(model, (ConfigurationElementDeclaration) declaration));
                stop();
            }
        }

        @Override
        protected void onOperation(HasOperationModels owner, OperationModel model) {
            if (equalsName.apply(model) && declaration instanceof OperationElementDeclaration) {
                elementModel.set(createComponentElement(model, (OperationElementDeclaration) declaration));
                stop();
            }
        }

        @Override
        protected void onConstruct(HasConstructModels owner, ConstructModel model) {
            if (equalsName.apply(model) && declaration instanceof ConstructElementDeclaration) {
                elementModel.set(createComponentElement(model, (ConstructElementDeclaration) declaration));
                stop();
            }
        }

        @Override
        protected void onSource(HasSourceModels owner, SourceModel model) {
            if (equalsName.apply(model) && declaration instanceof SourceElementDeclaration) {
                elementModel.set(createComponentElement(model, (SourceElementDeclaration) declaration));
                stop();
            }
        }
    }.walk(currentExtension);
    if (LOGGER.isDebugEnabled() && elementModel.get() == null) {
        LOGGER.debug(format("No model found with name [%s] of type [%s] for extension [%s]", declaration.getName(), declaration.getClass().getName(), declaration.getDeclaringExtension()));
    }
    return Optional.ofNullable(elementModel.get());
}
Also used : ExtensionMetadataTypeUtils.getId(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getId) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) NamedObject(org.mule.runtime.api.meta.NamedObject) LoggerFactory(org.slf4j.LoggerFactory) ParameterizedElementDeclaration(org.mule.runtime.app.declaration.api.ParameterizedElementDeclaration) ComposableModel(org.mule.runtime.api.meta.model.ComposableModel) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ArrayType(org.mule.metadata.api.model.ArrayType) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) Map(java.util.Map) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ParameterSimpleValue(org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ParameterValueVisitor(org.mule.runtime.app.declaration.api.ParameterValueVisitor) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) DslElementModelFactory(org.mule.runtime.config.api.dsl.model.DslElementModelFactory) ParameterElementDeclaration(org.mule.runtime.app.declaration.api.ParameterElementDeclaration) ExtensionModelUtils.isContent(org.mule.runtime.extension.api.util.ExtensionModelUtils.isContent) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) ObjectType(org.mule.metadata.api.model.ObjectType) ElementDeclarer.newObjectValue(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newObjectValue) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) String.format(java.lang.String.format) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) NAME_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.NAME_ATTRIBUTE_NAME) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) ConstructElementDeclaration(org.mule.runtime.app.declaration.api.ConstructElementDeclaration) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) ElementDeclaration(org.mule.runtime.app.declaration.api.ElementDeclaration) LayoutModel(org.mule.runtime.api.meta.model.display.LayoutModel) ConfigurationElementDeclaration(org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration) ExtensionModelUtils.isInfrastructure(org.mule.runtime.extension.api.util.ExtensionModelUtils.isInfrastructure) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) Optional(java.util.Optional) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) ReferableElementDeclaration(org.mule.runtime.app.declaration.api.ReferableElementDeclaration) ExtensionMetadataTypeUtils.getAlias(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getAlias) ExtensionModelUtils.isRequired(org.mule.runtime.extension.api.util.ExtensionModelUtils.isRequired) Optional.empty(java.util.Optional.empty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) SourceElementDeclaration(org.mule.runtime.app.declaration.api.SourceElementDeclaration) CONFIG_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.CONFIG_ATTRIBUTE_NAME) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) HasConstructModels(org.mule.runtime.api.meta.model.construct.HasConstructModels) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) RouteElementDeclaration(org.mule.runtime.app.declaration.api.RouteElementDeclaration) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) Function(java.util.function.Function) ExtensionMetadataTypeUtils.isFlattenedParameterGroup(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isFlattenedParameterGroup) ParameterListValue(org.mule.runtime.app.declaration.api.fluent.ParameterListValue) DslElementSyntaxBuilder(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntaxBuilder) ExtensionModelUtils.getDefaultValue(org.mule.runtime.extension.api.util.ExtensionModelUtils.getDefaultValue) ParameterObjectValue(org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue) Stream.concat(java.util.stream.Stream.concat) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) Logger(org.slf4j.Logger) ParameterValue(org.mule.runtime.app.declaration.api.ParameterValue) Stream.of(java.util.stream.Stream.of) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConnectionElementDeclaration(org.mule.runtime.app.declaration.api.ConnectionElementDeclaration) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) Collectors.toList(java.util.stream.Collectors.toList) TopLevelParameterDeclaration(org.mule.runtime.app.declaration.api.TopLevelParameterDeclaration) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) Reference(org.mule.runtime.api.util.Reference) OperationElementDeclaration(org.mule.runtime.app.declaration.api.OperationElementDeclaration) IS_CDATA(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler.IS_CDATA) ComponentElementDeclaration(org.mule.runtime.app.declaration.api.ComponentElementDeclaration) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ParameterGroupElementDeclaration(org.mule.runtime.app.declaration.api.ParameterGroupElementDeclaration) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) Reference(org.mule.runtime.api.util.Reference) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) NamedObject(org.mule.runtime.api.meta.NamedObject) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ConstructElementDeclaration(org.mule.runtime.app.declaration.api.ConstructElementDeclaration) ConfigurationElementDeclaration(org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration) HasConstructModels(org.mule.runtime.api.meta.model.construct.HasConstructModels) SourceElementDeclaration(org.mule.runtime.app.declaration.api.SourceElementDeclaration) OperationElementDeclaration(org.mule.runtime.app.declaration.api.OperationElementDeclaration) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) TopLevelParameterDeclaration(org.mule.runtime.app.declaration.api.TopLevelParameterDeclaration) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 2 with ConfigurationElementDeclaration

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

the class DeclarationElementModelFactoryTestCase method testConfigNoConnectionNoParams.

@Test
public void testConfigNoConnectionNoParams() {
    ConfigurationModel emptyConfig = mock(ConfigurationModel.class);
    when(emptyConfig.getName()).thenReturn(CONFIGURATION_NAME);
    when(emptyConfig.getParameterGroupModels()).thenReturn(emptyList());
    when(emptyConfig.getOperationModels()).thenReturn(emptyList());
    when(emptyConfig.getSourceModels()).thenReturn(emptyList());
    when(emptyConfig.getConnectionProviders()).thenReturn(emptyList());
    ExtensionModel extensionModel = mock(ExtensionModel.class);
    initializeExtensionMock(extensionModel);
    when(extensionModel.getConfigurationModels()).thenReturn(asList(emptyConfig));
    ConfigurationElementDeclaration declaration = ElementDeclarer.forExtension(EXTENSION_NAME).newConfiguration(CONFIGURATION_NAME).withRefName("sample").getDeclaration();
    DslElementModel<ConfigurationModel> element = create(declaration);
    assertThat(element.getModel(), is(configuration));
    assertThat(element.getContainedElements().isEmpty(), is(true));
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConfigurationElementDeclaration(org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Test(org.junit.Test)

Example 3 with ConfigurationElementDeclaration

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

the class DeclarationElementModelFactoryTestCase method testConfigNoParams.

@Test
public void testConfigNoParams() {
    ConfigurationElementDeclaration declaration = ElementDeclarer.forExtension(EXTENSION_NAME).newConfiguration(CONFIGURATION_NAME).withRefName("sample").getDeclaration();
    DslElementModel<ConfigurationModel> element = create(declaration);
    assertThat(element.getModel(), is(configuration));
    assertThat(element.getContainedElements().isEmpty(), is(true));
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConfigurationElementDeclaration(org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration) Test(org.junit.Test)

Example 4 with ConfigurationElementDeclaration

use of org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration 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)

Aggregations

ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)4 ConfigurationElementDeclaration (org.mule.runtime.app.declaration.api.ConfigurationElementDeclaration)4 Test (org.junit.Test)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 String.format (java.lang.String.format)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Function (java.util.function.Function)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream.concat (java.util.stream.Stream.concat)1 Stream.of (java.util.stream.Stream.of)1 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)1 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)1 ArrayType (org.mule.metadata.api.model.ArrayType)1 MetadataType (org.mule.metadata.api.model.MetadataType)1 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)1 ObjectType (org.mule.metadata.api.model.ObjectType)1 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)1