Commit 487b2d1d authored by Sara Bertocco's avatar Sara Bertocco
Browse files

Refactoring and new methods.

parent 06858b65
Pipeline #1051 failed with stages
in 8 seconds
target/**
/nbproject/
/target/
......@@ -7,8 +7,8 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<finalName>${project.artifactId}-${project.version}</finalName>
</properties>
......
......@@ -10,6 +10,7 @@ public abstract class NodeProperties {
private NodeProperties() { }
public static final String BASE_URI = "ivo://ivoa.net/vospace/core#";
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 CONTRIBUTOR_URI = "ivo://ivoa.net/vospace/core#contributor"; // an entity responsible for making contributions to this resource
......@@ -23,7 +24,7 @@ public abstract class NodeProperties {
public static final String GROUP_WRITE_URI = "ivo://ivoa.net/vospace/core#groupwrite"; // the list of groups which can read and write to this resource delimiter-separated
public static final String IDENTIFIER_URI = "ivo://ivoa.net/vospace/core#identifier"; // an unambiguous reference to the resource within a given context
public static final String LANGUAGE_URI = "ivo://ivoa.net/vospace/core#language"; // a language of the resource
public static final String CORE_URI = "ivo://ivoa.net/vospace/core#length"; // the length or size of a resource
public static final String LENGTH_URI = "ivo://ivoa.net/vospace/core#length"; // the length or size of a resource
public static final String MODIFICATION_TIME_URI = "ivo://ivoa.net/vospace/core#mtime"; // the data modification time
public static final String PUBLIC_READ_URI = "ivo://ivoa.net/vospace/core#publicread"; // whether this resource is world readable
public static final String PUBLISHER_URI = "ivo://ivoa.net/vospace/core#publisher"; // an entity responsible for making the resource available
......@@ -38,17 +39,19 @@ public abstract class NodeProperties {
// 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));
return getNodePropertyByURI(node, BASE_URI.concat(propertyName));
}
public static String getProperty(Node node, String propertyName) {
for (Property property : node.getProperties()) {
if (property.getUri().equals("ivo://ivoa.net/vospace/core#".concat(propertyName))) {
if (property.getUri().equals(BASE_URI.concat(propertyName))) {
return property.getValue();
}
}
......
package it.inaf.oats.vospace.datamodel;
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import net.ivoa.xml.vospace.v2.ContainerNode;
import net.ivoa.xml.vospace.v2.DataNode;
import net.ivoa.xml.vospace.v2.Node;
import java.net.URLDecoder;
import java.net.URLEncoder;
......@@ -14,8 +9,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import net.ivoa.xml.vospace.v2.StructuredDataNode;
public class NodeUtils {
......@@ -64,7 +57,7 @@ public class NodeUtils {
.map(p -> URLEncoder.encode(p, StandardCharsets.UTF_8).replace("+", "%20"))
.collect(Collectors.toList()));
}
// 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
......@@ -88,61 +81,54 @@ public class NodeUtils {
return sb.toString();
}
public static List<String> subPathComponents(String path) {
List resultList = new ArrayList<String>();
String[] pathComponents = path.split("[/]+");
if (pathComponents.length == 0) {
if (pathComponents.length == 0) {
// Manage root node
resultList.add("/");
} else {
// Manage all precursors in full path
String parentPath="/";
for (int i = 1; i < pathComponents.length; i++) {
String parentPath = "/";
for (int i = 1; i < pathComponents.length; i++) {
parentPath = parentPath + pathComponents[i] + "/";
// "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 checkIfWritable(Node myNode, String userName, List<String> userGroups) {
return checkAccessPropery(myNode, userName, userGroups, NodeProperties.GROUP_WRITE_URI);
}
public static boolean checkIfRedeable(Node myNode, String userName, List<String> userGroups) {
return checkAccessPropery(myNode, userName, userGroups, NodeProperties.GROUP_READ_URI);
}
public static boolean checkAccessPropery(Node myNode, String userName,
List<String> userGroups, String accessPropertyName) {
public static boolean checkAccessPropery(Node myNode, String userName,
List<String> userGroups, String accessPropertyName) {
// First check if parent node creator is == userid
List<String> nodeOwner
= NodeProperties.getNodePropertiesListByURI(myNode, NodeProperties.CREATOR_URI);
= NodeProperties.getNodePropertyAsListByURI(myNode, NodeProperties.CREATOR_URI);
if (nodeOwner == null
|| nodeOwner.isEmpty()
|| !nodeOwner.get(0).equals(userName)) {
......@@ -155,13 +141,13 @@ public class NodeUtils {
}
List<String> groupAccessPropValues
= NodeProperties.getNodePropertiesListByURI(myNode,
= NodeProperties.getNodePropertyAsListByURI(myNode,
accessPropertyName);
// If groupwrite property is absent in Parent Node throw exception
if (groupAccessPropValues == null
|| groupAccessPropValues.isEmpty()) {
return false;
return false;
}
List<String> nodeGroups
......@@ -176,6 +162,6 @@ public class NodeUtils {
}
return true;
}
}
}
......@@ -123,5 +123,6 @@ public class Node {
public void setUri(String value) {
this.uri = value;
}
}
package it.inaf.oats.vospace.datamodel;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment