karavan-core 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.bebelrc +3 -0
- package/.mocharc.json +11 -0
- package/.prettierignore +9 -0
- package/.prettierrc +14 -0
- package/package.json +62 -0
- package/src/core/api/CamelDefinitionApi.ts +3271 -0
- package/src/core/api/CamelDefinitionApiExt.ts +757 -0
- package/src/core/api/CamelDefinitionYaml.ts +412 -0
- package/src/core/api/CamelDefinitionYamlStep.ts +4733 -0
- package/src/core/api/CamelDisplayUtil.ts +143 -0
- package/src/core/api/CamelUtil.ts +360 -0
- package/src/core/api/ComponentApi.ts +368 -0
- package/src/core/api/KameletApi.ts +147 -0
- package/src/core/api/MainConfigurationApi.ts +47 -0
- package/src/core/api/ProjectModelApi.ts +75 -0
- package/src/core/api/SpiBeanApi.ts +104 -0
- package/src/core/api/TemplateApi.ts +58 -0
- package/src/core/api/TopologyUtils.ts +392 -0
- package/src/core/api/VariableUtil.ts +104 -0
- package/src/core/model/CamelDefinition.ts +3783 -0
- package/src/core/model/CamelMetadata.ts +2714 -0
- package/src/core/model/ComponentModels.ts +106 -0
- package/src/core/model/IntegrationDefinition.ts +188 -0
- package/src/core/model/KameletModels.ts +223 -0
- package/src/core/model/MainConfigurationModel.ts +37 -0
- package/src/core/model/ProjectModel.ts +43 -0
- package/src/core/model/SpiBeanModels.ts +53 -0
- package/src/core/model/TopologyDefinition.ts +117 -0
- package/test/addStep.spec.ts +124 -0
- package/test/addStep1.yaml +27 -0
- package/test/allowableValues.camel.yaml +19 -0
- package/test/allowableValues.spec.ts +30 -0
- package/test/avro-serialize-action.kamelet.yaml +70 -0
- package/test/beans.spec.ts +92 -0
- package/test/beans1.yaml +36 -0
- package/test/beans2.yaml +42 -0
- package/test/beans3.yaml +7 -0
- package/test/checkRequired.spec.ts +53 -0
- package/test/circuitBreaker.spec.ts +57 -0
- package/test/circuitBreaker.yaml +19 -0
- package/test/cloneDefinition.spec.ts +106 -0
- package/test/createKamelet.spec.ts +38 -0
- package/test/cxf.json +615 -0
- package/test/cxf.spec.ts +44 -0
- package/test/cxf.yaml +15 -0
- package/test/deleteStep.spec.ts +74 -0
- package/test/demo.spec.ts +49 -0
- package/test/demo.yaml +32 -0
- package/test/doCatchOnWhen.camel.yaml +20 -0
- package/test/doCatchOnWhen.spec.ts +36 -0
- package/test/errorHandler.spec.ts +38 -0
- package/test/errorHandler1.yaml +27 -0
- package/test/expression.spec.ts +55 -0
- package/test/findStep.spec.ts +112 -0
- package/test/findStep.yaml +65 -0
- package/test/getElementProperties.spec.ts +32 -0
- package/test/getElementPropertiesByName.spec.ts +31 -0
- package/test/getExpressionLanguage.spec.ts +40 -0
- package/test/hasElementWithId.camel.yaml +98 -0
- package/test/hasElementWithId.spec.ts +57 -0
- package/test/hasElementWithId1.camel.yaml +16 -0
- package/test/hasElementWithIdError.camel.yaml +98 -0
- package/test/integration.spec.ts +60 -0
- package/test/integration1.yaml +24 -0
- package/test/integration2.yaml +23 -0
- package/test/integrationToYaml.spec.ts +51 -0
- package/test/intercept.spec.ts +62 -0
- package/test/intercept.yaml +19 -0
- package/test/is-not-integration.yaml +5114 -0
- package/test/isIntegration.spec.ts +45 -0
- package/test/kamelet.spec.ts +61 -0
- package/test/metadata/components.json +697 -0
- package/test/metadata/kamelets.yaml +23414 -0
- package/test/metadata/spiBeans.json +3094 -0
- package/test/multiObjectProperties.spec.ts +46 -0
- package/test/multiObjectProperties1.yaml +19 -0
- package/test/multiple.spec.ts +38 -0
- package/test/multiple.yaml +29 -0
- package/test/openapi.spec.ts +48 -0
- package/test/openapi.yaml +7 -0
- package/test/placeholder.spec.ts +32 -0
- package/test/placeholder.yaml +133 -0
- package/test/plain-try-catch.yaml +31 -0
- package/test/plain.spec.ts +72 -0
- package/test/plain1.yaml +22 -0
- package/test/plain2.yaml +13 -0
- package/test/plain3.yaml +5 -0
- package/test/plain4.yaml +5 -0
- package/test/postgresql-source.kamelet.yaml +113 -0
- package/test/restConfigDsl.yaml +15 -0
- package/test/restDsl.spec.ts +83 -0
- package/test/restDsl.yaml +29 -0
- package/test/routes.spec.ts +37 -0
- package/test/routes1.yaml +31 -0
- package/test/supported-components.json +1221 -0
- package/test/supportedComponents.spec.ts +34 -0
- package/test/template1.AggregationStrategy.java +21 -0
- package/test/template1.Processor.java +13 -0
- package/test/template2.AggregationStrategy.java +21 -0
- package/test/template2.Processor.java +13 -0
- package/test/templateApi.spec.ts +45 -0
- package/test/timer-source.kamelet.yaml +75 -0
- package/test/tod.spec.ts +31 -0
- package/test/tod.yaml +9 -0
- package/test/topology.spec.ts +51 -0
- package/test/topology1.camel.yaml +56 -0
- package/test/topology2.camel.yaml +44 -0
- package/test/topology3.camel.yaml +27 -0
- package/test/tsconfig.testing.json +14 -0
- package/test/updateStep.spec.ts +72 -0
- package/test/variable1.camel.yaml +42 -0
- package/test/variable2.camel.yaml +42 -0
- package/test/variables.spec.ts +34 -0
- package/tsconfig.json +34 -0
@@ -0,0 +1,143 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
+
* contributor license agreements. See the NOTICE file distributed with
|
4
|
+
* this work for additional information regarding copyright ownership.
|
5
|
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
6
|
+
* (the "License"); you may not use this file except in compliance with
|
7
|
+
* the License. You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
import { Integration, CamelElement } from '../model/IntegrationDefinition';
|
18
|
+
import { CamelUtil } from './CamelUtil';
|
19
|
+
import { CamelDefinitionApi } from './CamelDefinitionApi';
|
20
|
+
import { CamelDefinitionApiExt } from './CamelDefinitionApiExt';
|
21
|
+
import { KameletModel } from '../model/KameletModels';
|
22
|
+
import { RouteDefinition } from '../model/CamelDefinition';
|
23
|
+
import { ComponentApi } from './ComponentApi';
|
24
|
+
import { CamelMetadataApi } from '../model/CamelMetadata';
|
25
|
+
|
26
|
+
export class CamelDisplayUtil {
|
27
|
+
private constructor() {}
|
28
|
+
|
29
|
+
static getTitle = (element: CamelElement): string => {
|
30
|
+
const k: KameletModel | undefined = CamelUtil.getKamelet(element);
|
31
|
+
if (k) {
|
32
|
+
return k.title();
|
33
|
+
} else if (element.dslName === 'RouteDefinition') {
|
34
|
+
const routeId = (element as RouteDefinition).id
|
35
|
+
return routeId ? routeId : CamelUtil.capitalizeName((element as any).stepName);
|
36
|
+
} else if ((element as any).uri && (['ToDefinition', 'FromDefinition', 'PollDefinition'].includes(element.dslName))) {
|
37
|
+
const uri = (element as any).uri
|
38
|
+
return ComponentApi.getComponentTitleFromUri(uri) || '';
|
39
|
+
} else {
|
40
|
+
const title = CamelMetadataApi.getCamelModelMetadataByClassName(element.dslName);
|
41
|
+
return title ? title.title : CamelUtil.capitalizeName((element as any).stepName);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
static getDescription = (element: CamelElement): string => {
|
46
|
+
const kamelet: KameletModel | undefined = CamelUtil.getKamelet(element);
|
47
|
+
if (kamelet) {
|
48
|
+
return kamelet.spec.definition.description;
|
49
|
+
} else if ((element as any).uri && (['ToDefinition', 'FromDefinition', 'PollDefinition'].includes(element.dslName))) {
|
50
|
+
const uri = (element as any).uri
|
51
|
+
return ComponentApi.getComponentDescriptionFromUri(uri) || '';
|
52
|
+
} else {
|
53
|
+
const description = CamelMetadataApi.getCamelModelMetadataByClassName(element.dslName)?.description;
|
54
|
+
return description ? description : CamelDisplayUtil.getTitle(element);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
static getStepDescription = (element: CamelElement): string => {
|
59
|
+
const description = (element as any).description;
|
60
|
+
return description ? description : CamelDisplayUtil.getTitle(element);
|
61
|
+
}
|
62
|
+
|
63
|
+
static isStepDefinitionExpanded = (integration: Integration, stepUuid: string, selectedUuid: string | undefined): boolean => {
|
64
|
+
const expandedUuids: string[] = [];
|
65
|
+
if (selectedUuid) {
|
66
|
+
expandedUuids.push(...CamelDisplayUtil.getParentStepDefinitions(integration, selectedUuid));
|
67
|
+
}
|
68
|
+
return expandedUuids.includes(stepUuid);
|
69
|
+
}
|
70
|
+
|
71
|
+
static getParentStepDefinitions = (integration: Integration, uuid: string): string[] => {
|
72
|
+
const result: string[] = [];
|
73
|
+
let meta = CamelDefinitionApiExt.findElementMetaInIntegration(integration, uuid);
|
74
|
+
let i = 0;
|
75
|
+
while (meta && meta.step?.dslName !== 'FromDefinition' && i < 100) {
|
76
|
+
i++;
|
77
|
+
if (meta.step?.dslName === 'StepDefinition') {
|
78
|
+
result.push(meta.step.uuid);
|
79
|
+
}
|
80
|
+
if (meta.parentUuid) {
|
81
|
+
meta = CamelDefinitionApiExt.findElementMetaInIntegration(integration, meta.parentUuid);
|
82
|
+
} else {
|
83
|
+
break;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
|
89
|
+
static setIntegrationVisibility = (integration: Integration, selectedUuid: string | undefined): Integration => {
|
90
|
+
const clone: Integration = CamelUtil.cloneIntegration(integration);
|
91
|
+
const expandedUuids: string[] = [];
|
92
|
+
if (selectedUuid) {
|
93
|
+
expandedUuids.push(...CamelDisplayUtil.getParentStepDefinitions(integration, selectedUuid));
|
94
|
+
}
|
95
|
+
|
96
|
+
const flows: any[] = [];
|
97
|
+
for (const flow of clone.spec.flows || []) {
|
98
|
+
if (flow.dslName !== 'RouteDefinition') {
|
99
|
+
flows.push(flow);
|
100
|
+
} else {
|
101
|
+
const visibleRoute = CamelDisplayUtil.setElementVisibility(flow, true, expandedUuids);
|
102
|
+
if (Object.keys(visibleRoute).length !== 0) {
|
103
|
+
flows.push(visibleRoute);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
clone.spec.flows = flows;
|
109
|
+
return clone;
|
110
|
+
}
|
111
|
+
|
112
|
+
static setElementVisibility = (step: CamelElement, showChildren: boolean, expandedUuids: string[]): CamelElement => {
|
113
|
+
const result = CamelDefinitionApi.createStep(step.dslName, step);
|
114
|
+
result.showChildren = showChildren;
|
115
|
+
if (result.dslName === 'StepDefinition') {
|
116
|
+
showChildren = expandedUuids.includes(result.uuid);
|
117
|
+
}
|
118
|
+
|
119
|
+
const elementChildDefinition = CamelDefinitionApiExt.getElementChildrenDefinition(step.dslName);
|
120
|
+
for (const element of elementChildDefinition) {
|
121
|
+
const camelElement = CamelDefinitionApiExt.getElementChildren(step, element);
|
122
|
+
if (element.multiple) {
|
123
|
+
(result as any)[element.name] = CamelDisplayUtil.setElementsVisibility((result as any)[element.name], showChildren, expandedUuids)
|
124
|
+
} else {
|
125
|
+
const prop = (result as any)[element.name];
|
126
|
+
if (prop && prop.hasOwnProperty('uuid')) {
|
127
|
+
(result as any)[element.name] = CamelDisplayUtil.setElementVisibility(camelElement[0], showChildren,expandedUuids)
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
return result;
|
132
|
+
}
|
133
|
+
|
134
|
+
static setElementsVisibility = (steps: CamelElement[] | undefined, showChildren: boolean, expandedUuids: string[]): CamelElement[] => {
|
135
|
+
const result: CamelElement[] = [];
|
136
|
+
if (steps) {
|
137
|
+
for (const step of steps) {
|
138
|
+
result.push(CamelDisplayUtil.setElementVisibility(step, showChildren, expandedUuids));
|
139
|
+
}
|
140
|
+
}
|
141
|
+
return result;
|
142
|
+
}
|
143
|
+
}
|
@@ -0,0 +1,360 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
+
* contributor license agreements. See the NOTICE file distributed with
|
4
|
+
* this work for additional information regarding copyright ownership.
|
5
|
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
6
|
+
* (the "License"); you may not use this file except in compliance with
|
7
|
+
* the License. You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
import { Integration, CamelElement, Beans, MetadataLabels, KameletTypes } from '../model/IntegrationDefinition';
|
18
|
+
import { CamelDefinitionApi } from './CamelDefinitionApi';
|
19
|
+
import {
|
20
|
+
KameletDefinition,
|
21
|
+
BeanFactoryDefinition,
|
22
|
+
RouteConfigurationDefinition,
|
23
|
+
ToDefinition,
|
24
|
+
} from '../model/CamelDefinition';
|
25
|
+
import { KameletApi } from './KameletApi';
|
26
|
+
import { KameletModel, Property } from '../model/KameletModels';
|
27
|
+
import { ComponentProperty } from '../model/ComponentModels';
|
28
|
+
import { ComponentApi } from './ComponentApi';
|
29
|
+
import { CamelMetadataApi, SensitiveKeys } from '../model/CamelMetadata';
|
30
|
+
import { CamelDefinitionApiExt } from './CamelDefinitionApiExt';
|
31
|
+
import { v4 as uuidv4 } from 'uuid';
|
32
|
+
import { CamelDefinitionYaml } from './CamelDefinitionYaml';
|
33
|
+
|
34
|
+
export class CamelUtil {
|
35
|
+
private constructor() {
|
36
|
+
}
|
37
|
+
|
38
|
+
static cloneIntegration = (integration: Integration): Integration => {
|
39
|
+
const clone = JSON.parse(JSON.stringify(integration));
|
40
|
+
const int: Integration = new Integration({ ...clone });
|
41
|
+
const flows: any[] = [];
|
42
|
+
|
43
|
+
for (const flow of int.spec.flows || []) {
|
44
|
+
if (flow.dslName !== 'Beans') {
|
45
|
+
flows.push(CamelDefinitionApi.createStep(flow.dslName, flow));
|
46
|
+
} else {
|
47
|
+
const newBeans = new Beans();
|
48
|
+
newBeans.beans.push(...(flow as Beans).beans.map(bean => CamelUtil.cloneBean(bean)));
|
49
|
+
flows.push(newBeans);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
for (const routeConfiguration of int.spec.flows?.filter(flow => flow.dslName === 'RouteConfiguration') || []) {
|
54
|
+
const newRouteConfiguration = CamelUtil.cloneRouteConfiguration(routeConfiguration);
|
55
|
+
flows.push(newRouteConfiguration);
|
56
|
+
}
|
57
|
+
|
58
|
+
int.spec.flows = flows;
|
59
|
+
return int;
|
60
|
+
};
|
61
|
+
|
62
|
+
static cloneStep = (step: CamelElement, generateUuids: boolean = false): CamelElement => {
|
63
|
+
const clone = JSON.parse(
|
64
|
+
JSON.stringify(step, (key, value) => {
|
65
|
+
if (generateUuids && key === 'uuid') {
|
66
|
+
return uuidv4();
|
67
|
+
} else {
|
68
|
+
return value;
|
69
|
+
}
|
70
|
+
}),
|
71
|
+
);
|
72
|
+
return CamelDefinitionApi.createStep(step.dslName, clone, true);
|
73
|
+
};
|
74
|
+
|
75
|
+
static cloneBean = (bean: BeanFactoryDefinition): BeanFactoryDefinition => {
|
76
|
+
const clone = JSON.parse(JSON.stringify(bean));
|
77
|
+
const newBean = new BeanFactoryDefinition(clone);
|
78
|
+
newBean.uuid = bean.uuid;
|
79
|
+
return newBean;
|
80
|
+
};
|
81
|
+
|
82
|
+
static cloneRouteConfiguration = (
|
83
|
+
routeConfiguration: RouteConfigurationDefinition,
|
84
|
+
): RouteConfigurationDefinition => {
|
85
|
+
const clone = JSON.parse(JSON.stringify(routeConfiguration));
|
86
|
+
const RouteConfiguration = new RouteConfigurationDefinition(clone);
|
87
|
+
RouteConfiguration.uuid = routeConfiguration.uuid;
|
88
|
+
return RouteConfiguration;
|
89
|
+
};
|
90
|
+
|
91
|
+
static capitalizeName = (name: string): string => {
|
92
|
+
if (name.length === 0) {
|
93
|
+
return name;
|
94
|
+
}
|
95
|
+
return name[0].toUpperCase() + name.substring(1);
|
96
|
+
};
|
97
|
+
|
98
|
+
static camelizeName = (name: string, separator: string, firstSmall: boolean): string => {
|
99
|
+
if (name.length === 0) return name;
|
100
|
+
const res = name
|
101
|
+
.split(separator)
|
102
|
+
.map(value => CamelUtil.capitalizeName(value))
|
103
|
+
.join('');
|
104
|
+
return firstSmall ? res[0].toLowerCase() + res.substring(1) : res;
|
105
|
+
};
|
106
|
+
|
107
|
+
static camelizeBody = (name: string, body: any, clone: boolean): any => {
|
108
|
+
if (body && Object.keys(body).length > 0) {
|
109
|
+
const oldKey = Object.keys(body)[0];
|
110
|
+
const key = CamelUtil.camelizeName(oldKey, '-', true);
|
111
|
+
return !clone && key === name ? { [key]: body[oldKey] } : body;
|
112
|
+
} else {
|
113
|
+
return {};
|
114
|
+
}
|
115
|
+
};
|
116
|
+
|
117
|
+
static camelizeObject = (body: any): any => {
|
118
|
+
if (Array.isArray(body)) {
|
119
|
+
return body.map(value => (typeof value === 'object' ? CamelUtil.camelizeObject(value) : value));
|
120
|
+
} else if (typeof body === 'object') {
|
121
|
+
const result: any = {};
|
122
|
+
for (const key in body) {
|
123
|
+
if (body?.hasOwnProperty(key)) {
|
124
|
+
const newKey = CamelUtil.camelizeName(key, '-', true);
|
125
|
+
const value = body[key];
|
126
|
+
if (typeof value === 'object' || Array.isArray(value)) {
|
127
|
+
result[newKey] = CamelUtil.camelizeObject(value);
|
128
|
+
} else {
|
129
|
+
result[newKey] = value;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
133
|
+
return result;
|
134
|
+
} else {
|
135
|
+
return body;
|
136
|
+
}
|
137
|
+
};
|
138
|
+
|
139
|
+
static isKameletComponent = (element: CamelElement | undefined): boolean => {
|
140
|
+
if (element?.dslName === 'KameletDefinition') {
|
141
|
+
return true;
|
142
|
+
} else if (element?.dslName === 'FromDefinition' || element?.dslName === 'ToDefinition') {
|
143
|
+
const uri: string = (element as any).uri;
|
144
|
+
return uri !== undefined && uri.startsWith('kamelet:');
|
145
|
+
} else {
|
146
|
+
return false;
|
147
|
+
}
|
148
|
+
};
|
149
|
+
|
150
|
+
static getKamelet = (element: CamelElement): KameletModel | undefined => {
|
151
|
+
if (element.dslName === 'KameletDefinition') {
|
152
|
+
return KameletApi.findKameletByName((element as KameletDefinition).name || '');
|
153
|
+
} else if (element.dslName === 'ToDefinition' && (element as ToDefinition).uri?.startsWith('kamelet:')) {
|
154
|
+
const kameletName = (element as ToDefinition).uri?.replace('kamelet:', '');
|
155
|
+
return KameletApi.findKameletByName(kameletName);
|
156
|
+
} else if (['FromDefinition', 'FromDefinition', 'ToDefinition'].includes(element.dslName)) {
|
157
|
+
const uri: string = (element as any).uri;
|
158
|
+
return uri !== undefined ? KameletApi.findKameletByUri(uri) : undefined;
|
159
|
+
} else {
|
160
|
+
return undefined;
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
static getKameletProperties = (element: any, requiredOnly: boolean = false): Property[] => {
|
165
|
+
const kamelet = CamelUtil.getKamelet(element);
|
166
|
+
const props: Property[] = kamelet ? KameletApi.getKameletProperties(kamelet?.metadata.name) : [];
|
167
|
+
if (requiredOnly) {
|
168
|
+
const required = kamelet?.spec.definition.required;
|
169
|
+
return props.filter(value => required?.includes(value.id));
|
170
|
+
} else {
|
171
|
+
return props;
|
172
|
+
}
|
173
|
+
};
|
174
|
+
|
175
|
+
static getKameletRequiredParameters = (element: any): string[] => {
|
176
|
+
const kamelet = CamelUtil.getKamelet(element);
|
177
|
+
return kamelet ? kamelet.spec.definition.required : [];
|
178
|
+
};
|
179
|
+
|
180
|
+
static getComponentProperties = (element: any): ComponentProperty[] => {
|
181
|
+
const dslName: string = (element as any).dslName;
|
182
|
+
const uri: string = (element as any).uri;
|
183
|
+
const name = ComponentApi.getComponentNameFromUri(uri);
|
184
|
+
|
185
|
+
if (dslName === 'ToDynamicDefinition') {
|
186
|
+
const component = ComponentApi.findByName(dslName);
|
187
|
+
return component ? ComponentApi.getComponentProperties(component?.component.name, 'producer') : [];
|
188
|
+
} else {
|
189
|
+
if (name) {
|
190
|
+
const component = ComponentApi.findByName(name);
|
191
|
+
return component
|
192
|
+
? ComponentApi.getComponentProperties(
|
193
|
+
component?.component.name,
|
194
|
+
element.dslName === 'FromDefinition' ? 'consumer' : 'producer',
|
195
|
+
)
|
196
|
+
: [];
|
197
|
+
} else {
|
198
|
+
return [];
|
199
|
+
}
|
200
|
+
}
|
201
|
+
};
|
202
|
+
|
203
|
+
static checkRequired = (element: CamelElement): [boolean, string[]] => {
|
204
|
+
const result: [boolean, string[]] = [true, []];
|
205
|
+
const className = element.dslName;
|
206
|
+
let elementMeta = CamelMetadataApi.getCamelModelMetadataByClassName(className);
|
207
|
+
|
208
|
+
if (elementMeta === undefined && className.endsWith('Expression')) {
|
209
|
+
elementMeta = CamelMetadataApi.getCamelLanguageMetadataByClassName(className);
|
210
|
+
}
|
211
|
+
|
212
|
+
if (elementMeta) {
|
213
|
+
for (const property of elementMeta.properties.filter(p => p.required)) {
|
214
|
+
const value = (element as any)[property.name];
|
215
|
+
if (property.type === 'string' && !property.isArray && (value === undefined || !value.trim())) {
|
216
|
+
result[0] = false;
|
217
|
+
result[1].push(`${property.displayName} is required`);
|
218
|
+
} else if (['ExpressionSubElementDefinition', 'ExpressionDefinition'].includes(property.type)) {
|
219
|
+
const expressionMeta = CamelMetadataApi.getCamelModelMetadataByClassName('ExpressionDefinition');
|
220
|
+
const expressionCheck = expressionMeta && value !== undefined && expressionMeta?.properties.some(ep => {
|
221
|
+
const expValue = value[ep.name];
|
222
|
+
if (expValue) {
|
223
|
+
const checkedExpression = CamelUtil.checkRequired(expValue);
|
224
|
+
return checkedExpression[0];
|
225
|
+
}
|
226
|
+
return false;
|
227
|
+
});
|
228
|
+
result[0] = !!expressionCheck;
|
229
|
+
if (!expressionCheck) {
|
230
|
+
result[1].push('Expression is not defined');
|
231
|
+
}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
if (className === 'FromDefinition' || className === 'ToDefinition') {
|
237
|
+
if (!CamelUtil.isKameletComponent(element)) {
|
238
|
+
const requiredProperties = CamelUtil.getComponentProperties(element).filter(p => p.required);
|
239
|
+
for (const property of requiredProperties) {
|
240
|
+
const value = CamelDefinitionApiExt.getParametersValue(element, property.name, property.kind === 'path');
|
241
|
+
if (value === undefined || (property.type === 'string' && value.trim().length === 0)) {
|
242
|
+
result[0] = false;
|
243
|
+
result[1].push(`${property.displayName} is required`);
|
244
|
+
}
|
245
|
+
}
|
246
|
+
const secretProperties = CamelUtil.getComponentProperties(element).filter(p => p.secret);
|
247
|
+
for (const property of secretProperties) {
|
248
|
+
const value = CamelDefinitionApiExt.getParametersValue(element, property.name, property.kind === 'path');
|
249
|
+
if (value !== undefined && property.type === 'string'
|
250
|
+
&& (!value?.trim()?.startsWith("{{") || !value?.trim()?.endsWith('}}'))) {
|
251
|
+
result[0] = false;
|
252
|
+
result[1].push(`${property.displayName} is set in plain text`);
|
253
|
+
}
|
254
|
+
}
|
255
|
+
} else {
|
256
|
+
const kamelet = CamelUtil.getKamelet(element);
|
257
|
+
let allSet = true;
|
258
|
+
const elementAsAny = (element as any);
|
259
|
+
const filledParameters = elementAsAny ? Object.keys(elementAsAny.parameters) : [];
|
260
|
+
const missingParameters =
|
261
|
+
kamelet?.spec.definition.required?.filter(name => !filledParameters.includes(name)) || [];
|
262
|
+
if (missingParameters.length > 0) {
|
263
|
+
allSet = false;
|
264
|
+
result[1].push(...missingParameters.map(name => `${name} is required`));
|
265
|
+
}
|
266
|
+
const sensitiveParameters = filledParameters.filter(p => CamelUtil.checkIfKameletParameterSensitive(p, kamelet));
|
267
|
+
sensitiveParameters.forEach(p => {
|
268
|
+
const value = elementAsAny?.parameters[p];
|
269
|
+
if (value !== undefined && (!value?.trim()?.startsWith("{{") || !value?.trim()?.endsWith('}}'))) {
|
270
|
+
result[0] = false;
|
271
|
+
result[1].push(`${p} is set in plain text`);
|
272
|
+
}
|
273
|
+
});
|
274
|
+
result[0] = allSet;
|
275
|
+
}
|
276
|
+
}
|
277
|
+
if (result[1] && result[1].length > 0) {
|
278
|
+
result[0] = false;
|
279
|
+
}
|
280
|
+
return result;
|
281
|
+
};
|
282
|
+
|
283
|
+
static checkIfKameletParameterSensitive(parameter: string, kamelet?: KameletModel): boolean {
|
284
|
+
if (SensitiveKeys.includes(parameter)) {
|
285
|
+
return true;
|
286
|
+
} else {
|
287
|
+
return (kamelet?.spec.definition.properties?.[parameter] as any)?.type === 'password';
|
288
|
+
}
|
289
|
+
}
|
290
|
+
|
291
|
+
static findPlaceholdersInObject = (item: any, result: Set<string> = new Set<string>()): Set<string> => {
|
292
|
+
if (typeof item === 'object') {
|
293
|
+
for (const value of Object.values(item)) {
|
294
|
+
if (value == undefined) {
|
295
|
+
continue;
|
296
|
+
} else if (Array.isArray(value)) {
|
297
|
+
CamelUtil.findPlaceholdersInArray(value, result);
|
298
|
+
} else if (typeof value === 'object') {
|
299
|
+
CamelUtil.findPlaceholdersInObject(value, result);
|
300
|
+
} else {
|
301
|
+
const placeholder = CamelUtil.findPlaceholder(value.toString());
|
302
|
+
if (placeholder[0] && placeholder[1]) {
|
303
|
+
result.add(placeholder[1]);
|
304
|
+
}
|
305
|
+
}
|
306
|
+
}
|
307
|
+
} else {
|
308
|
+
const placeholder = CamelUtil.findPlaceholder(item.toString());
|
309
|
+
if (placeholder[0] && placeholder[1]) {
|
310
|
+
result.add(placeholder[1]);
|
311
|
+
}
|
312
|
+
}
|
313
|
+
return result;
|
314
|
+
};
|
315
|
+
|
316
|
+
static findPlaceholdersInArray = (
|
317
|
+
items: any[] | undefined,
|
318
|
+
result: Set<string> = new Set<string>(),
|
319
|
+
): Set<string> => {
|
320
|
+
if (items) {
|
321
|
+
for (const item of items) {
|
322
|
+
if (typeof item === 'object') {
|
323
|
+
CamelUtil.findPlaceholdersInObject(item, result);
|
324
|
+
} else {
|
325
|
+
const placeholder = CamelUtil.findPlaceholder(item.toString());
|
326
|
+
if (placeholder[0] && placeholder[1]) {
|
327
|
+
result.add(placeholder[1]);
|
328
|
+
}
|
329
|
+
}
|
330
|
+
}
|
331
|
+
}
|
332
|
+
return result;
|
333
|
+
};
|
334
|
+
|
335
|
+
static findPlaceholder = (value: string): [boolean, string?] => {
|
336
|
+
const val = value?.trim();
|
337
|
+
const result = val?.includes('{{') && val?.includes('}}');
|
338
|
+
const start = val?.search('{{') + 2;
|
339
|
+
const end = val?.search('}}');
|
340
|
+
const placeholder = val?.substring(start, end)?.trim();
|
341
|
+
return [result, placeholder];
|
342
|
+
};
|
343
|
+
|
344
|
+
static createNewKameletCode = (kameletName: string, kameletType: KameletTypes, copyFromKameletName?: string): string => {
|
345
|
+
const integration = Integration.createNew(kameletName, 'kamelet');
|
346
|
+
const meta: MetadataLabels = new MetadataLabels({ 'camel.apache.org/kamelet.type': kameletType });
|
347
|
+
integration.metadata.labels = meta;
|
348
|
+
if (copyFromKameletName !== undefined && copyFromKameletName !== '') {
|
349
|
+
const kamelet = KameletApi.getKamelets().filter(k => k.metadata.name === copyFromKameletName).at(0);
|
350
|
+
if (kamelet) {
|
351
|
+
(integration as any).spec = kamelet.spec;
|
352
|
+
(integration as any).metadata.labels = kamelet.metadata.labels;
|
353
|
+
(integration as any).metadata.annotations = kamelet.metadata.annotations;
|
354
|
+
const i = CamelUtil.cloneIntegration(integration);
|
355
|
+
return CamelDefinitionYaml.integrationToYaml(i);
|
356
|
+
}
|
357
|
+
}
|
358
|
+
return CamelDefinitionYaml.integrationToYaml(integration);
|
359
|
+
};
|
360
|
+
}
|