Skip to content
Snippets Groups Projects
Commit 0c30dec1 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

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

parent 93e2b324
No related branches found
No related tags found
No related merge requests found
Pipeline #855 passed
package it.inaf.oats.vospace.persistence; package it.inaf.oats.vospace.persistence;
import java.sql.Array;
import net.ivoa.xml.vospace.v2.Node; import net.ivoa.xml.vospace.v2.Node;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -94,8 +95,7 @@ public class NodeDAO { ...@@ -94,8 +95,7 @@ public class NodeDAO {
Node node = getTypedNode(rs.getString("type")); Node node = getTypedNode(rs.getString("type"));
if(node instanceof DataNode) if (node instanceof DataNode) {
{
((DataNode) node).setBusy(rs.getBoolean("busy_state")); ((DataNode) node).setBusy(rs.getBoolean("busy_state"));
} }
...@@ -112,10 +112,10 @@ public class NodeDAO { ...@@ -112,10 +112,10 @@ public class NodeDAO {
addProperty(getPropertyURI("mtime"), rs.getString("last_modified"), addProperty(getPropertyURI("mtime"), rs.getString("last_modified"),
properties); properties);
addProperty(getPropertyURI("groupread"), rs.getString("group_read"), addProperty(getPropertyURI("groupread"), getGroupsString(rs, "group_read"),
properties); properties);
addProperty(getPropertyURI("groupwrite"), rs.getString("group_write"), addProperty(getPropertyURI("groupwrite"), getGroupsString(rs, "group_write"),
properties); properties);
addProperty(getPropertyURI("publicread"), rs.getString("is_public"), addProperty(getPropertyURI("publicread"), rs.getString("is_public"),
...@@ -132,6 +132,14 @@ public class NodeDAO { ...@@ -132,6 +132,14 @@ public class NodeDAO {
return "ivo://ivoa.net/vospace/core#".concat(propertyName); 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 // If value is null does nothing
private void addProperty(String uri, String value, List<Property> list) { private void addProperty(String uri, String value, List<Property> list) {
if (value != null) { if (value != null) {
......
...@@ -84,6 +84,8 @@ public class DataSourceConfig { ...@@ -84,6 +84,8 @@ public class DataSourceConfig {
ByteArrayResource scriptResource = replaceDollarQuoting(script.toPath()); ByteArrayResource scriptResource = replaceDollarQuoting(script.toPath());
ScriptUtils.executeSqlScript(conn, scriptResource); ScriptUtils.executeSqlScript(conn, scriptResource);
} }
ScriptUtils.executeSqlScript(conn, new ClassPathResource("test-data.sql"));
} }
} }
......
...@@ -2,6 +2,8 @@ package it.inaf.oats.vospace.persistence; ...@@ -2,6 +2,8 @@ package it.inaf.oats.vospace.persistence;
import javax.sql.DataSource; import javax.sql.DataSource;
import net.ivoa.xml.vospace.v2.ContainerNode; 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 static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -28,6 +30,17 @@ public class NodeDAOTest { ...@@ -28,6 +30,17 @@ public class NodeDAOTest {
@Test @Test
public void testListNode() { public void testListNode() {
ContainerNode root = (ContainerNode) dao.listNode("/").get(); 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;
} }
} }
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment