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