use of org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory.SOURCE_TYPE in project mule by mulesoft.
the class ApplicationModel method validateErrorMappings.
private void validateErrorMappings() {
executeOnEveryComponentTree(componentModel -> {
List<ComponentModel> errorMappings = componentModel.getInnerComponents().stream().filter(c -> c.getIdentifier().equals(ERROR_MAPPING_IDENTIFIER)).collect(toList());
if (!errorMappings.isEmpty()) {
List<ComponentModel> anyMappings = errorMappings.stream().filter(this::isErrorMappingWithSourceAny).collect(toList());
if (anyMappings.size() > 1) {
throw new MuleRuntimeException(createStaticMessage("Only one mapping for 'ANY' or an empty source type is allowed."));
} else if (anyMappings.size() == 1 && !isErrorMappingWithSourceAny(errorMappings.get(errorMappings.size() - 1))) {
throw new MuleRuntimeException(createStaticMessage("Only the last error mapping can have 'ANY' or an empty source type."));
}
List<String> sources = errorMappings.stream().map(model -> model.getParameters().get(SOURCE_TYPE)).collect(toList());
List<String> distinctSources = sources.stream().distinct().collect(toList());
if (sources.size() != distinctSources.size()) {
throw new MuleRuntimeException(createStaticMessage(format("Repeated source types are not allowed. Offending types are '%s'.", on("', '").join(disjunction(sources, distinctSources)))));
}
}
});
}
Aggregations