Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions services/save-and-restore/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ A special case is the root node as it has a fixed unique id:

**.../node/44bef5de-e8e6-4014-af37-b8f6c8a939a2**

The root node may also be retrieved using:

**.../root**

or

**.../node/root***

Retrieve multiple nodes
"""""""""""""""""""""""
Method: GET
Expand Down Expand Up @@ -265,6 +273,10 @@ The a list of all the children nodes of the node with id `{uniqueNodeId}`
}
]

One may retrieve the child nodes of the root node using:

**.../node/root/children**

.. _Get a configuration:

Get a configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public class ElasticsearchDAO implements NodeDAO {

@Override
public List<Node> getChildNodes(String uniqueNodeId) {
if("root".equals(uniqueNodeId)) {
uniqueNodeId = ROOT_FOLDER_UNIQUE_ID;
}
Optional<ESTreeNode> elasticsearchNode =
elasticsearchTreeRepository.findById(uniqueNodeId);
if (elasticsearchNode.isEmpty()) {
Expand All @@ -111,6 +114,9 @@ public List<Node> getChildNodes(String uniqueNodeId) {

@Override
public Node getNode(String uniqueNodeId) {
if("root".equals(uniqueNodeId)) {
uniqueNodeId = ROOT_FOLDER_UNIQUE_ID;
}
Optional<ESTreeNode> optional =
elasticsearchTreeRepository.findById(uniqueNodeId);
if (optional.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public Node createNode(@RequestParam(name = "parentNodeId") String parentsUnique
@SuppressWarnings("unused")
@GetMapping(value = "/node/{uniqueNodeId}", produces = JSON)
public Node getNode(@PathVariable final String uniqueNodeId) {
if("root".equals(uniqueNodeId)) {
return nodeDAO.getRootNode();
}
return nodeDAO.getNode(uniqueNodeId);
}

Expand Down Expand Up @@ -158,7 +161,7 @@ public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) {
public void deleteNodes(@RequestBody List<String> nodeIds) {
nodeDAO.deleteNodes(nodeIds);
nodeIds.forEach(id ->
webSocketService.sendMessageToClients(new WebSocketMessage(SaveAndRestoreMessageType.NODE_REMOVED, id)));
webSocketService.sendMessageToClients(new WebSocketMessage<>(SaveAndRestoreMessageType.NODE_REMOVED, id)));
}

/**
Expand Down Expand Up @@ -220,10 +223,19 @@ public Node updateNode(@RequestParam(value = "customTimeForMigration", required
}
nodeToUpdate.setUserName(principal.getName());
Node updatedNode = nodeDAO.updateNode(nodeToUpdate, Boolean.parseBoolean(customTimeForMigration));
webSocketService.sendMessageToClients(new WebSocketMessage(SaveAndRestoreMessageType.NODE_UPDATED, updatedNode));
webSocketService.sendMessageToClients(new WebSocketMessage<>(SaveAndRestoreMessageType.NODE_UPDATED, updatedNode));
return updatedNode;
}

/**
* Endpoint for the sake of convenience, i.e. client need not know the unique id of the root {@link Node}
* @return The root {@link Node}
*/
@GetMapping("/root")
public Node getRoot() {
return nodeDAO.getRootNode();
}

/**
* Checks if a {@link Node} has a tag named "golden". If so, it must be of type {@link NodeType#SNAPSHOT}.
*
Expand All @@ -235,11 +247,7 @@ private boolean areTagsValid(Node node) {
return true;
}

if (!node.getNodeType().equals(NodeType.SNAPSHOT) &&
node.getTags().stream().anyMatch(t -> t.getName().equalsIgnoreCase(Tag.GOLDEN))) {
return false;
}

return true;
return node.getNodeType().equals(NodeType.SNAPSHOT) ||
node.getTags().stream().noneMatch(t -> t.getName().equalsIgnoreCase(Tag.GOLDEN));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,25 @@ public void testGetChildNodes() {

List<Node> childNodes = nodeDAO.getChildNodes(rootNode.getUniqueId());
assertTrue(nodeDAO.getChildNodes(folder1.getUniqueId()).isEmpty());
}

@Test
public void testGetChildNodesFromRoot() {
Node rootNode = nodeDAO.getRootNode();

Node folder1 = Node.builder().name("SomeFolder").build();

// Create folder1 in the root folder
folder1 = nodeDAO.createNode(rootNode.getUniqueId(), folder1);

List<Node> childNodes = nodeDAO.getChildNodes("root");
assertTrue(nodeDAO.getChildNodes(folder1.getUniqueId()).isEmpty());
}

@Test
public void testGetRootNode() {
Node rootNode = nodeDAO.getNode("root");
assertEquals(Node.ROOT_FOLDER_UNIQUE_ID, rootNode.getUniqueId());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,4 +810,23 @@ public void testCreateNodeWithValidTags2() throws Exception {
mockMvc.perform(request).andExpect(status().isOk());

}

@Test
public void testGetRootNode() throws Exception {
when(nodeDAO.getRootNode()).thenReturn(Node.builder().uniqueId(Node.ROOT_FOLDER_UNIQUE_ID).build());
MockHttpServletRequestBuilder request = get("/root");
MvcResult mvcResult = mockMvc.perform(request).andExpect(status().isOk()).andReturn();
Node node = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), Node.class);
assertEquals(Node.ROOT_FOLDER_UNIQUE_ID, node.getUniqueId());
}

@Test
public void testRootNodeChildNodes() throws Exception {
when(nodeDAO.getChildNodes("root")).thenReturn(List.of(Node.builder().uniqueId("foo").build()));
MockHttpServletRequestBuilder request = get("/node/root/children");
MvcResult mvcResult = mockMvc.perform(request).andExpect(status().isOk()).andReturn();
List<Node> nodes = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() {
});
assertEquals(1, nodes.size());
}
}
Loading