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 a0f2a15f Intercept analysis for #787
a0f2a15f is described below

commit a0f2a15fafd0342272effd56eaea4de212e7338a
Author: Marat Gubaidullin <marat.gubaidul...@gmail.com>
AuthorDate: Fri Jun 16 10:49:01 2023 -0400

    Intercept analysis for #787
---
 karavan-core/src/core/api/CamelDefinitionYaml.ts | 15 ++++++
 karavan-core/test/intercept.spec.ts              | 66 ++++++++++++++++++++++++
 karavan-core/test/intercept.yaml                 | 19 +++++++
 3 files changed, 100 insertions(+)

diff --git a/karavan-core/src/core/api/CamelDefinitionYaml.ts 
b/karavan-core/src/core/api/CamelDefinitionYaml.ts
index 8b9af809..5c63b108 100644
--- a/karavan-core/src/core/api/CamelDefinitionYaml.ts
+++ b/karavan-core/src/core/api/CamelDefinitionYaml.ts
@@ -112,6 +112,19 @@ export class CamelDefinitionYaml {
             let newValue: any = JSON.parse(JSON.stringify(value));
             delete newValue.dslName;
             delete newValue[stepNameField];
+            // if ((value.inArray && !value.inSteps
+            //     && ["intercept",
+            //         "interceptFrom",
+            //         "interceptSendToEndpoint",
+            //         "onCompletion",
+            //         "onException"]
+            //         .includes(stepName))) {
+            //     delete newValue.inArray;
+            //     delete newValue.inSteps;
+            //     const xValue: any = {};
+            //     xValue[stepName] = newValue;
+            //     return xValue;
+            // } else
             if ((value.inArray && !value.inSteps)
                 || dslName === 'ExpressionSubElementDefinition'
                 || dslName === 'ExpressionDefinition'
@@ -192,6 +205,8 @@ export class CamelDefinitionYaml {
             .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}))));
         return result;
     }
 
diff --git a/karavan-core/test/intercept.spec.ts 
b/karavan-core/test/intercept.spec.ts
new file mode 100644
index 00000000..07fcf079
--- /dev/null
+++ b/karavan-core/test/intercept.spec.ts
@@ -0,0 +1,66 @@
+/*
+ * 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 * as fs from 'fs';
+import 'mocha';
+import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
+import {CamelUtil} from "../src/core/api/CamelUtil";
+import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
+import {
+    CatchDefinition,
+    ExpressionDefinition,
+    FromDefinition, LogDefinition,
+    PropertyExpressionDefinition
+} from "../src/core/model/CamelDefinition";
+import {expect} from "chai";
+import {
+    InterceptDefinition,
+    RouteConfigurationDefinition,
+    RouteDefinition,
+    SagaDefinition,
+    ToDefinition,
+    TryDefinition
+} from "../lib/model/CamelDefinition";
+import {Integration} from "../lib/model/IntegrationDefinition";
+
+describe('Intercept', () => {
+
+    it('Intercept YAML', () => {
+        // const yaml = fs.readFileSync('test/demo.yaml',{encoding:'utf8', 
flag:'r'});
+        // const i = CamelDefinitionYaml.yamlToIntegration("demo.yaml", yaml);
+        const i = Integration.createNew("intercept.camel", 'plain');
+
+        const intercept1 = new InterceptDefinition({
+            steps: [new LogDefinition({logName: 'log1', message: 
"intercept1"})]
+        })
+        const intercept2 = new InterceptDefinition({
+            steps: [new LogDefinition({logName: 'log2', message: 
"intercept2"})]
+        })
+        const routeConfiguration = new RouteConfigurationDefinition({
+            intercept: [intercept1, intercept2]
+        });
+        i.spec.flows?.push(routeConfiguration);
+
+        const yaml = CamelDefinitionYaml.integrationToYaml(i);
+        // console.log(yaml);
+
+        const i2 = CamelDefinitionYaml.yamlToIntegration("demo.yaml", yaml);
+        console.log(i.spec.flows?.[0].intercept);
+        console.log("------");
+        console.log(i2.spec.flows?.[0].intercept);
+    });
+
+});
\ No newline at end of file
diff --git a/karavan-core/test/intercept.yaml b/karavan-core/test/intercept.yaml
new file mode 100644
index 00000000..08a4c57f
--- /dev/null
+++ b/karavan-core/test/intercept.yaml
@@ -0,0 +1,19 @@
+- routeConfiguration:
+    intercept:
+      - intercept:
+          id: intercept-9b31
+          steps:
+            - log:
+                message: Interceptor ${body}
+                id: log-c2f5
+- route:
+    id: route-ddaa
+    from:
+      uri: kamelet:timer-source
+      id: from-847d
+      parameters:
+        message: Hello
+      steps:
+        - log:
+            message: Main ${body}
+            id: log-7972
\ No newline at end of file

Reply via email to