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

Split getNodePropertyByURI in 2 methods (String and List results); Added...

Split getNodePropertyByURI in 2 methods (String and List results); Added checkIfReadable util method
parent 2007e86b
No related branches found
No related tags found
No related merge requests found
Pipeline #987 passed
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package it.inaf.oats.vospace.datamodel; package it.inaf.oats.vospace.datamodel;
import java.util.List; import java.util.List;
...@@ -10,14 +5,10 @@ import java.util.stream.Collectors; ...@@ -10,14 +5,10 @@ import java.util.stream.Collectors;
import net.ivoa.xml.vospace.v2.Node; import net.ivoa.xml.vospace.v2.Node;
import net.ivoa.xml.vospace.v2.Property; import net.ivoa.xml.vospace.v2.Property;
/** public abstract class NodeProperties {
*
* @author bertocco
*/
public class NodeProperties {
private NodeProperties() {
private NodeProperties() { } }
public static final String AVAILABLE_SPACE_URI = "ivo://ivoa.net/vospace/core#availableSpace"; // the amount of space available within a container public static final String AVAILABLE_SPACE_URI = "ivo://ivoa.net/vospace/core#availableSpace"; // the amount of space available within a container
public static final String INITIAL_CREATION_TIME_URI = "ivo://ivoa.net/vospace/core#btime"; // the initial creation time public static final String INITIAL_CREATION_TIME_URI = "ivo://ivoa.net/vospace/core#btime"; // the initial creation time
...@@ -43,14 +34,18 @@ public class NodeProperties { ...@@ -43,14 +34,18 @@ public class NodeProperties {
public static final String SUBJECT_URI = "ivo://ivoa.net/vospace/core#subject"; // the topic of the resource public static final String SUBJECT_URI = "ivo://ivoa.net/vospace/core#subject"; // the topic of the resource
public static final String TITLE_URI = "ivo://ivoa.net/vospace/core#title"; // a name given to the resource public static final String TITLE_URI = "ivo://ivoa.net/vospace/core#title"; // a name given to the resource
public static final String TYPE_URI = "ivo://ivoa.net/vospace/core#type"; // the nature or genre of the resource public static final String TYPE_URI = "ivo://ivoa.net/vospace/core#type"; // the nature or genre of the resource
//
// Non-standard properties
public static final String ASYNC_TRANS_URN = "urn:async_trans";
public static final String STICKY_URN = "urn:sticky";
public static String getStandardNodePropertyByName(Node node, String propertyName) {
return getNodePropertyByURI(node, "ivo://ivoa.net/vospace/core#".concat(propertyName));
}
public static String getNodePropertyByURI(Node node, String propertyURI) {
public static String getProperty(Node node, String propertyName) {
for (Property property : node.getProperties()) { for (Property property : node.getProperties()) {
if (property.getUri().equals("ivo://ivoa.net/vospace/core#".concat(propertyName))) { if (property.getUri().equals(propertyURI)) {
return property.getValue(); return property.getValue();
} }
} }
...@@ -59,7 +54,7 @@ public class NodeProperties { ...@@ -59,7 +54,7 @@ public class NodeProperties {
// Returns all properties stored inside the node under the requested // Returns all properties stored inside the node under the requested
// property URI. // property URI.
public static List<String> getNodePropertyByURI(Node node, String propertyURI) { public static List<String> getNodePropertyAsListByURI(Node node, String propertyURI) {
List<String> propertyList = node.getProperties().stream() List<String> propertyList = node.getProperties().stream()
.filter((i) -> i.getUri() .filter((i) -> i.getUri()
...@@ -81,7 +76,5 @@ public class NodeProperties { ...@@ -81,7 +76,5 @@ public class NodeProperties {
} }
return List.of(trimmedProperty.split(separator)); return List.of(trimmedProperty.split(separator));
} }
} }
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package it.inaf.oats.vospace.datamodel; package it.inaf.oats.vospace.datamodel;
import java.security.Principal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.ivoa.xml.vospace.v2.Node; import net.ivoa.xml.vospace.v2.Node;
public class NodeUtils { public class NodeUtils {
/** /**
* Slash is a special character in defining REST endpoints and trying to * Slash is a special character in defining REST endpoints and trying to
* define a PathVariable containing slashes doesn't work, so the endpoint * define a PathVariable containing slashes doesn't work, so the endpoint
...@@ -56,7 +47,6 @@ public class NodeUtils { ...@@ -56,7 +47,6 @@ public class NodeUtils {
return sb.toString(); return sb.toString();
} }
public static List<String> subPathComponents(String path) { public static List<String> subPathComponents(String path) {
List resultList = new ArrayList<String>(); List resultList = new ArrayList<String>();
...@@ -76,21 +66,48 @@ public class NodeUtils { ...@@ -76,21 +66,48 @@ public class NodeUtils {
parentPath = parentPath + pathComponents[i] + "/"; parentPath = parentPath + pathComponents[i] + "/";
// "I'm managing path = " + parentPath.substring(0, parentPath.length()-1)); // "I'm managing path = " + parentPath.substring(0, parentPath.length()-1));
resultList.add(parentPath.substring(0, parentPath.length() - 1)); resultList.add(parentPath.substring(0, parentPath.length() - 1));
}
}
return resultList;
} }
public static boolean checkIfReadable(Node myNode, String userName, List<String> userGroups) {
if ("true".equals(NodeProperties.getNodePropertyByURI(myNode, NodeProperties.PUBLIC_READ_URI))) {
return true;
} }
return resultList; String creator = NodeProperties.getNodePropertyByURI(myNode, NodeProperties.CREATOR_URI);
if (creator != null && creator.equals(userName)) {
return true;
}
if (userGroups == null || userGroups.isEmpty()) {
return false;
}
List<String> groupReadValues = NodeProperties.getNodePropertyAsListByURI(myNode, NodeProperties.GROUP_READ_URI);
if (groupReadValues == null) {
return false;
}
for (String group : groupReadValues) {
if (userGroups.contains(group)) {
return true;
}
}
return false;
} }
public static boolean checkIfWritable(Node myNode, String userName, List<String> userGroups) { public static boolean checkIfWritable(Node myNode, String userName, List<String> userGroups) {
// First check if parent node creator is == userid // First check if parent node creator is == userid
List<String> nodeOwner List<String> nodeOwner
= NodeProperties.getNodePropertyByURI(myNode, NodeProperties.CREATOR_URI); = NodeProperties.getNodePropertyAsListByURI(myNode, NodeProperties.CREATOR_URI);
if (nodeOwner == null if (nodeOwner == null
|| nodeOwner.isEmpty() || nodeOwner.isEmpty()
...@@ -104,7 +121,7 @@ public class NodeUtils { ...@@ -104,7 +121,7 @@ public class NodeUtils {
} }
List<String> groupWritePropValues List<String> groupWritePropValues
= NodeProperties.getNodePropertyByURI(myNode, = NodeProperties.getNodePropertyAsListByURI(myNode,
NodeProperties.GROUP_WRITE_URI); NodeProperties.GROUP_WRITE_URI);
// If groupwrite property is absent in Parent Node throw exception // If groupwrite property is absent in Parent Node throw exception
...@@ -126,5 +143,4 @@ public class NodeUtils { ...@@ -126,5 +143,4 @@ public class NodeUtils {
return true; return true;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment