Commit 5d6584be authored by Sara Bertocco's avatar Sara Bertocco
Browse files
parents 8056579b a988d9c4
Loading
Loading
Loading
Loading
+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;

@@ -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);
    }
    
}
+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;
@@ -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;

@@ -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());
@@ -93,9 +96,5 @@ public class CreateNodeController extends BaseNodeController {
        // form vos://authority[!~]somepath/mynode..."

        return nodeURI.replaceAll("vos://[^/]+", "").equals(path);

    }

    

}
+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;

@@ -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 
@@ -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");
+5 −0
Original line number Diff line number Diff line
@@ -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;

@@ -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)));
    }
+4 −4
Original line number Diff line number Diff line
@@ -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;
@@ -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