use of org.apache.camel.Ordered in project camel-quarkus by apache.
the class KameletProcessor method configureTemplates.
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelContextCustomizerBuildItem configureTemplates(List<KameletResolverBuildItem> resolvers, KameletConfiguration configuration, KameletRecorder recorder) throws Exception {
List<RouteTemplateDefinition> definitions = new ArrayList<>();
List<KameletResolver> kameletResolvers = resolvers.stream().map(KameletResolverBuildItem::getResolver).sorted(Comparator.comparingInt(Ordered::getOrder)).collect(Collectors.toList());
CamelContext context = new DefaultCamelContext();
ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
for (String id : configuration.identifiers.orElse(Collections.emptyList())) {
for (KameletResolver resolver : kameletResolvers) {
final Optional<Resource> resource = resolver.resolve(id, ecc);
if (!resource.isPresent()) {
continue;
}
Collection<RoutesBuilder> rbs = ecc.getRoutesLoader().findRoutesBuilders(resource.get());
for (RoutesBuilder rb : rbs) {
RouteBuilder routeBuilder = (RouteBuilder) rb;
routeBuilder.configure();
if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() == 0) {
throw new IllegalStateException("No kamelet template was created for " + "kamelet:" + id + ". It might be that the kamelet was malformed?");
} else if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() > 1) {
throw new IllegalStateException("A kamelet is not supposed to create more than one route (" + "kamelet:" + id + "," + "routes: " + routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() + ")");
}
definitions.add(routeBuilder.getRouteTemplateCollection().getRouteTemplates().get(0));
}
}
}
return new CamelContextCustomizerBuildItem(recorder.createTemplateLoaderCustomizer(definitions));
}
Aggregations