karavan-core 4.8.0 → 99.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of karavan-core might be problematic. Click here for more details.
- package/index.js +3 -0
- package/package.json +8 -58
- package/.bebelrc +0 -3
- package/.mocharc.json +0 -11
- package/.prettierignore +0 -9
- package/.prettierrc +0 -14
- package/src/core/api/CamelDefinitionApi.ts +0 -3271
- package/src/core/api/CamelDefinitionApiExt.ts +0 -757
- package/src/core/api/CamelDefinitionYaml.ts +0 -412
- package/src/core/api/CamelDefinitionYamlStep.ts +0 -4733
- package/src/core/api/CamelDisplayUtil.ts +0 -143
- package/src/core/api/CamelUtil.ts +0 -360
- package/src/core/api/ComponentApi.ts +0 -368
- package/src/core/api/KameletApi.ts +0 -147
- package/src/core/api/MainConfigurationApi.ts +0 -47
- package/src/core/api/ProjectModelApi.ts +0 -75
- package/src/core/api/SpiBeanApi.ts +0 -104
- package/src/core/api/TemplateApi.ts +0 -58
- package/src/core/api/TopologyUtils.ts +0 -392
- package/src/core/api/VariableUtil.ts +0 -104
- package/src/core/model/CamelDefinition.ts +0 -3783
- package/src/core/model/CamelMetadata.ts +0 -2714
- package/src/core/model/ComponentModels.ts +0 -106
- package/src/core/model/IntegrationDefinition.ts +0 -188
- package/src/core/model/KameletModels.ts +0 -223
- package/src/core/model/MainConfigurationModel.ts +0 -37
- package/src/core/model/ProjectModel.ts +0 -43
- package/src/core/model/SpiBeanModels.ts +0 -53
- package/src/core/model/TopologyDefinition.ts +0 -117
- package/test/addStep.spec.ts +0 -124
- package/test/addStep1.yaml +0 -27
- package/test/allowableValues.camel.yaml +0 -19
- package/test/allowableValues.spec.ts +0 -30
- package/test/avro-serialize-action.kamelet.yaml +0 -70
- package/test/beans.spec.ts +0 -92
- package/test/beans1.yaml +0 -36
- package/test/beans2.yaml +0 -42
- package/test/beans3.yaml +0 -7
- package/test/checkRequired.spec.ts +0 -53
- package/test/circuitBreaker.spec.ts +0 -57
- package/test/circuitBreaker.yaml +0 -19
- package/test/cloneDefinition.spec.ts +0 -106
- package/test/createKamelet.spec.ts +0 -38
- package/test/cxf.json +0 -615
- package/test/cxf.spec.ts +0 -44
- package/test/cxf.yaml +0 -15
- package/test/deleteStep.spec.ts +0 -74
- package/test/demo.spec.ts +0 -49
- package/test/demo.yaml +0 -32
- package/test/doCatchOnWhen.camel.yaml +0 -20
- package/test/doCatchOnWhen.spec.ts +0 -36
- package/test/errorHandler.spec.ts +0 -38
- package/test/errorHandler1.yaml +0 -27
- package/test/expression.spec.ts +0 -55
- package/test/findStep.spec.ts +0 -112
- package/test/findStep.yaml +0 -65
- package/test/getElementProperties.spec.ts +0 -32
- package/test/getElementPropertiesByName.spec.ts +0 -31
- package/test/getExpressionLanguage.spec.ts +0 -40
- package/test/hasElementWithId.camel.yaml +0 -98
- package/test/hasElementWithId.spec.ts +0 -57
- package/test/hasElementWithId1.camel.yaml +0 -16
- package/test/hasElementWithIdError.camel.yaml +0 -98
- package/test/integration.spec.ts +0 -60
- package/test/integration1.yaml +0 -24
- package/test/integration2.yaml +0 -23
- package/test/integrationToYaml.spec.ts +0 -51
- package/test/intercept.spec.ts +0 -62
- package/test/intercept.yaml +0 -19
- package/test/is-not-integration.yaml +0 -5114
- package/test/isIntegration.spec.ts +0 -45
- package/test/kamelet.spec.ts +0 -61
- package/test/metadata/components.json +0 -697
- package/test/metadata/kamelets.yaml +0 -23414
- package/test/metadata/spiBeans.json +0 -3094
- package/test/multiObjectProperties.spec.ts +0 -46
- package/test/multiObjectProperties1.yaml +0 -19
- package/test/multiple.spec.ts +0 -38
- package/test/multiple.yaml +0 -29
- package/test/openapi.spec.ts +0 -48
- package/test/openapi.yaml +0 -7
- package/test/placeholder.spec.ts +0 -32
- package/test/placeholder.yaml +0 -133
- package/test/plain-try-catch.yaml +0 -31
- package/test/plain.spec.ts +0 -72
- package/test/plain1.yaml +0 -22
- package/test/plain2.yaml +0 -13
- package/test/plain3.yaml +0 -5
- package/test/plain4.yaml +0 -5
- package/test/postgresql-source.kamelet.yaml +0 -113
- package/test/restConfigDsl.yaml +0 -15
- package/test/restDsl.spec.ts +0 -83
- package/test/restDsl.yaml +0 -29
- package/test/routes.spec.ts +0 -37
- package/test/routes1.yaml +0 -31
- package/test/supported-components.json +0 -1221
- package/test/supportedComponents.spec.ts +0 -34
- package/test/template1.AggregationStrategy.java +0 -21
- package/test/template1.Processor.java +0 -13
- package/test/template2.AggregationStrategy.java +0 -21
- package/test/template2.Processor.java +0 -13
- package/test/templateApi.spec.ts +0 -45
- package/test/timer-source.kamelet.yaml +0 -75
- package/test/tod.spec.ts +0 -31
- package/test/tod.yaml +0 -9
- package/test/topology.spec.ts +0 -51
- package/test/topology1.camel.yaml +0 -56
- package/test/topology2.camel.yaml +0 -44
- package/test/topology3.camel.yaml +0 -27
- package/test/tsconfig.testing.json +0 -14
- package/test/updateStep.spec.ts +0 -72
- package/test/variable1.camel.yaml +0 -42
- package/test/variable2.camel.yaml +0 -42
- package/test/variables.spec.ts +0 -34
- package/tsconfig.json +0 -34
@@ -1,757 +0,0 @@
|
|
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 { CamelMetadataApi, ElementMeta, Languages, PropertyMeta } from '../model/CamelMetadata';
|
18
|
-
import { CamelUtil } from './CamelUtil';
|
19
|
-
import {
|
20
|
-
BeanFactoryDefinition,
|
21
|
-
ExpressionDefinition,
|
22
|
-
RouteDefinition,
|
23
|
-
RestDefinition,
|
24
|
-
RouteConfigurationDefinition, FromDefinition,
|
25
|
-
} from '../model/CamelDefinition';
|
26
|
-
import { Beans, CamelElement, CamelElementMeta, Integration } from '../model/IntegrationDefinition';
|
27
|
-
import { CamelDefinitionApi } from './CamelDefinitionApi';
|
28
|
-
|
29
|
-
export class ChildElement {
|
30
|
-
constructor(public name: string = '', public className: string = '', public multiple: boolean = false) {}
|
31
|
-
}
|
32
|
-
|
33
|
-
export class CamelDefinitionApiExt {
|
34
|
-
private constructor() {}
|
35
|
-
|
36
|
-
// additional helper functions for more readability
|
37
|
-
private static getFlowsOfType(integration: Integration, type: string): CamelElement[] {
|
38
|
-
return integration.spec.flows?.filter(flow => flow.dslName === type) ?? [];
|
39
|
-
}
|
40
|
-
|
41
|
-
private static getFlowsNotOfTypes(integration: Integration, types: string[]): any[] {
|
42
|
-
return integration.spec.flows?.filter(flow => !types.includes(flow.dslName)) ?? [];
|
43
|
-
}
|
44
|
-
|
45
|
-
static replaceFromInIntegration = (integration: Integration, fromId: string, newFrom: FromDefinition): Integration => {
|
46
|
-
const flows: any = [];
|
47
|
-
CamelDefinitionApiExt.getFlowsNotOfTypes(integration, ['RouteDefinition']).forEach(bean =>
|
48
|
-
flows.push(bean),
|
49
|
-
);
|
50
|
-
CamelDefinitionApiExt.getFlowsOfType(integration, 'RouteDefinition').map(flow => {
|
51
|
-
const route = (flow as RouteDefinition);
|
52
|
-
if (route.from.id === fromId) {
|
53
|
-
newFrom.steps = [...route.from.steps];
|
54
|
-
route.from = newFrom;
|
55
|
-
flows.push(route);
|
56
|
-
} else {
|
57
|
-
flows.push(route);
|
58
|
-
}
|
59
|
-
})
|
60
|
-
integration.spec.flows = flows;
|
61
|
-
return integration;
|
62
|
-
};
|
63
|
-
|
64
|
-
static addStepToIntegration = (integration: Integration, step: CamelElement, parentId: string, position?: number,): Integration => {
|
65
|
-
if (step.dslName === 'RouteDefinition') {
|
66
|
-
integration.spec.flows?.push(step as RouteDefinition);
|
67
|
-
} else {
|
68
|
-
const flows: any = [];
|
69
|
-
CamelDefinitionApiExt.getFlowsNotOfTypes(integration, ['RouteConfigurationDefinition', 'RouteDefinition']).forEach(bean =>
|
70
|
-
flows.push(bean),
|
71
|
-
);
|
72
|
-
const routes = CamelDefinitionApiExt.addStepToSteps(CamelDefinitionApiExt.getFlowsOfType(integration, 'RouteDefinition'), step, parentId, position,);
|
73
|
-
flows.push(...routes);
|
74
|
-
const routeConfigurations = CamelDefinitionApiExt.addStepToSteps(
|
75
|
-
CamelDefinitionApiExt.getFlowsOfType(integration, 'RouteConfigurationDefinition'),step, parentId, position,);
|
76
|
-
flows.push(...routeConfigurations);
|
77
|
-
integration.spec.flows = flows;
|
78
|
-
}
|
79
|
-
return integration;
|
80
|
-
};
|
81
|
-
|
82
|
-
static addStepToStep = (step: CamelElement, stepAdded: CamelElement, parentId: string, position: number = -1,): CamelElement => {
|
83
|
-
const result = CamelUtil.cloneStep(step);
|
84
|
-
const children = CamelDefinitionApiExt.getElementChildrenDefinition(result.dslName);
|
85
|
-
let added = false;
|
86
|
-
|
87
|
-
// Check all fields except steps
|
88
|
-
for (const child of children.filter(child => child.name !== 'steps') ?? []) {
|
89
|
-
if (result.uuid === parentId) {
|
90
|
-
if (child.className === stepAdded.dslName) {
|
91
|
-
added = true;
|
92
|
-
if (child.multiple) {
|
93
|
-
(result as any)[child.name].push(stepAdded);
|
94
|
-
} else {
|
95
|
-
(result as any)[child.name] = stepAdded;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
} else {
|
99
|
-
const fieldValue = (result as any)[child.name];
|
100
|
-
if (child.multiple) {
|
101
|
-
(result as any)[child.name] = CamelDefinitionApiExt.addStepToSteps((result as any)[child.name], stepAdded, parentId, position,);
|
102
|
-
} else if (fieldValue) {
|
103
|
-
(result as any)[child.name] = CamelDefinitionApiExt.addStepToStep(fieldValue, stepAdded, parentId, position);
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
|
108
|
-
// Then steps
|
109
|
-
const steps = children.filter(child => child.name === 'steps');
|
110
|
-
if (!added && steps && result.uuid === parentId) {
|
111
|
-
if (position > -1) {
|
112
|
-
(result as any).steps.splice(position, 0, stepAdded);
|
113
|
-
} else {
|
114
|
-
(result as any).steps.push(stepAdded);
|
115
|
-
}
|
116
|
-
} else if (!added && steps && (result as any).steps) {
|
117
|
-
(result as any).steps = CamelDefinitionApiExt.addStepToSteps((result as any).steps, stepAdded, parentId, position);
|
118
|
-
}
|
119
|
-
|
120
|
-
return result;
|
121
|
-
};
|
122
|
-
|
123
|
-
static addStepToSteps = (steps: CamelElement[], step: CamelElement, parentId: string, position?: number,): CamelElement[] => {
|
124
|
-
const result: CamelElement[] = [];
|
125
|
-
for (const element of steps) {
|
126
|
-
const newStep = CamelDefinitionApiExt.addStepToStep(element, step, parentId, position);
|
127
|
-
result.push(newStep);
|
128
|
-
}
|
129
|
-
return result;
|
130
|
-
};
|
131
|
-
|
132
|
-
static findElementInIntegration = (integration: Integration, uuid: string): CamelElement | undefined => {
|
133
|
-
return CamelDefinitionApiExt.findElementMetaInIntegration(integration, uuid)?.step;
|
134
|
-
};
|
135
|
-
|
136
|
-
static findElementMetaInIntegration = (integration: Integration, uuid: string): CamelElementMeta => {
|
137
|
-
const i = CamelUtil.cloneIntegration(integration);
|
138
|
-
const routes = i.spec.flows?.filter(flow =>
|
139
|
-
['RouteConfigurationDefinition', 'RouteDefinition'].includes(flow.dslName),
|
140
|
-
);
|
141
|
-
return CamelDefinitionApiExt.findElementInElements(routes, uuid);
|
142
|
-
};
|
143
|
-
|
144
|
-
static findElementPathUuids = (integration: Integration, uuid: string): string[] => {
|
145
|
-
const result: string[] = [];
|
146
|
-
let meta = CamelDefinitionApiExt.findElementMetaInIntegration(integration, uuid);
|
147
|
-
if (meta && meta.parentUuid) {
|
148
|
-
while (meta.step?.dslName !== 'FromDefinition') {
|
149
|
-
if (meta.parentUuid) {
|
150
|
-
result.push(meta.parentUuid);
|
151
|
-
meta = CamelDefinitionApiExt.findElementMetaInIntegration(integration, meta.parentUuid);
|
152
|
-
} else {
|
153
|
-
break;
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}
|
157
|
-
return result;
|
158
|
-
};
|
159
|
-
|
160
|
-
static findElementInElements = (steps: CamelElement[] | undefined, uuid: string, result: CamelElementMeta = new CamelElementMeta(undefined, undefined, undefined),
|
161
|
-
parentUuid?: string,): CamelElementMeta => {
|
162
|
-
if (result?.step !== undefined) {
|
163
|
-
return result;
|
164
|
-
}
|
165
|
-
|
166
|
-
if (steps !== undefined) {
|
167
|
-
for (let index = 0, step: CamelElement; (step = steps[index]); index++) {
|
168
|
-
if (step.uuid === uuid) {
|
169
|
-
result = new CamelElementMeta(step, parentUuid, index);
|
170
|
-
break;
|
171
|
-
} else {
|
172
|
-
const ce = CamelDefinitionApiExt.getElementChildrenDefinition(step.dslName);
|
173
|
-
for (const e of ce) {
|
174
|
-
const cel = CamelDefinitionApiExt.getElementChildren(step, e);
|
175
|
-
if (e.multiple) {
|
176
|
-
result = CamelDefinitionApiExt.findElementInElements(cel, uuid, result, step.uuid);
|
177
|
-
} else {
|
178
|
-
const prop = (step as any)[e.name];
|
179
|
-
if (prop && prop.hasOwnProperty('uuid')) {
|
180
|
-
result = CamelDefinitionApiExt.findElementInElements([prop], uuid, result, step.uuid);
|
181
|
-
}
|
182
|
-
}
|
183
|
-
}
|
184
|
-
}
|
185
|
-
}
|
186
|
-
}
|
187
|
-
return new CamelElementMeta(result?.step, result?.parentUuid, result?.position);
|
188
|
-
};
|
189
|
-
|
190
|
-
static hasElementWithId = (integration: Integration, id: string): number => {
|
191
|
-
return CamelDefinitionApiExt.checkIfHasId(integration, id, 0);
|
192
|
-
};
|
193
|
-
|
194
|
-
static checkIfHasId = (obj: Object, id: string, counter: number): number => {
|
195
|
-
for (const propName in obj) {
|
196
|
-
let prop = (obj as any)[propName];
|
197
|
-
if (propName === 'id' && id === prop) {
|
198
|
-
counter++;
|
199
|
-
counter = CamelDefinitionApiExt.checkIfHasId(prop, id, counter);
|
200
|
-
} else if (typeof prop === 'object' && prop !== null) {
|
201
|
-
counter = CamelDefinitionApiExt.checkIfHasId(prop, id, counter);
|
202
|
-
} else if (Array.isArray(prop)) {
|
203
|
-
for (const element of prop) {
|
204
|
-
CamelDefinitionApiExt.checkIfHasId(element, id, counter);
|
205
|
-
}
|
206
|
-
}
|
207
|
-
}
|
208
|
-
return counter;
|
209
|
-
};
|
210
|
-
|
211
|
-
static moveRouteElement = (integration: Integration, source: string, target: string, asChild: boolean,): Integration => {
|
212
|
-
const sourceFindStep = CamelDefinitionApiExt.findElementMetaInIntegration(integration, source);
|
213
|
-
const sourceStep = sourceFindStep.step;
|
214
|
-
const sourceUuid = sourceStep?.uuid;
|
215
|
-
const targetFindStep = CamelDefinitionApiExt.findElementMetaInIntegration(integration, target);
|
216
|
-
const parentUuid = targetFindStep.parentUuid;
|
217
|
-
if (sourceUuid && parentUuid && sourceStep && !CamelDefinitionApiExt.findElementPathUuids(integration, target).includes(source)) {
|
218
|
-
CamelDefinitionApiExt.deleteStepFromIntegration(integration, sourceUuid);
|
219
|
-
if (asChild) {
|
220
|
-
return CamelDefinitionApiExt.addStepToIntegration(
|
221
|
-
integration,
|
222
|
-
sourceStep,
|
223
|
-
target,
|
224
|
-
(targetFindStep?.step as any)?.steps?.length,
|
225
|
-
);
|
226
|
-
} else {
|
227
|
-
switch (targetFindStep.step?.dslName) {
|
228
|
-
case 'when':
|
229
|
-
return CamelDefinitionApiExt.addStepToIntegration(integration, sourceStep, targetFindStep.step?.uuid, undefined);
|
230
|
-
case 'otherwise':
|
231
|
-
return CamelDefinitionApiExt.addStepToIntegration(integration, sourceStep, targetFindStep.step?.uuid, undefined);
|
232
|
-
default:
|
233
|
-
return CamelDefinitionApiExt.addStepToIntegration(integration, sourceStep, parentUuid, targetFindStep.position);
|
234
|
-
}
|
235
|
-
}
|
236
|
-
}
|
237
|
-
return integration;
|
238
|
-
};
|
239
|
-
|
240
|
-
static deleteStepFromIntegration = (integration: Integration, uuidToDelete: string): Integration => {
|
241
|
-
const flows: any[] =
|
242
|
-
integration.spec.flows?.filter(
|
243
|
-
flow => !['RouteConfigurationDefinition', 'RouteDefinition'].includes(flow.dslName),
|
244
|
-
) ?? [];
|
245
|
-
const routes = CamelDefinitionApiExt.deleteStepFromSteps(
|
246
|
-
integration.spec.flows?.filter(flow =>
|
247
|
-
['RouteConfigurationDefinition', 'RouteDefinition'].includes(flow.dslName),
|
248
|
-
),
|
249
|
-
uuidToDelete,
|
250
|
-
);
|
251
|
-
flows.push(...routes);
|
252
|
-
integration.spec.flows = flows;
|
253
|
-
return integration;
|
254
|
-
};
|
255
|
-
|
256
|
-
static deleteStepFromStep = (step: CamelElement, uuidToDelete: string): CamelElement => {
|
257
|
-
const result = CamelDefinitionApi.createStep(step.dslName, step);
|
258
|
-
const ce = CamelDefinitionApiExt.getElementChildrenDefinition(step.dslName);
|
259
|
-
for (const e of ce) {
|
260
|
-
const cel = CamelDefinitionApiExt.getElementChildren(step, e);
|
261
|
-
if (e.multiple) {
|
262
|
-
(result as any)[e.name] = CamelDefinitionApiExt.deleteStepFromSteps((result as any)[e.name], uuidToDelete);
|
263
|
-
} else {
|
264
|
-
const prop = (result as any)[e.name];
|
265
|
-
if (prop?.hasOwnProperty('uuid')) {
|
266
|
-
if (prop.uuid === uuidToDelete) {
|
267
|
-
delete (result as any)[e.name];
|
268
|
-
} else {
|
269
|
-
(result as any)[e.name] = CamelDefinitionApiExt.deleteStepFromStep(cel[0], uuidToDelete);
|
270
|
-
}
|
271
|
-
}
|
272
|
-
}
|
273
|
-
}
|
274
|
-
return result;
|
275
|
-
};
|
276
|
-
|
277
|
-
static deleteStepFromSteps = (steps: CamelElement[] | undefined, uuidToDelete: string): CamelElement[] => {
|
278
|
-
const result: CamelElement[] = [];
|
279
|
-
if (steps !== undefined) {
|
280
|
-
for (const step of steps) {
|
281
|
-
if (step.uuid !== uuidToDelete) {
|
282
|
-
const newStep = CamelDefinitionApiExt.deleteStepFromStep(step, uuidToDelete);
|
283
|
-
result.push(newStep);
|
284
|
-
}
|
285
|
-
}
|
286
|
-
}
|
287
|
-
return result;
|
288
|
-
};
|
289
|
-
|
290
|
-
static addBeanToIntegration = (integration: Integration, bean: BeanFactoryDefinition): Integration => {
|
291
|
-
const flows: any[] = [];
|
292
|
-
const beans: Beans[] = integration.spec.flows?.filter(flow => flow.dslName === 'Beans') ?? [];
|
293
|
-
if (integration.spec.flows && beans.length === 0) {
|
294
|
-
flows.push(...integration.spec.flows);
|
295
|
-
flows.push(new Beans({ beans: [bean] }));
|
296
|
-
} else {
|
297
|
-
flows.push(...integration.spec.flows?.filter(flow => flow.dslName !== 'Beans') ?? []);
|
298
|
-
for (const flow of beans) {
|
299
|
-
const beans: BeanFactoryDefinition[] = [];
|
300
|
-
if ((flow as Beans).beans.filter(b => b.uuid === bean.uuid).length === 0) {
|
301
|
-
beans.push(...(flow as Beans).beans.filter(b => b.uuid !== bean.uuid));
|
302
|
-
beans.push(bean);
|
303
|
-
} else {
|
304
|
-
for (const b of (flow as Beans).beans) {
|
305
|
-
if (b.uuid === bean.uuid) beans.push(bean);
|
306
|
-
else beans.push(b);
|
307
|
-
}
|
308
|
-
}
|
309
|
-
const newBeans = new Beans({ beans: beans });
|
310
|
-
flows.push(newBeans);
|
311
|
-
}
|
312
|
-
}
|
313
|
-
integration.spec.flows = flows;
|
314
|
-
return integration;
|
315
|
-
};
|
316
|
-
|
317
|
-
static deleteBeanFromIntegration = (integration: Integration, bean?: BeanFactoryDefinition): Integration => {
|
318
|
-
const flows: any[] = [];
|
319
|
-
for (const flow of integration.spec.flows ?? []) {
|
320
|
-
if (flow.dslName === 'Beans') {
|
321
|
-
const beans: BeanFactoryDefinition[] = (flow as Beans).beans.filter(
|
322
|
-
b => !(b.uuid === bean?.uuid && b.type === bean?.type),
|
323
|
-
);
|
324
|
-
if (beans.length > 0) {
|
325
|
-
const newBeans = new Beans({ beans: beans });
|
326
|
-
flows.push(newBeans);
|
327
|
-
}
|
328
|
-
} else {
|
329
|
-
flows.push(flow);
|
330
|
-
}
|
331
|
-
}
|
332
|
-
integration.spec.flows = flows;
|
333
|
-
return integration;
|
334
|
-
};
|
335
|
-
|
336
|
-
static addRouteConfigurationToIntegration = (
|
337
|
-
integration: Integration,
|
338
|
-
routeConfiguration: RouteConfigurationDefinition,
|
339
|
-
): Integration => {
|
340
|
-
integration.spec.flows?.push(routeConfiguration);
|
341
|
-
return integration;
|
342
|
-
};
|
343
|
-
|
344
|
-
static deleteRouteConfigurationFromIntegration = (
|
345
|
-
integration: Integration,
|
346
|
-
routeConfiguration: RouteConfigurationDefinition,
|
347
|
-
): Integration => {
|
348
|
-
const newFlows: any[] = [];
|
349
|
-
const flows: any[] = integration.spec.flows ?? [];
|
350
|
-
newFlows.push(...flows.filter(flow => flow.dslName !== 'RouteConfigurationDefinition'));
|
351
|
-
newFlows.push(
|
352
|
-
...flows.filter(
|
353
|
-
flow => flow.dslName === 'RouteConfigurationDefinition' && flow.uuid !== routeConfiguration.uuid,
|
354
|
-
),
|
355
|
-
);
|
356
|
-
integration.spec.flows = newFlows;
|
357
|
-
return integration;
|
358
|
-
};
|
359
|
-
|
360
|
-
static updateRouteConfigurationToIntegration = (integration: Integration, e: CamelElement): Integration => {
|
361
|
-
const elementClone = CamelUtil.cloneStep(e);
|
362
|
-
const integrationClone: Integration = CamelUtil.cloneIntegration(integration);
|
363
|
-
|
364
|
-
integrationClone.spec.flows = integration.spec.flows?.map(flow => {
|
365
|
-
if (flow.dslName === 'RouteConfigurationDefinition') {
|
366
|
-
const route = CamelDefinitionApiExt.updateElement(flow, elementClone) as RouteConfigurationDefinition;
|
367
|
-
return CamelDefinitionApi.createRouteConfigurationDefinition(route);
|
368
|
-
}
|
369
|
-
return flow;
|
370
|
-
});
|
371
|
-
return integrationClone;
|
372
|
-
};
|
373
|
-
|
374
|
-
static addRestToIntegration = (integration: Integration, rest: RestDefinition): Integration => {
|
375
|
-
integration.spec.flows?.push(rest);
|
376
|
-
return integration;
|
377
|
-
};
|
378
|
-
|
379
|
-
static addRestMethodToIntegration = (
|
380
|
-
integration: Integration,
|
381
|
-
method: CamelElement,
|
382
|
-
restUuid: string,
|
383
|
-
): Integration => {
|
384
|
-
const flows: any[] = [];
|
385
|
-
const methodFunctions: { [key: string]: (rest: RestDefinition, method: CamelElement) => void } = {
|
386
|
-
GetDefinition: (rest: RestDefinition, method: CamelElement) => {
|
387
|
-
rest.get = CamelDefinitionApiExt.addRestMethodToRestMethods(rest.get, method);
|
388
|
-
},
|
389
|
-
PostDefinition: (rest: RestDefinition, method: CamelElement) => {
|
390
|
-
rest.post = CamelDefinitionApiExt.addRestMethodToRestMethods(rest.post, method);
|
391
|
-
},
|
392
|
-
PutDefinition: (rest: RestDefinition, method: CamelElement) => {
|
393
|
-
rest.put = CamelDefinitionApiExt.addRestMethodToRestMethods(rest.put, method);
|
394
|
-
},
|
395
|
-
PatchDefinition: (rest: RestDefinition, method: CamelElement) => {
|
396
|
-
rest.patch = CamelDefinitionApiExt.addRestMethodToRestMethods(rest.patch, method);
|
397
|
-
},
|
398
|
-
DeleteDefinition: (rest: RestDefinition, method: CamelElement) => {
|
399
|
-
rest.delete = CamelDefinitionApiExt.addRestMethodToRestMethods(rest.delete, method);
|
400
|
-
},
|
401
|
-
HeadDefinition: (rest: RestDefinition, method: CamelElement) => {
|
402
|
-
rest.head = CamelDefinitionApiExt.addRestMethodToRestMethods(rest.head, method);
|
403
|
-
},
|
404
|
-
};
|
405
|
-
|
406
|
-
for (let flow of integration.spec.flows ?? []) {
|
407
|
-
if (flow.dslName === 'RestDefinition') {
|
408
|
-
if (flow.uuid !== restUuid) {
|
409
|
-
flows.push(flow);
|
410
|
-
} else {
|
411
|
-
if (method.dslName in methodFunctions) {
|
412
|
-
methodFunctions[method.dslName](flow, method);
|
413
|
-
}
|
414
|
-
flows.push(flow);
|
415
|
-
}
|
416
|
-
} else {
|
417
|
-
flows.push(flow);
|
418
|
-
}
|
419
|
-
}
|
420
|
-
|
421
|
-
integration.spec.flows = flows;
|
422
|
-
return integration;
|
423
|
-
};
|
424
|
-
|
425
|
-
static addRestMethodToRestMethods = (methods: CamelElement[] = [], method: CamelElement): CamelElement[] => {
|
426
|
-
const elements: CamelElement[] = [];
|
427
|
-
for (const e of methods) {
|
428
|
-
if (e.uuid === method.uuid) {
|
429
|
-
elements.push(method);
|
430
|
-
} else {
|
431
|
-
elements.push(e);
|
432
|
-
}
|
433
|
-
}
|
434
|
-
if (elements.filter(e => e.uuid === method.uuid).length === 0) {
|
435
|
-
elements.push(method);
|
436
|
-
}
|
437
|
-
return elements;
|
438
|
-
};
|
439
|
-
|
440
|
-
static findRestMethodParent = (integration: Integration, method: CamelElement): string | undefined => {
|
441
|
-
const rests: RestDefinition[] = integration.spec.flows?.filter(flow => flow.dslName === 'RestDefinition') ?? [];
|
442
|
-
const methodTypes = ['get', 'post', 'put', 'patch', 'delete', 'head'];
|
443
|
-
|
444
|
-
for (const rest of rests) {
|
445
|
-
for (const type of methodTypes) {
|
446
|
-
if (
|
447
|
-
method.dslName.toLowerCase() === `${type}definition` &&
|
448
|
-
(rest as any)[type]?.find((m: any) => m.uuid === method.uuid)
|
449
|
-
) {
|
450
|
-
return rest.uuid;
|
451
|
-
}
|
452
|
-
}
|
453
|
-
}
|
454
|
-
};
|
455
|
-
|
456
|
-
static deleteRestConfigurationFromIntegration = (integration: Integration): Integration => {
|
457
|
-
const flows: any[] = [];
|
458
|
-
|
459
|
-
for (const flow of integration.spec.flows ?? []) {
|
460
|
-
if (flow.dslName !== 'RestConfigurationDefinition') {
|
461
|
-
flows.push(flow);
|
462
|
-
}
|
463
|
-
}
|
464
|
-
|
465
|
-
integration.spec.flows = flows;
|
466
|
-
return integration;
|
467
|
-
};
|
468
|
-
|
469
|
-
static deleteRestFromIntegration = (integration: Integration, restUuid?: string): Integration => {
|
470
|
-
const flows: any[] = [];
|
471
|
-
|
472
|
-
for (const flow of integration.spec.flows ?? []) {
|
473
|
-
if (flow.dslName !== 'RestDefinition' || flow.uuid !== restUuid) {
|
474
|
-
flows.push(flow);
|
475
|
-
}
|
476
|
-
}
|
477
|
-
|
478
|
-
integration.spec.flows = flows;
|
479
|
-
return integration;
|
480
|
-
};
|
481
|
-
|
482
|
-
static deleteRestMethodFromIntegration = (integration: Integration, methodUuid?: string): Integration => {
|
483
|
-
const flows: any[] = [];
|
484
|
-
const methods = ['get', 'post', 'put', 'patch', 'delete', 'head'];
|
485
|
-
|
486
|
-
for (const flow of integration.spec.flows ?? []) {
|
487
|
-
if (flow.dslName === 'RestDefinition') {
|
488
|
-
for (const method of methods) {
|
489
|
-
if (flow[method]) {
|
490
|
-
flow[method] = flow[method].filter((item: any) => item.uuid !== methodUuid);
|
491
|
-
}
|
492
|
-
}
|
493
|
-
}
|
494
|
-
flows.push(flow);
|
495
|
-
}
|
496
|
-
|
497
|
-
integration.spec.flows = flows;
|
498
|
-
return integration;
|
499
|
-
};
|
500
|
-
|
501
|
-
static getExpressionLanguageName = (expression: ExpressionDefinition | undefined): string | undefined => {
|
502
|
-
let result: string | undefined = undefined;
|
503
|
-
if (expression) {
|
504
|
-
for (const fieldName in expression) {
|
505
|
-
if ((expression as any)[fieldName] === undefined) {
|
506
|
-
continue;
|
507
|
-
}
|
508
|
-
|
509
|
-
const lang = Languages.find((value: [string, string, string]) => value[0] === fieldName);
|
510
|
-
if (lang) {
|
511
|
-
const camelLangMetadata = CamelMetadataApi.getCamelLanguageMetadataByName(lang[0]);
|
512
|
-
if (camelLangMetadata?.name) {
|
513
|
-
result = camelLangMetadata.name;
|
514
|
-
break;
|
515
|
-
}
|
516
|
-
}
|
517
|
-
}
|
518
|
-
}
|
519
|
-
return result;
|
520
|
-
};
|
521
|
-
|
522
|
-
static getExpressionLanguageClassName = (expression: ExpressionDefinition | undefined): string | undefined => {
|
523
|
-
let result: string | undefined = undefined;
|
524
|
-
if (expression) {
|
525
|
-
for (const fieldName in expression) {
|
526
|
-
if ((expression as any)[fieldName] === undefined) {
|
527
|
-
continue;
|
528
|
-
}
|
529
|
-
|
530
|
-
const lang = Languages.find((value: [string, string, string]) => value[0] === fieldName);
|
531
|
-
if (lang) {
|
532
|
-
const camelLangMetadata = CamelMetadataApi.getCamelLanguageMetadataByName(lang[0]);
|
533
|
-
if (camelLangMetadata?.className) {
|
534
|
-
result = camelLangMetadata.className;
|
535
|
-
break;
|
536
|
-
}
|
537
|
-
}
|
538
|
-
}
|
539
|
-
}
|
540
|
-
return result;
|
541
|
-
};
|
542
|
-
|
543
|
-
static getDataFormat = (element: CamelElement | undefined): ElementMeta | undefined => {
|
544
|
-
let result: ElementMeta | undefined = undefined;
|
545
|
-
if (element) {
|
546
|
-
Object.keys(element).forEach(fieldName => {
|
547
|
-
const df = CamelMetadataApi.getCamelDataFormatMetadataByName(fieldName);
|
548
|
-
result = (element as any)[fieldName] ? df : result;
|
549
|
-
});
|
550
|
-
}
|
551
|
-
return result;
|
552
|
-
}
|
553
|
-
|
554
|
-
static getExpressionValue = (expression: ExpressionDefinition | undefined): CamelElement | undefined => {
|
555
|
-
const language = CamelDefinitionApiExt.getExpressionLanguageName(expression);
|
556
|
-
if (language) {
|
557
|
-
return (expression as any)[language];
|
558
|
-
} else {
|
559
|
-
return undefined;
|
560
|
-
}
|
561
|
-
};
|
562
|
-
|
563
|
-
static updateIntegrationRestElement = (integration: Integration, e: CamelElement): Integration => {
|
564
|
-
const int: Integration = CamelUtil.cloneIntegration(integration);
|
565
|
-
const flows: CamelElement[] = [];
|
566
|
-
|
567
|
-
const methods = ['get', 'post', 'put', 'patch', 'delete', 'head'];
|
568
|
-
|
569
|
-
const isRest = (flow: any) => flow.dslName === 'RestDefinition' && flow.uuid === e.uuid;
|
570
|
-
const isRestConfig = (flow: any) => flow.dslName === 'RestConfigurationDefinition' && flow.uuid === e.uuid;
|
571
|
-
|
572
|
-
const isSingleRest = integration.spec.flows?.filter(isRest).length === 1;
|
573
|
-
const isSingleRestConfig = integration.spec.flows?.filter(isRestConfig).length === 1;
|
574
|
-
|
575
|
-
for (const flow of integration.spec.flows ?? []) {
|
576
|
-
if ((isSingleRest && isRest(flow)) || (isSingleRestConfig && isRestConfig(flow))) {
|
577
|
-
flows.push(CamelUtil.cloneStep(e));
|
578
|
-
} else if (flow.dslName === 'RestDefinition') {
|
579
|
-
for (const method of methods) {
|
580
|
-
if (flow[method]) {
|
581
|
-
for (let i = 0; i < flow[method].length; i++) {
|
582
|
-
if (flow[method][i].uuid === e.uuid) {
|
583
|
-
flow[method][i] = e;
|
584
|
-
}
|
585
|
-
}
|
586
|
-
}
|
587
|
-
}
|
588
|
-
flows.push(flow);
|
589
|
-
} else {
|
590
|
-
flows.push(flow);
|
591
|
-
}
|
592
|
-
}
|
593
|
-
|
594
|
-
int.spec.flows = flows;
|
595
|
-
return int;
|
596
|
-
};
|
597
|
-
|
598
|
-
static updateIntegrationRouteElement = (integration: Integration, e: CamelElement): Integration => {
|
599
|
-
const elementClone = CamelUtil.cloneStep(e);
|
600
|
-
const int: Integration = CamelUtil.cloneIntegration(integration);
|
601
|
-
const flows: CamelElement[] = [];
|
602
|
-
|
603
|
-
for (const flow of integration.spec.flows ?? []) {
|
604
|
-
if (flow.dslName === 'RouteDefinition') {
|
605
|
-
const route = CamelDefinitionApiExt.updateElement(flow, elementClone) as RouteDefinition;
|
606
|
-
flows.push(CamelDefinitionApi.createRouteDefinition(route));
|
607
|
-
} else if (flow.dslName === 'RouteConfigurationDefinition') {
|
608
|
-
const routeConfiguration = CamelDefinitionApiExt.updateElement(flow, elementClone) as RouteConfigurationDefinition;
|
609
|
-
flows.push(CamelDefinitionApi.createRouteConfigurationDefinition(routeConfiguration));
|
610
|
-
} else {
|
611
|
-
flows.push(flow);
|
612
|
-
}
|
613
|
-
}
|
614
|
-
|
615
|
-
int.spec.flows = flows;
|
616
|
-
return int;
|
617
|
-
};
|
618
|
-
|
619
|
-
static updateIntegrationBeanElement = (integration: Integration, e: CamelElement): Integration => {
|
620
|
-
const elementClone = CamelUtil.cloneStep(e);
|
621
|
-
const int: Integration = CamelUtil.cloneIntegration(integration);
|
622
|
-
const flows: CamelElement[] = [];
|
623
|
-
|
624
|
-
for (const flow of integration.spec.flows ?? []) {
|
625
|
-
if (flow.dslName === 'Beans') {
|
626
|
-
const route = CamelDefinitionApiExt.updateElement(flow, elementClone) as BeanFactoryDefinition;
|
627
|
-
flows.push(CamelDefinitionApi.createBeanFactoryDefinition(route));
|
628
|
-
} else {
|
629
|
-
flows.push(flow);
|
630
|
-
}
|
631
|
-
}
|
632
|
-
|
633
|
-
int.spec.flows = flows;
|
634
|
-
return int;
|
635
|
-
};
|
636
|
-
|
637
|
-
static updateElement = (element: CamelElement, e: CamelElement): CamelElement => {
|
638
|
-
if (element.uuid === e.uuid) {
|
639
|
-
return e;
|
640
|
-
}
|
641
|
-
const result: any = { ...element };
|
642
|
-
for (const key in result) {
|
643
|
-
if (result[key] instanceof CamelElement) {
|
644
|
-
result[key] = CamelDefinitionApiExt.updateElement(result[key], e);
|
645
|
-
} else if (Array.isArray(result[key])) {
|
646
|
-
result[key] = CamelDefinitionApiExt.updateElements(result[key], e);
|
647
|
-
}
|
648
|
-
}
|
649
|
-
return result as CamelElement;
|
650
|
-
};
|
651
|
-
|
652
|
-
static updateElements = (elements: CamelElement[], e: CamelElement): CamelElement[] => {
|
653
|
-
const result: any[] = [];
|
654
|
-
for (const element of elements) {
|
655
|
-
if (typeof element === 'object') {
|
656
|
-
const newElement = CamelDefinitionApiExt.updateElement(element, e);
|
657
|
-
result.push(newElement);
|
658
|
-
} else {
|
659
|
-
result.push(element);
|
660
|
-
}
|
661
|
-
}
|
662
|
-
return result;
|
663
|
-
};
|
664
|
-
|
665
|
-
static getElementProperties = (className: string | undefined): PropertyMeta[] => {
|
666
|
-
const result: PropertyMeta[] = [];
|
667
|
-
let uri: any = undefined;
|
668
|
-
let expression: any = undefined;
|
669
|
-
let parameters: any = undefined;
|
670
|
-
|
671
|
-
if (className) {
|
672
|
-
const properties =
|
673
|
-
className.endsWith('Definition') || className.endsWith('BuilderRef') || className.endsWith('Config')
|
674
|
-
? CamelMetadataApi.getCamelModelMetadataByClassName(className)?.properties
|
675
|
-
: className.endsWith('DataFormat')
|
676
|
-
? CamelMetadataApi.getCamelDataFormatMetadataByClassName(className)?.properties
|
677
|
-
: CamelMetadataApi.getCamelLanguageMetadataByClassName(className)?.properties;
|
678
|
-
|
679
|
-
if (properties) {
|
680
|
-
for (const p of properties.filter(p => p.name !== 'steps' && p.name !== 'configurationRef')) {
|
681
|
-
switch (p.name) {
|
682
|
-
case 'uri':
|
683
|
-
uri = p;
|
684
|
-
break;
|
685
|
-
case 'expression':
|
686
|
-
expression = p;
|
687
|
-
break;
|
688
|
-
case 'parameters':
|
689
|
-
parameters = p;
|
690
|
-
break;
|
691
|
-
default:
|
692
|
-
result.push(p);
|
693
|
-
}
|
694
|
-
}
|
695
|
-
}
|
696
|
-
}
|
697
|
-
|
698
|
-
if (uri) {
|
699
|
-
result.unshift(uri);
|
700
|
-
}
|
701
|
-
if (expression) {
|
702
|
-
result.unshift(expression);
|
703
|
-
}
|
704
|
-
if (parameters) {
|
705
|
-
result.push(parameters);
|
706
|
-
}
|
707
|
-
|
708
|
-
return result;
|
709
|
-
};
|
710
|
-
|
711
|
-
static getElementPropertiesByName = (name: string): PropertyMeta[] => {
|
712
|
-
const model = CamelMetadataApi.getCamelModelMetadataByName(name);
|
713
|
-
if (model) {
|
714
|
-
return CamelDefinitionApiExt.getElementProperties(model.className);
|
715
|
-
}
|
716
|
-
const language = CamelMetadataApi.getCamelLanguageMetadataByName(name);
|
717
|
-
if (language) {
|
718
|
-
return CamelDefinitionApiExt.getElementProperties(language.className);
|
719
|
-
}
|
720
|
-
const dataFormat = CamelMetadataApi.getCamelDataFormatMetadataByName(name);
|
721
|
-
if (dataFormat) {
|
722
|
-
return CamelDefinitionApiExt.getElementProperties(dataFormat.className);
|
723
|
-
}
|
724
|
-
return [];
|
725
|
-
};
|
726
|
-
|
727
|
-
static getParametersValue = (element: CamelElement | undefined, propertyName: string, pathParameter?: boolean): any => {
|
728
|
-
if (element && (element as any).parameters) {
|
729
|
-
return (element as any).parameters[propertyName];
|
730
|
-
}
|
731
|
-
};
|
732
|
-
|
733
|
-
static getElementChildrenDefinition = (dslName: string): ChildElement[] => {
|
734
|
-
const result: ChildElement[] = [];
|
735
|
-
const meta = CamelMetadataApi.getCamelModelMetadataByClassName(dslName);
|
736
|
-
|
737
|
-
if (meta) {
|
738
|
-
for (const property of meta.properties) {
|
739
|
-
if (property.isObject && CamelMetadataApi.getCamelModelMetadataByClassName(property.type)) {
|
740
|
-
result.push(new ChildElement(property.name, property.type, property.isArray));
|
741
|
-
}
|
742
|
-
}
|
743
|
-
}
|
744
|
-
|
745
|
-
if (CamelDefinitionApi.createStep(dslName, {}).hasSteps())
|
746
|
-
result.push(new ChildElement('steps', 'CamelElement', true));
|
747
|
-
return result;
|
748
|
-
};
|
749
|
-
|
750
|
-
static getElementChildren = (element: CamelElement, child: ChildElement): CamelElement[] => {
|
751
|
-
let children = (element as any)[child.name];
|
752
|
-
if (!Array.isArray(children)) {
|
753
|
-
children = children ? [children] : [];
|
754
|
-
}
|
755
|
-
return children;
|
756
|
-
};
|
757
|
-
}
|