Skip to content
Snippets Groups Projects
Commit 487b2d1d authored by Sara Bertocco's avatar Sara Bertocco
Browse files

Refactoring and new methods.

parent 06858b65
No related branches found
No related tags found
No related merge requests found
Pipeline #1051 failed
target/** target/**
/nbproject/ /nbproject/
/target/
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>15</maven.compiler.target>
<finalName>${project.artifactId}-${project.version}</finalName> <finalName>${project.artifactId}-${project.version}</finalName>
</properties> </properties>
......
...@@ -10,6 +10,7 @@ public abstract class NodeProperties { ...@@ -10,6 +10,7 @@ public abstract class NodeProperties {
private 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 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
public static final String CONTRIBUTOR_URI = "ivo://ivoa.net/vospace/core#contributor"; // an entity responsible for making contributions to this resource 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 { ...@@ -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 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 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 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 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 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 public static final String PUBLISHER_URI = "ivo://ivoa.net/vospace/core#publisher"; // an entity responsible for making the resource available
...@@ -40,15 +41,17 @@ public abstract class NodeProperties { ...@@ -40,15 +41,17 @@ public abstract class NodeProperties {
public static final String STICKY_URN = "urn:sticky"; public static final String STICKY_URN = "urn:sticky";
public static String getStandardNodePropertyByName(Node node, String propertyName) { 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) { 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(BASE_URI.concat(propertyName))) {
return property.getValue(); return property.getValue();
} }
} }
......
package it.inaf.oats.vospace.datamodel; 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 net.ivoa.xml.vospace.v2.Node;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
...@@ -14,8 +9,6 @@ import java.util.Arrays; ...@@ -14,8 +9,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.ivoa.xml.vospace.v2.StructuredDataNode;
public class NodeUtils { public class NodeUtils {
...@@ -89,7 +82,6 @@ public class NodeUtils { ...@@ -89,7 +82,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>();
...@@ -118,30 +110,24 @@ public class NodeUtils { ...@@ -118,30 +110,24 @@ public class NodeUtils {
} }
public static boolean checkIfWritable(Node myNode, String userName, List<String> userGroups) { public static boolean checkIfWritable(Node myNode, String userName, List<String> userGroups) {
return checkAccessPropery(myNode, userName, userGroups, NodeProperties.GROUP_WRITE_URI); return checkAccessPropery(myNode, userName, userGroups, NodeProperties.GROUP_WRITE_URI);
} }
public static boolean checkIfRedeable(Node myNode, String userName, List<String> userGroups) { public static boolean checkIfRedeable(Node myNode, String userName, List<String> userGroups) {
return checkAccessPropery(myNode, userName, userGroups, NodeProperties.GROUP_READ_URI); return checkAccessPropery(myNode, userName, userGroups, NodeProperties.GROUP_READ_URI);
} }
public static boolean checkAccessPropery(Node myNode, String userName, public static boolean checkAccessPropery(Node myNode, String userName,
List<String> userGroups, String accessPropertyName) { List<String> userGroups, String accessPropertyName) {
// First check if parent node creator is == userid // First check if parent node creator is == userid
List<String> nodeOwner List<String> nodeOwner
= NodeProperties.getNodePropertiesListByURI(myNode, NodeProperties.CREATOR_URI); = NodeProperties.getNodePropertyAsListByURI(myNode, NodeProperties.CREATOR_URI);
if (nodeOwner == null if (nodeOwner == null
|| nodeOwner.isEmpty() || nodeOwner.isEmpty()
...@@ -155,7 +141,7 @@ public class NodeUtils { ...@@ -155,7 +141,7 @@ public class NodeUtils {
} }
List<String> groupAccessPropValues List<String> groupAccessPropValues
= NodeProperties.getNodePropertiesListByURI(myNode, = NodeProperties.getNodePropertyAsListByURI(myNode,
accessPropertyName); accessPropertyName);
// If groupwrite property is absent in Parent Node throw exception // If groupwrite property is absent in Parent Node throw exception
......
...@@ -124,4 +124,5 @@ public class Node { ...@@ -124,4 +124,5 @@ public class Node {
this.uri = value; this.uri = value;
} }
} }
package it.inaf.oats.vospace.datamodel; 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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment