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
Loading
Loading
Loading
Loading
Loading
+38 −45
Original line number Diff line number Diff line
/*
 * 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;

import java.util.List;
@@ -10,14 +5,10 @@ import java.util.stream.Collectors;
import net.ivoa.xml.vospace.v2.Node;
import net.ivoa.xml.vospace.v2.Property;

/**
 *
 * @author bertocco
 */
public class NodeProperties {
public abstract 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 INITIAL_CREATION_TIME_URI = "ivo://ivoa.net/vospace/core#btime";       // the initial creation time
@@ -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 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
    //
    // 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 getProperty(Node node, String propertyName) {

    public static String getNodePropertyByURI(Node node, String propertyURI) {
        for (Property property : node.getProperties()) {
            if (property.getUri().equals("ivo://ivoa.net/vospace/core#".concat(propertyName))) {
            if (property.getUri().equals(propertyURI)) {
                return property.getValue();
            }
        }
@@ -59,7 +54,7 @@ public class NodeProperties {

    // Returns all properties stored inside the node under the requested
    // 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()
                .filter((i) -> i.getUri()
@@ -81,7 +76,5 @@ public class NodeProperties {
        }

        return List.of(trimmedProperty.split(separator));

    }
    
}
+53 −37
Original line number Diff line number Diff line
/*
 * 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;

import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import net.ivoa.xml.vospace.v2.Node;


public class NodeUtils {

    
    
    /**
     * Slash is a special character in defining REST endpoints and trying to
     * define a PathVariable containing slashes doesn't work, so the endpoint
@@ -56,7 +47,6 @@ public class NodeUtils {
        return sb.toString();
    }

    
    public static List<String> subPathComponents(String path) {

        List resultList = new ArrayList<String>();
@@ -76,21 +66,48 @@ public class NodeUtils {
                parentPath = parentPath + pathComponents[i] + "/";
                // "I'm managing path = " + 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) {

        // First check if parent node creator is == userid
        List<String> nodeOwner
                = NodeProperties.getNodePropertyByURI(myNode, NodeProperties.CREATOR_URI);
                        
                = NodeProperties.getNodePropertyAsListByURI(myNode, NodeProperties.CREATOR_URI);

        if (nodeOwner == null
                || nodeOwner.isEmpty()
@@ -104,7 +121,7 @@ public class NodeUtils {
            }

            List<String> groupWritePropValues
                    = NodeProperties.getNodePropertyByURI(myNode,
                    = NodeProperties.getNodePropertyAsListByURI(myNode,
                            NodeProperties.GROUP_WRITE_URI);

            // If groupwrite property is absent in Parent Node throw exception
@@ -126,5 +143,4 @@ public class NodeUtils {

        return true;
    }
    
}