Skip to content
Snippets Groups Projects
Commit ecb8bc95 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Inherited from vospace-parent and replaced all exception classes

parent b19603a4
No related branches found
No related tags found
No related merge requests found
Showing
with 45 additions and 421 deletions
......@@ -3,10 +3,9 @@
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
<groupId>it.inaf.ia2</groupId>
<artifactId>vospace-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>it.inaf.oats</groupId>
<artifactId>vospace-rest</artifactId>
......@@ -18,134 +17,19 @@
<!-- File catalog repository directory -->
<init_database_scripts_path>../../../vospace-file-catalog</init_database_scripts_path>
<finalName>${project.artifactId}-${project.version}</finalName>
<zonky.postgres-binaries.version>12.5.0</zonky.postgres-binaries.version>
</properties>
<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>
<groupId>it.inaf.ia2</groupId>
<artifactId>auth-lib</artifactId>
<version>2.0.0-SNAPSHOT</version>
<artifactId>vospace-parent-classes</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</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>
</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>
<finalName>${finalName}</finalName>
......@@ -173,17 +57,9 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<goals>
......@@ -202,4 +78,12 @@
</plugins>
</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>
......@@ -70,7 +70,7 @@ public class CreateNodeService {
}
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
......@@ -87,7 +87,7 @@ public class CreateNodeService {
} else {
if (!creator.equals(principal.getName())) // maybe a more specific exception would be more appropriate?
{
throw new PermissionDeniedException(path);
throw PermissionDeniedException.forPath(path);
}
}
......
......@@ -55,7 +55,7 @@ public class DeleteNodeController extends BaseNodeController {
if (pathComponents.isEmpty()) {
// Manage root node
throw new PermissionDeniedException("root");
throw PermissionDeniedException.forPath("/");
} else {
......@@ -72,7 +72,7 @@ public class DeleteNodeController extends BaseNodeController {
}
if (!NodeUtils.checkIfWritable(toBeDeletedNode, principal.getName(), principal.getGroups())) {
throw new PermissionDeniedException(path);
throw PermissionDeniedException.forPath(path);
}
try {
......
/*
* 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);
}
}
......@@ -47,7 +47,7 @@ public class ListNodeController extends BaseNodeController {
} else {
if (!NodeUtils.checkIfReadable(
optNode.get(), principal.getName(), principal.getGroups())) {
throw new PermissionDeniedException(path);
throw PermissionDeniedException.forPath(path);
}
}
......
......@@ -76,7 +76,7 @@ public class MoveService {
}
if (!nodeDao.isBranchWritable(sourceId, user.getName(), user.getGroups())) {
throw new PermissionDeniedException(sourcePath);
throw PermissionDeniedException.forPath(sourcePath);
}
Optional<ShortNodeDescriptor> destShortNodeDescriptor
......@@ -88,7 +88,7 @@ public class MoveService {
ShortNodeDescriptor snd = destShortNodeDescriptor.get();
if(snd.isBusy()) throw new NodeBusyException(destinationPath);
if(snd.isPermissionDenied()) throw new PermissionDeniedException(destinationPath);
if(snd.isPermissionDenied()) throw PermissionDeniedException.forPath(destinationPath);
if(!snd.isWritable()) throw new InternalFaultException("Destination is not writable: "+ destinationPath);
if(!snd.isContainer()) throw new InternalFaultException("Existing destination is not a container: " + destinationPath);
......
......@@ -50,7 +50,7 @@ public class SetNodeController extends BaseNodeController {
// The service SHALL throw a HTTP 403 status code including a PermissionDenied fault
// in the entity-body if the user does not have permissions to perform the operation
if (!NodeUtils.checkIfWritable(toBeModifiedNode, principal.getName(), principal.getGroups())) {
throw new PermissionDeniedException(path);
throw PermissionDeniedException.forPath(path);
}
// The service SHALL throw a HTTP 403 status code including a PermissionDenied fault
......@@ -60,7 +60,7 @@ public class SetNodeController extends BaseNodeController {
String newNodeType = node.getType();
if (!storedNodeType.equals(newNodeType)) {
LOG.debug("setNode trying to modify type. Stored ", storedNodeType + ", requested " + newNodeType);
throw new PermissionDeniedException(path);
throw PermissionDeniedException.forPath(path);
}
// This method cannot be used to modify the accepts or provides list of Views for the Node.
......
......@@ -165,13 +165,13 @@ public class UriService {
case pushToVoSpace:
case pullToVoSpace:
if (!NodeUtils.checkIfWritable(node, creator, groups)) {
throw new PermissionDeniedException(relativePath);
throw PermissionDeniedException.forPath(relativePath);
}
break;
case pullFromVoSpace:
if (!NodeUtils.checkIfReadable(node, creator, groups)) {
throw new PermissionDeniedException(relativePath);
throw PermissionDeniedException.forPath(relativePath);
}
break;
......
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ContainerNotFoundException extends VoSpaceErrorSummarizableException {
public ContainerNotFoundException(String path) {
super("Path: " + path,
VOSpaceFaultEnum.NODE_NOT_FOUND);
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.CONFLICT)
public class DuplicateNodeException extends VoSpaceErrorSummarizableException {
public DuplicateNodeException(String path) {
super("Path: " + path,
VOSpaceFaultEnum.DUPLICATE_NODE);
}
}
/*
* 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.exception;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("${server.error.path:${error.path:/error}}")
public class ErrorController extends AbstractErrorController {
@Autowired
public ErrorController(ErrorAttributes errorAttributes) {
super(errorAttributes);
}
@RequestMapping(produces = MediaType.TEXT_XML_VALUE)
public void errorText(HttpServletRequest request, HttpServletResponse response) throws Exception {
ErrorAttributeOptions options = ErrorAttributeOptions.of(ErrorAttributeOptions.Include.MESSAGE);
Map<String, Object> errors = super.getErrorAttributes(request, options);
response.setContentType("text/plain;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
String errorMessage = (String) errors.get("message");
if (errorMessage != null) {
response.getOutputStream().write(errorMessage.getBytes(StandardCharsets.UTF_8));
}
}
@Override
public String getErrorPath() {
return null;
}
}
/*
* 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.exception;
import net.ivoa.xml.uws.v1.ErrorSummary;
public class ErrorSummaryFactory {
public static ErrorSummary newErrorSummary(VOSpaceFaultEnum error, String detailMessage) {
ErrorSummary result = new ErrorSummary();
result.setMessage(error.getFaultRepresentation());
result.setType(error.getType());
if (detailMessage == null || detailMessage.isBlank()) {
result.setHasDetail(false);
} else {
result.setHasDetail(true);
result.setDetailMessage(error.getFaultCaptionForDetails()
+ " "
+ detailMessage);
}
return result;
}
public static ErrorSummary newErrorSummary(VOSpaceFaultEnum error) {
return newErrorSummary(error, null);
}
public static ErrorSummary newErrorSummary(VoSpaceErrorSummarizableException e)
{
return newErrorSummary(e.getFault(), e.getDetailMessage());
}
}
/*
* 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.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) // Status code 500
public class InternalFaultException extends VoSpaceErrorSummarizableException {
private static final Logger LOG = LoggerFactory.getLogger(InternalFaultException.class);
public InternalFaultException(String msg) {
super("Description: " + msg,
VOSpaceFaultEnum.INTERNAL_FAULT);
}
public InternalFaultException(Throwable cause) {
super("Description: " + getMessage(cause),
VOSpaceFaultEnum.INTERNAL_FAULT);
}
private static String getMessage(Throwable cause) {
LOG.error("Exception caught", cause);
return cause.getMessage() != null ? cause.getMessage() : cause.getClass().getCanonicalName();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class InvalidArgumentException extends VoSpaceErrorSummarizableException {
public InvalidArgumentException(String message) {
super("Description: " + message, VOSpaceFaultEnum.INVALID_ARGUMENT);
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class InvalidURIException extends VoSpaceErrorSummarizableException {
public InvalidURIException(String URI, String path) {
super("Payload node URI: " + URI
+ " is not consistent with request path: " + path,
VOSpaceFaultEnum.INVALID_URI);
}
public InvalidURIException(String URI) {
super("URI: " + URI + " is not in a valid format",
VOSpaceFaultEnum.INVALID_URI);
}
public InvalidURIException(IllegalArgumentException ex) {
super("Description: " + ex.getMessage(),
VOSpaceFaultEnum.INVALID_URI);
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class LinkFoundException extends VoSpaceErrorSummarizableException {
public LinkFoundException(String path) {
super("Link Node found at path: " + path,
VOSpaceFaultEnum.INVALID_URI);
}
}
/*
* 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.exception;
public class NodeBusyException extends VoSpaceErrorSummarizableException {
public NodeBusyException(String path) {
super("Path: " + path,
VOSpaceFaultEnum.NODE_BUSY);
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class NodeNotFoundException extends VoSpaceErrorSummarizableException {
public NodeNotFoundException(String path) {
super("Path: " + path,
VOSpaceFaultEnum.NODE_NOT_FOUND);
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.FORBIDDEN)
public class PermissionDeniedException extends VoSpaceErrorSummarizableException {
public PermissionDeniedException(String path) {
super("Path: " + path,
VOSpaceFaultEnum.PERMISSION_DENIED);
}
}
/*
* 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.exception;
public class ProtocolNotSupportedException extends VoSpaceErrorSummarizableException{
public ProtocolNotSupportedException(String protocol) {
super("Protocol: " + protocol,
VOSpaceFaultEnum.PROTOCOL_NOT_SUPPORTED);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment