Commit 3e9d1e34 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

copyBranch bugfix for source nodes with parent_relative_path = ''

parent 35b451bf
Loading
Loading
Loading
Loading
+6 −21
Original line number Original line Diff line number Diff line
@@ -204,22 +204,6 @@ 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"));
@@ -370,9 +354,11 @@ public class NodeDAO {
        String parentInsert = "INSERT INTO node (node_id, parent_path, parent_relative_path, name, type, location_id, creator_id, group_write, group_read, is_public,\n"
        String parentInsert = "INSERT INTO node (node_id, parent_path, parent_relative_path, name, type, location_id, creator_id, group_write, group_read, is_public,\n"
                + "job_id, tstamp_wrapper_dir, format, async_trans, sticky, accept_views, provide_views, protocols, target)\n";
                + "job_id, tstamp_wrapper_dir, format, async_trans, sticky, accept_views, provide_views, protocols, target)\n";


        // If destination has path '' no prefix, else "destination_path."
        String ctePathPrefix = "SELECT CASE WHEN path::varchar = '' THEN '' ELSE (path::varchar || '.') END AS prefix\n"
        String ctePathPrefix = "SELECT CASE WHEN path::varchar = '' THEN '' ELSE (path::varchar || '.') END AS prefix\n"
                + "FROM node WHERE node_id = id_from_vos_path(?)";
                + "FROM node WHERE node_id = id_from_vos_path(?)";


        // Calculates also new path, even if it's usually generated by database functions
        String cteCopiedNodes = "SELECT nextval('node_node_id_seq') AS new_node_id,\n"
        String cteCopiedNodes = "SELECT nextval('node_node_id_seq') AS new_node_id,\n"
                + "((SELECT prefix FROM path_prefix) || currval('node_node_id_seq'))::ltree AS new_path,\n"
                + "((SELECT prefix FROM path_prefix) || currval('node_node_id_seq'))::ltree AS new_path,\n"
                + "path, relative_path, parent_path, parent_relative_path, ? AS name,\n"
                + "path, relative_path, parent_path, parent_relative_path, ? AS name,\n"
@@ -393,7 +379,7 @@ public class NodeDAO {


        String parentSelect = "SELECT\n"
        String parentSelect = "SELECT\n"
                + "new_node_id, new_parent_path,\n"
                + "new_node_id, new_parent_path,\n"
                + "CASE WHEN nlevel(new_parent_path) = rel_offset THEN ''::ltree ELSE subpath(new_parent_path, rel_offset) END new_parent_relative_path,\n"
                + "CASE WHEN nlevel(new_parent_path) <= rel_offset THEN ''::ltree ELSE subpath(new_parent_path, rel_offset) END new_parent_relative_path,\n"
                + "name, type, location_id, creator_id, group_write, group_read, is_public,\n"
                + "name, type, location_id, creator_id, group_write, group_read, is_public,\n"
                + "job_id, tstamp_wrapper_dir, format, async_trans, sticky, accept_views, provide_views, protocols, target\n"
                + "job_id, tstamp_wrapper_dir, format, async_trans, sticky, accept_views, provide_views, protocols, target\n"
                + "FROM copied_nodes_paths\n";
                + "FROM copied_nodes_paths\n";
@@ -414,7 +400,6 @@ public class NodeDAO {
            ps.setString(3, sourceVosPath);
            ps.setString(3, sourceVosPath);
            return ps;
            return ps;
        }); 
        }); 

    }
    }


    public boolean isBranchBusy(long parentNodeId) {
    public boolean isBranchBusy(long parentNodeId) {
+37 −2
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ public class NodeDAOTest {
        ReflectionTestUtils.setField(dao, "authority", AUTHORITY);
        ReflectionTestUtils.setField(dao, "authority", AUTHORITY);
    }
    }


    
    @Test
    @Test
    public void testCreateNode() {
    public void testCreateNode() {
        DataNode dataNode = new DataNode();
        DataNode dataNode = new DataNode();
@@ -87,12 +88,12 @@ 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(5, root.getNodes().size());


        assertEquals("true", NodeProperties.getNodePropertyByURI(root, NodeProperties.PUBLIC_READ_URI));
        assertEquals("true", NodeProperties.getNodePropertyByURI(root, NodeProperties.PUBLIC_READ_URI));
        assertEquals("0", NodeProperties.getNodePropertyByURI(root, NodeProperties.LENGTH_URI));
        assertEquals("0", NodeProperties.getNodePropertyByURI(root, NodeProperties.LENGTH_URI));


        assertEquals("group1 group2", NodeProperties.getNodePropertyByURI(root.getNodes().get(0), NodeProperties.GROUP_READ_URI));
        assertEquals("group1", NodeProperties.getNodePropertyByURI(root.getNodes().get(0), NodeProperties.GROUP_READ_URI));


        String bTime = NodeProperties.getNodePropertyByURI(root.getNodes().get(0), NodeProperties.INITIAL_CREATION_TIME_URI);
        String bTime = NodeProperties.getNodePropertyByURI(root.getNodes().get(0), NodeProperties.INITIAL_CREATION_TIME_URI);
        assertTrue(bTime.contains("T"));
        assertTrue(bTime.contains("T"));
@@ -284,6 +285,7 @@ public class NodeDAOTest {


    }
    }


    
    @Test
    @Test
    public void testMoveNodeBranch() {
    public void testMoveNodeBranch() {
        // Let's move /test3/m1 to /test3/group1
        // Let's move /test3/m1 to /test3/group1
@@ -320,6 +322,9 @@ public class NodeDAOTest {
        Optional<Long> optSourceChildId = dao.getNodeId("/test3/m1/m2");
        Optional<Long> optSourceChildId = dao.getNodeId("/test3/m1/m2");
        assertTrue(optSourceChildId.isPresent());
        assertTrue(optSourceChildId.isPresent());
        
        
        Optional<Long> optSourceChildLinkId = dao.getNodeId("/test3/m1/link1");
        assertTrue(optSourceChildLinkId.isPresent());

        Optional<Long> optDestParentId = dao.getNodeId("/test3/group1");
        Optional<Long> optDestParentId = dao.getNodeId("/test3/group1");
        assertTrue(optDestParentId.isPresent());
        assertTrue(optDestParentId.isPresent());


@@ -337,8 +342,38 @@ public class NodeDAOTest {
        Optional<Long> recheckSourceChild = dao.getNodeId("/test3/m1/m2");
        Optional<Long> recheckSourceChild = dao.getNodeId("/test3/m1/m2");
        assertTrue(recheckSourceChild.isPresent());
        assertTrue(recheckSourceChild.isPresent());
        
        
        Optional<Long> resultIdChildLink = dao.getNodeId("/test3/group1/copy_of_m1/link1");
        assertTrue(resultIdChildLink.isPresent());
        
        Optional<Long> recheckSourceChildLink = dao.getNodeId("/test3/m1/link1");
        assertTrue(recheckSourceChildLink.isPresent());

    }
    
    @Test
    public void testMoveAndCopyIntegrated() {
                
        assertTrue(dao.getNodeId("/mycontainer").isPresent());
        assertTrue(dao.getNodeId("/mycontainer/destination2").isPresent());
        assertTrue(dao.getNodeId("/mycontainer/destination2/control").isPresent());
                
        dao.copyBranch("/mycontainer/destination2/control", "/mycontainer/control");
        
        assertTrue(dao.getNodeId("/mycontainer/container1").isPresent());
        
        Optional<ShortNodeDescriptor> optSnd = 
                dao.getShortNodeDescriptor("/mycontainer/destination2", "user3", List.of("group1"));
        
        dao.moveNodeBranch(dao.getNodeId("/mycontainer/container1").get(), optSnd.get().getDestinationNodeLtreePath());
        
        assertTrue(dao.getNodeId("/mycontainer/destination2/container1").isPresent());
        assertTrue(dao.getNodeId("/mycontainer/container1").isEmpty());        
        dao.copyBranch("/mycontainer/destination2/container1", "/mycontainer/container1");
        
        assertTrue(dao.getNodeId("/mycontainer/container1").isPresent());
    }
    }
    
    

    @Test
    @Test
    public void testRenameNode() {
    public void testRenameNode() {
        String oldPath = "/test1/f1";
        String oldPath = "/test1/f1";
+6 −0
Original line number Original line Diff line number Diff line
@@ -34,6 +34,12 @@ INSERT INTO node (parent_path, parent_relative_path, name, job_id, type, creator
INSERT INTO node (parent_path, parent_relative_path, name, async_trans, type, creator_id, is_public, location_id) VALUES ('9', '', 'masynctrans', true, 'container', 'user3', false, 3);      -- /test3/masynctrans
INSERT INTO node (parent_path, parent_relative_path, name, async_trans, type, creator_id, is_public, location_id) VALUES ('9', '', 'masynctrans', true, 'container', 'user3', false, 3);      -- /test3/masynctrans
INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, is_public, location_id) VALUES ('9', '', 'asyncloc', 'container', 'user3', false, 1);      -- /test3/asyncloc
INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, is_public, location_id) VALUES ('9', '', 'asyncloc', 'container', 'user3', false, 1);      -- /test3/asyncloc
INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('9', '', 'group1', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3);      -- /test3/group1
INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('9', '', 'group1', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3);      -- /test3/group1
INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id, target) VALUES ('9.10', '', 'link1', 'link', 'user3', '{"group1"}', '{"group1"}', false, 3, 'vos://authority/dummy/link');      -- /test3/m1/link1

INSERT INTO node (parent_path, parent_relative_path, name, sticky, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('', NULL, 'mycontainer', true, 'container', 'user3', '{"group1"}', '{"group1"}', false, 3);      -- /mycontainer
INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('19', '', 'container1', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3);      -- /mycontainer/container1
INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('19', '', 'destination2', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3);      -- /mycontainer/destination2
INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, group_write, group_read, is_public, location_id) VALUES ('19.21', '20', 'control', 'container', 'user3', '{"group1"}', '{"group1"}', false, 3);      -- /mycontainer/destination2/control




DELETE FROM job;
DELETE FROM job;