Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into jamal-khey/fix-load-flow-result-global-filter
  • Loading branch information
Slimane AMAR committed Dec 31, 2024
2 parents 24fa5c1 + f43b154 commit 561ea75
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,19 @@ public ResponseEntity<Void> updateNode(@RequestBody NetworkModificationNode node
return ResponseEntity.ok().build();
}

@PutMapping(value = "/studies/{studyUuid}/tree/nodes/{parentUuid}/children-column-positions")
@Operation(summary = "update children column positions")
@ApiResponses(value = {
@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<Void> updateNodesColumnPositions(@RequestBody List<NetworkModificationNode> 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, children, userId);
return ResponseEntity.ok().build();
}

@GetMapping(value = "/studies/{studyUuid}/tree/nodes/{id}")
@Operation(summary = "get simplified node")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public abstract class AbstractNode {

String description;

Integer columnPosition;

Boolean readOnly;

NodeType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public UUID getId() {
@Column
String description;

@Column
Integer columnPosition;

@Column
Boolean readOnly;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -113,6 +114,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 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";
Expand Down Expand Up @@ -309,6 +311,20 @@ public void emitSubtreeMoved(UUID studyUuid, UUID parentNodeSubtreeMoved, UUID r
);
}

@PostCompletion
public void emitColumnsChanged(UUID studyUuid, UUID parentNodeUuid, List<UUID> orderedUuids) {
try {
sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(orderedUuids))
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_UPDATE_TYPE, NODES_COLUMN_POSITIONS_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("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetworkModificationNode> childrenNodes, String userId) {
// Convert to a map for quick lookup
Map<UUID, Integer> nodeIdToColumnPosition = childrenNodes.stream()
.collect(Collectors.toMap(NetworkModificationNode::getId, NetworkModificationNode::getColumnPosition));

List<UUID> childrenIds = childrenNodes.stream().map(NetworkModificationNode::getId).toList();
networkModificationNodeInfoRepository.findAllById(childrenIds).forEach(entity -> {
Integer newColumnPosition = nodeIdToColumnPosition.get(entity.getId());
entity.setColumnPosition(Objects.requireNonNull(newColumnPosition));
});

List<UUID> orderedUuids = childrenNodes.stream()
.sorted(Comparator.comparingInt(AbstractNode::getColumnPosition))
.map(NetworkModificationNode::getId)
.toList();

notificationService.emitColumnsChanged(studyUuid, parentUuid, orderedUuids);
notificationService.emitElementUpdated(studyUuid, userId);
}

private boolean isRenameNode(AbstractNode node) {
NetworkModificationNode renameNode = NetworkModificationNode.builder()
.id(node.getId())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="boutiercha (generated)" id="1734094779057-10">
<addColumn tableName="network_modification_node_info">
<column name="column_position" type="integer"/>
</addColumn>
</changeSet>
<changeSet author="boutiercha (generated)" id="1734094779057-11">
<addColumn tableName="root_node_info">
<column name="column_position" type="integer"/>
</addColumn>
</changeSet>
</databaseChangeLog>
5 changes: 4 additions & 1 deletion src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,8 @@ databaseChangeLog:
file: changesets/changelog_20241211T123019Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20241211T181846Z.xml
file: changesets/changelog_20241213T125757Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20241211T181846Z.xml
relativeToChangelogFile: true
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,34 @@ 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);
List<NetworkModificationNode> 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)
.content(objectWriter.writeValueAsString(nodes))
.header(USER_ID_HEADER, "userId"))
.andExpect(status().isOk());

List<UUID> 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);
}

// 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
Expand Down Expand Up @@ -1336,6 +1364,14 @@ private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) {
assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY));
}

private void checkColumnsChangedMessageSent(UUID studyUuid, UUID parentNodeUuid, List<UUID> orderedUuids) throws Exception {
Message<byte[]> message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION);
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()));
}

private void checkUpdateNodesMessageReceived(UUID studyUuid, List<UUID> nodesUuids) {
Message<byte[]> messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION);
assertEquals("", new String(messageStatus.getPayload()));
Expand Down

0 comments on commit 561ea75

Please sign in to comment.