Loading src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +31 −4 Original line number Original line Diff line number Diff line Loading @@ -171,20 +171,31 @@ public class NodeDAO { String vosPath = URIUtils.returnVosPathFromNodeURI(newNode, authority); String vosPath = URIUtils.returnVosPathFromNodeURI(newNode, authority); if (recursive) { boolean isLinkNode = newNode instanceof LinkNode; // If is link ignore recursive: LinkNodes are supposed to be childless if (recursive && !isLinkNode) { updatePermissionsRecursively(newNode, vosPath); updatePermissionsRecursively(newNode, vosPath); } else { } else { jdbcTemplate.update(conn -> { jdbcTemplate.update(conn -> { String sql = "UPDATE node\n" String sql = "UPDATE node\n" + "SET group_read = ?, group_write = ?, is_public = ?" + "SET group_read = ?, group_write = ?, is_public = ?\n"; + "WHERE node_id = id_from_vos_path(?)\n"; if (isLinkNode) { sql += ", target = ?\n"; } sql += "WHERE node_id = id_from_vos_path(?)\n"; PreparedStatement ps = conn.prepareStatement(sql); PreparedStatement ps = conn.prepareStatement(sql); int i = 0; int i = 0; ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_READ_URI))); ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_READ_URI))); ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_WRITE_URI))); ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_WRITE_URI))); ps.setBoolean(++i, Boolean.valueOf(NodeProperties.getNodePropertyByURI(newNode, NodeProperties.PUBLIC_READ_URI))); ps.setBoolean(++i, Boolean.valueOf(NodeProperties.getNodePropertyByURI(newNode, NodeProperties.PUBLIC_READ_URI))); if (isLinkNode) { ps.setString(++i, ((LinkNode) newNode).getTarget() ); } ps.setString(++i, vosPath); ps.setString(++i, vosPath); return ps; return ps; }); }); Loading @@ -193,6 +204,22 @@ public class NodeDAO { return newNode; return newNode; } } private void setLinkNodeTarget(String nodeVosPath, String target) { jdbcTemplate.update(conn -> { String sql = "UPDATE node\n" + "SET target = ?\n" + "WHERE node_id = id_from_vos_path(?)\n"; PreparedStatement ps = conn.prepareStatement(sql); int i = 0; ps.setString(++i, target); ps.setString(++i, nodeVosPath); return ps; }); } private Node getNodeFromResultSet(ResultSet rs) throws SQLException { private Node getNodeFromResultSet(ResultSet rs) throws SQLException { Node node = NodeUtils.getTypedNode(rs.getString("type")); Node node = NodeUtils.getTypedNode(rs.getString("type")); Loading src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java +63 −37 Original line number Original line Diff line number Diff line Loading @@ -311,7 +311,6 @@ public class NodeDAOTest { } } @Test @Test public void testCopyNodeBranch() { public void testCopyNodeBranch() { // Let's copy /test3/m1 to /test3/group1 // Let's copy /test3/m1 to /test3/group1 Loading Loading @@ -445,6 +444,33 @@ public class NodeDAOTest { assertEquals("true", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); assertEquals("true", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); } } @Test public void testSetLinkNodeTarget() { Property publicReadProperty = getProperty(NodeProperties.PUBLIC_READ_URI, String.valueOf(false)); LinkNode node = new LinkNode(); node.setUri("vos://example.com!vospace/mylink1"); node.getProperties().add(publicReadProperty); node.setTarget("vos://example.com!vospace/mydummytarget1"); dao.createNode(node); node = (LinkNode) dao.listNode("/mylink1").get(); assertEquals("false", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); assertEquals("vos://example.com!vospace/mydummytarget1", node.getTarget()); node.getProperties().clear(); publicReadProperty.setValue(String.valueOf(true)); node.getProperties().add(publicReadProperty); node.setTarget("vos://example.com!vospace/mydummytarget1_modded"); dao.setNode(node); node = (LinkNode) dao.listNode("/mylink1").get(); assertEquals("true", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); assertEquals("vos://example.com!vospace/mydummytarget1_modded", node.getTarget()); } @Test @Test public void testSetNodeRecursiveGroup() { public void testSetNodeRecursiveGroup() { Loading src/main/java/it/inaf/oats/vospace/SetNodeController.java +1 −1 File changed.Contains only whitespace changes. Show changes Loading
src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +31 −4 Original line number Original line Diff line number Diff line Loading @@ -171,20 +171,31 @@ public class NodeDAO { String vosPath = URIUtils.returnVosPathFromNodeURI(newNode, authority); String vosPath = URIUtils.returnVosPathFromNodeURI(newNode, authority); if (recursive) { boolean isLinkNode = newNode instanceof LinkNode; // If is link ignore recursive: LinkNodes are supposed to be childless if (recursive && !isLinkNode) { updatePermissionsRecursively(newNode, vosPath); updatePermissionsRecursively(newNode, vosPath); } else { } else { jdbcTemplate.update(conn -> { jdbcTemplate.update(conn -> { String sql = "UPDATE node\n" String sql = "UPDATE node\n" + "SET group_read = ?, group_write = ?, is_public = ?" + "SET group_read = ?, group_write = ?, is_public = ?\n"; + "WHERE node_id = id_from_vos_path(?)\n"; if (isLinkNode) { sql += ", target = ?\n"; } sql += "WHERE node_id = id_from_vos_path(?)\n"; PreparedStatement ps = conn.prepareStatement(sql); PreparedStatement ps = conn.prepareStatement(sql); int i = 0; int i = 0; ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_READ_URI))); ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_READ_URI))); ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_WRITE_URI))); ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_WRITE_URI))); ps.setBoolean(++i, Boolean.valueOf(NodeProperties.getNodePropertyByURI(newNode, NodeProperties.PUBLIC_READ_URI))); ps.setBoolean(++i, Boolean.valueOf(NodeProperties.getNodePropertyByURI(newNode, NodeProperties.PUBLIC_READ_URI))); if (isLinkNode) { ps.setString(++i, ((LinkNode) newNode).getTarget() ); } ps.setString(++i, vosPath); ps.setString(++i, vosPath); return ps; return ps; }); }); Loading @@ -193,6 +204,22 @@ public class NodeDAO { return newNode; return newNode; } } private void setLinkNodeTarget(String nodeVosPath, String target) { jdbcTemplate.update(conn -> { String sql = "UPDATE node\n" + "SET target = ?\n" + "WHERE node_id = id_from_vos_path(?)\n"; PreparedStatement ps = conn.prepareStatement(sql); int i = 0; ps.setString(++i, target); ps.setString(++i, nodeVosPath); return ps; }); } private Node getNodeFromResultSet(ResultSet rs) throws SQLException { private Node getNodeFromResultSet(ResultSet rs) throws SQLException { Node node = NodeUtils.getTypedNode(rs.getString("type")); Node node = NodeUtils.getTypedNode(rs.getString("type")); Loading
src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java +63 −37 Original line number Original line Diff line number Diff line Loading @@ -311,7 +311,6 @@ public class NodeDAOTest { } } @Test @Test public void testCopyNodeBranch() { public void testCopyNodeBranch() { // Let's copy /test3/m1 to /test3/group1 // Let's copy /test3/m1 to /test3/group1 Loading Loading @@ -445,6 +444,33 @@ public class NodeDAOTest { assertEquals("true", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); assertEquals("true", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); } } @Test public void testSetLinkNodeTarget() { Property publicReadProperty = getProperty(NodeProperties.PUBLIC_READ_URI, String.valueOf(false)); LinkNode node = new LinkNode(); node.setUri("vos://example.com!vospace/mylink1"); node.getProperties().add(publicReadProperty); node.setTarget("vos://example.com!vospace/mydummytarget1"); dao.createNode(node); node = (LinkNode) dao.listNode("/mylink1").get(); assertEquals("false", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); assertEquals("vos://example.com!vospace/mydummytarget1", node.getTarget()); node.getProperties().clear(); publicReadProperty.setValue(String.valueOf(true)); node.getProperties().add(publicReadProperty); node.setTarget("vos://example.com!vospace/mydummytarget1_modded"); dao.setNode(node); node = (LinkNode) dao.listNode("/mylink1").get(); assertEquals("true", NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI)); assertEquals("vos://example.com!vospace/mydummytarget1_modded", node.getTarget()); } @Test @Test public void testSetNodeRecursiveGroup() { public void testSetNodeRecursiveGroup() { Loading
src/main/java/it/inaf/oats/vospace/SetNodeController.java +1 −1 File changed.Contains only whitespace changes. Show changes