Loading src/main/java/it/inaf/ia2/transfer/controller/GetFileController.java +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public class GetFileController extends FileController { throw PermissionDeniedException.forPath(path); } File file = new File(fileInfo.getOsPath()); File file = new File(fileInfo.getFsPath()); FileResponseUtil.getFileResponse(response, file, path); } else { throw new NodeNotFoundException(path); Loading src/main/java/it/inaf/ia2/transfer/persistence/FileDAO.java +53 −13 Original line number Diff line number Diff line Loading @@ -47,7 +47,8 @@ public class FileDAO { + "accept_views, provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n" + "(SELECT user_name FROM users WHERE user_id = creator_id) AS username, n.job_id,\n" + "base_path, get_os_path(n.node_id) AS os_path, ? AS vos_path, false AS is_directory,\n" + "type = 'link' AS is_link\n" + "type = 'link' AS is_link,\n" + "fs_path \n" + "FROM node n\n" + "JOIN location l ON (n.location_id IS NOT NULL AND n.location_id = l.location_id) OR (n.location_id IS NULL AND l.location_id = ?)\n" + "LEFT JOIN storage s ON s.storage_id = l.storage_dest_id\n" Loading Loading @@ -111,22 +112,25 @@ public class FileDAO { } public void updateFileAttributes(int nodeId, String fsPath, String contentType, String contentEncoding, Long contentLength, String contentMd5) { String sql = "UPDATE node SET content_type = ?, content_encoding = ?, content_length = ?, content_md5 = ?, location_id = ? " String sql = "UPDATE node SET fs_path = ?, content_type = ?, content_encoding = ?, content_length = ?, content_md5 = ?, location_id = ? " + "WHERE node_id = ?"; jdbcTemplate.update(conn -> { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, contentType); ps.setString(2, contentEncoding); ps.setLong(3, contentLength); ps.setString(4, contentMd5); ps.setInt(5, uploadLocationId); ps.setInt(6, nodeId); int i = 0; ps.setString(++i, fsPath); ps.setString(++i, contentType); ps.setString(++i, contentEncoding); ps.setLong(++i, contentLength); ps.setString(++i, contentMd5); ps.setInt(++i, uploadLocationId); ps.setInt(++i, nodeId); return ps; }); Loading Loading @@ -170,7 +174,7 @@ public class FileDAO { throw new IllegalArgumentException("Received empty list of paths"); } String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans,\n" String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans, n.fs_path,\n" + "n.content_type, n.content_encoding, n.content_length, n.content_md5,\n" + "n.accept_views, n.provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n" + "(SELECT user_name FROM users WHERE user_id = n.creator_id) AS username,\n" Loading Loading @@ -203,7 +207,7 @@ public class FileDAO { // TODO: same problem as get archive file infos public List<FileInfo> getBranchFileInfos(String rootVosPath, String jobId) { String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans,\n" String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans, n.fs_path\n" + "n.content_type, n.content_encoding, n.content_length, n.content_md5,\n" + "n.accept_views, n.provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n" + "(SELECT user_name FROM users WHERE user_id = n.creator_id) AS username,\n" Loading Loading @@ -297,11 +301,47 @@ public class FileDAO { fi.setLocationType(rs.getString("location_type")); } fillOsPath(fi, rs); this.fillActualBasePath(fi, rs); this.fillFsPath(fi, rs); return fi; } private void fillActualBasePath(FileInfo fi, ResultSet rs) throws SQLException { String basePath = rs.getString("base_path"); if (basePath == null) { return; } Path completeBasePath = Path.of(basePath); boolean asyncLocation = "async".equals(rs.getString("location_type")); if (asyncLocation) { String username = rs.getString("username"); completeBasePath = completeBasePath.resolve(username).resolve("retrieve"); } fi.setActualBasePath(completeBasePath.toString()); } private void fillFsPath(FileInfo fi, ResultSet rs) throws SQLException { String fsPath = rs.getString("fs_path"); if (fsPath == null) { return; } if (fsPath.startsWith("/")) { fsPath = fsPath.substring(1); } Path completeFsPath = Path.of(fsPath); fi.setFsPath(completeFsPath.toString()); } private void fillOsPath(FileInfo fi, ResultSet rs) throws SQLException { String basePath = rs.getString("base_path"); Loading src/main/java/it/inaf/ia2/transfer/persistence/model/FileInfo.java +30 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ */ package it.inaf.ia2.transfer.persistence.model; import java.nio.file.Path; import java.util.List; public class FileInfo { Loading @@ -13,6 +14,10 @@ public class FileInfo { private String osPath; private String virtualPath; private String virtualName; private String fsPath; // actualBasePath differs from base path in db due to some location type // dependent manipulations (performed by FileDAO) private String actualBasePath; private boolean isPublic; private boolean virtualParent; private boolean directory; Loading Loading @@ -199,6 +204,31 @@ public class FileInfo { this.jobId = jobId; } public String getFsPath() { return fsPath; } public void setFsPath(String fsPath) { this.fsPath = fsPath; } public String getActualBasePath() { return actualBasePath; } public void setActualBasePath(String actualBasePath) { this.actualBasePath = actualBasePath; } // This function returns the full path of this file on storage public String getFilePath() { if (this.actualBasePath == null || this.fsPath == null) { return null; } else { return Path.of(this.actualBasePath).resolve(this.fsPath).toString(); } } public static String getVosParentPath(FileInfo fileInfo) { return fileInfo.getVirtualPath().substring(0, fileInfo.getVirtualPath().lastIndexOf("/")); } Loading src/main/java/it/inaf/ia2/transfer/service/ArchiveService.java +1 −1 Original line number Diff line number Diff line Loading @@ -308,7 +308,7 @@ public class ArchiveService { throw PermissionDeniedException.forPath(fileInfo.getVirtualPath()); } File file = new File(fileInfo.getOsPath()); File file = new File(fileInfo.getFsPath()); LOG.trace("Adding file " + file.getAbsolutePath() + " to tar archive"); try ( InputStream is = new FileInputStream(file)) { Loading src/main/java/it/inaf/ia2/transfer/service/FileCopyService.java +2 −2 Original line number Diff line number Diff line Loading @@ -206,8 +206,8 @@ public class FileCopyService { throw PermissionDeniedException.forPath(sourceFileInfo.getVirtualPath()); } File file = new File(sourceFileInfo.getOsPath()); LOG.trace("Copying file: {} to {}",file.getAbsolutePath(), destinationFileInfo.getOsPath()); File file = new File(sourceFileInfo.getFsPath()); LOG.trace("Copying file: {} to {}",file.getAbsolutePath(), destinationFileInfo.getFsPath()); putFileService.copyLocalFile(sourceFileInfo, destinationFileInfo, remainingQuota); Loading Loading
src/main/java/it/inaf/ia2/transfer/controller/GetFileController.java +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public class GetFileController extends FileController { throw PermissionDeniedException.forPath(path); } File file = new File(fileInfo.getOsPath()); File file = new File(fileInfo.getFsPath()); FileResponseUtil.getFileResponse(response, file, path); } else { throw new NodeNotFoundException(path); Loading
src/main/java/it/inaf/ia2/transfer/persistence/FileDAO.java +53 −13 Original line number Diff line number Diff line Loading @@ -47,7 +47,8 @@ public class FileDAO { + "accept_views, provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n" + "(SELECT user_name FROM users WHERE user_id = creator_id) AS username, n.job_id,\n" + "base_path, get_os_path(n.node_id) AS os_path, ? AS vos_path, false AS is_directory,\n" + "type = 'link' AS is_link\n" + "type = 'link' AS is_link,\n" + "fs_path \n" + "FROM node n\n" + "JOIN location l ON (n.location_id IS NOT NULL AND n.location_id = l.location_id) OR (n.location_id IS NULL AND l.location_id = ?)\n" + "LEFT JOIN storage s ON s.storage_id = l.storage_dest_id\n" Loading Loading @@ -111,22 +112,25 @@ public class FileDAO { } public void updateFileAttributes(int nodeId, String fsPath, String contentType, String contentEncoding, Long contentLength, String contentMd5) { String sql = "UPDATE node SET content_type = ?, content_encoding = ?, content_length = ?, content_md5 = ?, location_id = ? " String sql = "UPDATE node SET fs_path = ?, content_type = ?, content_encoding = ?, content_length = ?, content_md5 = ?, location_id = ? " + "WHERE node_id = ?"; jdbcTemplate.update(conn -> { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, contentType); ps.setString(2, contentEncoding); ps.setLong(3, contentLength); ps.setString(4, contentMd5); ps.setInt(5, uploadLocationId); ps.setInt(6, nodeId); int i = 0; ps.setString(++i, fsPath); ps.setString(++i, contentType); ps.setString(++i, contentEncoding); ps.setLong(++i, contentLength); ps.setString(++i, contentMd5); ps.setInt(++i, uploadLocationId); ps.setInt(++i, nodeId); return ps; }); Loading Loading @@ -170,7 +174,7 @@ public class FileDAO { throw new IllegalArgumentException("Received empty list of paths"); } String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans,\n" String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans, n.fs_path,\n" + "n.content_type, n.content_encoding, n.content_length, n.content_md5,\n" + "n.accept_views, n.provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n" + "(SELECT user_name FROM users WHERE user_id = n.creator_id) AS username,\n" Loading Loading @@ -203,7 +207,7 @@ public class FileDAO { // TODO: same problem as get archive file infos public List<FileInfo> getBranchFileInfos(String rootVosPath, String jobId) { String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans,\n" String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans, n.fs_path\n" + "n.content_type, n.content_encoding, n.content_length, n.content_md5,\n" + "n.accept_views, n.provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n" + "(SELECT user_name FROM users WHERE user_id = n.creator_id) AS username,\n" Loading Loading @@ -297,11 +301,47 @@ public class FileDAO { fi.setLocationType(rs.getString("location_type")); } fillOsPath(fi, rs); this.fillActualBasePath(fi, rs); this.fillFsPath(fi, rs); return fi; } private void fillActualBasePath(FileInfo fi, ResultSet rs) throws SQLException { String basePath = rs.getString("base_path"); if (basePath == null) { return; } Path completeBasePath = Path.of(basePath); boolean asyncLocation = "async".equals(rs.getString("location_type")); if (asyncLocation) { String username = rs.getString("username"); completeBasePath = completeBasePath.resolve(username).resolve("retrieve"); } fi.setActualBasePath(completeBasePath.toString()); } private void fillFsPath(FileInfo fi, ResultSet rs) throws SQLException { String fsPath = rs.getString("fs_path"); if (fsPath == null) { return; } if (fsPath.startsWith("/")) { fsPath = fsPath.substring(1); } Path completeFsPath = Path.of(fsPath); fi.setFsPath(completeFsPath.toString()); } private void fillOsPath(FileInfo fi, ResultSet rs) throws SQLException { String basePath = rs.getString("base_path"); Loading
src/main/java/it/inaf/ia2/transfer/persistence/model/FileInfo.java +30 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ */ package it.inaf.ia2.transfer.persistence.model; import java.nio.file.Path; import java.util.List; public class FileInfo { Loading @@ -13,6 +14,10 @@ public class FileInfo { private String osPath; private String virtualPath; private String virtualName; private String fsPath; // actualBasePath differs from base path in db due to some location type // dependent manipulations (performed by FileDAO) private String actualBasePath; private boolean isPublic; private boolean virtualParent; private boolean directory; Loading Loading @@ -199,6 +204,31 @@ public class FileInfo { this.jobId = jobId; } public String getFsPath() { return fsPath; } public void setFsPath(String fsPath) { this.fsPath = fsPath; } public String getActualBasePath() { return actualBasePath; } public void setActualBasePath(String actualBasePath) { this.actualBasePath = actualBasePath; } // This function returns the full path of this file on storage public String getFilePath() { if (this.actualBasePath == null || this.fsPath == null) { return null; } else { return Path.of(this.actualBasePath).resolve(this.fsPath).toString(); } } public static String getVosParentPath(FileInfo fileInfo) { return fileInfo.getVirtualPath().substring(0, fileInfo.getVirtualPath().lastIndexOf("/")); } Loading
src/main/java/it/inaf/ia2/transfer/service/ArchiveService.java +1 −1 Original line number Diff line number Diff line Loading @@ -308,7 +308,7 @@ public class ArchiveService { throw PermissionDeniedException.forPath(fileInfo.getVirtualPath()); } File file = new File(fileInfo.getOsPath()); File file = new File(fileInfo.getFsPath()); LOG.trace("Adding file " + file.getAbsolutePath() + " to tar archive"); try ( InputStream is = new FileInputStream(file)) { Loading
src/main/java/it/inaf/ia2/transfer/service/FileCopyService.java +2 −2 Original line number Diff line number Diff line Loading @@ -206,8 +206,8 @@ public class FileCopyService { throw PermissionDeniedException.forPath(sourceFileInfo.getVirtualPath()); } File file = new File(sourceFileInfo.getOsPath()); LOG.trace("Copying file: {} to {}",file.getAbsolutePath(), destinationFileInfo.getOsPath()); File file = new File(sourceFileInfo.getFsPath()); LOG.trace("Copying file: {} to {}",file.getAbsolutePath(), destinationFileInfo.getFsPath()); putFileService.copyLocalFile(sourceFileInfo, destinationFileInfo, remainingQuota); Loading