diff --git a/src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NetworkModificationNodeInfoRepository.java b/src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NetworkModificationNodeInfoRepository.java index 07c1e9768..6fa2532be 100644 --- a/src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NetworkModificationNodeInfoRepository.java +++ b/src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NetworkModificationNodeInfoRepository.java @@ -9,6 +9,7 @@ import org.gridsuite.study.server.networkmodificationtree.entities.AbstractNodeInfoEntity; import org.gridsuite.study.server.networkmodificationtree.entities.NetworkModificationNodeInfoEntity; +import org.springframework.data.jpa.repository.Query; import java.util.List; import java.util.UUID; @@ -20,4 +21,7 @@ public interface NetworkModificationNodeInfoRepository extends NodeInfoRepositor List findAllByNodeStudyIdAndName(UUID studyUuid, String name); List findByModificationGroupUuidIn(List modificationGroupUuid); + + @Query("select n.columnPosition from NetworkModificationNodeInfoEntity n where n.idNode in :uuids") + List findColumnPositionsByUuidIn(List uuids); } 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 737234e49..df82cb39f 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 @@ -36,6 +36,9 @@ public interface NodeRepository extends JpaRepository { @NativeQuery("UPDATE node_export SET status = :status WHERE export_uuid = :exportUuid") void updateExportNetworkStatus(UUID exportUuid, String status); + @NativeQuery("select cast(n.id_node AS VARCHAR) from NODE n where n.parent_node = :nodeUuid") + List findChildrenUuids(UUID nodeUuid); + @NativeQuery("WITH RECURSIVE NodeHierarchy (id_node) AS ( " + " SELECT n0.id_node" + " FROM NODE n0 " + 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 a862eee9a..d56e29bce 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -79,7 +79,7 @@ public NetworkModificationTreeService(NodeRepository nodesRepository, this.reportService = reportService; } - private NodeEntity createNetworkModificationNode(StudyEntity study, NodeEntity parentNode, NetworkModificationNode networkModificationNode) { + private NetworkModificationNodeInfoEntity createNetworkModificationNode(StudyEntity study, NodeEntity parentNode, NetworkModificationNode networkModificationNode) { NodeEntity newNode = nodesRepository.save(new NodeEntity(null, parentNode, NodeType.NETWORK_MODIFICATION, study, false, null, new ArrayList<>())); if (networkModificationNode.getModificationGroupUuid() == null) { networkModificationNode.setModificationGroupUuid(UUID.randomUUID()); @@ -87,7 +87,7 @@ private NodeEntity createNetworkModificationNode(StudyEntity study, NodeEntity p if (networkModificationNode.getNodeType() == null) { networkModificationNode.setNodeType(NetworkModificationNodeType.CONSTRUCTION); } - networkModificationNodeInfoRepository.save( + NetworkModificationNodeInfoEntity newNodeInfo = networkModificationNodeInfoRepository.save( NetworkModificationNodeInfoEntity.builder() .modificationGroupUuid(networkModificationNode.getModificationGroupUuid()) .idNode(newNode.getIdNode()) @@ -96,7 +96,8 @@ private NodeEntity createNetworkModificationNode(StudyEntity study, NodeEntity p .nodeType(networkModificationNode.getNodeType()) .build() ); - return newNode; + newNodeInfo.setNode(newNode); + return newNodeInfo; } public List getNetworkModificationsByNodeInfos( @@ -114,8 +115,7 @@ public List getNetworkModificationsByNodeInfos( .toList(); } - // TODO test if studyUuid exist and have a node - private NetworkModificationNode createAndInsertNode(StudyEntity study, UUID nodeId, NetworkModificationNode nodeInfo, InsertMode insertMode, String userId) { + private NetworkModificationNode createAndInsertNode(StudyEntity study, UUID nodeId, NetworkModificationNode nodeInfo, InsertMode insertMode) { NodeEntity reference = getNodeEntity(nodeId); assertNodeNameNotExist(study.getId(), nodeInfo.getName()); @@ -123,24 +123,44 @@ private NetworkModificationNode createAndInsertNode(StudyEntity study, UUID node if (insertMode.equals(InsertMode.BEFORE) && reference.getType().equals(NodeType.ROOT)) { throw new StudyException(NOT_ALLOWED); } - NodeEntity parent = insertMode.equals(InsertMode.BEFORE) ? reference.getParentNode() : reference; - NodeEntity node = createNetworkModificationNode(study, parent, nodeInfo); - nodeInfo.setId(node.getIdNode()); - if (insertMode.equals(InsertMode.BEFORE)) { - reference.setParentNode(node); - } else if (insertMode.equals(InsertMode.AFTER)) { - getChildren(nodeId).stream() - .filter(n -> !n.getIdNode().equals(node.getIdNode())) - .forEach(child -> child.setParentNode(node)); + // Create node + NetworkModificationNodeInfoEntity nodeInfoEntity = createNetworkModificationNode(study, insertMode.equals(InsertMode.BEFORE) ? reference.getParentNode() : reference, nodeInfo); + NodeEntity nodeEntity = nodeInfoEntity.getNode(); + nodeInfo.setId(nodeInfoEntity.getIdNode()); + + // Set parent and position + switch (insertMode) { + case CHILD -> nodeInfoEntity.setColumnPosition(getNextColumnPosition(reference.getIdNode())); + case BEFORE -> { + AbstractNodeInfoEntity referenceNodeInfoEntity = getNodeInfoEntity(reference.getIdNode()); + nodeInfoEntity.setColumnPosition(referenceNodeInfoEntity.getColumnPosition()); + reference.setParentNode(nodeEntity); + referenceNodeInfoEntity.setColumnPosition(0); + } + case AFTER -> { + nodeInfoEntity.setColumnPosition(0); + getChildren(nodeId).stream() + .filter(n -> !n.getIdNode().equals(nodeEntity.getIdNode())) + .forEach(child -> child.setParentNode(nodeEntity)); + } } return nodeInfo; } + private int getNextColumnPosition(UUID parentNodeId) { + return networkModificationNodeInfoRepository.findColumnPositionsByUuidIn(nodesRepository.findChildrenUuids(parentNodeId)) + .stream() + .filter(Objects::nonNull) + .mapToInt(i -> i) + .max() + .orElse(-1) + 1; + } + @Transactional public NetworkModificationNode createNode(@NonNull StudyEntity study, @NonNull UUID nodeId, @NonNull NetworkModificationNode nodeInfo, @NonNull InsertMode insertMode, String userId) { // create new node - NetworkModificationNode newNode = createAndInsertNode(study, nodeId, nodeInfo, insertMode, userId); + NetworkModificationNode newNode = createAndInsertNode(study, nodeId, nodeInfo, insertMode); NetworkModificationNodeInfoEntity newNodeInfoEntity = networkModificationNodeInfoRepository.getReferenceById(newNode.getId()); rootNetworkNodeInfoService.createNodeLinks(study, newNodeInfoEntity); @@ -150,7 +170,7 @@ public NetworkModificationNode createNode(@NonNull StudyEntity study, @NonNull U private NetworkModificationNode duplicateNode(@NonNull StudyEntity targetStudy, @NonNull UUID referenceNodeId, @NonNull NetworkModificationNode newNodeInfo, @NonNull UUID originNodeUuid, @NonNull InsertMode insertMode, Map mappingModificationUuids) { // create new node - NetworkModificationNode newNode = createAndInsertNode(targetStudy, referenceNodeId, newNodeInfo, insertMode, null); + NetworkModificationNode newNode = createAndInsertNode(targetStudy, referenceNodeId, newNodeInfo, insertMode); NetworkModificationNodeInfoEntity newNodeInfoEntity = networkModificationNodeInfoRepository.getReferenceById(newNode.getId()); NetworkModificationNodeInfoEntity originNodeInfoEntity = networkModificationNodeInfoRepository.getReferenceById(originNodeUuid); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index 8f48228fb..511751764 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -1031,6 +1031,7 @@ void testNodeInsertion() throws Exception { createNode(root.getStudyId(), root, networkModification1, userId); createNode(root.getStudyId(), root, networkModification2, userId); root = getRootNode(root.getStudyId()); + assertEquals(Set.of(0, 1), root.getChildren().stream().map(AbstractNode::getColumnPosition).collect(Collectors.toCollection(TreeSet::new))); /* root / \ n1 n2 @@ -1038,23 +1039,24 @@ void testNodeInsertion() throws Exception { AbstractNode unchangedNode = root.getChildren().get(0); AbstractNode willBeMoved = root.getChildren().get(1); insertNode(root.getStudyId(), willBeMoved, networkModification3, InsertMode.BEFORE, root, userId); + root = getRootNode(root.getStudyId()); + assertEquals(Set.of(0, 1), root.getChildren().stream().map(AbstractNode::getColumnPosition).collect(Collectors.toCollection(TreeSet::new))); /* root / \ n3 n2 / n1 */ - 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(0); assertEquals(willBeMoved.getId(), newNode.getChildren().get(0).getId()); + assertEquals(Set.of(0), newNode.getChildren().stream().map(AbstractNode::getColumnPosition).collect(Collectors.toCollection(TreeSet::new))); mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", root.getStudyId(), UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(networkModification1)) .header(USER_ID_HEADER, "userId")) .andExpect(status().isNotFound()); - } @Test @@ -1070,12 +1072,18 @@ void testInsertAfter() throws Exception { createNode(root.getStudyId(), root, node2, userId); createNode(root.getStudyId(), root, node3, userId); root = getRootNode(root.getStudyId()); - var originalChildren = root.getChildren().stream().map(AbstractNode::getId).collect(Collectors.toSet()); + Set originalChildrenUuids = root.getChildren().stream().map(AbstractNode::getId).collect(Collectors.toSet()); + assertEquals(Set.of(0, 1), root.getChildren().stream().map(AbstractNode::getColumnPosition).collect(Collectors.toCollection(TreeSet::new))); + insertNode(root.getStudyId(), root, node1, InsertMode.AFTER, root, userId); root = getRootNode(root.getStudyId()); assertEquals(1, root.getChildren().size()); - var grandChildren = getRootNode(root.getStudyId()).getChildren().get(0).getChildren().stream().map(AbstractNode::getId).collect(Collectors.toSet()); - assertEquals(originalChildren, grandChildren); + assertEquals(Set.of(0), root.getChildren().stream().map(AbstractNode::getColumnPosition).collect(Collectors.toCollection(TreeSet::new))); + + List grandChildren = getRootNode(root.getStudyId()).getChildren().get(0).getChildren(); + Set grandChildrenUuids = grandChildren.stream().map(AbstractNode::getId).collect(Collectors.toSet()); + assertEquals(originalChildrenUuids, grandChildrenUuids); + assertEquals(Set.of(0, 1), grandChildren.stream().map(AbstractNode::getColumnPosition).collect(Collectors.toCollection(TreeSet::new))); UUID rootNetworkUuid = studyTestUtils.getOneRootNetworkUuid(root.getStudyId()); assertEquals(VARIANT_ID, networkModificationTreeService.getVariantId(node1.getId(), rootNetworkUuid)); diff --git a/src/test/java/org/gridsuite/study/server/studycontroller/NodeControllerTest.java b/src/test/java/org/gridsuite/study/server/studycontroller/NodeControllerTest.java index b0744d095..47feb8b27 100644 --- a/src/test/java/org/gridsuite/study/server/studycontroller/NodeControllerTest.java +++ b/src/test/java/org/gridsuite/study/server/studycontroller/NodeControllerTest.java @@ -52,10 +52,13 @@ void testCutAndPasteNode() throws Exception { UUID firstRootNetworkUuid = studyTestUtils.getOneRootNetworkUuid(study1Uuid); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); + assertEquals(0, rootNode.getChildren().get(0).getColumnPosition()); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", userId); - + assertEquals(0, node1.getColumnPosition()); + assertEquals(1, node2.getColumnPosition()); + assertEquals(1, emptyNode.getColumnPosition()); /* * rootNode * / \ @@ -109,7 +112,10 @@ void testCutAndPasteNode() throws Exception { // cut the node1 and paste it after node2 cutAndPasteNode(study1Uuid, node1, node2.getId(), InsertMode.AFTER, 0, userId); - + allNodes = networkModificationTreeService.getAllNodes(study1Uuid); + Map allNodesInfos = networkModificationTreeService.getAllStudyNodesByUuid(study1Uuid); + assertEquals(0, allNodesInfos.get(node1.getId()).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node2.getId()).getColumnPosition()); /* * rootNode * / \ @@ -121,7 +127,6 @@ void testCutAndPasteNode() throws Exception { */ //node2 should now have 1 child : node 1 - allNodes = networkModificationTreeService.getAllNodes(study1Uuid); assertEquals(List.of(node1.getId()), allNodes.stream() .filter(nodeEntity -> nodeEntity.getParentNode() != null @@ -140,7 +145,11 @@ void testCutAndPasteNode() throws Exception { // cut and paste the node2 before emptyNode cutAndPasteNode(study1Uuid, node2, emptyNode.getId(), InsertMode.BEFORE, 1, userId); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); - + allNodesInfos = networkModificationTreeService.getAllStudyNodesByUuid(study1Uuid); + assertEquals(0, allNodesInfos.get(modificationNodeUuid).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node2.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(node1.getId()).getColumnPosition()); + assertEquals(1, allNodesInfos.get(emptyNode.getId()).getColumnPosition()); /* * rootNode * / \ @@ -176,7 +185,11 @@ void testCutAndPasteNode() throws Exception { //cut and paste node2 in a new branch starting from modificationNode cutAndPasteNode(study1Uuid, node2, modificationNodeUuid, InsertMode.CHILD, 1, userId); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); - + allNodesInfos = networkModificationTreeService.getAllStudyNodesByUuid(study1Uuid); + assertEquals(0, allNodesInfos.get(modificationNodeUuid).getColumnPosition()); + assertEquals(1, allNodesInfos.get(emptyNode.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(node1.getId()).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node2.getId()).getColumnPosition()); /* * rootNode * / \ @@ -323,10 +336,21 @@ void testCutAndPasteSubtree() throws Exception { RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, userId); - NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", BuildStatus.BUILT, userId); NetworkModificationNode emptyNodeChild = createNetworkModificationNode(study1Uuid, emptyNode.getId(), UUID.randomUUID(), VARIANT_ID_3, "emptyNodeChild", BuildStatus.BUILT, userId); + assertEquals(0, rootNode.getChildren().get(0).getColumnPosition()); + assertEquals(1, emptyNode.getColumnPosition()); + assertEquals(0, node1.getColumnPosition()); + assertEquals(0, emptyNodeChild.getColumnPosition()); + /* + * rootNode + * / \ + * modificationNode emptyNode + * / \ + * node1 emptyNodeChild + */ + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/subtrees?subtreeToCutParentNodeUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}", study1Uuid, emptyNode.getId(), emptyNodeChild.getId()) @@ -343,6 +367,23 @@ void testCutAndPasteSubtree() throws Exception { .andExpect(status().isOk()); wireMockStubs.verifyNetworkModificationDeleteIndex(deleteModificationIndexStub); + Map allNodesInfos = networkModificationTreeService.getAllStudyNodesByUuid(study1Uuid); + assertEquals(0, allNodesInfos.get(modificationNodeUuid).getColumnPosition()); + assertEquals(0, allNodesInfos.get(node1.getId()).getColumnPosition()); + assertEquals(1, allNodesInfos.get(emptyNode.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(emptyNodeChild.getId()).getColumnPosition()); + /* + * rootNode + * / + * modificationNode + * / + * node1 + * / + * emptyNode + * / + * emptyNodeChild + */ + checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(emptyNode.getId(), emptyNodeChild.getId())); checkComputationStatusMessageReceived(); @@ -478,6 +519,18 @@ void testDuplicateNode() throws Exception { NetworkModificationNode node3 = createNetworkModificationNode(study1Uuid, rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node3", BuildStatus.BUILT, userId); NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", userId); + assertEquals(0, rootNode.getChildren().get(0).getColumnPosition()); + assertEquals(1, node3.getColumnPosition()); + assertEquals(0, node1.getColumnPosition()); + assertEquals(1, node2.getColumnPosition()); + /* + * rootNode + * / \ + * modificationNode node3 + * / \ + * node1 node2 + */ + // add modification on node "node1" String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; wireMockStubs.stubNetworkModificationPost(mapper.writeValueAsString(new NetworkModificationsResult(List.of(UUID.randomUUID()), List.of(Optional.empty())))); @@ -524,6 +577,22 @@ void testDuplicateNode() throws Exception { // duplicate the node1 after node2 UUID duplicatedNodeUuid = duplicateNode(study1Uuid, study1Uuid, node1, node2.getId(), InsertMode.AFTER, true, userId); + Map allNodesInfos = networkModificationTreeService.getAllStudyNodesByUuid(study1Uuid); + assertEquals(0, allNodesInfos.get(modificationNodeUuid).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node3.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(node1.getId()).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node2.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(duplicatedNodeUuid).getColumnPosition()); + /* + * rootNode + * / \ + * modificationNode node3 + * / \ + * node1 node2 + * \ + * duplicatedNode + */ + //node2 should now have 1 child allNodes = networkModificationTreeService.getAllNodes(study1Uuid); assertEquals(1, allNodes.stream() @@ -542,6 +611,23 @@ void testDuplicateNode() throws Exception { .count()); //now the tree looks like root -> modificationNode -> duplicatedNode2 -> node1 -> node2 -> duplicatedNode1 + allNodesInfos = networkModificationTreeService.getAllStudyNodesByUuid(study1Uuid); + assertEquals(0, allNodesInfos.get(modificationNodeUuid).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node3.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(duplicatedNodeUuid2).getColumnPosition()); + assertEquals(0, allNodesInfos.get(node1.getId()).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node2.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(duplicatedNodeUuid).getColumnPosition()); + /* + * rootNode + * / \ + * modificationNode node3 + * / \ + * duplicatedNode2 node2 + * / \ + * node1 duplicatedNode + */ + //duplicate node1 in a new branch starting from duplicatedNode2 UUID duplicatedNodeUuid3 = duplicateNode(study1Uuid, study1Uuid, node1, duplicatedNodeUuid2, InsertMode.CHILD, true, userId); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); @@ -554,6 +640,24 @@ void testDuplicateNode() throws Exception { //and expect that no other node has the new branch create node as parent assertEquals(0, allNodes.stream().filter(nodeEntity -> nodeEntity.getParentNode() != null && nodeEntity.getParentNode().getIdNode().equals(duplicatedNodeUuid3)).count()); + allNodesInfos = networkModificationTreeService.getAllStudyNodesByUuid(study1Uuid); + assertEquals(0, allNodesInfos.get(modificationNodeUuid).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node3.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(duplicatedNodeUuid2).getColumnPosition()); + assertEquals(0, allNodesInfos.get(node1.getId()).getColumnPosition()); + assertEquals(1, allNodesInfos.get(duplicatedNodeUuid3).getColumnPosition()); + assertEquals(1, allNodesInfos.get(node2.getId()).getColumnPosition()); + assertEquals(0, allNodesInfos.get(duplicatedNodeUuid).getColumnPosition()); + /* + * rootNode + * / \ + * modificationNode node3 + * / \ + * duplicatedNode2 node2 + * / \ \ + * node1 duplicatedNodeUuid3 duplicatedNode + */ + //try copy non-existing node and expect not found mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", @@ -594,13 +698,21 @@ void testDuplicateSubtree() throws Exception { NetworkModificationNode node3 = createNetworkModificationNode(study1Uuid, node2.getId(), UUID.randomUUID(), VARIANT_ID, "node3", BuildStatus.BUILT, userId); NetworkModificationNode node4 = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", userId); - /*tree state - root - ├── root children - │ └── node 1 - │ └── node 2 - │ └── node 3 - └── node 4 + assertEquals(0, rootNode.getChildren().get(0).getColumnPosition()); + assertEquals(1, node4.getColumnPosition()); + assertEquals(0, node1.getColumnPosition()); + assertEquals(0, node2.getColumnPosition()); + assertEquals(0, node3.getColumnPosition()); + /* + * rootNode + * / \ + * modificationNode node4 + * / + * node1 + * / + * node2 + * / + * node3 */ // add modification on node "node1" (not built) -> invalidation of node 3 @@ -676,16 +788,20 @@ void testDuplicateSubtree() throws Exception { checkElementUpdatedMessageSent(study1Uuid, userId); wireMockStubs.verifyDuplicateModificationGroup(stubDuplicateUuid, 3); - /*tree state - root - ├── root children - │ └── node 1 - │ └── node 2 - │ └── node 3 - └── node 4 - └── node 1 duplicated - └── node 2 duplicated - └── node 3 duplicated + Map allNodesInfos = networkModificationTreeService.getAllStudyNodesByUuid(study1Uuid); + networkModificationTreeService.getAllChildrenUuids(node4.getId()).forEach(childUuid -> + assertEquals(0, allNodesInfos.get(childUuid).getColumnPosition()) + ); + /* + * rootNode + * / \ + * modificationNode node4 + * / \ + * node1 duplicate node1 + * / \ + * node2 duplicate node2 + * / \ + * node3 duplicate node3 */ mockMvc.perform(get(STUDIES_URL + diff --git a/src/test/java/org/gridsuite/study/server/studycontroller/StudyTestBase.java b/src/test/java/org/gridsuite/study/server/studycontroller/StudyTestBase.java index b19091bd7..7601d8940 100644 --- a/src/test/java/org/gridsuite/study/server/studycontroller/StudyTestBase.java +++ b/src/test/java/org/gridsuite/study/server/studycontroller/StudyTestBase.java @@ -475,10 +475,11 @@ protected NetworkModificationNode createNetworkModificationNode(UUID studyUuid, modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getOneRootNetworkUuid(studyUuid), + UUID rootNetworkUuid = studyTestUtils.getOneRootNetworkUuid(studyUuid); + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), rootNetworkUuid, RootNetworkNodeInfo.builder().variantId(variantId).nodeBuildStatus(NodeBuildStatus.from(buildStatus)).build()); - return modificationNode; + return (NetworkModificationNode) networkModificationTreeService.getNode(modificationNode.getId(), rootNetworkUuid); } protected void assertStudyCreation(UUID studyUuid, String userId, String... errorMessage) {