Loading src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +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; Loading Loading @@ -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")); } Loading @@ -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"), Loading @@ -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) { Loading src/test/java/it/inaf/oats/vospace/persistence/DataSourceConfig.java +2 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,8 @@ public class DataSourceConfig { ByteArrayResource scriptResource = replaceDollarQuoting(script.toPath()); ScriptUtils.executeSqlScript(conn, scriptResource); } ScriptUtils.executeSqlScript(conn, new ClassPathResource("test-data.sql")); } } Loading src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java +14 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; } } src/test/resources/test-data.sql 0 → 100644 +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) Loading
src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +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; Loading Loading @@ -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")); } Loading @@ -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"), Loading @@ -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) { Loading
src/test/java/it/inaf/oats/vospace/persistence/DataSourceConfig.java +2 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,8 @@ public class DataSourceConfig { ByteArrayResource scriptResource = replaceDollarQuoting(script.toPath()); ScriptUtils.executeSqlScript(conn, scriptResource); } ScriptUtils.executeSqlScript(conn, new ClassPathResource("test-data.sql")); } } Loading
src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java +14 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; } }
src/test/resources/test-data.sql 0 → 100644 +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)