Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
fix: Empty camel routes should show basic skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Delawen committed Jul 10, 2023
1 parent 607a486 commit cd093e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- route:
id: empty-route
from:
uri: null
steps: []
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,13 +40,32 @@ public CamelRoute() {
}

public CamelRoute(final List<Step> steps, final Map<String, Object> 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<Step> steps, final StepCatalog catalog, final Map<String, Object> md) {
private Flow processFlows(final List<Step> steps, final StepCatalog catalog) {
if (steps == null || steps.isEmpty()) {
return;
return null;
}
final var flow = new KamelPopulator(catalog).getFlow(steps);
setFlows(new LinkedList<>());
Expand Down Expand Up @@ -82,15 +102,7 @@ private void processFlows(final List<Step> 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<String, Object> metadata) {
Expand Down

0 comments on commit cd093e5

Please sign in to comment.