Skip to content
Snippets Groups Projects
Commit 3fa71326 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added recursive parameter on SetNodeController

parent abd5a70a
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,6 @@ package it.inaf.oats.vospace; ...@@ -2,7 +2,6 @@ package it.inaf.oats.vospace;
import it.inaf.ia2.aa.data.User; import it.inaf.ia2.aa.data.User;
import it.inaf.oats.vospace.datamodel.NodeUtils; import it.inaf.oats.vospace.datamodel.NodeUtils;
import it.inaf.oats.vospace.exception.LinkFoundException;
import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.exception.NodeNotFoundException;
import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.exception.PermissionDeniedException;
import it.inaf.oats.vospace.persistence.NodeDAO; import it.inaf.oats.vospace.persistence.NodeDAO;
...@@ -18,6 +17,7 @@ import org.springframework.http.MediaType; ...@@ -18,6 +17,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
...@@ -31,7 +31,8 @@ public class SetNodeController extends BaseNodeController { ...@@ -31,7 +31,8 @@ public class SetNodeController extends BaseNodeController {
@PostMapping(value = {"/nodes", "/nodes/**"}, @PostMapping(value = {"/nodes", "/nodes/**"},
consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) produces = {MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Node> setNode(@RequestBody Node node, User principal, HttpServletRequest request) { public ResponseEntity<Node> setNode(@RequestBody Node node, User principal, HttpServletRequest request,
@RequestParam(value = "recursive", required = false, defaultValue = "false") boolean recursive) {
String path = getPath(); String path = getPath();
LOG.debug("setNode called for path {}", path); LOG.debug("setNode called for path {}", path);
...@@ -70,7 +71,7 @@ public class SetNodeController extends BaseNodeController { ...@@ -70,7 +71,7 @@ public class SetNodeController extends BaseNodeController {
// A HTTP 200 status code and a Node representation in the entity-body The full // A HTTP 200 status code and a Node representation in the entity-body The full
// expanded record for the node SHALL be returned, including any xsi:type // expanded record for the node SHALL be returned, including any xsi:type
// specific extensions. // specific extensions.
return ResponseEntity.ok(nodeDao.setNode(node)); return ResponseEntity.ok(nodeDao.setNode(node, recursive));
} }
private void checkViews(DataNode requestedDataNode, DataNode savedDataNode) { private void checkViews(DataNode requestedDataNode, DataNode savedDataNode) {
......
...@@ -123,7 +123,6 @@ public class SetNodeControllerTest { ...@@ -123,7 +123,6 @@ public class SetNodeControllerTest {
.accept(MediaType.APPLICATION_XML)) .accept(MediaType.APPLICATION_XML))
.andDo(print()) .andDo(print())
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
} }
/* Test case: /* Test case:
...@@ -147,7 +146,6 @@ public class SetNodeControllerTest { ...@@ -147,7 +146,6 @@ public class SetNodeControllerTest {
.accept(MediaType.APPLICATION_XML)) .accept(MediaType.APPLICATION_XML))
.andDo(print()) .andDo(print())
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
} }
/* Test case: /* Test case:
...@@ -210,7 +208,7 @@ public class SetNodeControllerTest { ...@@ -210,7 +208,7 @@ public class SetNodeControllerTest {
when(nodeDao.listNode(eq("/"))) when(nodeDao.listNode(eq("/")))
.thenReturn(Optional.of(getContainerParentNode("/"))); .thenReturn(Optional.of(getContainerParentNode("/")));
when(nodeDao.listNode(eq("/mydata1"))).thenReturn(Optional.of(node)); when(nodeDao.listNode(eq("/mydata1"))).thenReturn(Optional.of(node));
when(nodeDao.setNode(any())).thenReturn(node); when(nodeDao.setNode(any(), eq(false))).thenReturn(node);
mockMvc.perform(post("/nodes/mydata1") mockMvc.perform(post("/nodes/mydata1")
.header("Authorization", "Bearer user2_token") .header("Authorization", "Bearer user2_token")
...@@ -221,4 +219,29 @@ public class SetNodeControllerTest { ...@@ -221,4 +219,29 @@ public class SetNodeControllerTest {
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
@Test
public void testSetNodeRecursive() throws Exception {
String requestBody = getResourceFileContent("modify-container-node.xml");
ContainerNode node = new ContainerNode();
node.setUri(URI_PREFIX + "/myfolder1");
Property groupWriteProp = new Property();
groupWriteProp.setUri(NodeProperties.GROUP_WRITE_URI);
groupWriteProp.setValue("group1");
node.getProperties().add(groupWriteProp);
when(nodeDao.listNode(eq("/"))).thenReturn(Optional.of(getContainerParentNode("/")));
when(nodeDao.listNode(eq("/myfolder1"))).thenReturn(Optional.of(node));
when(nodeDao.setNode(any(), eq(true))).thenReturn(node);
mockMvc.perform(post("/nodes/myfolder1")
.param("recursive", "true")
.header("Authorization", "Bearer user2_token")
.content(requestBody)
.contentType(MediaType.APPLICATION_XML)
.accept(MediaType.APPLICATION_XML))
.andDo(print())
.andExpect(status().isOk());
}
} }
<vos:node xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vos="http://www.ivoa.net/xml/VOSpace/v2.0" xsi:type="vos:ContainerNode" uri="vos://example.com!vospace/myfolder1">
</vos:node>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment