@contrail/flexplm 1.0.9 → 1.0.11
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/lib/package.json +46 -0
- package/package.json +1 -1
- package/lib/flexplm-request.d.ts +0 -3
- package/lib/flexplm-request.js +0 -34
- package/lib/flexplm-utils.d.ts +0 -5
- package/lib/flexplm-utils.js +0 -33
- package/lib/index.d.ts +0 -10
- package/lib/index.js +0 -26
- package/lib/util/config-defaults.d.ts +0 -6
- package/lib/util/config-defaults.js +0 -71
- package/lib/util/data-converter.d.ts +0 -22
- package/lib/util/data-converter.js +0 -318
- package/lib/util/federation.d.ts +0 -15
- package/lib/util/federation.js +0 -149
- package/lib/util/flexplm-connect.d.ts +0 -16
- package/lib/util/flexplm-connect.js +0 -130
- package/lib/util/interfaces.d.ts +0 -91
- package/lib/util/interfaces.js +0 -2
- package/lib/util/logger-config.d.ts +0 -1
- package/lib/util/logger-config.js +0 -26
- package/lib/util/mockData.d.ts +0 -39
- package/lib/util/mockData.js +0 -100
- package/lib/util/thumbnail-util.d.ts +0 -15
- package/lib/util/thumbnail-util.js +0 -112
- package/lib/util/type-utils.d.ts +0 -12
- package/lib/util/type-utils.js +0 -101
package/lib/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contrail/flexplm",
|
|
3
|
+
"version": "1.0.10",
|
|
4
|
+
"description": "Library used for integration with flexplm.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
10
|
+
"lint": "tslint -p tsconfig.json",
|
|
11
|
+
"test": "jest"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/jest": "^29.5.2",
|
|
18
|
+
"jest": "^29.5.0",
|
|
19
|
+
"prettier": "^1.19.1",
|
|
20
|
+
"ts-jest": "^29.1.1",
|
|
21
|
+
"tslint": "^5.11.0",
|
|
22
|
+
"tslint-config-prettier": "^1.18.0",
|
|
23
|
+
"typescript": "^4.0.0"
|
|
24
|
+
},
|
|
25
|
+
"jest": {
|
|
26
|
+
"moduleFileExtensions": [
|
|
27
|
+
"js",
|
|
28
|
+
"json",
|
|
29
|
+
"ts"
|
|
30
|
+
],
|
|
31
|
+
"rootDir": "src",
|
|
32
|
+
"testRegex": ".spec.ts$",
|
|
33
|
+
"transform": {
|
|
34
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
35
|
+
},
|
|
36
|
+
"coverageDirectory": "../coverage",
|
|
37
|
+
"testEnvironment": "node"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@contrail/app-framework": "^1.2.0",
|
|
41
|
+
"@contrail/sdk": "^1.2.11",
|
|
42
|
+
"@contrail/transform-data": "^1.0.8",
|
|
43
|
+
"axios": "^1.4.0",
|
|
44
|
+
"p-limit": "^3.1.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/package.json
CHANGED
package/lib/flexplm-request.d.ts
DELETED
package/lib/flexplm-request.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FlexPLMRequest = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const BASE_URL = 'https://PP-2006031951wo.portal.ptc.io/Windchill/servlet/rest/cdee';
|
|
9
|
-
const BASE_CONFIG = {
|
|
10
|
-
method: 'POST',
|
|
11
|
-
headers: {
|
|
12
|
-
'Accept': 'application/json',
|
|
13
|
-
'Content-Type': 'application/json',
|
|
14
|
-
'CSRF_NONCE': '2OaLp+0dWNBtrkTwtdDC491zaacu6Hykvqi/lpl6bZgJ/QXBrK/B1J5FErMkmAmktr/I3thcbO1Xn3HJ7Ne/l9kpaedUmn7H75Xey4ZbNLsenW+anM3vxIZ7ELosk3k=',
|
|
15
|
-
'Authorization': 'Basic d2NhZG1pbjpSZXRhaWwyMDIwLQ==',
|
|
16
|
-
'Cookie': 'JSESSIONID=36D5B3C74C1F963C6C73E9AF5B6BDA78.tomcat1; JSESSIONID=B8090C802D8548EA773C97F5886FAB79.tomcat1',
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
class FlexPLMRequest {
|
|
20
|
-
static async request(path, data) {
|
|
21
|
-
const config = Object.assign({}, BASE_CONFIG);
|
|
22
|
-
config.url = BASE_URL + path;
|
|
23
|
-
config.data = data;
|
|
24
|
-
try {
|
|
25
|
-
const resp = await (0, axios_1.default)(config);
|
|
26
|
-
return Promise.resolve(resp.data);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error(`${FlexPLMRequest} error: ${error.message}`);
|
|
30
|
-
return Promise.resolve(null);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.FlexPLMRequest = FlexPLMRequest;
|
package/lib/flexplm-utils.d.ts
DELETED
package/lib/flexplm-utils.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlexPLMUtils = void 0;
|
|
4
|
-
class FlexPLMUtils {
|
|
5
|
-
static computeLevelFromPath(path) {
|
|
6
|
-
return (path.match(/:/g) || []).length + 1;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
exports.FlexPLMUtils = FlexPLMUtils;
|
|
10
|
-
FlexPLMUtils.convertTypePath = (path) => {
|
|
11
|
-
if (!path) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
let newPath = path;
|
|
15
|
-
while (newPath.indexOf('\\') > 1) {
|
|
16
|
-
newPath = newPath.replace('\\', ':');
|
|
17
|
-
}
|
|
18
|
-
while (newPath.indexOf('[') > 1) {
|
|
19
|
-
newPath = newPath.replace('[', '*');
|
|
20
|
-
}
|
|
21
|
-
while (newPath.indexOf(']') > 1) {
|
|
22
|
-
newPath = newPath.replace(']', '*');
|
|
23
|
-
}
|
|
24
|
-
while (newPath.indexOf(' ') > 1) {
|
|
25
|
-
newPath = newPath.replace(' ', '_');
|
|
26
|
-
}
|
|
27
|
-
newPath = newPath.toLowerCase();
|
|
28
|
-
return newPath;
|
|
29
|
-
};
|
|
30
|
-
FlexPLMUtils.getParentTypePath = (path) => {
|
|
31
|
-
const newPath = FlexPLMUtils.convertTypePath(path);
|
|
32
|
-
return (!newPath || newPath.indexOf(':') < 0) ? null : newPath.substring(0, newPath.lastIndexOf(':'));
|
|
33
|
-
};
|
package/lib/index.d.ts
DELETED
|
@@ -1,10 +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/federation';
|
|
6
|
-
export * from './util/flexplm-connect';
|
|
7
|
-
export * from './util/interfaces';
|
|
8
|
-
export * from './util/logger-config';
|
|
9
|
-
export * from './util/thumbnail-util';
|
|
10
|
-
export * from './util/type-utils';
|
package/lib/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./flexplm-request"), exports);
|
|
18
|
-
__exportStar(require("./flexplm-utils"), exports);
|
|
19
|
-
__exportStar(require("./util/config-defaults"), exports);
|
|
20
|
-
__exportStar(require("./util/data-converter"), exports);
|
|
21
|
-
__exportStar(require("./util/federation"), exports);
|
|
22
|
-
__exportStar(require("./util/flexplm-connect"), exports);
|
|
23
|
-
__exportStar(require("./util/interfaces"), exports);
|
|
24
|
-
__exportStar(require("./util/logger-config"), exports);
|
|
25
|
-
__exportStar(require("./util/thumbnail-util"), exports);
|
|
26
|
-
__exportStar(require("./util/type-utils"), exports);
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigDefaults = void 0;
|
|
4
|
-
const sdk_1 = require("@contrail/sdk");
|
|
5
|
-
const util_1 = require("@contrail/util");
|
|
6
|
-
class ConfigDefaults {
|
|
7
|
-
static async setConfigDefaults(config) {
|
|
8
|
-
if (!config.apiHost || !config.userName || !config.password) {
|
|
9
|
-
throw new Error(ConfigDefaults.NEED_CONFIG_VALUES);
|
|
10
|
-
}
|
|
11
|
-
if (config?.itemPreDevelopmentLifecycleStages && !(config?.itemPreDevelopmentLifecycleStages instanceof Array)) {
|
|
12
|
-
config.itemPreDevelopmentLifecycleStages = config.itemPreDevelopmentLifecycleStages.split(',');
|
|
13
|
-
}
|
|
14
|
-
const defaultConfig = {
|
|
15
|
-
urlContext: '/Windchill',
|
|
16
|
-
sendMode: {
|
|
17
|
-
ASYNC_PUBLISH_SEASON: 'vibeiqfile'
|
|
18
|
-
},
|
|
19
|
-
itemPreDevelopmentLifecycleStages: ['concept'],
|
|
20
|
-
identifierAtts: {
|
|
21
|
-
LCSProduct: ['itemNumber'],
|
|
22
|
-
LCSSeason: ['flexPLMSeasonName'],
|
|
23
|
-
LCSSKU: ['itemNumber']
|
|
24
|
-
},
|
|
25
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
26
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
27
|
-
payloadDefaultAsArray: true
|
|
28
|
-
};
|
|
29
|
-
const configArr = [defaultConfig];
|
|
30
|
-
if (config.configFile) {
|
|
31
|
-
const fileConfig = await ConfigDefaults.getConfigFile(config.configFile);
|
|
32
|
-
configArr.push(fileConfig);
|
|
33
|
-
}
|
|
34
|
-
configArr.push(config);
|
|
35
|
-
const outputConfig = util_1.ObjectUtil.mergeDeep({}, ...configArr);
|
|
36
|
-
const uName = outputConfig.userName;
|
|
37
|
-
const pass = outputConfig.password;
|
|
38
|
-
outputConfig.userName = () => uName;
|
|
39
|
-
outputConfig.password = () => pass;
|
|
40
|
-
outputConfig['OOBvibeEventEndpoint'] = '/rfa/vibeiq/vibeEvents';
|
|
41
|
-
console.log('outputConfig: ' + JSON.stringify(outputConfig));
|
|
42
|
-
return outputConfig;
|
|
43
|
-
}
|
|
44
|
-
static async getConfigFile(fileId) {
|
|
45
|
-
try {
|
|
46
|
-
const options = {
|
|
47
|
-
entityName: 'file',
|
|
48
|
-
id: fileId,
|
|
49
|
-
};
|
|
50
|
-
const file = await new sdk_1.Entities().get(options);
|
|
51
|
-
if (!file) {
|
|
52
|
-
console.log('failed to find file with id: ' + fileId);
|
|
53
|
-
return {};
|
|
54
|
-
}
|
|
55
|
-
const downloadUrl = file['downloadUrl'];
|
|
56
|
-
if (!downloadUrl) {
|
|
57
|
-
console.log('file didnt have downloadUrl. fileId: ' + fileId);
|
|
58
|
-
return {};
|
|
59
|
-
}
|
|
60
|
-
const response = await fetch(downloadUrl);
|
|
61
|
-
const config = await response.json();
|
|
62
|
-
return config ? config : {};
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
console.log('Error getting config file: ' + fileId + '- ' + e.message);
|
|
66
|
-
return {};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.ConfigDefaults = ConfigDefaults;
|
|
71
|
-
ConfigDefaults.NEED_CONFIG_VALUES = 'To connect to FlexPLM all these APP values need to be set apiHost, userName, and password';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { FCConfig } from './interfaces';
|
|
2
|
-
import { MapFileUtil } from '@contrail/transform-data';
|
|
3
|
-
export declare class DataConverter {
|
|
4
|
-
private config;
|
|
5
|
-
private mapFileUtil;
|
|
6
|
-
private typeUtils;
|
|
7
|
-
private transformMapFile;
|
|
8
|
-
private useDisplayForEnumerationMatching;
|
|
9
|
-
private objRefCache;
|
|
10
|
-
constructor(config: FCConfig, mapFileUtil: MapFileUtil);
|
|
11
|
-
getFlexPLMObjectDataFromEvent(event: any, dataToSkip: string[]): Promise<{}>;
|
|
12
|
-
getFlexPLMObjectData(newData: any, dataToSkip: string[], expandObjRef: boolean): Promise<{}>;
|
|
13
|
-
getFlexPLMValue(prop: any, newData: any, expandObjRef: boolean): Promise<any>;
|
|
14
|
-
getEnumerationValue(prop: any, nd: any): any;
|
|
15
|
-
getObjectReferenceValue(prop: any, newData: any, expandObjRef?: boolean): Promise<any>;
|
|
16
|
-
getMappingClass(entity: object, mapping: any): string;
|
|
17
|
-
setEntityValues(entity: any, data: any, keysToSkip?: string[]): Promise<any>;
|
|
18
|
-
getEntityValues(objectClass: string, data: any, keysToSkip?: string[]): Promise<{}>;
|
|
19
|
-
getEntityValue(prop: any, data: any): Promise<any>;
|
|
20
|
-
setEnumerationKeys(prop: any, nd: any, matchByDisplay: any): any;
|
|
21
|
-
getPersistableChanges(entity: object, changes: object): object;
|
|
22
|
-
}
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataConverter = void 0;
|
|
4
|
-
const sdk_1 = require("@contrail/sdk");
|
|
5
|
-
const type_utils_1 = require("./type-utils");
|
|
6
|
-
const transform_data_1 = require("@contrail/transform-data");
|
|
7
|
-
const app_framework_1 = require("@contrail/app-framework");
|
|
8
|
-
const util_1 = require("@contrail/util");
|
|
9
|
-
class DataConverter {
|
|
10
|
-
constructor(config, mapFileUtil) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.mapFileUtil = mapFileUtil;
|
|
13
|
-
this.useDisplayForEnumerationMatching = false;
|
|
14
|
-
this.objRefCache = {};
|
|
15
|
-
this.typeUtils = new type_utils_1.TypeUtils();
|
|
16
|
-
this.transformMapFile = this.config['transformMapFile'];
|
|
17
|
-
this.useDisplayForEnumerationMatching = this.config['dataConverter']
|
|
18
|
-
&& this.config['dataConverter']['useDisplayForEnumerationMatching'];
|
|
19
|
-
}
|
|
20
|
-
async getFlexPLMObjectDataFromEvent(event, dataToSkip) {
|
|
21
|
-
return this.getFlexPLMObjectData(event.newData, dataToSkip, true);
|
|
22
|
-
}
|
|
23
|
-
async getFlexPLMObjectData(newData, dataToSkip, expandObjRef) {
|
|
24
|
-
if (app_framework_1.Logger.isDebugOn()) {
|
|
25
|
-
console.debug('newData: ' + JSON.stringify(newData));
|
|
26
|
-
}
|
|
27
|
-
dataToSkip = dataToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'workspaceId']);
|
|
28
|
-
const data = {};
|
|
29
|
-
const typeId = newData?.typeId;
|
|
30
|
-
if (!typeId) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
data['typePath'] = newData['typePath'];
|
|
34
|
-
const type = await this.typeUtils.getTypeById(typeId);
|
|
35
|
-
const typeProps = this.typeUtils.filterTypeProperties(type, newData);
|
|
36
|
-
for (const prop of typeProps) {
|
|
37
|
-
const slug = prop['slug'];
|
|
38
|
-
if (dataToSkip.includes(slug)) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
data[slug] = await this.getFlexPLMValue(prop, newData, expandObjRef);
|
|
42
|
-
}
|
|
43
|
-
if (app_framework_1.Logger.isDebugOn()) {
|
|
44
|
-
console.debug('getFlexPLMObjectData-data: ' + JSON.stringify(data));
|
|
45
|
-
}
|
|
46
|
-
return data;
|
|
47
|
-
}
|
|
48
|
-
async getFlexPLMValue(prop, newData, expandObjRef) {
|
|
49
|
-
const propertyType = prop['propertyType'];
|
|
50
|
-
const slug = prop['slug'];
|
|
51
|
-
const nd = newData[slug];
|
|
52
|
-
let value;
|
|
53
|
-
if (['string', 'text'].includes(propertyType)) {
|
|
54
|
-
value = nd || '';
|
|
55
|
-
}
|
|
56
|
-
else if (['number', 'currency', 'percent', 'sequence'].includes(propertyType)) {
|
|
57
|
-
value = nd || 0;
|
|
58
|
-
}
|
|
59
|
-
else if ('date' === propertyType) {
|
|
60
|
-
if (nd) {
|
|
61
|
-
value = nd;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
value = null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else if ('boolean' === propertyType) {
|
|
68
|
-
value = (nd) ? true : false;
|
|
69
|
-
}
|
|
70
|
-
else if ('choice' === propertyType) {
|
|
71
|
-
value = this.getEnumerationValue(prop, nd);
|
|
72
|
-
}
|
|
73
|
-
else if ('multi_select' === propertyType) {
|
|
74
|
-
value = this.getEnumerationValue(prop, nd);
|
|
75
|
-
}
|
|
76
|
-
else if ('object_reference' === propertyType) {
|
|
77
|
-
value = await this.getObjectReferenceValue(prop, newData, expandObjRef);
|
|
78
|
-
if (app_framework_1.Logger.isDebugOn()) {
|
|
79
|
-
console.debug('object_reference: ' + JSON.stringify(value));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else if ('image' === propertyType) {
|
|
83
|
-
}
|
|
84
|
-
else if ('formula' === propertyType) {
|
|
85
|
-
value = nd;
|
|
86
|
-
}
|
|
87
|
-
else if ('json' === propertyType) {
|
|
88
|
-
value = nd;
|
|
89
|
-
}
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
|
-
getEnumerationValue(prop, nd) {
|
|
93
|
-
const propertyType = prop['propertyType'];
|
|
94
|
-
let value;
|
|
95
|
-
if (['choice', 'multi_select'].includes(propertyType)) {
|
|
96
|
-
const options = prop['options'];
|
|
97
|
-
if ('choice' === propertyType) {
|
|
98
|
-
if (nd) {
|
|
99
|
-
const option = options.find(option => option.value == nd);
|
|
100
|
-
if (option) {
|
|
101
|
-
value = Object.assign({}, option);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
value = {};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else if ('multi_select' === propertyType) {
|
|
109
|
-
value = [];
|
|
110
|
-
if (nd instanceof Array) {
|
|
111
|
-
nd.forEach(key => {
|
|
112
|
-
const optionObject = options.find(option => option.value == key);
|
|
113
|
-
if (optionObject) {
|
|
114
|
-
const option = Object.assign({}, optionObject);
|
|
115
|
-
value.push(option);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
else if (typeof nd === 'string' && '' !== nd) {
|
|
120
|
-
const optionObject = options.find(option => option.value == nd);
|
|
121
|
-
if (optionObject) {
|
|
122
|
-
const option = Object.assign({}, optionObject);
|
|
123
|
-
value.push(option);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return value;
|
|
129
|
-
}
|
|
130
|
-
async getObjectReferenceValue(prop, newData, expandObjRef = false) {
|
|
131
|
-
const slug = prop['slug'];
|
|
132
|
-
console.debug('getObjectReferenceValue-prop: ' + slug);
|
|
133
|
-
let value = newData[slug];
|
|
134
|
-
const entityType = prop['referencedTypeRootSlug'];
|
|
135
|
-
const entityId = newData[slug + 'Id'];
|
|
136
|
-
if (!value && expandObjRef) {
|
|
137
|
-
if (entityId) {
|
|
138
|
-
if (this.objRefCache[entityId]) {
|
|
139
|
-
console.log('cache hit: ' + entityId);
|
|
140
|
-
return this.objRefCache[entityId];
|
|
141
|
-
}
|
|
142
|
-
const criteria = {
|
|
143
|
-
id: entityId
|
|
144
|
-
};
|
|
145
|
-
const entities = await new sdk_1.Entities().get({
|
|
146
|
-
entityName: entityType,
|
|
147
|
-
criteria
|
|
148
|
-
});
|
|
149
|
-
value = (entities && entities[0]) ? entities[0] : undefined;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (value) {
|
|
153
|
-
const unprocessedValue = value;
|
|
154
|
-
const objectClass = this.typeUtils.getEventObjectClass(entityType, newData);
|
|
155
|
-
value = await this.getFlexPLMObjectData(value, [], false);
|
|
156
|
-
value['entityReference'] = entityType + ':' + entityId;
|
|
157
|
-
value['objectClass'] = objectClass;
|
|
158
|
-
value['typePath'] = unprocessedValue['typePath'];
|
|
159
|
-
if (this.transformMapFile) {
|
|
160
|
-
const wholeMap = await this.mapFileUtil.getMapFile(this.transformMapFile);
|
|
161
|
-
const objClass = this.getMappingClass(unprocessedValue, wholeMap);
|
|
162
|
-
const mapping = await this.mapFileUtil.getMappingSection(this.transformMapFile, objClass, 'vibe2flex');
|
|
163
|
-
if (mapping) {
|
|
164
|
-
const tasks = transform_data_1.MapFileUtil.getTransformTasks(mapping);
|
|
165
|
-
if (tasks.length > 0) {
|
|
166
|
-
const convertedArray = transform_data_1.TransformProcessor.transformData([value], tasks);
|
|
167
|
-
value = convertedArray[0];
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
value = {};
|
|
174
|
-
}
|
|
175
|
-
this.objRefCache[entityId] = value;
|
|
176
|
-
return value;
|
|
177
|
-
}
|
|
178
|
-
getMappingClass(entity, mapping) {
|
|
179
|
-
const entityTypePath = entity['typePath'];
|
|
180
|
-
const typeMapKey = mapping['typeMapKey'];
|
|
181
|
-
let objClass = typeMapKey[entityTypePath];
|
|
182
|
-
const entityType = entity['entityType'];
|
|
183
|
-
if (!objClass) {
|
|
184
|
-
objClass = this.typeUtils.getEventObjectClass(entityType, entity);
|
|
185
|
-
}
|
|
186
|
-
if (!objClass) {
|
|
187
|
-
objClass = entityType;
|
|
188
|
-
}
|
|
189
|
-
return objClass;
|
|
190
|
-
}
|
|
191
|
-
async setEntityValues(entity, data, keysToSkip = []) {
|
|
192
|
-
const type = await this.typeUtils.getTypeById(entity.typeId);
|
|
193
|
-
keysToSkip = keysToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'workspaceId']);
|
|
194
|
-
let typeProps = this.typeUtils.filterTypeProperties(type, entity);
|
|
195
|
-
typeProps = typeProps.filter(prop => !keysToSkip.includes(prop['slug']));
|
|
196
|
-
const dataKeys = Object.getOwnPropertyNames(data);
|
|
197
|
-
typeProps = typeProps.filter(prop => dataKeys.includes(prop['slug']));
|
|
198
|
-
for (const prop of typeProps) {
|
|
199
|
-
const slug = prop['slug'];
|
|
200
|
-
entity[slug] = await this.getEntityValue(prop, data);
|
|
201
|
-
}
|
|
202
|
-
return entity;
|
|
203
|
-
}
|
|
204
|
-
async getEntityValues(objectClass, data, keysToSkip = []) {
|
|
205
|
-
const entityValues = {};
|
|
206
|
-
const tco = this.typeUtils.getEntityTypeClientOptions(objectClass, data);
|
|
207
|
-
const type = await this.typeUtils.getByRootAndPath(tco);
|
|
208
|
-
const typePath = type['typePath'];
|
|
209
|
-
if (typePath && (typePath.startsWith('item') || typePath.startsWith('project-item'))) {
|
|
210
|
-
if (['LCSProduct', 'LCSProductSeasonLink'].includes(objectClass)) {
|
|
211
|
-
entityValues['roles'] = ['family'];
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
entityValues['roles'] = ['color', 'option'];
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
let typeProps = this.typeUtils.filterTypeProperties(type, entityValues);
|
|
218
|
-
typeProps = typeProps.filter(prop => !keysToSkip.includes(prop['slug']));
|
|
219
|
-
for (const prop of typeProps) {
|
|
220
|
-
const slug = prop['slug'];
|
|
221
|
-
const value = await this.getEntityValue(prop, data);
|
|
222
|
-
if (value) {
|
|
223
|
-
entityValues[slug] = value;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return entityValues;
|
|
227
|
-
}
|
|
228
|
-
async getEntityValue(prop, data) {
|
|
229
|
-
const propertyType = prop['propertyType'];
|
|
230
|
-
const slug = prop['slug'];
|
|
231
|
-
const nd = data[slug];
|
|
232
|
-
let value;
|
|
233
|
-
if (['string', 'text'].includes(propertyType)) {
|
|
234
|
-
value = nd;
|
|
235
|
-
}
|
|
236
|
-
else if (['number', 'currency', 'percent', 'sequence'].includes(propertyType)) {
|
|
237
|
-
value = (null === nd) ? 0 : nd;
|
|
238
|
-
}
|
|
239
|
-
else if ('date' === propertyType) {
|
|
240
|
-
if (nd) {
|
|
241
|
-
const d = new Date(nd);
|
|
242
|
-
value = d.toISOString();
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
value = null;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
else if ('boolean' === propertyType) {
|
|
249
|
-
value = (nd) ? true : false;
|
|
250
|
-
}
|
|
251
|
-
else if ('choice' === propertyType) {
|
|
252
|
-
value = this.setEnumerationKeys(prop, nd, this.useDisplayForEnumerationMatching);
|
|
253
|
-
}
|
|
254
|
-
else if ('multi_select' === propertyType) {
|
|
255
|
-
value = this.setEnumerationKeys(prop, nd, this.useDisplayForEnumerationMatching);
|
|
256
|
-
}
|
|
257
|
-
else if ('object_reference' === propertyType) {
|
|
258
|
-
}
|
|
259
|
-
else if ('image' === propertyType) {
|
|
260
|
-
console.log('TODO');
|
|
261
|
-
}
|
|
262
|
-
else if ('formula' === propertyType) {
|
|
263
|
-
console.log('TODO');
|
|
264
|
-
}
|
|
265
|
-
else if ('json' === propertyType) {
|
|
266
|
-
console.log('TODO');
|
|
267
|
-
}
|
|
268
|
-
return value;
|
|
269
|
-
}
|
|
270
|
-
setEnumerationKeys(prop, nd, matchByDisplay) {
|
|
271
|
-
const propertyType = prop['propertyType'];
|
|
272
|
-
let value;
|
|
273
|
-
if (['choice', 'multi_select'].includes(propertyType)) {
|
|
274
|
-
const options = prop['options'];
|
|
275
|
-
if ('choice' === propertyType) {
|
|
276
|
-
if (nd) {
|
|
277
|
-
const matchKey = (matchByDisplay) ? 'display' : 'value';
|
|
278
|
-
const option = options.find(option => option[matchKey] == nd[matchKey]);
|
|
279
|
-
if (option) {
|
|
280
|
-
value = option.value;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
value = undefined;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else if ('multi_select' === propertyType) {
|
|
288
|
-
value = [];
|
|
289
|
-
const matchKey = (matchByDisplay) ? 'display' : 'value';
|
|
290
|
-
if (nd instanceof Array) {
|
|
291
|
-
nd.forEach(selectedOpt => {
|
|
292
|
-
const optionObject = options.find(option => option[matchKey] == selectedOpt[matchKey]);
|
|
293
|
-
if (optionObject) {
|
|
294
|
-
const option = optionObject.value;
|
|
295
|
-
value.push(option);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return value;
|
|
302
|
-
}
|
|
303
|
-
getPersistableChanges(entity, changes) {
|
|
304
|
-
const entityCompareValues = {};
|
|
305
|
-
for (const key of (Object.getOwnPropertyNames(changes))) {
|
|
306
|
-
entityCompareValues[key] = entity[key];
|
|
307
|
-
}
|
|
308
|
-
const diffs = util_1.ObjectUtil.compareDeep(entityCompareValues, changes, '');
|
|
309
|
-
const diffValues = {};
|
|
310
|
-
if (diffs && diffs.length > 0) {
|
|
311
|
-
for (const diff of diffs) {
|
|
312
|
-
diffValues[diff.propertyName] = diff.newValue;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return diffValues;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
exports.DataConverter = DataConverter;
|
package/lib/util/federation.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { FederationRecord } from './interfaces';
|
|
2
|
-
export declare class Federation {
|
|
3
|
-
private CHUNK_SIZE;
|
|
4
|
-
getFederatedMappedRefId(entityType: string, entityId: string): Promise<string>;
|
|
5
|
-
createFederatedRecord(eventBody: any): Promise<any>;
|
|
6
|
-
getFederationRecordFromMappedRefId(mappedRefId: string): Promise<FederationRecord>;
|
|
7
|
-
static getEntityId(fedRecord: FederationRecord): {
|
|
8
|
-
entityType: string;
|
|
9
|
-
entityId: string;
|
|
10
|
-
};
|
|
11
|
-
getEntityFromMappedRefId(mappedRefId: string): Promise<any>;
|
|
12
|
-
getFederationRecordsFromIds(ids: string[]): Promise<FederationRecord[]>;
|
|
13
|
-
getFederationRecordsFromIdsBulk(ids: string[]): Promise<FederationRecord[]>;
|
|
14
|
-
splitIntoChunksByLen(arr: any, len: any): any[];
|
|
15
|
-
}
|