diff --git a/src/main/java/it/inaf/oats/vospace/CreateNodeController.java b/src/main/java/it/inaf/oats/vospace/CreateNodeController.java index 1a0e791c69834207387ab57b6a9d9a0e5999515c..ebf2c0214acf09892862968d861e12540866ef16 100644 --- a/src/main/java/it/inaf/oats/vospace/CreateNodeController.java +++ b/src/main/java/it/inaf/oats/vospace/CreateNodeController.java @@ -32,10 +32,11 @@ public class CreateNodeController extends BaseNodeController { List userGroups = principal.getGroups(); - if (!isValidURI(node.getUri())) + if (!isValidURI(node.getUri())) { throw new InvalidURIException(node.getUri()); - - if(!isUrlConsistentWithPayloadURI(node.getUri(), path)) { + } + + if (!isUrlConsistentWithPayloadURI(node.getUri(), path)) { throw new InvalidURIException(node.getUri(), path); } @@ -59,38 +60,42 @@ public class CreateNodeController extends BaseNodeController { } List nodeGroups - = Arrays.asList(groupWritePropValues.get(0).split(",",-1)); + = Arrays.asList(groupWritePropValues.get(0).split(",", -1)); if (!nodeGroups.stream().anyMatch((i) -> userGroups.contains(i))) { throw new PermissionDeniedException(path); } - // Check if parent node is a LinkNode and if so throw exception - if (parentNode.getType().equals("vos:LinkNode")) { - throw new LinkFoundException(getParentPath(path)); + // Check if parent node is not a Container node and in case throw + // appropriate exception + + if (!parentNode.getType().equals("vos:ContainerNode")) { + if (parentNode.getType().equals("vos:LinkNode")) { + throw new LinkFoundException(getParentPath(path)); + } else { + throw new ContainerNotFoundException(getParentPath(path)); + } } - nodeDao.createNode(node); return node; } - + // Assuming that this service implementation uses only ! as a separator // in the authority part of the URI - private boolean isValidURI(String nodeURI) - { + private boolean isValidURI(String nodeURI) { String parsedAuthority; - if(!nodeURI.startsWith("vos://")) - { + if (!nodeURI.startsWith("vos://")) { return false; } else { - parsedAuthority = nodeURI.replaceAll("vos://", "").split("/",-1)[0]; + parsedAuthority = nodeURI.replaceAll("vos://", "").split("/", -1)[0]; } - - if(parsedAuthority.isEmpty() || - !parsedAuthority.replace("~","!").equals(authority)) + + if (parsedAuthority.isEmpty() + || !parsedAuthority.replace("~", "!").equals(authority)) { return false; - - return true; + } + + return true; } private boolean isUrlConsistentWithPayloadURI(String nodeURI, String path) {