diff --git a/src/main/java/it/inaf/oats/vospace/JobService.java b/src/main/java/it/inaf/oats/vospace/JobService.java index 63290feddade2ee3e516b3823e34c6ddcf4abd80..b7e38375fb4d4f72bd67512b526b07e137881ca5 100644 --- a/src/main/java/it/inaf/oats/vospace/JobService.java +++ b/src/main/java/it/inaf/oats/vospace/JobService.java @@ -111,15 +111,17 @@ public class JobService { default: throw new UnsupportedOperationException("Not implemented yet"); } - + + job.setPhase(ExecutionPhase.COMPLETED); + } catch (VoSpaceErrorSummarizableException e) { job.setPhase(ExecutionPhase.ERROR); - job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e)); - jobDAO.updateJob(job); + job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e)); } catch (Exception e) { job.setPhase(ExecutionPhase.ERROR); job.setErrorSummary(ErrorSummaryFactory.newErrorSummary( - new InternalFaultException(e))); + new InternalFaultException(e))); + } finally { jobDAO.updateJob(job); } } diff --git a/src/main/java/it/inaf/oats/vospace/URIUtils.java b/src/main/java/it/inaf/oats/vospace/URIUtils.java index b30df8df998896bcab5099f9225ea091913ddce2..dbfedf21627bf115b76befd9ca8717e079bff738 100644 --- a/src/main/java/it/inaf/oats/vospace/URIUtils.java +++ b/src/main/java/it/inaf/oats/vospace/URIUtils.java @@ -5,6 +5,7 @@ */ package it.inaf.oats.vospace; +import it.inaf.oats.vospace.exception.InternalFaultException; import it.inaf.oats.vospace.exception.InvalidURIException; import java.net.URI; import java.net.URISyntaxException; @@ -18,23 +19,32 @@ public class URIUtils { private static final Pattern FORBIDDEN_CHARS = Pattern.compile("[\\x00\\x08\\x0B\\x0C\\x0E-\\x1F" + Pattern.quote("<>?\":\\|'`*") + "]"); private static final String SCHEME = "vos"; - public static String returnURIFromVosPath(String vosPath, String authority) - throws URISyntaxException { - URI uri = new URI( - SCHEME, - authority, - vosPath, - null, - null - ); - - return uri.toASCIIString(); - } - + public static String returnURIFromVosPath(String vosPath, String authority) { + String result = null; + + try { + URI uri = new URI( + SCHEME, + authority, + vosPath, + null, + null + ); + + result = uri.toASCIIString(); + + } catch (URISyntaxException e) { + throw new InternalFaultException("unable to percent encode URI from authority and path: " + + authority + " , " + vosPath); + } + + return result; + } + public static String returnVosPathFromNodeURI(Node myNode, String authority) { return returnVosPathFromNodeURI(myNode.getUri(), authority); } - + // This method validates the URI too public static String returnVosPathFromNodeURI(String nodeURI, String authority) { diff --git a/src/main/java/it/inaf/oats/vospace/UriService.java b/src/main/java/it/inaf/oats/vospace/UriService.java index 0bdd3599248c94d9e224eb5abdbcf68e937d30dd..5f94fb6f75e9de0dba492f3325f3f1672445f13c 100644 --- a/src/main/java/it/inaf/oats/vospace/UriService.java +++ b/src/main/java/it/inaf/oats/vospace/UriService.java @@ -134,7 +134,7 @@ public class UriService { case pushToVoSpace: case pullToVoSpace: DataNode newNode = new DataNode(); - newNode.setUri("vos://"+ authority +relativePath); + newNode.setUri(URIUtils.returnURIFromVosPath(relativePath, authority)); return createNodeService.createNode(newNode, relativePath, user); default: throw new InternalFaultException("No supported job direction specified"); @@ -148,7 +148,7 @@ public class UriService { throw new InvalidArgumentException("Invalid target size: " + transfer.getTarget().size()); } - String relativePath = transfer.getTarget().get(0).substring("vos://".length() + authority.length()); + String relativePath = URIUtils.returnVosPathFromNodeURI(transfer.getTarget().get(0), authority); User user = (User) servletRequest.getUserPrincipal(); String creator = user.getName(); @@ -233,7 +233,7 @@ public class UriService { Location location = locationDAO.findPortalLocation(url.getHost()).orElseThrow(() -> new InternalFaultException("No registered location found for host " + url.getHost())); - String vosPath = nodeUri.replaceAll("vos://[^/]+", ""); + String vosPath = URIUtils.returnVosPathFromNodeURI(nodeUri, authority); String fileName = url.getPath().substring(url.getPath().lastIndexOf("/") + 1); diff --git a/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java b/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java index c6cd9eb01bf2e3e354e00c86dc9407a6606b5c59..e17f55faec256563d99080b65da4c538e3a3a527 100644 --- a/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +++ b/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java @@ -455,17 +455,7 @@ public class NodeDAO { } private String getUri(String path) { - // Percent encode path - String result = null; - - try { - result = URIUtils.returnURIFromVosPath(path, authority); - } catch (URISyntaxException e) { - throw new InternalFaultException("unable to percent encode URI from authority and path: " - + authority + " , " + path); - } - - return result; + return URIUtils.returnURIFromVosPath(path, authority); } private NodePaths getPathsFromResultSet(ResultSet rs) throws SQLException {