@contrail/flexplm 1.3.0 → 1.3.1-alpha.3507ab6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/lib/cli/commands/compile.d.ts +1 -0
  2. package/lib/cli/commands/compile.js +71 -0
  3. package/lib/cli/commands/compile.spec.d.ts +1 -0
  4. package/lib/cli/commands/compile.spec.js +80 -0
  5. package/lib/cli/commands/create.d.ts +1 -0
  6. package/lib/cli/commands/create.js +75 -0
  7. package/lib/cli/commands/create.spec.d.ts +1 -0
  8. package/lib/cli/commands/create.spec.js +78 -0
  9. package/lib/cli/commands/upload.d.ts +10 -0
  10. package/lib/cli/commands/upload.js +228 -0
  11. package/lib/cli/commands/upload.spec.d.ts +1 -0
  12. package/lib/cli/commands/upload.spec.js +88 -0
  13. package/lib/cli/index.d.ts +2 -0
  14. package/lib/cli/index.js +64 -0
  15. package/lib/cli/index.spec.d.ts +1 -0
  16. package/lib/cli/index.spec.js +79 -0
  17. package/lib/cli/template/mapping-template.ts.template +62 -0
  18. package/lib/entity-processor/base-entity-processor.d.ts +89 -42
  19. package/lib/entity-processor/base-entity-processor.js +438 -385
  20. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  21. package/lib/entity-processor/base-entity-processor.spec.js +398 -397
  22. package/lib/flexplm-request.d.ts +3 -3
  23. package/lib/flexplm-request.js +34 -34
  24. package/lib/flexplm-utils.d.ts +5 -5
  25. package/lib/flexplm-utils.js +33 -33
  26. package/lib/flexplm-utils.spec.d.ts +1 -1
  27. package/lib/flexplm-utils.spec.js +26 -26
  28. package/lib/index.d.ts +23 -22
  29. package/lib/index.js +39 -38
  30. package/lib/interfaces/interfaces.d.ts +105 -105
  31. package/lib/interfaces/interfaces.js +2 -2
  32. package/lib/interfaces/item-family-changes.d.ts +20 -20
  33. package/lib/interfaces/item-family-changes.js +56 -56
  34. package/lib/interfaces/mapping-file.d.ts +460 -0
  35. package/lib/interfaces/mapping-file.js +2 -0
  36. package/lib/interfaces/publish-change-data.d.ts +19 -19
  37. package/lib/interfaces/publish-change-data.js +32 -32
  38. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  39. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  40. package/lib/publish/base-process-publish-assortment.d.ts +118 -93
  41. package/lib/publish/base-process-publish-assortment.js +998 -944
  42. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  43. package/lib/publish/base-process-publish-assortment.spec.js +1688 -1670
  44. package/lib/publish/mockData.d.ts +1389 -1389
  45. package/lib/publish/mockData.js +4524 -4519
  46. package/lib/transform/identifier-conversion-spec-mockData.js +472 -444
  47. package/lib/transform/identifier-conversion.d.ts +51 -15
  48. package/lib/transform/identifier-conversion.js +248 -212
  49. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  50. package/lib/transform/identifier-conversion.spec.js +343 -339
  51. package/lib/util/config-defaults.d.ts +8 -8
  52. package/lib/util/config-defaults.js +88 -85
  53. package/lib/util/config-defaults.spec.d.ts +1 -1
  54. package/lib/util/config-defaults.spec.js +302 -293
  55. package/lib/util/data-converter-spec-mockData.js +219 -205
  56. package/lib/util/data-converter.d.ts +136 -39
  57. package/lib/util/data-converter.js +718 -592
  58. package/lib/util/data-converter.spec.d.ts +1 -1
  59. package/lib/util/data-converter.spec.js +906 -904
  60. package/lib/util/error-response-object.d.ts +9 -4
  61. package/lib/util/error-response-object.js +54 -47
  62. package/lib/util/error-response-object.spec.d.ts +1 -1
  63. package/lib/util/error-response-object.spec.js +99 -99
  64. package/lib/util/event-short-message-status.d.ts +19 -19
  65. package/lib/util/event-short-message-status.js +24 -23
  66. package/lib/util/federation.d.ts +15 -15
  67. package/lib/util/federation.js +157 -149
  68. package/lib/util/flexplm-connect.d.ts +29 -22
  69. package/lib/util/flexplm-connect.js +190 -176
  70. package/lib/util/flexplm-connect.spec.d.ts +1 -1
  71. package/lib/util/flexplm-connect.spec.js +88 -88
  72. package/lib/util/logger-config.d.ts +1 -1
  73. package/lib/util/logger-config.js +27 -26
  74. package/lib/util/map-util-spec-mockData.js +219 -205
  75. package/lib/util/map-utils.d.ts +33 -6
  76. package/lib/util/map-utils.js +42 -15
  77. package/lib/util/map-utils.spec.d.ts +1 -1
  78. package/lib/util/map-utils.spec.js +89 -89
  79. package/lib/util/mockData.d.ts +80 -80
  80. package/lib/util/mockData.js +103 -103
  81. package/lib/util/thumbnail-util.d.ts +55 -34
  82. package/lib/util/thumbnail-util.js +242 -215
  83. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  84. package/lib/util/thumbnail-util.spec.js +440 -434
  85. package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
  86. package/lib/util/type-conversion-utils.d.ts +163 -23
  87. package/lib/util/type-conversion-utils.js +408 -265
  88. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  89. package/lib/util/type-conversion-utils.spec.js +868 -868
  90. package/lib/util/type-defaults.d.ts +74 -16
  91. package/lib/util/type-defaults.js +279 -221
  92. package/lib/util/type-defaults.spec.d.ts +1 -1
  93. package/lib/util/type-defaults.spec.js +516 -516
  94. package/lib/util/type-utils.d.ts +34 -13
  95. package/lib/util/type-utils.js +137 -114
  96. package/lib/util/type-utils.spec.d.ts +1 -1
  97. package/lib/util/type-utils.spec.js +192 -190
  98. package/package.json +21 -6
  99. package/scripts/copy-template.js +10 -0
  100. package/.claude/settings.local.json +0 -8
  101. package/.github/pull_request_template.md +0 -31
  102. package/.github/workflows/flexplm-lib.yml +0 -27
  103. package/.github/workflows/publish-to-npm.yml +0 -124
  104. package/CHANGELOG.md +0 -32
  105. package/publish.bat +0 -5
  106. package/publish.sh +0 -5
  107. package/src/entity-processor/base-entity-processor.spec.ts +0 -460
  108. package/src/entity-processor/base-entity-processor.ts +0 -515
  109. package/src/flexplm-request.ts +0 -28
  110. package/src/flexplm-utils.spec.ts +0 -27
  111. package/src/flexplm-utils.ts +0 -29
  112. package/src/index.ts +0 -22
  113. package/src/interfaces/interfaces.ts +0 -122
  114. package/src/interfaces/item-family-changes.ts +0 -67
  115. package/src/interfaces/publish-change-data.ts +0 -43
  116. package/src/publish/base-process-publish-assortment-callback.ts +0 -50
  117. package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
  118. package/src/publish/base-process-publish-assortment.ts +0 -1134
  119. package/src/publish/mockData.ts +0 -4561
  120. package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
  121. package/src/transform/identifier-conversion.spec.ts +0 -354
  122. package/src/transform/identifier-conversion.ts +0 -282
  123. package/src/util/config-defaults.spec.ts +0 -350
  124. package/src/util/config-defaults.ts +0 -93
  125. package/src/util/data-converter-spec-mockData.ts +0 -231
  126. package/src/util/data-converter.spec.ts +0 -1041
  127. package/src/util/data-converter.ts +0 -762
  128. package/src/util/error-response-object.spec.ts +0 -116
  129. package/src/util/error-response-object.ts +0 -50
  130. package/src/util/event-short-message-status.ts +0 -22
  131. package/src/util/federation.ts +0 -172
  132. package/src/util/flexplm-connect.spec.ts +0 -132
  133. package/src/util/flexplm-connect.ts +0 -208
  134. package/src/util/logger-config.ts +0 -20
  135. package/src/util/map-util-spec-mockData.ts +0 -231
  136. package/src/util/map-utils.spec.ts +0 -103
  137. package/src/util/map-utils.ts +0 -41
  138. package/src/util/mockData.ts +0 -101
  139. package/src/util/thumbnail-util.spec.ts +0 -508
  140. package/src/util/thumbnail-util.ts +0 -272
  141. package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
  142. package/src/util/type-conversion-utils.spec.ts +0 -968
  143. package/src/util/type-conversion-utils.ts +0 -460
  144. package/src/util/type-defaults.spec.ts +0 -669
  145. package/src/util/type-defaults.ts +0 -281
  146. package/src/util/type-utils.spec.ts +0 -227
  147. package/src/util/type-utils.ts +0 -144
  148. package/tsconfig.json +0 -29
  149. package/tslint.json +0 -57
@@ -1,515 +0,0 @@
1
- import { FCConfig, EntityPayloadType } from '../interfaces/interfaces';
2
- import { DataConverter } from '../util/data-converter';
3
- import { TypeUtils } from '../util/type-utils';
4
- import { FlexPLMConnect,} from '../util/flexplm-connect';
5
- import { MapUtil } from '../util/map-utils';
6
- import { MapFileUtil } from '@contrail/transform-data';
7
- import { Entities } from '@contrail/sdk';
8
- import { TypeProperty } from '@contrail/types';
9
- import { TypeConversionUtils } from '../util/type-conversion-utils';
10
- import { ThumbnailUtil } from '../util/thumbnail-util';
11
- import { EventShortMessageStatus } from '../util/event-short-message-status';
12
-
13
- const UNSUPPORTED_TYPE = 'Unsupported eventType.';
14
- export class IncomingEntityResponse {
15
- entity: any
16
- earlyReturn: any
17
- }
18
-
19
- export abstract class BaseEntityProcessor {
20
-
21
- protected typeUtil: TypeUtils;
22
- protected transformMapFile: string;
23
- protected entities;
24
- protected orgSlug: string;
25
- constructor(
26
- protected config: FCConfig,
27
- protected dc: DataConverter,
28
- protected mapFileUtil: MapFileUtil,
29
- protected baseType: string
30
- ) {
31
- this.typeUtil = new TypeUtils();
32
- this.transformMapFile = this.config?.transformMapFile;
33
- this.entities = new Entities();
34
- this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
35
- }
36
-
37
- // inbound
38
- async inbound(event: EntityPayloadType) {
39
- const eventType = event.eventType;
40
- console.log(`inbound entity: ${eventType}:${event.objectClass}`);
41
-
42
- switch (eventType) {
43
- case 'PERSIST':
44
- return await this.handleIncomingUpsert(event);
45
- case 'DELETE':
46
- return await this.handleIncomingDelete(event);
47
- default:
48
- console.error(UNSUPPORTED_TYPE);
49
- return {
50
- status: 500,
51
- data: { UNSUPPORTED_TYPE }
52
- };
53
- }
54
- }
55
-
56
- async handleIncomingUpsert (event: EntityPayloadType) {
57
- const inboundData = await this.getTransformedData(event);
58
- const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
59
- // This case means there was an early return in the getIncomingEntity method
60
- if (incomingEntityResponse.earlyReturn) {
61
- const statusMsg = this.getInboundStatusMessage({
62
- status: EventShortMessageStatus.FAILURE,
63
- statusMessage: incomingEntityResponse.earlyReturn.shortStatusMessage || '',
64
- objectClass: event.objectClass,
65
- federatedId: event.federatedId
66
- });
67
- console.log(statusMsg);
68
- return incomingEntityResponse.earlyReturn;
69
- }
70
-
71
- const entity = incomingEntityResponse.entity;
72
- if (!entity) {
73
- const createEntityResponse = await this.getCreateEntity(inboundData);
74
- if (createEntityResponse.earlyReturn) {
75
- const status = (createEntityResponse.earlyReturn.shortStatusMessage === EventShortMessageStatus.NOT_CREATABLE)
76
- ? EventShortMessageStatus.SUCCESS
77
- : EventShortMessageStatus.FAILURE;
78
- const statusMsg = this.getInboundStatusMessage({
79
- status,
80
- statusMessage: createEntityResponse.earlyReturn.shortStatusMessage ||'',
81
- objectClass: event.objectClass,
82
- federatedId: event.federatedId
83
- });
84
- console.log(statusMsg);
85
- return createEntityResponse.earlyReturn;
86
- }
87
- let createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
88
- const shouldSyncThumbnail = await TypeConversionUtils.syncInboundImages(
89
- this.transformMapFile, this.mapFileUtil, event.data
90
- );
91
- if (shouldSyncThumbnail) {
92
- createdEntity = await new ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType }) || createdEntity;
93
- }
94
- const statusMsg = this.getInboundStatusMessage({
95
- status: EventShortMessageStatus.SUCCESS,
96
- statusMessage: EventShortMessageStatus.CREATED,
97
- objectClass: event.objectClass,
98
- entityId: 'id',
99
- federatedId: event.federatedId
100
- });
101
- console.log(statusMsg);
102
- return createdEntity;
103
- }
104
-
105
- const diffs = await this.getUpdatesForEntity(entity, inboundData);
106
- const shouldSyncThumbnail = await TypeConversionUtils.syncInboundImages(
107
- this.transformMapFile, this.mapFileUtil, event.data
108
- );
109
- let thumbnailEntity;
110
- if (shouldSyncThumbnail) {
111
- thumbnailEntity = await new ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: entity.id, primaryViewableId: entity.primaryViewableId, event, entityName: this.baseType });
112
- }
113
-
114
- const hasPropertyChanges = Object.getOwnPropertyNames(diffs).length > 0;
115
-
116
- if (!hasPropertyChanges && thumbnailEntity) {
117
- const statusMsg = this.getInboundStatusMessage({
118
- status: EventShortMessageStatus.SUCCESS,
119
- statusMessage: EventShortMessageStatus.PRIMARY_CONTENT_UPDATED,
120
- objectClass: event.objectClass,
121
- entityId: entity.id,
122
- federatedId: event.federatedId
123
- });
124
- console.log(statusMsg);
125
- return thumbnailEntity;
126
- }
127
-
128
- if (!hasPropertyChanges) {
129
- const statusMsg = this.getInboundStatusMessage({
130
- status: EventShortMessageStatus.SUCCESS,
131
- statusMessage: EventShortMessageStatus.NO_CHANGES,
132
- objectClass: event.objectClass,
133
- entityId: entity.id,
134
- federatedId: event.federatedId
135
- });
136
- console.log(statusMsg);
137
- const message = 'No Changes to persist for entity: ' + entity.id;
138
- return {
139
- status: 200,
140
- data: {message}
141
- };
142
- }
143
-
144
- const updatedEntity = await this.updateEntity(this.baseType, entity, diffs);
145
- const statusMsg = this.getInboundStatusMessage({
146
- status: EventShortMessageStatus.SUCCESS,
147
- statusMessage: EventShortMessageStatus.UPDATED,
148
- objectClass: event.objectClass,
149
- entityId: entity.id,
150
- federatedId: event.federatedId
151
- });
152
- console.log(statusMsg);
153
- return updatedEntity;
154
- }
155
-
156
- getInboundStatusMessage(statusObject){
157
- return 'BaseEntityProcessor: inbound: status: ' + statusObject.status
158
- + ', statusMessage: ' + statusObject.statusMessage
159
- + ', entityType: ' + this.baseType
160
- + ', entityId: ' + statusObject.entityId
161
- + ', objectClass: ' + statusObject.objectClass
162
- + ', federatedId: ' + statusObject.federatedId
163
- + ', orgSlug: ' + this.orgSlug;
164
- }
165
-
166
- /**This will query for the entity, and handle post-processing
167
- * of any critieria that is defined at the sub-type level.
168
- * Because sub-type criteria can't be used in the search done
169
- * on the server. This is expected to be called by getIncomingEntity().
170
- *
171
- * @param entityType: the root type of the entity
172
- * @param entityTypePath: the full type path of the entity. Ex: custom-entity:sample
173
- * @param propertyCriteria: all the criteria to search for the entity
174
- * @returns the entities that match the criteria
175
- */
176
- async queryEntityWithSubTypeCriteria(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any[]>{
177
- //allCriteria; identifierKeys; entityType; entityTypePath
178
- if(!entityType || !entityTypePath){
179
- throw new Error('type and entityTypePath must be defined');
180
- }
181
- if(!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0){
182
- throw new Error('propertyCriteria must be defined and have at least one property');
183
- }
184
-
185
- const {rootTypeCriteria, subTypeCriteria} = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
186
-
187
- const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
188
-
189
- return returnedEntities;
190
- }
191
-
192
- /** This is to get the criteria for the entity that is being processed.
193
- * This is to be overridden for item & project-item because of the need for
194
- * setting the roles criteria.
195
- *
196
- * @param entityType: the root type of the entity
197
- * @param entityTypePath: the full type path of the entity. Ex: custom-entity:sample
198
- * @param propertyCriteria: all the criteria to search for the entity
199
- * @returns the criteria for the entity
200
- */
201
- async getCriteriaForEntity(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any>{
202
- if(!entityType || !entityTypePath){
203
- throw new Error('type and entityTypePath must be defined');
204
- }
205
- if(!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0){
206
- throw new Error('propertyCriteria must be defined and have at least one property');
207
- }
208
- const rootType = await this.typeUtil.getByRootAndPath({root: entityType});
209
- const rootTypePropertyKeys = await this.getRootTypePropertyKeys(rootType, propertyCriteria);
210
-
211
- const rootTypeCriteria = {};
212
- const subTypeCriteria = {};
213
- if(entityType !== entityTypePath){
214
- subTypeCriteria['typePath'] = entityTypePath;
215
- }
216
- for(const key in propertyCriteria){
217
- if(rootTypePropertyKeys.includes(key)){
218
- rootTypeCriteria[key] = propertyCriteria[key];
219
- }else{
220
- subTypeCriteria[key] = propertyCriteria[key];
221
- }
222
- }
223
-
224
- return {rootTypeCriteria, subTypeCriteria};
225
- }
226
-
227
- /** This is to get the properties that are owned by the root type
228
- * This needs to be overridded for multi-level types, such as item
229
- * and project-item. And for those types, the propertyCriteria
230
- * will be needed to determine the correct level.
231
- *
232
- * @param rootType: the full root type entity for the processed entity
233
- * @param propertyCriteria: the criteria to determine the correct level (unused for single level types)
234
- * @returns: string[] of the property keys
235
- */
236
- getRootTypePropertyKeys(rootType, propertyCriteria = null): string[] {
237
- const props: TypeProperty[] = rootType['typeProperties'];
238
- const rootTypePropertyKeys = props.map(prop => prop.slug);
239
-
240
- return rootTypePropertyKeys;
241
- }
242
-
243
-
244
- async handleIncomingDelete(event) {
245
- console.warn('delete is not configured', event);
246
- }
247
-
248
- async getTransformedData(event) {
249
- let inboundData = event.data;
250
- console.debug('inboundData: ' + JSON.stringify(inboundData));
251
-
252
- const mapKey = await TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, inboundData, TypeConversionUtils.FLEX2VIBE_DIRECTION);
253
- inboundData = await MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, mapKey, TypeConversionUtils.FLEX2VIBE_DIRECTION);
254
- console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
255
-
256
-
257
-
258
- return inboundData;
259
- }
260
-
261
- async getUpdatesForEntity(entity, inboundData) {
262
- const vibeOwningKeys = await this.getVibeOwningKeys(entity);
263
- let updates = {
264
- typeId: entity.typeId,
265
- roles: entity.roles,
266
- id: entity.id,
267
- };
268
-
269
- updates = await this.dc.setEntityValues(updates, inboundData, vibeOwningKeys);
270
- for(const prop of ['typeId', 'roles', 'id']){
271
- delete updates[prop];
272
- }
273
-
274
- return this.dc.getPersistableChanges(entity, updates);
275
- }
276
-
277
- async getVibeOwningKeys(entity) {
278
- let vibeOwningKeys = [];
279
- if (this.transformMapFile && entity) {
280
- //Technically the transform is flex->vibe. But the vibe entity being updated was passed in,
281
- // so we use VIBE2FLEX_DIRECTION to get the mapKey
282
- const mapKey = await TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
283
-
284
- const mapSection = await MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
285
- vibeOwningKeys = mapSection?.vibeOwningKeys || [];
286
- }
287
- console.debug('vibeOwningKeys: ' + vibeOwningKeys);
288
- return vibeOwningKeys;
289
- }
290
-
291
- async getVibeOwningKeysFromInbound(entity) {
292
- let vibeOwningKeys = [];
293
- if (this.transformMapFile && entity) {
294
- const mapKey = await TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, entity, TypeConversionUtils.FLEX2VIBE_DIRECTION);
295
-
296
- const mapSection = await MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
297
- vibeOwningKeys = mapSection?.vibeOwningKeys || [];
298
- }
299
- console.debug('vibeOwningKeys: ' + vibeOwningKeys);
300
- return vibeOwningKeys;
301
- }
302
-
303
- async createEntity(entityName, changes) {
304
- const options = {
305
- entityName: entityName,
306
- object: changes,
307
- };
308
- console.log("createEntity: " + JSON.stringify(options));
309
-
310
- return await new Entities().create(options);
311
- }
312
-
313
- async updateEntity(entityName, entity, diffs) {
314
- const options = {
315
- entityName: entityName,
316
- id: entity['id'],
317
- object: diffs
318
- };
319
- console.log('updateEntity: ' + JSON.stringify(options));
320
-
321
- return await new Entities().update(options);
322
- }
323
-
324
- // This method must be implemented by derived classes
325
- protected abstract getIncomingEntity(event, inboundData): Promise<IncomingEntityResponse>;
326
- protected abstract getCreateEntity(inboundData): Promise<IncomingEntityResponse>;
327
-
328
- // outbound
329
-
330
- async outbound(event) {
331
- const entityType = event.entityType;
332
- const eventType = event.eventType;
333
- const entityId = event.id;
334
- console.log(`outbound: ${entityType}:${entityId}`);
335
-
336
- switch (eventType) {
337
- case 'update':
338
- case 'create':
339
- return await this.handleOutgoingUpsert(entityType, event);
340
- case 'delete':
341
- return await this.handleOutgoingDelete(entityType, event);
342
- case 'sendUpsertToFlexPLM':
343
- return await this.sendUpsertToFlexPLM(event);
344
- default:
345
- console.log(UNSUPPORTED_TYPE);
346
- return {
347
- status: 500,
348
- data: { UNSUPPORTED_TYPE }
349
- };
350
- }
351
- }
352
-
353
- async handleOutgoingUpsert(entityType, event) {
354
- const objectClass = await TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
355
- if (!objectClass) {
356
- const message = 'ObjectClass must have a value.';
357
- console.log(message);
358
- return {
359
- status: 500,
360
- data: { message }
361
- };
362
- }
363
-
364
- try {
365
- const payload = await this.getOutgoingUpsertPayload(entityType, event);
366
- const flexResponse: any = await new FlexPLMConnect(this.config).sendToFlexPLM(payload);
367
-
368
- const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
369
- if(outboundEntityUpdates){
370
- flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
371
- }
372
-
373
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + EventShortMessageStatus.SUCCESS
374
- + ', statusMessage: '+ flexResponse.status
375
- + ', entityType: ' + this.baseType
376
- + ', entityId: ' + event.id
377
- + ', objectClass: ' + payload.objectClass
378
- + ', updateFromResponse: ' + (( outboundEntityUpdates &&Object.keys(outboundEntityUpdates).length > 0)? 'true' : 'false')
379
- + ', orgSlug: ' + this.orgSlug;
380
- console.log(statusMsg);
381
-
382
- return flexResponse;
383
-
384
- } catch(e){
385
- const statusMsg = 'BaseEntityProcessor: outbound: status: '+ EventShortMessageStatus.FAILURE
386
- + ', statusMessage: ' + e.httpResponseStatus
387
- + ', entityType: ' + this.baseType
388
- + ', entityId: ' + event.id
389
- + ', objectClass: ' + objectClass
390
- + ', updateFromResponse: ' + 'false'
391
- + ', orgSlug: ' + this.orgSlug;
392
- console.log(statusMsg);
393
- throw e;
394
- }
395
- }
396
-
397
- async getOutboundEntityUpdates(event, flexResponse): Promise<any> {
398
- const payload = flexResponse?.data?.payload;
399
- const flexPayload = (payload)? payload[0] : undefined;
400
- let outboundEntityUpdates = undefined;
401
- if(flexPayload && 'OK' === flexPayload.status) {
402
- if(flexPayload.data && !flexPayload.data?.flexPLMObjectClass){
403
- flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
404
- }
405
- const inboundData = await this.getTransformedData(flexPayload);
406
- outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData)
407
- }
408
- return outboundEntityUpdates;
409
- }
410
-
411
- async handleOutgoingDelete(entityType, event) {
412
- console.warn('delete is not configured', entityType, event.oldData);
413
- }
414
-
415
- // This method must be implemented by derived classes
416
- protected abstract getOutgoingUpsertPayload(entityType, event): Promise<EntityPayloadType>;
417
-
418
- /** Create a new event-workflow-request to rerun sending the entity to FlexPLM
419
- * The event must contain any information needed to ensure it is put in the correct queue for the entity
420
- *
421
- * @param triggerKey Ex: event.entityType + '|sendUpsertToFlexPLM'
422
- * @param event
423
- * @returns
424
- */
425
-
426
- protected async triggerNewEvent(triggerKey: string, event: any) {
427
- const newEvent = {
428
- entityName: 'event-workflow-request',
429
- object: {
430
- triggerKey,
431
- event
432
- }
433
- };
434
- const response = await this.entities.create(newEvent);
435
-
436
- return response;
437
- }
438
-
439
- /** Sends the current state of the entity to FlexPLM.
440
- * So any changes made in Vibe between the event being generated and the event being processed are sent to FlexPLM.
441
- *
442
- * @param event must contain entityType, id; which are used to query for the entity
443
- * @returns results of sending the entity to FlexPLM
444
- */
445
- protected async sendUpsertToFlexPLM(event) {
446
- const payload = await this.getEntityCurrentStateUpsertPayload(event);
447
- if(!payload){
448
- const message = 'No payload to send to FlexPLM';
449
- console.log(message);
450
- return {
451
- status: 500,
452
- data: {message}
453
- };
454
- };
455
- let objectClass = payload.objectClass;
456
- try {
457
- const flexResponse: any = await new FlexPLMConnect(this.config).sendToFlexPLM(payload);
458
-
459
- const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
460
- if(outboundEntityUpdates){
461
- flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
462
- }
463
-
464
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + EventShortMessageStatus.SUCCESS
465
- + ', statusMessage: ' + flexResponse.status
466
- + ', entityType: ' + this.baseType
467
- + ', entityId: ' + event.id
468
- + ', objectClass: ' + objectClass
469
- + ', updateFromResponse: ' + ((outboundEntityUpdates &&Object.keys(outboundEntityUpdates).length > 0)? 'true' : 'false')
470
- + ', orgSlug: ' + this.orgSlug;
471
- console.log(statusMsg);
472
- return flexResponse;
473
- }catch(e){
474
- const statusMsg = 'BaseEntityProcessor: outbound: status: '+ EventShortMessageStatus.FAILURE
475
- + ', statusMessage: ' + e.httpResponseStatus
476
- + ', entityType: ' + this.baseType
477
- + ', entityId: ' + event.id
478
- + ', objectClass: ' + objectClass
479
- + ', updateFromResponse: ' + 'false'
480
- + ', orgSlug: ' + this.orgSlug;
481
- console.log(statusMsg);
482
- throw e;
483
- }
484
- }
485
-
486
- /** Generates the payload to send to FlexPLM, based on the current state of the entity.
487
- * The current state of the entity are used as the newData and oldData; which is passed
488
- * to getOutgoingUpsertPayload to generate the payload.
489
- * @param event information about the item to send to FlexPLM
490
- * @returns The payload to send to FlexPLM
491
- */
492
- protected async getEntityCurrentStateUpsertPayload(event: any): Promise<EntityPayloadType> {
493
-
494
- const id = event.id;
495
- if(!id){
496
- return undefined;
497
- }
498
-
499
- const entity = await this.entities.get({
500
- entityName: this.baseType,
501
- id
502
- });
503
-
504
- if(!entity){
505
- return undefined;
506
- }
507
-
508
- event.newData = entity;
509
- event.oldData = entity;
510
-
511
- const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
512
-
513
- return payload;
514
- }
515
- }
@@ -1,28 +0,0 @@
1
- import axios, { AxiosRequestConfig } from 'axios';
2
-
3
- const BASE_URL: string = 'https://PP-2006031951wo.portal.ptc.io/Windchill/servlet/rest/cdee';
4
- const BASE_CONFIG: AxiosRequestConfig = {
5
- method: 'POST',
6
- headers: {
7
- 'Accept': 'application/json',
8
- 'Content-Type': 'application/json',
9
- 'CSRF_NONCE': '2OaLp+0dWNBtrkTwtdDC491zaacu6Hykvqi/lpl6bZgJ/QXBrK/B1J5FErMkmAmktr/I3thcbO1Xn3HJ7Ne/l9kpaedUmn7H75Xey4ZbNLsenW+anM3vxIZ7ELosk3k=',
10
- 'Authorization': 'Basic d2NhZG1pbjpSZXRhaWwyMDIwLQ==',
11
- 'Cookie': 'JSESSIONID=36D5B3C74C1F963C6C73E9AF5B6BDA78.tomcat1; JSESSIONID=B8090C802D8548EA773C97F5886FAB79.tomcat1',
12
- },
13
- };
14
-
15
- export class FlexPLMRequest {
16
- static async request(path: string, data: any){
17
- const config = Object.assign({}, BASE_CONFIG);
18
- config.url = BASE_URL + path;
19
- config.data = data;
20
- try {
21
- const resp = await axios(config);
22
- return Promise.resolve(resp.data);
23
- } catch (error) {
24
- console.error(`${FlexPLMRequest} error: ${error.message}`);
25
- return Promise.resolve(null);
26
- }
27
- }
28
- }
@@ -1,27 +0,0 @@
1
- import { FlexPLMUtils } from './flexplm-utils';
2
-
3
- describe('Types Controller', () => {
4
-
5
- beforeEach(async () => {
6
- });
7
-
8
- it('should convert a type path', () => {
9
- expect(FlexPLMUtils.convertTypePath('Product')).toEqual('product');
10
- expect(FlexPLMUtils.convertTypePath('Product\\Apparel')).toEqual('product:apparel');
11
- expect(FlexPLMUtils.convertTypePath('Product\\Skin Care')).toEqual('product:skin_care');
12
- expect(FlexPLMUtils.convertTypePath('Product\\Apparel\\Shirt')).toEqual('product:apparel:shirt');
13
- expect(FlexPLMUtils.convertTypePath('Product\\Apparel\\[Shirt]')).toEqual('product:apparel:*shirt*');
14
- expect(FlexPLMUtils.convertTypePath('')).toBeNull();
15
- });
16
- it('should compute level in tree', () => {
17
- expect(FlexPLMUtils.computeLevelFromPath('product')).toEqual(1);
18
- expect(FlexPLMUtils.computeLevelFromPath('product:apparel')).toEqual(2);
19
- expect(FlexPLMUtils.computeLevelFromPath('product:apparel:dress:mini')).toEqual(4);
20
- });
21
- it('should get a parent type path', () => {
22
- expect(FlexPLMUtils.getParentTypePath('product')).toBeNull();
23
- expect(FlexPLMUtils.getParentTypePath('product:apparel')).toEqual('product');
24
- expect(FlexPLMUtils.getParentTypePath('product:apparel:stuff')).toEqual('product:apparel');
25
- expect(FlexPLMUtils.getParentTypePath('Product\\Apparel')).toEqual('product');
26
- });
27
- });
@@ -1,29 +0,0 @@
1
- export class FlexPLMUtils {
2
- static convertTypePath = (path: string): string => {
3
- if (!path) { return null; }
4
- let newPath = path;
5
- while (newPath.indexOf('\\') > 1) {
6
- newPath = newPath.replace('\\', ':');
7
- }
8
- while (newPath.indexOf('[') > 1) {
9
- newPath = newPath.replace('[', '*');
10
- }
11
- while (newPath.indexOf(']') > 1) {
12
- newPath = newPath.replace(']', '*');
13
- }
14
- while (newPath.indexOf(' ') > 1) {
15
- newPath = newPath.replace(' ', '_');
16
- }
17
- newPath = newPath.toLowerCase();
18
- return newPath;
19
- }
20
-
21
- static getParentTypePath = (path: string): string => {
22
- const newPath = FlexPLMUtils.convertTypePath(path);
23
- return (!newPath || newPath.indexOf(':') < 0) ? null : newPath.substring(0, newPath.lastIndexOf(':'));
24
- }
25
-
26
- static computeLevelFromPath(path: string) {
27
- return (path.match(/:/g) || []).length + 1;
28
- }
29
- }
package/src/index.ts DELETED
@@ -1,22 +0,0 @@
1
- export * from './flexplm-request';
2
- export * from './flexplm-utils';
3
- export * from './util/config-defaults';
4
- export * from './util/data-converter';
5
- export * from './util/error-response-object';
6
- export * from './util/event-short-message-status';
7
- export * from './util/federation';
8
- export * from './util/flexplm-connect';
9
- export * from './interfaces/interfaces';
10
- export * from './util/logger-config';
11
- export * from './util/thumbnail-util';
12
- export * from './util/type-conversion-utils';
13
- export * from './util/type-defaults';
14
- export * from './util/type-utils';
15
- export * from './util/map-utils';
16
- export * from './interfaces/interfaces';
17
- export * from './interfaces/item-family-changes';
18
- export * from './interfaces/publish-change-data';
19
- export * from './publish/base-process-publish-assortment';
20
- export * from './publish/base-process-publish-assortment-callback';
21
- export * from './entity-processor/base-entity-processor';
22
- export * from './transform/identifier-conversion';