@contrail/flexplm 1.2.0-alpha.0 → 1.3.0-alpha.0
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/package.json +1 -1
- package/scripts/output.png +0 -0
- package/scripts/test-get-request.ts +35 -0
- package/src/util/flexplm-connect.spec.ts +132 -0
- package/src/util/flexplm-connect.ts +14 -5
- package/src/util/type-conversion-utils-spec-mockData.ts +18 -0
- package/src/util/type-conversion-utils.spec.ts +184 -0
- package/src/util/type-conversion-utils.ts +74 -0
- package/lib/entity-processor/base-entity-processor.d.ts +0 -42
- package/lib/entity-processor/base-entity-processor.js +0 -363
- package/lib/entity-processor/base-entity-processor.spec.d.ts +0 -1
- package/lib/entity-processor/base-entity-processor.spec.js +0 -302
- 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/flexplm-utils.spec.d.ts +0 -1
- package/lib/flexplm-utils.spec.js +0 -26
- package/lib/index.d.ts +0 -22
- package/lib/index.js +0 -38
- package/lib/interfaces/interfaces.d.ts +0 -105
- package/lib/interfaces/interfaces.js +0 -2
- package/lib/interfaces/item-family-changes.d.ts +0 -20
- package/lib/interfaces/item-family-changes.js +0 -56
- package/lib/interfaces/publish-change-data.d.ts +0 -19
- package/lib/interfaces/publish-change-data.js +0 -32
- package/lib/publish/base-process-publish-assortment-callback.d.ts +0 -9
- package/lib/publish/base-process-publish-assortment-callback.js +0 -38
- package/lib/publish/base-process-publish-assortment.d.ts +0 -93
- package/lib/publish/base-process-publish-assortment.js +0 -944
- package/lib/publish/base-process-publish-assortment.spec.d.ts +0 -1
- package/lib/publish/base-process-publish-assortment.spec.js +0 -1670
- package/lib/publish/mockData.d.ts +0 -1389
- package/lib/publish/mockData.js +0 -4519
- package/lib/transform/identifier-conversion-spec-mockData.d.ts +0 -0
- package/lib/transform/identifier-conversion-spec-mockData.js +0 -444
- package/lib/transform/identifier-conversion.d.ts +0 -15
- package/lib/transform/identifier-conversion.js +0 -212
- package/lib/transform/identifier-conversion.spec.d.ts +0 -1
- package/lib/transform/identifier-conversion.spec.js +0 -339
- package/lib/util/config-defaults.d.ts +0 -8
- package/lib/util/config-defaults.js +0 -85
- package/lib/util/config-defaults.spec.d.ts +0 -1
- package/lib/util/config-defaults.spec.js +0 -293
- package/lib/util/data-converter-spec-mockData.d.ts +0 -0
- package/lib/util/data-converter-spec-mockData.js +0 -205
- package/lib/util/data-converter.d.ts +0 -39
- package/lib/util/data-converter.js +0 -592
- package/lib/util/data-converter.spec.d.ts +0 -1
- package/lib/util/data-converter.spec.js +0 -904
- package/lib/util/error-response-object.d.ts +0 -4
- package/lib/util/error-response-object.js +0 -47
- package/lib/util/error-response-object.spec.d.ts +0 -1
- package/lib/util/error-response-object.spec.js +0 -99
- package/lib/util/event-short-message-status.d.ts +0 -18
- package/lib/util/event-short-message-status.js +0 -22
- package/lib/util/federation.d.ts +0 -15
- package/lib/util/federation.js +0 -149
- package/lib/util/flexplm-connect.d.ts +0 -18
- package/lib/util/flexplm-connect.js +0 -171
- package/lib/util/logger-config.d.ts +0 -1
- package/lib/util/logger-config.js +0 -26
- package/lib/util/map-util-spec-mockData.d.ts +0 -0
- package/lib/util/map-util-spec-mockData.js +0 -205
- package/lib/util/map-utils.d.ts +0 -6
- package/lib/util/map-utils.js +0 -15
- package/lib/util/map-utils.spec.d.ts +0 -1
- package/lib/util/map-utils.spec.js +0 -89
- package/lib/util/mockData.d.ts +0 -79
- package/lib/util/mockData.js +0 -99
- package/lib/util/thumbnail-util.d.ts +0 -19
- package/lib/util/thumbnail-util.js +0 -114
- package/lib/util/thumbnail-util.spec.d.ts +0 -1
- package/lib/util/thumbnail-util.spec.js +0 -242
- package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
- package/lib/util/type-conversion-utils-spec-mockData.js +0 -241
- package/lib/util/type-conversion-utils.d.ts +0 -21
- package/lib/util/type-conversion-utils.js +0 -223
- package/lib/util/type-conversion-utils.spec.d.ts +0 -1
- package/lib/util/type-conversion-utils.spec.js +0 -708
- package/lib/util/type-defaults.d.ts +0 -16
- package/lib/util/type-defaults.js +0 -221
- package/lib/util/type-defaults.spec.d.ts +0 -1
- package/lib/util/type-defaults.spec.js +0 -516
- package/lib/util/type-utils.d.ts +0 -13
- package/lib/util/type-utils.js +0 -114
- package/lib/util/type-utils.spec.d.ts +0 -1
- package/lib/util/type-utils.spec.js +0 -190
package/package.json
CHANGED
|
Binary file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { FlexPLMConnect } from '../src/util/flexplm-connect';
|
|
4
|
+
import { FCConfig } from '../src/interfaces/interfaces';
|
|
5
|
+
|
|
6
|
+
const config: FCConfig = {
|
|
7
|
+
apiHost: 'http://windchill.archergrey.com',
|
|
8
|
+
urlContext: '',
|
|
9
|
+
vibeEventEndpoint: '',
|
|
10
|
+
csrfEndpoint: '',
|
|
11
|
+
plmEnviornment: '',
|
|
12
|
+
userName: () => '', // fill in manually
|
|
13
|
+
password: () => '', // fill in manually
|
|
14
|
+
itemPreDevelopmentLifecycleStages: [],
|
|
15
|
+
payloadDefaultAsArray: true,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
async function main() {
|
|
19
|
+
const connect = new FlexPLMConnect(config);
|
|
20
|
+
const response = await connect.getRequest({
|
|
21
|
+
urlPath: '/Windchill/images/000001/000001/000001/cavkingcharlessmalldogs_medium_large-.-2965893984400.png',
|
|
22
|
+
includeUrlContext: false,
|
|
23
|
+
returnFullResponse: true,
|
|
24
|
+
}) as Response;
|
|
25
|
+
|
|
26
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
27
|
+
const outputPath = path.resolve(__dirname, 'output.png');
|
|
28
|
+
fs.writeFileSync(outputPath, buffer);
|
|
29
|
+
console.log(`Saved response to ${outputPath}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
main().catch((err) => {
|
|
33
|
+
console.error('Error:', err.message);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
|
|
2
|
+
import { FlexPLMConnect } from './flexplm-connect';
|
|
3
|
+
import { FCConfig } from '../interfaces/interfaces';
|
|
4
|
+
|
|
5
|
+
const mockJsonData = { items: [{ id: '123', name: 'test' }] };
|
|
6
|
+
|
|
7
|
+
const mockResponse = (status: number, json = mockJsonData) => ({
|
|
8
|
+
status,
|
|
9
|
+
json: jest.fn().mockResolvedValue(json),
|
|
10
|
+
text: jest.fn().mockResolvedValue('error text'),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const globalFetch = global.fetch;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
global.fetch = jest.fn().mockResolvedValue(mockResponse(200));
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterAll(() => {
|
|
20
|
+
global.fetch = globalFetch;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const createConfig = (overrides?: Partial<FCConfig>): FCConfig => ({
|
|
24
|
+
apiHost: 'https://flexplm.example.com',
|
|
25
|
+
urlContext: '/FlexPLM',
|
|
26
|
+
vibeEventEndpoint: '/api/events',
|
|
27
|
+
csrfEndpoint: '/csrf',
|
|
28
|
+
plmEnviornment: 'test',
|
|
29
|
+
userName: () => 'user',
|
|
30
|
+
password: () => 'pass',
|
|
31
|
+
itemPreDevelopmentLifecycleStages: [],
|
|
32
|
+
payloadDefaultAsArray: true,
|
|
33
|
+
...overrides,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('FlexPLMConnect.getRequest', () => {
|
|
37
|
+
|
|
38
|
+
it('should call default URL with urlContext when no params provided', async () => {
|
|
39
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
40
|
+
await connect.getRequest();
|
|
41
|
+
|
|
42
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
43
|
+
'https://flexplm.example.com/FlexPLM/servlet/rest/api/events',
|
|
44
|
+
expect.objectContaining({ method: 'GET' }),
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should use the constructor endpoint in the default URL', async () => {
|
|
49
|
+
const connect = new FlexPLMConnect(createConfig(), '/custom/endpoint');
|
|
50
|
+
await connect.getRequest();
|
|
51
|
+
|
|
52
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
53
|
+
'https://flexplm.example.com/FlexPLM/servlet/rest/custom/endpoint',
|
|
54
|
+
expect.any(Object),
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should return parsed JSON by default', async () => {
|
|
59
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
60
|
+
const result = await connect.getRequest();
|
|
61
|
+
expect(result).toEqual(mockJsonData);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should use urlPath when provided', async () => {
|
|
65
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
66
|
+
await connect.getRequest({ urlPath: '/custom/path' });
|
|
67
|
+
|
|
68
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
69
|
+
'https://flexplm.example.com/FlexPLM/custom/path',
|
|
70
|
+
expect.any(Object),
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should exclude urlContext when includeUrlContext is false', async () => {
|
|
75
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
76
|
+
await connect.getRequest({ includeUrlContext: false });
|
|
77
|
+
|
|
78
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
79
|
+
'https://flexplm.example.com/servlet/rest/api/events',
|
|
80
|
+
expect.any(Object),
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should exclude urlContext with custom urlPath', async () => {
|
|
85
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
86
|
+
await connect.getRequest({ urlPath: '/custom/path', includeUrlContext: false });
|
|
87
|
+
|
|
88
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
89
|
+
'https://flexplm.example.com/custom/path',
|
|
90
|
+
expect.any(Object),
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should return full response when returnFullResponse is true', async () => {
|
|
95
|
+
const rawResponse = mockResponse(200);
|
|
96
|
+
(global.fetch as jest.Mock).mockResolvedValue(rawResponse);
|
|
97
|
+
|
|
98
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
99
|
+
const result = await connect.getRequest({ returnFullResponse: true });
|
|
100
|
+
|
|
101
|
+
expect(result).toBe(rawResponse);
|
|
102
|
+
expect(rawResponse.json).not.toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should throw on status >= 300', async () => {
|
|
106
|
+
(global.fetch as jest.Mock).mockResolvedValue(mockResponse(404));
|
|
107
|
+
|
|
108
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
109
|
+
await expect(connect.getRequest()).rejects.toThrow('Error connecting to FlexPLM:status: 404');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should throw on status >= 300 even with returnFullResponse', async () => {
|
|
113
|
+
(global.fetch as jest.Mock).mockResolvedValue(mockResponse(500));
|
|
114
|
+
|
|
115
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
116
|
+
await expect(connect.getRequest({ returnFullResponse: true })).rejects.toThrow(
|
|
117
|
+
'Error connecting to FlexPLM:status: 500',
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should throw when response.json() fails', async () => {
|
|
122
|
+
const badResponse = {
|
|
123
|
+
status: 200,
|
|
124
|
+
json: jest.fn().mockRejectedValue(new Error('Invalid JSON')),
|
|
125
|
+
text: jest.fn().mockResolvedValue('not json'),
|
|
126
|
+
};
|
|
127
|
+
(global.fetch as jest.Mock).mockResolvedValue(badResponse);
|
|
128
|
+
|
|
129
|
+
const connect = new FlexPLMConnect(createConfig());
|
|
130
|
+
await expect(connect.getRequest()).rejects.toThrow('Error getting json data from FlexPLM: Invalid JSON');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -171,12 +171,18 @@ export class FlexPLMConnect {
|
|
|
171
171
|
return await this.processRequest(payload);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
/** Runs a
|
|
175
|
-
*
|
|
174
|
+
/** Runs a GET request to FlexPLM.
|
|
175
|
+
* @param params - Optional configuration for the request.
|
|
176
|
+
* @param params.urlPath - Custom URL path to use instead of the default `/servlet/rest` + endpoint.
|
|
177
|
+
* @param params.includeUrlContext - Whether to include the urlContext in the URL. Defaults to `true`.
|
|
178
|
+
* @param params.returnFullResponse - If `true`, returns the raw `Response` object instead of parsed JSON. Defaults to `false`.
|
|
179
|
+
* @returns The parsed JSON response body, or the raw `Response` object if `returnFullResponse` is `true`.
|
|
176
180
|
*/
|
|
177
|
-
async getRequest(){
|
|
178
|
-
const
|
|
179
|
-
const
|
|
181
|
+
async getRequest(params?: { urlPath?: string; includeUrlContext?: boolean; returnFullResponse?: boolean }): Promise<Response | unknown>{
|
|
182
|
+
const { urlPath, includeUrlContext = true, returnFullResponse = false } = params || {};
|
|
183
|
+
const urlContext = includeUrlContext ? this.config.urlContext : '';
|
|
184
|
+
const path = urlPath || ('/servlet/rest' + this.vibeEventEndpoint);
|
|
185
|
+
const vibeEventsURL: string = this.config.apiHost + urlContext + path;
|
|
180
186
|
const csrfOptions = this.getRequestOptions('GET');
|
|
181
187
|
const response = await fetch(vibeEventsURL, csrfOptions);
|
|
182
188
|
|
|
@@ -186,6 +192,9 @@ export class FlexPLMConnect {
|
|
|
186
192
|
console.error(await response.text());
|
|
187
193
|
throw new Error(message);
|
|
188
194
|
}
|
|
195
|
+
if(returnFullResponse){
|
|
196
|
+
return response;
|
|
197
|
+
}
|
|
189
198
|
try {
|
|
190
199
|
const data = await response.json();
|
|
191
200
|
return data;
|
|
@@ -142,6 +142,12 @@ exports.mapping = {
|
|
|
142
142
|
isOutboundCreatable: (entity, context) => {
|
|
143
143
|
return false;
|
|
144
144
|
},
|
|
145
|
+
syncInboundImages: (entity, context) => {
|
|
146
|
+
return true;
|
|
147
|
+
},
|
|
148
|
+
syncOutboundImages: (entity, context) => {
|
|
149
|
+
return false;
|
|
150
|
+
},
|
|
145
151
|
vibe2flex: {
|
|
146
152
|
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
147
153
|
rekey: {
|
|
@@ -175,6 +181,18 @@ exports.mapping = {
|
|
|
175
181
|
}
|
|
176
182
|
return true;
|
|
177
183
|
},
|
|
184
|
+
syncInboundImages: (entity, context) => {
|
|
185
|
+
if (context && context.skipImages) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return true;
|
|
189
|
+
},
|
|
190
|
+
syncOutboundImages: (entity, context) => {
|
|
191
|
+
if (context && context.skipImages) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
},
|
|
178
196
|
vibe2flex: {
|
|
179
197
|
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
180
198
|
rekey: {
|
|
@@ -781,4 +781,188 @@ describe('conversion-utils', () => {
|
|
|
781
781
|
});
|
|
782
782
|
|
|
783
783
|
});
|
|
784
|
+
|
|
785
|
+
describe('syncInboundImages', () =>{
|
|
786
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
787
|
+
|
|
788
|
+
it('should return true for custom-entity:pack', async () =>{
|
|
789
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
790
|
+
.mockImplementation(async () =>{
|
|
791
|
+
return mapping;
|
|
792
|
+
});
|
|
793
|
+
const entity = {
|
|
794
|
+
entityType: 'custom-entity',
|
|
795
|
+
typePath: 'custom-entity:pack'
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
try{
|
|
799
|
+
const results = await TypeConversionUtils.syncInboundImages(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
800
|
+
expect(results).toBeTruthy();
|
|
801
|
+
|
|
802
|
+
} finally {
|
|
803
|
+
spy.mockRestore();
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
it('should return true for custom-entity:prefix', async () =>{
|
|
808
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
809
|
+
.mockImplementation(async () =>{
|
|
810
|
+
return mapping;
|
|
811
|
+
});
|
|
812
|
+
const entity = {
|
|
813
|
+
entityType: 'custom-entity',
|
|
814
|
+
typePath: 'custom-entity:prefix'
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
try{
|
|
818
|
+
const results = await TypeConversionUtils.syncInboundImages(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
819
|
+
expect(results).toBeTruthy();
|
|
820
|
+
|
|
821
|
+
} finally {
|
|
822
|
+
spy.mockRestore();
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
it('should pass context to syncInboundImages function', async () =>{
|
|
827
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
828
|
+
.mockImplementation(async () =>{
|
|
829
|
+
return mapping;
|
|
830
|
+
});
|
|
831
|
+
const entity = {
|
|
832
|
+
entityType: 'custom-entity',
|
|
833
|
+
typePath: 'custom-entity:prefix'
|
|
834
|
+
}
|
|
835
|
+
const context = { skipImages: true };
|
|
836
|
+
|
|
837
|
+
try{
|
|
838
|
+
const results = await TypeConversionUtils.syncInboundImages(TRANSFORM_MAP_FILE, mapFileUtil, entity, context);
|
|
839
|
+
expect(results).toBeFalsy();
|
|
840
|
+
|
|
841
|
+
} finally {
|
|
842
|
+
spy.mockRestore();
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
it('should default to false when no mapping exists', async () =>{
|
|
847
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
848
|
+
.mockImplementation(async () =>{
|
|
849
|
+
return mapping;
|
|
850
|
+
});
|
|
851
|
+
const entity = {
|
|
852
|
+
entityType: 'custom-entity',
|
|
853
|
+
typePath: 'custom-entity:catName'
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
try{
|
|
857
|
+
const results = await TypeConversionUtils.syncInboundImages(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
858
|
+
expect(results).toBeFalsy();
|
|
859
|
+
|
|
860
|
+
} finally {
|
|
861
|
+
spy.mockRestore();
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
it('should default to false when no fileId', async () =>{
|
|
866
|
+
const entity = {
|
|
867
|
+
entityType: 'custom-entity',
|
|
868
|
+
typePath: 'custom-entity:pack'
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
const results = await TypeConversionUtils.syncInboundImages(null, mapFileUtil, entity);
|
|
872
|
+
expect(results).toBeFalsy();
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
describe('syncOutboundImages', () =>{
|
|
878
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
879
|
+
|
|
880
|
+
it('should return false for custom-entity:pack', async () =>{
|
|
881
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
882
|
+
.mockImplementation(async () =>{
|
|
883
|
+
return mapping;
|
|
884
|
+
});
|
|
885
|
+
const entity = {
|
|
886
|
+
entityType: 'custom-entity',
|
|
887
|
+
typePath: 'custom-entity:pack'
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
try{
|
|
891
|
+
const results = await TypeConversionUtils.syncOutboundImages(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
892
|
+
expect(results).toBeFalsy();
|
|
893
|
+
|
|
894
|
+
} finally {
|
|
895
|
+
spy.mockRestore();
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
it('should return true for custom-entity:prefix', async () =>{
|
|
900
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
901
|
+
.mockImplementation(async () =>{
|
|
902
|
+
return mapping;
|
|
903
|
+
});
|
|
904
|
+
const entity = {
|
|
905
|
+
entityType: 'custom-entity',
|
|
906
|
+
typePath: 'custom-entity:prefix'
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
try{
|
|
910
|
+
const results = await TypeConversionUtils.syncOutboundImages(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
911
|
+
expect(results).toBeTruthy();
|
|
912
|
+
|
|
913
|
+
} finally {
|
|
914
|
+
spy.mockRestore();
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
it('should pass context to syncOutboundImages function', async () =>{
|
|
919
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
920
|
+
.mockImplementation(async () =>{
|
|
921
|
+
return mapping;
|
|
922
|
+
});
|
|
923
|
+
const entity = {
|
|
924
|
+
entityType: 'custom-entity',
|
|
925
|
+
typePath: 'custom-entity:prefix'
|
|
926
|
+
}
|
|
927
|
+
const context = { skipImages: true };
|
|
928
|
+
|
|
929
|
+
try{
|
|
930
|
+
const results = await TypeConversionUtils.syncOutboundImages(TRANSFORM_MAP_FILE, mapFileUtil, entity, context);
|
|
931
|
+
expect(results).toBeFalsy();
|
|
932
|
+
|
|
933
|
+
} finally {
|
|
934
|
+
spy.mockRestore();
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
it('should default to true when no mapping exists', async () =>{
|
|
939
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
940
|
+
.mockImplementation(async () =>{
|
|
941
|
+
return mapping;
|
|
942
|
+
});
|
|
943
|
+
const entity = {
|
|
944
|
+
entityType: 'custom-entity',
|
|
945
|
+
typePath: 'custom-entity:catName'
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
try{
|
|
949
|
+
const results = await TypeConversionUtils.syncOutboundImages(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
950
|
+
expect(results).toBeTruthy();
|
|
951
|
+
|
|
952
|
+
} finally {
|
|
953
|
+
spy.mockRestore();
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
it('should default to true when no fileId', async () =>{
|
|
958
|
+
const entity = {
|
|
959
|
+
entityType: 'custom-entity',
|
|
960
|
+
typePath: 'custom-entity:pack'
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
const results = await TypeConversionUtils.syncOutboundImages(null, mapFileUtil, entity);
|
|
964
|
+
expect(results).toBeTruthy();
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
});
|
|
784
968
|
});
|
|
@@ -377,6 +377,80 @@ export class TypeConversionUtils {
|
|
|
377
377
|
return isOutboundCreatable;
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
+
/** Takes in a VibeIQ entity object and determines whether inbound
|
|
381
|
+
* images should be synced. The creation owning system is expected
|
|
382
|
+
* to also control image syncing. Defaults to false if no mapping exists.
|
|
383
|
+
* Map file entry in '<mapKey>:syncInboundImages()'
|
|
384
|
+
*
|
|
385
|
+
* @param fileId id for mapFile
|
|
386
|
+
* @param mapFileUtil class to get mapfile
|
|
387
|
+
* @param entity VibeIQ entity
|
|
388
|
+
* @param context optional context object
|
|
389
|
+
* @returns Promise<boolean>
|
|
390
|
+
*/
|
|
391
|
+
static async syncInboundImages(fileId: string, mapFileUtil: MapFileUtil, entity: any, context?: any): Promise<boolean> {
|
|
392
|
+
|
|
393
|
+
let syncImages = false;
|
|
394
|
+
|
|
395
|
+
if (!fileId) {
|
|
396
|
+
return syncImages;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
let mapKey: string | undefined;
|
|
400
|
+
try {
|
|
401
|
+
mapKey = await this.getMapKey(fileId, mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
402
|
+
} catch {
|
|
403
|
+
return syncImages;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (!mapKey) {
|
|
407
|
+
return syncImages;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const mapData = await MapUtil.getFullMapSection(fileId, mapFileUtil, mapKey);
|
|
411
|
+
if (mapData && mapData['syncInboundImages']) {
|
|
412
|
+
syncImages = await mapData['syncInboundImages'](entity, context);
|
|
413
|
+
}
|
|
414
|
+
return syncImages;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** Takes in a VibeIQ entity object and determines whether outbound
|
|
418
|
+
* images should be synced. The creation owning system is expected
|
|
419
|
+
* to also control image syncing. Defaults to true if no mapping exists.
|
|
420
|
+
* Map file entry in '<mapKey>:syncOutboundImages()'
|
|
421
|
+
*
|
|
422
|
+
* @param fileId id for mapFile
|
|
423
|
+
* @param mapFileUtil class to get mapfile
|
|
424
|
+
* @param entity VibeIQ entity
|
|
425
|
+
* @param context optional context object
|
|
426
|
+
* @returns Promise<boolean>
|
|
427
|
+
*/
|
|
428
|
+
static async syncOutboundImages(fileId: string, mapFileUtil: MapFileUtil, entity: any, context?: any): Promise<boolean> {
|
|
429
|
+
|
|
430
|
+
let syncImages = true;
|
|
431
|
+
|
|
432
|
+
if (!fileId) {
|
|
433
|
+
return syncImages;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
let mapKey: string | undefined;
|
|
437
|
+
try {
|
|
438
|
+
mapKey = await this.getMapKey(fileId, mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
439
|
+
} catch {
|
|
440
|
+
return syncImages;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (!mapKey) {
|
|
444
|
+
return syncImages;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const mapData = await MapUtil.getFullMapSection(fileId, mapFileUtil, mapKey);
|
|
448
|
+
if (mapData && mapData['syncOutboundImages']) {
|
|
449
|
+
syncImages = await mapData['syncOutboundImages'](entity, context);
|
|
450
|
+
}
|
|
451
|
+
return syncImages;
|
|
452
|
+
}
|
|
453
|
+
|
|
380
454
|
static getObjectType(object:any) {
|
|
381
455
|
let objectType = object['flexPLMObjectClass'];
|
|
382
456
|
return objectType;
|
|
@@ -1,42 +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 { 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
|
-
}
|