From 98e584425901883e194fad48fe728bcd7b6c2091 Mon Sep 17 00:00:00 2001 From: tplevko Date: Mon, 7 Oct 2024 09:44:41 +0200 Subject: [PATCH] fix(1472): sort kamelets alphabetically in the catalog --- .../generator/CatalogGenerator.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CatalogGenerator.java b/packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CatalogGenerator.java index 41a410f0a..6c274daa1 100644 --- a/packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CatalogGenerator.java +++ b/packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CatalogGenerator.java @@ -250,7 +250,7 @@ private CatalogDefinitionEntry getKameletsEntry(List kamelets, String na var root = jsonMapper.createObjectNode(); try { - kamelets.forEach(kamelet -> { + sortKamelets(kamelets).forEach(kamelet -> { processKameletFile(kamelet, root); }); @@ -293,6 +293,22 @@ private void processKameletFile(String kamelet, ObjectNode targetObject) { } } + private List sortKamelets(List kamelets) { + return kamelets.stream().sorted( + (k1, k2) -> { + try { + JsonNode kameletNode1 = yamlMapper.readTree(k1); + JsonNode kameletNode2 = yamlMapper.readTree(k2); + String kamelet1 = kameletNode1.get("metadata").get("name").asText().toLowerCase(); + String kamelet2 = kameletNode2.get("metadata").get("name").asText().toLowerCase(); + return kamelet1.compareTo(kamelet2); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, e.toString(), e); + } + return 0; + }).toList(); + } + private void processK8sSchema(CatalogDefinition index) { if (camelCatalogVersionLoader.getKubernetesSchema() == null) { LOGGER.severe("Kubernetes JSON Schema is not loaded");