This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git

commit 6a5006e1512cba134a83e3919ca2c024eb223a64
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Fri Nov 22 16:03:12 2024 -0500

    Support route templates
---
 karavan-core/src/core/api/CamelDefinitionYaml.ts   | 17 ++++++++--
 .../src/core/model/IntegrationDefinition.ts        |  2 +-
 karavan-core/test/routeTemplate.spec.ts            | 37 ++++++++++++++++++++++
 karavan-core/test/routeTemplate1.camel.yaml        | 21 ++++++++++++
 karavan-core/test/routeTemplate2.camel.yaml        | 33 +++++++++++++++++++
 5 files changed, 107 insertions(+), 3 deletions(-)

diff --git a/karavan-core/src/core/api/CamelDefinitionYaml.ts 
b/karavan-core/src/core/api/CamelDefinitionYaml.ts
index 5852eb8e..d82020fb 100644
--- a/karavan-core/src/core/api/CamelDefinitionYaml.ts
+++ b/karavan-core/src/core/api/CamelDefinitionYaml.ts
@@ -16,7 +16,11 @@
  */
 import * as yaml from 'js-yaml';
 import { Beans, CamelElement, Integration } from 
'../model/IntegrationDefinition';
-import { BeanFactoryDefinition, RouteConfigurationDefinition, RouteDefinition 
} from '../model/CamelDefinition';
+import {
+    BeanFactoryDefinition,
+    RouteConfigurationDefinition,
+    RouteDefinition, RouteTemplateDefinition,
+} from '../model/CamelDefinition';
 import { CamelUtil } from './CamelUtil';
 import { CamelDefinitionYamlStep } from './CamelDefinitionYamlStep';
 
@@ -95,7 +99,9 @@ export class CamelDefinitionYaml {
             object.inSteps = !!inSteps;
         }
 
-        if (object.dslName.endsWith('Expression')) {
+        if (object.dslName === 'RouteTemplateDefinition') {
+            object.route.inArray = true;
+        } else if (object.dslName.endsWith('Expression')) {
             delete object.language;
             delete object.expressionName;
         } else if (object.dslName.endsWith('DataFormat')) {
@@ -187,6 +193,11 @@ export class CamelDefinitionYaml {
                 const xValue: any = {};
                 xValue[stepName] = newValue;
                 return xValue;
+            } else if (value.inArray && dslName === 'RouteDefinition' && 
!isKamelet ) { // route in RouteTemplate
+                delete value?.dslName;
+                delete value?.stepName;
+                delete value?.inArray;
+                return value;
             } else if (
                 (value.inArray && !value.inSteps) ||
                 dslName === 'ExpressionSubElementDefinition' ||
@@ -302,6 +313,8 @@ export class CamelDefinitionYaml {
             .forEach((f: any) => 
result.push(CamelDefinitionYamlStep.readRestConfigurationDefinition(f.restConfiguration)));
         flows.filter((e: any) => e.hasOwnProperty('rest'))
             .forEach((f: any) => 
result.push(CamelDefinitionYamlStep.readRestDefinition(f.rest)));
+        flows.filter((e: any) => e.hasOwnProperty('routeTemplate'))
+            .forEach((f: any) => 
result.push(CamelDefinitionYamlStep.readRouteTemplateDefinition(f.routeTemplate)));
         flows.filter((e: any) => e.hasOwnProperty('route'))
             .forEach((f: any) => 
result.push(CamelDefinitionYamlStep.readRouteDefinition(f.route)));
         flows.filter((e: any) => e.hasOwnProperty('from'))
diff --git a/karavan-core/src/core/model/IntegrationDefinition.ts 
b/karavan-core/src/core/model/IntegrationDefinition.ts
index 7e95432b..4f424584 100644
--- a/karavan-core/src/core/model/IntegrationDefinition.ts
+++ b/karavan-core/src/core/model/IntegrationDefinition.ts
@@ -121,7 +121,7 @@ export class Integration {
     kind: string = 'Integration' || 'Kamelet';
     metadata: Metadata = new Metadata();
     spec: Spec = new Spec();
-    type: 'crd' | 'plain' | 'kamelet' = 'crd';
+    type: 'crd' | 'plain' | 'kamelet' = 'plain';
 
     public constructor(init?: Partial<Integration>) {
         Object.assign(this, init);
diff --git a/karavan-core/test/routeTemplate.spec.ts 
b/karavan-core/test/routeTemplate.spec.ts
new file mode 100644
index 00000000..59fdbba4
--- /dev/null
+++ b/karavan-core/test/routeTemplate.spec.ts
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import 'mocha';
+import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
+import * as fs from 'fs';
+import { expect } from 'chai';
+
+describe('Route Templates', () => {
+
+    it('Parse routeTemplate1', () => {
+        const text = fs.readFileSync('test/routeTemplate1.camel.yaml', 
{encoding: 'utf8', flag: 'r'});
+        const i = CamelDefinitionYaml.yamlToIntegration("test1.yaml", text);
+        const text2 = CamelDefinitionYaml.integrationToYaml(i);
+        expect(text2).to.equal(text);
+    });
+
+    it('Parse routeTemplate2', () => {
+        const text = fs.readFileSync('test/routeTemplate2.camel.yaml', 
{encoding: 'utf8', flag: 'r'});
+        const i = CamelDefinitionYaml.yamlToIntegration("test1.yaml", text);
+        const text2 = CamelDefinitionYaml.integrationToYaml(i);
+        expect(text2).to.equal(text);
+    });
+});
\ No newline at end of file
diff --git a/karavan-core/test/routeTemplate1.camel.yaml 
b/karavan-core/test/routeTemplate1.camel.yaml
new file mode 100644
index 00000000..5c495b65
--- /dev/null
+++ b/karavan-core/test/routeTemplate1.camel.yaml
@@ -0,0 +1,21 @@
+- routeTemplate:
+    id: routeFileReaderTemplate
+    description: File reader
+    route:
+      id: routeFileReader
+      description: File reader
+      from:
+        id: from-c667
+        description: Read file
+        uri: file
+        parameters:
+          directoryName: "{{folderName}}"
+          noop: true
+        steps:
+          - to:
+              id: to-1234
+              uri: direct
+              parameters:
+                name: converter
+    parameters:
+      - name: folderName
diff --git a/karavan-core/test/routeTemplate2.camel.yaml 
b/karavan-core/test/routeTemplate2.camel.yaml
new file mode 100644
index 00000000..fd3dd399
--- /dev/null
+++ b/karavan-core/test/routeTemplate2.camel.yaml
@@ -0,0 +1,33 @@
+- routeTemplate:
+    id: routeFileReaderTemplate
+    description: File reader
+    route:
+      id: routeFileReader
+      description: File reader
+      from:
+        id: from-c667
+        description: Read file
+        uri: file
+        parameters:
+          directoryName: "{{folderName}}"
+          noop: true
+        steps:
+          - to:
+              id: to-1234
+              uri: direct
+              parameters:
+                name: converter
+    parameters:
+      - name: folderName
+- route:
+    id: route-dummy
+    autoStartup: false
+    from:
+      id: from-dummy
+      uri: direct
+      parameters:
+        name: dummy
+      steps:
+        - log:
+            id: log-b47b
+            message: DUMMY

Reply via email to