@izara_project/izara-shared-search-and-sort 1.0.3 → 1.0.5
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 +5 -1
- package/package.json +3 -1
- package/src/ChangeLevelSharedLib.js +610 -0
- package/src/DataFieldsSharedLib.js +118 -91
- package/src/FiltersSharedLib.js +232 -567
- package/src/LogicalStructureSharedLib.js +573 -0
- package/src/SearchSortSharedLib.js +23 -27
|
@@ -0,0 +1,573 @@
|
|
|
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
|
+
|
|
29
|
+
function combineLogicalStructure(
|
|
30
|
+
objType,
|
|
31
|
+
initialLogicalElementId,
|
|
32
|
+
logicalElements,
|
|
33
|
+
) {
|
|
34
|
+
console.log('combineLogicalStructure: ', {
|
|
35
|
+
objType,
|
|
36
|
+
initialLogicalElementId,
|
|
37
|
+
logicalElements,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
let returnInitialElementId = null;
|
|
41
|
+
let initialLogicalElementObject = logicalElements[initialLogicalElementId]
|
|
42
|
+
if (initialLogicalElementObject.logicalElementType !== 'logicalStructure') {
|
|
43
|
+
returnInitialElementId = initialLogicalElementId;
|
|
44
|
+
} else {
|
|
45
|
+
returnInitialElementId = logicalElements[initialLogicalElementId].initialLogicalElementId;
|
|
46
|
+
};
|
|
47
|
+
console.log('returnInitialElementId', returnInitialElementId);
|
|
48
|
+
|
|
49
|
+
let previousLogicalElementId = null;
|
|
50
|
+
let previousLogicalElementObject = null;
|
|
51
|
+
|
|
52
|
+
let operationLogicalElementId = null;
|
|
53
|
+
let operationLogicalElementObject = null;
|
|
54
|
+
|
|
55
|
+
let nextLogicalElementId = null;
|
|
56
|
+
let nextLogicalElementObject = null;
|
|
57
|
+
|
|
58
|
+
let returnLogicalElements = {};
|
|
59
|
+
|
|
60
|
+
let errorsObject = {};
|
|
61
|
+
let errorsFound = [];
|
|
62
|
+
|
|
63
|
+
for (const [logicalElementId, logicalElementObject] of Object.entries(logicalElements)) {
|
|
64
|
+
console.log('extract logicalELements: ', { initialLogicalElementId, logicalElementId, logicalElementObject });
|
|
65
|
+
|
|
66
|
+
if (initialLogicalElementId !== logicalElementId) {
|
|
67
|
+
continue;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
let logicalElementType = logicalElementObject.logicalElementType;
|
|
71
|
+
console.log('logicalElementType: ', logicalElementType);
|
|
72
|
+
|
|
73
|
+
if (logicalElementType === 'openBracket') {
|
|
74
|
+
console.log('----------type: openBracket ----------');
|
|
75
|
+
if (!logicalElementObject.hasOwnProperty('previousLogicalElementId')) {
|
|
76
|
+
errorsObject[logicalElementId] = `this logical structure is not set previousLogicalElementId`;
|
|
77
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set previousLogicalElementId`);
|
|
78
|
+
};
|
|
79
|
+
if (!logicalElementObject.hasOwnProperty('nextLogicalElementId')) {
|
|
80
|
+
errorsObject[logicalElementId] = `this logical structure is not set nextLogicalElementId`;
|
|
81
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set nextLogicalElementId`);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
nextLogicalElementId = logicalElementId;
|
|
85
|
+
nextLogicalElementObject = { [nextLogicalElementId]: logicalElementObject };
|
|
86
|
+
initialLogicalElementId = logicalElementObject.nextLogicalElementId;
|
|
87
|
+
|
|
88
|
+
} else if (logicalElementType === 'logicalStructure') {
|
|
89
|
+
console.log('----------type: logicalStructure ----------');
|
|
90
|
+
|
|
91
|
+
if (!logicalElementObject.hasOwnProperty('objType')) {
|
|
92
|
+
errorsObject[logicalElementId] = `this logical structure is not set objType`;
|
|
93
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set objType`);
|
|
94
|
+
};
|
|
95
|
+
if (!logicalElementObject.hasOwnProperty('initialLogicalElementId')) {
|
|
96
|
+
errorsObject[logicalElementId] = `this logical structure is not set initialLogicalElementId`;
|
|
97
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set initialLogicalElementId`);
|
|
98
|
+
};
|
|
99
|
+
if (!logicalElementObject.hasOwnProperty('previousLogicalElementId')) {
|
|
100
|
+
errorsObject[logicalElementId] = `this logical structure is not set previousLogicalElementId`;
|
|
101
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set previousLogicalElementId`);
|
|
102
|
+
};
|
|
103
|
+
if (!logicalElementObject.hasOwnProperty('nextLogicalElementId')) {
|
|
104
|
+
errorsObject[logicalElementId] = `this logical structure is not set nextLogicalElementId`;
|
|
105
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set nextLogicalElementId`);
|
|
106
|
+
};
|
|
107
|
+
if (!logicalElementObject.hasOwnProperty('logicalElements')) {
|
|
108
|
+
errorsObject[logicalElementId] = `this logical structure is not set logicalElements`;
|
|
109
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set logicalElements`);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
nextLogicalElementId = logicalElementObject.initialLogicalElementId;
|
|
113
|
+
nextLogicalElementObject = logicalElementObject.logicalElements;
|
|
114
|
+
|
|
115
|
+
if (logicalElementObject.nextLogicalElementId !== null) {
|
|
116
|
+
initialLogicalElementId = logicalElementObject.nextLogicalElementId;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
} else if (logicalElementType === 'operation') {
|
|
120
|
+
console.log('----------type: operation ----------');
|
|
121
|
+
if (!logicalElementObject.hasOwnProperty('previousLogicalElementId')) {
|
|
122
|
+
errorsObject[logicalElementId] = `this logical structure is not set previousLogicalElementId`;
|
|
123
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set previousLogicalElementId`);
|
|
124
|
+
};
|
|
125
|
+
if (!logicalElementObject.hasOwnProperty('nextLogicalElementId')) {
|
|
126
|
+
errorsObject[logicalElementId] = `this logical structure is not set nextLogicalElementId`;
|
|
127
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set nextLogicalElementId`);
|
|
128
|
+
};
|
|
129
|
+
if (!logicalElementObject.hasOwnProperty('operation')) {
|
|
130
|
+
errorsObject[logicalElementId] = `this logical structure is not set operation`;
|
|
131
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set operation`);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
operationLogicalElementId = logicalElementId;
|
|
135
|
+
operationLogicalElementObject = logicalElementObject;
|
|
136
|
+
initialLogicalElementId = logicalElementObject.nextLogicalElementId;
|
|
137
|
+
continue;
|
|
138
|
+
|
|
139
|
+
} else if (logicalElementType === 'closeBracket') {
|
|
140
|
+
console.log('----------type: closeBracket ----------');
|
|
141
|
+
if (!logicalElementObject.hasOwnProperty('previousLogicalElementId')) {
|
|
142
|
+
errorsObject[logicalElementId] = `this logical structure is not set previousLogicalElementId`;
|
|
143
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set previousLogicalElementId`);
|
|
144
|
+
};
|
|
145
|
+
if (!logicalElementObject.hasOwnProperty('nextLogicalElementId')) {
|
|
146
|
+
errorsObject[logicalElementId] = `this logical structure is not set nextLogicalElementId`;
|
|
147
|
+
errorsFound.push(`this logical structure logicalElementId: ${logicalElementId} is not set nextLogicalElementId`);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
nextLogicalElementId = logicalElementId;
|
|
151
|
+
nextLogicalElementObject = { [nextLogicalElementId]: logicalElementObject };
|
|
152
|
+
initialLogicalElementId = logicalElementObject.nextLogicalElementId;
|
|
153
|
+
|
|
154
|
+
} else {
|
|
155
|
+
//* error
|
|
156
|
+
errorsObject[logicalElementId] = `has error on logicalElementType: ${logicalElementType}`;
|
|
157
|
+
errorsFound.push(`has error on logicalElementType in logicalElementId: ${logicalElementId}`);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
if (errorsFound.length > 0) {
|
|
161
|
+
return [null, errorsObject, errorsFound];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let operations = null;
|
|
165
|
+
let operationErrorObjects = {};
|
|
166
|
+
let operationErrors = [];
|
|
167
|
+
|
|
168
|
+
[
|
|
169
|
+
previousLogicalElementId,
|
|
170
|
+
previousLogicalElementObject,
|
|
171
|
+
operations,
|
|
172
|
+
operationErrorObjects,
|
|
173
|
+
operationErrors
|
|
174
|
+
] = combineOperation(
|
|
175
|
+
previousLogicalElementId,
|
|
176
|
+
previousLogicalElementObject,
|
|
177
|
+
operationLogicalElementId,
|
|
178
|
+
operationLogicalElementObject,
|
|
179
|
+
nextLogicalElementId,
|
|
180
|
+
nextLogicalElementObject
|
|
181
|
+
);
|
|
182
|
+
console.log('return combineOperation: ', {
|
|
183
|
+
previousLogicalElementId,
|
|
184
|
+
previousLogicalElementObject,
|
|
185
|
+
operations,
|
|
186
|
+
operationErrors
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (operationErrors.length > 0) {
|
|
190
|
+
Object.assign(errorsObject, operationErrorObjects);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
if (operations !== null) {
|
|
194
|
+
Object.assign(returnLogicalElements, operations);
|
|
195
|
+
operationLogicalElementId = null;
|
|
196
|
+
operationLogicalElementObject = null;
|
|
197
|
+
} else {
|
|
198
|
+
Object.assign(returnLogicalElements, previousLogicalElementObject);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
} //end iterate logicalElements
|
|
202
|
+
|
|
203
|
+
console.log('returnLogicalElements: ', { returnLogicalElements });
|
|
204
|
+
|
|
205
|
+
let returnComplexLogicalStructure = {
|
|
206
|
+
objType: objType,
|
|
207
|
+
initialLogicalElementId: returnInitialElementId,
|
|
208
|
+
logicalElements: returnLogicalElements
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
return [returnComplexLogicalStructure, errorsObject, errorsFound];
|
|
212
|
+
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
function combineOperation(
|
|
216
|
+
previousLogicalElementId,
|
|
217
|
+
previousLogicalElementObject,
|
|
218
|
+
operationLogicalElementId,
|
|
219
|
+
operationLogicalElementObject,
|
|
220
|
+
nextLogicalElementId,
|
|
221
|
+
nextLogicalElementObject
|
|
222
|
+
) {
|
|
223
|
+
console.log('combineOperation: ', {
|
|
224
|
+
previousLogicalElementId,
|
|
225
|
+
previousLogicalElementObject,
|
|
226
|
+
operationLogicalElementId,
|
|
227
|
+
operationLogicalElementObject,
|
|
228
|
+
nextLogicalElementId,
|
|
229
|
+
nextLogicalElementObject
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
let errorsObject = {};
|
|
233
|
+
let errorsFound = []
|
|
234
|
+
|
|
235
|
+
if (!nextLogicalElementObject) {
|
|
236
|
+
errorsFound.push('cannot found current filterElement object')
|
|
237
|
+
return [null, null, null, errorsObject, errorsFound];
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
if (!previousLogicalElementObject) {
|
|
241
|
+
return [nextLogicalElementId, nextLogicalElementObject, null, errorsObject, errorsFound];
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
if (!operationLogicalElementObject) {
|
|
245
|
+
console.log('------------ previous & current ------------', {
|
|
246
|
+
previousLogicalElementId,
|
|
247
|
+
previousLogicalElementObject,
|
|
248
|
+
operationLogicalElementId,
|
|
249
|
+
operationLogicalElementObject,
|
|
250
|
+
nextLogicalElementId,
|
|
251
|
+
nextLogicalElementObject
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
let operations = {};
|
|
255
|
+
let returnnextElementId = null;
|
|
256
|
+
let returnNextElementObject = null;
|
|
257
|
+
|
|
258
|
+
if (previousLogicalElementObject[previousLogicalElementId].logicalElementType === 'openBracket') {
|
|
259
|
+
if (nextLogicalElementObject[nextLogicalElementId].logicalElementType === 'closeBracket') {
|
|
260
|
+
|
|
261
|
+
if (Object.entries(previousLogicalElementObject).length <= 2) {
|
|
262
|
+
|
|
263
|
+
previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId = nextLogicalElementId;
|
|
264
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = previousLogicalElementId;
|
|
265
|
+
|
|
266
|
+
} else {
|
|
267
|
+
|
|
268
|
+
if (previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId === null) {
|
|
269
|
+
previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId = nextLogicalElementId;
|
|
270
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = previousLogicalElementId;
|
|
271
|
+
|
|
272
|
+
} else {
|
|
273
|
+
|
|
274
|
+
let checkNextLogicalElementId = previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId;
|
|
275
|
+
console.log('checkNextLogicalElementId:', checkNextLogicalElementId);
|
|
276
|
+
|
|
277
|
+
for (let i = 0; i < Object.entries(previousLogicalElementObject).length; i++) {
|
|
278
|
+
let [logicalElementId, logicalObject] = Object.entries(previousLogicalElementObject)[i];
|
|
279
|
+
console.log('extract logical element: ', { logicalElementId, logicalObject });
|
|
280
|
+
|
|
281
|
+
if (logicalElementId !== checkNextLogicalElementId) {
|
|
282
|
+
continue;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
console.log('------------- has next logicalElemet to continue -------------');
|
|
286
|
+
|
|
287
|
+
if (logicalObject.nextLogicalElementId !== null) {
|
|
288
|
+
checkNextLogicalElementId = logicalObject.nextLogicalElementId;
|
|
289
|
+
continue;
|
|
290
|
+
} else {
|
|
291
|
+
previousLogicalElementObject[logicalElementId].nextLogicalElementId = nextLogicalElementId;
|
|
292
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = logicalElementId;
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
operations = Object.assign(previousLogicalElementObject, nextLogicalElementObject);
|
|
299
|
+
console.log('operations: ', operations);
|
|
300
|
+
|
|
301
|
+
returnnextElementId = nextLogicalElementId;
|
|
302
|
+
returnNextElementObject = nextLogicalElementObject;
|
|
303
|
+
|
|
304
|
+
} else {
|
|
305
|
+
|
|
306
|
+
previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId = nextLogicalElementId;
|
|
307
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = previousLogicalElementId;
|
|
308
|
+
|
|
309
|
+
operations = Object.assign(previousLogicalElementObject, nextLogicalElementObject);
|
|
310
|
+
|
|
311
|
+
console.log('operations: ', operations);
|
|
312
|
+
returnnextElementId = nextLogicalElementId;
|
|
313
|
+
returnNextElementObject = nextLogicalElementObject;
|
|
314
|
+
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
} else if (previousLogicalElementObject[previousLogicalElementId].logicalElementType === 'closeBracket') {
|
|
318
|
+
|
|
319
|
+
if (nextLogicalElementObject[nextLogicalElementId].logicalElementType === 'closeBracket') {
|
|
320
|
+
|
|
321
|
+
previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId = nextLogicalElementId;
|
|
322
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = previousLogicalElementId;
|
|
323
|
+
|
|
324
|
+
operations = Object.assign(previousLogicalElementObject, nextLogicalElementObject);
|
|
325
|
+
console.log('operations: ', operations);
|
|
326
|
+
|
|
327
|
+
returnnextElementId = nextLogicalElementId;
|
|
328
|
+
returnNextElementObject = nextLogicalElementObject;
|
|
329
|
+
|
|
330
|
+
} else {
|
|
331
|
+
errorsObject[nextLogicalElementId] = 'this path has logical structure error';
|
|
332
|
+
errorsFound.push(`${nextLogicalElementId}: this path has logical structure error`);
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
} else {
|
|
336
|
+
|
|
337
|
+
if (nextLogicalElementObject[nextLogicalElementId].logicalElementType === 'closeBracket') {
|
|
338
|
+
|
|
339
|
+
console.log('previousLogicalElementObject: ', previousLogicalElementObject);
|
|
340
|
+
|
|
341
|
+
if (Object.entries(previousLogicalElementObject).length <= 2) {
|
|
342
|
+
|
|
343
|
+
previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId = nextLogicalElementId;
|
|
344
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = previousLogicalElementId;
|
|
345
|
+
|
|
346
|
+
} else {
|
|
347
|
+
|
|
348
|
+
if (previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId === null) {
|
|
349
|
+
previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId = nextLogicalElementId;
|
|
350
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = previousLogicalElementId;
|
|
351
|
+
|
|
352
|
+
} else {
|
|
353
|
+
|
|
354
|
+
let checkNextLogicalElementId = previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId;
|
|
355
|
+
console.log('checkNextLogicalElementId:', checkNextLogicalElementId);
|
|
356
|
+
|
|
357
|
+
for (let i = 0; i < Object.entries(previousLogicalElementObject).length; i++) {
|
|
358
|
+
let [logicalElementId, logicalObject] = Object.entries(previousLogicalElementObject)[i];
|
|
359
|
+
console.log('extract logical element: ', { logicalElementId, logicalObject });
|
|
360
|
+
|
|
361
|
+
if (logicalElementId !== checkNextLogicalElementId) {
|
|
362
|
+
continue;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
console.log('------------- has next logicalElemet to continue -------------');
|
|
366
|
+
|
|
367
|
+
if (logicalObject.nextLogicalElementId !== null) {
|
|
368
|
+
checkNextLogicalElementId = logicalObject.nextLogicalElementId;
|
|
369
|
+
continue;
|
|
370
|
+
} else {
|
|
371
|
+
previousLogicalElementObject[logicalElementId].nextLogicalElementId = nextLogicalElementId;
|
|
372
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = logicalElementId;
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
operations = Object.assign(previousLogicalElementObject, nextLogicalElementObject);
|
|
379
|
+
console.log("operations: ", operations);
|
|
380
|
+
|
|
381
|
+
returnnextElementId = nextLogicalElementId;
|
|
382
|
+
returnNextElementObject = nextLogicalElementObject;
|
|
383
|
+
|
|
384
|
+
} else {
|
|
385
|
+
errorsObject[nextLogicalElementId] = 'this path has logical structure error';
|
|
386
|
+
errorsFound.push(`${nextLogicalElementId}: this path has logical structure error`);
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
return [returnnextElementId, returnNextElementObject, operations, errorsObject, errorsFound];
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
if (previousLogicalElementObject && operationLogicalElementObject && nextLogicalElementObject) {
|
|
393
|
+
console.log('------------ previous & operation & current ------------', {
|
|
394
|
+
previousLogicalElementId,
|
|
395
|
+
previousLogicalElementObject,
|
|
396
|
+
operationLogicalElementId,
|
|
397
|
+
operationLogicalElementObject,
|
|
398
|
+
nextLogicalElementId,
|
|
399
|
+
nextLogicalElementObject
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
let operations = {};
|
|
403
|
+
|
|
404
|
+
previousLogicalElementObject[previousLogicalElementId].nextLogicalElementId = operationLogicalElementId;
|
|
405
|
+
nextLogicalElementObject[nextLogicalElementId].previousLogicalElementId = operationLogicalElementId;
|
|
406
|
+
|
|
407
|
+
operationLogicalElementObject.previousLogicalElementId = previousLogicalElementId;
|
|
408
|
+
operationLogicalElementObject.nextLogicalElementId = nextLogicalElementId;
|
|
409
|
+
|
|
410
|
+
console.log('after set previous and next: ', {
|
|
411
|
+
previousLogicalElementObject,
|
|
412
|
+
operationLogicalElementObject,
|
|
413
|
+
nextLogicalElementObject
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
operations = Object.assign(previousLogicalElementObject, { [operationLogicalElementId]: operationLogicalElementObject }, nextLogicalElementObject);
|
|
417
|
+
|
|
418
|
+
return [nextLogicalElementId, nextLogicalElementObject, operations, errorsObject, errorsFound];
|
|
419
|
+
|
|
420
|
+
} else {
|
|
421
|
+
errorsObject[previousLogicalElementId] = 'found error that incorrect of logical structure';
|
|
422
|
+
errorsObject[currentLogicalElementId] = 'found error that incorrect of logical structure';
|
|
423
|
+
errorsObject[operationLogicalElementId] = 'found error that incorrect of logical structure';
|
|
424
|
+
errorsFound.push('found error that incorrect of logical structure');
|
|
425
|
+
|
|
426
|
+
return [null, null, null, errorsObject, errorsFound];
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
function findLastLogicalElements(
|
|
433
|
+
initialLogicalElementId,
|
|
434
|
+
logicalElements
|
|
435
|
+
) {
|
|
436
|
+
let lastCurrentLogicalId = null;
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
let logicaclElement = logicalElements[initialLogicalElementId];
|
|
440
|
+
_izContext.logger.debug('logicaclElement: ', logicaclElement);
|
|
441
|
+
|
|
442
|
+
if (logicaclElement.nextLogicalElementId !== null) {
|
|
443
|
+
|
|
444
|
+
lastCurrentLogicalId = findLastLogicalElements(
|
|
445
|
+
logicaclElement.nextLogicalElementId,
|
|
446
|
+
logicalElements
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
} else {
|
|
450
|
+
lastCurrentLogicalId = initialLogicalElementId;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return lastCurrentLogicalId
|
|
454
|
+
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function addBrackets(
|
|
458
|
+
filtersStructure
|
|
459
|
+
) {
|
|
460
|
+
|
|
461
|
+
let logicalElements = {};
|
|
462
|
+
|
|
463
|
+
let uuid_openBracket = uuidV4();
|
|
464
|
+
_izContext.logger.debug('uuid_openBracket: ', uuid_openBracket);
|
|
465
|
+
|
|
466
|
+
let openBracketObject = {
|
|
467
|
+
logicalElementType: "openBracket",
|
|
468
|
+
previousLogicalElementId: null,
|
|
469
|
+
nextLogicalElementId: filtersStructure.initialLogicalElementId
|
|
470
|
+
};
|
|
471
|
+
_izContext.logger.debug('openBracketObject: ', openBracketObject);
|
|
472
|
+
|
|
473
|
+
filtersStructure.logicalElements[filtersStructure.initialLogicalElementId].previousLogicalElementId = uuid_openBracket;
|
|
474
|
+
|
|
475
|
+
let lastLogicalElementId = findLastLogicalElements(
|
|
476
|
+
filtersStructure.initialLogicalElementId,
|
|
477
|
+
filtersStructure.logicalElements
|
|
478
|
+
);
|
|
479
|
+
_izContext.logger.debug('lastLogicalElementId: ', lastLogicalElementId);
|
|
480
|
+
|
|
481
|
+
let uuid_closeBracket = uuidV4();
|
|
482
|
+
_izContext.logger.debug('uuid_closeBracket: ', uuid_closeBracket);
|
|
483
|
+
|
|
484
|
+
filtersStructure.logicalElements[lastLogicalElementId].nextLogicalElementId = uuid_closeBracket;
|
|
485
|
+
|
|
486
|
+
let closeBracket = {
|
|
487
|
+
logicalElementType: "closeBracket",
|
|
488
|
+
previousLogicalElementId: lastLogicalElementId,
|
|
489
|
+
nextLogicalElementId: null
|
|
490
|
+
};
|
|
491
|
+
_izContext.logger.debug('closeBracket: ', closeBracket);
|
|
492
|
+
|
|
493
|
+
logicalElements = Object.assign({ [uuid_openBracket]: openBracketObject }, filtersStructure.logicalElements, { [uuid_closeBracket]: closeBracket });
|
|
494
|
+
_izContext.logger.debug('logicalElements: ', logicalElements);
|
|
495
|
+
|
|
496
|
+
return [
|
|
497
|
+
uuid_openBracket,
|
|
498
|
+
uuid_closeBracket,
|
|
499
|
+
{
|
|
500
|
+
objType: filtersStructure.objType,
|
|
501
|
+
initialLogicalElementId: uuid_openBracket,
|
|
502
|
+
logicalElements: logicalElements
|
|
503
|
+
}
|
|
504
|
+
]
|
|
505
|
+
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function combineLogicalElements(
|
|
509
|
+
firstFilterStructure,
|
|
510
|
+
secondFilterStructure,
|
|
511
|
+
operator = "AND"
|
|
512
|
+
) {
|
|
513
|
+
_izContext.logger.debug('combineLogicalElements: ', {
|
|
514
|
+
firstFilterStructure,
|
|
515
|
+
secondFilterStructure,
|
|
516
|
+
operator
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
let objType = firstFilterStructure.objType;
|
|
520
|
+
|
|
521
|
+
let [firstInitialLogicalElementId, firstLastLogicalElementId, firstFiltersStructureBrcket] = addBrackets(
|
|
522
|
+
firstFilterStructure
|
|
523
|
+
);
|
|
524
|
+
_izContext.logger.debug("first filterStructure addBrackets", {
|
|
525
|
+
firstInitialLogicalElementId,
|
|
526
|
+
firstLastLogicalElementId,
|
|
527
|
+
firstFiltersStructureBrcket
|
|
528
|
+
})
|
|
529
|
+
|
|
530
|
+
let [secondInitialLogicalElementId, secondLastLogicalElementId, secondFiltersStructureBrcket] = addBrackets(
|
|
531
|
+
secondFilterStructure
|
|
532
|
+
);
|
|
533
|
+
_izContext.logger.debug("second filterStructure addBrackets", {
|
|
534
|
+
secondInitialLogicalElementId,
|
|
535
|
+
secondLastLogicalElementId,
|
|
536
|
+
secondFiltersStructureBrcket
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
let uuid_operation = uuidV4();
|
|
540
|
+
_izContext.logger.debug('uuid_operation: ', uuid_operation);
|
|
541
|
+
|
|
542
|
+
let operationObject = {
|
|
543
|
+
logicalElementType: 'operation',
|
|
544
|
+
previousLogicalElementId: firstLastLogicalElementId,
|
|
545
|
+
nextLogicalElementId: secondInitialLogicalElementId,
|
|
546
|
+
operation: operator
|
|
547
|
+
};
|
|
548
|
+
_izContext.logger.debug('operationObject: ', operationObject);
|
|
549
|
+
|
|
550
|
+
firstFiltersStructureBrcket.logicalElements[firstLastLogicalElementId].nextLogicalElementId = uuid_operation;
|
|
551
|
+
secondFiltersStructureBrcket.logicalElements[secondInitialLogicalElementId].previousLogicalElementId = uuid_operation;
|
|
552
|
+
|
|
553
|
+
let logicalElements = Object.assign(firstFiltersStructureBrcket.logicalElements, { [uuid_operation]: operationObject }, secondFiltersStructureBrcket.logicalElements);
|
|
554
|
+
_izContext.logger.debug('logicalElements: ', logicalElements);
|
|
555
|
+
|
|
556
|
+
return {
|
|
557
|
+
objType: objType,
|
|
558
|
+
initialLogicalElementId: firstInitialLogicalElementId,
|
|
559
|
+
logicalElements: logicalElements
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
export default {
|
|
568
|
+
combineLogicalStructure,
|
|
569
|
+
// combineOperation,
|
|
570
|
+
combineLogicalElements,
|
|
571
|
+
addBrackets,
|
|
572
|
+
combineLogicalElements
|
|
573
|
+
}
|