Loading src/main/java/it/inaf/oats/vospace/BaseNodeController.java +6 −9 Original line number Diff line number Diff line package it.inaf.oats.vospace; import it.inaf.oats.vospace.datamodel.NodeUtils; import it.inaf.oats.vospace.exception.InvalidURIException; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; Loading @@ -9,20 +10,16 @@ public abstract class BaseNodeController { @Autowired private HttpServletRequest servletRequest; protected String getPath() { String requestURL = servletRequest.getRequestURL().toString(); try { return NodeUtils.getPathFromRequestURLString(requestURL); } catch (IllegalArgumentException ex) { throw new InvalidURIException(ex); } } protected String getParentPath(String path) { return NodeUtils.getParentPath(path); } } src/main/java/it/inaf/oats/vospace/CreateNodeController.java +6 −7 Original line number Diff line number Diff line package it.inaf.oats.vospace; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.datamodel.NodeUtils; import net.ivoa.xml.vospace.v2.Node; import org.springframework.http.MediaType; Loading @@ -9,15 +8,17 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.beans.factory.annotation.Autowired; import it.inaf.oats.vospace.persistence.NodeDAO; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.PutMapping; import it.inaf.oats.vospace.exception.*; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @RestController public class CreateNodeController extends BaseNodeController { private static final Logger LOG = LoggerFactory.getLogger(CreateNodeController.class); @Autowired private NodeDAO nodeDao; Loading @@ -31,6 +32,8 @@ public class CreateNodeController extends BaseNodeController { String path = getPath(); LOG.debug("createNode called for path {}", path); // Validate payload node URI if (!isValidURI(node.getUri())) { throw new InvalidURIException(node.getUri()); Loading Loading @@ -93,9 +96,5 @@ public class CreateNodeController extends BaseNodeController { // form vos://authority[!~]somepath/mynode..." return nodeURI.replaceAll("vos://[^/]+", "").equals(path); } } src/main/java/it/inaf/oats/vospace/DeleteNodeController.java +6 −12 Original line number Diff line number Diff line /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package it.inaf.oats.vospace; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.datamodel.NodeUtils; import it.inaf.oats.vospace.exception.ContainerNotFoundException; import it.inaf.oats.vospace.exception.InternalFaultException; import it.inaf.oats.vospace.exception.LinkFoundException; import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.persistence.NodeDAO; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import net.ivoa.xml.vospace.v2.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class DeleteNodeController extends BaseNodeController { private static final Logger LOG = LoggerFactory.getLogger(DeleteNodeController.class); @Autowired private NodeDAO nodeDAO; Loading @@ -39,6 +32,7 @@ public class DeleteNodeController extends BaseNodeController { public ResponseEntity<String> deleteNode(HttpServletRequest request, User principal) { String path = getPath(); LOG.debug("deleteNode called for path {}", path); // Check if the node is present, // if the node does not exist the service SHALL throw a HTTP 404 status code Loading @@ -53,7 +47,7 @@ public class DeleteNodeController extends BaseNodeController { // status code including a LinkFound fault in the entity-body if either /a // or /a/b are LinkNodes. List<String> pathComponents = NodeUtils.subPathComponents(path); if (pathComponents.size() == 0) { if (pathComponents.isEmpty()) { // Manage root node throw new PermissionDeniedException("root"); Loading src/main/java/it/inaf/oats/vospace/ListNodeController.java +5 −0 Original line number Diff line number Diff line Loading @@ -10,11 +10,15 @@ import net.ivoa.xml.vospace.v2.Node; import it.inaf.oats.vospace.persistence.NodeDAO; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; @RestController public class ListNodeController extends BaseNodeController { private static final Logger LOG = LoggerFactory.getLogger(ListNodeController.class); @Autowired private NodeDAO nodeDAO; Loading @@ -22,6 +26,7 @@ public class ListNodeController extends BaseNodeController { produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE}) public ResponseEntity<Node> listNode(HttpServletRequest request) { String path = getPath(); LOG.debug("listNode called for path {}", path); return ResponseEntity.ok(nodeDAO.listNode(path) .orElseThrow(() -> new NodeNotFoundException(path))); } Loading src/main/java/it/inaf/oats/vospace/UriService.java +4 −4 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ import it.inaf.ia2.aa.ServletRapClient; import it.inaf.ia2.aa.data.User; import it.inaf.ia2.rap.client.call.TokenExchangeRequest; import it.inaf.oats.vospace.datamodel.NodeProperties; import static it.inaf.oats.vospace.datamodel.NodeUtils.urlEncodePath; import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.persistence.NodeDAO; import java.util.ArrayList; import java.util.List; Loading Loading @@ -65,13 +67,11 @@ public class UriService { String relativePath = transfer.getTarget().substring("vos://".length() + authority.length()); // TODO handle node not found Node node = nodeDao.listNode(relativePath).get(); Node node = nodeDao.listNode(relativePath).orElseThrow(() -> new NodeNotFoundException(relativePath)); // TODO build the path according to node type // // TODO add token for authenticated access String endpoint = fileServiceUrl + relativePath + "?jobId=" + job.getJobId(); String endpoint = fileServiceUrl + urlEncodePath(relativePath) + "?jobId=" + job.getJobId(); if (!"true".equals(NodeProperties.getNodePropertiesListByURI(node, NodeProperties.PUBLIC_READ_URI))) { endpoint += "&token=" + getEndpointToken(fileServiceUrl + relativePath); Loading Loading
src/main/java/it/inaf/oats/vospace/BaseNodeController.java +6 −9 Original line number Diff line number Diff line package it.inaf.oats.vospace; import it.inaf.oats.vospace.datamodel.NodeUtils; import it.inaf.oats.vospace.exception.InvalidURIException; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; Loading @@ -9,20 +10,16 @@ public abstract class BaseNodeController { @Autowired private HttpServletRequest servletRequest; protected String getPath() { String requestURL = servletRequest.getRequestURL().toString(); try { return NodeUtils.getPathFromRequestURLString(requestURL); } catch (IllegalArgumentException ex) { throw new InvalidURIException(ex); } } protected String getParentPath(String path) { return NodeUtils.getParentPath(path); } }
src/main/java/it/inaf/oats/vospace/CreateNodeController.java +6 −7 Original line number Diff line number Diff line package it.inaf.oats.vospace; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.datamodel.NodeUtils; import net.ivoa.xml.vospace.v2.Node; import org.springframework.http.MediaType; Loading @@ -9,15 +8,17 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.beans.factory.annotation.Autowired; import it.inaf.oats.vospace.persistence.NodeDAO; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.PutMapping; import it.inaf.oats.vospace.exception.*; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @RestController public class CreateNodeController extends BaseNodeController { private static final Logger LOG = LoggerFactory.getLogger(CreateNodeController.class); @Autowired private NodeDAO nodeDao; Loading @@ -31,6 +32,8 @@ public class CreateNodeController extends BaseNodeController { String path = getPath(); LOG.debug("createNode called for path {}", path); // Validate payload node URI if (!isValidURI(node.getUri())) { throw new InvalidURIException(node.getUri()); Loading Loading @@ -93,9 +96,5 @@ public class CreateNodeController extends BaseNodeController { // form vos://authority[!~]somepath/mynode..." return nodeURI.replaceAll("vos://[^/]+", "").equals(path); } }
src/main/java/it/inaf/oats/vospace/DeleteNodeController.java +6 −12 Original line number Diff line number Diff line /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package it.inaf.oats.vospace; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.datamodel.NodeUtils; import it.inaf.oats.vospace.exception.ContainerNotFoundException; import it.inaf.oats.vospace.exception.InternalFaultException; import it.inaf.oats.vospace.exception.LinkFoundException; import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.persistence.NodeDAO; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import net.ivoa.xml.vospace.v2.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class DeleteNodeController extends BaseNodeController { private static final Logger LOG = LoggerFactory.getLogger(DeleteNodeController.class); @Autowired private NodeDAO nodeDAO; Loading @@ -39,6 +32,7 @@ public class DeleteNodeController extends BaseNodeController { public ResponseEntity<String> deleteNode(HttpServletRequest request, User principal) { String path = getPath(); LOG.debug("deleteNode called for path {}", path); // Check if the node is present, // if the node does not exist the service SHALL throw a HTTP 404 status code Loading @@ -53,7 +47,7 @@ public class DeleteNodeController extends BaseNodeController { // status code including a LinkFound fault in the entity-body if either /a // or /a/b are LinkNodes. List<String> pathComponents = NodeUtils.subPathComponents(path); if (pathComponents.size() == 0) { if (pathComponents.isEmpty()) { // Manage root node throw new PermissionDeniedException("root"); Loading
src/main/java/it/inaf/oats/vospace/ListNodeController.java +5 −0 Original line number Diff line number Diff line Loading @@ -10,11 +10,15 @@ import net.ivoa.xml.vospace.v2.Node; import it.inaf.oats.vospace.persistence.NodeDAO; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; @RestController public class ListNodeController extends BaseNodeController { private static final Logger LOG = LoggerFactory.getLogger(ListNodeController.class); @Autowired private NodeDAO nodeDAO; Loading @@ -22,6 +26,7 @@ public class ListNodeController extends BaseNodeController { produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE}) public ResponseEntity<Node> listNode(HttpServletRequest request) { String path = getPath(); LOG.debug("listNode called for path {}", path); return ResponseEntity.ok(nodeDAO.listNode(path) .orElseThrow(() -> new NodeNotFoundException(path))); } Loading
src/main/java/it/inaf/oats/vospace/UriService.java +4 −4 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ import it.inaf.ia2.aa.ServletRapClient; import it.inaf.ia2.aa.data.User; import it.inaf.ia2.rap.client.call.TokenExchangeRequest; import it.inaf.oats.vospace.datamodel.NodeProperties; import static it.inaf.oats.vospace.datamodel.NodeUtils.urlEncodePath; import it.inaf.oats.vospace.exception.NodeNotFoundException; import it.inaf.oats.vospace.persistence.NodeDAO; import java.util.ArrayList; import java.util.List; Loading Loading @@ -65,13 +67,11 @@ public class UriService { String relativePath = transfer.getTarget().substring("vos://".length() + authority.length()); // TODO handle node not found Node node = nodeDao.listNode(relativePath).get(); Node node = nodeDao.listNode(relativePath).orElseThrow(() -> new NodeNotFoundException(relativePath)); // TODO build the path according to node type // // TODO add token for authenticated access String endpoint = fileServiceUrl + relativePath + "?jobId=" + job.getJobId(); String endpoint = fileServiceUrl + urlEncodePath(relativePath) + "?jobId=" + job.getJobId(); if (!"true".equals(NodeProperties.getNodePropertiesListByURI(node, NodeProperties.PUBLIC_READ_URI))) { endpoint += "&token=" + getEndpointToken(fileServiceUrl + relativePath); Loading