Commit 5700e878 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Bug #3612 - Fixed method getParentPath() in CreateNodeController class.

Passes testSubPath() test in CreateNodeControllerTest now.
parent 66f3a3cd
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@ public class CreateNodeController extends BaseNodeController {
        List<String> nodeGroups
                = Arrays.asList(groupWritePropValues.get(0).split(" ", -1));

        if (userGroups == null || 
                !nodeGroups.stream().anyMatch((i) -> userGroups.contains(i))) {
        if (userGroups == null
                || !nodeGroups.stream().anyMatch((i) -> userGroups.contains(i))) {
            // If groups don't match check ownership at least
            List<String> nodeOwner
                    = getNodePropertyByURI(parentNode, "ivo://ivoa.net/vospace/core#creator");
@@ -114,13 +114,26 @@ public class CreateNodeController extends BaseNodeController {

    }

    // This method assumes that URL is in the format /node1/node2/...
    // multiple slashes as a single separator are allowed
    // But the output has only single slash separators
    private String getParentPath(String path) {
        String[] parsedPath = path.split("/");

        String[] parsedPath = path.split("[/]+");

        if (parsedPath.length < 2 || !parsedPath[0].isEmpty()) {
            throw new IllegalArgumentException();
        }

        StringBuilder sb = new StringBuilder();
        sb.append("/");

        for (int i = 0; i < parsedPath.length - 1; i++) {
            sb.append("/").append(parsedPath[i]);
        System.out.println(parsedPath.length);
        for (int i = 1; i < parsedPath.length - 1; i++) {
            sb.append(parsedPath[i]);
            if (i < parsedPath.length - 2) {
                sb.append("/");
            }
        }

        return sb.toString();
+1 −1
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ public class CreateNodeControllerTest {
        verifyArguments();
    }
    
    //@Test
    @Test
    public void testSubPath() throws Exception {

        String requestBody = getResourceFileContent("create-unstructured-data-node.xml")