Skip to content
Snippets Groups Projects
Commit bd64b755 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Added LinkNodes management to SetNode

parent b6c3b93a
No related branches found
No related tags found
No related merge requests found
...@@ -171,20 +171,31 @@ public class NodeDAO { ...@@ -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;
}); });
...@@ -193,6 +204,22 @@ public class NodeDAO { ...@@ -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"));
......
...@@ -311,7 +311,6 @@ public class NodeDAOTest { ...@@ -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
...@@ -445,6 +444,33 @@ public class NodeDAOTest { ...@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment