@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
|
@@ -428,146 +428,725 @@ function combineOperation(
|
|
|
428
428
|
|
|
429
429
|
};
|
|
430
430
|
|
|
431
|
+
// function combineLogicalElements(
|
|
432
|
+
// firstFilterStructure,
|
|
433
|
+
// secondFilterStructure,
|
|
434
|
+
// operator = "AND"
|
|
435
|
+
// ) {
|
|
436
|
+
// console.log('combineLogicalElements: ', {
|
|
437
|
+
// firstFilterStructure,
|
|
438
|
+
// secondFilterStructure,
|
|
439
|
+
// operator
|
|
440
|
+
// });
|
|
441
|
+
|
|
442
|
+
// let objType = firstFilterStructure.objType;
|
|
443
|
+
|
|
444
|
+
// let [firstInitialLogicalElementId, firstLastLogicalElementId, firstFiltersStructureBrcket] = addBrackets(
|
|
445
|
+
// firstFilterStructure
|
|
446
|
+
// );
|
|
447
|
+
// console.log("first filterStructure addBrackets", {
|
|
448
|
+
// firstInitialLogicalElementId,
|
|
449
|
+
// firstLastLogicalElementId,
|
|
450
|
+
// firstFiltersStructureBrcket
|
|
451
|
+
// })
|
|
452
|
+
|
|
453
|
+
// let [secondInitialLogicalElementId, secondLastLogicalElementId, secondFiltersStructureBrcket] = addBrackets(
|
|
454
|
+
// secondFilterStructure
|
|
455
|
+
// );
|
|
456
|
+
// console.log("second filterStructure addBrackets", {
|
|
457
|
+
// secondInitialLogicalElementId,
|
|
458
|
+
// secondLastLogicalElementId,
|
|
459
|
+
// secondFiltersStructureBrcket
|
|
460
|
+
// })
|
|
461
|
+
|
|
462
|
+
// let uuid_operation = uuidV4();
|
|
463
|
+
// console.log('uuid_operation: ', uuid_operation);
|
|
464
|
+
|
|
465
|
+
// let operationObject = {
|
|
466
|
+
// logicalElementType: 'operation',
|
|
467
|
+
// previousLogicalElementId: firstLastLogicalElementId,
|
|
468
|
+
// nextLogicalElementId: secondInitialLogicalElementId,
|
|
469
|
+
// operation: operator
|
|
470
|
+
// };
|
|
471
|
+
// console.log('operationObject: ', operationObject);
|
|
472
|
+
|
|
473
|
+
// firstFiltersStructureBrcket.logicalElements[firstLastLogicalElementId].nextLogicalElementId = uuid_operation;
|
|
474
|
+
// secondFiltersStructureBrcket.logicalElements[secondInitialLogicalElementId].previousLogicalElementId = uuid_operation;
|
|
475
|
+
|
|
476
|
+
// let logicalElements = Object.assign(firstFiltersStructureBrcket.logicalElements, { [uuid_operation]: operationObject }, secondFiltersStructureBrcket.logicalElements);
|
|
477
|
+
// console.log('logicalElements: ', logicalElements);
|
|
478
|
+
|
|
479
|
+
// return {
|
|
480
|
+
// objType: objType,
|
|
481
|
+
// initialLogicalElementId: firstInitialLogicalElementId,
|
|
482
|
+
// logicalElements: logicalElements
|
|
483
|
+
// };
|
|
484
|
+
|
|
485
|
+
// }
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
//...function check exist bracket
|
|
489
|
+
function checkAndCreateBracket(filterLogicalStucture) {
|
|
490
|
+
console.log("checkAndCreateBracket params::::", filterLogicalStucture);
|
|
431
491
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
) {
|
|
436
|
-
|
|
492
|
+
let errorsFound = [];
|
|
493
|
+
|
|
494
|
+
// if >1 element need to add brackets
|
|
495
|
+
if (filterLogicalStucture.logicalElements[filterLogicalStucture.initialLogicalElementId].nextLogicalElementId !== null) {
|
|
496
|
+
console.log("nextLogicalElementId != null", filterLogicalStucture.logicalElements[filterLogicalStucture.initialLogicalElementId].nextLogicalElementId);
|
|
497
|
+
[filterLogicalStucture, errorsFound] = createLogicalElementBracket(filterLogicalStucture);
|
|
498
|
+
}
|
|
499
|
+
console.log("nextLogicalElementId = null");
|
|
500
|
+
return [filterLogicalStucture, errorsFound];
|
|
501
|
+
}
|
|
437
502
|
|
|
503
|
+
function createLogicalElementBracket(filterLogicalStucture) {
|
|
504
|
+
console.log("createLogicalElementBracket params::::", filterLogicalStucture);
|
|
438
505
|
|
|
439
|
-
|
|
440
|
-
|
|
506
|
+
// ---- add closeBracket
|
|
507
|
+
console.log("------create closeBracket------");
|
|
508
|
+
const MAX_LOGICAL_ELEMENTS = 1000;
|
|
441
509
|
|
|
442
|
-
|
|
510
|
+
let working_logicalElementId = filterLogicalStucture.initialLogicalElementId;
|
|
443
511
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
)
|
|
512
|
+
for (let infiniteCheck = 0; infiniteCheck <= MAX_LOGICAL_ELEMENTS; infiniteCheck++) {
|
|
513
|
+
//// 1000 should = limit CONST MAX_LOGICAL_ELEMENTS
|
|
514
|
+
// console.log("-----working_logicalElementId-----", working_logicalElementId);
|
|
515
|
+
if (filterLogicalStucture.logicalElements[working_logicalElementId].nextLogicalElementId === null) {
|
|
516
|
+
console.log("-----last logicalElement-----", filterLogicalStucture.logicalElements[working_logicalElementId]);
|
|
517
|
+
let closeBracket_uuid = uuidV4(); //uuidV4
|
|
518
|
+
console.log("closeBracket_uuid", closeBracket_uuid);
|
|
448
519
|
|
|
449
|
-
|
|
450
|
-
|
|
520
|
+
filterLogicalStucture.logicalElements[closeBracket_uuid] = {
|
|
521
|
+
logicalElementType: "closeBracket",
|
|
522
|
+
previousLogicalElementId: working_logicalElementId,
|
|
523
|
+
nextLogicalElementId: null,
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
filterLogicalStucture.logicalElements[working_logicalElementId].nextLogicalElementId = closeBracket_uuid;
|
|
527
|
+
console.log("------filterLogicalStucture before break loop------", filterLogicalStucture);
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
if (infiniteCheck >= MAX_LOGICAL_ELEMENTS) {
|
|
531
|
+
// throw no retry error
|
|
532
|
+
// throw new NoRetryError("Error: max count logicalElement");
|
|
533
|
+
return [null, ["Error: max count logicalElement"]]
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
working_logicalElementId = filterLogicalStucture.logicalElements[working_logicalElementId].nextLogicalElementId;
|
|
451
537
|
}
|
|
452
538
|
|
|
453
|
-
|
|
539
|
+
console.log("------filterLogicalStucture before add open bracket------", filterLogicalStucture);
|
|
540
|
+
|
|
541
|
+
// ---- add openBracket
|
|
542
|
+
|
|
543
|
+
console.log("start create openBracket");
|
|
544
|
+
console.log("start logicalElement====>", filterLogicalStucture.logicalElements[filterLogicalStucture.initialLogicalElementId]);
|
|
545
|
+
|
|
546
|
+
let openBracket_uuid = uuidV4(); //uuidV4
|
|
547
|
+
console.log("openBracket_uuid", openBracket_uuid);
|
|
548
|
+
console.log("filterLogicalStucture before return:::::>>>>", filterLogicalStucture);
|
|
549
|
+
|
|
550
|
+
filterLogicalStucture.logicalElements[openBracket_uuid] = {
|
|
551
|
+
logicalElementType: "openBracket",
|
|
552
|
+
previousLogicalElementId: null,
|
|
553
|
+
nextLogicalElementId: filterLogicalStucture.initialLogicalElementId,
|
|
554
|
+
};
|
|
454
555
|
|
|
556
|
+
filterLogicalStucture.logicalElements[filterLogicalStucture.initialLogicalElementId].previousLogicalElementId = openBracket_uuid;
|
|
557
|
+
filterLogicalStucture.initialLogicalElementId = openBracket_uuid;
|
|
558
|
+
return [filterLogicalStucture, []];
|
|
455
559
|
}
|
|
456
560
|
|
|
457
|
-
function
|
|
458
|
-
|
|
561
|
+
function checkObjType(
|
|
562
|
+
fromObjType,
|
|
563
|
+
toObjType
|
|
459
564
|
) {
|
|
460
565
|
|
|
461
|
-
let
|
|
566
|
+
let from = {
|
|
567
|
+
serviceTag: fromObjType.serviceTag,
|
|
568
|
+
objectType: fromObjType.objectType
|
|
569
|
+
};
|
|
462
570
|
|
|
463
|
-
let
|
|
464
|
-
|
|
571
|
+
let to = {
|
|
572
|
+
serviceTag: toObjType.serviceTag,
|
|
573
|
+
objectType: toObjType.objectType
|
|
574
|
+
};
|
|
465
575
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
previousLogicalElementId: null,
|
|
469
|
-
nextLogicalElementId: filtersStructure.initialLogicalElementId
|
|
576
|
+
if (hash(to) === hash(from)) {
|
|
577
|
+
return true;
|
|
470
578
|
};
|
|
471
|
-
_izContext.logger.debug('openBracketObject: ', openBracketObject);
|
|
472
579
|
|
|
473
|
-
|
|
580
|
+
return false;
|
|
474
581
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// validate to changed searchType and filterType
|
|
585
|
+
/**
|
|
586
|
+
* recieved request thougth sortedResult??? case specail filter
|
|
587
|
+
* @param {string} requiredSearchType
|
|
588
|
+
* @param {string[]} filterArrays
|
|
589
|
+
*
|
|
590
|
+
* return [filters]
|
|
591
|
+
*/
|
|
592
|
+
async function changeObjTypePath(
|
|
593
|
+
requiredObjType,
|
|
594
|
+
filtersStructure,
|
|
595
|
+
path = null,
|
|
596
|
+
) {
|
|
597
|
+
try {
|
|
598
|
+
console.log('----- function validateSearchTypeFilterType -----', {
|
|
599
|
+
requiredObjType,
|
|
600
|
+
filtersStructure,
|
|
601
|
+
path
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
let filterLogicalStructure = {};
|
|
605
|
+
|
|
606
|
+
let errorsObject = {};
|
|
607
|
+
let errorsFound = [];
|
|
608
|
+
|
|
609
|
+
if (path !== null) {
|
|
610
|
+
console.log('-------------- continue process path --------------');
|
|
611
|
+
|
|
612
|
+
let logicalElements = {};
|
|
613
|
+
let previousLogicalElementId = null;
|
|
614
|
+
let previousLogicalElement = null;
|
|
615
|
+
let currentLogicalElementId = null;
|
|
616
|
+
let currentLogicalElement = null;
|
|
617
|
+
|
|
618
|
+
if (path.length > 1) {
|
|
619
|
+
|
|
620
|
+
for (let i = 0; i < path.length; i++) {
|
|
621
|
+
|
|
622
|
+
let pathObject = path[i];
|
|
623
|
+
let logicalStructureElements = filtersStructure.logicalElements;
|
|
624
|
+
console.log('logicalStructureElements', logicalStructureElements);
|
|
625
|
+
|
|
626
|
+
let initialLogicalElementId = filtersStructure.initialLogicalElementId;
|
|
627
|
+
console.log('initialLogicalElementId', initialLogicalElementId);
|
|
480
628
|
|
|
481
|
-
|
|
482
|
-
|
|
629
|
+
if (i + 1 === path.length) {
|
|
630
|
+
console.log(`------------------- final path: ${i} ---------------------`);
|
|
483
631
|
|
|
484
|
-
|
|
632
|
+
if (previousLogicalElementId !== null) {
|
|
485
633
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
634
|
+
if (checkObjType(pathObject.objType, logicalElements[previousLogicalElementId].objType) !== true) {
|
|
635
|
+
errorsFound.push('objType is not equals in structure');
|
|
636
|
+
console.log('before return: ', {
|
|
637
|
+
filterLogicalStructure: {},
|
|
638
|
+
errorsObject,
|
|
639
|
+
errorsFound
|
|
640
|
+
});
|
|
641
|
+
return [{}, errorsObject, errorsFound];
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
filterLogicalStructure = {
|
|
645
|
+
objType: pathObject.objType,
|
|
646
|
+
initialLogicalElementId: previousLogicalElementId,
|
|
647
|
+
logicalElements: logicalElements
|
|
648
|
+
};
|
|
649
|
+
console.log('filterLogicalStructure: ', filterLogicalStructure);
|
|
650
|
+
|
|
651
|
+
} else {
|
|
652
|
+
if (checkObjType(requiredObjType, filtersStructure.objType) === true) {
|
|
653
|
+
filterLogicalStructure = filtersStructure;
|
|
654
|
+
} else {
|
|
655
|
+
errorsFound.push('objType is not equals in structure');
|
|
656
|
+
console.log('before return: ', {
|
|
657
|
+
filterLogicalStructure: {},
|
|
658
|
+
errorsObject,
|
|
659
|
+
errorsFound
|
|
660
|
+
});
|
|
661
|
+
return [{}, errorsObject, errorsFound];
|
|
662
|
+
};
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
} else {
|
|
666
|
+
console.log(`------------------- between path: ${i} ---------------------`);
|
|
667
|
+
|
|
668
|
+
let logicalElementsStructure = logicalStructureElements[initialLogicalElementId];
|
|
669
|
+
console.log('logicalElementsStructure', logicalElementsStructure);
|
|
670
|
+
|
|
671
|
+
if (previousLogicalElement !== null) {
|
|
672
|
+
|
|
673
|
+
currentLogicalElementId = uuidV4();
|
|
674
|
+
console.log('currentLogicalElementId: ', currentLogicalElementId);
|
|
675
|
+
|
|
676
|
+
currentLogicalElement = {
|
|
677
|
+
logicalElementType: 'childComplexFilter',
|
|
678
|
+
previousLogicalElementId: null,
|
|
679
|
+
nextLogicalElementId: null,
|
|
680
|
+
childLogicalElementId: filtersStructure.initialLogicalElementId,
|
|
681
|
+
|
|
682
|
+
objType: pathObject.pathLinkType.objType,
|
|
683
|
+
pathLinkType: {
|
|
684
|
+
objType: pathObject.objType,
|
|
685
|
+
relType: pathObject.pathLinkType.relType,
|
|
686
|
+
direction: pathObject.pathLinkType.direction
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
console.log('currentLogicalElement', currentLogicalElement);
|
|
690
|
+
|
|
691
|
+
let logicalStructure;
|
|
692
|
+
[previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
|
|
693
|
+
logicalElements,
|
|
694
|
+
previousLogicalElementId,
|
|
695
|
+
previousLogicalElement,
|
|
696
|
+
currentLogicalElementId,
|
|
697
|
+
currentLogicalElement,
|
|
698
|
+
filtersStructure
|
|
699
|
+
);
|
|
700
|
+
console.log('return create child ', {
|
|
701
|
+
previousLogicalElementId,
|
|
702
|
+
previousLogicalElement,
|
|
703
|
+
logicalStructure,
|
|
704
|
+
errorsFound
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
logicalElements = logicalStructure;
|
|
708
|
+
|
|
709
|
+
} else {
|
|
710
|
+
|
|
711
|
+
if (logicalElementsStructure.logicalElementType === 'childComplexFilter') {
|
|
712
|
+
|
|
713
|
+
let childLogicalElementId = logicalElementsStructure.childLogicalElementId;
|
|
714
|
+
console.log('childLogicalElementId', childLogicalElementId);
|
|
715
|
+
|
|
716
|
+
if (childLogicalElementId !== null) {
|
|
717
|
+
console.log('-------- has child filter structure --------');
|
|
718
|
+
|
|
719
|
+
let childLogicalElement = logicalStructureElements[childLogicalElementId];
|
|
720
|
+
console.log('childLogicalElement', childLogicalElement);
|
|
721
|
+
|
|
722
|
+
let pathCheck = false;
|
|
723
|
+
|
|
724
|
+
for (const pathObj of path) {
|
|
725
|
+
if (checkObjType(childLogicalElement.objType, pathObj.objType) === true) {
|
|
726
|
+
pathCheck = true;
|
|
727
|
+
};
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
if (pathCheck) {
|
|
731
|
+
|
|
732
|
+
if (logicalElementsStructure.nextLogicalElementId === null) {
|
|
733
|
+
|
|
734
|
+
//* delete level of objType
|
|
735
|
+
let checkChild = false;
|
|
736
|
+
for (const objType of PATHCONSTANCES.objTypes) {
|
|
737
|
+
if (checkObjType(objType, childLogicalElement.objType) === true) {
|
|
738
|
+
if (!childLogicalElement.hasOwnProperty('childLogicalElementId')) {
|
|
739
|
+
|
|
740
|
+
// let childSchema = await getObjectSchema.getObjSchemaS3(
|
|
741
|
+
let childSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(
|
|
742
|
+
{}, //_izContext maybe delete
|
|
743
|
+
childLogicalElement.objType
|
|
744
|
+
);
|
|
745
|
+
console.log('childSchema: ', childSchema);
|
|
746
|
+
|
|
747
|
+
if (childSchema.hasOwnProperty('extendObjType')) {
|
|
748
|
+
if (checkObjType(requiredObjType, childSchema.extendObjType) === true) {
|
|
749
|
+
checkChild = false;
|
|
750
|
+
break;
|
|
751
|
+
};
|
|
752
|
+
};
|
|
753
|
+
};
|
|
754
|
+
checkChild = true;
|
|
755
|
+
break;
|
|
756
|
+
};
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
if (checkChild) {
|
|
760
|
+
|
|
761
|
+
delete filtersStructure.logicalElements[initialLogicalElementId];
|
|
762
|
+
console.log('filtersStructure: ', filtersStructure);
|
|
763
|
+
|
|
764
|
+
filtersStructure.objType = childLogicalElement.objType;
|
|
765
|
+
filtersStructure.initialLogicalElementId = childLogicalElementId;
|
|
766
|
+
filtersStructure.logicalElements[childLogicalElementId].previousLogicalElementId = null;
|
|
767
|
+
console.log('after filtersStructure: ', filtersStructure);
|
|
768
|
+
|
|
769
|
+
logicalElements = filtersStructure.logicalElements;
|
|
770
|
+
|
|
771
|
+
continue;
|
|
772
|
+
|
|
773
|
+
};
|
|
774
|
+
};
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
currentLogicalElementId = uuidV4();
|
|
778
|
+
console.log('currentLogicalElementId: ', currentLogicalElementId)
|
|
779
|
+
|
|
780
|
+
currentLogicalElement = {
|
|
781
|
+
logicalElementType: 'childComplexFilter',
|
|
782
|
+
previousLogicalElementId: null,
|
|
783
|
+
nextLogicalElementId: null,
|
|
784
|
+
childLogicalElementId: filtersStructure.initialLogicalElementId,
|
|
785
|
+
|
|
786
|
+
objType: pathObject.pathLinkType.objType,
|
|
787
|
+
pathLinkType: {
|
|
788
|
+
objType: pathObject.objType,
|
|
789
|
+
relType: pathObject.pathLinkType.relType,
|
|
790
|
+
direction: pathObject.pathLinkType.direction
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
console.log('currentLogicalElement', currentLogicalElement);
|
|
794
|
+
|
|
795
|
+
let logicalStructure = {};
|
|
796
|
+
[previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
|
|
797
|
+
_izContext,
|
|
798
|
+
logicalElements,
|
|
799
|
+
previousLogicalElementId,
|
|
800
|
+
previousLogicalElement,
|
|
801
|
+
currentLogicalElementId,
|
|
802
|
+
currentLogicalElement,
|
|
803
|
+
filtersStructure
|
|
804
|
+
)
|
|
805
|
+
console.log('return create child', {
|
|
806
|
+
previousLogicalElementId,
|
|
807
|
+
previousLogicalElement,
|
|
808
|
+
logicalStructure,
|
|
809
|
+
errorsFound
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
logicalElements = logicalStructure;
|
|
813
|
+
console.log('logicalElements: ', logicalElements);
|
|
814
|
+
|
|
815
|
+
// if (logicalElementsStructure.nextLogicalElementId !== null) {
|
|
816
|
+
// console.log("-------- no child filter structure --------", vvv);
|
|
817
|
+
// }
|
|
818
|
+
|
|
819
|
+
} else {
|
|
820
|
+
console.log('-------- no child filter structure --------', vvv);
|
|
821
|
+
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
} else {
|
|
825
|
+
|
|
826
|
+
currentLogicalElementId = uuidV4();
|
|
827
|
+
console.log('currentLogicalElementId: ', currentLogicalElementId);
|
|
828
|
+
|
|
829
|
+
currentLogicalElement = {
|
|
830
|
+
logicalElementType: 'childComplexFilter',
|
|
831
|
+
previousLogicalElementId: null,
|
|
832
|
+
nextLogicalElementId: null,
|
|
833
|
+
childLogicalElementId: filtersStructure.initialLogicalElementId,
|
|
834
|
+
|
|
835
|
+
objType: pathObject.pathLinkType.objType,
|
|
836
|
+
pathLinkType: {
|
|
837
|
+
objType: pathObject.objType,
|
|
838
|
+
relType: pathObject.pathLinkType.relType,
|
|
839
|
+
direction: pathObject.pathLinkType.direction
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
console.log('currentLogicalElement', currentLogicalElement);
|
|
843
|
+
|
|
844
|
+
let logicalStructure = {};
|
|
845
|
+
// change function name ==> set logicalElementId
|
|
846
|
+
[previousLogicalElementId, previousLogicalElement, logicalStructure, errorsFound] = createChildComplexFilterStructure(
|
|
847
|
+
_izContext,
|
|
848
|
+
logicalElements,
|
|
849
|
+
previousLogicalElementId,
|
|
850
|
+
previousLogicalElement,
|
|
851
|
+
currentLogicalElementId,
|
|
852
|
+
currentLogicalElement,
|
|
853
|
+
filtersStructure
|
|
854
|
+
)
|
|
855
|
+
console.log('return create child', {
|
|
856
|
+
previousLogicalElementId,
|
|
857
|
+
previousLogicalElement,
|
|
858
|
+
logicalStructure,
|
|
859
|
+
errorsFound
|
|
860
|
+
});
|
|
861
|
+
logicalElements = logicalStructure;
|
|
862
|
+
};
|
|
863
|
+
};
|
|
864
|
+
};
|
|
865
|
+
};
|
|
866
|
+
} else {
|
|
867
|
+
console.log('------------ path euals 1 -----------');
|
|
868
|
+
console.log('pathObject', path[0]);
|
|
869
|
+
|
|
870
|
+
if (checkObjType(requiredObjType, filtersStructure.objType) === true) {
|
|
871
|
+
filterLogicalStructure = filtersStructure;
|
|
872
|
+
} else {
|
|
873
|
+
errorsObject = {
|
|
874
|
+
[requiredObjType.objectType]: `is not equals objType in filter structure: objType: ${filtersStructure.objType.objectType}`
|
|
875
|
+
};
|
|
876
|
+
errorsFound.push(`${requiredObjType.objectType} is not equals objType in filter structure: objType: ${filtersStructure.objType.objectType}`);
|
|
877
|
+
return [filterLogicalStructure, errorsObject, errorsFound];
|
|
878
|
+
};
|
|
879
|
+
};
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
console.log('before return filterLogicalStructure: ', {
|
|
883
|
+
path,
|
|
884
|
+
filterLogicalStructure,
|
|
885
|
+
errorsObject,
|
|
886
|
+
errorsFound
|
|
887
|
+
});
|
|
888
|
+
return [filterLogicalStructure, errorsObject, errorsFound];
|
|
889
|
+
|
|
890
|
+
} catch (err) {
|
|
891
|
+
_izContext.logger.error('error ValidateSearchTypeFilterType: ', err)
|
|
892
|
+
throw (err);
|
|
490
893
|
};
|
|
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
894
|
|
|
506
|
-
}
|
|
895
|
+
};
|
|
896
|
+
//###################################################################################################################################################################################
|
|
507
897
|
|
|
508
|
-
function
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
898
|
+
function createChildComplexFilterStructure(
|
|
899
|
+
logicalElements,
|
|
900
|
+
previousLogicalElementId,
|
|
901
|
+
previousLogicalElement,
|
|
902
|
+
currentLogicalElementId,
|
|
903
|
+
currentLogicalElement,
|
|
904
|
+
filtersStructure
|
|
512
905
|
) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
906
|
+
console.log('createChildComplexFilterStructure: ', {
|
|
907
|
+
logicalElements,
|
|
908
|
+
previousLogicalElementId,
|
|
909
|
+
previousLogicalElement,
|
|
910
|
+
currentLogicalElementId,
|
|
911
|
+
currentLogicalElement,
|
|
912
|
+
filtersStructure
|
|
517
913
|
});
|
|
518
914
|
|
|
519
|
-
let
|
|
915
|
+
let errorsFound = [];
|
|
520
916
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
917
|
+
if (!currentLogicalElement) {
|
|
918
|
+
errorsFound.push('no current logical element to process');
|
|
919
|
+
return [previousLogicalElementId, previousLogicalElement, logicalElements, errorsFound];
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
if (!previousLogicalElement) {
|
|
923
|
+
filtersStructure.logicalElements[filtersStructure.initialLogicalElementId].previousLogicalElementId = currentLogicalElementId;
|
|
924
|
+
logicalElements = Object.assign({ [currentLogicalElementId]: currentLogicalElement }, logicalElements, filtersStructure.logicalElements);
|
|
925
|
+
} else {
|
|
926
|
+
|
|
927
|
+
currentLogicalElement.childLogicalElementId = previousLogicalElementId;
|
|
928
|
+
console.log('currentLogicalElement', currentLogicalElement);
|
|
929
|
+
|
|
930
|
+
logicalElements[previousLogicalElementId].previousLogicalElementId = currentLogicalElementId;
|
|
931
|
+
console.log('logicalElements', logicalElements);
|
|
932
|
+
|
|
933
|
+
logicalElements = Object.assign({ [currentLogicalElementId]: currentLogicalElement }, logicalElements);
|
|
934
|
+
console.log('after logicalElements', logicalElements);
|
|
935
|
+
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
previousLogicalElementId = currentLogicalElementId;
|
|
939
|
+
previousLogicalElement = currentLogicalElement;
|
|
940
|
+
|
|
941
|
+
return [previousLogicalElementId, previousLogicalElement, logicalElements, errorsFound];
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
async function findObjTypePathToAnotherObjType(
|
|
945
|
+
fromObjType,
|
|
946
|
+
toObjType,
|
|
947
|
+
PATHCONSTANCES
|
|
948
|
+
) {
|
|
949
|
+
console.log('----- function findObjTypePathToAnotherObjType -----', {
|
|
950
|
+
fromObjType,
|
|
951
|
+
toObjType
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
let [path, errorsObject, errorsFound] = await recursiveFindObjTypeTypePathToAnotherObjType(
|
|
955
|
+
PATHCONSTANCES,
|
|
956
|
+
fromObjType,
|
|
957
|
+
toObjType,
|
|
532
958
|
);
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
let operationObject = {
|
|
543
|
-
logicalElementType: 'operation',
|
|
544
|
-
previousLogicalElementId: firstLastLogicalElementId,
|
|
545
|
-
nextLogicalElementId: secondInitialLogicalElementId,
|
|
546
|
-
operation: operator
|
|
959
|
+
console.log('return path', {
|
|
960
|
+
path,
|
|
961
|
+
errorsObject,
|
|
962
|
+
errorsFound
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
if (path !== null) {
|
|
966
|
+
console.log('--------------- will return -----------------');
|
|
967
|
+
return [path, errorsObject, errorsFound];
|
|
547
968
|
};
|
|
548
|
-
_izContext.logger.debug('operationObject: ', operationObject);
|
|
549
969
|
|
|
550
|
-
|
|
551
|
-
secondFiltersStructureBrcket.logicalElements[secondInitialLogicalElementId].previousLogicalElementId = uuid_operation;
|
|
970
|
+
return [path, errorsObject, errorsFound];
|
|
552
971
|
|
|
553
|
-
|
|
554
|
-
_izContext.logger.debug('logicalElements: ', logicalElements);
|
|
972
|
+
};
|
|
555
973
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
974
|
+
async function recursiveFindObjTypeTypePathToAnotherObjType(
|
|
975
|
+
PATHCONSTANCES,
|
|
976
|
+
fromObjType,
|
|
977
|
+
toObjType,
|
|
978
|
+
iter = 1
|
|
979
|
+
) {
|
|
980
|
+
console.log('----- function recursiveFindObjTypeTypePathToAnotherObjType -----', {
|
|
981
|
+
PATHCONSTANCES,
|
|
982
|
+
fromObjType,
|
|
983
|
+
toObjType,
|
|
984
|
+
iter
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
let errorsObject = {};
|
|
988
|
+
let errorsFound = [];
|
|
989
|
+
|
|
990
|
+
let continueProcess = false;
|
|
991
|
+
|
|
992
|
+
for (const objType of PATHCONSTANCES.objTypes) {
|
|
993
|
+
console.log('objType: ', objType);
|
|
994
|
+
if (checkObjType(fromObjType, objType) === true) {
|
|
995
|
+
// if (hash(fromObjType) === hash(objType)) {
|
|
996
|
+
continueProcess = true;
|
|
997
|
+
};
|
|
560
998
|
};
|
|
561
999
|
|
|
562
|
-
|
|
1000
|
+
if (continueProcess) {
|
|
1001
|
+
console.log('------------ continue to find path --------------');
|
|
563
1002
|
|
|
1003
|
+
if (checkObjType(fromObjType, toObjType) === true) {
|
|
1004
|
+
// if (hash(fromObjType) === hash(toObjType)) {
|
|
1005
|
+
return [[{ objType: toObjType }], errorsObject, errorsFound];
|
|
1006
|
+
};
|
|
564
1007
|
|
|
1008
|
+
if (iter >= MAX_ITER) {
|
|
1009
|
+
return [null, errorsObject, errorsFound];
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
// let objectRelationship = await getObjectSchema.getObjectRelationshipWithCache(
|
|
1013
|
+
const objectRelationship = await getObjectSchema.getObjectRelationship(
|
|
1014
|
+
{}, //_izContext maybe delete
|
|
1015
|
+
fromObjType
|
|
1016
|
+
);
|
|
1017
|
+
console.log("objectRelationship: ", { fromObjType, objectRelationship });
|
|
1018
|
+
|
|
1019
|
+
let path = null;
|
|
1020
|
+
let previousNextPath = null;
|
|
1021
|
+
let currentNextPath = null;
|
|
1022
|
+
|
|
1023
|
+
for (const relationshipObject of objectRelationship) {
|
|
1024
|
+
console.log('relationshipObject: ', relationshipObject);
|
|
1025
|
+
|
|
1026
|
+
let relType = relationshipObject.relType;
|
|
1027
|
+
console.log('relType: ', relType);
|
|
1028
|
+
|
|
1029
|
+
let otherObjType = relationshipObject.other.objType;
|
|
1030
|
+
console.log('otherObjType: ', otherObjType);
|
|
1031
|
+
|
|
1032
|
+
let relCheck = false;
|
|
1033
|
+
|
|
1034
|
+
for (const relPath of PATHCONSTANCES.relTypes) {
|
|
1035
|
+
if (hash(relType) === hash(relPath)) {
|
|
1036
|
+
relCheck = true;
|
|
1037
|
+
break;
|
|
1038
|
+
};
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
if (!relCheck) {
|
|
1042
|
+
//* no relationshipTag in constance
|
|
1043
|
+
continue;
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
// const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
|
|
1047
|
+
const objectSchema = await getObjectSchema.getObjSchemaS3WithoutHierarchy(
|
|
1048
|
+
{}, //_izContext maybe delete
|
|
1049
|
+
toObjType,
|
|
1050
|
+
);
|
|
1051
|
+
console.log('objectSchema: ', objectSchema);
|
|
1052
|
+
console.log('before relationshipObject: ', {
|
|
1053
|
+
from: fromObjType,
|
|
1054
|
+
to: toObjType,
|
|
1055
|
+
next: otherObjType,
|
|
1056
|
+
relationshipObject
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
if (objectSchema.hasOwnProperty('extendObjType')) {
|
|
1060
|
+
if (checkObjType(otherObjType, objectSchema.extendObjType) === true) {
|
|
1061
|
+
// if (hash(nextObjType) === hash(objectSchema.extendObjType)) {
|
|
1062
|
+
otherObjType = toObjType;
|
|
1063
|
+
};
|
|
1064
|
+
};
|
|
1065
|
+
console.log('after relationshipObject: ', {
|
|
1066
|
+
from: fromObjType,
|
|
1067
|
+
to: toObjType,
|
|
1068
|
+
next: otherObjType,
|
|
1069
|
+
relationshipObject
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
let pathErrorsObject;
|
|
1073
|
+
let pathErrorsFound;
|
|
1074
|
+
|
|
1075
|
+
//* recurvsive path
|
|
1076
|
+
[currentNextPath, pathErrorsObject, pathErrorsFound] = await recursiveFindObjTypeTypePathToAnotherObjType(
|
|
1077
|
+
PATHCONSTANCES,
|
|
1078
|
+
otherObjType,
|
|
1079
|
+
toObjType,
|
|
1080
|
+
iter + 1
|
|
1081
|
+
);
|
|
1082
|
+
console.log('return recursive path: ', {
|
|
1083
|
+
currentNextPath,
|
|
1084
|
+
pathErrorsObject,
|
|
1085
|
+
pathErrorsFound
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
if (currentNextPath !== null) {
|
|
1089
|
+
|
|
1090
|
+
previousNextPath = currentNextPath;
|
|
1091
|
+
|
|
1092
|
+
let addPath = {
|
|
1093
|
+
objType: fromObjType,
|
|
1094
|
+
pathLinkType: {
|
|
1095
|
+
objType: otherObjType,
|
|
1096
|
+
relType: relType,
|
|
1097
|
+
direction: relationshipObject.other.direction
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
console.log('addPath: ', addPath);
|
|
1101
|
+
|
|
1102
|
+
previousNextPath.unshift(addPath);
|
|
1103
|
+
console.log('path: ', path);
|
|
1104
|
+
|
|
1105
|
+
} else {
|
|
1106
|
+
continue;
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
if (previousNextPath !== null) {
|
|
1110
|
+
if (path !== null) {
|
|
1111
|
+
if (path.length > previousNextPath.length) {
|
|
1112
|
+
path = previousNextPath;
|
|
1113
|
+
};
|
|
1114
|
+
console.log('path: ', path);
|
|
1115
|
+
return [path, errorsObject, errorsFound];
|
|
1116
|
+
} else {
|
|
1117
|
+
path = previousNextPath;
|
|
1118
|
+
};
|
|
1119
|
+
};
|
|
1120
|
+
};// end iterate relType
|
|
1121
|
+
|
|
1122
|
+
// if (previousNextPath !== null) {
|
|
1123
|
+
if (path !== null) {
|
|
1124
|
+
if (path.length > previousNextPath.length) {
|
|
1125
|
+
path = previousNextPath;
|
|
1126
|
+
};
|
|
1127
|
+
console.log('path: ', path);
|
|
1128
|
+
return [path, errorsObject, errorsFound];
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
} else {
|
|
1132
|
+
errorsObject = {
|
|
1133
|
+
[fromObjType.objectType]: 'cannot found this objType that can process in path'
|
|
1134
|
+
};
|
|
1135
|
+
errorsFound.push(`${fromObjType.objectType}: cannot found objType that can process in path`);
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
return [null, errorsObject, errorsFound];
|
|
1139
|
+
|
|
1140
|
+
};
|
|
565
1141
|
|
|
566
1142
|
|
|
567
1143
|
export default {
|
|
568
1144
|
combineLogicalStructure,
|
|
569
1145
|
// combineOperation,
|
|
570
|
-
combineLogicalElements,
|
|
571
|
-
|
|
572
|
-
|
|
1146
|
+
// combineLogicalElements,
|
|
1147
|
+
|
|
1148
|
+
checkAndCreateBracket,
|
|
1149
|
+
|
|
1150
|
+
changeObjTypePath,
|
|
1151
|
+
findObjTypePathToAnotherObjType
|
|
573
1152
|
}
|