diff --git a/src/main/java/it/inaf/oats/vospace/UriService.java b/src/main/java/it/inaf/oats/vospace/UriService.java index ca39095ea146cfdbabc4de8a82d96b8fdcd62f14..0041ba21c45161dba80908b414dd922dddd04cca 100644 --- a/src/main/java/it/inaf/oats/vospace/UriService.java +++ b/src/main/java/it/inaf/oats/vospace/UriService.java @@ -11,7 +11,6 @@ import javax.servlet.http.HttpServletRequest; import net.ivoa.xml.uws.v1.JobSummary; import net.ivoa.xml.uws.v1.ResultReference; import net.ivoa.xml.vospace.v2.Node; -import net.ivoa.xml.vospace.v2.Property; import net.ivoa.xml.vospace.v2.Protocol; import net.ivoa.xml.vospace.v2.Transfer; import org.springframework.beans.factory.annotation.Autowired; @@ -74,7 +73,7 @@ public class UriService { // TODO add token for authenticated access String endpoint = fileServiceUrl + relativePath + "?jobId=" + job.getJobId(); - if (!"true".equals(NodeProperties.getProperty(node, "publicread"))) { + if (!"true".equals(NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI))) { endpoint += "&token=" + getEndpointToken(fileServiceUrl + relativePath); } 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 f9021ab477e34a782191911abe40ce868ee1f5dd..216f64c9264dcdae970c28672da39e0686e338b8 100644 --- a/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +++ b/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java @@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; - @Repository public class NodeDAO { @@ -89,7 +88,7 @@ public class NodeDAO { public Optional<Node> listNode(String path) { - String sql = "SELECT os.vos_path, n.node_id, type, async_trans, busy_state, creator_id, group_read, group_write,\n" + String sql = "SELECT os.vos_path, n.node_id, type, async_trans, sticky, busy_state, creator_id, group_read, group_write,\n" + "is_public, content_length, created_on, last_modified, accept_views, provide_views\n" + "FROM node n\n" + "JOIN node_vos_path os ON n.node_id = os.node_id\n" @@ -178,16 +177,18 @@ public class NodeDAO { addProperty(getPropertyURI("groupwrite"), getGroupsString(rs, "group_write"), properties); - addProperty(getPropertyURI("publicread"), rs.getString("is_public"), + addProperty(getPropertyURI("publicread"), String.valueOf(rs.getBoolean("is_public")), properties); - addProperty("urn:async_trans", rs.getString("async_trans"), + addProperty("urn:async_trans", String.valueOf(rs.getBoolean("async_trans")), properties); + addProperty("urn:sticky", String.valueOf(rs.getBoolean("sticky")), properties); + node.setProperties(properties); return node; } - + public void deleteNode(String path) { int nodesWithPath = countNodesWithPath(path); if (nodesWithPath == 0) { @@ -205,8 +206,8 @@ public class NodeDAO { + "async_trans, busy_state, owner_id, creator_id, group_read, " + "group_write, is_public, delta, content_type, content_encoding, " + "content_length, content_md5, created_on, last_modified, " - + "accept_views, provide_views, protocols)\n"; - + + "accept_views, provide_views, protocols, sticky)\n"; + String deleteSql = "DELETE \n" + "FROM node n\n" + "USING node_vos_path os\n" @@ -218,13 +219,13 @@ public class NodeDAO { + "async_trans, busy_state, owner_id, creator_id, group_read, " + "group_write, is_public, delta, content_type, content_encoding, " + "content_length, content_md5, created_on, last_modified, " - + "accept_views, provide_views, protocols\n"; - - String withSql = "WITH del AS ("+deleteSql+")"; - - String sql = withSql+insertSql+"SELECT * FROM del\n"; - - jdbcTemplate.update(sql, path, path); + + "accept_views, provide_views, protocols, sticky\n"; + + String withSql = "WITH del AS (" + deleteSql + ")"; + + String sql = withSql + insertSql + "SELECT * FROM del\n"; + + jdbcTemplate.update(sql, path, path); } // utility method for deleteNode 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 bb41fc74b0b24fe7ae57e49fc2c0fa2e67bc9ba1..073e2646f0058c1e209e6f67f290c6b9fc52f040 100644 --- a/src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java +++ b/src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java @@ -1,5 +1,7 @@ package it.inaf.oats.vospace.persistence; +import it.inaf.oats.vospace.datamodel.NodeProperties; +import it.inaf.oats.vospace.datamodel.NodeUtils; import java.util.ArrayList; import java.util.List; import javax.sql.DataSource; @@ -53,6 +55,8 @@ public class NodeDAOTest { public void testListNode() { ContainerNode root = (ContainerNode) dao.listNode("/").get(); assertEquals(2, root.getNodes().size()); + + assertEquals("true", NodeProperties.getNodePropertyAsListByURI(root, NodeProperties.PUBLIC_READ_URI).get(0)); assertEquals("group1 group2", getProperty(root.getNodes().get(0), "ivo://ivoa.net/vospace/core#groupread")); } diff --git a/src/test/resources/test-data.sql b/src/test/resources/test-data.sql index 37ca24465cf434ff9ae2e60e81c4c676dc594dff..15d968fe837d88add352d84ef0696bc0cd913251 100644 --- a/src/test/resources/test-data.sql +++ b/src/test/resources/test-data.sql @@ -1,7 +1,7 @@ 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, location_id) VALUES (NULL, NULL, '', 'container', '0', '0', 1); +INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, location_id, is_public) VALUES (NULL, NULL, '', 'container', '0', '0', 1, true); INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, group_read, group_write, location_id) VALUES ('', NULL, 'test1', 'container', 'user1', 'user1', '{"group1","group2"}','{"group2"}', 1); -- /test1 INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, location_id) VALUES ('2', '', 'f1', 'container', 'user1', 'user1', 1); -- /test1/f1 (rel: /f1)