diff --git a/.gitignore b/.gitignore index 222fb6170412423a5f8f5add107be1fc6bf4f21e..adf370143dd81cff1e9d307c1319569be4a215c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target/** /nbproject/ +/target/ diff --git a/pom.xml b/pom.xml index 379d41eef6bffcdd6cea60d97080505c1de2a466..9a6747ef5f9271b564c7ba2bd1fde4f186ea873c 100644 --- a/pom.xml +++ b/pom.xml @@ -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> diff --git a/src/main/java/it/inaf/oats/vospace/datamodel/NodeProperties.java b/src/main/java/it/inaf/oats/vospace/datamodel/NodeProperties.java index fac730e73dce3e82cb1b2fab306f61685f377ed5..fbc098a9ef05a0a4b6610cb4060537d2c78a5fb2 100644 --- a/src/main/java/it/inaf/oats/vospace/datamodel/NodeProperties.java +++ b/src/main/java/it/inaf/oats/vospace/datamodel/NodeProperties.java @@ -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(); } } diff --git a/src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java b/src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java index 77c14b13ae98e74839639db7121b2aa8c89d097d..5a0c7c61f29c6d8d38e6cd3a6e13f8608005069f 100644 --- a/src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java +++ b/src/main/java/it/inaf/oats/vospace/datamodel/NodeUtils.java @@ -1,10 +1,5 @@ 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; - } - + } + } diff --git a/src/main/java/net/ivoa/xml/vospace/v2/Node.java b/src/main/java/net/ivoa/xml/vospace/v2/Node.java index 277e12fba4799f8a50335b5ecc455963a6abe5a1..c90a75cda047c5e6a7cd71dbf676a8dacd97a41b 100644 --- a/src/main/java/net/ivoa/xml/vospace/v2/Node.java +++ b/src/main/java/net/ivoa/xml/vospace/v2/Node.java @@ -123,5 +123,6 @@ public class Node { public void setUri(String value) { this.uri = value; } - + + } diff --git a/src/test/java/it/inaf/oats/vospace/datamodel/NodeUtilsTest.java b/src/test/java/it/inaf/oats/vospace/datamodel/NodeUtilsTest.java index eb52987bc75d772973804cca85ef6550299d8078..065dd2014e84c8f45eeb04dd79afcadda15545ab 100644 --- a/src/test/java/it/inaf/oats/vospace/datamodel/NodeUtilsTest.java +++ b/src/test/java/it/inaf/oats/vospace/datamodel/NodeUtilsTest.java @@ -1,5 +1,8 @@ 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;