Commit e73e7332 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Commented out or deleted code referencing relative_parent_path and os_name

parent 2147e5fe
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -232,8 +232,10 @@ public class UriService {
            }
        } else {

            /*
            Location location = locationDAO.getNodeLocation(relativePath).orElse(null);

            
            if (location != null && location.getType() == LocationType.PORTAL) {
                String fileName = nodeDao.getNodeOsName(relativePath);
                endpoint = "http://" + location.getSource().getHostname() + location.getSource().getBaseUrl();
@@ -241,9 +243,9 @@ public class UriService {
                    endpoint += "/";
                }
                endpoint += fileName;
            } else {
            } else {*/
                endpoint = fileServiceUrl + urlEncodePath(relativePath);
            }
            //}

            endpoint += "?jobId=" + job.getJobId();

@@ -294,9 +296,9 @@ public class UriService {

        String vosPath = URIUtils.returnVosPathFromNodeURI(nodeUri, authority);

        String fileName = url.getPath().substring(url.getPath().lastIndexOf("/") + 1);
        // String fileName = url.getPath().substring(url.getPath().lastIndexOf("/") + 1);

        nodeDao.setNodeLocation(vosPath, location.getId(), fileName);
        nodeDao.setNodeLocation(vosPath, location.getId());
    }

    public Transfer getTransfer(JobSummary job) {
+22 −31
Original line number Diff line number Diff line
@@ -71,8 +71,8 @@ public class NodeDAO {
        StringBuilder sb = new StringBuilder();
        sb.append("INSERT INTO node");
        sb.append(" (name, job_id, creator_id, group_read, group_write,");
        sb.append(" is_public, parent_path, parent_relative_path, type, accept_views, provide_views, target)");
        sb.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        sb.append(" is_public, parent_path, type, accept_views, provide_views, target)");
        sb.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

        jdbcTemplate.update(conn -> {
            PreparedStatement ps = conn.prepareStatement(sb.toString());
@@ -88,7 +88,6 @@ public class NodeDAO {
            ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(myNode, NodeProperties.GROUP_WRITE_URI)));
            ps.setBoolean(++i, Boolean.valueOf(NodeProperties.getNodePropertyByURI(myNode, NodeProperties.PUBLIC_READ_URI)));
            ps.setObject(++i, paths.get(0).getPath(), Types.OTHER);            
            ps.setObject(++i, paths.get(0).getRelativePath(), Types.OTHER);
            ps.setObject(++i, NodeUtils.getDbNodeType(myNode), Types.OTHER);
            ps.setObject(++i, fromViewsToArray(ps, myNode, d -> d.getAccepts()), Types.OTHER);
            ps.setObject(++i, fromViewsToArray(ps, myNode, d -> d.getProvides()), Types.OTHER);
@@ -298,7 +297,7 @@ public class NodeDAO {
    }

    public void renameNode(Long nodeId, String name) {
        String sql = "UPDATE node SET name = ?, os_name = COALESCE(os_name, name) "
        String sql = "UPDATE node SET name = ? "
                + "WHERE node_id = ?";

        jdbcTemplate.update(conn -> {
@@ -313,8 +312,7 @@ public class NodeDAO {
    public void moveNodeBranch(Long sourceRootId, String destParentLtreePath) {

        String sql = "UPDATE node c SET "
                + "parent_path = (? || SUBPATH(c.path, (SELECT nlevel(parent_path) FROM node WHERE node_id = ?), -1))::ltree, "
                + "parent_relative_path = COALESCE(c.parent_relative_path, c.parent_path) " // not sure about this
                + "parent_path = (? || SUBPATH(c.path, (SELECT nlevel(parent_path) FROM node WHERE node_id = ?), -1))::ltree "                
                + "FROM node n "
                + "WHERE n.path @> c.path AND n.node_id = ?";

@@ -332,7 +330,7 @@ public class NodeDAO {
        String destVosParentPath = NodeUtils.getParentPath(destVosPath);
        String destName = NodeUtils.getNodeName(destVosPath);

        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, 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";

        // If destination has path '' no prefix, else "destination_path."
@@ -342,25 +340,24 @@ public class NodeDAO {
        // 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"
                + "((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, parent_path, ? AS name,\n"
                + "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"
                + "FROM node WHERE node_id = id_from_vos_path(?)\n"
                + "UNION ALL\n"
                + "SELECT nextval('node_node_id_seq') AS new_node_id,\n"
                + "(p.new_path::varchar || '.' || currval('node_node_id_seq'))::ltree,\n"
                + "n.path, n.relative_path, n.parent_path, n.parent_relative_path, n.name,\n"
                + "n.path, n.parent_path, n.name,\n"
                + "n.type, n.location_id, n.creator_id, n.group_write, n.group_read, n.is_public,\n"
                + "n.job_id, n.tstamp_wrapper_dir, n.format, n.async_trans, n.sticky, n.accept_views, n.provide_views, n.protocols, n.target\n"
                + "FROM node n\n"
                + "JOIN copied_nodes p ON p.path = n.parent_path";

        String cteCopiedNodesPaths = "SELECT subpath(new_path, 0, nlevel(new_path) - 1) AS new_parent_path,\n"
                + "nlevel(parent_path) - nlevel(parent_relative_path) AS rel_offset, * FROM copied_nodes";
                + " * FROM copied_nodes";

        String parentSelect = "SELECT\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"
                + "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"
                + "FROM copied_nodes_paths\n";
@@ -490,8 +487,8 @@ public class NodeDAO {
        }

        String insertSql = "INSERT INTO deleted_node "
                + "(node_id, parent_path, parent_relative_path, fs_path, "
                + "name, os_name, tstamp_wrapper_dir, type, location_id, format, "
                + "(node_id, parent_path, fs_path, "
                + "name, tstamp_wrapper_dir, type, location_id, format, "
                + "async_trans, job_id, creator_id, group_read, "
                + "group_write, is_public, quota, content_type, content_encoding, "
                + "content_length, content_md5, created_on, last_modified, "
@@ -502,8 +499,8 @@ public class NodeDAO {
                + "USING node p\n"
                + "WHERE n.path <@ p.path AND p.node_id = id_from_vos_path(?)\n"
                + "RETURNING\n"
                + "n.node_id, n.parent_path, n.parent_relative_path, n.fs_path, "
                + "n.name, n.os_name, n.tstamp_wrapper_dir, n.type, n.location_id, n.format, "
                + "n.node_id, n.parent_path, n.fs_path, "
                + "n.name, n.tstamp_wrapper_dir, n.type, n.location_id, n.format, "
                + "n.async_trans, n.job_id, n.creator_id, n.group_read, "
                + "n.group_write, n.is_public, n.quota, n.content_type, n.content_encoding, "
                + "n.content_length, n.content_md5, n.created_on, n.last_modified, "
@@ -526,6 +523,7 @@ public class NodeDAO {
        return jdbcTemplate.queryForObject(sql, args, types, Integer.class);
    }

    /*
    public String getNodeOsName(String vosPath) {
        String sql = "SELECT \n"
                + "COALESCE(os_name, name) AS os_name\n"
@@ -536,16 +534,15 @@ public class NodeDAO {
        int[] types = {Types.VARCHAR};

        return jdbcTemplate.queryForObject(sql, args, types, String.class);
    }
    }*/

    public void setNodeLocation(String vosPath, int locationId, String nodeOsName) {
    public void setNodeLocation(String vosPath, int locationId) {

        String sql = "UPDATE node SET location_id = ?, os_name = ? WHERE node_id = id_from_vos_path(?)";
        String sql = "UPDATE node SET location_id = ? WHERE node_id = id_from_vos_path(?)";

        int updated = jdbcTemplate.update(sql, ps -> {
            ps.setInt(1, locationId);            
            ps.setString(2, nodeOsName);
            ps.setString(3, vosPath);
            ps.setString(2, vosPath);
        });

        if (updated != 1) {
@@ -606,7 +603,7 @@ public class NodeDAO {
    }

    private NodePaths getPathsFromResultSet(ResultSet rs) throws SQLException {
        NodePaths paths = new NodePaths(rs.getString("path"), rs.getString("relative_path"));
        NodePaths paths = new NodePaths(rs.getString("path"));
        return paths;
    }

@@ -734,7 +731,7 @@ public class NodeDAO {

        String parentPath = NodeUtils.getParentPath(path);

        String sql = "SELECT path, relative_path "
        String sql = "SELECT path "
                + "FROM node n "
                + "WHERE node_id = id_from_vos_path(?)";

@@ -797,20 +794,14 @@ public class NodeDAO {
    private class NodePaths {

        private final String path;
        private final String relativePath;

        public NodePaths(String myPath, String myRelativePath) {
        public NodePaths(String myPath) {

            this.path = myPath;
            this.relativePath = myRelativePath;
        }

        public String getPath() {
            return this.path;
        }

        public String getRelativePath() {
            return this.relativePath;
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ public class TransferControllerTest {
        verify(jobDao, times(2)).updateJob(argThat(j -> ExecutionPhase.QUEUED == j.getPhase()), any());
    }

    /*
    @Test
    public void testPullToVoSpacePortal() throws Exception {

@@ -157,7 +158,7 @@ public class TransferControllerTest {
        assertTrue(endpoint.startsWith("http://archive.lbto.org"));

        verify(nodeDao, times(1)).setNodeLocation(eq("/portalnode"), eq(2), eq("lbcr.20130512.060722.fits.gz"));
    }
    }*/

    @Test
    public void testPushToVoSpace() throws Exception {
+1 −1
Original line number Diff line number Diff line
@@ -413,7 +413,7 @@ public class UriServiceTest {

        uriService.setNodeRemoteLocation(nodeUri, contentUri);

        verify(nodeDAO).setNodeLocation(eq("/test/f1/lbtfile.fits"), eq(5), eq("lbtfile.fits"));
        verify(nodeDAO).setNodeLocation(eq("/test/f1/lbtfile.fits"), eq(5));
    }

    @Test
+2 −18
Original line number Diff line number Diff line
@@ -377,23 +377,13 @@ public class NodeDAOTest {
        Optional<Long> rootId = dao.getNodeId(oldPath);
        assertTrue(rootId.isPresent());

        assertEquals("f1", dao.getNodeOsName(oldPath));

        dao.renameNode(rootId.get(), "f_pippo");

        assertTrue(dao.listNode(oldPath).isEmpty());
        assertTrue(dao.listNode(oldPathChild).isEmpty());

        // After the first rename the os_name column has to be equal to the old name
        // to avoid issues with renaming folders where some files have been uploaded
        assertEquals("f1", dao.getNodeOsName(newPath));

        assertTrue(dao.listNode(newPath).isPresent());
        assertTrue(dao.listNode(newPathChild).isPresent());

        // The second rename mustn't change the os_name column
        dao.renameNode(rootId.get(), "f_pippo_second_rename");
        assertEquals("f1", dao.getNodeOsName("/test1/f_pippo_second_rename"));
    }

    @Test
@@ -432,14 +422,14 @@ public class NodeDAOTest {
        dataNode.setUri("vos://example.com!vospace/mydata2");
        dao.createNode(dataNode);

        dao.setNodeLocation("/mydata2", 1, "mydata2");
        dao.setNodeLocation("/mydata2", 1);
    }

    @Test
    public void testSetNodeLocationFailure() {
        boolean exception = false;
        try {
            dao.setNodeLocation("/foo", 1, "foo");
            dao.setNodeLocation("/foo", 1);
        } catch (InternalFaultException ex) {
            exception = true;
        }
@@ -540,12 +530,6 @@ public class NodeDAOTest {
        checkGroups(NodeProperties.getNodePropertyAsListByURI(child2, NodeProperties.GROUP_WRITE_URI), "group6");
    }

    @Test
    public void testGetNodeOsName() {
        assertEquals("f2", dao.getNodeOsName("/test1/f1/f2_renamed"));
        assertEquals("f4", dao.getNodeOsName("/test2/f4"));
    }

    @Test
    public void testReleaseNodesByJobId() {
        Optional<Long> optId = dao.getNodeId("/test3/m1");