Skip to content

Commit 98f4217

Browse files
committed
Camel Core Updates For 4.14.0
1 parent 6563b89 commit 98f4217

17 files changed

+27566
-57
lines changed

karavan-core/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

karavan-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "karavan-core",
33
"publisher": "camel-karavan",
4-
"version": "4.10.2",
4+
"version": "4.14.0",
55
"description": "Apache Camel Karavan Core",
66
"scripts": {
77
"build": "tsc && tsc-alias",

karavan-core/src/core/api/CamelDefinitionApiExt.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,22 @@ export class CamelDefinitionApiExt {
446446
return integration;
447447
};
448448

449+
static deleteRouteFromIntegration = (
450+
integration: Integration,
451+
routeId: string,
452+
): Integration => {
453+
const newFlows: any[] = [];
454+
const flows: any[] = integration.spec.flows ?? [];
455+
newFlows.push(...flows.filter(flow => flow.dslName !== 'RouteDefinition'));
456+
newFlows.push(
457+
...flows.filter(
458+
flow => flow.dslName === 'RouteDefinition' && flow.id !== routeId,
459+
),
460+
);
461+
integration.spec.flows = newFlows;
462+
return integration;
463+
};
464+
449465
static updateRouteTemplateToIntegration = (integration: Integration, e: CamelElement): Integration => {
450466
const elementClone = CamelUtil.cloneStep(e);
451467
const integrationClone: Integration = CamelUtil.cloneIntegration(integration);

karavan-core/src/core/api/CamelDefinitionYaml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class CamelDefinitionYaml {
322322
flows.filter((e: any) => e.hasOwnProperty('route'))
323323
.forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteDefinition(f.route)));
324324
flows.filter((e: any) => e.hasOwnProperty('from'))
325-
.forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteDefinition(new RouteDefinition({from: f.from}))));
325+
.forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteDefinition(new RouteDefinition({from: f.from, id: f.id}))));
326326
flows.filter((e: any) => e.hasOwnProperty('beans'))
327327
.forEach((b: any) => result.push(CamelDefinitionYaml.readBeanDefinition(b)));
328328
flows.filter((e: any) => e.hasOwnProperty('routeConfiguration'))

karavan-core/src/core/api/CamelDisplayUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class CamelDisplayUtil {
3333
} else if (element.dslName === 'RouteDefinition') {
3434
const routeId = (element as RouteDefinition).id
3535
return routeId ? routeId : CamelUtil.capitalizeName((element as any).stepName);
36-
} else if ((element as any).uri && (['ToDefinition', 'FromDefinition', 'PollDefinition', 'ToDynamicDefinition'].includes(element.dslName))) {
36+
} else if ((element as any).uri && (['ToDefinition', 'FromDefinition', 'PollDefinition', 'ToDynamicDefinition', 'WireTapDefinition'].includes(element.dslName))) {
3737
const uri = (element as any).uri
3838
return ComponentApi.getComponentTitleFromUri(uri) || '';
3939
} else {
@@ -46,7 +46,7 @@ export class CamelDisplayUtil {
4646
const kamelet: KameletModel | undefined = CamelUtil.getKamelet(element);
4747
if (kamelet) {
4848
return kamelet.spec.definition.description;
49-
} else if ((element as any).uri && (['ToDefinition', 'FromDefinition', 'PollDefinition', 'ToDynamicDefinition'].includes(element.dslName))) {
49+
} else if ((element as any).uri && (['ToDefinition', 'FromDefinition', 'PollDefinition', 'ToDynamicDefinition', 'WireTapDefinition'].includes(element.dslName))) {
5050
const uri = (element as any).uri
5151
return ComponentApi.getComponentDescriptionFromUri(uri) || '';
5252
} else {

karavan-core/src/core/api/CamelUtil.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class CamelUtil {
152152
static isKameletComponent = (element: CamelElement | undefined): boolean => {
153153
if (element?.dslName === 'KameletDefinition') {
154154
return true;
155-
} else if (element?.dslName === 'FromDefinition' || element?.dslName === 'ToDefinition' || element?.dslName === 'ToDynamicDefinition') {
155+
} else if (element && ['FromDefinition', 'ToDefinition', 'WireTapDefinition', 'ToDynamicDefinition'].includes(element?.dslName)) {
156156
const uri: string = (element as any).uri;
157157
return uri !== undefined && uri.startsWith('kamelet:');
158158
} else {
@@ -166,7 +166,7 @@ export class CamelUtil {
166166
} else if (element.dslName === 'ToDefinition' && (element as ToDefinition).uri?.startsWith('kamelet:')) {
167167
const kameletName = (element as ToDefinition).uri?.replace('kamelet:', '');
168168
return KameletApi.findKameletByName(kameletName);
169-
} else if (['FromDefinition', 'ToDynamicDefinition', 'ToDefinition'].includes(element.dslName)) {
169+
} else if (['FromDefinition', 'ToDynamicDefinition', 'ToDefinition', 'WireTapDefinition'].includes(element.dslName)) {
170170
const uri: string = (element as any).uri;
171171
return uri !== undefined ? KameletApi.findKameletByUri(uri) : undefined;
172172
} else {
@@ -376,7 +376,7 @@ export class CamelUtil {
376376
const meta: MetadataLabels = new MetadataLabels({ 'camel.apache.org/kamelet.type': kameletType });
377377
integration.metadata.labels = meta;
378378
if (copyFromKameletName !== undefined && copyFromKameletName !== '') {
379-
const kamelet = KameletApi.getKamelets().filter(k => k.metadata.name === copyFromKameletName).at(0);
379+
const kamelet = KameletApi.getAllKamelets().filter(k => k.metadata.name === copyFromKameletName).at(0);
380380
if (kamelet) {
381381
(integration as any).spec = kamelet.spec;
382382
(integration as any).metadata.labels = kamelet.metadata.labels;

karavan-core/src/core/api/ComponentApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ export class ComponentApi {
274274
prop.description = value.description;
275275
prop.type = value.type;
276276
prop.displayName = value.displayName;
277+
prop.supportFileReference = value.supportFileReference;
278+
prop.inputLanguage = value.inputLanguage;
277279
prop.group = value.group;
278280
prop.type = value.type;
279281
prop.deprecated = value.deprecated;

karavan-core/src/core/api/KameletApi.ts

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,61 @@
1717
import { KameletModel, Property } from '../model/KameletModels';
1818
import * as yaml from 'js-yaml';
1919

20-
const Kamelets: KameletModel[] = [];
21-
const CustomNames: string[] = [];
20+
const CamelKamelets: KameletModel[] = [];
21+
const CustomKamelets: KameletModel[] = [];
22+
const ProjectKamelets: KameletModel[] = [];
2223
const BlockedKamelets: string[] = [];
24+
2325
export class KameletApi {
2426
private constructor() {}
2527

2628
static getCustomKameletNames = (): string[] => {
27-
return CustomNames;
29+
return CustomKamelets.map(k => k.metadata.name);
2830
};
2931

30-
static saveCustomKameletNames = (names: string[]) => {
31-
CustomNames.length = 0;
32-
CustomNames.push(...names);
32+
static getProjectKameletNames = (): string[] => {
33+
return ProjectKamelets.map(k => k.metadata.name);
3334
};
3435

35-
static saveCustomKameletName = (name: string) => {
36-
CustomNames.push(name);
37-
}
36+
static saveCustomKamelet = (yaml: string): void => {
37+
const kamelet: KameletModel = KameletApi.yamlToKamelet(yaml);
38+
const kameletIndex = CustomKamelets.findIndex((k: KameletModel) => k.metadata.name === kamelet.metadata.name);
39+
if (kameletIndex === -1) {
40+
CustomKamelets.push(kamelet);
41+
} else {
42+
CustomKamelets.splice(kameletIndex, 1, kamelet)
43+
}
44+
};
45+
46+
static saveCustomKamelets = (kameletYamls: string[], clean: boolean = false): void => {
47+
const kamelets: KameletModel[] = kameletYamls.map(text => KameletApi.yamlToKamelet(text));
48+
if (clean) CustomKamelets.length = 0;
49+
CustomKamelets.push(
50+
...kamelets.sort((a, b) =>
51+
a.spec.definition.title.localeCompare(b.spec.definition.title, undefined, { sensitivity: 'base' }),
52+
),
53+
);
54+
};
3855

39-
static removeCustomKameletName = (name: string) => {
40-
const index = CustomNames.indexOf(name);
41-
if (index > -1) {
42-
CustomNames.splice(index,1);
56+
static saveProjectKamelets = (kameletYamls: string[], clean: boolean = false): void => {
57+
const kamelets: KameletModel[] = kameletYamls.map(text => KameletApi.yamlToKamelet(text));
58+
if (clean) ProjectKamelets.length = 0;
59+
ProjectKamelets.push(
60+
...kamelets.sort((a, b) =>
61+
a.spec.definition.title.localeCompare(b.spec.definition.title, undefined, { sensitivity: 'base' }),
62+
),
63+
);
64+
};
65+
66+
static saveProjectKamelet = (yaml: string): void => {
67+
const kamelet: KameletModel = KameletApi.yamlToKamelet(yaml);
68+
const kameletIndex = ProjectKamelets.findIndex((k: KameletModel) => k.metadata.name === kamelet.metadata.name);
69+
if (kameletIndex === -1) {
70+
ProjectKamelets.push(kamelet);
71+
} else {
72+
ProjectKamelets.splice(kameletIndex, 1, kamelet)
4373
}
44-
}
74+
};
4575

4676
static getKameletProperties = (kameletName: string): Property[] => {
4777
const kamelet: KameletModel | undefined = KameletApi.findKameletByName(kameletName);
@@ -71,8 +101,8 @@ export class KameletApi {
71101
}
72102
};
73103

74-
static getKamelets = (): KameletModel[] => {
75-
return Kamelets.sort((a, b) => a.title().localeCompare(b.title(), undefined, { sensitivity: 'base' }));
104+
static getAllKamelets = (): KameletModel[] => {
105+
return [...ProjectKamelets, ...CustomKamelets, ...CamelKamelets].sort((a, b) => a.title().localeCompare(b.title(), undefined, { sensitivity: 'base' }));
76106
};
77107

78108
static jsonToKamelet = (json: string): KameletModel => {
@@ -82,7 +112,11 @@ export class KameletApi {
82112
};
83113

84114
static findKameletByName = (name: string): KameletModel | undefined => {
85-
return Kamelets.find((k: KameletModel) => k.metadata.name === name);
115+
for (const list of [ProjectKamelets, CustomKamelets, CamelKamelets]) {
116+
const found = list.find((k) => k.metadata.name === name);
117+
if (found) return found;
118+
}
119+
return undefined;
86120
};
87121

88122
static findKameletByUri = (uri: string): KameletModel | undefined => {
@@ -94,37 +128,16 @@ export class KameletApi {
94128
return KameletApi.jsonToKamelet(JSON.stringify(fromYaml));
95129
};
96130

97-
static saveKamelets = (kameletYamls: string[], clean: boolean = false): void => {
131+
static saveCamelKamelets = (kameletYamls: string[], clean: boolean = false): void => {
98132
const kamelets: KameletModel[] = kameletYamls.map(text => KameletApi.yamlToKamelet(text));
99-
if (clean) Kamelets.length = 0;
100-
Kamelets.push(
133+
if (clean) CamelKamelets.length = 0;
134+
CamelKamelets.push(
101135
...kamelets.sort((a, b) =>
102136
a.spec.definition.title.localeCompare(b.spec.definition.title, undefined, { sensitivity: 'base' }),
103137
),
104138
);
105139
};
106140

107-
static saveKamelet = (yaml: string): void => {
108-
const kamelet: KameletModel = KameletApi.yamlToKamelet(yaml);
109-
const kameletIndex = Kamelets.findIndex((k: KameletModel) => k.metadata.name === kamelet.metadata.name);
110-
if (kameletIndex === -1) {
111-
Kamelets.push(kamelet);
112-
KameletApi.saveCustomKameletName(kamelet.metadata.name);
113-
}
114-
else {
115-
Kamelets.splice(kameletIndex, 1, kamelet)
116-
}
117-
};
118-
119-
static removeKamelet = (yaml: string): void => {
120-
const kamelet: KameletModel = KameletApi.yamlToKamelet(yaml);
121-
const kameletIndex = Kamelets.findIndex((k: KameletModel) => k.metadata.name === kamelet.metadata.name);
122-
if (kameletIndex > -1) {
123-
Kamelets.splice(kameletIndex,1);
124-
KameletApi.removeCustomKameletName(kamelet.metadata.name);
125-
}
126-
};
127-
128141
static saveBlockedKameletNames = (names: string[]): void => {
129142
BlockedKamelets.length = 0;
130143
BlockedKamelets.push(...names);
@@ -140,7 +153,7 @@ export class KameletApi {
140153
}
141154
return BlockedKamelets;
142155
}
143-
156+
144157
static getBlockedKameletNames = () => {
145158
return BlockedKamelets;
146159
}

0 commit comments

Comments
 (0)