Skip to content

Commit

Permalink
Fix storage node rename to not delete children nodes with same names
Browse files Browse the repository at this point in the history
Signed-off-by: GONCALVES Bruno <[email protected]>
(cherry picked from commit 9cd601a)
  • Loading branch information
BrunoRte committed Jun 30, 2023
1 parent 5b88cf4 commit ce5e1fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ public void renameNode(String nodeId, String name) {
getSession().execute(deleteFrom(CHILDREN_BY_NAME_AND_CLASS)
.whereColumn(ID).isEqualTo(literal(parentNodeUuid))
.whereColumn(CHILD_NAME).isEqualTo(literal(nodeInfo.getName()))
.whereColumn(CHILD_PSEUDO_CLASS).isEqualTo(literal(nodeInfo.getPseudoClass()))
.build());

getSession().execute(insertInto(CHILDREN_BY_NAME_AND_CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ protected void nextDependentTests() {
new CassandraRenameIssueTest().test(storage);
clear();

new CassandraRenameIssueTest().testRenameChildWithSameName(storage);
clear();

new TimeSeriesIssueTest().testEmptyChunks(storage);
clear();
new TimeSeriesIssueTest().testNullString(storage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import com.powsybl.afs.storage.NodeGenericMetadata;
import com.powsybl.afs.storage.NodeInfo;

import java.util.List;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand All @@ -32,4 +36,27 @@ public void test(AppStorage storage) {
assertEquals(2, storage.getChildNodes(test1NodeInfo.getId()).size());
assertEquals("newtest1", storage.getNodeInfo(test1NodeInfo.getId()).getName());
}

public void testRenameChildWithSameName(AppStorage storage) {
NodeInfo rootNodeId = storage.createRootNodeIfNotExists("test", "folder");
NodeInfo test1NodeInfo = storage.createNode(rootNodeId.getId(), "test1", "folder", "", 0, new NodeGenericMetadata());
storage.flush();
NodeInfo test2Project = storage.createNode(test1NodeInfo.getId(), "test2", "project", "", 0, new NodeGenericMetadata());
storage.setConsistent(test2Project.getId());
NodeInfo test2Folder = storage.createNode(test1NodeInfo.getId(), "test2", "folder", "", 0, new NodeGenericMetadata());
storage.setConsistent(test2Folder.getId());
storage.flush();
storage.renameNode(test2Project.getId(), "newTest2");
storage.flush();
List<NodeInfo> childNodes = storage.getChildNodes(test1NodeInfo.getId());
assertEquals(2, childNodes.size());
Optional<NodeInfo> first = childNodes.stream().filter(nodeInfo -> nodeInfo.getId().equals(test2Project.getId())).findFirst();
assertTrue(first.isPresent());
assertEquals("newTest2", first.get().getName());
Optional<NodeInfo> second = childNodes.stream().filter(nodeInfo -> nodeInfo.getId().equals(test2Folder.getId())).findFirst();
assertTrue(second.isPresent());
assertEquals("test2", second.get().getName());
assertEquals("test2", storage.getNodeInfo(test2Folder.getId()).getName());
assertEquals("newTest2", storage.getNodeInfo(test2Project.getId()).getName());
}
}

0 comments on commit ce5e1fe

Please sign in to comment.