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


The following commit(s) were added to refs/heads/main by this push:
     new 5eaf7dee Fix #1239
5eaf7dee is described below

commit 5eaf7deef238f7fb124f20ecfc847545db848486
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Fri Apr 19 17:28:45 2024 -0400

    Fix #1239
---
 karavan-core/src/core/api/CamelDefinitionYaml.ts | 70 +++++++++++-------------
 karavan-core/test/integrationToYaml.spec.ts      | 51 ++++++++---------
 karavan-core/test/postgresql-source.kamelet.yaml |  7 +--
 3 files changed, 56 insertions(+), 72 deletions(-)

diff --git a/karavan-core/src/core/api/CamelDefinitionYaml.ts 
b/karavan-core/src/core/api/CamelDefinitionYaml.ts
index bd39d1c6..6e2d14b9 100644
--- a/karavan-core/src/core/api/CamelDefinitionYaml.ts
+++ b/karavan-core/src/core/api/CamelDefinitionYaml.ts
@@ -276,46 +276,31 @@ export class CamelDefinitionYaml {
         return 'none';
     };
     static flowsToCamelElements = (flows: any[]): any[] => {
-        const rules: { [key: string]: (flow: any) => any } = {
-            restConfiguration: (flow: any) =>
-                
CamelDefinitionYamlStep.readRestConfigurationDefinition(flow.restConfiguration),
-            rest: (flow: any) => 
CamelDefinitionYamlStep.readRestDefinition(flow.rest),
-            route: (flow: any) => 
CamelDefinitionYamlStep.readRouteDefinition(flow.route),
-            from: (flow: any) => 
CamelDefinitionYamlStep.readRouteDefinition(new RouteDefinition({ from: 
flow.from })),
-            beans: (flow: any) => CamelDefinitionYaml.readBeanDefinition(flow),
-            routeConfiguration: (flow: any) =>
-                
CamelDefinitionYamlStep.readRouteConfigurationDefinition(flow.routeConfiguration),
-            errorHandler: (flow: any) =>
-                CamelDefinitionYamlStep.readRouteConfigurationDefinition(
-                    new RouteConfigurationDefinition({ errorHandler: 
flow.errorHandler }),
-                ),
-            onException: (flow: any) =>
-                CamelDefinitionYamlStep.readRouteConfigurationDefinition(
-                    new RouteConfigurationDefinition({ onException: 
flow.onException }),
-                ),
-            intercept: (flow: any) =>
-                CamelDefinitionYamlStep.readRouteConfigurationDefinition(
-                    new RouteConfigurationDefinition({ intercept: 
flow.intercept }),
-                ),
-            interceptFrom: (flow: any) =>
-                CamelDefinitionYamlStep.readRouteConfigurationDefinition(
-                    new RouteConfigurationDefinition({ interceptFrom: 
flow.interceptFrom }),
-                ),
-            interceptSendToEndpoint: (flow: any) =>
-                CamelDefinitionYamlStep.readRouteConfigurationDefinition(
-                    new RouteConfigurationDefinition({ 
interceptSendToEndpoint: flow.interceptSendToEndpoint }),
-                ),
-            onCompletion: (flow: any) =>
-                CamelDefinitionYamlStep.readRouteConfigurationDefinition(
-                    new RouteConfigurationDefinition({ onCompletion: 
flow.onCompletion }),
-                ),
-        };
-
         const result: any[] = [];
-
-        for (const [rule, func] of Object.entries(rules)) {
-            flows.filter((e: any) => e.hasOwnProperty(rule)).forEach((f: any) 
=> result.push(func(f)));
-        }
+        flows.filter((e: any) => e.hasOwnProperty('restConfiguration'))
+            .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('route'))
+            .forEach((f: any) => 
result.push(CamelDefinitionYamlStep.readRouteDefinition(f.route)));
+        flows.filter((e: any) => e.hasOwnProperty('from'))
+            .forEach((f: any) =>  
result.push(CamelDefinitionYamlStep.readRouteDefinition(new 
RouteDefinition({from: f.from}))));
+        flows.filter((e: any) => e.hasOwnProperty('beans'))
+            .forEach((b: any) => 
result.push(CamelDefinitionYaml.readBeanDefinition(b)));
+        flows.filter((e: any) => e.hasOwnProperty('routeConfiguration'))
+            .forEach((e: any) => 
result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(e.routeConfiguration)));
+        flows.filter((e: any) => e.hasOwnProperty('errorHandler'))
+            .forEach((f: any) =>  
result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new 
RouteConfigurationDefinition({errorHandler: f.errorHandler}))));
+        flows.filter((e: any) => e.hasOwnProperty('onException'))
+            .forEach((f: any) =>  
result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new 
RouteConfigurationDefinition({onException: f.onException}))));
+        flows.filter((e: any) => e.hasOwnProperty('intercept'))
+            .forEach((f: any) =>  
result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new 
RouteConfigurationDefinition({intercept: f.intercept}))));
+        flows.filter((e: any) => e.hasOwnProperty('interceptFrom'))
+            .forEach((f: any) =>  
result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new 
RouteConfigurationDefinition({interceptFrom: f.interceptFrom}))));
+        flows.filter((e: any) => e.hasOwnProperty('interceptSendToEndpoint'))
+            .forEach((f: any) =>  
result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new 
RouteConfigurationDefinition({interceptSendToEndpoint: 
f.interceptSendToEndpoint}))));
+        flows.filter((e: any) => e.hasOwnProperty('onCompletion'))
+            .forEach((f: any) =>  
result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new 
RouteConfigurationDefinition({onCompletion: f.onCompletion}))));
 
         return result;
     };
@@ -332,6 +317,13 @@ export class CamelDefinitionYaml {
                     );
                 }
             }
+            if (bean && bean.property && Array.isArray(bean.property)) {
+                // convert map style to properties if requires
+                Array.from(bean.property).forEach((val: any) => {
+                    props[val.key] = val.value;
+                })
+                delete bean.property;
+            }
             bean.properties = props;
             result.beans.push(new RegistryBeanDefinition(bean));
         }
diff --git a/karavan-core/test/integrationToYaml.spec.ts 
b/karavan-core/test/integrationToYaml.spec.ts
index 3369a717..a58243fb 100644
--- a/karavan-core/test/integrationToYaml.spec.ts
+++ b/karavan-core/test/integrationToYaml.spec.ts
@@ -20,40 +20,33 @@ import 'mocha';
 import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
 import {FilterDefinition, ToDefinition} from 
"../src/core/model/CamelDefinition";
 import { RouteDefinition} from "../src/core/model/CamelDefinition";
+import { RegistryBeanDefinition } from '../lib/model/CamelDefinition';
 
-describe('CRD YAML to Integration', () => {
+describe('Integration to YAML', () => {
 
-
-
-    it('YAML <-> Object 1', () => {
-        const yaml = 
fs.readFileSync('test/integration1.yaml',{encoding:'utf8', flag:'r'});
-        const i = CamelDefinitionYaml.yamlToIntegration("test1.yaml", yaml);
-        expect(i.metadata.name).to.equal('test1.yaml');
-        expect(i.kind).to.equal('Integration');
-        expect(i.spec.flows?.length).to.equal(1);
-        expect(i.type).to.equal('crd');
-        if (i.spec.flows){
-            const f:FilterDefinition = (i.spec.flows[0] as 
RouteDefinition).from.steps[1];
-            const t:ToDefinition = <ToDefinition> (f.steps ? f.steps[0] : 
undefined);
-            expect(t.uri).to.equal("log");
-            expect(t.parameters.level).to.equal("OFF");
+    it('YAML <-> Object', () => {
+        const yaml = 
fs.readFileSync('test/avro-serialize-action.kamelet.yaml',{encoding:'utf8', 
flag:'r'});
+        const i = 
CamelDefinitionYaml.yamlToIntegration("avro-serialize-action.kamelet.yaml", 
yaml);
+        expect(i.metadata.name).to.equal('avro-serialize-action');
+        expect(i.kind).to.equal('Kamelet');
+        if (i.spec.flows?.[1]){
+            const b:RegistryBeanDefinition = (i.spec.flows?.[1].beans[0] as 
RegistryBeanDefinition);
+            expect(b.properties.validate).to.equal("{{validate}}");
+            expect(b.properties.schema).to.equal("{{schema:}}");
         }
-        console.log(CamelDefinitionYaml.integrationToYaml(i))
     });
 
-    it('YAML <-> Object 2', () => {
-        const yaml = 
fs.readFileSync('test/integration2.yaml',{encoding:'utf8', flag:'r'});
-        const i = CamelDefinitionYaml.yamlToIntegration("test1.yaml", yaml);
-        expect(i.metadata.name).to.equal('test1.yaml');
-        expect(i.kind).to.equal('Integration');
-        expect(i.spec.flows?.length).to.equal(1);
-        expect(i.type).to.equal('crd');
-
-        if (i.spec.flows){
-            const f:FilterDefinition = (i.spec.flows[0] as 
RouteDefinition).from.steps[1];
-            const t:ToDefinition = <ToDefinition> (f.steps ? f.steps[0] : 
undefined);
-            expect(t.uri).to.equal("log");
-            expect(t.parameters.level).to.equal("OFF");
+    it('YAML <-> Object', () => {
+        const yaml = 
fs.readFileSync('test/postgresql-source.kamelet.yaml',{encoding:'utf8', 
flag:'r'});
+        const i = 
CamelDefinitionYaml.yamlToIntegration("postgresql-source.kamelet.yaml", yaml);
+        expect(i.metadata.name).to.equal('postgresql-source');
+        expect(i.kind).to.equal('Kamelet');
+        if (i.spec.flows?.[1]){
+            const b:RegistryBeanDefinition = (i.spec.flows?.[1].beans[0] as 
RegistryBeanDefinition);
+            expect(b.properties.username).to.equal("{{username}}");
+            expect(b.properties.password).to.equal("{{password}}");
+            
expect(b.properties.url).to.equal("jdbc:postgresql://{{serverName}}:{{serverPort}}/{{databaseName}}");
+            
expect(b.properties.driverClassName).to.equal("org.postgresql.Driver");
         }
     });
 
diff --git a/karavan-core/test/postgresql-source.kamelet.yaml 
b/karavan-core/test/postgresql-source.kamelet.yaml
index 2fcd541e..bb3bb952 100644
--- a/karavan-core/test/postgresql-source.kamelet.yaml
+++ b/karavan-core/test/postgresql-source.kamelet.yaml
@@ -20,7 +20,7 @@ metadata:
   name: postgresql-source
   annotations:
     camel.apache.org/kamelet.support.level: "Stable"
-    camel.apache.org/catalog.version: "4.1.0-SNAPSHOT"
+    camel.apache.org/catalog.version: "4.6.0-SNAPSHOT"
     camel.apache.org/kamelet.icon: 
"data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dGl0bGU+UG9zdGdyZVNRTCBpY29uPC90aXRsZT48cGF0aCBkPSJNMTcuMTI4IDBhMTAuMTM0IDEwLjEzNCAwIDAgMC0yLjc1NS40MDNsLS4wNjMuMDJBMTAuOTIyIDEwLjkyMiAwIDAgMCAxMi42LjI1OEMxMS40MjIuMjM4IDEwLjQxLjUyNCA5LjU5NCAxIDguNzkuNzIxIDcuMTIyLjI0IDUuMzY0LjMzNiA0LjE0LjQwMyAyLjgwNC43NzUgMS44MTQgMS44Mi44MjcgMi44NjUuMzA1IDQuNDgyLjQxNSA2LjY4MmMuMDMuNjA3LjIwMyAxLjU5Ny
 [...]
     camel.apache.org/provider: "Apache Software Foundation"
     camel.apache.org/kamelet.group: "SQL"
@@ -62,7 +62,6 @@ spec:
         type: string
         format: password
         x-descriptors:
-          - urn:alm:descriptor:com.tectonic.ui:password
           - urn:camel:group:credentials
       query:
         title: Query
@@ -90,8 +89,8 @@ spec:
     - "camel:jackson"
     - "camel:kamelet"
     - "camel:sql"
-    - "mvn:org.postgresql:postgresql:42.6.0"
-    - "mvn:org.apache.commons:commons-dbcp2:2.10.0"
+    - "mvn:org.postgresql:postgresql:42.7.3"
+    - "mvn:org.apache.commons:commons-dbcp2:2.12.0"
   template:
     beans:
       - name: dsBean

Reply via email to