From 0bf0e0bc3913750d6544682b119e42e3b2715016 Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Sat, 14 Dec 2024 01:10:50 +0100 Subject: [PATCH 1/7] New API point to update the nodes' column position in gridstudy-app's tree. Signed-off-by: BOUTIER Charly --- .../study/server/StudyController.java | 13 ++++++++++++ .../AbstractNodeRepositoryProxy.java | 1 + .../dto/AbstractNode.java | 2 ++ .../entities/AbstractNodeInfoEntity.java | 3 +++ .../notification/NotificationService.java | 16 ++++++++++++++ .../NetworkModificationTreeService.java | 21 +++++++++++++++++++ .../changesets/changelog_20241213T125757Z.xml | 13 ++++++++++++ .../db/changelog/db.changelog-master.yaml | 3 +++ 8 files changed, 72 insertions(+) create mode 100644 src/main/resources/db/changelog/changesets/changelog_20241213T125757Z.xml diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 4b1a0243c..792ae30e2 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -1282,6 +1282,19 @@ public ResponseEntity updateNode(@RequestBody NetworkModificationNode node return ResponseEntity.ok().build(); } + @PutMapping(value = "/studies/{studyUuid}/tree/nodes/columnpositions/{parentUuid}") + @Operation(summary = "update nodes column positions") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "the nodes column positions have been updated"), + @ApiResponse(responseCode = "404", description = "The study or a node was not found")}) + public ResponseEntity updateNodesColumnPositions(@RequestBody List nodes, + @Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, + @Parameter(description = "parent node uuid") @PathVariable("parentUuid") UUID parentUuid, + @RequestHeader(HEADER_USER_ID) String userId) { + networkModificationTreeService.updateNodesColumnPositions(studyUuid, parentUuid, nodes, userId); + return ResponseEntity.ok().build(); + } + @GetMapping(value = "/studies/{studyUuid}/tree/nodes/{id}") @Operation(summary = "get simplified node") @ApiResponses(value = { diff --git a/src/main/java/org/gridsuite/study/server/networkmodificationtree/AbstractNodeRepositoryProxy.java b/src/main/java/org/gridsuite/study/server/networkmodificationtree/AbstractNodeRepositoryProxy.java index 51a8c7a1e..6dec21ee9 100644 --- a/src/main/java/org/gridsuite/study/server/networkmodificationtree/AbstractNodeRepositoryProxy.java +++ b/src/main/java/org/gridsuite/study/server/networkmodificationtree/AbstractNodeRepositoryProxy.java @@ -39,6 +39,7 @@ protected U completeNodeInfo(AbstractNodeInfoEntity nodeInfoEntity, U node) { node.setId(nodeInfoEntity.getId()); node.setName(nodeInfoEntity.getName()); node.setDescription(nodeInfoEntity.getDescription()); + node.setColumnPosition(nodeInfoEntity.getColumnPosition()); node.setReadOnly(nodeInfoEntity.getReadOnly()); return node; } diff --git a/src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/AbstractNode.java b/src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/AbstractNode.java index aec11d121..1c56baecf 100644 --- a/src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/AbstractNode.java +++ b/src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/AbstractNode.java @@ -48,6 +48,8 @@ public abstract class AbstractNode { String description; + Integer columnPosition; + Boolean readOnly; NodeType type; diff --git a/src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/AbstractNodeInfoEntity.java b/src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/AbstractNodeInfoEntity.java index 388be9482..3cb34673b 100644 --- a/src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/AbstractNodeInfoEntity.java +++ b/src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/AbstractNodeInfoEntity.java @@ -44,6 +44,9 @@ public UUID getId() { @Column String description; + @Column + Integer columnPosition; + @Column Boolean readOnly; } diff --git a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java index a16191267..48d749a3d 100644 --- a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java +++ b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java @@ -23,6 +23,7 @@ import java.time.Instant; import java.util.Collection; +import java.util.Map; import java.util.Set; import java.util.UUID; @@ -112,6 +113,7 @@ public class NotificationService { public static final String NODE_RENAMED = "nodeRenamed"; public static final String NODE_BUILD_STATUS_UPDATED = "nodeBuildStatusUpdated"; public static final String SUBTREE_MOVED = "subtreeMoved"; + public static final String COLUMNS_CHANGED = "columnsChanged"; public static final String SUBTREE_CREATED = "subtreeCreated"; public static final String MESSAGE_LOG = "Sending message : {}"; public static final String DEFAULT_ERROR_MESSAGE = "Unknown error"; @@ -300,6 +302,20 @@ public void emitSubtreeMoved(UUID studyUuid, UUID parentNodeSubtreeMoved, UUID r ); } + @PostCompletion + public void emitColumnsChanged(UUID studyUuid, UUID parentNodeUuid, Map nodes) { + try { + sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(nodes)) + .setHeader(HEADER_STUDY_UUID, studyUuid) + .setHeader(HEADER_UPDATE_TYPE, COLUMNS_CHANGED) + .setHeader(HEADER_PARENT_NODE, parentNodeUuid) + .build() + ); + } catch (JsonProcessingException e) { + LOGGER.error("Unable to notify on column positions update", e); + } + } + @PostCompletion public void emitSubtreeInserted(UUID studyUuid, UUID parentNodeSubtreeInserted, UUID referenceNodeUuid) { sendUpdateMessage(MessageBuilder.withPayload("") 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 867802011..0efe64186 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -445,6 +445,27 @@ public void updateNode(UUID studyUuid, NetworkModificationNode node, String user notificationService.emitElementUpdated(studyUuid, userId); } + @Transactional + public void updateNodesColumnPositions(UUID studyUuid, UUID parentUuid, List nodes, String userId) { + List nodeIds = nodes.stream().map(NetworkModificationNode::getId).collect(Collectors.toList()); + + List networkModificationNodeEntities = networkModificationNodeInfoRepository.findAllById(nodeIds); + + // Convert to a map for quick lookup + Map nodeIdToColumnPosition = nodes.stream() + .collect(Collectors.toMap(NetworkModificationNode::getId, NetworkModificationNode::getColumnPosition)); + + networkModificationNodeEntities.forEach(entity -> { + Integer newColumnPosition = nodeIdToColumnPosition.get(entity.getId()); + if (newColumnPosition != null) { + entity.setColumnPosition(newColumnPosition); + } + }); + + notificationService.emitColumnsChanged(studyUuid, parentUuid, nodeIdToColumnPosition); + notificationService.emitElementUpdated(studyUuid, userId); + } + private boolean isRenameNode(AbstractNode node) { NetworkModificationNode renameNode = NetworkModificationNode.builder() .id(node.getId()) diff --git a/src/main/resources/db/changelog/changesets/changelog_20241213T125757Z.xml b/src/main/resources/db/changelog/changesets/changelog_20241213T125757Z.xml new file mode 100644 index 000000000..dd8a32f7e --- /dev/null +++ b/src/main/resources/db/changelog/changesets/changelog_20241213T125757Z.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index 86bf4da9f..b1a2affc9 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -267,4 +267,7 @@ databaseChangeLog: relativeToChangelogFile: true - include: file: changesets/changelog_20241211T123019Z.xml + relativeToChangelogFile: true + - include: + file: changesets/changelog_20241213T125757Z.xml relativeToChangelogFile: true \ No newline at end of file From 98f41be5b1534d27b62658aea739b8dfa2d86d42 Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Sun, 15 Dec 2024 02:04:24 +0100 Subject: [PATCH 2/7] Returns a simple array of UUID as payload --- .../server/notification/NotificationService.java | 13 ++++++------- .../service/NetworkModificationTreeService.java | 9 +++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java index 48d749a3d..ef0993f9d 100644 --- a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java +++ b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java @@ -23,7 +23,6 @@ import java.time.Instant; import java.util.Collection; -import java.util.Map; import java.util.Set; import java.util.UUID; @@ -303,13 +302,13 @@ public void emitSubtreeMoved(UUID studyUuid, UUID parentNodeSubtreeMoved, UUID r } @PostCompletion - public void emitColumnsChanged(UUID studyUuid, UUID parentNodeUuid, Map nodes) { + public void emitColumnsChanged(UUID studyUuid, UUID parentNodeUuid, UUID[] orderedUuids) { try { - sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(nodes)) - .setHeader(HEADER_STUDY_UUID, studyUuid) - .setHeader(HEADER_UPDATE_TYPE, COLUMNS_CHANGED) - .setHeader(HEADER_PARENT_NODE, parentNodeUuid) - .build() + sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(orderedUuids)) + .setHeader(HEADER_STUDY_UUID, studyUuid) + .setHeader(HEADER_UPDATE_TYPE, COLUMNS_CHANGED) + .setHeader(HEADER_PARENT_NODE, parentNodeUuid) + .build() ); } catch (JsonProcessingException e) { LOGGER.error("Unable to notify on column positions update", e); 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 0efe64186..1221b63e0 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -453,7 +453,7 @@ public void updateNodesColumnPositions(UUID studyUuid, UUID parentUuid, List nodeIdToColumnPosition = nodes.stream() - .collect(Collectors.toMap(NetworkModificationNode::getId, NetworkModificationNode::getColumnPosition)); + .collect(Collectors.toMap(NetworkModificationNode::getId, NetworkModificationNode::getColumnPosition)); networkModificationNodeEntities.forEach(entity -> { Integer newColumnPosition = nodeIdToColumnPosition.get(entity.getId()); @@ -462,7 +462,12 @@ public void updateNodesColumnPositions(UUID studyUuid, UUID parentUuid, List Date: Tue, 17 Dec 2024 00:09:25 +0100 Subject: [PATCH 3/7] Returns a simple array of UUID as payload Signed-off-by: BOUTIER Charly --- .../server/NetworkModificationTreeTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index 47b792aec..62ccee1b7 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -874,6 +874,35 @@ void testNodeUpdate() throws Exception { .andExpect(status().isNotFound()); } + @Test + void testUpdateNodesColumnPositions() throws Exception { + String userId = "userId"; + RootNode root = createRoot(); + final NetworkModificationNode node1 = buildNetworkModificationNode("nod", "silently", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); + final NetworkModificationNode node2 = buildNetworkModificationNode("nodding", "politely", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); + createNode(root.getStudyId(), root, node1, userId); + createNode(root.getStudyId(), root, node2, userId); + assertNull(node1.getColumnPosition()); + node1.setColumnPosition(1); + node2.setColumnPosition(0); + ArrayList nodes = new ArrayList<>(); + nodes.add(node1); + nodes.add(node2); + + mockMvc.perform(put("/v1/studies/{studyUuid}/tree/nodes/columnpositions/{parentUuid}", root.getStudyId(), root.getId()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectWriter.writeValueAsString(nodes)) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); + + UUID[] expectedInOrder = new UUID[]{ + node2.getId(), + node1.getId() + }; + checkColumnsChangedMessageSent(root.getStudyId(), root.getId(), expectedInOrder); + checkElementUpdatedMessageSent(root.getStudyId(), userId); + } + // This test is for a part of the code that is not used yet // We update a node description (this is not used in the front) and we assume that it will emit a nodeUpdated notif // If it's not the case or if this test causes problems feel free to update it / remove it as needed @@ -1336,6 +1365,18 @@ private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); } + private void checkColumnsChangedMessageSent(UUID studyUuid, UUID parentNodeUuid, UUID[] orderedUuids) { + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); + assertEquals(NotificationService.COLUMNS_CHANGED, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); + assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); + assertEquals(parentNodeUuid, message.getHeaders().get(NotificationService.HEADER_PARENT_NODE)); + String expected = Arrays.stream(orderedUuids) + .map(UUID::toString) + .map(uuid -> "\"" + uuid + "\"") // Add quotes around each UUID + .collect(Collectors.joining(",", "[", "]")); // Join them in JSON format + assertEquals(expected, new String(message.getPayload())); + } + private void checkUpdateNodesMessageReceived(UUID studyUuid, List nodesUuids) { Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); From fda0703fdac5de1c64f20fccfec25400bbb5f516 Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Tue, 17 Dec 2024 11:04:48 +0100 Subject: [PATCH 4/7] PR Review Signed-off-by: BOUTIER Charly --- .../org/gridsuite/study/server/StudyController.java | 10 +++++----- .../server/service/NetworkModificationTreeService.java | 10 +++++----- .../study/server/NetworkModificationTreeTest.java | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index c1924f12f..869aa837a 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -1296,16 +1296,16 @@ public ResponseEntity updateNode(@RequestBody NetworkModificationNode node return ResponseEntity.ok().build(); } - @PutMapping(value = "/studies/{studyUuid}/tree/nodes/columnpositions/{parentUuid}") - @Operation(summary = "update nodes column positions") + @PutMapping(value = "/studies/{studyUuid}/tree/nodes/{parentUuid}/children-column-positions") + @Operation(summary = "update children column positions") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "the nodes column positions have been updated"), + @ApiResponse(responseCode = "200", description = "the node column positions have been updated"), @ApiResponse(responseCode = "404", description = "The study or a node was not found")}) - public ResponseEntity updateNodesColumnPositions(@RequestBody List nodes, + public ResponseEntity updateNodesColumnPositions(@RequestBody List children, @Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "parent node uuid") @PathVariable("parentUuid") UUID parentUuid, @RequestHeader(HEADER_USER_ID) String userId) { - networkModificationTreeService.updateNodesColumnPositions(studyUuid, parentUuid, nodes, userId); + networkModificationTreeService.updateNodesColumnPositions(studyUuid, parentUuid, children, userId); return ResponseEntity.ok().build(); } 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 1221b63e0..879746842 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -446,13 +446,13 @@ public void updateNode(UUID studyUuid, NetworkModificationNode node, String user } @Transactional - public void updateNodesColumnPositions(UUID studyUuid, UUID parentUuid, List nodes, String userId) { - List nodeIds = nodes.stream().map(NetworkModificationNode::getId).collect(Collectors.toList()); + public void updateNodesColumnPositions(UUID studyUuid, UUID parentUuid, List childrenNodes, String userId) { + List childrenIds = childrenNodes.stream().map(NetworkModificationNode::getId).collect(Collectors.toList()); - List networkModificationNodeEntities = networkModificationNodeInfoRepository.findAllById(nodeIds); + List networkModificationNodeEntities = networkModificationNodeInfoRepository.findAllById(childrenIds); // Convert to a map for quick lookup - Map nodeIdToColumnPosition = nodes.stream() + Map nodeIdToColumnPosition = childrenNodes.stream() .collect(Collectors.toMap(NetworkModificationNode::getId, NetworkModificationNode::getColumnPosition)); networkModificationNodeEntities.forEach(entity -> { @@ -462,7 +462,7 @@ public void updateNodesColumnPositions(UUID studyUuid, UUID parentUuid, List Date: Tue, 17 Dec 2024 11:30:26 +0100 Subject: [PATCH 5/7] Review Signed-off-by: Slimane AMAR --- .../notification/NotificationService.java | 3 ++- .../NetworkModificationTreeService.java | 19 +++++++------------ .../server/NetworkModificationTreeTest.java | 8 ++------ 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java index ef0993f9d..87fd1e017 100644 --- a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java +++ b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java @@ -23,6 +23,7 @@ import java.time.Instant; import java.util.Collection; +import java.util.List; import java.util.Set; import java.util.UUID; @@ -302,7 +303,7 @@ public void emitSubtreeMoved(UUID studyUuid, UUID parentNodeSubtreeMoved, UUID r } @PostCompletion - public void emitColumnsChanged(UUID studyUuid, UUID parentNodeUuid, UUID[] orderedUuids) { + public void emitColumnsChanged(UUID studyUuid, UUID parentNodeUuid, List orderedUuids) { try { sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(orderedUuids)) .setHeader(HEADER_STUDY_UUID, studyUuid) 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 879746842..2f0a2b600 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -447,25 +447,20 @@ public void updateNode(UUID studyUuid, NetworkModificationNode node, String user @Transactional public void updateNodesColumnPositions(UUID studyUuid, UUID parentUuid, List childrenNodes, String userId) { - List childrenIds = childrenNodes.stream().map(NetworkModificationNode::getId).collect(Collectors.toList()); - - List networkModificationNodeEntities = networkModificationNodeInfoRepository.findAllById(childrenIds); - // Convert to a map for quick lookup Map nodeIdToColumnPosition = childrenNodes.stream() .collect(Collectors.toMap(NetworkModificationNode::getId, NetworkModificationNode::getColumnPosition)); - networkModificationNodeEntities.forEach(entity -> { + List childrenIds = childrenNodes.stream().map(NetworkModificationNode::getId).toList(); + networkModificationNodeInfoRepository.findAllById(childrenIds).forEach(entity -> { Integer newColumnPosition = nodeIdToColumnPosition.get(entity.getId()); - if (newColumnPosition != null) { - entity.setColumnPosition(newColumnPosition); - } + entity.setColumnPosition(Objects.requireNonNull(newColumnPosition)); }); - UUID[] orderedUuids = childrenNodes.stream() - .sorted(Comparator.comparingInt(AbstractNode::getColumnPosition)) - .map(NetworkModificationNode::getId) - .toArray(UUID[]::new); + List orderedUuids = childrenNodes.stream() + .sorted(Comparator.comparingInt(AbstractNode::getColumnPosition)) + .map(NetworkModificationNode::getId) + .toList(); notificationService.emitColumnsChanged(studyUuid, parentUuid, orderedUuids); notificationService.emitElementUpdated(studyUuid, userId); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index 58f4f80f1..4e98068ab 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -1365,16 +1365,12 @@ private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); } - private void checkColumnsChangedMessageSent(UUID studyUuid, UUID parentNodeUuid, UUID[] orderedUuids) { + private void checkColumnsChangedMessageSent(UUID studyUuid, UUID parentNodeUuid, UUID[] orderedUuids) throws Exception { Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.COLUMNS_CHANGED, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(parentNodeUuid, message.getHeaders().get(NotificationService.HEADER_PARENT_NODE)); - String expected = Arrays.stream(orderedUuids) - .map(UUID::toString) - .map(uuid -> "\"" + uuid + "\"") // Add quotes around each UUID - .collect(Collectors.joining(",", "[", "]")); // Join them in JSON format - assertEquals(expected, new String(message.getPayload())); + assertEquals(objectMapper.writeValueAsString(orderedUuids), new String(message.getPayload())); } private void checkUpdateNodesMessageReceived(UUID studyUuid, List nodesUuids) { From 29a86a2451abf55964aba5f1396cc0833fb3384d Mon Sep 17 00:00:00 2001 From: Slimane AMAR Date: Tue, 17 Dec 2024 13:22:16 +0100 Subject: [PATCH 6/7] Add test in database Signed-off-by: Slimane AMAR --- .../server/NetworkModificationTreeTest.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index 4e98068ab..c3976ab05 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -885,9 +885,7 @@ void testUpdateNodesColumnPositions() throws Exception { assertNull(node1.getColumnPosition()); node1.setColumnPosition(1); node2.setColumnPosition(0); - ArrayList nodes = new ArrayList<>(); - nodes.add(node1); - nodes.add(node2); + List nodes = List.of(node1, node2); mockMvc.perform(put("/v1/studies/{studyUuid}/tree/nodes/{parentUuid}/children-column-positions", root.getStudyId(), root.getId()) .contentType(MediaType.APPLICATION_JSON) @@ -895,11 +893,12 @@ void testUpdateNodesColumnPositions() throws Exception { .header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()); - UUID[] expectedInOrder = new UUID[]{ - node2.getId(), - node1.getId() - }; - checkColumnsChangedMessageSent(root.getStudyId(), root.getId(), expectedInOrder); + List nodesUuids = List.of(node2.getId(), node1.getId()); + for (NetworkModificationNodeInfoEntity entity : networkModificationNodeInfoRepository.findAllById(nodesUuids)) { + assertEquals(entity.getId().equals(node2.getId()) ? 0 : 1, entity.getColumnPosition()); + } + + checkColumnsChangedMessageSent(root.getStudyId(), root.getId(), nodesUuids); checkElementUpdatedMessageSent(root.getStudyId(), userId); } @@ -1365,7 +1364,7 @@ private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); } - private void checkColumnsChangedMessageSent(UUID studyUuid, UUID parentNodeUuid, UUID[] orderedUuids) throws Exception { + private void checkColumnsChangedMessageSent(UUID studyUuid, UUID parentNodeUuid, List orderedUuids) throws Exception { Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.COLUMNS_CHANGED, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); From 5be3d4409f778816c750fd9a487db4202629da06 Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Tue, 17 Dec 2024 13:56:59 +0100 Subject: [PATCH 7/7] PR Review Signed-off-by: BOUTIER Charly --- .../study/server/notification/NotificationService.java | 4 ++-- .../gridsuite/study/server/NetworkModificationTreeTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java index 87fd1e017..958205168 100644 --- a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java +++ b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java @@ -113,7 +113,7 @@ public class NotificationService { public static final String NODE_RENAMED = "nodeRenamed"; public static final String NODE_BUILD_STATUS_UPDATED = "nodeBuildStatusUpdated"; public static final String SUBTREE_MOVED = "subtreeMoved"; - public static final String COLUMNS_CHANGED = "columnsChanged"; + public static final String NODES_COLUMN_POSITIONS_CHANGED = "nodesColumnPositionsChanged"; public static final String SUBTREE_CREATED = "subtreeCreated"; public static final String MESSAGE_LOG = "Sending message : {}"; public static final String DEFAULT_ERROR_MESSAGE = "Unknown error"; @@ -307,7 +307,7 @@ public void emitColumnsChanged(UUID studyUuid, UUID parentNodeUuid, List o try { sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(orderedUuids)) .setHeader(HEADER_STUDY_UUID, studyUuid) - .setHeader(HEADER_UPDATE_TYPE, COLUMNS_CHANGED) + .setHeader(HEADER_UPDATE_TYPE, NODES_COLUMN_POSITIONS_CHANGED) .setHeader(HEADER_PARENT_NODE, parentNodeUuid) .build() ); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index c3976ab05..7f2ea6b04 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -1366,7 +1366,7 @@ private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { private void checkColumnsChangedMessageSent(UUID studyUuid, UUID parentNodeUuid, List orderedUuids) throws Exception { Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); - assertEquals(NotificationService.COLUMNS_CHANGED, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); + assertEquals(NotificationService.NODES_COLUMN_POSITIONS_CHANGED, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(parentNodeUuid, message.getHeaders().get(NotificationService.HEADER_PARENT_NODE)); assertEquals(objectMapper.writeValueAsString(orderedUuids), new String(message.getPayload()));