Commit 54212e6c authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Retrieved groupread and groupwrite properties from array. Added test data SQL file

parent 03e81673
Loading
Loading
Loading
Loading
+23 −15
Original line number Diff line number Diff line
package it.inaf.oats.vospace.persistence;

import java.sql.Array;
import net.ivoa.xml.vospace.v2.Node;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -94,8 +95,7 @@ public class NodeDAO {

        Node node = getTypedNode(rs.getString("type"));

        if(node instanceof DataNode)
        {
        if (node instanceof DataNode) {
            ((DataNode) node).setBusy(rs.getBoolean("busy_state"));
        }

@@ -112,10 +112,10 @@ public class NodeDAO {
        addProperty(getPropertyURI("mtime"), rs.getString("last_modified"),
                properties);

        addProperty(getPropertyURI("groupread"), rs.getString("group_read"),
        addProperty(getPropertyURI("groupread"), getGroupsString(rs, "group_read"),
                properties);

        addProperty(getPropertyURI("groupwrite"), rs.getString("group_write"),
        addProperty(getPropertyURI("groupwrite"), getGroupsString(rs, "group_write"),
                properties);

        addProperty(getPropertyURI("publicread"), rs.getString("is_public"),
@@ -132,6 +132,14 @@ public class NodeDAO {
        return "ivo://ivoa.net/vospace/core#".concat(propertyName);
    }

    private String getGroupsString(ResultSet rs, String column) throws SQLException {
        Array array = rs.getArray(column);
        if (array == null) {
            return null;
        }
        return String.join(" ", (String[]) array.getArray());
    }

    // If value is null does nothing
    private void addProperty(String uri, String value, List<Property> list) {
        if (value != null) {
+2 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ public class DataSourceConfig {
                ByteArrayResource scriptResource = replaceDollarQuoting(script.toPath());
                ScriptUtils.executeSqlScript(conn, scriptResource);
            }

            ScriptUtils.executeSqlScript(conn, new ClassPathResource("test-data.sql"));
        }
    }

+14 −1
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@ package it.inaf.oats.vospace.persistence;

import javax.sql.DataSource;
import net.ivoa.xml.vospace.v2.ContainerNode;
import net.ivoa.xml.vospace.v2.Node;
import net.ivoa.xml.vospace.v2.Property;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -28,6 +30,17 @@ public class NodeDAOTest {
    @Test
    public void testListNode() {
        ContainerNode root = (ContainerNode) dao.listNode("/").get();
        assertEquals(4, root.getNodes().size());
        assertEquals(2, root.getNodes().size());

        assertEquals("group1 group2", getProperty(root.getNodes().get(0), "ivo://ivoa.net/vospace/core#groupread"));
    }

    private String getProperty(Node node, String uri) {
        for (Property property : node.getProperties()) {
            if (uri.equals(property.getUri())) {
                return property.getValue();
            }
        }
        return null;
    }
}
+13 −0
Original line number Diff line number Diff line
DELETE FROM node;
ALTER SEQUENCE node_node_id_seq RESTART WITH 1;

INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id) VALUES (NULL, NULL, '', 'container', '0', '0');

INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, group_read, group_write) VALUES ('', NULL, 'test1', 'container', 'user1', 'user1', '{"group1","group2"}','{"group2"}');      -- /test1
INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id) VALUES ('2', '', 'f1', 'container', 'user1', 'user1');      -- /test1/f1 (rel: /f1)
INSERT INTO node (parent_path, parent_relative_path, name, os_name, type, owner_id, creator_id) VALUES ('2.3', '3', 'f2_renamed', 'f2', 'container', 'user1', 'user1');      -- /test1/f1/f2_renamed (rel: /f1/f2)
INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id) VALUES ('2.3.4', '3.4', 'f3', 'data', 'user1', 'user1');      -- /test1/f1/f2_renamed/f3 (rel: /f1/f2/f3)

INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, is_public) VALUES ('', NULL, 'test2', 'container', 'user2', 'user2', true);      -- /test2
INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, is_public) VALUES ('5', '', 'f4', 'container', 'user2', 'user2', true);    -- /test2/f4 (rel: /f4)
INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, is_public) VALUES ('5', '', 'f5', 'container', 'user2', 'user2', true);    -- /test2/f5 (rel: /f5)