diff --git a/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java b/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java index 853e5f2cb948d44b2e5b28cfa448d0942b59a3aa..64ab6b68f8d52555f2388437491cbb01e462033c 100644 --- a/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +++ b/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java @@ -1,5 +1,6 @@ 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; @@ -93,38 +94,37 @@ public class NodeDAO { private Node getNodeFromResultSet(ResultSet rs) throws SQLException { Node node = getTypedNode(rs.getString("type")); - - if(node instanceof DataNode) - { + + if (node instanceof DataNode) { ((DataNode) node).setBusy(rs.getBoolean("busy_state")); - } - + } + node.setUri(getUri(rs.getString("vos_path"))); List<Property> properties = new ArrayList<>(); - + addProperty(getPropertyURI("length"), rs.getString("content_length"), properties); - + addProperty(getPropertyURI("btime"), rs.getString("created_on"), properties); - + 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"), properties); - + addProperty("urn:async_trans", rs.getString("async_trans"), properties); - node.setProperties(properties); + node.setProperties(properties); return node; } @@ -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) { diff --git a/src/test/java/it/inaf/oats/vospace/persistence/DataSourceConfig.java b/src/test/java/it/inaf/oats/vospace/persistence/DataSourceConfig.java index 9ba7203d9eba1decfd7b1875d1fd23f7af4ab95b..eadeaec8d8962ee0e45436f8ebc06caf269762f8 100644 --- a/src/test/java/it/inaf/oats/vospace/persistence/DataSourceConfig.java +++ b/src/test/java/it/inaf/oats/vospace/persistence/DataSourceConfig.java @@ -84,6 +84,8 @@ public class DataSourceConfig { ByteArrayResource scriptResource = replaceDollarQuoting(script.toPath()); ScriptUtils.executeSqlScript(conn, scriptResource); } + + ScriptUtils.executeSqlScript(conn, new ClassPathResource("test-data.sql")); } } diff --git a/src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java b/src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java index b0757235b8f8dad130246a5ba0f2b10ceb9e6a37..d1cfcf0ddd2cfac25120653b87d6b53dfb7fa500 100644 --- a/src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java +++ b/src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java @@ -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; } } diff --git a/src/test/resources/test-data.sql b/src/test/resources/test-data.sql new file mode 100644 index 0000000000000000000000000000000000000000..2a0c10bc91be31372de426fc50c14c550911a448 --- /dev/null +++ b/src/test/resources/test-data.sql @@ -0,0 +1,13 @@ +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)