You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/12/23 19:02:30 UTC
[camel-karavan] branch main updated: Function to check if integration has node withId. #577
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 3a311c7 Function to check if integration has node withId. #577
3a311c7 is described below
commit 3a311c7f0ec45a9a12df51efbb4a913e38a5b7d6
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Fri Dec 23 11:43:47 2022 -0500
Function to check if integration has node withId. #577
---
karavan-core/src/core/api/CamelDefinitionApiExt.ts | 6 ++
karavan-core/test/findStep.spec.ts | 22 ++---
karavan-core/test/findStep.yaml | 93 ++++++++++++++--------
3 files changed, 72 insertions(+), 49 deletions(-)
diff --git a/karavan-core/src/core/api/CamelDefinitionApiExt.ts b/karavan-core/src/core/api/CamelDefinitionApiExt.ts
index a72b7f0..d41c954 100644
--- a/karavan-core/src/core/api/CamelDefinitionApiExt.ts
+++ b/karavan-core/src/core/api/CamelDefinitionApiExt.ts
@@ -27,6 +27,7 @@ import {
Integration
} from "../model/IntegrationDefinition";
import {CamelDefinitionApi} from "./CamelDefinitionApi";
+import {CamelDefinitionYaml} from "./CamelDefinitionYaml";
export class ChildElement {
name: string = ''
@@ -145,6 +146,11 @@ export class CamelDefinitionApiExt {
return new CamelElementMeta(result?.step, result?.parentUuid, result?.position);
}
+ static hasElementWithId = (integration: Integration, id: string): boolean => {
+ const yaml = CamelDefinitionYaml.integrationToYaml(integration);
+ return yaml.includes("id: " + id);
+ }
+
static moveRouteElement = (integration: Integration, source: string, target: string, asChild: boolean): Integration => {
const sourceFindStep = CamelDefinitionApiExt.findElementMetaInIntegration(integration, source);
const sourceStep = sourceFindStep.step;
diff --git a/karavan-core/test/findStep.spec.ts b/karavan-core/test/findStep.spec.ts
index 7358be0..5515f57 100644
--- a/karavan-core/test/findStep.spec.ts
+++ b/karavan-core/test/findStep.spec.ts
@@ -97,23 +97,15 @@ describe('Find Step', () => {
expect(log.message).to.equal(log2.message);
});
- it('Find Steps in YAML', () => {
+ it('Find Steps in YAML by Id', () => {
const yaml = fs.readFileSync('test/findStep.yaml',{encoding:'utf8', flag:'r'});
const i = CamelDefinitionYaml.yamlToIntegration("demo.yaml", yaml);
- const step: StepDefinition = i.spec.flows?.[0].from.steps[0];
- const choice: ChoiceDefinition = i.spec.flows?.[0].from.steps[0].steps[0];
- const log: LogDefinition = i.spec.flows?.[0].from.steps[1];
-
- // i.spec.flows?.[0].from.steps?.forEach((s:any) => console.log(s.uuid, CamelDefinitionApiExt.findElementInIntegration(i, s.uuid)?.dslName));
-
- // console.log('----')
- // CamelDefinitionApiExt.findElementPathUuids(i, log.uuid).forEach(u => console.log(u, CamelDefinitionApiExt.findElementInIntegration(i, u)?.dslName))
-
- // console.log('----')
- // CamelDefinitionApiExt.findElementPathUuids(i, step.uuid).forEach(u => console.log(u, CamelDefinitionApiExt.findElementInIntegration(i, u)?.dslName))
-
- // console.log('----')
- // CamelDefinitionApiExt.findElementPathUuids(i, choice.uuid).forEach(u => console.log(u, CamelDefinitionApiExt.findElementInIntegration(i, u)?.dslName))
+ const yaml2 = CamelDefinitionYaml.integrationToYaml(i);
+ expect(yaml2).to.equal(yaml);
+ const res1 = CamelDefinitionApiExt.hasElementWithId(i, 'to-6a8b');
+ const res2 = CamelDefinitionApiExt.hasElementWithId(i, 'to-6a81');
+ expect(res1).to.equal(true);
+ expect(res2).to.equal(false);
});
});
\ No newline at end of file
diff --git a/karavan-core/test/findStep.yaml b/karavan-core/test/findStep.yaml
index 1a0d654..4f21940 100644
--- a/karavan-core/test/findStep.yaml
+++ b/karavan-core/test/findStep.yaml
@@ -1,35 +1,60 @@
-apiVersion: camel.apache.org/v1
-kind: Integration
-metadata:
- name: postman.yaml
-spec:
- flows:
- - route:
- from:
- uri: kamelet:timer-source
- steps:
- - step:
- steps:
- - choice: {}
- - log: {}
- - log:
- message: ${body}
- - aggregate: {}
- - choice: {}
- - split:
+- restConfiguration: {}
+- rest:
+ id: rest-6cff
+ get:
+ - id: get-ea54
+- route:
+ id: route-66bd
+ from:
+ uri: kamelet:timer-source
+ id: from-6c72
+ parameters:
+ period: 2000
+ message: Hello World
+ steps:
+ - step:
+ id: step-6889
+ steps:
+ - choice:
+ id: choice-5cca
+ - log:
+ id: log-7d33
+ - log:
+ message: ${body}
+ id: log-0023
+ - aggregate:
+ id: aggregate-6615
+ - choice:
+ when:
+ - id: when-2521
expression: {}
- - saga: {}
- - to:
- uri: direct:hello-world
- - to:
- uri: salesforce:getSObject
- parameters:
- sObjectId: xxx
- sObjectClass: Account
- parameters:
- period: 2000
- message: Hello World
- - route:
- from:
- uri: direct:hello-world
- id: hello-world
\ No newline at end of file
+ steps:
+ - log:
+ id: log-8bc9
+ id: choice-9b86
+ otherwise:
+ id: otherwise-4843
+ steps:
+ - to:
+ uri: arangodb
+ id: to-3d1c
+ - split:
+ id: split-fe40
+ expression: {}
+ - saga:
+ id: saga-0075
+ - to:
+ uri: direct:hello-world
+ id: to-6a8b
+ - to:
+ uri: salesforce:getSObject
+ id: to-6f22
+ parameters:
+ sObjectId: xxx
+ sObjectClass: Account
+- route:
+ id: hello-world
+ from:
+ uri: direct:hello-world
+ id: from-5a9f
+- routeConfiguration: {}