use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class MinimalApplicationModelGenerator method enableComponentDependencies.
/**
* Enables the {@link ComponentModel} and its dependencies in the {@link ApplicationModel}.
*
* @param requestedComponentModel the requested {@link ComponentModel} to be enabled.
*/
private void enableComponentDependencies(ComponentModel requestedComponentModel) {
final String requestComponentModelName = requestedComponentModel.getNameAttribute();
final Set<DependencyNode> componentDependencies = dependencyResolver.resolveComponentDependencies(requestedComponentModel);
final Set<DependencyNode> alwaysEnabledComponents = dependencyResolver.resolveAlwaysEnabledComponents();
final ImmutableSet.Builder<DependencyNode> otherRequiredGlobalComponentsSetBuilder = ImmutableSet.<DependencyNode>builder().addAll(componentDependencies).addAll(alwaysEnabledComponents);
if (requestComponentModelName != null && dependencyResolver.getApplicationModel().findTopLevelNamedComponent(requestComponentModelName).isPresent()) {
otherRequiredGlobalComponentsSetBuilder.add(new DependencyNode(requestComponentModelName, TOP_LEVEL));
}
Set<DependencyNode> allRequiredComponentModels = resolveDependencies(otherRequiredGlobalComponentsSetBuilder.build());
enableTopLevelElementDependencies(allRequiredComponentModels);
enableInnerElementDependencies(allRequiredComponentModels);
ComponentModel parentModel = requestedComponentModel.getParent();
while (parentModel != null && parentModel.getParent() != null) {
parentModel.setEnabled(true);
parentModel = parentModel.getParent();
}
// Finally we set the requested componentModel as enabled as it could have been disabled when traversing dependencies
requestedComponentModel.setEnabled(true);
requestedComponentModel.executedOnEveryInnerComponent(componentModel -> componentModel.setEnabled(true));
enableParentComponentModels(requestedComponentModel);
// Mule root component model has to be enabled too
this.dependencyResolver.getApplicationModel().getRootComponentModel().setEnabled(true);
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class MacroExpansionModuleModel method getParameterChild.
private ComponentModel getParameterChild(Map<String, String> parameters, String wrapperParameters, String entryParameter) {
ComponentModel.Builder parametersBuilder = new ComponentModel.Builder();
parametersBuilder.setIdentifier(builder().namespace(CORE_PREFIX).name(wrapperParameters).build());
parameters.forEach((paramName, paramValue) -> {
ComponentModel.Builder parameterBuilder = new ComponentModel.Builder();
parameterBuilder.setIdentifier(builder().namespace(CORE_PREFIX).name(entryParameter).build());
parameterBuilder.addParameter(KEY_ATTRIBUTE_NAME, paramName, false);
parameterBuilder.addParameter(VALUE_ATTRIBUTE_NAME, paramValue, false);
parametersBuilder.addChildComponentModel(parameterBuilder.build());
});
ComponentModel parametersComponentModel = parametersBuilder.build();
for (ComponentModel parameterComponentModel : parametersComponentModel.getInnerComponents()) {
parameterComponentModel.setParent(parametersComponentModel);
}
return parametersComponentModel;
}
use of org.mule.runtime.config.internal.model.ComponentModel 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.config.internal.model.ComponentModel in project mule by mulesoft.
the class MacroExpansionModuleModel method expandOperations.
private void expandOperations(Set<String> moduleGlobalElementsNames) {
applicationModel.executeOnEveryMuleComponentTree(containerComponentModel -> {
HashMap<Integer, ComponentModel> componentModelsToReplaceByIndex = new HashMap<>();
IntStream.range(0, containerComponentModel.getInnerComponents().size()).forEach(i -> {
ComponentModel operationRefModel = containerComponentModel.getInnerComponents().get(i);
lookForOperation(operationRefModel).ifPresent(operationModel -> {
final String containerName = calculateContainerRootName(containerComponentModel, operationModel);
final ComponentModel moduleOperationChain = createModuleOperationChain(operationRefModel, operationModel, moduleGlobalElementsNames, Optional.empty(), containerName);
componentModelsToReplaceByIndex.put(i, moduleOperationChain);
});
});
for (Map.Entry<Integer, ComponentModel> entry : componentModelsToReplaceByIndex.entrySet()) {
entry.getValue().setParent(containerComponentModel);
containerComponentModel.getInnerComponents().add(entry.getKey(), entry.getValue());
containerComponentModel.getInnerComponents().remove(entry.getKey() + 1);
}
componentModelsToReplaceByIndex.clear();
});
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class MacroExpansionModuleModel method extractParameters.
/**
* Iterates over the collection of {@link ParameterModel}s making a clear distinction between {@link ParameterRole#BEHAVIOUR}
* and {@link ParameterRole#CONTENT} or {@link ParameterRole#PRIMARY_CONTENT} roles, where the former maps to simple attributes
* while the latter are child elements.
* <p/>
* If the value of the parameter is missing, then it will try to pick up a default value (also from the
* {@link ParameterModel#getDefaultValue()})
*
* @param componentModel to look for the values
* @param parameters collection of parameters to look for in the parametrized {@link ComponentModel}
* @return a {@link Map} with the values to be macro expanded in the final mule application
*/
private Map<String, String> extractParameters(ComponentModel componentModel, List<ParameterModel> parameters) {
Map<String, String> valuesMap = new HashMap<>();
for (ParameterModel parameterExtension : parameters) {
String paramName = parameterExtension.getName();
String value = null;
switch(parameterExtension.getRole()) {
case BEHAVIOUR:
if (componentModel.getParameters().containsKey(paramName)) {
value = componentModel.getParameters().get(paramName);
}
break;
case CONTENT:
case PRIMARY_CONTENT:
final Optional<ComponentModel> childComponentModel = componentModel.getInnerComponents().stream().filter(cm -> paramName.equals(cm.getIdentifier().getName())).findFirst();
if (childComponentModel.isPresent()) {
value = childComponentModel.get().getTextContent();
}
break;
}
if (value == null && (parameterExtension.getDefaultValue() != null)) {
value = String.valueOf(parameterExtension.getDefaultValue());
}
if (value != null) {
valuesMap.put(paramName, value);
}
}
return valuesMap;
}
Aggregations