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

Merge origin/master into copyNode

Conflicts:
	src/main/java/it/inaf/oats/vospace/JobService.java
	src/main/java/it/inaf/oats/vospace/MoveService.java
	src/test/java/it/inaf/oats/vospace/persistence/NodeDAOTest.java
Merge commit
parents 52ef5808 12aec7f7
Loading
Loading
Loading
Loading
+13 −129
Original line number Original line Diff line number Diff line
@@ -3,10 +3,9 @@
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <modelVersion>4.0.0</modelVersion>
    <parent>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <groupId>it.inaf.ia2</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <artifactId>vospace-parent</artifactId>
        <version>2.4.5</version>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    </parent>
    <groupId>it.inaf.oats</groupId>
    <groupId>it.inaf.oats</groupId>
    <artifactId>vospace-rest</artifactId>
    <artifactId>vospace-rest</artifactId>
@@ -18,134 +17,19 @@
        <!-- File catalog repository directory -->
        <!-- File catalog repository directory -->
        <init_database_scripts_path>../../../vospace-file-catalog</init_database_scripts_path>
        <init_database_scripts_path>../../../vospace-file-catalog</init_database_scripts_path>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <zonky.postgres-binaries.version>12.5.0</zonky.postgres-binaries.version>
    </properties>
    </properties>


    <dependencies>
    <dependencies>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
      
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        <!-- Jackson-JAXB compatibility -->
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        
        <dependency>
            <groupId>it.oats.inaf</groupId>
            <artifactId>vospace-datamodel</artifactId>
            <version>1.0-SNAPSHOT</version>
            <exclusions>
                <!-- Transitive dependency excluded to avoid duplicated dependency issues.
                We want to use always the version provided by Spring Boot -->
                <exclusion>
                    <groupId>com.fasterxml.jackson.module</groupId>
                    <artifactId>jackson-module-jaxb-annotations</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
              
        <dependency>
        <dependency>
            <groupId>it.inaf.ia2</groupId>
            <groupId>it.inaf.ia2</groupId>
            <artifactId>auth-lib</artifactId>
            <artifactId>vospace-parent-classes</artifactId>
            <version>2.0.0-SNAPSHOT</version>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        </dependency>
                
        <dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <artifactId>jedis</artifactId>
        </dependency>
        </dependency>
        
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-inline</artifactId>
        </dependency>
        
        <!-- Embedded PostgreSQL: -->
        <dependency>
            <groupId>com.opentable.components</groupId>
            <artifactId>otj-pg-embedded</artifactId>
            <version>0.13.3</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
    
    <profiles>
        <profile>
            <id>platform-linux</id>
            <activation>
                <os>
                    <family>unix</family> 
                </os>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>io.zonky.test.postgres</groupId>
                    <artifactId>embedded-postgres-binaries-linux-amd64</artifactId>
                    <version>${zonky.postgres-binaries.version}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>platform-windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>io.zonky.test.postgres</groupId>
                    <artifactId>embedded-postgres-binaries-windows-amd64</artifactId>
                    <version>${zonky.postgres-binaries.version}</version>
                    <scope>test</scope>
                </dependency>
    </dependencies>
    </dependencies>
        </profile>
    </profiles>
    
    <repositories>
        <repository>
            <id>ia2-snapshots</id>
            <name>your custom repo</name>
            <url>http://repo.ia2.inaf.it/maven/repository/snapshots</url>
        </repository>
    </repositories>


    <build>
    <build>
        <finalName>${finalName}</finalName>
        <finalName>${finalName}</finalName>
@@ -173,17 +57,9 @@
                <groupId>org.springframework.boot</groupId>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <trimStackTrace>false</trimStackTrace>
                </configuration>
            </plugin>
            <plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6</version>
                <executions>
                <executions>
                    <execution>
                    <execution>
                        <goals>
                        <goals>
@@ -202,4 +78,12 @@
        </plugins>
        </plugins>
    </build>
    </build>


    <repositories>
        <repository>
            <id>ia2-snapshots</id>
            <name>IA2 snapshot repository</name>
            <url>http://repo.ia2.inaf.it/maven/repository/snapshots</url>
        </repository>
    </repositories>

</project>
</project>
+2 −2
Original line number Original line Diff line number Diff line
@@ -70,7 +70,7 @@ public class CreateNodeService {
        }
        }


        if (!NodeUtils.checkIfWritable(parentNode, principal.getName(), principal.getGroups())) {
        if (!NodeUtils.checkIfWritable(parentNode, principal.getName(), principal.getGroups())) {
            throw new PermissionDeniedException(path);
            throw PermissionDeniedException.forPath(path);
        }
        }


        // Check if node creator property is set. If not set it according to 
        // Check if node creator property is set. If not set it according to 
@@ -87,7 +87,7 @@ public class CreateNodeService {
        } else {
        } else {
            if (!creator.equals(principal.getName())) // maybe a more specific exception would be more appropriate?
            if (!creator.equals(principal.getName())) // maybe a more specific exception would be more appropriate?
            {
            {
                throw new PermissionDeniedException(path);
                throw PermissionDeniedException.forPath(path);
            }
            }
        }
        }


+3 −3
Original line number Original line Diff line number Diff line
@@ -55,7 +55,7 @@ public class DeleteNodeController extends BaseNodeController {
        if (pathComponents.isEmpty()) { 
        if (pathComponents.isEmpty()) { 
            
            
            // Manage root node
            // Manage root node
            throw new PermissionDeniedException("root");
            throw PermissionDeniedException.forPath("/");
            
            
        } else {
        } else {
            
            
@@ -72,7 +72,7 @@ public class DeleteNodeController extends BaseNodeController {
        }
        }
        
        
        if (!NodeUtils.checkIfWritable(toBeDeletedNode, principal.getName(), principal.getGroups())) {
        if (!NodeUtils.checkIfWritable(toBeDeletedNode, principal.getName(), principal.getGroups())) {
            throw new PermissionDeniedException(path);
            throw PermissionDeniedException.forPath(path);
        }
        }
                
                
        try {
        try {
+20 −0
Original line number Original line Diff line number Diff line
/*
 * This file is part of vospace-rest
 * Copyright (C) 2021 Istituto Nazionale di Astrofisica
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
package it.inaf.oats.vospace;

import it.inaf.oats.vospace.exception.DefaultErrorController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ErrorController extends DefaultErrorController {

    @Autowired
    public ErrorController(ErrorAttributes errorAttributes) {
        super(errorAttributes);
    }
}
+32 −5
Original line number Original line Diff line number Diff line
@@ -7,6 +7,8 @@ package it.inaf.oats.vospace;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.inaf.ia2.aa.data.User;
import it.inaf.ia2.aa.data.User;
import it.inaf.oats.vospace.datamodel.Views;
import it.inaf.oats.vospace.exception.InvalidArgumentException;
import java.io.OutputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Collectors;
@@ -39,8 +41,33 @@ public class FileServiceClient {


    public String startArchiveJob(Transfer transfer, String jobId) {
    public String startArchiveJob(Transfer transfer, String jobId) {


        List<String> vosPaths = transfer.getTarget().stream()
        if (transfer.getTarget().size() != 1) {
                .map(p -> p.substring("vos://".length() + authority.length())).collect(Collectors.toList());
            throw new IllegalArgumentException("Target size is " + transfer.getTarget().size());
        }

        String target = transfer.getTarget().get(0)
                .substring("vos://".length() + authority.length());

        String viewUri = transfer.getView().getUri();

        // Generate list of paths using view include parameters
        List<String> vosPaths = transfer.getView().getParam().stream()
                .map(p -> {
                    if (p.getUri().equals(viewUri + "/include")) {
                        if (p.getValue().contains("../")) {
                            throw new InvalidArgumentException("Relative paths are not supported");
                        }
                        return target + "/" + p.getValue();
                    } else {
                        throw new InvalidArgumentException("Unsupported view parameter: " + p.getUri());
                    }
                })
                .collect(Collectors.toList());

        if (vosPaths.isEmpty()) {
            // Add target path
            vosPaths.add(target);
        }


        ArchiveRequest archiveRequest = new ArchiveRequest();
        ArchiveRequest archiveRequest = new ArchiveRequest();
        archiveRequest.setJobId(jobId);
        archiveRequest.setJobId(jobId);
@@ -65,7 +92,7 @@ public class FileServiceClient {
        }, new Object[]{});
        }, new Object[]{});
    }
    }


    private static class ArchiveRequest {
    public static class ArchiveRequest {


        private String type;
        private String type;
        private String jobId;
        private String jobId;
@@ -98,9 +125,9 @@ public class FileServiceClient {


    private static String archiveTypeFromViewUri(String viewUri) {
    private static String archiveTypeFromViewUri(String viewUri) {
        switch (viewUri) {
        switch (viewUri) {
            case "ivo://ia2.inaf.it/vospace/views#tar":
            case Views.TAR_VIEW_URI:
                return "TAR";
                return "TAR";
            case "ivo://ia2.inaf.it/vospace/views#zip":
            case Views.ZIP_VIEW_URI:
                return "ZIP";
                return "ZIP";
            default:
            default:
                throw new IllegalArgumentException("Archive type not defined for " + viewUri);
                throw new IllegalArgumentException("Archive type not defined for " + viewUri);
Loading