@contrail/flexplm 1.0.12 → 1.0.14
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.
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FCConfig, EntityPayloadType } from '../util/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
|
+
constructor(config: FCConfig, dc: DataConverter, mapFileUtil: MapFileUtil, baseType: string);
|
|
18
|
+
inbound(event: EntityPayloadType): Promise<any>;
|
|
19
|
+
handleIncomingUpdate(event: EntityPayloadType): Promise<any>;
|
|
20
|
+
handleIncomingDelete(event: any): Promise<void>;
|
|
21
|
+
getTransformedData(event: any): Promise<any>;
|
|
22
|
+
getUpdatesForEntity(entity: any, inboundData: any): Promise<object>;
|
|
23
|
+
getVibeOwningKeys(entity: any): Promise<any[]>;
|
|
24
|
+
updateEntity(entityName: any, entity: any, diffs: any): Promise<any>;
|
|
25
|
+
protected abstract getIncomingEntity(event: any, inboundData: any): IncomingEntityResponse;
|
|
26
|
+
outbound(event: any): Promise<void | import("../util/interfaces").FlexPLMResponseData>;
|
|
27
|
+
handleOutgoingUpsert(entityType: any, event: any): Promise<import("../util/interfaces").FlexPLMResponseData>;
|
|
28
|
+
handleOutgoingDelete(entityType: any, event: any): Promise<void>;
|
|
29
|
+
protected abstract getOutgoingUpsertPayload(entityType: any, event: any): Promise<EntityPayloadType>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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 UNSUPPORTED_TYPE = 'Unsupported eventType.';
|
|
9
|
+
class IncomingEntityResponse {
|
|
10
|
+
}
|
|
11
|
+
exports.IncomingEntityResponse = IncomingEntityResponse;
|
|
12
|
+
class BaseEntityProcessor {
|
|
13
|
+
constructor(config, dc, mapFileUtil, baseType) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.dc = dc;
|
|
16
|
+
this.mapFileUtil = mapFileUtil;
|
|
17
|
+
this.baseType = baseType;
|
|
18
|
+
this.typeUtil = new type_utils_1.TypeUtils();
|
|
19
|
+
this.transformMapFile = this.config['transformMapFile'];
|
|
20
|
+
this.entities = new sdk_1.Entities();
|
|
21
|
+
}
|
|
22
|
+
async inbound(event) {
|
|
23
|
+
const eventType = event.eventType;
|
|
24
|
+
console.log(`inbound entity: ${eventType}:${event.objectClass}`);
|
|
25
|
+
switch (eventType) {
|
|
26
|
+
case 'PERSIST':
|
|
27
|
+
return await this.handleIncomingUpdate(event);
|
|
28
|
+
case 'DELETE':
|
|
29
|
+
return await this.handleIncomingDelete(event);
|
|
30
|
+
default:
|
|
31
|
+
console.error(UNSUPPORTED_TYPE);
|
|
32
|
+
return {
|
|
33
|
+
status: 500,
|
|
34
|
+
data: { UNSUPPORTED_TYPE }
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async handleIncomingUpdate(event) {
|
|
39
|
+
const inboundData = await this.getTransformedData(event);
|
|
40
|
+
const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
|
|
41
|
+
if (incomingEntityResponse.earlyReturn) {
|
|
42
|
+
return incomingEntityResponse.earlyReturn;
|
|
43
|
+
}
|
|
44
|
+
const entity = incomingEntityResponse.entity;
|
|
45
|
+
if (!entity) {
|
|
46
|
+
const message = 'No entity found';
|
|
47
|
+
console.debug(message);
|
|
48
|
+
return {
|
|
49
|
+
status: 404,
|
|
50
|
+
data: { message }
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const diffs = await this.getUpdatesForEntity(entity, inboundData);
|
|
54
|
+
if (Object.getOwnPropertyNames(diffs).length == 0) {
|
|
55
|
+
const message = 'No Changes to persist for entity: ' + entity.id;
|
|
56
|
+
console.log(message);
|
|
57
|
+
return {
|
|
58
|
+
status: 200,
|
|
59
|
+
data: { message }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return this.updateEntity(this.baseType, entity, diffs);
|
|
63
|
+
}
|
|
64
|
+
async handleIncomingDelete(event) {
|
|
65
|
+
console.warn('delete is not configured', event);
|
|
66
|
+
}
|
|
67
|
+
async getTransformedData(event) {
|
|
68
|
+
let inboundData = event.data;
|
|
69
|
+
console.debug('inboundData: ' + JSON.stringify(inboundData));
|
|
70
|
+
const objectClass = event.objectClass;
|
|
71
|
+
inboundData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, objectClass, 'flex2vibe');
|
|
72
|
+
console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
|
|
73
|
+
return inboundData;
|
|
74
|
+
}
|
|
75
|
+
async getUpdatesForEntity(entity, inboundData) {
|
|
76
|
+
const vibeOwningKeys = await this.getVibeOwningKeys(entity);
|
|
77
|
+
let updates = {
|
|
78
|
+
typeId: entity.typeId,
|
|
79
|
+
roles: entity.roles,
|
|
80
|
+
id: entity.id,
|
|
81
|
+
};
|
|
82
|
+
updates = await this.dc.setEntityValues(entity, inboundData, vibeOwningKeys);
|
|
83
|
+
for (const prop of ['typeId', 'roles', 'id']) {
|
|
84
|
+
delete updates[prop];
|
|
85
|
+
}
|
|
86
|
+
return this.dc.getPersistableChanges(entity, updates);
|
|
87
|
+
}
|
|
88
|
+
async getVibeOwningKeys(entity) {
|
|
89
|
+
let vibeOwningKeys = [];
|
|
90
|
+
if (this.transformMapFile) {
|
|
91
|
+
const wholeMap = await this.mapFileUtil.getMapFile(this.transformMapFile);
|
|
92
|
+
const objClass = this.dc.getMappingClass(entity, wholeMap);
|
|
93
|
+
vibeOwningKeys = wholeMap?.[objClass]?.vibeOwningKeys || [];
|
|
94
|
+
}
|
|
95
|
+
console.debug('vibeOwningKeys: ' + vibeOwningKeys);
|
|
96
|
+
return vibeOwningKeys;
|
|
97
|
+
}
|
|
98
|
+
async updateEntity(entityName, entity, diffs) {
|
|
99
|
+
const options = {
|
|
100
|
+
entityName: entityName,
|
|
101
|
+
id: entity['id'],
|
|
102
|
+
object: diffs
|
|
103
|
+
};
|
|
104
|
+
console.log('options: ' + JSON.stringify(options));
|
|
105
|
+
return await new sdk_1.Entities().update(options);
|
|
106
|
+
}
|
|
107
|
+
async outbound(event) {
|
|
108
|
+
const entityType = event.entityType;
|
|
109
|
+
const eventType = event.eventType;
|
|
110
|
+
const entityId = event.id;
|
|
111
|
+
console.log(`outbound: ${entityType}:${entityId}`);
|
|
112
|
+
switch (eventType) {
|
|
113
|
+
case 'update':
|
|
114
|
+
case 'create':
|
|
115
|
+
return await this.handleOutgoingUpsert(entityType, event);
|
|
116
|
+
case 'delete':
|
|
117
|
+
return await this.handleOutgoingDelete(entityType, event);
|
|
118
|
+
default:
|
|
119
|
+
console.log(UNSUPPORTED_TYPE);
|
|
120
|
+
return {
|
|
121
|
+
status: 500,
|
|
122
|
+
data: { UNSUPPORTED_TYPE }
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async handleOutgoingUpsert(entityType, event) {
|
|
127
|
+
const objectClass = this.typeUtil.getEventObjectClass(entityType, event.newData);
|
|
128
|
+
if (!objectClass) {
|
|
129
|
+
const message = 'ObjectClass must have a value.';
|
|
130
|
+
console.log(message);
|
|
131
|
+
return {
|
|
132
|
+
status: 500,
|
|
133
|
+
data: { message }
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const payload = await this.getOutgoingUpsertPayload(entityType, event);
|
|
137
|
+
return await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
138
|
+
}
|
|
139
|
+
async handleOutgoingDelete(entityType, event) {
|
|
140
|
+
console.warn('delete is not configured', entityType, event.oldData);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.BaseEntityProcessor = BaseEntityProcessor;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -24,3 +24,5 @@ __exportStar(require("./util/interfaces"), exports);
|
|
|
24
24
|
__exportStar(require("./util/logger-config"), exports);
|
|
25
25
|
__exportStar(require("./util/thumbnail-util"), exports);
|
|
26
26
|
__exportStar(require("./util/type-utils"), exports);
|
|
27
|
+
__exportStar(require("./util/map-utils"), exports);
|
|
28
|
+
__exportStar(require("./entity-processor/base-entity-processor"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapUtil = void 0;
|
|
4
|
+
const transform_data_1 = require("@contrail/transform-data");
|
|
5
|
+
class MapUtil {
|
|
6
|
+
static async applyTransformMap(transformMapFile, mapFileUtil, data, type, direction) {
|
|
7
|
+
if (transformMapFile) {
|
|
8
|
+
const mapping = await mapFileUtil.getMappingSection(transformMapFile, type, direction);
|
|
9
|
+
if (mapping) {
|
|
10
|
+
const tasks = transform_data_1.MapFileUtil.getTransformTasks(mapping);
|
|
11
|
+
if (tasks.length > 0) {
|
|
12
|
+
const convertedArray = transform_data_1.TransformProcessor.transformData([data], tasks);
|
|
13
|
+
data = convertedArray[0];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.MapUtil = MapUtil;
|