diff --git a/src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NodeRepository.java b/src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NodeRepository.java index 2395be9b7..6954f8e44 100644 --- a/src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NodeRepository.java +++ b/src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NodeRepository.java @@ -29,21 +29,32 @@ public interface NodeRepository extends JpaRepository { List findAllByStudyIdAndTypeAndStashed(UUID id, NodeType type, boolean stashed); @Query(nativeQuery = true, value = - "WITH RECURSIVE NodeHierarchy (id_node, depth) AS ( " + - " SELECT n0.id_node, 0 AS depth" + + "WITH RECURSIVE NodeHierarchy (id_node) AS ( " + + " SELECT n0.id_node" + " FROM NODE n0 " + " WHERE id_node = :nodeUuid " + " UNION ALL " + - " SELECT n.id_node, nh.depth + 1 as depth" + + " SELECT n.id_node" + " FROM NODE n " + " INNER JOIN NodeHierarchy nh ON n.parent_node = nh.id_node " + ") " + - "SELECT nh.id_node::text " + - "FROM NodeHierarchy nh " + - "ORDER BY nh.depth DESC") - List findAllDescendants(UUID nodeUuid); + "SELECT cast(nh.id_node AS VARCHAR) " + + "FROM NodeHierarchy nh where nh.id_node != :nodeUuid ") + List findAllChildrenUuids(UUID nodeUuid); - List findAllByIdNodeIn(List uuids); + @Query(nativeQuery = true, value = + "WITH RECURSIVE NodeHierarchy (id_node) AS ( " + + " SELECT n0.id_node" + + " FROM NODE n0 " + + " WHERE id_node = :nodeUuid " + + " UNION ALL " + + " SELECT n.id_node" + + " FROM NODE n " + + " INNER JOIN NodeHierarchy nh ON n.parent_node = nh.id_node " + + ") " + + "SELECT * FROM NODE n " + + "WHERE n.id_node IN (SELECT nh.id_node FROM NodeHierarchy nh) AND n.id_node != :nodeUuid") + List findAllChildren(UUID nodeUuid); List findAllByStudyIdAndStashedAndParentNodeIdNodeOrderByStashDateDesc(UUID id, boolean stashed, UUID parentNode); diff --git a/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkNodeInfoRepository.java b/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkNodeInfoRepository.java index 2e69c3688..796304fb5 100644 --- a/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkNodeInfoRepository.java +++ b/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkNodeInfoRepository.java @@ -57,4 +57,6 @@ public interface RootNetworkNodeInfoRepository extends JpaRepository 0 from RootNetworkNodeInfoEntity rnni LEFT JOIN rnni.rootNetwork rn LEFT JOIN rn.study s " + "where s.id = :studyUuid and (rnni.nodeBuildStatus.globalBuildStatus = :buildStatus or rnni.nodeBuildStatus.localBuildStatus = :buildStatus)") boolean existsByStudyUuidAndBuildStatus(UUID studyUuid, BuildStatus buildStatus); + + List getAllByRootNetworkIdAndNodeInfoIdIn(UUID rootNetworkUuid, List nodesUuids); } diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java index 561ea11d0..5ae4b5219 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -128,7 +128,7 @@ private NetworkModificationNode createAndInsertNode(StudyEntity study, UUID node if (insertMode.equals(InsertMode.BEFORE)) { reference.setParentNode(node); } else if (insertMode.equals(InsertMode.AFTER)) { - nodesRepository.findAllByParentNodeIdNode(nodeId).stream() + getChildren(nodeId).stream() .filter(n -> !n.getIdNode().equals(node.getIdNode())) .forEach(child -> child.setParentNode(node)); } @@ -238,7 +238,7 @@ public void moveStudyNode(UUID nodeToMoveUuid, UUID anchorNodeUuid, InsertMode i private UUID moveNode(UUID nodeToMoveUuid, UUID anchorNodeUuid, InsertMode insertMode) { NodeEntity nodeToMoveEntity = getNodeEntity(nodeToMoveUuid); - nodesRepository.findAllByParentNodeIdNode(nodeToMoveUuid) + getChildren(nodeToMoveUuid) .forEach(child -> child.setParentNode(nodeToMoveEntity.getParentNode())); NodeEntity anchorNodeEntity = getNodeEntity(anchorNodeUuid); @@ -253,7 +253,7 @@ private UUID moveNode(UUID nodeToMoveUuid, UUID anchorNodeUuid, InsertMode inser if (insertMode.equals(InsertMode.BEFORE)) { anchorNodeEntity.setParentNode(nodeToMoveEntity); } else if (insertMode.equals(InsertMode.AFTER)) { - nodesRepository.findAllByParentNodeIdNode(anchorNodeUuid).stream() + getChildren(anchorNodeUuid).stream() .filter(n -> !n.getIdNode().equals(nodeToMoveEntity.getIdNode())) .forEach(child -> child.setParentNode(nodeToMoveEntity)); } @@ -264,7 +264,7 @@ private UUID moveNode(UUID nodeToMoveUuid, UUID anchorNodeUuid, InsertMode inser @Transactional public void moveStudySubtree(UUID parentNodeToMoveUuid, UUID anchorNodeUuid) { - List children = getChildrenByParentUuid(parentNodeToMoveUuid); + List children = getChildren(parentNodeToMoveUuid); moveNode(parentNodeToMoveUuid, anchorNodeUuid, InsertMode.CHILD); children.forEach(child -> self.moveStudySubtree(child.getIdNode(), parentNodeToMoveUuid)); } @@ -299,9 +299,9 @@ private void stashNodes(UUID id, boolean stashChildren, List stashedNodes, UUID modificationGroupUuid = self.getModificationGroupUuid(nodeToStash.getIdNode()); networkModificationService.deleteStashedModifications(modificationGroupUuid); if (!stashChildren) { - nodesRepository.findAllByParentNodeIdNode(id).forEach(node -> node.setParentNode(nodeToStash.getParentNode())); + getChildren(id).forEach(node -> node.setParentNode(nodeToStash.getParentNode())); } else { - nodesRepository.findAllByParentNodeIdNode(id) + getChildren(id) .forEach(child -> stashNodes(child.getIdNode(), true, stashedNodes, false)); } stashedNodes.add(id); @@ -329,9 +329,9 @@ private void deleteNodes(UUID id, boolean deleteChildren, boolean allowDeleteRoo rootNetworkNodeInfoService.fillDeleteNodeInfo(id, deleteNodeInfos); if (!deleteChildren) { - nodesRepository.findAllByParentNodeIdNode(id).forEach(node -> node.setParentNode(nodeToDelete.getParentNode())); + getChildren(id).forEach(node -> node.setParentNode(nodeToDelete.getParentNode())); } else { - nodesRepository.findAllByParentNodeIdNode(id) + getChildren(id) .forEach(child -> deleteNodes(child.getIdNode(), true, false, removedNodes, deleteNodeInfos)); } removedNodes.add(id); @@ -344,12 +344,28 @@ private void deleteNodes(UUID id, boolean deleteChildren, boolean allowDeleteRoo }); } - public List getChildrenByParentUuid(UUID parentUuid) { + public List getChildren(UUID parentUuid) { return nodesRepository.findAllByParentNodeIdNode(parentUuid); } - public List getAllChildrenFromParentUuid(UUID parentUuid) { - return nodesRepository.findAllDescendants(parentUuid); + public List getAllChildrenUuids(UUID parentUuid) { + return nodesRepository.findAllChildrenUuids(parentUuid); + } + + // TODO Remove this method and use getAllChildrenUuids + public List getChildrenUuids(UUID parentUuid) { + List children = new ArrayList<>(); + doGetChildrenUuids(parentUuid, children); + return children; + } + + private void doGetChildrenUuids(UUID parentUuid, List children) { + Optional optNode = nodesRepository.findById(parentUuid); + optNode.ifPresent(node -> getChildren(parentUuid) + .forEach(child -> { + children.add(child.getIdNode()); + doGetChildrenUuids(child.getIdNode(), children); + })); } @Transactional @@ -411,10 +427,7 @@ private void completeNodeInfos(List nodes, UUID rootNetworkUuid) { @Transactional public AbstractNode getStudySubtree(UUID studyId, UUID parentNodeUuid, UUID rootNetworkUuid) { -// TODO: not working because of proxy appearing in tests TOFIX later -// List nodeUuids = nodesRepository.findAllDescendants(parentNodeUuid).stream().map(UUID::fromString).toList(); -// List nodes = nodesRepository.findAllById(nodeUuids); - List nodes = nodesRepository.findAllByStudyId(studyId); + List nodes = nodesRepository.findAllChildren(parentNodeUuid); List allNodeInfos = new ArrayList<>(); allNodeInfos.addAll(rootNodeInfoRepository.findAllByNodeStudyId(studyId).stream().map(RootNodeInfoEntity::toDto).toList()); @@ -561,7 +574,7 @@ private AbstractNode getSimpleNode(UUID nodeId) { @Transactional public AbstractNode getNode(UUID nodeId, UUID rootNetworkUuid) { AbstractNode node = getSimpleNode(nodeId); - nodesRepository.findAllByParentNodeIdNode(node.getId()).stream().map(NodeEntity::getIdNode).forEach(node.getChildrenIds()::add); + getChildren(node.getId()).stream().map(NodeEntity::getIdNode).forEach(node.getChildrenIds()::add); if (rootNetworkUuid != null) { completeNodeInfos(List.of(node), rootNetworkUuid); } @@ -691,7 +704,7 @@ public List> getStashedNodes(UUID studyUuid) { nodes.stream().map(node -> networkModificationNodeInfos.get(node.getIdNode())) .forEach(abstractNode -> { ArrayList children = new ArrayList<>(); - doGetChildren(abstractNode.getId(), children); + doGetChildrenUuids(abstractNode.getId(), children); result.add(Pair.of(abstractNode, children.size())); }); return result; @@ -746,7 +759,7 @@ public Map getModificationReports(UUID nodeUuid, UUID rootNetworkUui } private void restoreNodeChildren(UUID studyId, UUID parentNodeId) { - nodesRepository.findAllByParentNodeIdNode(parentNodeId).forEach(nodeEntity -> { + getChildren(parentNodeId).forEach(nodeEntity -> { NetworkModificationNodeInfoEntity modificationNodeToRestore = networkModificationNodeInfoRepository.findById(nodeEntity.getIdNode()).orElseThrow(() -> new StudyException(NODE_NOT_FOUND)); if (self.isNodeNameExists(studyId, modificationNodeToRestore.getName())) { String newName = getSuffixedNodeName(studyId, modificationNodeToRestore.getName()); @@ -883,7 +896,7 @@ private boolean hasAnyBuiltChildren(NodeEntity node, UUID rootNetworkUuid, Set { - invalidateNodeInfos.add(rootNetworkNodeInfoService.invalidateRootNetworkNode(child.getIdNode(), rootNetworkUuid, InvalidateNodeTreeParameters.ALL)); - invalidateNodeInfos.add(invalidateChildrenNodes(child.getIdNode(), rootNetworkUuid)); - }); + List rootNetworkNodeInfoEntities = rootNetworkNodeInfoService.getRootNetworkNodes(rootNetworkUuid, getAllChildrenUuids(nodeUuid)); + + rootNetworkNodeInfoEntities.forEach(child -> + invalidateNodeInfos.add(rootNetworkNodeInfoService.invalidateRootNetworkNode(child, InvalidateNodeTreeParameters.ALL)) + ); + return invalidateNodeInfos; } @@ -1010,21 +1024,6 @@ public Boolean isReadOnly(UUID nodeUuid) { return getNodeInfoEntity(nodeUuid).getReadOnly(); } - public List getChildren(UUID id) { - List children = new ArrayList<>(); - doGetChildren(id, children); - return children; - } - - private void doGetChildren(UUID id, List children) { - Optional optNode = nodesRepository.findById(id); - optNode.ifPresent(node -> nodesRepository.findAllByParentNodeIdNode(id) - .forEach(child -> { - children.add(child.getIdNode()); - doGetChildren(child.getIdNode(), children); - })); - } - // only used for tests @Transactional public UUID getParentNode(UUID nodeUuid, NodeType nodeType) { @@ -1060,7 +1059,7 @@ private void fillIndexedNodeInfosToInvalidate(UUID parentNodeUuid, boolean inclu if (includeParentNode) { nodesToInvalidate.add(parentNodeUuid); } - nodesToInvalidate.addAll(getChildren(parentNodeUuid)); + nodesToInvalidate.addAll(getAllChildrenUuids(parentNodeUuid)); invalidateNodeInfos.addGroupUuids( networkModificationNodeInfoRepository.findAllById(nodesToInvalidate).stream() .map(NetworkModificationNodeInfoEntity::getModificationGroupUuid).toList() diff --git a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java index 8b34ce750..247af9dbf 100644 --- a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java +++ b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java @@ -234,7 +234,10 @@ public void fillDeleteNodeInfo(UUID nodeUuid, DeleteNodeInfos deleteNodeInfos) { public InvalidateNodeInfos invalidateRootNetworkNode(UUID nodeUuid, UUID rootNetworUuid, InvalidateNodeTreeParameters invalidateTreeParameters) { RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(nodeUuid, rootNetworUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + return invalidateRootNetworkNode(rootNetworkNodeInfoEntity, invalidateTreeParameters); + } + public InvalidateNodeInfos invalidateRootNetworkNode(RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity, InvalidateNodeTreeParameters invalidateTreeParameters) { // No need to invalidate a node with a status different of "BUILT" if (!rootNetworkNodeInfoEntity.getNodeBuildStatus().toDto().isBuilt()) { return new InvalidateNodeInfos(); @@ -358,6 +361,10 @@ public List getComputationResultUuids(UUID studyUuid, ComputationType comp .toList(); } + public List getRootNetworkNodes(UUID rootNetworkUuid, List nodesUuids) { + return rootNetworkNodeInfoRepository.getAllByRootNetworkIdAndNodeInfoIdIn(rootNetworkUuid, nodesUuids); + } + public List getAllByStudyUuidWithLoadFlowResultsNotNull(UUID studyUuid) { return rootNetworkNodeInfoRepository.findAllByRootNetworkStudyIdAndLoadFlowResultUuidNotNull(studyUuid); } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index f21fec2e3..998cbbd92 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -1592,7 +1592,7 @@ private void removeSecurityAnalysisParameters(@Nullable UUID securityAnalysisPar @Transactional public void createNetworkModification(UUID studyUuid, String createModificationAttributes, UUID nodeUuid, String userId) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_CREATING_IN_PROGRESS); try { NetworkModificationsResult networkModificationResults = null; @@ -1624,7 +1624,7 @@ public void createNetworkModification(UUID studyUuid, String createModificationA @Transactional public void updateNetworkModification(UUID studyUuid, String updateModificationAttributes, UUID nodeUuid, UUID modificationUuid, String userId) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); try { networkModificationService.updateModification(updateModificationAttributes, modificationUuid); @@ -1747,7 +1747,7 @@ public void moveStudyNode(UUID studyUuid, UUID nodeToMoveUuid, UUID referenceNod //Unbuild previous children if necessary if (shouldUnbuildChildren) { - oldChildren = networkModificationTreeService.getChildrenByParentUuid(nodeToMoveUuid); + oldChildren = networkModificationTreeService.getChildren(nodeToMoveUuid); } networkModificationTreeService.moveStudyNode(nodeToMoveUuid, referenceNodeUuid, insertMode); @@ -1782,7 +1782,7 @@ public void moveStudySubtree(UUID studyUuid, UUID parentNodeToMoveUuid, UUID ref checkStudyContainsNode(studyUuid, referenceNodeUuid); networkModificationTreeService.assertIsRootOrConstructionNode(referenceNodeUuid); - List allChildren = networkModificationTreeService.getChildren(parentNodeToMoveUuid); + List allChildren = networkModificationTreeService.getChildrenUuids(parentNodeToMoveUuid); if (allChildren.contains(referenceNodeUuid)) { throw new StudyException(NOT_ALLOWED); } @@ -1891,7 +1891,7 @@ public void deleteInvalidationInfos(InvalidateNodeInfos invalidateNodeInfos) { @Transactional public void deleteNetworkModifications(UUID studyUuid, UUID nodeUuid, List modificationsUuids, String userId) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); StudyEntity studyEntity = studyRepository.findById(studyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_DELETING_IN_PROGRESS); try { @@ -1912,7 +1912,7 @@ public void deleteNetworkModifications(UUID studyUuid, UUID nodeUuid, List @Transactional public void stashNetworkModifications(UUID studyUuid, UUID nodeUuid, List modificationsUuids, String userId) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_STASHING_IN_PROGRESS); try { if (!networkModificationTreeService.getStudyUuidForNodeId(nodeUuid).equals(studyUuid)) { @@ -1929,7 +1929,7 @@ public void stashNetworkModifications(UUID studyUuid, UUID nodeUuid, List @Transactional public void updateNetworkModificationsActivation(UUID studyUuid, UUID nodeUuid, List modificationsUuids, String userId, boolean activated) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); try { if (!networkModificationTreeService.getStudyUuidForNodeId(nodeUuid).equals(studyUuid)) { @@ -1946,7 +1946,7 @@ public void updateNetworkModificationsActivation(UUID studyUuid, UUID nodeUuid, @Transactional public void updateNetworkModificationsActivationInRootNetwork(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, Set modificationsUuids, String userId, boolean activated) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); networkModificationService.verifyModifications(networkModificationTreeService.getModificationGroupUuid(nodeUuid), modificationsUuids); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, Optional.of(rootNetworkUuid), childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); try { @@ -1963,7 +1963,7 @@ public void updateNetworkModificationsActivationInRootNetwork(UUID studyUuid, UU @Transactional public void restoreNetworkModifications(UUID studyUuid, UUID nodeUuid, List modificationsUuids, String userId) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_RESTORING_IN_PROGRESS); try { if (!networkModificationTreeService.getStudyUuidForNodeId(nodeUuid).equals(studyUuid)) { @@ -1983,7 +1983,7 @@ private void removeNodesFromAliases(UUID studyUuid, List nodeIds, boolean if (!CollectionUtils.isEmpty(studyEntity.getNodeAliases())) { Set allNodeIds = new HashSet<>(nodeIds); if (removeChildren) { - nodeIds.forEach(n -> allNodeIds.addAll(networkModificationTreeService.getAllChildrenFromParentUuid(n).stream().map(UUID::fromString).toList())); + nodeIds.forEach(n -> allNodeIds.addAll(networkModificationTreeService.getAllChildrenUuids(n))); } studyEntity.getNodeAliases().forEach(nodeAliasEmbeddable -> { if (nodeAliasEmbeddable.getNodeId() != null && allNodeIds.contains(nodeAliasEmbeddable.getNodeId())) { @@ -2003,7 +2003,7 @@ public void deleteNodes(UUID studyUuid, List nodeIds, boolean deleteChildr startTime.set(System.nanoTime()); boolean invalidateChildrenBuild = !deleteChildren && networkModificationTreeService.hasModifications(nodeId, false); - List childrenNodes = networkModificationTreeService.getChildrenByParentUuid(nodeId); + List childrenNodes = networkModificationTreeService.getChildren(nodeId); List removedNodes = networkModificationTreeService.doDeleteNode(nodeId, deleteChildren, deleteNodeInfos); CompletableFuture executeInParallel = CompletableFuture.allOf( @@ -2133,11 +2133,11 @@ public void moveNetworkModifications(UUID studyUuid, UUID targetNodeUuid, UUID o boolean targetNodeBelongsToSourceNodeSubTree = moveBetweenNodes && networkModificationTreeService.hasAncestor(targetNodeUuid, originNodeUuid); boolean preserveTargetNodeBuildStatus = moveBetweenNodes && !targetNodeBelongsToSourceNodeSubTree; - List childrenUuids = networkModificationTreeService.getChildren(targetNodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(targetNodeUuid); List originNodeChildrenUuids = new ArrayList<>(); notificationService.emitStartModificationEquipmentNotification(studyUuid, targetNodeUuid, childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); if (moveBetweenNodes) { - originNodeChildrenUuids = networkModificationTreeService.getChildren(originNodeUuid); + originNodeChildrenUuids = networkModificationTreeService.getChildrenUuids(originNodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, originNodeUuid, originNodeChildrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); } try { @@ -2189,7 +2189,7 @@ private void emitNetworkModificationImpactsForAllRootNetworks(List modificationsUuis, String userId, StudyConstants.ModificationsActionType action) { - List childrenUuids = networkModificationTreeService.getChildren(targetNodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(targetNodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, targetNodeUuid, childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); try { checkStudyContainsNode(studyUuid, targetNodeUuid); @@ -2644,7 +2644,7 @@ private void postProcessEventCrud(UUID studyUuid, UUID nodeUuid) { @Transactional public void createDynamicSimulationEvent(UUID studyUuid, UUID nodeUuid, String userId, EventInfos event) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartEventCrudNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.EVENTS_CRUD_CREATING_IN_PROGRESS); try { dynamicSimulationEventService.saveEvent(nodeUuid, event); @@ -2656,7 +2656,7 @@ public void createDynamicSimulationEvent(UUID studyUuid, UUID nodeUuid, String u @Transactional public void updateDynamicSimulationEvent(UUID studyUuid, UUID nodeUuid, String userId, EventInfos event) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartEventCrudNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.EVENTS_CRUD_UPDATING_IN_PROGRESS); try { dynamicSimulationEventService.saveEvent(nodeUuid, event); @@ -2668,7 +2668,7 @@ public void updateDynamicSimulationEvent(UUID studyUuid, UUID nodeUuid, String u @Transactional public void deleteDynamicSimulationEvents(UUID studyUuid, UUID nodeUuid, String userId, List eventUuids) { - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartEventCrudNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.EVENTS_CRUD_DELETING_IN_PROGRESS); try { dynamicSimulationEventService.deleteEvents(eventUuids); @@ -2863,7 +2863,7 @@ public void insertVoltageInitModifications(UUID studyUuid, UUID nodeUuid, UUID r return; } - List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); + List childrenUuids = networkModificationTreeService.getChildrenUuids(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); try { checkStudyContainsNode(studyUuid, nodeUuid); diff --git a/src/test/java/org/gridsuite/study/server/ModificationIndexationTest.java b/src/test/java/org/gridsuite/study/server/ModificationIndexationTest.java index 5fc791521..75279b4fa 100644 --- a/src/test/java/org/gridsuite/study/server/ModificationIndexationTest.java +++ b/src/test/java/org/gridsuite/study/server/ModificationIndexationTest.java @@ -93,7 +93,7 @@ void testInvalidateBuiltNodeAndItsChildren() { node3.getModificationGroupUuid() )); - SQLStatementCountValidator.assertSelectCount(21); + SQLStatementCountValidator.assertSelectCount(17); } @Test @@ -105,7 +105,7 @@ void testInvalidateNotBuiltNodeAndItsChildren() { node5.getModificationGroupUuid() )); - SQLStatementCountValidator.assertSelectCount(21); + SQLStatementCountValidator.assertSelectCount(17); } @Test @@ -116,7 +116,7 @@ void testInvalidateBuiltNodeChildrenOnly() { node5.getModificationGroupUuid() )); - SQLStatementCountValidator.assertSelectCount(12); + SQLStatementCountValidator.assertSelectCount(8); } @Test @@ -128,7 +128,7 @@ void testInvalidateNotBuiltNodeChildrenOnly() { node3.getModificationGroupUuid() )); - SQLStatementCountValidator.assertSelectCount(21); + SQLStatementCountValidator.assertSelectCount(17); } @Test @@ -149,7 +149,7 @@ void testInvalidateBuiltNodeOnlyWithoutBuiltChildren() { node3.getModificationGroupUuid() )); - SQLStatementCountValidator.assertSelectCount(21); + SQLStatementCountValidator.assertSelectCount(19); } private void createStudyAndNodesWithIndexedModification() { diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index d48dbe26e..05fe0fc7b 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -598,7 +598,7 @@ void testNodeModificationInfos() throws Exception { List children = root.getChildren(); assertEquals(2, children.size()); - NetworkModificationNode n1 = (NetworkModificationNode) children.get(0); + NetworkModificationNode n1 = (NetworkModificationNode) (children.stream().filter(c -> c.getName().equals("n1")).findFirst().orElseThrow()); NetworkModificationNodeInfoEntity n1Infos = networkModificationTreeService.getNetworkModificationNodeInfoEntity(n1.getId()); RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(n1.getId(), firstRootNetworkUuid).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); @@ -662,27 +662,27 @@ void testNodeManipulation() throws Exception { /* expected : root / \ - node1 node2 + node1(hypo 1) node2(loadflow) */ assertChildrenEquals(Set.of(node1, node2), root.getChildren()); node2.setName("niark"); node1.setName("condriak"); node1.setModificationGroupUuid(UUID.randomUUID()); - createNode(root.getStudyId(), children.get(1), node2, userId); - createNode(root.getStudyId(), children.get(1), node1, userId); + AbstractNode child = children.stream().filter(c -> c.getName().equals("loadflow")).findFirst().orElseThrow(); + createNode(root.getStudyId(), child, node2, userId); + createNode(root.getStudyId(), child, node1, userId); /* expected root / \ - node1 node2 + node1 node2(loadflow) / \ node(condriak) node(niark) */ root = getRootNode(root.getStudyId(), firstRootNetwork); - AbstractNode child; - if (root.getChildren().get(0).getName().equals(children.get(1).getName())) { + if (root.getChildren().get(0).getName().equals(child.getName())) { child = root.getChildren().get(0); } else { child = root.getChildren().get(1); @@ -693,23 +693,26 @@ void testNodeManipulation() throws Exception { deleteNode(root.getStudyId(), List.of(child), false, Set.of(child), true, userId); /* expected - root - / | \ - node node node + root + / | \ + node node node + (hypo 1) (condriak) (niark) */ root = getRootNode(root.getStudyId(), firstRootNetwork); assertEquals(3, root.getChildren().size()); child = root.getChildren().get(0); + createNode(root.getStudyId(), child, node4, userId); deleteNode(root.getStudyId(), List.of(child), true, Set.of(child, node4), userId); /* expected - root - | - node + root + | \ + node node */ + root = getRootNode(root.getStudyId(), firstRootNetwork); assertEquals(2, root.getChildren().size()); assertEquals(3, nodeRepository.findAll().size()); @@ -857,7 +860,7 @@ void testNodeInsertion() throws Exception { */ root = getRootNode(root.getStudyId()); assertEquals(1, root.getChildren().stream().filter(child -> child.getId().equals(unchangedNode.getId())).count()); - AbstractNode newNode = root.getChildren().get(0).getId().equals(unchangedNode.getId()) ? root.getChildren().get(1) : root.getChildren().get(1); + AbstractNode newNode = root.getChildren().get(0).getId().equals(unchangedNode.getId()) ? root.getChildren().get(1) : root.getChildren().get(0); assertEquals(willBeMoved.getId(), newNode.getChildren().get(0).getId()); mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", root.getStudyId(), UUID.randomUUID()) diff --git a/src/test/java/org/gridsuite/study/server/NodeSequenceTest.java b/src/test/java/org/gridsuite/study/server/NodeSequenceTest.java index cd4120b7d..10dedb834 100644 --- a/src/test/java/org/gridsuite/study/server/NodeSequenceTest.java +++ b/src/test/java/org/gridsuite/study/server/NodeSequenceTest.java @@ -118,7 +118,7 @@ void testCreateTwoSecuritySequence() { AbstractNode nNode = parentOfSubtree.getChildren().getFirst(); checkSecuritySequence(nNode, " (1)"); - verify(notificationService, times(1)).emitSubtreeInserted(studyUuid, networkModificationTreeService.getChildrenByParentUuid(constructionNode.getId()).getFirst().getIdNode(), constructionNode.getId()); + verify(notificationService, times(1)).emitSubtreeInserted(studyUuid, networkModificationTreeService.getChildren(constructionNode.getId()).getFirst().getIdNode(), constructionNode.getId()); verify(notificationService, times(1)).emitSubtreeInserted(studyUuid, nNode.getId(), parentOfSubtree.getId()); verify(notificationService, times(2)).emitElementUpdated(studyUuid, userId); }