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

more partial implementation of copy node

parent c183754c
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import it.inaf.oats.vospace.exception.NodeNotFoundException;
import it.inaf.oats.vospace.exception.PermissionDeniedException;
import it.inaf.oats.vospace.persistence.NodeDAO;
import it.inaf.oats.vospace.persistence.NodeDAO.ShortNodeDescriptor;
import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import net.ivoa.xml.vospace.v2.Transfer;
@@ -65,6 +66,8 @@ public class CopyService {
        // check source branch for read and lock it
        nodeBranchService.checkBranchForReadAndLock(sourcePath, jobId);
        
        copyNode(sourcePath, destinationPath, jobId);

    }

    private void validatePath(String path) {
@@ -73,4 +76,18 @@ public class CopyService {
        }
    }

    private void copyNode(String vosSourceNode, String vosDestNode, String jobId) {
        String sourceName = NodeUtils.getNodeName(vosSourceNode);
        String destPath = vosDestNode + "/" + sourceName;

        nodeDao.copySingleNode(sourceName, destPath, jobId);
        List<String> children = nodeDao.listNodeChildren(sourceName);
        if (children != null && !children.isEmpty()) {
            for (String n : children) {
                this.copyNode(sourceName + "/" +n, destPath+"/"+n, jobId);
            }
        }

    }

}
+25 −6
Original line number Diff line number Diff line
@@ -136,6 +136,25 @@ public class NodeDAO {
        return Optional.of(node);
    }
    
    public List<String> listNodeChildren(String path) {

        String sql = "SELECT n.name\n"
                + "FROM node n\n"
                + "WHERE n.path ~ ('*.' || id_from_vos_path(?) || '.*{1}')::lquery\n"               
                + "ORDER BY n.path";

        List<String> childrenNames = jdbcTemplate.query(conn -> {
            PreparedStatement ps = conn.prepareStatement(sql);
            int i = 0;
            ps.setString(++i, path);
            return ps;
        }, (row, index) -> {
            return row.getString("name");
        });
        
        return childrenNames;        
    }

    public Node setNode(Node newNode) {
        return setNode(newNode, false);
    }
@@ -320,8 +339,8 @@ public class NodeDAO {
        });
    }

    public void copySingleNode(Long sourceId,
            Long destId, String jobId) {
    public void copySingleNode(String sourceVosPath,
            String destVosPath, String jobId) {

        // Select source node
        String selectSourceSQL = "SELECT\n"
@@ -330,13 +349,13 @@ public class NodeDAO {
                + "c.group_read, c.group_write, c.is_public, c.delta, c.content_type, c.content_encoding,\n"
                + "c.content_length, c.content_md5, c.accept_views, c.provide_views, c.protocols\n"
                + "FROM node c\n"
                + "WHERE c.node_id = ?";
                + "WHERE c.node_id = id_from_vos_path(?)";

        // Select destination node necessary information
        String selectDestinationSQL = "SELECT\n"
                + "d.path, d.parent_path, d.parent_relative_path\n"
                + "FROM node d\n"
                + "WHERE d.node_id = ?";
                + "WHERE d.node_id = id_from_vos_path(?)";

        // Insert branch 
        String insertSQL = "INSERT INTO node\n"
@@ -357,8 +376,8 @@ public class NodeDAO {

        jdbcTemplate.update(conn -> {
            PreparedStatement ps = conn.prepareStatement(cteSQL);
            ps.setLong(1, sourceId);
            ps.setLong(2, destId);
            ps.setString(1, sourceVosPath);
            ps.setString(2, destVosPath);
            ps.setString(3, jobId);
            return ps;
        });