use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.
the class DefaultEventContextTestCase method componentData.
@Test
@Description("Verify that a location produces connector and source data.")
public void componentData() throws Exception {
TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder().type(SOURCE).identifier(buildFromStringRepresentation("http:listener")).build();
ComponentLocation location = mock(ComponentLocation.class);
when(location.getComponentIdentifier()).thenReturn(typedComponentIdentifier);
when(location.getParts()).thenReturn(asList(new DefaultLocationPart("flow", empty(), empty(), empty())));
BaseEventContext context = contextWithComponentLocation.apply(location);
assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), is("http"));
assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getName(), is("listener"));
}
use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.
the class ApplicationModel method getConfigurationPropertiesProvidersFromComponents.
private List<ConfigurationPropertiesProvider> getConfigurationPropertiesProvidersFromComponents(ArtifactConfig artifactConfig, ConfigurationPropertiesResolver localResolver) {
Map<ComponentIdentifier, ConfigurationPropertiesProviderFactory> providerFactoriesMap = new HashMap<>();
ServiceLoader<ConfigurationPropertiesProviderFactory> providerFactories = java.util.ServiceLoader.load(ConfigurationPropertiesProviderFactory.class);
providerFactories.forEach(service -> {
ComponentIdentifier componentIdentifier = service.getSupportedComponentIdentifier();
if (providerFactoriesMap.containsKey(componentIdentifier)) {
throw new MuleRuntimeException(createStaticMessage("Multiple configuration providers for component: " + componentIdentifier));
}
providerFactoriesMap.put(componentIdentifier, service);
});
List<ConfigurationPropertiesProvider> configConfigurationPropertiesProviders = new ArrayList<>();
artifactConfig.getConfigFiles().stream().forEach(configFile -> configFile.getConfigLines().stream().forEach(configLine -> {
for (ConfigLine componentConfigLine : configLine.getChildren()) {
if (componentConfigLine.getNamespace() == null) {
continue;
}
ComponentIdentifier componentIdentifier = ComponentIdentifier.builder().namespace(componentConfigLine.getNamespace()).name(componentConfigLine.getIdentifier()).build();
if (!providerFactoriesMap.containsKey(componentIdentifier)) {
continue;
}
DefaultConfigurationParameters.Builder configurationParametersBuilder = DefaultConfigurationParameters.builder();
ConfigurationParameters configurationParameters = resolveConfigurationParameters(configurationParametersBuilder, componentConfigLine, localResolver);
ConfigurationPropertiesProvider provider = providerFactoriesMap.get(componentIdentifier).createProvider(configurationParameters, externalResourceProvider);
if (provider instanceof Component) {
Component providerComponent = (Component) provider;
TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder().type(UNKNOWN).identifier(componentIdentifier).build();
DefaultComponentLocation.DefaultLocationPart locationPart = new DefaultComponentLocation.DefaultLocationPart(componentIdentifier.getName(), of(typedComponentIdentifier), of(configFile.getFilename()), of(configLine.getLineNumber()));
providerComponent.setAnnotations(ImmutableMap.<QName, Object>builder().put(AbstractComponent.LOCATION_KEY, new DefaultComponentLocation(of(componentIdentifier.getName()), singletonList(locationPart))).build());
}
configConfigurationPropertiesProviders.add(provider);
try {
initialiseIfNeeded(provider);
} catch (InitialisationException e) {
throw new MuleRuntimeException(e);
}
}
}));
return configConfigurationPropertiesProviders;
}
use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.
the class ComponentLocationVisitor method getModuleOperationTypeComponentIdentifier.
private Optional<TypedComponentIdentifier> getModuleOperationTypeComponentIdentifier(ComponentModel componentModel) {
final ComponentIdentifier originalIdentifier = (ComponentIdentifier) componentModel.getCustomAttributes().get(ORIGINAL_IDENTIFIER);
final String namespace = originalIdentifier.getNamespace();
final String operationName = originalIdentifier.getName();
final ComponentIdentifier operationIdentifier = ComponentIdentifier.builder().namespace(namespace).name(operationName).build();
return of(builder().identifier(operationIdentifier).type(OPERATION).build());
}
use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.
the class ComponentLocationVisitor method processModuleOperationChildren.
/**
* It rewrites the history for those macro expanded operations that are not direct children from a flow, which means the
* returned {@link ComponentLocation} are mapped to the new operation rather the original flow.
*
* @param componentModel source to generate the new {@link ComponentLocation}, it also relies in its parent
* {@link ComponentModel#getParent()}
* @param operationTypedIdentifier identifier of the current operation
* @return a fictitious {@link ComponentLocation}
*/
private DefaultComponentLocation processModuleOperationChildren(ComponentModel componentModel, Optional<TypedComponentIdentifier> operationTypedIdentifier) {
final Optional<TypedComponentIdentifier> parentOperationTypedIdentifier = getModuleOperationTypeComponentIdentifier(componentModel.getParent());
final String operationName = parentOperationTypedIdentifier.get().getIdentifier().getName();
return new DefaultComponentLocation(of(operationName), emptyList()).appendLocationPart(operationName, parentOperationTypedIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber()).appendLocationPart(PROCESSORS_PART_NAME, empty(), empty(), empty()).appendLocationPart(findProcessorPath(componentModel), operationTypedIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
}
use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.
the class ComponentLocationVisitor method accept.
/**
* For every {@link ComponentModel} in the configuration, sets the {@link DefaultComponentLocation} associated within an
* annotation under the key {@link AbstractComponent#LOCATION_KEY}.
*
* @param componentModel the component model that will be assign it's {@link DefaultComponentLocation}.
*/
@Override
public void accept(ComponentModel componentModel) {
if (componentModel.getParent() == null) {
// do not process root element
return;
}
DefaultComponentLocation componentLocation;
Optional<TypedComponentIdentifier> typedComponentIdentifier = of(builder().identifier(componentModel.getIdentifier()).type(componentModel.getComponentType().orElse(UNKNOWN)).build());
if (componentModel.isRoot()) {
String componentModelNameAttribute = componentModel.getNameAttribute();
ImmutableList<DefaultLocationPart> parts = ImmutableList.<DefaultLocationPart>builder().add(new DefaultLocationPart(componentModelNameAttribute, typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber())).build();
componentLocation = new DefaultComponentLocation(ofNullable(componentModelNameAttribute), parts);
} else if (existsWithinRootContainer(componentModel)) {
ComponentModel parentComponentModel = componentModel.getParent();
DefaultComponentLocation parentComponentLocation = parentComponentModel.getComponentLocation();
if (isHttpProxyPart(componentModel)) {
componentLocation = parentComponentLocation.appendLocationPart(componentModel.getIdentifier().getName(), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
} else if (isRootProcessorScope(parentComponentModel)) {
componentLocation = processFlowDirectChild(componentModel, parentComponentLocation, typedComponentIdentifier);
} else if (isMunitFlowIdentifier(parentComponentModel)) {
componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
} else if (isErrorHandler(componentModel)) {
componentLocation = processErrorHandlerComponent(componentModel, parentComponentLocation, typedComponentIdentifier);
} else if (isTemplateOnErrorHandler(componentModel)) {
componentLocation = processOnErrorModel(componentModel, parentComponentLocation, typedComponentIdentifier);
} else if (parentComponentIsRouter(componentModel)) {
if (isRoute(componentModel)) {
componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), of(TypedComponentIdentifier.builder().type(SCOPE).identifier(ROUTE_COMPONENT_IDENTIFIER).build()), componentModel.getConfigFileName(), componentModel.getLineNumber());
} else if (isProcessor(componentModel)) {
// this is the case of the routes directly inside the router as with scatter-gather
componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findProcessorPath(componentModel), empty(), empty(), empty()).appendProcessorsPart().appendLocationPart("0", typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
} else {
// this is the case of the when element inside the choice
componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), of(TypedComponentIdentifier.builder().type(UNKNOWN).identifier(ROUTE_COMPONENT_IDENTIFIER).build()), empty(), empty());
}
} else if (isProcessor(componentModel)) {
if (isModuleOperation(componentModel.getParent())) {
final Optional<TypedComponentIdentifier> operationTypedIdentifier = ApplicationModel.MODULE_OPERATION_CHAIN.equals(typedComponentIdentifier.get().getIdentifier()) ? getModuleOperationTypeComponentIdentifier(componentModel) : typedComponentIdentifier;
componentLocation = processModuleOperationChildren(componentModel, operationTypedIdentifier);
} else {
componentLocation = parentComponentLocation.appendProcessorsPart().appendLocationPart(findProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
}
} else {
if (isBatchAggregator(componentModel)) {
componentLocation = parentComponentLocation.appendLocationPart(BATCH_AGGREGATOR_COMPONENT_IDENTIFIER.getName(), of(TypedComponentIdentifier.builder().type(UNKNOWN).identifier(BATCH_AGGREGATOR_COMPONENT_IDENTIFIER).build()), componentModel.getConfigFileName(), componentModel.getLineNumber());
} else {
componentLocation = parentComponentLocation.appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
}
}
} else {
DefaultComponentLocation parentComponentLocation = componentModel.getParent().getComponentLocation();
componentLocation = parentComponentLocation.appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
}
componentModel.setComponentLocation(componentLocation);
}
Aggregations