@contrail/flexplm 1.3.0-alpha.0 → 1.3.0-alpha.3
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.
- package/.github/pull_request_template.md +31 -31
- package/.github/workflows/flexplm-lib.yml +27 -27
- package/CHANGELOG.md +1 -1
- package/lib/entity-processor/base-entity-processor.d.ts +42 -0
- package/lib/entity-processor/base-entity-processor.js +377 -0
- package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -0
- package/lib/entity-processor/base-entity-processor.spec.js +426 -0
- package/lib/flexplm-request.d.ts +3 -0
- package/lib/flexplm-request.js +34 -0
- package/lib/flexplm-utils.d.ts +5 -0
- package/lib/flexplm-utils.js +33 -0
- package/lib/flexplm-utils.spec.d.ts +1 -0
- package/lib/flexplm-utils.spec.js +26 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +38 -0
- package/lib/interfaces/interfaces.d.ts +105 -0
- package/lib/interfaces/interfaces.js +2 -0
- package/lib/interfaces/item-family-changes.d.ts +20 -0
- package/lib/interfaces/item-family-changes.js +56 -0
- package/lib/interfaces/publish-change-data.d.ts +19 -0
- package/lib/interfaces/publish-change-data.js +32 -0
- package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -0
- package/lib/publish/base-process-publish-assortment-callback.js +38 -0
- package/lib/publish/base-process-publish-assortment.d.ts +93 -0
- package/lib/publish/base-process-publish-assortment.js +944 -0
- package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -0
- package/lib/publish/base-process-publish-assortment.spec.js +1670 -0
- package/lib/publish/mockData.d.ts +1389 -0
- package/lib/publish/mockData.js +4519 -0
- package/lib/transform/identifier-conversion-spec-mockData.d.ts +0 -0
- package/lib/transform/identifier-conversion-spec-mockData.js +444 -0
- package/lib/transform/identifier-conversion.d.ts +15 -0
- package/lib/transform/identifier-conversion.js +212 -0
- package/lib/transform/identifier-conversion.spec.d.ts +1 -0
- package/lib/transform/identifier-conversion.spec.js +339 -0
- package/lib/util/config-defaults.d.ts +8 -0
- package/lib/util/config-defaults.js +85 -0
- package/lib/util/config-defaults.spec.d.ts +1 -0
- package/lib/util/config-defaults.spec.js +293 -0
- package/lib/util/data-converter-spec-mockData.d.ts +0 -0
- package/lib/util/data-converter-spec-mockData.js +205 -0
- package/lib/util/data-converter.d.ts +39 -0
- package/lib/util/data-converter.js +592 -0
- package/lib/util/data-converter.spec.d.ts +1 -0
- package/lib/util/data-converter.spec.js +904 -0
- package/lib/util/error-response-object.d.ts +4 -0
- package/lib/util/error-response-object.js +47 -0
- package/lib/util/error-response-object.spec.d.ts +1 -0
- package/lib/util/error-response-object.spec.js +99 -0
- package/lib/util/event-short-message-status.d.ts +18 -0
- package/lib/util/event-short-message-status.js +22 -0
- package/lib/util/federation.d.ts +15 -0
- package/lib/util/federation.js +149 -0
- package/lib/util/flexplm-connect.d.ts +22 -0
- package/lib/util/flexplm-connect.js +176 -0
- package/lib/util/flexplm-connect.spec.d.ts +1 -0
- package/lib/util/flexplm-connect.spec.js +88 -0
- package/lib/util/logger-config.d.ts +1 -0
- package/lib/util/logger-config.js +26 -0
- package/lib/util/map-util-spec-mockData.d.ts +0 -0
- package/lib/util/map-util-spec-mockData.js +205 -0
- package/lib/util/map-utils.d.ts +6 -0
- package/lib/util/map-utils.js +15 -0
- package/lib/util/map-utils.spec.d.ts +1 -0
- package/lib/util/map-utils.spec.js +89 -0
- package/lib/util/mockData.d.ts +79 -0
- package/lib/util/mockData.js +99 -0
- package/lib/util/thumbnail-util.d.ts +28 -0
- package/lib/util/thumbnail-util.js +202 -0
- package/lib/util/thumbnail-util.spec.d.ts +1 -0
- package/lib/util/thumbnail-util.spec.js +398 -0
- package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
- package/lib/util/type-conversion-utils-spec-mockData.js +259 -0
- package/lib/util/type-conversion-utils.d.ts +23 -0
- package/lib/util/type-conversion-utils.js +266 -0
- package/lib/util/type-conversion-utils.spec.d.ts +1 -0
- package/lib/util/type-conversion-utils.spec.js +868 -0
- package/lib/util/type-defaults.d.ts +16 -0
- package/lib/util/type-defaults.js +221 -0
- package/lib/util/type-defaults.spec.d.ts +1 -0
- package/lib/util/type-defaults.spec.js +516 -0
- package/lib/util/type-utils.d.ts +13 -0
- package/lib/util/type-utils.js +114 -0
- package/lib/util/type-utils.spec.d.ts +1 -0
- package/lib/util/type-utils.spec.js +190 -0
- package/package.json +1 -1
- package/publish.bat +4 -4
- package/publish.sh +4 -4
- package/src/entity-processor/base-entity-processor.spec.ts +157 -0
- package/src/entity-processor/base-entity-processor.ts +21 -2
- package/src/flexplm-request.ts +28 -28
- package/src/flexplm-utils.spec.ts +27 -27
- package/src/flexplm-utils.ts +29 -29
- package/src/index.ts +21 -21
- package/src/interfaces/item-family-changes.ts +66 -66
- package/src/interfaces/publish-change-data.ts +42 -42
- package/src/publish/base-process-publish-assortment-callback.ts +50 -50
- package/src/transform/identifier-conversion-spec-mockData.ts +495 -495
- package/src/transform/identifier-conversion.spec.ts +353 -353
- package/src/transform/identifier-conversion.ts +281 -281
- package/src/util/config-defaults.spec.ts +350 -350
- package/src/util/config-defaults.ts +92 -92
- package/src/util/data-converter-spec-mockData.ts +230 -230
- package/src/util/error-response-object.spec.ts +115 -115
- package/src/util/error-response-object.ts +49 -49
- package/src/util/federation.ts +172 -172
- package/src/util/logger-config.ts +19 -19
- package/src/util/map-util-spec-mockData.ts +230 -230
- package/src/util/map-utils.spec.ts +102 -102
- package/src/util/map-utils.ts +40 -40
- package/src/util/mockData.ts +97 -97
- package/src/util/thumbnail-util.spec.ts +190 -0
- package/src/util/thumbnail-util.ts +109 -1
- package/src/util/type-conversion-utils.spec.ts +25 -25
- package/src/util/type-conversion-utils.ts +10 -9
- package/src/util/type-defaults.spec.ts +668 -668
- package/src/util/type-defaults.ts +280 -280
- package/src/util/type-utils.spec.ts +227 -227
- package/src/util/type-utils.ts +144 -144
- package/tsconfig.json +28 -26
- package/tslint.json +57 -57
- package/scripts/output.png +0 -0
- package/scripts/test-get-request.ts +0 -35
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
## What
|
|
2
|
-
- [ ] Bugfix
|
|
3
|
-
- [ ] Feature
|
|
4
|
-
- [ ] Enhancement
|
|
5
|
-
|
|
6
|
-
Description:
|
|
7
|
-
<!--
|
|
8
|
-
Describe the functional changes of the PR.
|
|
9
|
-
|
|
10
|
-
If the mechanism of your change are complex, describe them in detail as you
|
|
11
|
-
would if you were explaining them to a team mate.
|
|
12
|
-
|
|
13
|
-
If the PR is simple, there is no need to repeat yourself. A small description
|
|
14
|
-
is sufficient.
|
|
15
|
-
-->
|
|
16
|
-
|
|
17
|
-
## Why
|
|
18
|
-
<!--
|
|
19
|
-
why is this change needed? Same rules as with #What
|
|
20
|
-
-->
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## Testing added
|
|
24
|
-
<!--
|
|
25
|
-
Describe the testing you added to this PR
|
|
26
|
-
-->
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
## Link to Jira ticket(s)
|
|
30
|
-
https://vibe-team.atlassian.net/browse/VIBE-TICKET_NUMBER_HERE
|
|
31
|
-
|
|
1
|
+
## What
|
|
2
|
+
- [ ] Bugfix
|
|
3
|
+
- [ ] Feature
|
|
4
|
+
- [ ] Enhancement
|
|
5
|
+
|
|
6
|
+
Description:
|
|
7
|
+
<!--
|
|
8
|
+
Describe the functional changes of the PR.
|
|
9
|
+
|
|
10
|
+
If the mechanism of your change are complex, describe them in detail as you
|
|
11
|
+
would if you were explaining them to a team mate.
|
|
12
|
+
|
|
13
|
+
If the PR is simple, there is no need to repeat yourself. A small description
|
|
14
|
+
is sufficient.
|
|
15
|
+
-->
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
<!--
|
|
19
|
+
why is this change needed? Same rules as with #What
|
|
20
|
+
-->
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Testing added
|
|
24
|
+
<!--
|
|
25
|
+
Describe the testing you added to this PR
|
|
26
|
+
-->
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Link to Jira ticket(s)
|
|
30
|
+
https://vibe-team.atlassian.net/browse/VIBE-TICKET_NUMBER_HERE
|
|
31
|
+
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
name: flexplm-lib-tests
|
|
2
|
-
on:
|
|
3
|
-
pull_request:
|
|
4
|
-
workflow_dispatch: # allow running in github actions manually
|
|
5
|
-
jobs:
|
|
6
|
-
test:
|
|
7
|
-
runs-on: ubuntu-24.04
|
|
8
|
-
strategy:
|
|
9
|
-
matrix:
|
|
10
|
-
node-version: [22.14.0]
|
|
11
|
-
steps:
|
|
12
|
-
- name: Node.js
|
|
13
|
-
uses: actions/setup-node@v3
|
|
14
|
-
with:
|
|
15
|
-
node-version: ${{ matrix.node-version }}
|
|
16
|
-
|
|
17
|
-
- uses: actions/checkout@v3
|
|
18
|
-
|
|
19
|
-
- name: NPM Install
|
|
20
|
-
env:
|
|
21
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
22
|
-
run: npm ci
|
|
23
|
-
|
|
24
|
-
- name: Unit Tests -
|
|
25
|
-
env:
|
|
26
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
27
|
-
run: npm test
|
|
1
|
+
name: flexplm-lib-tests
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
workflow_dispatch: # allow running in github actions manually
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
runs-on: ubuntu-24.04
|
|
8
|
+
strategy:
|
|
9
|
+
matrix:
|
|
10
|
+
node-version: [22.14.0]
|
|
11
|
+
steps:
|
|
12
|
+
- name: Node.js
|
|
13
|
+
uses: actions/setup-node@v3
|
|
14
|
+
with:
|
|
15
|
+
node-version: ${{ matrix.node-version }}
|
|
16
|
+
|
|
17
|
+
- uses: actions/checkout@v3
|
|
18
|
+
|
|
19
|
+
- name: NPM Install
|
|
20
|
+
env:
|
|
21
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
22
|
+
run: npm ci
|
|
23
|
+
|
|
24
|
+
- name: Unit Tests -
|
|
25
|
+
env:
|
|
26
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
27
|
+
run: npm test
|
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FCConfig, EntityPayloadType } from '../interfaces/interfaces';
|
|
2
|
+
import { DataConverter } from '../util/data-converter';
|
|
3
|
+
import { TypeUtils } from '../util/type-utils';
|
|
4
|
+
import { MapFileUtil } from '@contrail/transform-data';
|
|
5
|
+
export declare class IncomingEntityResponse {
|
|
6
|
+
entity: any;
|
|
7
|
+
earlyReturn: any;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class BaseEntityProcessor {
|
|
10
|
+
protected config: FCConfig;
|
|
11
|
+
protected dc: DataConverter;
|
|
12
|
+
protected mapFileUtil: MapFileUtil;
|
|
13
|
+
protected baseType: string;
|
|
14
|
+
protected typeUtil: TypeUtils;
|
|
15
|
+
protected transformMapFile: string;
|
|
16
|
+
protected entities: any;
|
|
17
|
+
protected orgSlug: string;
|
|
18
|
+
constructor(config: FCConfig, dc: DataConverter, mapFileUtil: MapFileUtil, baseType: string);
|
|
19
|
+
inbound(event: EntityPayloadType): Promise<any>;
|
|
20
|
+
handleIncomingUpsert(event: EntityPayloadType): Promise<any>;
|
|
21
|
+
getInboundStatusMessage(statusObject: any): string;
|
|
22
|
+
queryEntityWithSubTypeCriteria(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any[]>;
|
|
23
|
+
getCriteriaForEntity(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any>;
|
|
24
|
+
getRootTypePropertyKeys(rootType: any, propertyCriteria?: any): string[];
|
|
25
|
+
handleIncomingDelete(event: any): Promise<void>;
|
|
26
|
+
getTransformedData(event: any): Promise<any>;
|
|
27
|
+
getUpdatesForEntity(entity: any, inboundData: any): Promise<object>;
|
|
28
|
+
getVibeOwningKeys(entity: any): Promise<any[]>;
|
|
29
|
+
getVibeOwningKeysFromInbound(entity: any): Promise<any[]>;
|
|
30
|
+
createEntity(entityName: any, changes: any): Promise<any>;
|
|
31
|
+
updateEntity(entityName: any, entity: any, diffs: any): Promise<any>;
|
|
32
|
+
protected abstract getIncomingEntity(event: any, inboundData: any): Promise<IncomingEntityResponse>;
|
|
33
|
+
protected abstract getCreateEntity(inboundData: any): Promise<IncomingEntityResponse>;
|
|
34
|
+
outbound(event: any): Promise<any>;
|
|
35
|
+
handleOutgoingUpsert(entityType: any, event: any): Promise<any>;
|
|
36
|
+
getOutboundEntityUpdates(event: any, flexResponse: any): Promise<any>;
|
|
37
|
+
handleOutgoingDelete(entityType: any, event: any): Promise<void>;
|
|
38
|
+
protected abstract getOutgoingUpsertPayload(entityType: any, event: any): Promise<EntityPayloadType>;
|
|
39
|
+
protected triggerNewEvent(triggerKey: string, event: any): Promise<any>;
|
|
40
|
+
protected sendUpsertToFlexPLM(event: any): Promise<any>;
|
|
41
|
+
protected getEntityCurrentStateUpsertPayload(event: any): Promise<EntityPayloadType>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEntityProcessor = exports.IncomingEntityResponse = void 0;
|
|
4
|
+
const type_utils_1 = require("../util/type-utils");
|
|
5
|
+
const flexplm_connect_1 = require("../util/flexplm-connect");
|
|
6
|
+
const map_utils_1 = require("../util/map-utils");
|
|
7
|
+
const sdk_1 = require("@contrail/sdk");
|
|
8
|
+
const type_conversion_utils_1 = require("../util/type-conversion-utils");
|
|
9
|
+
const thumbnail_util_1 = require("../util/thumbnail-util");
|
|
10
|
+
const event_short_message_status_1 = require("../util/event-short-message-status");
|
|
11
|
+
const UNSUPPORTED_TYPE = 'Unsupported eventType.';
|
|
12
|
+
class IncomingEntityResponse {
|
|
13
|
+
}
|
|
14
|
+
exports.IncomingEntityResponse = IncomingEntityResponse;
|
|
15
|
+
class BaseEntityProcessor {
|
|
16
|
+
constructor(config, dc, mapFileUtil, baseType) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
this.dc = dc;
|
|
19
|
+
this.mapFileUtil = mapFileUtil;
|
|
20
|
+
this.baseType = baseType;
|
|
21
|
+
this.typeUtil = new type_utils_1.TypeUtils();
|
|
22
|
+
this.transformMapFile = this.config?.transformMapFile;
|
|
23
|
+
this.entities = new sdk_1.Entities();
|
|
24
|
+
this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
|
|
25
|
+
}
|
|
26
|
+
async inbound(event) {
|
|
27
|
+
const eventType = event.eventType;
|
|
28
|
+
console.log(`inbound entity: ${eventType}:${event.objectClass}`);
|
|
29
|
+
switch (eventType) {
|
|
30
|
+
case 'PERSIST':
|
|
31
|
+
return await this.handleIncomingUpsert(event);
|
|
32
|
+
case 'DELETE':
|
|
33
|
+
return await this.handleIncomingDelete(event);
|
|
34
|
+
default:
|
|
35
|
+
console.error(UNSUPPORTED_TYPE);
|
|
36
|
+
return {
|
|
37
|
+
status: 500,
|
|
38
|
+
data: { UNSUPPORTED_TYPE }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async handleIncomingUpsert(event) {
|
|
43
|
+
const inboundData = await this.getTransformedData(event);
|
|
44
|
+
const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
|
|
45
|
+
if (incomingEntityResponse.earlyReturn) {
|
|
46
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
47
|
+
status: event_short_message_status_1.EventShortMessageStatus.FAILURE,
|
|
48
|
+
statusMessage: incomingEntityResponse.earlyReturn.shortStatusMessage || '',
|
|
49
|
+
objectClass: event.objectClass,
|
|
50
|
+
federatedId: event.federatedId
|
|
51
|
+
});
|
|
52
|
+
console.log(statusMsg);
|
|
53
|
+
return incomingEntityResponse.earlyReturn;
|
|
54
|
+
}
|
|
55
|
+
const entity = incomingEntityResponse.entity;
|
|
56
|
+
if (!entity) {
|
|
57
|
+
const createEntityResponse = await this.getCreateEntity(inboundData);
|
|
58
|
+
if (createEntityResponse.earlyReturn) {
|
|
59
|
+
const status = (createEntityResponse.earlyReturn.shortStatusMessage === event_short_message_status_1.EventShortMessageStatus.NOT_CREATABLE)
|
|
60
|
+
? event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
61
|
+
: event_short_message_status_1.EventShortMessageStatus.FAILURE;
|
|
62
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
63
|
+
status,
|
|
64
|
+
statusMessage: createEntityResponse.earlyReturn.shortStatusMessage || '',
|
|
65
|
+
objectClass: event.objectClass,
|
|
66
|
+
federatedId: event.federatedId
|
|
67
|
+
});
|
|
68
|
+
console.log(statusMsg);
|
|
69
|
+
return createEntityResponse.earlyReturn;
|
|
70
|
+
}
|
|
71
|
+
const createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
|
|
72
|
+
const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
|
|
73
|
+
if (shouldSyncThumbnail) {
|
|
74
|
+
const thumbnailUpdates = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType });
|
|
75
|
+
if (thumbnailUpdates) {
|
|
76
|
+
await this.updateEntity(this.baseType, createdEntity, thumbnailUpdates);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
80
|
+
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
81
|
+
statusMessage: event_short_message_status_1.EventShortMessageStatus.CREATED,
|
|
82
|
+
objectClass: event.objectClass,
|
|
83
|
+
entityId: 'id',
|
|
84
|
+
federatedId: event.federatedId
|
|
85
|
+
});
|
|
86
|
+
console.log(statusMsg);
|
|
87
|
+
return createdEntity;
|
|
88
|
+
}
|
|
89
|
+
const diffs = await this.getUpdatesForEntity(entity, inboundData);
|
|
90
|
+
const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
|
|
91
|
+
let thumbnailUpdates;
|
|
92
|
+
if (shouldSyncThumbnail) {
|
|
93
|
+
thumbnailUpdates = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: entity.id, primaryViewableId: entity.primaryViewableId, event, entityName: this.baseType });
|
|
94
|
+
}
|
|
95
|
+
const allUpdates = { ...diffs, ...thumbnailUpdates };
|
|
96
|
+
if (Object.getOwnPropertyNames(allUpdates).length == 0) {
|
|
97
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
98
|
+
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
99
|
+
statusMessage: event_short_message_status_1.EventShortMessageStatus.NO_CHANGES,
|
|
100
|
+
objectClass: event.objectClass,
|
|
101
|
+
entityId: entity.id,
|
|
102
|
+
federatedId: event.federatedId
|
|
103
|
+
});
|
|
104
|
+
console.log(statusMsg);
|
|
105
|
+
const message = 'No Changes to persist for entity: ' + entity.id;
|
|
106
|
+
return {
|
|
107
|
+
status: 200,
|
|
108
|
+
data: { message }
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const updatedEntity = await this.updateEntity(this.baseType, entity, allUpdates);
|
|
112
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
113
|
+
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
114
|
+
statusMessage: event_short_message_status_1.EventShortMessageStatus.UPDATED,
|
|
115
|
+
objectClass: event.objectClass,
|
|
116
|
+
entityId: entity.id,
|
|
117
|
+
federatedId: event.federatedId
|
|
118
|
+
});
|
|
119
|
+
console.log(statusMsg);
|
|
120
|
+
return updatedEntity;
|
|
121
|
+
}
|
|
122
|
+
getInboundStatusMessage(statusObject) {
|
|
123
|
+
return 'BaseEntityProcessor: inbound: status: ' + statusObject.status
|
|
124
|
+
+ ', statusMessage: ' + statusObject.statusMessage
|
|
125
|
+
+ ', entityType: ' + this.baseType
|
|
126
|
+
+ ', entityId: ' + statusObject.entityId
|
|
127
|
+
+ ', objectClass: ' + statusObject.objectClass
|
|
128
|
+
+ ', federatedId: ' + statusObject.federatedId
|
|
129
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
130
|
+
}
|
|
131
|
+
async queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria) {
|
|
132
|
+
if (!entityType || !entityTypePath) {
|
|
133
|
+
throw new Error('type and entityTypePath must be defined');
|
|
134
|
+
}
|
|
135
|
+
if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
|
|
136
|
+
throw new Error('propertyCriteria must be defined and have at least one property');
|
|
137
|
+
}
|
|
138
|
+
const { rootTypeCriteria, subTypeCriteria } = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
|
|
139
|
+
const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
|
|
140
|
+
return returnedEntities;
|
|
141
|
+
}
|
|
142
|
+
async getCriteriaForEntity(entityType, entityTypePath, propertyCriteria) {
|
|
143
|
+
if (!entityType || !entityTypePath) {
|
|
144
|
+
throw new Error('type and entityTypePath must be defined');
|
|
145
|
+
}
|
|
146
|
+
if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
|
|
147
|
+
throw new Error('propertyCriteria must be defined and have at least one property');
|
|
148
|
+
}
|
|
149
|
+
const rootType = await this.typeUtil.getByRootAndPath({ root: entityType });
|
|
150
|
+
const rootTypePropertyKeys = await this.getRootTypePropertyKeys(rootType, propertyCriteria);
|
|
151
|
+
const rootTypeCriteria = {};
|
|
152
|
+
const subTypeCriteria = {};
|
|
153
|
+
if (entityType !== entityTypePath) {
|
|
154
|
+
subTypeCriteria['typePath'] = entityTypePath;
|
|
155
|
+
}
|
|
156
|
+
for (const key in propertyCriteria) {
|
|
157
|
+
if (rootTypePropertyKeys.includes(key)) {
|
|
158
|
+
rootTypeCriteria[key] = propertyCriteria[key];
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
subTypeCriteria[key] = propertyCriteria[key];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { rootTypeCriteria, subTypeCriteria };
|
|
165
|
+
}
|
|
166
|
+
getRootTypePropertyKeys(rootType, propertyCriteria = null) {
|
|
167
|
+
const props = rootType['typeProperties'];
|
|
168
|
+
const rootTypePropertyKeys = props.map(prop => prop.slug);
|
|
169
|
+
return rootTypePropertyKeys;
|
|
170
|
+
}
|
|
171
|
+
async handleIncomingDelete(event) {
|
|
172
|
+
console.warn('delete is not configured', event);
|
|
173
|
+
}
|
|
174
|
+
async getTransformedData(event) {
|
|
175
|
+
let inboundData = event.data;
|
|
176
|
+
console.debug('inboundData: ' + JSON.stringify(inboundData));
|
|
177
|
+
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, inboundData, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
178
|
+
inboundData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, mapKey, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
179
|
+
console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
|
|
180
|
+
return inboundData;
|
|
181
|
+
}
|
|
182
|
+
async getUpdatesForEntity(entity, inboundData) {
|
|
183
|
+
const vibeOwningKeys = await this.getVibeOwningKeys(entity);
|
|
184
|
+
let updates = {
|
|
185
|
+
typeId: entity.typeId,
|
|
186
|
+
roles: entity.roles,
|
|
187
|
+
id: entity.id,
|
|
188
|
+
};
|
|
189
|
+
updates = await this.dc.setEntityValues(updates, inboundData, vibeOwningKeys);
|
|
190
|
+
for (const prop of ['typeId', 'roles', 'id']) {
|
|
191
|
+
delete updates[prop];
|
|
192
|
+
}
|
|
193
|
+
return this.dc.getPersistableChanges(entity, updates);
|
|
194
|
+
}
|
|
195
|
+
async getVibeOwningKeys(entity) {
|
|
196
|
+
let vibeOwningKeys = [];
|
|
197
|
+
if (this.transformMapFile && entity) {
|
|
198
|
+
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
199
|
+
const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
|
|
200
|
+
vibeOwningKeys = mapSection?.vibeOwningKeys || [];
|
|
201
|
+
}
|
|
202
|
+
console.debug('vibeOwningKeys: ' + vibeOwningKeys);
|
|
203
|
+
return vibeOwningKeys;
|
|
204
|
+
}
|
|
205
|
+
async getVibeOwningKeysFromInbound(entity) {
|
|
206
|
+
let vibeOwningKeys = [];
|
|
207
|
+
if (this.transformMapFile && entity) {
|
|
208
|
+
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
209
|
+
const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
|
|
210
|
+
vibeOwningKeys = mapSection?.vibeOwningKeys || [];
|
|
211
|
+
}
|
|
212
|
+
console.debug('vibeOwningKeys: ' + vibeOwningKeys);
|
|
213
|
+
return vibeOwningKeys;
|
|
214
|
+
}
|
|
215
|
+
async createEntity(entityName, changes) {
|
|
216
|
+
const options = {
|
|
217
|
+
entityName: entityName,
|
|
218
|
+
object: changes,
|
|
219
|
+
};
|
|
220
|
+
console.log("createEntity: " + JSON.stringify(options));
|
|
221
|
+
return await new sdk_1.Entities().create(options);
|
|
222
|
+
}
|
|
223
|
+
async updateEntity(entityName, entity, diffs) {
|
|
224
|
+
const options = {
|
|
225
|
+
entityName: entityName,
|
|
226
|
+
id: entity['id'],
|
|
227
|
+
object: diffs
|
|
228
|
+
};
|
|
229
|
+
console.log('updateEntity: ' + JSON.stringify(options));
|
|
230
|
+
return await new sdk_1.Entities().update(options);
|
|
231
|
+
}
|
|
232
|
+
async outbound(event) {
|
|
233
|
+
const entityType = event.entityType;
|
|
234
|
+
const eventType = event.eventType;
|
|
235
|
+
const entityId = event.id;
|
|
236
|
+
console.log(`outbound: ${entityType}:${entityId}`);
|
|
237
|
+
switch (eventType) {
|
|
238
|
+
case 'update':
|
|
239
|
+
case 'create':
|
|
240
|
+
return await this.handleOutgoingUpsert(entityType, event);
|
|
241
|
+
case 'delete':
|
|
242
|
+
return await this.handleOutgoingDelete(entityType, event);
|
|
243
|
+
case 'sendUpsertToFlexPLM':
|
|
244
|
+
return await this.sendUpsertToFlexPLM(event);
|
|
245
|
+
default:
|
|
246
|
+
console.log(UNSUPPORTED_TYPE);
|
|
247
|
+
return {
|
|
248
|
+
status: 500,
|
|
249
|
+
data: { UNSUPPORTED_TYPE }
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async handleOutgoingUpsert(entityType, event) {
|
|
254
|
+
const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
|
|
255
|
+
if (!objectClass) {
|
|
256
|
+
const message = 'ObjectClass must have a value.';
|
|
257
|
+
console.log(message);
|
|
258
|
+
return {
|
|
259
|
+
status: 500,
|
|
260
|
+
data: { message }
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
const payload = await this.getOutgoingUpsertPayload(entityType, event);
|
|
265
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
266
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
267
|
+
if (outboundEntityUpdates) {
|
|
268
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
269
|
+
}
|
|
270
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
271
|
+
+ ', statusMessage: ' + flexResponse.status
|
|
272
|
+
+ ', entityType: ' + this.baseType
|
|
273
|
+
+ ', entityId: ' + event.id
|
|
274
|
+
+ ', objectClass: ' + payload.objectClass
|
|
275
|
+
+ ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
|
|
276
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
277
|
+
console.log(statusMsg);
|
|
278
|
+
return flexResponse;
|
|
279
|
+
}
|
|
280
|
+
catch (e) {
|
|
281
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
|
|
282
|
+
+ ', statusMessage: ' + e.httpResponseStatus
|
|
283
|
+
+ ', entityType: ' + this.baseType
|
|
284
|
+
+ ', entityId: ' + event.id
|
|
285
|
+
+ ', objectClass: ' + objectClass
|
|
286
|
+
+ ', updateFromResponse: ' + 'false'
|
|
287
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
288
|
+
console.log(statusMsg);
|
|
289
|
+
throw e;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
async getOutboundEntityUpdates(event, flexResponse) {
|
|
293
|
+
const payload = flexResponse?.data?.payload;
|
|
294
|
+
const flexPayload = (payload) ? payload[0] : undefined;
|
|
295
|
+
let outboundEntityUpdates = undefined;
|
|
296
|
+
if (flexPayload && 'OK' === flexPayload.status) {
|
|
297
|
+
if (flexPayload.data && !flexPayload.data?.flexPLMObjectClass) {
|
|
298
|
+
flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
|
|
299
|
+
}
|
|
300
|
+
const inboundData = await this.getTransformedData(flexPayload);
|
|
301
|
+
outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData);
|
|
302
|
+
}
|
|
303
|
+
return outboundEntityUpdates;
|
|
304
|
+
}
|
|
305
|
+
async handleOutgoingDelete(entityType, event) {
|
|
306
|
+
console.warn('delete is not configured', entityType, event.oldData);
|
|
307
|
+
}
|
|
308
|
+
async triggerNewEvent(triggerKey, event) {
|
|
309
|
+
const newEvent = {
|
|
310
|
+
entityName: 'event-workflow-request',
|
|
311
|
+
object: {
|
|
312
|
+
triggerKey,
|
|
313
|
+
event
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const response = await this.entities.create(newEvent);
|
|
317
|
+
return response;
|
|
318
|
+
}
|
|
319
|
+
async sendUpsertToFlexPLM(event) {
|
|
320
|
+
const payload = await this.getEntityCurrentStateUpsertPayload(event);
|
|
321
|
+
if (!payload) {
|
|
322
|
+
const message = 'No payload to send to FlexPLM';
|
|
323
|
+
console.log(message);
|
|
324
|
+
return {
|
|
325
|
+
status: 500,
|
|
326
|
+
data: { message }
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
;
|
|
330
|
+
let objectClass = payload.objectClass;
|
|
331
|
+
try {
|
|
332
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
333
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
334
|
+
if (outboundEntityUpdates) {
|
|
335
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
336
|
+
}
|
|
337
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
338
|
+
+ ', statusMessage: ' + flexResponse.status
|
|
339
|
+
+ ', entityType: ' + this.baseType
|
|
340
|
+
+ ', entityId: ' + event.id
|
|
341
|
+
+ ', objectClass: ' + objectClass
|
|
342
|
+
+ ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
|
|
343
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
344
|
+
console.log(statusMsg);
|
|
345
|
+
return flexResponse;
|
|
346
|
+
}
|
|
347
|
+
catch (e) {
|
|
348
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
|
|
349
|
+
+ ', statusMessage: ' + e.httpResponseStatus
|
|
350
|
+
+ ', entityType: ' + this.baseType
|
|
351
|
+
+ ', entityId: ' + event.id
|
|
352
|
+
+ ', objectClass: ' + objectClass
|
|
353
|
+
+ ', updateFromResponse: ' + 'false'
|
|
354
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
355
|
+
console.log(statusMsg);
|
|
356
|
+
throw e;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
async getEntityCurrentStateUpsertPayload(event) {
|
|
360
|
+
const id = event.id;
|
|
361
|
+
if (!id) {
|
|
362
|
+
return undefined;
|
|
363
|
+
}
|
|
364
|
+
const entity = await this.entities.get({
|
|
365
|
+
entityName: this.baseType,
|
|
366
|
+
id
|
|
367
|
+
});
|
|
368
|
+
if (!entity) {
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
event.newData = entity;
|
|
372
|
+
event.oldData = entity;
|
|
373
|
+
const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
|
|
374
|
+
return payload;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
exports.BaseEntityProcessor = BaseEntityProcessor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|