diff --git a/src/main/java/it/inaf/oats/vospace/SetNodeController.java b/src/main/java/it/inaf/oats/vospace/SetNodeController.java index c9b4c7d5f4b11d0c086d949e9a56894082a48734..ea3147c5c35e597db6733d92a979e47ec692115d 100644 --- a/src/main/java/it/inaf/oats/vospace/SetNodeController.java +++ b/src/main/java/it/inaf/oats/vospace/SetNodeController.java @@ -14,6 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -60,46 +61,10 @@ public class SetNodeController extends BaseNodeController { LOG.debug("setNode trying to modify type. Stored ", storedNodeType + ", requested " + newNodeType); throw new PermissionDeniedException(path); } - // This method cannot be used to modify the accepts or provides list of Views for the Node. - // For this case, throws exception in NodeDAO - // This method cannot be used to create children of a container Node. (Non capisco, Sara) - - // If a parent node in the URI path does not exist then the service SHALL throw a - // HTTP 404 status code including a ContainerNotFound fault in the entity-body - // For example, given the URI path /a/b/c, the service must throw a HTTP 404 status - // code including a ContainerNotFound fault in the entity-body if either /a or /a/b - // do not exist. - List<String> pathComponents = NodeUtils.subPathComponents(path); - if (pathComponents.size() == 0) { - - // Manage root node - throw new PermissionDeniedException("root"); - - } else { - - // Manage all precursors in full path - for (int i = 0; i < pathComponents.size(); i++) { - String tmpPath = pathComponents.get(i); - Node mynode = nodeDao.listNode(tmpPath) - .orElseThrow(() -> new NodeNotFoundException(tmpPath)); - if (mynode.getType().equals("vos:LinkNode") && i < pathComponents.size()-1) // a LinkNode leaf can be deleted - throw new LinkFoundException(tmpPath); - - } - - } - - - //The service SHOULD throw a HTTP 500 status code including an InternalFault fault - // in the entity-body if the operation fails - // Done in NodeDAO - - // to be fixed - // A HTTP 200 status code and a Node representation in the entity-body The full - // expanded record for the node SHALL be returned, including any xsi:type - // specific extensions. - return ResponseEntity.ok(nodeDao.setNode(node)); - + + Node result = nodeDao.setNode(node).orElseThrow(() -> new PermissionDeniedException("")); + + return ResponseEntity.ok(result); } } 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 96f81dd2b8530f71f317f58e9d144a51113dd6f0..ab8095eba6328612b4bf40a8513476c53f3c9685 100644 --- a/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java +++ b/src/main/java/it/inaf/oats/vospace/persistence/NodeDAO.java @@ -124,29 +124,22 @@ public class NodeDAO { } - public Node setNode(Node newNode) { + public Optional<Node> setNode(Node newNode) { // Verify that the node is in the database - String nodeURI = newNode.getUri(); - List<NodePaths> paths = getNodePathsFromDB(nodeURI); - - if (paths.isEmpty()) { - throw new IllegalStateException("Unable to find node during node update"); - } - if (paths.size() > 1) { - throw new IllegalStateException("Multiple ltree parent paths during node update"); - } - + String vosPath = NodeUtils.getVosPath(newNode); + // List<NodePaths> paths = getNodePathsFromDB(nodeURI); + // This method cannot be used to modify the accepts or provides list of Views for the Node. // Only DataNodes has Views (see VOSpace Data Model // Check if trying to change views getting Views (if present) of the modified node if (newNode instanceof DataNode) { DataNode dataNode = (DataNode)newNode; List<View> requestedAcceptedViews = dataNode.getAccepts(); - List<View> savedAcceptedViews = getAcceptedViewsFromDB(paths.get(0).getPath()); + List<View> savedAcceptedViews = getAcceptedViewsFromDB(vosPath); // Get the Views of the saved node List<View> requestedProvidedViews = dataNode.getProvides(); - List<View> savedProvidedViews = getProvidedViewsFromDB(paths.get(0).getPath()); + List<View> savedProvidedViews = getProvidedViewsFromDB(vosPath); if (!requestedAcceptedViews.isEmpty()) { //se sono non nulle, devo fare i controlli, altrimenti di sicuro l'utente non sta chiedendo di cambiarle @@ -180,11 +173,11 @@ public class NodeDAO { ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_READ_URI))); ps.setArray(++i, fromPropertyToArray(ps, NodeProperties.getNodePropertyByURI(newNode, NodeProperties.GROUP_WRITE_URI))); ps.setBoolean(++i, Boolean.valueOf(NodeProperties.getNodePropertyByURI(newNode, NodeProperties.PUBLIC_READ_URI))); - ps.setString(++i, paths.get(0).getPath()); + ps.setString(++i, vosPath); return ps; }); - return newNode; + return Optional.of(newNode); }