@izara_project/izara-shared-search-and-sort 1.0.5 → 1.0.6
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/index.js +0 -2
- package/package.json +1 -1
- package/src/DataFieldsSharedLib.js +1 -1
- package/src/LogicalStructureSharedLib.js +679 -100
- package/src/SearchSortSharedLib.js +23 -13
- package/src/ChangeLevelSharedLib.js +0 -610
|
@@ -23,10 +23,9 @@ import lodash from 'lodash';
|
|
|
23
23
|
const { isEmpty } = lodash;
|
|
24
24
|
import filtersSharedLib from './FiltersSharedLib.js'; //const filtersSharedLib = require('./FiltersSharedLib');
|
|
25
25
|
import dataFieldsSharedLib from './DataFieldsSharedLib.js';
|
|
26
|
-
import searchResultShared from '@izara_project/izara-core-library-search-result';
|
|
27
26
|
|
|
28
27
|
|
|
29
|
-
function createSearchRequest(
|
|
28
|
+
async function createSearchRequest(
|
|
30
29
|
objType,
|
|
31
30
|
initialLogicalElementId,
|
|
32
31
|
logicalElements,
|
|
@@ -54,6 +53,16 @@ function createSearchRequest(
|
|
|
54
53
|
let errorsObject = {};
|
|
55
54
|
let errorsFound = [];
|
|
56
55
|
|
|
56
|
+
let requiredDataPromise = dataFieldsSharedLib.createRequiredData(
|
|
57
|
+
objType,
|
|
58
|
+
requiredDataFields,
|
|
59
|
+
complexFilterCombinations,
|
|
60
|
+
perParentCombinations,
|
|
61
|
+
requiredDataLinkStepObjects,
|
|
62
|
+
requiredDataLinkSteps,
|
|
63
|
+
values,
|
|
64
|
+
);
|
|
65
|
+
|
|
57
66
|
//* create complexFilter normalize to send backend
|
|
58
67
|
let [
|
|
59
68
|
complexFilterRequest,
|
|
@@ -79,15 +88,16 @@ function createSearchRequest(
|
|
|
79
88
|
Object.assign(errorsObject, complexErrorsObject);
|
|
80
89
|
}
|
|
81
90
|
|
|
82
|
-
let requiredData = dataFieldsSharedLib.createRequiredData(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
);
|
|
91
|
+
// let requiredData = dataFieldsSharedLib.createRequiredData(
|
|
92
|
+
// objType,
|
|
93
|
+
// requiredDataFields,
|
|
94
|
+
// complexFilterCombinations,
|
|
95
|
+
// perParentCombinations,
|
|
96
|
+
// requiredDataLinkStepObjects,
|
|
97
|
+
// requiredDataLinkSteps,
|
|
98
|
+
// values,
|
|
99
|
+
// );
|
|
100
|
+
let requiredData = await requiredDataPromise;
|
|
91
101
|
console.log('return create requiredData: ', requiredData);
|
|
92
102
|
|
|
93
103
|
if (requiredData.status === 'invalid' || requiredData.errorsFound.length > 0) {
|
|
@@ -142,7 +152,7 @@ function createSearchRequest(
|
|
|
142
152
|
|
|
143
153
|
}
|
|
144
154
|
|
|
145
|
-
function createSortRequest(
|
|
155
|
+
async function createSortRequest(
|
|
146
156
|
objType,
|
|
147
157
|
initialLogicalElementId,
|
|
148
158
|
logicalElements,
|
|
@@ -198,7 +208,7 @@ function createSortRequest(
|
|
|
198
208
|
}
|
|
199
209
|
console.log("sortFieldMain: ", sortFieldMain)
|
|
200
210
|
|
|
201
|
-
let [searchResultRequest, status, errorsObject, errorsFound] = createSearchRequest(
|
|
211
|
+
let [searchResultRequest, status, errorsObject, errorsFound] = await createSearchRequest(
|
|
202
212
|
objType,
|
|
203
213
|
initialLogicalElementId,
|
|
204
214
|
logicalElements,
|
|
@@ -1,610 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2025 Sven Mason <http://izara.io>
|
|
3
|
-
|
|
4
|
-
This program is free software: you can redistribute it and/or modify
|
|
5
|
-
it under the terms of the GNU Affero General Public License as
|
|
6
|
-
published by the Free Software Foundation, either version 3 of the
|
|
7
|
-
License, or (at your option) any later version.
|
|
8
|
-
|
|
9
|
-
This program is distributed in the hope that it will be useful,
|
|
10
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
GNU Affero General Public License for more details.
|
|
13
|
-
|
|
14
|
-
You should have received a copy of the GNU Affero General Public License
|
|
15
|
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import { objectHash as hash } from '@izara_project/izara-shared-core'; //const hash = require('@izara_project/izara-shared-core').objectHash;
|
|
22
|
-
import lodash from 'lodash';
|
|
23
|
-
const { isEmpty } = lodash;
|
|
24
|
-
import { v4 as uuidV4 } from 'uuid'; //const { v4: uuidv4 } = require('uuid');
|
|
25
|
-
import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
|
|
26
|
-
const MAX_ITER = 4;
|
|
27
|
-
|
|
28
|
-
function checkObjType(
|
|
29
|
-
fromObjType,
|
|
30
|
-
toObjType
|
|
31
|
-
) {
|
|
32
|
-
|
|
33
|
-
let from = {
|
|
34
|
-
serviceTag: fromObjType.serviceTag,
|
|
35
|
-
objectType: fromObjType.objectType
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
let to = {
|
|
39
|
-
serviceTag: toObjType.serviceTag,
|
|
40
|
-
objectType: toObjType.objectType
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
if (hash(to) === hash(from)) {
|
|
44
|
-
return true;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return false;
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// validate to changed searchType and filterType
|
|
52
|
-
/**
|
|
53
|
-
* recieved request thougth sortedResult??? case specail filter
|
|
54
|
-
* @param {string} requiredSearchType
|
|
55
|
-
* @param {string[]} filterArrays
|
|
56
|
-
*
|
|
57
|
-
* return [filters]
|
|
58
|
-
*/
|
|
59
|
-
async function changeObjTypePath(
|
|
60
|
-
requiredObjType,
|
|
61
|
-
filtersStructure,
|
|
62
|
-
path = null,
|
|
63
|
-
) {
|
|
64
|
-
try {
|
|
65
|
-
console.log('----- function validateSearchTypeFilterType -----', {
|
|
66
|
-
requiredObjType,
|
|
67
|
-
filtersStructure,
|
|
68
|
-
path
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
let filterLogicalStructure = {};
|
|
72
|
-
|
|
73
|
-
let errorsObject = {};
|
|
74
|
-
let errorsFound = [];
|
|
75
|
-
|
|
76
|
-
if (path !== null) {
|
|
77
|
-
console.log('-------------- continue process path --------------');
|
|
78
|
-
|
|
79
|
-
let logicalElements = {};
|
|
80
|
-
let previousLogicalElementId = null;
|
|
81
|
-
let previousLogicalElement = null;
|
|
82
|
-
let currentLogicalElementId = null;
|
|
83
|
-
let currentLogicalElement = null;
|
|
84
|
-
|
|
85
|
-
if (path.length > 1) {
|
|
86
|
-
|
|
87
|
-
for (let i = 0; i < path.length; i++) {
|
|
88
|
-
|
|
89
|
-
let pathObject = path[i];
|
|
90
|
-
let logicalStructureElements = filtersStructure.logicalElements;
|
|
91
|
-
console.log('logicalStructureElements', logicalStructureElements);
|
|
92
|
-
|
|
93
|
-
let initialLogicalElementId = filtersStructure.initialLogicalElementId;
|
|
94
|
-
console.log('initialLogicalElementId', initialLogicalElementId);
|
|
95
|
-
|
|
96
|
-
if (i + 1 === path.length) {
|
|
97
|
-
console.log(`------------------- final path: ${i} ---------------------`);
|
|
98
|
-
|
|
99
|
-
if (previousLogicalElementId !== null) {
|
|
100
|
-
|
|
101
|
-
if (checkObjType(pathObject.objType, logicalElements[previousLogicalElementId].objType) !== true) {
|
|
102
|
-
errorsFound.push('objType is not equals in structure');
|
|
103
|
-
console.log('before return: ', {
|
|
104
|
-
filterLogicalStructure: {},
|
|
105
|
-
errorsObject,
|
|
106
|
-
errorsFound
|
|
107
|
-
});
|
|
108
|
-
return [{}, errorsObject, errorsFound];
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
filterLogicalStructure = {
|
|
112
|
-
objType: pathObject.objType,
|
|
113
|
-
initialLogicalElementId: previousLogicalElementId,
|
|
114
|
-
logicalElements: logicalElements
|
|
115
|
-
};
|
|
116
|
-
console.log('filterLogicalStructure: ', filterLogicalStructure);
|
|
117
|
-
|
|
118
|
-
} else {
|
|
119
|
-
if (checkObjType(requiredObjType, filtersStructure.objType) === true) {
|
|
120
|
-
filterLogicalStructure = filtersStructure;
|
|
121
|
-
} else {
|
|
122
|
-
errorsFound.push('objType is not equals in structure');
|
|
123
|
-
console.log('before return: ', {
|
|
124
|
-
filterLogicalStructure: {},
|
|
125
|
-
errorsObject,
|
|
126
|
-
errorsFound
|
|
127
|
-
});
|
|
128
|
-
return [{}, errorsObject, errorsFound];
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
} else {
|
|
133
|
-
console.log(`------------------- between path: ${i} ---------------------`);
|
|
134
|
-
|
|
135
|
-
let logicalElementsStructure = logicalStructureElements[initialLogicalElementId];
|
|
136
|
-
console.log('logicalElementsStructure', logicalElementsStructure);
|
|
137
|
-
|
|
138
|
-
if (previousLogicalElement !== null) {
|
|
139
|
-
|
|
140
|
-
currentLogicalElementId = uuidV4();
|
|
141
|
-
console.log('currentLogicalElementId: ', currentLogicalElementId);
|
|
142
|
-
|
|
143
|
-
currentLogicalElement = {
|
|
144
|
-
logicalElementType: 'childComplexFilter',
|
|
145
|
-
previousLogicalElementId: null,
|
|
146
|
-
nextLogicalElementId: null,
|
|
147
|
-
childLogicalElementId: filtersStructure.initialLogicalElementId,
|
|
148
|
-
|
|
149
|
-
objType: pathObject.pathLinkType.objType,
|
|
150
|
-
pathLinkType: {
|
|
151
|
-
objType: pathObject.objType,
|
|
152
|
-
relType: pathObject.pathLinkType.relType,
|
|
153
|
-
direction: pathObject.pathLinkType.direction
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
console.log('currentLogicalElement', currentLogicalElement);
|
|
157
|
-
|
|
158
|
-
let logicalStructure;
|
|
159
|
-
[previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
|
|
160
|
-
logicalElements,
|
|
161
|
-
previousLogicalElementId,
|
|
162
|
-
previousLogicalElement,
|
|
163
|
-
currentLogicalElementId,
|
|
164
|
-
currentLogicalElement,
|
|
165
|
-
filtersStructure
|
|
166
|
-
);
|
|
167
|
-
console.log('return create child ', {
|
|
168
|
-
previousLogicalElementId,
|
|
169
|
-
previousLogicalElement,
|
|
170
|
-
logicalStructure,
|
|
171
|
-
errorsFound
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
logicalElements = logicalStructure;
|
|
175
|
-
|
|
176
|
-
} else {
|
|
177
|
-
|
|
178
|
-
if (logicalElementsStructure.logicalElementType === 'childComplexFilter') {
|
|
179
|
-
|
|
180
|
-
let childLogicalElementId = logicalElementsStructure.childLogicalElementId;
|
|
181
|
-
console.log('childLogicalElementId', childLogicalElementId);
|
|
182
|
-
|
|
183
|
-
if (childLogicalElementId !== null) {
|
|
184
|
-
console.log('-------- has child filter structure --------');
|
|
185
|
-
|
|
186
|
-
let childLogicalElement = logicalStructureElements[childLogicalElementId];
|
|
187
|
-
console.log('childLogicalElement', childLogicalElement);
|
|
188
|
-
|
|
189
|
-
let pathCheck = false;
|
|
190
|
-
|
|
191
|
-
for (const pathObj of path) {
|
|
192
|
-
if (checkObjType(childLogicalElement.objType, pathObj.objType) === true) {
|
|
193
|
-
pathCheck = true;
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
if (pathCheck) {
|
|
198
|
-
|
|
199
|
-
if (logicalElementsStructure.nextLogicalElementId === null) {
|
|
200
|
-
|
|
201
|
-
//* delete level of objType
|
|
202
|
-
let checkChild = false;
|
|
203
|
-
for (const objType of PATHCONSTANCES.objTypes) {
|
|
204
|
-
if (checkObjType(objType, childLogicalElement.objType) === true) {
|
|
205
|
-
if (!childLogicalElement.hasOwnProperty('childLogicalElementId')) {
|
|
206
|
-
|
|
207
|
-
// let childSchema = await getObjectSchema.getObjSchemaS3(
|
|
208
|
-
let childSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(
|
|
209
|
-
childLogicalElement.objType
|
|
210
|
-
);
|
|
211
|
-
console.log('childSchema: ', childSchema);
|
|
212
|
-
|
|
213
|
-
if (childSchema.hasOwnProperty('extendObjType')) {
|
|
214
|
-
if (checkObjType(requiredObjType, childSchema.extendObjType) === true) {
|
|
215
|
-
checkChild = false;
|
|
216
|
-
break;
|
|
217
|
-
};
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
checkChild = true;
|
|
221
|
-
break;
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
if (checkChild) {
|
|
226
|
-
|
|
227
|
-
delete filtersStructure.logicalElements[initialLogicalElementId];
|
|
228
|
-
console.log('filtersStructure: ', filtersStructure);
|
|
229
|
-
|
|
230
|
-
filtersStructure.objType = childLogicalElement.objType;
|
|
231
|
-
filtersStructure.initialLogicalElementId = childLogicalElementId;
|
|
232
|
-
filtersStructure.logicalElements[childLogicalElementId].previousLogicalElementId = null;
|
|
233
|
-
console.log('after filtersStructure: ', filtersStructure);
|
|
234
|
-
|
|
235
|
-
logicalElements = filtersStructure.logicalElements;
|
|
236
|
-
|
|
237
|
-
continue;
|
|
238
|
-
|
|
239
|
-
};
|
|
240
|
-
};
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
currentLogicalElementId = uuidV4();
|
|
244
|
-
console.log('currentLogicalElementId: ', currentLogicalElementId)
|
|
245
|
-
|
|
246
|
-
currentLogicalElement = {
|
|
247
|
-
logicalElementType: 'childComplexFilter',
|
|
248
|
-
previousLogicalElementId: null,
|
|
249
|
-
nextLogicalElementId: null,
|
|
250
|
-
childLogicalElementId: filtersStructure.initialLogicalElementId,
|
|
251
|
-
|
|
252
|
-
objType: pathObject.pathLinkType.objType,
|
|
253
|
-
pathLinkType: {
|
|
254
|
-
objType: pathObject.objType,
|
|
255
|
-
relType: pathObject.pathLinkType.relType,
|
|
256
|
-
direction: pathObject.pathLinkType.direction
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
console.log('currentLogicalElement', currentLogicalElement);
|
|
260
|
-
|
|
261
|
-
let logicalStructure = {};
|
|
262
|
-
[previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
|
|
263
|
-
_izContext,
|
|
264
|
-
logicalElements,
|
|
265
|
-
previousLogicalElementId,
|
|
266
|
-
previousLogicalElement,
|
|
267
|
-
currentLogicalElementId,
|
|
268
|
-
currentLogicalElement,
|
|
269
|
-
filtersStructure
|
|
270
|
-
)
|
|
271
|
-
console.log('return create child', {
|
|
272
|
-
previousLogicalElementId,
|
|
273
|
-
previousLogicalElement,
|
|
274
|
-
logicalStructure,
|
|
275
|
-
errorsFound
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
logicalElements = logicalStructure;
|
|
279
|
-
console.log('logicalElements: ', logicalElements);
|
|
280
|
-
|
|
281
|
-
// if (logicalElementsStructure.nextLogicalElementId !== null) {
|
|
282
|
-
// console.log("-------- no child filter structure --------", vvv);
|
|
283
|
-
// }
|
|
284
|
-
|
|
285
|
-
} else {
|
|
286
|
-
console.log('-------- no child filter structure --------', vvv);
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
} else {
|
|
291
|
-
|
|
292
|
-
currentLogicalElementId = uuidV4();
|
|
293
|
-
console.log('currentLogicalElementId: ', currentLogicalElementId);
|
|
294
|
-
|
|
295
|
-
currentLogicalElement = {
|
|
296
|
-
logicalElementType: 'childComplexFilter',
|
|
297
|
-
previousLogicalElementId: null,
|
|
298
|
-
nextLogicalElementId: null,
|
|
299
|
-
childLogicalElementId: filtersStructure.initialLogicalElementId,
|
|
300
|
-
|
|
301
|
-
objType: pathObject.pathLinkType.objType,
|
|
302
|
-
pathLinkType: {
|
|
303
|
-
objType: pathObject.objType,
|
|
304
|
-
relType: pathObject.pathLinkType.relType,
|
|
305
|
-
direction: pathObject.pathLinkType.direction
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
console.log('currentLogicalElement', currentLogicalElement);
|
|
309
|
-
|
|
310
|
-
let logicalStructure = {};
|
|
311
|
-
// change function name ==> set logicalElementId
|
|
312
|
-
[previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
|
|
313
|
-
_izContext,
|
|
314
|
-
logicalElements,
|
|
315
|
-
previousLogicalElementId,
|
|
316
|
-
previousLogicalElement,
|
|
317
|
-
currentLogicalElementId,
|
|
318
|
-
currentLogicalElement,
|
|
319
|
-
filtersStructure
|
|
320
|
-
)
|
|
321
|
-
console.log('return create child', {
|
|
322
|
-
previousLogicalElementId,
|
|
323
|
-
previousLogicalElement,
|
|
324
|
-
logicalStructure,
|
|
325
|
-
errorsFound
|
|
326
|
-
});
|
|
327
|
-
logicalElements = logicalStructure;
|
|
328
|
-
};
|
|
329
|
-
};
|
|
330
|
-
};
|
|
331
|
-
};
|
|
332
|
-
} else {
|
|
333
|
-
console.log('------------ path euals 1 -----------');
|
|
334
|
-
console.log('pathObject', path[0]);
|
|
335
|
-
|
|
336
|
-
if (checkObjType(requiredObjType, filtersStructure.objType) === true) {
|
|
337
|
-
filterLogicalStructure = filtersStructure;
|
|
338
|
-
} else {
|
|
339
|
-
errorsObject = {
|
|
340
|
-
[requiredObjType.objectType]: `is not equals objType in filter structure: objType: ${filtersStructure.objType.objectType}`
|
|
341
|
-
};
|
|
342
|
-
errorsFound.push(`${requiredObjType.objectType} is not equals objType in filter structure: objType: ${filtersStructure.objType.objectType}`);
|
|
343
|
-
return [filterLogicalStructure, errorsObject, errorsFound];
|
|
344
|
-
};
|
|
345
|
-
};
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
console.log('before return filterLogicalStructure: ', {
|
|
349
|
-
path,
|
|
350
|
-
filterLogicalStructure,
|
|
351
|
-
errorsObject,
|
|
352
|
-
errorsFound
|
|
353
|
-
});
|
|
354
|
-
return [filterLogicalStructure, errorsObject, errorsFound];
|
|
355
|
-
|
|
356
|
-
} catch (err) {
|
|
357
|
-
_izContext.logger.error('error ValidateSearchTypeFilterType: ', err)
|
|
358
|
-
throw (err);
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
};
|
|
362
|
-
//###################################################################################################################################################################################
|
|
363
|
-
|
|
364
|
-
function createChildComplexFilterStructure(
|
|
365
|
-
logicalElements,
|
|
366
|
-
previousLogicalElementId,
|
|
367
|
-
previousLogicalElement,
|
|
368
|
-
currentLogicalElementId,
|
|
369
|
-
currentLogicalElement,
|
|
370
|
-
filtersStructure
|
|
371
|
-
) {
|
|
372
|
-
console.log('createChildComplexFilterStructure: ', {
|
|
373
|
-
logicalElements,
|
|
374
|
-
previousLogicalElementId,
|
|
375
|
-
previousLogicalElement,
|
|
376
|
-
currentLogicalElementId,
|
|
377
|
-
currentLogicalElement,
|
|
378
|
-
filtersStructure
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
let errorsFound = [];
|
|
382
|
-
|
|
383
|
-
if (!currentLogicalElement) {
|
|
384
|
-
errorsFound.push('no current logical element to process');
|
|
385
|
-
return [previousLogicalElementId, previousLogicalElement, logicalElements, errorsFound];
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
if (!previousLogicalElement) {
|
|
389
|
-
filtersStructure.logicalElements[filtersStructure.initialLogicalElementId].previousLogicalElementId = currentLogicalElementId;
|
|
390
|
-
logicalElements = Object.assign({ [currentLogicalElementId]: currentLogicalElement }, logicalElements, filtersStructure.logicalElements);
|
|
391
|
-
} else {
|
|
392
|
-
|
|
393
|
-
currentLogicalElement.childLogicalElementId = previousLogicalElementId;
|
|
394
|
-
console.log('currentLogicalElement', currentLogicalElement);
|
|
395
|
-
|
|
396
|
-
logicalElements[previousLogicalElementId].previousLogicalElementId = currentLogicalElementId;
|
|
397
|
-
console.log('logicalElements', logicalElements);
|
|
398
|
-
|
|
399
|
-
logicalElements = Object.assign({ [currentLogicalElementId]: currentLogicalElement }, logicalElements);
|
|
400
|
-
console.log('after logicalElements', logicalElements);
|
|
401
|
-
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
previousLogicalElementId = currentLogicalElementId;
|
|
405
|
-
previousLogicalElement = currentLogicalElement;
|
|
406
|
-
|
|
407
|
-
return [previousLogicalElementId, previousLogicalElement, logicalElements, errorsFound];
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
async function findObjTypePathToAnotherObjType(
|
|
411
|
-
fromObjType,
|
|
412
|
-
toObjType,
|
|
413
|
-
PATHCONSTANCES
|
|
414
|
-
) {
|
|
415
|
-
console.log('----- function findObjTypePathToAnotherObjType -----', {
|
|
416
|
-
fromObjType,
|
|
417
|
-
toObjType
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
let [path, errorsObject, errorsFound] = await recursiveFindObjTypeTypePathToAnotherObjType(
|
|
421
|
-
PATHCONSTANCES,
|
|
422
|
-
fromObjType,
|
|
423
|
-
toObjType,
|
|
424
|
-
);
|
|
425
|
-
console.log('return path', {
|
|
426
|
-
path,
|
|
427
|
-
errorsObject,
|
|
428
|
-
errorsFound
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
if (path !== null) {
|
|
432
|
-
console.log('--------------- will return -----------------');
|
|
433
|
-
return [path, errorsObject, errorsFound];
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
return [path, errorsObject, errorsFound];
|
|
437
|
-
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
async function recursiveFindObjTypeTypePathToAnotherObjType(
|
|
441
|
-
PATHCONSTANCES,
|
|
442
|
-
fromObjType,
|
|
443
|
-
toObjType,
|
|
444
|
-
iter = 1
|
|
445
|
-
) {
|
|
446
|
-
console.log('----- function recursiveFindObjTypeTypePathToAnotherObjType -----', {
|
|
447
|
-
PATHCONSTANCES,
|
|
448
|
-
fromObjType,
|
|
449
|
-
toObjType,
|
|
450
|
-
iter
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
let errorsObject = {};
|
|
454
|
-
let errorsFound = [];
|
|
455
|
-
|
|
456
|
-
let continueProcess = false;
|
|
457
|
-
|
|
458
|
-
for (const objType of PATHCONSTANCES.objTypes) {
|
|
459
|
-
console.log('objType: ', objType);
|
|
460
|
-
if (checkObjType(fromObjType, objType) === true) {
|
|
461
|
-
// if (hash(fromObjType) === hash(objType)) {
|
|
462
|
-
continueProcess = true;
|
|
463
|
-
};
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
if (continueProcess) {
|
|
467
|
-
console.log('------------ continue to find path --------------');
|
|
468
|
-
|
|
469
|
-
if (checkObjType(fromObjType, toObjType) === true) {
|
|
470
|
-
// if (hash(fromObjType) === hash(toObjType)) {
|
|
471
|
-
return [[{ objType: toObjType }], errorsObject, errorsFound];
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
if (iter >= MAX_ITER) {
|
|
475
|
-
return [null, errorsObject, errorsFound];
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
// let objectRelationship = await getObjectSchema.getObjectRelationshipWithCache(
|
|
479
|
-
const objectRelationship = await getObjectSchema.getObjectRelationship(
|
|
480
|
-
fromObjType
|
|
481
|
-
);
|
|
482
|
-
console.log("objectRelationship: ", { fromObjType, objectRelationship });
|
|
483
|
-
|
|
484
|
-
let path = null;
|
|
485
|
-
let previousNextPath = null;
|
|
486
|
-
let currentNextPath = null;
|
|
487
|
-
|
|
488
|
-
for (const relationshipObject of objectRelationship) {
|
|
489
|
-
console.log('relationshipObject: ', relationshipObject);
|
|
490
|
-
|
|
491
|
-
let relType = relationshipObject.relType;
|
|
492
|
-
console.log('relType: ', relType);
|
|
493
|
-
|
|
494
|
-
let otherObjType = relationshipObject.other.objType;
|
|
495
|
-
console.log('otherObjType: ', otherObjType);
|
|
496
|
-
|
|
497
|
-
let relCheck = false;
|
|
498
|
-
|
|
499
|
-
for (const relPath of PATHCONSTANCES.relTypes) {
|
|
500
|
-
if (hash(relType) === hash(relPath)) {
|
|
501
|
-
relCheck = true;
|
|
502
|
-
break;
|
|
503
|
-
};
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
if (!relCheck) {
|
|
507
|
-
//* no relationshipTag in constance
|
|
508
|
-
continue;
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
// const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
|
|
512
|
-
const objectSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(
|
|
513
|
-
toObjType,
|
|
514
|
-
);
|
|
515
|
-
console.log('objectSchema: ', objectSchema);
|
|
516
|
-
console.log('before relationshipObject: ', {
|
|
517
|
-
from: fromObjType,
|
|
518
|
-
to: toObjType,
|
|
519
|
-
next: otherObjType,
|
|
520
|
-
relationshipObject
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
if (objectSchema.hasOwnProperty('extendObjType')) {
|
|
524
|
-
if (checkObjType(otherObjType, objectSchema.extendObjType) === true) {
|
|
525
|
-
// if (hash(nextObjType) === hash(objectSchema.extendObjType)) {
|
|
526
|
-
otherObjType = toObjType;
|
|
527
|
-
};
|
|
528
|
-
};
|
|
529
|
-
console.log('after relationshipObject: ', {
|
|
530
|
-
from: fromObjType,
|
|
531
|
-
to: toObjType,
|
|
532
|
-
next: otherObjType,
|
|
533
|
-
relationshipObject
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
let pathErrorsObject;
|
|
537
|
-
let pathErrorsFound;
|
|
538
|
-
|
|
539
|
-
//* recurvsive path
|
|
540
|
-
[currentNextPath, pathErrorsObject, pathErrorsFound] = await recursiveFindObjTypeTypePathToAnotherObjType(
|
|
541
|
-
PATHCONSTANCES,
|
|
542
|
-
otherObjType,
|
|
543
|
-
toObjType,
|
|
544
|
-
iter + 1
|
|
545
|
-
);
|
|
546
|
-
console.log('return recursive path: ', {
|
|
547
|
-
currentNextPath,
|
|
548
|
-
pathErrorsObject,
|
|
549
|
-
pathErrorsFound
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
if (currentNextPath !== null) {
|
|
553
|
-
|
|
554
|
-
previousNextPath = currentNextPath;
|
|
555
|
-
|
|
556
|
-
let addPath = {
|
|
557
|
-
objType: fromObjType,
|
|
558
|
-
pathLinkType: {
|
|
559
|
-
objType: otherObjType,
|
|
560
|
-
relType: relType,
|
|
561
|
-
direction: relationshipObject.other.direction
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
console.log('addPath: ', addPath);
|
|
565
|
-
|
|
566
|
-
previousNextPath.unshift(addPath);
|
|
567
|
-
console.log('path: ', path);
|
|
568
|
-
|
|
569
|
-
} else {
|
|
570
|
-
continue;
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
if (previousNextPath !== null) {
|
|
574
|
-
if (path !== null) {
|
|
575
|
-
if (path.length > previousNextPath.length) {
|
|
576
|
-
path = previousNextPath;
|
|
577
|
-
};
|
|
578
|
-
console.log('path: ', path);
|
|
579
|
-
return [path, errorsObject, errorsFound];
|
|
580
|
-
} else {
|
|
581
|
-
path = previousNextPath;
|
|
582
|
-
};
|
|
583
|
-
};
|
|
584
|
-
};// end iterate relType
|
|
585
|
-
|
|
586
|
-
// if (previousNextPath !== null) {
|
|
587
|
-
if (path !== null) {
|
|
588
|
-
if (path.length > previousNextPath.length) {
|
|
589
|
-
path = previousNextPath;
|
|
590
|
-
};
|
|
591
|
-
console.log('path: ', path);
|
|
592
|
-
return [path, errorsObject, errorsFound];
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
} else {
|
|
596
|
-
errorsObject = {
|
|
597
|
-
[fromObjType.objectType]: 'cannot found this objType that can process in path'
|
|
598
|
-
};
|
|
599
|
-
errorsFound.push(`${fromObjType.objectType}: cannot found objType that can process in path`);
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
return [null, errorsObject, errorsFound];
|
|
603
|
-
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
export default {
|
|
608
|
-
changeObjTypePath,
|
|
609
|
-
findObjTypePathToAnotherObjType
|
|
610
|
-
}
|