Loading src/main/java/it/inaf/oats/vospace/DeleteNodeService.java +34 −21 Original line number Diff line number Diff line Loading @@ -20,69 +20,82 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Isolation; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.exception.InternalFaultException; import it.inaf.oats.vospace.exception.NodeBusyException; import org.springframework.transaction.annotation.Transactional; /** * * @author Nicola Fulvio Calabria <nicola.calabria at inaf.it> */ @Service @EnableTransactionManagement public class DeleteNodeService { @Autowired protected NodeDAO nodeDao; @Value("${vospace-authority}") protected String authority; @Transactional(rollbackFor = { Exception.class }, @Transactional(rollbackFor = {Exception.class}, isolation = Isolation.REPEATABLE_READ) public void deleteNode(String path, User principal) { public void deleteNode(String path, User principal) { Node toBeDeletedNode = nodeDao.listNode(path) .orElseThrow(() -> new NodeNotFoundException(path)); .orElseThrow(() -> new NodeNotFoundException(path)); if (!NodeUtils.checkIfWritable(toBeDeletedNode, principal.getName(), principal.getGroups())) { throw PermissionDeniedException.forPath(path); } nodeDao.deleteNode(path); Long nodeId = nodeDao.getNodeId(path).get(); if (nodeDao.isBranchBusy(nodeId)) { throw new NodeBusyException(path); } if (nodeDao.isBranchImmutable(nodeId)) { throw new InternalFaultException("Target branch contains immutable nodes"); } nodeDao.deleteNode(path); } public void doPreliminaryChecks(String path) throws Exception { // Check if the node is present, // if the node does not exist the service SHALL throw a HTTP 404 status code // including a NodeNotFound fault in the entity-body // If note present, got it nodeDao.listNode(path) .orElseThrow(() -> new NodeNotFoundException(path)); .orElseThrow(() -> new NodeNotFoundException(path)); // If a parent node in the URI path is a LinkNode, the service SHALL throw // a HTTP 400 status code including a LinkFound fault in the entity-body. // For example, given the URI path /a/b/c, the service must throw a HTTP 400 // 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.isEmpty()) { if (pathComponents.isEmpty()) { // Manage root node throw PermissionDeniedException.forPath("/"); } else { // Manage all precursors in full path for (int i = 0; i < pathComponents.size(); i++) { 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 if (mynode.getType().equals("vos:LinkNode") && i < pathComponents.size() - 1) // a LinkNode leaf can be deleted { throw new LinkFoundException(tmpPath); } } } } } Loading
src/main/java/it/inaf/oats/vospace/DeleteNodeService.java +34 −21 Original line number Diff line number Diff line Loading @@ -20,69 +20,82 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Isolation; import it.inaf.ia2.aa.data.User; import it.inaf.oats.vospace.exception.InternalFaultException; import it.inaf.oats.vospace.exception.NodeBusyException; import org.springframework.transaction.annotation.Transactional; /** * * @author Nicola Fulvio Calabria <nicola.calabria at inaf.it> */ @Service @EnableTransactionManagement public class DeleteNodeService { @Autowired protected NodeDAO nodeDao; @Value("${vospace-authority}") protected String authority; @Transactional(rollbackFor = { Exception.class }, @Transactional(rollbackFor = {Exception.class}, isolation = Isolation.REPEATABLE_READ) public void deleteNode(String path, User principal) { public void deleteNode(String path, User principal) { Node toBeDeletedNode = nodeDao.listNode(path) .orElseThrow(() -> new NodeNotFoundException(path)); .orElseThrow(() -> new NodeNotFoundException(path)); if (!NodeUtils.checkIfWritable(toBeDeletedNode, principal.getName(), principal.getGroups())) { throw PermissionDeniedException.forPath(path); } nodeDao.deleteNode(path); Long nodeId = nodeDao.getNodeId(path).get(); if (nodeDao.isBranchBusy(nodeId)) { throw new NodeBusyException(path); } if (nodeDao.isBranchImmutable(nodeId)) { throw new InternalFaultException("Target branch contains immutable nodes"); } nodeDao.deleteNode(path); } public void doPreliminaryChecks(String path) throws Exception { // Check if the node is present, // if the node does not exist the service SHALL throw a HTTP 404 status code // including a NodeNotFound fault in the entity-body // If note present, got it nodeDao.listNode(path) .orElseThrow(() -> new NodeNotFoundException(path)); .orElseThrow(() -> new NodeNotFoundException(path)); // If a parent node in the URI path is a LinkNode, the service SHALL throw // a HTTP 400 status code including a LinkFound fault in the entity-body. // For example, given the URI path /a/b/c, the service must throw a HTTP 400 // 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.isEmpty()) { if (pathComponents.isEmpty()) { // Manage root node throw PermissionDeniedException.forPath("/"); } else { // Manage all precursors in full path for (int i = 0; i < pathComponents.size(); i++) { 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 if (mynode.getType().equals("vos:LinkNode") && i < pathComponents.size() - 1) // a LinkNode leaf can be deleted { throw new LinkFoundException(tmpPath); } } } } }