Loading src/main/java/it/inaf/oats/vospace/CreateNodeController.java +6 −54 Original line number Original line Diff line number Diff line package it.inaf.oats.vospace; 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.NodeProperties; import net.ivoa.xml.vospace.v2.Node; import net.ivoa.xml.vospace.v2.Node; import org.springframework.http.MediaType; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody; Loading Loading @@ -61,8 +62,8 @@ public class CreateNodeController extends BaseNodeController { // First check if parent node creator is == userid // First check if parent node creator is == userid List<String> nodeOwner List<String> nodeOwner = getNodePropertyByURI( = NodeProperties.getNodePropertyByURI( parentNode, "ivo://ivoa.net/vospace/core#creator"); parentNode, NodeProperties.CREATOR_URI); if (nodeOwner == null if (nodeOwner == null || nodeOwner.isEmpty() || nodeOwner.isEmpty() Loading @@ -78,7 +79,7 @@ public class CreateNodeController extends BaseNodeController { } } List<String> groupWritePropValues List<String> groupWritePropValues = getNodePropertyByURI(parentNode, = NodeProperties.getNodePropertyByURI(parentNode, "ivo://ivoa.net/vospace/core#groupwrite"); "ivo://ivoa.net/vospace/core#groupwrite"); // If groupwrite property is absent in Parent Node throw exception // If groupwrite property is absent in Parent Node throw exception Loading @@ -88,7 +89,7 @@ public class CreateNodeController extends BaseNodeController { } } List<String> nodeGroups List<String> nodeGroups = parsePropertyStringToList(groupWritePropValues.get(0)); = NodeProperties.parsePropertyStringToList(groupWritePropValues.get(0)); if (nodeGroups.isEmpty() if (nodeGroups.isEmpty() || !nodeGroups.stream() || !nodeGroups.stream() Loading Loading @@ -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)); } } } Loading
src/main/java/it/inaf/oats/vospace/CreateNodeController.java +6 −54 Original line number Original line Diff line number Diff line package it.inaf.oats.vospace; 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.NodeProperties; import net.ivoa.xml.vospace.v2.Node; import net.ivoa.xml.vospace.v2.Node; import org.springframework.http.MediaType; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody; Loading Loading @@ -61,8 +62,8 @@ public class CreateNodeController extends BaseNodeController { // First check if parent node creator is == userid // First check if parent node creator is == userid List<String> nodeOwner List<String> nodeOwner = getNodePropertyByURI( = NodeProperties.getNodePropertyByURI( parentNode, "ivo://ivoa.net/vospace/core#creator"); parentNode, NodeProperties.CREATOR_URI); if (nodeOwner == null if (nodeOwner == null || nodeOwner.isEmpty() || nodeOwner.isEmpty() Loading @@ -78,7 +79,7 @@ public class CreateNodeController extends BaseNodeController { } } List<String> groupWritePropValues List<String> groupWritePropValues = getNodePropertyByURI(parentNode, = NodeProperties.getNodePropertyByURI(parentNode, "ivo://ivoa.net/vospace/core#groupwrite"); "ivo://ivoa.net/vospace/core#groupwrite"); // If groupwrite property is absent in Parent Node throw exception // If groupwrite property is absent in Parent Node throw exception Loading @@ -88,7 +89,7 @@ public class CreateNodeController extends BaseNodeController { } } List<String> nodeGroups List<String> nodeGroups = parsePropertyStringToList(groupWritePropValues.get(0)); = NodeProperties.parsePropertyStringToList(groupWritePropValues.get(0)); if (nodeGroups.isEmpty() if (nodeGroups.isEmpty() || !nodeGroups.stream() || !nodeGroups.stream() Loading Loading @@ -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)); } } }