diff --git a/pom.xml b/pom.xml index efb9ef488c2fb4d2522e73bbf197b859acb28a89..9aa64c0411432c5f08aad33884f74a936995e88e 100644 --- a/pom.xml +++ b/pom.xml @@ -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> diff --git a/src/main/java/it/inaf/oats/vospace/CreateNodeService.java b/src/main/java/it/inaf/oats/vospace/CreateNodeService.java index 206a85e68115c5fc109f1692010987430f7a40cd..516f110643e7fdcb2e108527a740a938d6e61b72 100644 --- a/src/main/java/it/inaf/oats/vospace/CreateNodeService.java +++ b/src/main/java/it/inaf/oats/vospace/CreateNodeService.java @@ -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); } } diff --git a/src/main/java/it/inaf/oats/vospace/DeleteNodeController.java b/src/main/java/it/inaf/oats/vospace/DeleteNodeController.java index 45faca5611607002dfc18f7757d2b5abe1a8b64b..6ca9f25a2392c39a5a1261f27a40098c987d8105 100644 --- a/src/main/java/it/inaf/oats/vospace/DeleteNodeController.java +++ b/src/main/java/it/inaf/oats/vospace/DeleteNodeController.java @@ -55,7 +55,7 @@ public class DeleteNodeController extends BaseNodeController { if (pathComponents.isEmpty()) { // Manage root node - throw new PermissionDeniedException("root"); + throw PermissionDeniedException.forPath("/"); } else { @@ -71,8 +71,8 @@ public class DeleteNodeController extends BaseNodeController { } - if(!NodeUtils.checkIfWritable(toBeDeletedNode, principal.getName(), principal.getGroups())) { - throw new PermissionDeniedException(path); + if (!NodeUtils.checkIfWritable(toBeDeletedNode, principal.getName(), principal.getGroups())) { + throw PermissionDeniedException.forPath(path); } try { diff --git a/src/main/java/it/inaf/oats/vospace/ErrorController.java b/src/main/java/it/inaf/oats/vospace/ErrorController.java new file mode 100644 index 0000000000000000000000000000000000000000..138bd4a32688ff5c8545ac399e028e15383d4590 --- /dev/null +++ b/src/main/java/it/inaf/oats/vospace/ErrorController.java @@ -0,0 +1,20 @@ +/* + * 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); + } +} diff --git a/src/main/java/it/inaf/oats/vospace/ListNodeController.java b/src/main/java/it/inaf/oats/vospace/ListNodeController.java index bcc4b50a2407a435c47ed1d6f98dac34fb5ac5d5..1da35f704589be2336e568229bc25c7aca5e1dbc 100644 --- a/src/main/java/it/inaf/oats/vospace/ListNodeController.java +++ b/src/main/java/it/inaf/oats/vospace/ListNodeController.java @@ -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); } } diff --git a/src/main/java/it/inaf/oats/vospace/MoveService.java b/src/main/java/it/inaf/oats/vospace/MoveService.java index 1d8ce50a325f66e77b599ad14d11d8ce10dec37f..6fba8eb6c1dc038bde3fa658c2646afce5da368f 100644 --- a/src/main/java/it/inaf/oats/vospace/MoveService.java +++ b/src/main/java/it/inaf/oats/vospace/MoveService.java @@ -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); diff --git a/src/main/java/it/inaf/oats/vospace/SetNodeController.java b/src/main/java/it/inaf/oats/vospace/SetNodeController.java index 16de28d6b009e88aa5d57f22852154395e6fff45..91b6d7fa4ef332fe22fbd1534b7faee4d9e79ab1 100644 --- a/src/main/java/it/inaf/oats/vospace/SetNodeController.java +++ b/src/main/java/it/inaf/oats/vospace/SetNodeController.java @@ -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. diff --git a/src/main/java/it/inaf/oats/vospace/UriService.java b/src/main/java/it/inaf/oats/vospace/UriService.java index de871b380807b86e18b14732d9a3135876346752..06ed2b41cbf29ad73aeaa2c9484958f94356b749 100644 --- a/src/main/java/it/inaf/oats/vospace/UriService.java +++ b/src/main/java/it/inaf/oats/vospace/UriService.java @@ -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; diff --git a/src/main/java/it/inaf/oats/vospace/exception/ContainerNotFoundException.java b/src/main/java/it/inaf/oats/vospace/exception/ContainerNotFoundException.java deleted file mode 100644 index 95fdd32dd6ab812e2122ac2d009cd616569afc98..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/ContainerNotFoundException.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/DuplicateNodeException.java b/src/main/java/it/inaf/oats/vospace/exception/DuplicateNodeException.java deleted file mode 100644 index 95c0c241583bace74160127b2fdafa14beea9444..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/DuplicateNodeException.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/ErrorController.java b/src/main/java/it/inaf/oats/vospace/exception/ErrorController.java deleted file mode 100644 index 17d2091445134e663d2312a23a4a9f785e4e8932..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/ErrorController.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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; - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/ErrorSummaryFactory.java b/src/main/java/it/inaf/oats/vospace/exception/ErrorSummaryFactory.java deleted file mode 100644 index 7db96116ffa38fe5075e9243396d5a075d7c77c3..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/ErrorSummaryFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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()); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/InternalFaultException.java b/src/main/java/it/inaf/oats/vospace/exception/InternalFaultException.java deleted file mode 100644 index 1e78a4fb1e90363e68f636995b81c1dbcc2b0c74..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/InternalFaultException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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(); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/InvalidArgumentException.java b/src/main/java/it/inaf/oats/vospace/exception/InvalidArgumentException.java deleted file mode 100644 index b94230a94a3d43bc054a8b2eee70742a8d914ce2..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/InvalidArgumentException.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/InvalidURIException.java b/src/main/java/it/inaf/oats/vospace/exception/InvalidURIException.java deleted file mode 100644 index 3c9248e6db690c17c1dd4be9cfaf8e49c5152200..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/InvalidURIException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/LinkFoundException.java b/src/main/java/it/inaf/oats/vospace/exception/LinkFoundException.java deleted file mode 100644 index 55d3f99cb0cf7b5dce9d8fd834c60f2d5d57c751..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/LinkFoundException.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/NodeBusyException.java b/src/main/java/it/inaf/oats/vospace/exception/NodeBusyException.java deleted file mode 100644 index 7e0d8fc3d58e538de3f56e5253f03ebf00fdf277..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/NodeBusyException.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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); - } - -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/NodeNotFoundException.java b/src/main/java/it/inaf/oats/vospace/exception/NodeNotFoundException.java deleted file mode 100644 index 9024dc2fe9b4cc0cf5d2a69715d9add1802b9ba5..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/NodeNotFoundException.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/PermissionDeniedException.java b/src/main/java/it/inaf/oats/vospace/exception/PermissionDeniedException.java deleted file mode 100644 index 446e410a900c53f210c514836b37942104b0df1e..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/PermissionDeniedException.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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); - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/ProtocolNotSupportedException.java b/src/main/java/it/inaf/oats/vospace/exception/ProtocolNotSupportedException.java deleted file mode 100644 index 6a767964c4bd9c5465d591f9663c1e0a450800fc..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/ProtocolNotSupportedException.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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); - } - -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/VOSpaceFaultEnum.java b/src/main/java/it/inaf/oats/vospace/exception/VOSpaceFaultEnum.java deleted file mode 100644 index 82bf0b5e27dd14d4b41555878cadc605dfd0800b..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/VOSpaceFaultEnum.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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; - -// NFC: ErrorType usage is not covered in documentation, as far as I can see -// these are tentative default values. -import net.ivoa.xml.uws.v1.ErrorType; - -public enum VOSpaceFaultEnum { - // pushto - OPERATION_NOT_SUPPORTED("Operation Not Supported", ErrorType.FATAL, "OperationNotSupported"), - INTERNAL_FAULT("Internal Fault", ErrorType.TRANSIENT, "InternalFault"), - PERMISSION_DENIED("Permission Denied", ErrorType.FATAL, "PermissionDenied"), - VIEW_NOT_SUPPORTED("View Not Supported", ErrorType.FATAL, "ViewNotSupported"), - PROTOCOL_NOT_SUPPORTED("Protocol Not Supported", ErrorType.FATAL, "ProtocolNotSupported"), - INVALID_ARGUMENT("Invalid Argument", ErrorType.FATAL, "InvalidArgument"), - NODE_BUSY("Node Busy", ErrorType.TRANSIENT, "NodeBusy"), - // additional for pullto - INVALID_URI("Invalid URI", ErrorType.FATAL, "InvalidURI"), - INVALID_DATA("Invalid Data", ErrorType.FATAL, "InvalidData"), - // additional for pullfrom - NODE_NOT_FOUND("Node Not Found", ErrorType.FATAL, "NodeNotFound"), - // additional for pushfrom - TRANSFER_FAILED("Transfer Failed", ErrorType.FATAL, "TransferFailed"), - // additional for movenode/copynode - DUPLICATE_NODE("Duplicate Node", ErrorType.FATAL, "DuplicateNode"); - - private final String faultRepresentation; - private final ErrorType type; - private final String faultCaptionForDetails; - - private VOSpaceFaultEnum(String faultRepresentation, - ErrorType type, - String faultCaptionForDetails) { - this.faultRepresentation = faultRepresentation; - this.type = type; - this.faultCaptionForDetails = faultCaptionForDetails; - } - - public String getFaultRepresentation() { - return this.faultRepresentation; - } - - public ErrorType getType() { - return this.type; - } - - public String getFaultCaptionForDetails() { - return faultCaptionForDetails; - } - -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/VoSpaceErrorSummarizableException.java b/src/main/java/it/inaf/oats/vospace/exception/VoSpaceErrorSummarizableException.java deleted file mode 100644 index ebd8b2ab4a4b195ec34170c320ff3913cc63f6dc..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/VoSpaceErrorSummarizableException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.INTERNAL_SERVER_ERROR) -public abstract class VoSpaceErrorSummarizableException extends VoSpaceException { - - VOSpaceFaultEnum fault; - private String detailMessage; - - public VoSpaceErrorSummarizableException(String detailMessage, VOSpaceFaultEnum fault) - { - super(fault.getFaultCaptionForDetails() + " " + detailMessage); - this.detailMessage = detailMessage; - this.fault = fault; - } - - public VOSpaceFaultEnum getFault() - { - return this.fault; - } - - public String getDetailMessage() - { - return this.detailMessage; - } -} diff --git a/src/main/java/it/inaf/oats/vospace/exception/VoSpaceException.java b/src/main/java/it/inaf/oats/vospace/exception/VoSpaceException.java deleted file mode 100644 index 4d3c983630f051f8a5b358df4399261e36b8f82a..0000000000000000000000000000000000000000 --- a/src/main/java/it/inaf/oats/vospace/exception/VoSpaceException.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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 VoSpaceException extends RuntimeException { - - public VoSpaceException(String message) { - super(message); - } -} diff --git a/src/test/java/it/inaf/oats/vospace/TransferControllerTest.java b/src/test/java/it/inaf/oats/vospace/TransferControllerTest.java index d85292b90ce739cfff876fdc569f93b9b4dd3be8..2b6fa1f48d3cdeb6f745d59b20595c8ede9a6a13 100644 --- a/src/test/java/it/inaf/oats/vospace/TransferControllerTest.java +++ b/src/test/java/it/inaf/oats/vospace/TransferControllerTest.java @@ -313,7 +313,7 @@ public class TransferControllerTest { job.setJobId("123"); job.setPhase(ExecutionPhase.EXECUTING); ErrorSummary e = ErrorSummaryFactory.newErrorSummary( - new PermissionDeniedException("/pippo1/pippo2") + PermissionDeniedException.forPath("/pippo1/pippo2") ); job.setErrorSummary(e); diff --git a/src/test/java/it/inaf/oats/vospace/persistence/JobDAOTest.java b/src/test/java/it/inaf/oats/vospace/persistence/JobDAOTest.java index 922a6d7751b64f4cac66b48bd6cc4d2d0719cd6a..69b0f8e0a1a2206c14ba85e67b8d47765b616e8a 100644 --- a/src/test/java/it/inaf/oats/vospace/persistence/JobDAOTest.java +++ b/src/test/java/it/inaf/oats/vospace/persistence/JobDAOTest.java @@ -146,7 +146,7 @@ public class JobDAOTest { // Generate it from exception ErrorSummary errorSummary = ErrorSummaryFactory.newErrorSummary( - new PermissionDeniedException("/pippo1/pippo2")); + PermissionDeniedException.forPath("/pippo1/pippo2")); // Check if properly generated assertTrue(errorSummary.isHasDetail()); @@ -177,7 +177,7 @@ public class JobDAOTest { // Generate it from exception ErrorSummary errorSummary = ErrorSummaryFactory.newErrorSummary( - new PermissionDeniedException("/pippo1/pippo2")); + PermissionDeniedException.forPath("/pippo1/pippo2")); // Check if properly generated assertTrue(errorSummary.isHasDetail());