Search in sources :

Example 11 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel in project mule by mulesoft.

the class DefaultXmlDslElementModelConverter method asXml.

/**
 * {@inheritDoc}
 */
@Override
public Element asXml(DslElementModel elementModel) {
    Object model = elementModel.getModel();
    checkArgument(model instanceof ConfigurationModel || model instanceof ComponentModel || model instanceof MetadataType, "The element must be either a MetadataType, ConfigurationModel or a ComponentModel");
    DslElementSyntax dsl = elementModel.getDsl();
    Element componentRoot = createElement(dsl, elementModel.getConfiguration());
    if (isEETransform(componentRoot)) {
        return populateEETransform(elementModel);
    }
    writeApplicationElement(componentRoot, elementModel, componentRoot);
    return componentRoot;
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) Element(org.w3c.dom.Element) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) MetadataType(org.mule.metadata.api.model.MetadataType)

Example 12 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel in project mule by mulesoft.

the class MacroExpansionModuleModel method extractProperties.

/**
 * Extracts the properties of the current <module/> if applies (it might not have a configuration in it)
 *
 * @param configRefName current <operation/> to macro expand, from which the config-ref attribute's value will be extracted.
 * @return a map with the name and values of the <module/>'s properties.
 */
private Map<String, String> extractProperties(Optional<String> configRefName) {
    Map<String, String> valuesMap = new HashMap<>();
    configRefName.ifPresent(configParameter -> {
        // look for the global element which "name" attribute maps to "configParameter" value
        ComponentModel configRefComponentModel = applicationModel.getRootComponentModel().getInnerComponents().stream().filter(componentModel -> looForConfiguration(componentModel).isPresent() && configParameter.equals(componentModel.getParameters().get(NAME_ATTRIBUTE))).findFirst().orElseThrow(() -> new IllegalArgumentException(format("There's no <%s:config> named [%s] in the current mule app", extensionModel.getXmlDslModel().getPrefix(), configParameter)));
        // as configParameter != null, a ConfigurationModel must exists
        final ConfigurationModel configurationModel = getConfigurationModel().get();
        valuesMap.putAll(extractParameters(configRefComponentModel, configurationModel.getAllParameterModels()));
        valuesMap.putAll(extractConnectionProperties(configRefComponentModel, configurationModel));
    });
    return valuesMap;
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) HashMap(java.util.HashMap) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel)

Example 13 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel in project mule by mulesoft.

the class MacroExpansionModuleModel method lookForOperation.

/**
 * Looks for an operation checking if it is defined within the scope of a {@link ConfigurationModel} or the
 * {@link ExtensionModel}.
 *
 * @param operationIdentifier element to look for in the current {@link #extensionModel}
 * @param prefix to check if the {@code operationIdentifier} namespace targets an operation of the <module/> (usually maps to
 *        the {@link ExtensionModel} prefix, or the {@link #TNS_PREFIX}.
 * @return an {@link OperationModel} if found, {@link Optional#empty()} otherwise.
 */
private Optional<OperationModel> lookForOperation(ComponentIdentifier operationIdentifier, String prefix) {
    Optional<OperationModel> result = Optional.empty();
    final String operationName = operationIdentifier.getName();
    if (operationIdentifier.getNamespace().equals(prefix)) {
        // As the operation can be inside the extension or the config, it has to be looked up in both elements.
        final HasOperationModels hasOperationModels = getConfigurationModel().map(configurationModel -> (HasOperationModels) configurationModel).orElse(extensionModel);
        result = hasOperationModels.getOperationModel(operationName);
    }
    // If the operation is not present, it might be a private one and it must be looked inside of the model property
    if (!result.isPresent() && extensionModel.getModelProperty(PrivateOperationsModelProperty.class).isPresent()) {
        result = extensionModel.getModelProperty(PrivateOperationsModelProperty.class).get().getOperationModel(operationName);
    }
    return result;
}
Also used : HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) IntStream(java.util.stream.IntStream) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) HashMap(java.util.HashMap) Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) CommonBeanDefinitionCreator(org.mule.runtime.config.internal.dsl.spring.CommonBeanDefinitionCreator) MODULE_OPERATION_CHAIN(org.mule.runtime.config.internal.model.ApplicationModel.MODULE_OPERATION_CHAIN) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) Map(java.util.Map) NAME_ATTRIBUTE(org.mule.runtime.config.internal.model.ApplicationModel.NAME_ATTRIBUTE) Collectors.toSet(java.util.stream.Collectors.toSet) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) Collections.emptyMap(java.util.Collections.emptyMap) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) VARS(org.mule.runtime.api.el.BindingContextUtils.VARS) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) MODULE_CONFIG_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONFIG_GLOBAL_ELEMENT_NAME) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 14 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel 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 15 with ConfigurationModel

use of org.mule.runtime.api.meta.model.config.ConfigurationModel in project mule by mulesoft.

the class SoapExtensionDeclarationTestCase method assertSoapExtensionModel.

@Test
public void assertSoapExtensionModel() {
    Map<String, Object> params = new HashMap<>();
    params.put(TYPE_PROPERTY_NAME, FootballSoapExtension.class.getName());
    params.put(VERSION, getProductVersion());
    ExtensionModel model = loader.loadExtensionModel(FootballSoapExtension.class.getClassLoader(), getDefault(emptySet()), params);
    assertErrorModels(model.getErrorModels());
    assertThat(model.getConfigurationModels(), hasSize(1));
    ConfigurationModel configuration = model.getConfigurationModels().get(0);
    assertThat(configuration.getName(), is(DEFAULT_CONFIG_NAME));
    assertThat(configuration.getDescription(), is(DEFAULT_CONFIG_DESCRIPTION));
    assertThat(configuration.getOperationModels(), hasSize(1));
    assertOperation(configuration.getOperationModels().get(0));
    List<ConnectionProviderModel> providers = configuration.getConnectionProviders();
    assertThat(providers, hasSize(3));
    assertConnectionProvider(providers.get(0), "base-connection", "", false, new ParameterProber("laLigaAddress", null, StringType.class, true), new ParameterProber("leaguesAddress", "http://some-url.com", StringType.class, false));
    assertConnectionProvider(providers.get(1), CALCIO_ID + "-connection", CALCIO_DESC, false);
    assertConnectionProvider(providers.get(2), "la-liga-connection", "", true, new ParameterProber("firstDivision", StringType.class), new ParameterProber("secondDivision", StringType.class), new ParameterProber("wsdlLocation", StringType.class));
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) HashMap(java.util.HashMap) FootballSoapExtension(org.mule.test.soap.extension.FootballSoapExtension) StringType(org.mule.metadata.api.model.StringType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) Test(org.junit.Test)

Aggregations

ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)35 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)19 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)16 Test (org.junit.Test)15 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)13 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)11 Optional (java.util.Optional)9 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)9 List (java.util.List)8 Set (java.util.Set)7 ObjectType (org.mule.metadata.api.model.ObjectType)7 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)7 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)7 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)7 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)7 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)7 DslSyntaxResolver (org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 MetadataType (org.mule.metadata.api.model.MetadataType)6