@contrail/flexplm 1.3.2-alpha.328325d → 1.3.2-alpha.3ffe557

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 (111) hide show
  1. package/lib/cli/commands/compile.d.ts +4 -0
  2. package/lib/cli/commands/compile.js +73 -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 +5 -0
  6. package/lib/cli/commands/create.js +77 -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 +17 -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 +5 -0
  14. package/lib/cli/index.js +70 -0
  15. package/lib/cli/index.spec.d.ts +1 -0
  16. package/lib/cli/index.spec.js +85 -0
  17. package/lib/cli/template/mapping-template.ts.template +62 -0
  18. package/lib/entity-processor/base-entity-processor.d.ts +47 -5
  19. package/lib/entity-processor/base-entity-processor.js +53 -28
  20. package/lib/entity-processor/base-entity-processor.spec.js +1 -103
  21. package/lib/index.d.ts +1 -0
  22. package/lib/index.js +1 -0
  23. package/lib/interfaces/mapping-file.d.ts +460 -0
  24. package/lib/interfaces/mapping-file.js +2 -0
  25. package/lib/publish/base-process-publish-assortment.d.ts +25 -0
  26. package/lib/publish/base-process-publish-assortment.js +60 -6
  27. package/lib/publish/base-process-publish-assortment.spec.js +22 -4
  28. package/lib/publish/mockData.js +5 -0
  29. package/lib/transform/identifier-conversion-spec-mockData.js +34 -6
  30. package/lib/transform/identifier-conversion.d.ts +36 -0
  31. package/lib/transform/identifier-conversion.js +36 -0
  32. package/lib/transform/identifier-conversion.spec.js +4 -0
  33. package/lib/util/config-defaults.js +3 -0
  34. package/lib/util/config-defaults.spec.js +9 -0
  35. package/lib/util/data-converter-spec-mockData.js +17 -3
  36. package/lib/util/data-converter.d.ts +97 -0
  37. package/lib/util/data-converter.js +133 -1
  38. package/lib/util/data-converter.spec.js +68 -0
  39. package/lib/util/error-response-object.d.ts +5 -0
  40. package/lib/util/error-response-object.js +7 -0
  41. package/lib/util/event-short-message-status.js +1 -0
  42. package/lib/util/federation.js +8 -0
  43. package/lib/util/flexplm-connect.d.ts +7 -0
  44. package/lib/util/flexplm-connect.js +14 -0
  45. package/lib/util/logger-config.js +1 -0
  46. package/lib/util/map-util-spec-mockData.js +17 -3
  47. package/lib/util/map-utils.d.ts +27 -0
  48. package/lib/util/map-utils.js +27 -0
  49. package/lib/util/thumbnail-util.d.ts +21 -0
  50. package/lib/util/thumbnail-util.js +28 -1
  51. package/lib/util/thumbnail-util.spec.js +6 -0
  52. package/lib/util/type-conversion-utils-spec-mockData.js +3 -3
  53. package/lib/util/type-conversion-utils.d.ts +140 -0
  54. package/lib/util/type-conversion-utils.js +143 -0
  55. package/lib/util/type-defaults.d.ts +58 -0
  56. package/lib/util/type-defaults.js +58 -0
  57. package/lib/util/type-defaults.spec.js +5 -5
  58. package/lib/util/type-utils.d.ts +21 -0
  59. package/lib/util/type-utils.js +23 -0
  60. package/lib/util/type-utils.spec.js +2 -0
  61. package/package.json +21 -6
  62. package/scripts/copy-template.js +10 -0
  63. package/.github/pull_request_template.md +0 -31
  64. package/.github/workflows/flexplm-lib.yml +0 -27
  65. package/.github/workflows/publish-to-npm.yml +0 -121
  66. package/CHANGELOG.md +0 -35
  67. package/publish.bat +0 -5
  68. package/publish.sh +0 -5
  69. package/src/entity-processor/base-entity-processor.spec.ts +0 -582
  70. package/src/entity-processor/base-entity-processor.ts +0 -565
  71. package/src/flexplm-request.ts +0 -28
  72. package/src/flexplm-utils.spec.ts +0 -27
  73. package/src/flexplm-utils.ts +0 -29
  74. package/src/index.ts +0 -22
  75. package/src/interfaces/interfaces.ts +0 -122
  76. package/src/interfaces/item-family-changes.ts +0 -67
  77. package/src/interfaces/publish-change-data.ts +0 -43
  78. package/src/publish/base-process-publish-assortment-callback.ts +0 -50
  79. package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
  80. package/src/publish/base-process-publish-assortment.ts +0 -1134
  81. package/src/publish/mockData.ts +0 -4561
  82. package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
  83. package/src/transform/identifier-conversion.spec.ts +0 -354
  84. package/src/transform/identifier-conversion.ts +0 -282
  85. package/src/util/config-defaults.spec.ts +0 -350
  86. package/src/util/config-defaults.ts +0 -93
  87. package/src/util/data-converter-spec-mockData.ts +0 -231
  88. package/src/util/data-converter.spec.ts +0 -1041
  89. package/src/util/data-converter.ts +0 -762
  90. package/src/util/error-response-object.spec.ts +0 -116
  91. package/src/util/error-response-object.ts +0 -50
  92. package/src/util/event-short-message-status.ts +0 -22
  93. package/src/util/federation.ts +0 -172
  94. package/src/util/flexplm-connect.spec.ts +0 -132
  95. package/src/util/flexplm-connect.ts +0 -208
  96. package/src/util/logger-config.ts +0 -20
  97. package/src/util/map-util-spec-mockData.ts +0 -231
  98. package/src/util/map-utils.spec.ts +0 -103
  99. package/src/util/map-utils.ts +0 -41
  100. package/src/util/mockData.ts +0 -101
  101. package/src/util/thumbnail-util.spec.ts +0 -508
  102. package/src/util/thumbnail-util.ts +0 -272
  103. package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
  104. package/src/util/type-conversion-utils.spec.ts +0 -968
  105. package/src/util/type-conversion-utils.ts +0 -460
  106. package/src/util/type-defaults.spec.ts +0 -669
  107. package/src/util/type-defaults.ts +0 -281
  108. package/src/util/type-utils.spec.ts +0 -227
  109. package/src/util/type-utils.ts +0 -144
  110. package/tsconfig.json +0 -24
  111. package/tslint.json +0 -57
@@ -1,565 +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 function is to get the entity using the identity service based on the passed in criteria.
167
- * If no entity is found, it will return undefined. If multiple entities are found, it will throw an error.
168
- * The criteria is expected to be based on the identifier properties defined in the transformMapFile for the entity,
169
- * but it can be any criteria.
170
- * If not all parameters needed for the criteria are present, it will throw an error.
171
- *
172
- * @param params.poolKey the key to use for the identity service pool. The default poolKey is the entityType. Ex: 'item' or 'item:material'
173
- * @param params.propertyName the name of the property to use for the criteria. Ex: 'itemNumber'
174
- * @param params.propertyValue the value of the property to use for the criteria. Ex: '12345'
175
- * @return the entity that is found based on the criteria, or undefined if no entity is found
176
- * @throws error if multiple entities are found based on the criteria
177
- */
178
- async getEntityUsingIdentityService(params :{
179
- poolKey: string,
180
- propertyName: string,
181
- propertyValue: string
182
- }): Promise<any | undefined> {
183
- const {poolKey, propertyName, propertyValue} = params;
184
- if(!poolKey || !propertyName || !propertyValue){
185
- throw new Error('poolKey, propertyName, and propertyValue must be defined');
186
- }
187
-
188
- const identityEntities = await this.entities.get({
189
- entityName: 'identity',
190
- criteria: {
191
- poolKey,
192
- propertyName,
193
- propertyValue
194
- }
195
- });
196
-
197
- if(!identityEntities || (Array.isArray(identityEntities) && identityEntities.length === 0)){
198
- return undefined;
199
- }
200
-
201
- if(Array.isArray(identityEntities) && identityEntities.length > 1){
202
- throw new Error('Multiple identity entities found for poolKey: ' + poolKey + ', ' + propertyName + ': ' + propertyValue);
203
- }
204
-
205
- const identityEntity = Array.isArray(identityEntities) ? identityEntities[0] : identityEntities;
206
- const entityReference = identityEntity.entityReference;
207
- const [entityName, id] = entityReference.split(':');
208
-
209
- const entity = await this.entities.get({
210
- entityName,
211
- id
212
- });
213
-
214
- return entity;
215
- }
216
- /**This will query for the entity, and handle post-processing
217
- * of any critieria that is defined at the sub-type level.
218
- * Because sub-type criteria can't be used in the search done
219
- * on the server. This is expected to be called by getIncomingEntity().
220
- *
221
- * @param entityType: the root type of the entity
222
- * @param entityTypePath: the full type path of the entity. Ex: custom-entity:sample
223
- * @param propertyCriteria: all the criteria to search for the entity
224
- * @returns the entities that match the criteria
225
- */
226
- async queryEntityWithSubTypeCriteria(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any[]>{
227
- //allCriteria; identifierKeys; entityType; entityTypePath
228
- if(!entityType || !entityTypePath){
229
- throw new Error('type and entityTypePath must be defined');
230
- }
231
- if(!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0){
232
- throw new Error('propertyCriteria must be defined and have at least one property');
233
- }
234
-
235
- const {rootTypeCriteria, subTypeCriteria} = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
236
-
237
- const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
238
-
239
- return returnedEntities;
240
- }
241
-
242
- /** This is to get the criteria for the entity that is being processed.
243
- * This is to be overridden for item & project-item because of the need for
244
- * setting the roles criteria.
245
- *
246
- * @param entityType: the root type of the entity
247
- * @param entityTypePath: the full type path of the entity. Ex: custom-entity:sample
248
- * @param propertyCriteria: all the criteria to search for the entity
249
- * @returns the criteria for the entity
250
- */
251
- async getCriteriaForEntity(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any>{
252
- if(!entityType || !entityTypePath){
253
- throw new Error('type and entityTypePath must be defined');
254
- }
255
- if(!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0){
256
- throw new Error('propertyCriteria must be defined and have at least one property');
257
- }
258
- const rootType = await this.typeUtil.getByRootAndPath({root: entityType});
259
- const rootTypePropertyKeys = await this.getRootTypePropertyKeys(rootType, propertyCriteria);
260
-
261
- const rootTypeCriteria = {};
262
- const subTypeCriteria = {};
263
- if(entityType !== entityTypePath){
264
- subTypeCriteria['typePath'] = entityTypePath;
265
- }
266
- for(const key in propertyCriteria){
267
- if(rootTypePropertyKeys.includes(key)){
268
- rootTypeCriteria[key] = propertyCriteria[key];
269
- }else{
270
- subTypeCriteria[key] = propertyCriteria[key];
271
- }
272
- }
273
-
274
- return {rootTypeCriteria, subTypeCriteria};
275
- }
276
-
277
- /** This is to get the properties that are owned by the root type
278
- * This needs to be overridded for multi-level types, such as item
279
- * and project-item. And for those types, the propertyCriteria
280
- * will be needed to determine the correct level.
281
- *
282
- * @param rootType: the full root type entity for the processed entity
283
- * @param propertyCriteria: the criteria to determine the correct level (unused for single level types)
284
- * @returns: string[] of the property keys
285
- */
286
- getRootTypePropertyKeys(rootType, propertyCriteria = null): string[] {
287
- const props: TypeProperty[] = rootType['typeProperties'];
288
- const rootTypePropertyKeys = props.map(prop => prop.slug);
289
-
290
- return rootTypePropertyKeys;
291
- }
292
-
293
-
294
- async handleIncomingDelete(event) {
295
- console.warn('delete is not configured', event);
296
- }
297
-
298
- async getTransformedData(event) {
299
- let inboundData = event.data;
300
- console.debug('inboundData: ' + JSON.stringify(inboundData));
301
-
302
- const mapKey = await TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, inboundData, TypeConversionUtils.FLEX2VIBE_DIRECTION);
303
- inboundData = await MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, mapKey, TypeConversionUtils.FLEX2VIBE_DIRECTION);
304
- console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
305
-
306
-
307
-
308
- return inboundData;
309
- }
310
-
311
- async getUpdatesForEntity(entity, inboundData) {
312
- const vibeOwningKeys = await this.getVibeOwningKeys(entity);
313
- let updates = {
314
- typeId: entity.typeId,
315
- roles: entity.roles,
316
- id: entity.id,
317
- };
318
-
319
- updates = await this.dc.setEntityValues(updates, inboundData, vibeOwningKeys);
320
- for(const prop of ['typeId', 'roles', 'id']){
321
- delete updates[prop];
322
- }
323
-
324
- return this.dc.getPersistableChanges(entity, updates);
325
- }
326
-
327
- async getVibeOwningKeys(entity) {
328
- let vibeOwningKeys = [];
329
- if (this.transformMapFile && entity) {
330
- //Technically the transform is flex->vibe. But the vibe entity being updated was passed in,
331
- // so we use VIBE2FLEX_DIRECTION to get the mapKey
332
- const mapKey = await TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
333
-
334
- const mapSection = await MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
335
- vibeOwningKeys = mapSection?.vibeOwningKeys || [];
336
- }
337
- console.debug('vibeOwningKeys: ' + vibeOwningKeys);
338
- return vibeOwningKeys;
339
- }
340
-
341
- async getVibeOwningKeysFromInbound(entity) {
342
- let vibeOwningKeys = [];
343
- if (this.transformMapFile && entity) {
344
- const mapKey = await TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, entity, TypeConversionUtils.FLEX2VIBE_DIRECTION);
345
-
346
- const mapSection = await MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
347
- vibeOwningKeys = mapSection?.vibeOwningKeys || [];
348
- }
349
- console.debug('vibeOwningKeys: ' + vibeOwningKeys);
350
- return vibeOwningKeys;
351
- }
352
-
353
- async createEntity(entityName, changes) {
354
- const options = {
355
- entityName: entityName,
356
- object: changes,
357
- };
358
- console.log("createEntity: " + JSON.stringify(options));
359
-
360
- return await new Entities().create(options);
361
- }
362
-
363
- async updateEntity(entityName, entity, diffs) {
364
- const options = {
365
- entityName: entityName,
366
- id: entity['id'],
367
- object: diffs
368
- };
369
- console.log('updateEntity: ' + JSON.stringify(options));
370
-
371
- return await new Entities().update(options);
372
- }
373
-
374
- // This method must be implemented by derived classes
375
- protected abstract getIncomingEntity(event, inboundData): Promise<IncomingEntityResponse>;
376
- protected abstract getCreateEntity(inboundData): Promise<IncomingEntityResponse>;
377
-
378
- // outbound
379
-
380
- async outbound(event) {
381
- const entityType = event.entityType;
382
- const eventType = event.eventType;
383
- const entityId = event.id;
384
- console.log(`outbound: ${entityType}:${entityId}`);
385
-
386
- switch (eventType) {
387
- case 'update':
388
- case 'create':
389
- return await this.handleOutgoingUpsert(entityType, event);
390
- case 'delete':
391
- return await this.handleOutgoingDelete(entityType, event);
392
- case 'sendUpsertToFlexPLM':
393
- return await this.sendUpsertToFlexPLM(event);
394
- default:
395
- console.log(UNSUPPORTED_TYPE);
396
- return {
397
- status: 500,
398
- data: { UNSUPPORTED_TYPE }
399
- };
400
- }
401
- }
402
-
403
- async handleOutgoingUpsert(entityType, event) {
404
- const objectClass = await TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
405
- if (!objectClass) {
406
- const message = 'ObjectClass must have a value.';
407
- console.log(message);
408
- return {
409
- status: 500,
410
- data: { message }
411
- };
412
- }
413
-
414
- try {
415
- const payload = await this.getOutgoingUpsertPayload(entityType, event);
416
- const flexResponse: any = await new FlexPLMConnect(this.config).sendToFlexPLM(payload);
417
-
418
- const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
419
- if(outboundEntityUpdates){
420
- flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
421
- }
422
-
423
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + EventShortMessageStatus.SUCCESS
424
- + ', statusMessage: '+ flexResponse.status
425
- + ', entityType: ' + this.baseType
426
- + ', entityId: ' + event.id
427
- + ', objectClass: ' + payload.objectClass
428
- + ', updateFromResponse: ' + (( outboundEntityUpdates &&Object.keys(outboundEntityUpdates).length > 0)? 'true' : 'false')
429
- + ', orgSlug: ' + this.orgSlug;
430
- console.log(statusMsg);
431
-
432
- return flexResponse;
433
-
434
- } catch(e){
435
- const statusMsg = 'BaseEntityProcessor: outbound: status: '+ EventShortMessageStatus.FAILURE
436
- + ', statusMessage: ' + e.httpResponseStatus
437
- + ', entityType: ' + this.baseType
438
- + ', entityId: ' + event.id
439
- + ', objectClass: ' + objectClass
440
- + ', updateFromResponse: ' + 'false'
441
- + ', orgSlug: ' + this.orgSlug;
442
- console.log(statusMsg);
443
- throw e;
444
- }
445
- }
446
-
447
- async getOutboundEntityUpdates(event, flexResponse): Promise<any> {
448
- const payload = flexResponse?.data?.payload;
449
- const flexPayload = (payload)? payload[0] : undefined;
450
- let outboundEntityUpdates = undefined;
451
- if(flexPayload && 'OK' === flexPayload.status) {
452
- if(flexPayload.data && !flexPayload.data?.flexPLMObjectClass){
453
- flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
454
- }
455
- const inboundData = await this.getTransformedData(flexPayload);
456
- outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData)
457
- }
458
- return outboundEntityUpdates;
459
- }
460
-
461
- async handleOutgoingDelete(entityType, event) {
462
- console.warn('delete is not configured', entityType, event.oldData);
463
- }
464
-
465
- // This method must be implemented by derived classes
466
- protected abstract getOutgoingUpsertPayload(entityType, event): Promise<EntityPayloadType>;
467
-
468
- /** Create a new event-workflow-request to rerun sending the entity to FlexPLM
469
- * The event must contain any information needed to ensure it is put in the correct queue for the entity
470
- *
471
- * @param triggerKey Ex: event.entityType + '|sendUpsertToFlexPLM'
472
- * @param event
473
- * @returns
474
- */
475
-
476
- protected async triggerNewEvent(triggerKey: string, event: any) {
477
- const newEvent = {
478
- entityName: 'event-workflow-request',
479
- object: {
480
- triggerKey,
481
- event
482
- }
483
- };
484
- const response = await this.entities.create(newEvent);
485
-
486
- return response;
487
- }
488
-
489
- /** Sends the current state of the entity to FlexPLM.
490
- * So any changes made in Vibe between the event being generated and the event being processed are sent to FlexPLM.
491
- *
492
- * @param event must contain entityType, id; which are used to query for the entity
493
- * @returns results of sending the entity to FlexPLM
494
- */
495
- protected async sendUpsertToFlexPLM(event) {
496
- const payload = await this.getEntityCurrentStateUpsertPayload(event);
497
- if(!payload){
498
- const message = 'No payload to send to FlexPLM';
499
- console.log(message);
500
- return {
501
- status: 500,
502
- data: {message}
503
- };
504
- };
505
- let objectClass = payload.objectClass;
506
- try {
507
- const flexResponse: any = await new FlexPLMConnect(this.config).sendToFlexPLM(payload);
508
-
509
- const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
510
- if(outboundEntityUpdates){
511
- flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
512
- }
513
-
514
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + EventShortMessageStatus.SUCCESS
515
- + ', statusMessage: ' + flexResponse.status
516
- + ', entityType: ' + this.baseType
517
- + ', entityId: ' + event.id
518
- + ', objectClass: ' + objectClass
519
- + ', updateFromResponse: ' + ((outboundEntityUpdates &&Object.keys(outboundEntityUpdates).length > 0)? 'true' : 'false')
520
- + ', orgSlug: ' + this.orgSlug;
521
- console.log(statusMsg);
522
- return flexResponse;
523
- }catch(e){
524
- const statusMsg = 'BaseEntityProcessor: outbound: status: '+ EventShortMessageStatus.FAILURE
525
- + ', statusMessage: ' + e.httpResponseStatus
526
- + ', entityType: ' + this.baseType
527
- + ', entityId: ' + event.id
528
- + ', objectClass: ' + objectClass
529
- + ', updateFromResponse: ' + 'false'
530
- + ', orgSlug: ' + this.orgSlug;
531
- console.log(statusMsg);
532
- throw e;
533
- }
534
- }
535
-
536
- /** Generates the payload to send to FlexPLM, based on the current state of the entity.
537
- * The current state of the entity are used as the newData and oldData; which is passed
538
- * to getOutgoingUpsertPayload to generate the payload.
539
- * @param event information about the item to send to FlexPLM
540
- * @returns The payload to send to FlexPLM
541
- */
542
- protected async getEntityCurrentStateUpsertPayload(event: any): Promise<EntityPayloadType> {
543
-
544
- const id = event.id;
545
- if(!id){
546
- return undefined;
547
- }
548
-
549
- const entity = await this.entities.get({
550
- entityName: this.baseType,
551
- id
552
- });
553
-
554
- if(!entity){
555
- return undefined;
556
- }
557
-
558
- event.newData = entity;
559
- event.oldData = entity;
560
-
561
- const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
562
-
563
- return payload;
564
- }
565
- }
@@ -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';