From da45c497195a9acbb649cbe98d9bdee1015dc884 Mon Sep 17 00:00:00 2001
From: Sara Bertocco <sara.bertocco@inaf.it>
Date: Tue, 2 Feb 2021 10:03:45 +0100
Subject: [PATCH] Working on redmine task
 #3635src/main/java/it/inaf/oats/vospace/BaseNodeController.java

---
 .../oats/vospace/CreateNodeController.java    | 60 ++-----------------
 1 file changed, 6 insertions(+), 54 deletions(-)

diff --git a/src/main/java/it/inaf/oats/vospace/CreateNodeController.java b/src/main/java/it/inaf/oats/vospace/CreateNodeController.java
index 8095246..fe9452a 100644
--- a/src/main/java/it/inaf/oats/vospace/CreateNodeController.java
+++ b/src/main/java/it/inaf/oats/vospace/CreateNodeController.java
@@ -1,6 +1,7 @@
 package it.inaf.oats.vospace;
 
 import it.inaf.ia2.aa.data.User;
+import it.inaf.oats.vospace.datamodel.NodeProperties;
 import net.ivoa.xml.vospace.v2.Node;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -61,8 +62,8 @@ public class CreateNodeController extends BaseNodeController {
 
         // First check if parent node creator is == userid
         List<String> nodeOwner
-                = getNodePropertyByURI(
-                        parentNode, "ivo://ivoa.net/vospace/core#creator");
+                = NodeProperties.getNodePropertyByURI(
+                        parentNode, NodeProperties.CREATOR_URI);
 
         if (nodeOwner == null
                 || nodeOwner.isEmpty()
@@ -78,7 +79,7 @@ public class CreateNodeController extends BaseNodeController {
             }
 
             List<String> groupWritePropValues
-                    = getNodePropertyByURI(parentNode,
+                    = NodeProperties.getNodePropertyByURI(parentNode,
                             "ivo://ivoa.net/vospace/core#groupwrite");
 
             // If groupwrite property is absent in Parent Node throw exception
@@ -88,7 +89,7 @@ public class CreateNodeController extends BaseNodeController {
             }
 
             List<String> nodeGroups
-                    = parsePropertyStringToList(groupWritePropValues.get(0));
+                    = NodeProperties.parsePropertyStringToList(groupWritePropValues.get(0));
 
             if (nodeGroups.isEmpty()
                     || !nodeGroups.stream()
@@ -129,55 +130,6 @@ 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("[/]+");
-
-        if (parsedPath.length < 2 || !parsedPath[0].isEmpty()) {
-            throw new IllegalArgumentException();
-        }
-
-        StringBuilder sb = new StringBuilder();
-        sb.append("/");
-
-        for (int i = 1; i < parsedPath.length - 1; i++) {
-            sb.append(parsedPath[i]);
-            if (i < parsedPath.length - 2) {
-                sb.append("/");
-            }
-        }
-
-        return sb.toString();
-    }
-
-    // Returns all properties stored inside the node under the requested
-    // property URI.    
-    private List<String> getNodePropertyByURI(Node node, String propertyURI) {
-
-        List<String> propertyList = node.getProperties().stream()
-                .filter((i) -> i.getUri()
-                .equals(propertyURI))
-                .map((i) -> i.getValue())
-                .collect(Collectors.toList());
-
-        return propertyList;
-    }
-
-    private List<String> parsePropertyStringToList(String property) {
-        // If separator changes, this method should remain consistent
-        // For now it assumes that " " is the separator        
-        String separator = " ";
-
-        String trimmedProperty = property.trim();
-        if (trimmedProperty.isEmpty()) {
-            return List.of();
-        }
-
-        return List.of(trimmedProperty.split(separator));
-
-    }
+    
 
 }
-- 
GitLab