From cd093e59c1f85d4999193dd3f3c6635b13285591 Mon Sep 17 00:00:00 2001 From: Maria Arias de Reyna Date: Mon, 10 Jul 2023 16:46:50 +0200 Subject: [PATCH] fix: Empty camel routes should show basic skeleton Fixes https://github.com/KaotoIO/kaoto-ui/issues/2056 --- .../resource/v2/IntegrationsResourceTest.java | 2 +- .../backend/api/resource/empty-route.yaml | 5 +++ .../deployment/camelroute/CamelRoute.java | 36 ++++++++++++------- 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 api/src/test/resources/io/kaoto/backend/api/resource/empty-route.yaml diff --git a/api/src/test/java/io/kaoto/backend/api/resource/v2/IntegrationsResourceTest.java b/api/src/test/java/io/kaoto/backend/api/resource/v2/IntegrationsResourceTest.java index def5c0c2b..378609594 100644 --- a/api/src/test/java/io/kaoto/backend/api/resource/v2/IntegrationsResourceTest.java +++ b/api/src/test/java/io/kaoto/backend/api/resource/v2/IntegrationsResourceTest.java @@ -368,7 +368,7 @@ void beans() throws Exception { @ParameterizedTest @ValueSource(strings = {"Camel Route#route-multi.yaml", "KameletBinding#kamelet-binding-multi.yaml", - "Kamelet#eip.kamelet.yaml", "Camel Route#rest-dsl-multi.yaml", + "Kamelet#eip.kamelet.yaml", "Camel Route#rest-dsl-multi.yaml", "Camel Route#empty-route.yaml", "Camel Route#route-with-beans.yaml", "Integration#integration.yaml", "Integration#integration-multiroute.yaml", "Kamelet#jms-amqp-10-source.kamelet.yaml", "Integration#integration-no-step.yaml", "Integration#integration-with-beans.yaml", diff --git a/api/src/test/resources/io/kaoto/backend/api/resource/empty-route.yaml b/api/src/test/resources/io/kaoto/backend/api/resource/empty-route.yaml new file mode 100644 index 000000000..66df4e5a4 --- /dev/null +++ b/api/src/test/resources/io/kaoto/backend/api/resource/empty-route.yaml @@ -0,0 +1,5 @@ +- route: + id: empty-route + from: + uri: null + steps: [] diff --git a/camel-route-support/src/main/java/io/kaoto/backend/model/deployment/camelroute/CamelRoute.java b/camel-route-support/src/main/java/io/kaoto/backend/model/deployment/camelroute/CamelRoute.java index 7d318d93c..159980e9e 100644 --- a/camel-route-support/src/main/java/io/kaoto/backend/model/deployment/camelroute/CamelRoute.java +++ b/camel-route-support/src/main/java/io/kaoto/backend/model/deployment/camelroute/CamelRoute.java @@ -9,6 +9,7 @@ import io.kaoto.backend.api.service.step.parser.camelroute.CamelRouteDeserializer; import io.kaoto.backend.model.deployment.kamelet.Bean; import io.kaoto.backend.model.deployment.kamelet.Flow; +import io.kaoto.backend.model.deployment.kamelet.step.From; import io.kaoto.backend.model.deployment.rest.HttpVerb; import io.kaoto.backend.model.deployment.rest.Rest; import io.kaoto.backend.model.step.Step; @@ -39,13 +40,32 @@ public CamelRoute() { } public CamelRoute(final List steps, final Map metadata, final StepCatalog catalog) { - processFlows(steps, catalog, metadata); + Flow f = processFlows(steps, catalog); processBeans(metadata); + + //We have an empty flow, but don't show it empty + if ((getBeans() == null || getBeans().isEmpty()) && f == null) { + setFlows(new LinkedList<>()); + f = new Flow(); + f.setFrom(new From()); + f.getFrom().setSteps(new LinkedList<>()); + getFlows().add(f); + } + + if (f != null && metadata.containsKey("name")) { + f.setId(String.valueOf(metadata.get("name"))); + } + if (f != null && metadata.containsKey("route-configuration-id")) { + f.setRouteConfigurationId(String.valueOf(metadata.get("route-configuration-id"))); + } + if (f != null && metadata.containsKey("description")) { + f.setDescription(String.valueOf(metadata.get("description"))); + } } - private void processFlows(final List steps, final StepCatalog catalog, final Map md) { + private Flow processFlows(final List steps, final StepCatalog catalog) { if (steps == null || steps.isEmpty()) { - return; + return null; } final var flow = new KamelPopulator(catalog).getFlow(steps); setFlows(new LinkedList<>()); @@ -82,15 +102,7 @@ private void processFlows(final List steps, final StepCatalog catalog, fin getFlows().add(f); } - if (f != null && md.containsKey("name")) { - f.setId(String.valueOf(md.get("name"))); - } - if (f != null && md.containsKey("route-configuration-id")) { - f.setRouteConfigurationId(String.valueOf(md.get("route-configuration-id"))); - } - if (f != null && md.containsKey("description")) { - f.setDescription(String.valueOf(md.get("description"))); - } + return f; } private void processBeans(final Map metadata) {