karavan-core 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. package/.bebelrc +3 -0
  2. package/.mocharc.json +11 -0
  3. package/.prettierignore +9 -0
  4. package/.prettierrc +14 -0
  5. package/package.json +62 -0
  6. package/src/core/api/CamelDefinitionApi.ts +3271 -0
  7. package/src/core/api/CamelDefinitionApiExt.ts +757 -0
  8. package/src/core/api/CamelDefinitionYaml.ts +412 -0
  9. package/src/core/api/CamelDefinitionYamlStep.ts +4733 -0
  10. package/src/core/api/CamelDisplayUtil.ts +143 -0
  11. package/src/core/api/CamelUtil.ts +360 -0
  12. package/src/core/api/ComponentApi.ts +368 -0
  13. package/src/core/api/KameletApi.ts +147 -0
  14. package/src/core/api/MainConfigurationApi.ts +47 -0
  15. package/src/core/api/ProjectModelApi.ts +75 -0
  16. package/src/core/api/SpiBeanApi.ts +104 -0
  17. package/src/core/api/TemplateApi.ts +58 -0
  18. package/src/core/api/TopologyUtils.ts +392 -0
  19. package/src/core/api/VariableUtil.ts +104 -0
  20. package/src/core/model/CamelDefinition.ts +3783 -0
  21. package/src/core/model/CamelMetadata.ts +2714 -0
  22. package/src/core/model/ComponentModels.ts +106 -0
  23. package/src/core/model/IntegrationDefinition.ts +188 -0
  24. package/src/core/model/KameletModels.ts +223 -0
  25. package/src/core/model/MainConfigurationModel.ts +37 -0
  26. package/src/core/model/ProjectModel.ts +43 -0
  27. package/src/core/model/SpiBeanModels.ts +53 -0
  28. package/src/core/model/TopologyDefinition.ts +117 -0
  29. package/test/addStep.spec.ts +124 -0
  30. package/test/addStep1.yaml +27 -0
  31. package/test/allowableValues.camel.yaml +19 -0
  32. package/test/allowableValues.spec.ts +30 -0
  33. package/test/avro-serialize-action.kamelet.yaml +70 -0
  34. package/test/beans.spec.ts +92 -0
  35. package/test/beans1.yaml +36 -0
  36. package/test/beans2.yaml +42 -0
  37. package/test/beans3.yaml +7 -0
  38. package/test/checkRequired.spec.ts +53 -0
  39. package/test/circuitBreaker.spec.ts +57 -0
  40. package/test/circuitBreaker.yaml +19 -0
  41. package/test/cloneDefinition.spec.ts +106 -0
  42. package/test/createKamelet.spec.ts +38 -0
  43. package/test/cxf.json +615 -0
  44. package/test/cxf.spec.ts +44 -0
  45. package/test/cxf.yaml +15 -0
  46. package/test/deleteStep.spec.ts +74 -0
  47. package/test/demo.spec.ts +49 -0
  48. package/test/demo.yaml +32 -0
  49. package/test/doCatchOnWhen.camel.yaml +20 -0
  50. package/test/doCatchOnWhen.spec.ts +36 -0
  51. package/test/errorHandler.spec.ts +38 -0
  52. package/test/errorHandler1.yaml +27 -0
  53. package/test/expression.spec.ts +55 -0
  54. package/test/findStep.spec.ts +112 -0
  55. package/test/findStep.yaml +65 -0
  56. package/test/getElementProperties.spec.ts +32 -0
  57. package/test/getElementPropertiesByName.spec.ts +31 -0
  58. package/test/getExpressionLanguage.spec.ts +40 -0
  59. package/test/hasElementWithId.camel.yaml +98 -0
  60. package/test/hasElementWithId.spec.ts +57 -0
  61. package/test/hasElementWithId1.camel.yaml +16 -0
  62. package/test/hasElementWithIdError.camel.yaml +98 -0
  63. package/test/integration.spec.ts +60 -0
  64. package/test/integration1.yaml +24 -0
  65. package/test/integration2.yaml +23 -0
  66. package/test/integrationToYaml.spec.ts +51 -0
  67. package/test/intercept.spec.ts +62 -0
  68. package/test/intercept.yaml +19 -0
  69. package/test/is-not-integration.yaml +5114 -0
  70. package/test/isIntegration.spec.ts +45 -0
  71. package/test/kamelet.spec.ts +61 -0
  72. package/test/metadata/components.json +697 -0
  73. package/test/metadata/kamelets.yaml +23414 -0
  74. package/test/metadata/spiBeans.json +3094 -0
  75. package/test/multiObjectProperties.spec.ts +46 -0
  76. package/test/multiObjectProperties1.yaml +19 -0
  77. package/test/multiple.spec.ts +38 -0
  78. package/test/multiple.yaml +29 -0
  79. package/test/openapi.spec.ts +48 -0
  80. package/test/openapi.yaml +7 -0
  81. package/test/placeholder.spec.ts +32 -0
  82. package/test/placeholder.yaml +133 -0
  83. package/test/plain-try-catch.yaml +31 -0
  84. package/test/plain.spec.ts +72 -0
  85. package/test/plain1.yaml +22 -0
  86. package/test/plain2.yaml +13 -0
  87. package/test/plain3.yaml +5 -0
  88. package/test/plain4.yaml +5 -0
  89. package/test/postgresql-source.kamelet.yaml +113 -0
  90. package/test/restConfigDsl.yaml +15 -0
  91. package/test/restDsl.spec.ts +83 -0
  92. package/test/restDsl.yaml +29 -0
  93. package/test/routes.spec.ts +37 -0
  94. package/test/routes1.yaml +31 -0
  95. package/test/supported-components.json +1221 -0
  96. package/test/supportedComponents.spec.ts +34 -0
  97. package/test/template1.AggregationStrategy.java +21 -0
  98. package/test/template1.Processor.java +13 -0
  99. package/test/template2.AggregationStrategy.java +21 -0
  100. package/test/template2.Processor.java +13 -0
  101. package/test/templateApi.spec.ts +45 -0
  102. package/test/timer-source.kamelet.yaml +75 -0
  103. package/test/tod.spec.ts +31 -0
  104. package/test/tod.yaml +9 -0
  105. package/test/topology.spec.ts +51 -0
  106. package/test/topology1.camel.yaml +56 -0
  107. package/test/topology2.camel.yaml +44 -0
  108. package/test/topology3.camel.yaml +27 -0
  109. package/test/tsconfig.testing.json +14 -0
  110. package/test/updateStep.spec.ts +72 -0
  111. package/test/variable1.camel.yaml +42 -0
  112. package/test/variable2.camel.yaml +42 -0
  113. package/test/variables.spec.ts +34 -0
  114. package/tsconfig.json +34 -0
@@ -0,0 +1,368 @@
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 { Component, ComponentHeader, ComponentProperty, SupportedComponent } from '../model/ComponentModels';
18
+ import { CamelElement } from '../model/IntegrationDefinition';
19
+
20
+ const Components: Component[] = [];
21
+ const SupportedComponents: SupportedComponent[] = [];
22
+ let SupportedOnly: boolean = false;
23
+ const BlockedComponents: string[] = [];
24
+
25
+ export const INTERNAL_COMPONENTS = ['direct', 'seda', 'vertx']
26
+
27
+ export class ComponentApi {
28
+ private constructor() {}
29
+
30
+ static setSupportedOnly = (supportedOnly: boolean): void => {
31
+ SupportedOnly = supportedOnly;
32
+ };
33
+
34
+ static saveSupportedComponents = (jsons: string): void => {
35
+ SupportedComponents.length = 0;
36
+ const sc: SupportedComponent[] = (JSON.parse(jsons) as []).map(json => new SupportedComponent(json));
37
+ SupportedComponents.push(...sc);
38
+ };
39
+
40
+ static getSupportedComponents = (): SupportedComponent[] => {
41
+ return SupportedComponents;
42
+ };
43
+
44
+ static jsonToComponent = (json: string): Component => {
45
+ const fromJson: Component = JSON.parse(json) as Component;
46
+ const k: Component = new Component(fromJson);
47
+ return k;
48
+ };
49
+
50
+ static saveComponents = (jsons: string[], clean: boolean = false): void => {
51
+ if (clean) Components.length = 0;
52
+ const components: Component[] = jsons.map(json => ComponentApi.jsonToComponent(json));
53
+ Components.push(...components);
54
+ };
55
+
56
+ static saveComponent = (json: string): void => {
57
+ const component: Component = ComponentApi.jsonToComponent(json);
58
+ if (Components.findIndex((c: Component) => c.component.name === component.component.name) === -1) {
59
+ Components.push(component);
60
+ }
61
+ };
62
+
63
+ static getComponents = (): Component[] => {
64
+ const comps: Component[] = [];
65
+ if (SupportedOnly) {
66
+ comps.push(
67
+ ...Components.filter(
68
+ comp => SupportedComponents.findIndex(sc => sc.name === comp.component.name) !== -1,
69
+ ),
70
+ );
71
+ } else {
72
+ comps.push(...Components);
73
+ }
74
+ return comps
75
+ .map(comp => {
76
+ const sc = SupportedComponents.find(sc => sc.name === comp.component.name);
77
+ if (sc !== undefined) {
78
+ comp.component.supportLevel = sc.level;
79
+ comp.component.supportType = 'Supported';
80
+ return comp;
81
+ } else {
82
+ comp.component.supportType = 'Community';
83
+ return comp;
84
+ }
85
+ })
86
+ .sort((a, b) => a.component.name.localeCompare(b.component.name, undefined, { sensitivity: 'base' }));
87
+ };
88
+
89
+ static findByName = (name: string): Component | undefined => {
90
+ return ComponentApi.getComponents().find((c: Component) => c.component.name === name);
91
+ };
92
+
93
+ static findStepComponent = (step?: CamelElement): Component | undefined => {
94
+ return ComponentApi.findByName((step as any)?.uri)
95
+ };
96
+
97
+ static getComponentHeadersList = (step?: CamelElement): ComponentHeader [] => {
98
+ const component = step && ComponentApi.findStepComponent(step);
99
+ if (component && component.headers) {
100
+ return Object.getOwnPropertyNames(component.headers).map(n => {
101
+ const header = component.headers[n];
102
+ header.name = n;
103
+ return header;
104
+ })
105
+ } else {
106
+ return [];
107
+ }
108
+ };
109
+
110
+ static getComponentNameFromUri = (uri: string): string | undefined => {
111
+ return uri !== undefined ? uri.split(':')[0] : undefined;
112
+ };
113
+
114
+ static getComponentTitleFromUri = (uri: string): string | undefined => {
115
+ if (uri !== undefined) {
116
+ const componentName = uri.split(':')[0];
117
+ const title = ComponentApi.findByName(componentName)?.component.title;
118
+ return title ? title : componentName;
119
+ } else {
120
+ return undefined;
121
+ }
122
+ };
123
+
124
+ static getComponentDescriptionFromUri = (uri: string): string | undefined => {
125
+ if (uri !== undefined) {
126
+ const componentName = uri.split(':')[0];
127
+ const description = ComponentApi.findByName(componentName)?.component.description;
128
+ return description ? description : componentName;
129
+ } else {
130
+ return undefined;
131
+ }
132
+ };
133
+
134
+ static parseElementUri(def: any): any {
135
+ if (def.dslName === 'ToDynamicDefinition') {
136
+ return def;
137
+ }
138
+ const uriParts = ComponentApi.parseUri(def.uri);
139
+ if (uriParts.length > 1 && !def.uri.startsWith('kamelet:')) {
140
+ const uriValues = ComponentApi.getUriParts(def.uri);
141
+ uriValues.forEach((value, key) => {
142
+ def.parameters[key] = value;
143
+ });
144
+ def.uri = uriParts[0];
145
+ }
146
+ return def;
147
+ }
148
+
149
+ static getUriParts = (uri: string): Map<string, string> => {
150
+ const result: Map<string, string> = new Map<string, string>();
151
+ const name = ComponentApi.getComponentNameFromUri(uri);
152
+ if (name) {
153
+ const component = ComponentApi.findByName(name);
154
+ const syntax = component?.component.syntax;
155
+ const syntaxParts = ComponentApi.parseSyntax(syntax + '');
156
+ const syntaxSeparators = ComponentApi.getSyntaxSeparators(syntax + '');
157
+ let newUri = uri === name ? name + syntaxSeparators.join('') : uri;
158
+
159
+ if (name === 'salesforce') {
160
+ // workaround for salesforce component
161
+ const parts = newUri.split(':');
162
+ if (parts.length === 2) result.set('operationName', parts.at(1) || '').set('topicName', '');
163
+ else if (parts.length === 3)
164
+ result.set('operationName', parts.at(1) || '').set('topicName', parts.at(2) || '');
165
+ } else if (name === 'cxf') {
166
+ // workaround for CXF component
167
+ const cxfParts = newUri.split(':');
168
+ const firstPart = cxfParts.at(1);
169
+ const secondPart = cxfParts.at(2);
170
+ if (cxfParts.length === 3 && firstPart === 'bean' && secondPart)
171
+ result.set('beanId', firstPart + ':' + secondPart);
172
+ if (cxfParts.length === 2 && firstPart?.startsWith('//')) result.set('address', firstPart);
173
+ } else if (name === 'jt400') {
174
+ // workaround for JT400 component
175
+ const jt400Parts = newUri.split('.').join(':').split('/').join(':').split('@').join(':').split(':');
176
+ const userID = jt400Parts.at(1) || '';
177
+ const password = jt400Parts.at(2) || '';
178
+ const systemName = jt400Parts.at(3) || '';
179
+ const objectPath = jt400Parts.at(4) || '';
180
+ const type = jt400Parts.at(5) || '';
181
+ result.set('userID', userID);
182
+ result.set('password', password);
183
+ result.set('systemName', systemName);
184
+ result.set('objectPath', objectPath);
185
+ result.set('type', type);
186
+ } else {
187
+ // workarounds end
188
+ syntaxParts
189
+ .filter((_, i) => i > 0)
190
+ .forEach((part, index) => {
191
+ if (index < syntaxParts.length - 1) {
192
+ const startSeparator = syntaxSeparators[index];
193
+ const endSeparator = syntaxSeparators[index + 1];
194
+ const start = newUri.indexOf(startSeparator) + startSeparator.length;
195
+ const end = endSeparator ? newUri.indexOf(endSeparator, start) : newUri.length;
196
+ const val = newUri.substring(start, end);
197
+ result.set(part, val);
198
+ newUri = newUri.substring(end);
199
+ }
200
+ });
201
+ }
202
+ }
203
+ return result;
204
+ };
205
+
206
+ static parseSyntax = (syntax: string): string[] => {
207
+ const separators: string[] = ['://', '//', ':', '/', '#'];
208
+ let simplifiedSyntax = '' + syntax;
209
+ separators.forEach(s => {
210
+ simplifiedSyntax = simplifiedSyntax?.replaceAll(s, ':');
211
+ });
212
+ return simplifiedSyntax.split(':');
213
+ };
214
+
215
+ static getSyntaxSeparators = (syntax: string): string[] => {
216
+ const result: string[] = [];
217
+ const parts: string[] = ComponentApi.parseSyntax(syntax);
218
+ let str = '';
219
+ parts.forEach((part, index) => {
220
+ if (index < parts.length - 1) {
221
+ const start = syntax.indexOf(part, str.length) + part.length;
222
+ const end = syntax.indexOf(parts[index + 1], start);
223
+ const separator = syntax.substring(start, end);
224
+ result.push(separator);
225
+ str = str + part + separator;
226
+ }
227
+ });
228
+ return result;
229
+ };
230
+
231
+ static parseUri = (uri?: string): string[] => {
232
+ const separators: string[] = ['://', '//', ':', '/', '#'];
233
+ let simplifiedUri = '' + uri;
234
+ separators.forEach(s => {
235
+ simplifiedUri = simplifiedUri.replaceAll(s, ':');
236
+ });
237
+ return simplifiedUri.split(':');
238
+ };
239
+
240
+ static getUriSeparators = (uri: string): string[] => {
241
+ const result: string[] = [];
242
+ const name = ComponentApi.getComponentNameFromUri(uri);
243
+ if (name) {
244
+ const component = ComponentApi.findByName(name);
245
+ const syntax = '' + component?.component.syntax;
246
+ const parts: string[] = Array.from(ComponentApi.getUriParts(uri).keys());
247
+ let str = '';
248
+ parts.forEach((part, index) => {
249
+ if (index < parts.length - 1) {
250
+ const start = syntax.indexOf(part, str.length) + part.length;
251
+ const end = syntax.indexOf(parts[index + 1], start);
252
+ const separator = syntax.substring(start, end);
253
+ result.push(separator);
254
+ str = str + part + separator;
255
+ }
256
+ });
257
+ }
258
+ return result;
259
+ };
260
+
261
+ static getPathParameterValue = (uri: string, pathParameter: string): string | undefined => {
262
+ return ComponentApi.getUriParts(uri).get(pathParameter);
263
+ };
264
+
265
+ static getComponentProperties = (componentName: string, type: 'consumer' | 'producer'): ComponentProperty[] => {
266
+ const invertedType = type === 'consumer' ? 'producer' : 'consumer';
267
+ const component: Component | undefined = ComponentApi.findByName(componentName);
268
+ const properties: ComponentProperty[] = [];
269
+ if (component !== undefined && component.properties) {
270
+ for (const [key, value] of Object.entries(component.properties) as [string, any][]) {
271
+ const prop = new ComponentProperty();
272
+ prop.name = key;
273
+ prop.label = value.label;
274
+ prop.description = value.description;
275
+ prop.type = value.type;
276
+ prop.displayName = value.displayName;
277
+ prop.group = value.group;
278
+ prop.type = value.type;
279
+ prop.deprecated = value.deprecated;
280
+ prop.secret = value.secret;
281
+ prop.enum = value.enum;
282
+ prop.kind = value.kind;
283
+ prop.required = value.required;
284
+ if (value.defaultValue) {
285
+ prop.defaultValue = value.defaultValue;
286
+ }
287
+ if (!value.deprecated) {
288
+ properties.push(prop);
289
+ }
290
+ }
291
+ }
292
+ const result: ComponentProperty[] = [];
293
+ result.push(...properties.filter(p => p.kind === 'path'));
294
+ result.push(...properties.filter(p => p.kind !== 'path' && p.required));
295
+ result.push(...properties.filter(p => p.label.length === 0 && p.kind !== 'path' && !p.required));
296
+ result.push(
297
+ ...properties.filter(p => !p.label.includes(invertedType) && !p.label.includes('advanced') && !p.required),
298
+ );
299
+ result.push(...properties.filter(p => p.label === 'formatting' && !p.required));
300
+ result.push(
301
+ ...properties.filter(
302
+ p =>
303
+ !p.label.includes(invertedType) &&
304
+ (p.label.includes('scheduler') || p.label.includes('security') || p.label.includes('advanced')),
305
+ ),
306
+ );
307
+ result.push(
308
+ ...properties.filter(
309
+ p =>
310
+ !p.label.includes(invertedType) &&
311
+ (p.label.includes('scheduler') || p.label.includes('security') || p.label.includes('advanced')),
312
+ ),
313
+ );
314
+ return Array.from(new Map(result.map(item => [item.name, item])).values());
315
+ };
316
+
317
+
318
+ static getComponentHeaders = (componentName: string, type: 'consumer' | 'producer'): ComponentHeader[] => {
319
+ const invertedType = type === 'consumer' ? 'producer' : 'consumer';
320
+ const component: Component | undefined = ComponentApi.findByName(componentName);
321
+ const properties: ComponentHeader[] = [];
322
+ if (component !== undefined && component.headers) {
323
+ for (const [key, value] of Object.entries(component.headers) as [string, any][]) {
324
+ const prop = new ComponentHeader();
325
+ prop.name = key;
326
+ prop.label = value.label;
327
+ prop.description = value.description;
328
+ prop.index = value.index;
329
+ prop.displayName = value.displayName;
330
+ prop.group = value.group;
331
+ prop.deprecated = value.deprecated;
332
+ prop.secret = value.secret;
333
+ prop.kind = value.kind;
334
+ prop.constantName = value.constantName;
335
+ prop.defaultValue = value.defaultValue;
336
+ prop.javaType = value.javaType;
337
+ prop.autowired = value.autowired;
338
+ if (!value.deprecated) {
339
+ properties.push(prop);
340
+ }
341
+ }
342
+ }
343
+ return Array.from(new Map(properties.map(item => [item.name, item])).values());
344
+ };
345
+
346
+
347
+ static saveBlockedComponentNames = (componentNames: string[]) => {
348
+ BlockedComponents.length = 0;
349
+ BlockedComponents.push(...componentNames);
350
+ }
351
+
352
+
353
+ static saveBlockedComponentName = (componentName: string, checked :boolean) => {
354
+ const index = BlockedComponents.indexOf(componentName);
355
+ if (!checked && index === -1) {
356
+ BlockedComponents.push(componentName);
357
+ }
358
+ else if (checked && index > -1) {
359
+ BlockedComponents.splice(index, 1);
360
+ }
361
+ return BlockedComponents;
362
+ }
363
+
364
+
365
+ static getBlockedComponentNames = () => {
366
+ return BlockedComponents;
367
+ }
368
+ }
@@ -0,0 +1,147 @@
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 { KameletModel, Property } from '../model/KameletModels';
18
+ import * as yaml from 'js-yaml';
19
+
20
+ const Kamelets: KameletModel[] = [];
21
+ const CustomNames: string[] = [];
22
+ const BlockedKamelets: string[] = [];
23
+ export class KameletApi {
24
+ private constructor() {}
25
+
26
+ static getCustomKameletNames = (): string[] => {
27
+ return CustomNames;
28
+ };
29
+
30
+ static saveCustomKameletNames = (names: string[]) => {
31
+ CustomNames.length = 0;
32
+ CustomNames.push(...names);
33
+ };
34
+
35
+ static saveCustomKameletName = (name: string) => {
36
+ CustomNames.push(name);
37
+ }
38
+
39
+ static removeCustomKameletName = (name: string) => {
40
+ const index = CustomNames.indexOf(name);
41
+ if (index > -1) {
42
+ CustomNames.splice(index,1);
43
+ }
44
+ }
45
+
46
+ static getKameletProperties = (kameletName: string): Property[] => {
47
+ const kamelet: KameletModel | undefined = KameletApi.findKameletByName(kameletName);
48
+ const properties: Property[] = [];
49
+ try {
50
+ if (kamelet !== undefined) {
51
+ const map: Map<string, any> = kamelet.spec.definition.properties
52
+ ? new Map(Object.entries(kamelet.spec.definition.properties))
53
+ : new Map();
54
+ map.forEach((value, key) => {
55
+ const prop = new Property();
56
+ prop.id = key;
57
+ prop.title = value.title;
58
+ prop.default = value.default;
59
+ prop.description = value.description;
60
+ prop.format = value.format;
61
+ prop.example = value.example;
62
+ prop.type = value.type;
63
+ prop.enum = value.enum;
64
+ if (value.default) prop.value = value.default;
65
+ prop['x-descriptors'] = value['x-descriptors'];
66
+ properties.push(prop);
67
+ });
68
+ }
69
+ } finally {
70
+ return properties;
71
+ }
72
+ };
73
+
74
+ static getKamelets = (): KameletModel[] => {
75
+ return Kamelets.sort((a, b) => a.title().localeCompare(b.title(), undefined, { sensitivity: 'base' }));
76
+ };
77
+
78
+ static jsonToKamelet = (json: string): KameletModel => {
79
+ const fromJson: KameletModel = JSON.parse(json) as KameletModel;
80
+ const k: KameletModel = new KameletModel(fromJson);
81
+ return k;
82
+ };
83
+
84
+ static findKameletByName = (name: string): KameletModel | undefined => {
85
+ return Kamelets.find((k: KameletModel) => k.metadata.name === name);
86
+ };
87
+
88
+ static findKameletByUri = (uri: string): KameletModel | undefined => {
89
+ return KameletApi.findKameletByName(uri.split(':')[1]);
90
+ };
91
+
92
+ static yamlToKamelet = (text: string): KameletModel => {
93
+ const fromYaml = yaml.load(text);
94
+ return KameletApi.jsonToKamelet(JSON.stringify(fromYaml));
95
+ };
96
+
97
+ static saveKamelets = (kameletYamls: string[], clean: boolean = false): void => {
98
+ const kamelets: KameletModel[] = kameletYamls.map(text => KameletApi.yamlToKamelet(text));
99
+ if (clean) Kamelets.length = 0;
100
+ Kamelets.push(
101
+ ...kamelets.sort((a, b) =>
102
+ a.spec.definition.title.localeCompare(b.spec.definition.title, undefined, { sensitivity: 'base' }),
103
+ ),
104
+ );
105
+ };
106
+
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
+
128
+ static saveBlockedKameletNames = (names: string[]): void => {
129
+ BlockedKamelets.length = 0;
130
+ BlockedKamelets.push(...names);
131
+ }
132
+
133
+ static saveBlockedKameletName = (name: string, checked: boolean) => {
134
+ const index = BlockedKamelets.indexOf(name);
135
+ if ( !checked && index === -1) {
136
+ BlockedKamelets.push(name);
137
+ }
138
+ else if ( checked && index > -1) {
139
+ BlockedKamelets.splice(index, 1);
140
+ }
141
+ return BlockedKamelets;
142
+ }
143
+
144
+ static getBlockedKameletNames = () => {
145
+ return BlockedKamelets;
146
+ }
147
+ }
@@ -0,0 +1,47 @@
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 { ApplicationProperty, ApplicationPropertyGroup } from '../model/MainConfigurationModel';
18
+
19
+ const MainApplicationProperties: ApplicationProperty[] = [];
20
+ const MainApplicationGroups: ApplicationPropertyGroup[] = [];
21
+
22
+ export class MainConfigurationApi {
23
+ private constructor() {}
24
+
25
+
26
+ static saveApplicationProperties = (objects: [], clean: boolean = false): void => {
27
+ if (clean) MainApplicationProperties.length = 0;
28
+ const properties: ApplicationProperty[] = objects.map(object => new ApplicationProperty(object));
29
+ MainApplicationProperties.push(...properties);
30
+ };
31
+
32
+ static getApplicationProperties = (): ApplicationProperty[] => {
33
+ const comps: ApplicationProperty[] = [];
34
+ comps.push(...MainApplicationProperties);
35
+ return comps;
36
+ };
37
+
38
+ static findByName = (name: string): ApplicationProperty | undefined => {
39
+ return MainConfigurationApi.getApplicationProperties().find((c: ApplicationProperty) => c.name === name);
40
+ };
41
+
42
+ static saveApplicationPropertyGroups = (objects: []): void => {
43
+ MainApplicationGroups.length = 0;
44
+ const properties: ApplicationPropertyGroup[] = objects.map(object => new ApplicationPropertyGroup(object));
45
+ MainApplicationProperties.push(...properties);
46
+ };
47
+ }
@@ -0,0 +1,75 @@
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 { ProjectModel, ProjectProperty } from '../model/ProjectModel';
18
+
19
+ export class ProjectModelApi {
20
+ private constructor() {}
21
+
22
+ static propertiesToProject = (properties: string): ProjectModel => {
23
+ const lines = properties.split(/\r?\n/).filter(text => text.trim().length > 0 && !text.trim().startsWith('#'));
24
+ const project = new ProjectModel();
25
+
26
+ project.properties = lines.map(value => ProjectModelApi.stringToProperty(value));
27
+ return project;
28
+ };
29
+
30
+ static stringToProperty = (line: string): ProjectProperty => {
31
+ const pair = line.split('=');
32
+ const value = pair[1];
33
+ return ProjectProperty.createNew(pair[0], value);
34
+ };
35
+
36
+ static propertiesToString = (properties: ProjectProperty[]): string => {
37
+ return properties
38
+ .map(({ key, value }) => {
39
+ if (key !== undefined && value !== undefined) return `${key}=${value}`;
40
+ return '';
41
+ })
42
+ .join('\n');
43
+ };
44
+
45
+ static getProfiles = (properties: ProjectProperty[]): string[] => {
46
+ const result: string[] = [];
47
+ properties.forEach(({ key }) => {
48
+ if (key.startsWith('%')) {
49
+ const profile = key.substring(1, key.indexOf('.'));
50
+ if (!result.includes(profile)) result.push(profile);
51
+ }
52
+ });
53
+ return result;
54
+ };
55
+
56
+ static updateProperties = (properties: string, project: ProjectModel): string => {
57
+ const mapFromProject: Map<string, any> = ProjectModelApi.projectToMap(project);
58
+ const result: string[] = [];
59
+
60
+ for (const [key, value] of mapFromProject) {
61
+ if (value !== undefined) result.push(`${key}=${value}`);
62
+ }
63
+
64
+ return result.join('\n');
65
+ };
66
+
67
+ static projectToMap = (project: ProjectModel): Map<string, any> => {
68
+ const map = new Map<string, any>();
69
+
70
+ if (project.properties && project.properties.length > 0) {
71
+ project.properties.forEach(({ key, value }) => map.set(key, value));
72
+ }
73
+ return map;
74
+ };
75
+ }