use of org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.DefaultLocationPart 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.dsl.api.component.config.DefaultComponentLocation.DefaultLocationPart 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