@@ -128,7 +128,7 @@ private NetworkModificationNode createAndInsertNode(StudyEntity study, UUID node
128
128
if (insertMode .equals (InsertMode .BEFORE )) {
129
129
reference .setParentNode (node );
130
130
} else if (insertMode .equals (InsertMode .AFTER )) {
131
- nodesRepository . findAllByParentNodeIdNode (nodeId ).stream ()
131
+ getChildren (nodeId ).stream ()
132
132
.filter (n -> !n .getIdNode ().equals (node .getIdNode ()))
133
133
.forEach (child -> child .setParentNode (node ));
134
134
}
@@ -238,7 +238,7 @@ public void moveStudyNode(UUID nodeToMoveUuid, UUID anchorNodeUuid, InsertMode i
238
238
private UUID moveNode (UUID nodeToMoveUuid , UUID anchorNodeUuid , InsertMode insertMode ) {
239
239
NodeEntity nodeToMoveEntity = getNodeEntity (nodeToMoveUuid );
240
240
241
- nodesRepository . findAllByParentNodeIdNode (nodeToMoveUuid )
241
+ getChildren (nodeToMoveUuid )
242
242
.forEach (child -> child .setParentNode (nodeToMoveEntity .getParentNode ()));
243
243
244
244
NodeEntity anchorNodeEntity = getNodeEntity (anchorNodeUuid );
@@ -253,7 +253,7 @@ private UUID moveNode(UUID nodeToMoveUuid, UUID anchorNodeUuid, InsertMode inser
253
253
if (insertMode .equals (InsertMode .BEFORE )) {
254
254
anchorNodeEntity .setParentNode (nodeToMoveEntity );
255
255
} else if (insertMode .equals (InsertMode .AFTER )) {
256
- nodesRepository . findAllByParentNodeIdNode (anchorNodeUuid ).stream ()
256
+ getChildren (anchorNodeUuid ).stream ()
257
257
.filter (n -> !n .getIdNode ().equals (nodeToMoveEntity .getIdNode ()))
258
258
.forEach (child -> child .setParentNode (nodeToMoveEntity ));
259
259
}
@@ -264,7 +264,7 @@ private UUID moveNode(UUID nodeToMoveUuid, UUID anchorNodeUuid, InsertMode inser
264
264
265
265
@ Transactional
266
266
public void moveStudySubtree (UUID parentNodeToMoveUuid , UUID anchorNodeUuid ) {
267
- List <NodeEntity > children = getChildrenByParentUuid (parentNodeToMoveUuid );
267
+ List <NodeEntity > children = getChildren (parentNodeToMoveUuid );
268
268
moveNode (parentNodeToMoveUuid , anchorNodeUuid , InsertMode .CHILD );
269
269
children .forEach (child -> self .moveStudySubtree (child .getIdNode (), parentNodeToMoveUuid ));
270
270
}
@@ -299,9 +299,9 @@ private void stashNodes(UUID id, boolean stashChildren, List<UUID> stashedNodes,
299
299
UUID modificationGroupUuid = self .getModificationGroupUuid (nodeToStash .getIdNode ());
300
300
networkModificationService .deleteStashedModifications (modificationGroupUuid );
301
301
if (!stashChildren ) {
302
- nodesRepository . findAllByParentNodeIdNode (id ).forEach (node -> node .setParentNode (nodeToStash .getParentNode ()));
302
+ getChildren (id ).forEach (node -> node .setParentNode (nodeToStash .getParentNode ()));
303
303
} else {
304
- nodesRepository . findAllByParentNodeIdNode (id )
304
+ getChildren (id )
305
305
.forEach (child -> stashNodes (child .getIdNode (), true , stashedNodes , false ));
306
306
}
307
307
stashedNodes .add (id );
@@ -329,9 +329,9 @@ private void deleteNodes(UUID id, boolean deleteChildren, boolean allowDeleteRoo
329
329
rootNetworkNodeInfoService .fillDeleteNodeInfo (id , deleteNodeInfos );
330
330
331
331
if (!deleteChildren ) {
332
- nodesRepository . findAllByParentNodeIdNode (id ).forEach (node -> node .setParentNode (nodeToDelete .getParentNode ()));
332
+ getChildren (id ).forEach (node -> node .setParentNode (nodeToDelete .getParentNode ()));
333
333
} else {
334
- nodesRepository . findAllByParentNodeIdNode (id )
334
+ getChildren (id )
335
335
.forEach (child -> deleteNodes (child .getIdNode (), true , false , removedNodes , deleteNodeInfos ));
336
336
}
337
337
removedNodes .add (id );
@@ -344,12 +344,28 @@ private void deleteNodes(UUID id, boolean deleteChildren, boolean allowDeleteRoo
344
344
});
345
345
}
346
346
347
- public List <NodeEntity > getChildrenByParentUuid (UUID parentUuid ) {
347
+ public List <NodeEntity > getChildren (UUID parentUuid ) {
348
348
return nodesRepository .findAllByParentNodeIdNode (parentUuid );
349
349
}
350
350
351
- public List <String > getAllChildrenFromParentUuid (UUID parentUuid ) {
352
- return nodesRepository .findAllDescendants (parentUuid );
351
+ public List <UUID > getAllChildrenUuids (UUID parentUuid ) {
352
+ return nodesRepository .findAllChildrenUuids (parentUuid );
353
+ }
354
+
355
+ // TODO Remove this method and use getAllChildrenUuids
356
+ public List <UUID > getChildrenUuids (UUID parentUuid ) {
357
+ List <UUID > children = new ArrayList <>();
358
+ doGetChildrenUuids (parentUuid , children );
359
+ return children ;
360
+ }
361
+
362
+ private void doGetChildrenUuids (UUID parentUuid , List <UUID > children ) {
363
+ Optional <NodeEntity > optNode = nodesRepository .findById (parentUuid );
364
+ optNode .ifPresent (node -> getChildren (parentUuid )
365
+ .forEach (child -> {
366
+ children .add (child .getIdNode ());
367
+ doGetChildrenUuids (child .getIdNode (), children );
368
+ }));
353
369
}
354
370
355
371
@ Transactional
@@ -411,10 +427,7 @@ private void completeNodeInfos(List<AbstractNode> nodes, UUID rootNetworkUuid) {
411
427
412
428
@ Transactional
413
429
public AbstractNode getStudySubtree (UUID studyId , UUID parentNodeUuid , UUID rootNetworkUuid ) {
414
- // TODO: not working because of proxy appearing in tests TOFIX later
415
- // List<UUID> nodeUuids = nodesRepository.findAllDescendants(parentNodeUuid).stream().map(UUID::fromString).toList();
416
- // List<NodeEntity> nodes = nodesRepository.findAllById(nodeUuids);
417
- List <NodeEntity > nodes = nodesRepository .findAllByStudyId (studyId );
430
+ List <NodeEntity > nodes = nodesRepository .findAllChildren (parentNodeUuid );
418
431
419
432
List <AbstractNode > allNodeInfos = new ArrayList <>();
420
433
allNodeInfos .addAll (rootNodeInfoRepository .findAllByNodeStudyId (studyId ).stream ().map (RootNodeInfoEntity ::toDto ).toList ());
@@ -561,7 +574,7 @@ private AbstractNode getSimpleNode(UUID nodeId) {
561
574
@ Transactional
562
575
public AbstractNode getNode (UUID nodeId , UUID rootNetworkUuid ) {
563
576
AbstractNode node = getSimpleNode (nodeId );
564
- nodesRepository . findAllByParentNodeIdNode (node .getId ()).stream ().map (NodeEntity ::getIdNode ).forEach (node .getChildrenIds ()::add );
577
+ getChildren (node .getId ()).stream ().map (NodeEntity ::getIdNode ).forEach (node .getChildrenIds ()::add );
565
578
if (rootNetworkUuid != null ) {
566
579
completeNodeInfos (List .of (node ), rootNetworkUuid );
567
580
}
@@ -691,7 +704,7 @@ public List<Pair<AbstractNode, Integer>> getStashedNodes(UUID studyUuid) {
691
704
nodes .stream ().map (node -> networkModificationNodeInfos .get (node .getIdNode ()))
692
705
.forEach (abstractNode -> {
693
706
ArrayList <UUID > children = new ArrayList <>();
694
- doGetChildren (abstractNode .getId (), children );
707
+ doGetChildrenUuids (abstractNode .getId (), children );
695
708
result .add (Pair .of (abstractNode , children .size ()));
696
709
});
697
710
return result ;
@@ -746,7 +759,7 @@ public Map<UUID, UUID> getModificationReports(UUID nodeUuid, UUID rootNetworkUui
746
759
}
747
760
748
761
private void restoreNodeChildren (UUID studyId , UUID parentNodeId ) {
749
- nodesRepository . findAllByParentNodeIdNode (parentNodeId ).forEach (nodeEntity -> {
762
+ getChildren (parentNodeId ).forEach (nodeEntity -> {
750
763
NetworkModificationNodeInfoEntity modificationNodeToRestore = networkModificationNodeInfoRepository .findById (nodeEntity .getIdNode ()).orElseThrow (() -> new StudyException (NODE_NOT_FOUND ));
751
764
if (self .isNodeNameExists (studyId , modificationNodeToRestore .getName ())) {
752
765
String newName = getSuffixedNodeName (studyId , modificationNodeToRestore .getName ());
@@ -883,7 +896,7 @@ private boolean hasAnyBuiltChildren(NodeEntity node, UUID rootNetworkUuid, Set<N
883
896
}
884
897
checkedChildren .add (node );
885
898
886
- for (NodeEntity child : getChildrenByParentUuid (node .getIdNode ())) {
899
+ for (NodeEntity child : getChildren (node .getIdNode ())) {
887
900
if (!checkedChildren .contains (child )
888
901
&& hasAnyBuiltChildren (child , rootNetworkUuid , checkedChildren )) {
889
902
return true ;
@@ -919,11 +932,12 @@ private void fillIndexedNodeTreeInfosToInvalidate(NodeEntity nodeEntity, UUID ro
919
932
920
933
private InvalidateNodeInfos invalidateChildrenNodes (UUID nodeUuid , UUID rootNetworkUuid ) {
921
934
InvalidateNodeInfos invalidateNodeInfos = new InvalidateNodeInfos ();
922
- nodesRepository .findAllByParentNodeIdNode (nodeUuid )
923
- .forEach (child -> {
924
- invalidateNodeInfos .add (rootNetworkNodeInfoService .invalidateRootNetworkNode (child .getIdNode (), rootNetworkUuid , InvalidateNodeTreeParameters .ALL ));
925
- invalidateNodeInfos .add (invalidateChildrenNodes (child .getIdNode (), rootNetworkUuid ));
926
- });
935
+ List <RootNetworkNodeInfoEntity > rootNetworkNodeInfoEntities = rootNetworkNodeInfoService .getRootNetworkNodes (rootNetworkUuid , getAllChildrenUuids (nodeUuid ));
936
+
937
+ rootNetworkNodeInfoEntities .forEach (child ->
938
+ invalidateNodeInfos .add (rootNetworkNodeInfoService .invalidateRootNetworkNode (child , InvalidateNodeTreeParameters .ALL ))
939
+ );
940
+
927
941
return invalidateNodeInfos ;
928
942
}
929
943
@@ -1010,21 +1024,6 @@ public Boolean isReadOnly(UUID nodeUuid) {
1010
1024
return getNodeInfoEntity (nodeUuid ).getReadOnly ();
1011
1025
}
1012
1026
1013
- public List <UUID > getChildren (UUID id ) {
1014
- List <UUID > children = new ArrayList <>();
1015
- doGetChildren (id , children );
1016
- return children ;
1017
- }
1018
-
1019
- private void doGetChildren (UUID id , List <UUID > children ) {
1020
- Optional <NodeEntity > optNode = nodesRepository .findById (id );
1021
- optNode .ifPresent (node -> nodesRepository .findAllByParentNodeIdNode (id )
1022
- .forEach (child -> {
1023
- children .add (child .getIdNode ());
1024
- doGetChildren (child .getIdNode (), children );
1025
- }));
1026
- }
1027
-
1028
1027
// only used for tests
1029
1028
@ Transactional
1030
1029
public UUID getParentNode (UUID nodeUuid , NodeType nodeType ) {
@@ -1060,7 +1059,7 @@ private void fillIndexedNodeInfosToInvalidate(UUID parentNodeUuid, boolean inclu
1060
1059
if (includeParentNode ) {
1061
1060
nodesToInvalidate .add (parentNodeUuid );
1062
1061
}
1063
- nodesToInvalidate .addAll (getChildren (parentNodeUuid ));
1062
+ nodesToInvalidate .addAll (getAllChildrenUuids (parentNodeUuid ));
1064
1063
invalidateNodeInfos .addGroupUuids (
1065
1064
networkModificationNodeInfoRepository .findAllById (nodesToInvalidate ).stream ()
1066
1065
.map (NetworkModificationNodeInfoEntity ::getModificationGroupUuid ).toList ()
0 commit comments