Commit 64c2fee1 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Implemented retrieval of portal files during tar/zip archive generation and...

Implemented retrieval of portal files during tar/zip archive generation and other ArchiveService improvements
parent 0608bd6a
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class FileServiceApplication {
@@ -38,4 +39,9 @@ public class FileServiceApplication {
        registration.addUrlPatterns("/*");
        return registration;
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
+1 −3
Original line number Diff line number Diff line
@@ -61,9 +61,7 @@ public class GetFileController extends FileController {
    private ResponseEntity<?> getFileResponse(FileInfo fileInfo) {

        File file = new File(fileInfo.getOsPath());
        String vosName = fileInfo.getVirtualPath() == null ? null
                : fileInfo.getVirtualPath().substring(fileInfo.getVirtualPath().lastIndexOf("/") + 1);

        return FileResponseUtil.getFileResponse(response, file, vosName);
        return FileResponseUtil.getFileResponse(response, file, fileInfo.getVirtualName());
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public class FileDAO {
    public Optional<FileInfo> getFileInfo(String virtualPath) {

        String sql = "SELECT n.node_id, is_public, group_read, group_write, creator_id, async_trans,\n"
                + "content_type, content_encoding, content_length, content_md5,\n"
                + "content_type, content_encoding, content_length, content_md5, name, n.location_id,\n"
                + "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"
                + "base_path, get_os_path(n.node_id) AS os_path, ? AS vos_path, false AS is_directory\n"
@@ -133,7 +133,7 @@ public class FileDAO {
                + "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"
                + "base_path, get_os_path(n.node_id) AS os_path, get_vos_path(n.node_id) AS vos_path,\n"
                + "n.type = 'container' AS is_directory\n"
                + "n.type = 'container' AS is_directory, n.name, n.location_id\n"
                + "FROM node n\n"
                + "JOIN node p ON p.path @> n.path\n"
                + "LEFT JOIN location l ON l.location_id = n.location_id\n"
@@ -169,11 +169,16 @@ public class FileDAO {
        fi.setProvideViews(toList(rs.getArray("provide_views")));
        fi.setVirtualParent(rs.getBoolean("virtual_parent"));
        fi.setVirtualPath(rs.getString("vos_path"));
        fi.setVirtualName(rs.getString("name"));
        fi.setContentEncoding(rs.getString("content_encoding"));
        fi.setContentLength(rs.getLong("content_length"));
        fi.setContentMd5(rs.getString("content_md5"));
        fi.setContentType(rs.getString("content_type"));
        fi.setDirectory(rs.getBoolean("is_directory"));
        int locationId = rs.getInt("location_id");
        if (!rs.wasNull()) {
            fi.setLocationId(locationId);
        }

        fillOsPath(fi, rs);

+21 −5
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 */
package it.inaf.ia2.transfer.persistence;

import it.inaf.ia2.transfer.persistence.model.JobException;
import java.sql.Types;
import javax.sql.DataSource;
import net.ivoa.xml.uws.v1.ExecutionPhase;
@@ -53,8 +54,7 @@ public class JobDAO {
                ps -> {
                    ps.setString(1, jobId);
                }, rs -> {
                    if(rs.next())
                    {
                    if (rs.next()) {
                        return ExecutionPhase.fromValue(rs.getString("phase"));
                    } else {
                        return null;
@@ -64,4 +64,20 @@ public class JobDAO {
        return result;
    }

    public void setJobError(String jobId, JobException jobError) {

        String sql = "UPDATE job SET phase = ?, error_message = ?, error_type = ?,\n"
                + "error_has_detail = ?, error_detail = ?, end_time = NOW()\n"
                + "WHERE job_id = ?";

        jdbcTemplate.update(sql, ps -> {
            int i = 0;
            ps.setObject(++i, ExecutionPhase.ERROR, Types.OTHER);
            ps.setString(++i, jobError.getErrorMessage());
            ps.setObject(++i, jobError.getType().value(), Types.OTHER);
            ps.setBoolean(++i, jobError.getErrorDetail() != null);
            ps.setString(++i, jobError.getErrorDetail());
            ps.setString(++i, jobId);
        });
    }
}
+44 −0
Original line number Diff line number Diff line
/*
 * This file is part of vospace-file-service
 * Copyright (C) 2021 Istituto Nazionale di Astrofisica
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
package it.inaf.ia2.transfer.persistence;

import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class LocationDAO {

    private final JdbcTemplate jdbcTemplate;

    @Autowired
    public LocationDAO(DataSource fileCatalogDatasource) {
        this.jdbcTemplate = new JdbcTemplate(fileCatalogDatasource);
    }

    public Map<Integer, String> getPortalLocationUrls() {

        String sql = "SELECT location_id, hostname, base_url\n"
                + "FROM location l\n"
                + "JOIN storage s ON s.storage_id = l.storage_dest_id\n"
                + "WHERE location_type = 'portal'";

        return jdbcTemplate.query(sql, rs -> {
            Map<Integer, String> locationUrls = new HashMap<>();
            while (rs.next()) {
                int locationId = rs.getInt("location_id");
                String hostname = rs.getString("hostname");
                String baseUrl = rs.getString("base_url");
                String url = "http://" + hostname + baseUrl;
                locationUrls.put(locationId, url);
            }
            return locationUrls;
        });
    }
}
Loading