diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java b/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java index b30d720..00a57fb 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java @@ -104,7 +104,7 @@ public class ItemsManager extends Impersonable{ @Inject DownloadHandler downloadHandler; - + @Inject TrashHandler trashHandler; @@ -114,11 +114,11 @@ public class ItemsManager extends Impersonable{ @Inject Item2NodeConverter item2Node; - + @Inject StorageOperationMediator opMediator; - + @Inject PublicLinkHandler publicLinkHandler; @@ -406,7 +406,7 @@ public class ItemsManager extends Impersonable{ Item currentItem = node2Item.getItem(publicLink.getId(), ses, Excludes.GET_ONLY_CONTENT); return downloadHandler.downloadFileItem(ses,(AbstractFileItem) currentItem, currentUser, true); } - + }catch(RepositoryException re ){ log.error("jcr error getting public link", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); @@ -611,7 +611,7 @@ public class ItemsManager extends Impersonable{ Item currentItem = node2Item.getItem(node, Excludes.ALL); if (!(currentItem instanceof AbstractFileItem)) throw new InvalidItemException("this item is not a file"); - + return downloadHandler.downloadVersionedItem(ses, currentUser, (AbstractFileItem) currentItem, versionName, true); }catch(RepositoryException re ){ @@ -711,7 +711,7 @@ public class ItemsManager extends Impersonable{ } return null; } - + @PUT @Path("{id}/move") @@ -876,18 +876,18 @@ public class ItemsManager extends Impersonable{ ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); authChecker.checkMoveOpsForProtectedFolders(ses, id); - authChecker.checkWriteAuthorizationControl(ses, currentUser, id, false); final Node nodeToMove = ses.getNodeByIdentifier(id); final Item item = node2Item.getItem(nodeToMove, null); - if (item instanceof SharedFolder) - throw new InvalidItemException("shared folder"); + /*if (item instanceof SharedFolder) + throw new InvalidItemException("shared folder");*/ if (Constants.FOLDERS_TO_EXLUDE.contains(item.getTitle())) throw new InvalidItemException("protected folder cannot be renamed"); + String uniqueName = Utils.checkExistanceAndGetUniqueName(ses, nodeToMove.getParent(), newName); try { ses.getWorkspace().getLockManager().lock(nodeToMove.getPath(), true, true, 0,currentUser); @@ -895,17 +895,23 @@ public class ItemsManager extends Impersonable{ }catch (LockException e) { throw new ItemLockedException(e); } - try { - String uniqueName = Utils.checkExistanceAndGetUniqueName(ses, nodeToMove.getParent(), newName); - - String newPath = String.format("%s/%s", nodeToMove.getParent().getPath(), uniqueName); - nodeToMove.setProperty(NodeProperty.TITLE.toString(), uniqueName); - Utils.setPropertyOnChangeNode(nodeToMove, currentUser, ItemAction.RENAMED); - ses.move(nodeToMove.getPath(), newPath); - - accountingHandler.createRename(item.getTitle(), uniqueName, ses.getNode(newPath), currentUser, ses, false); + if (item instanceof SharedFolder) { + authChecker.checkAdministratorControl(ses, currentUser, (SharedFolder)item); + nodeToMove.setProperty(NodeProperty.TITLE.toString(), uniqueName); + Utils.setPropertyOnChangeNode(nodeToMove, currentUser, ItemAction.RENAMED); + accountingHandler.createRename(item.getTitle(), uniqueName, nodeToMove, currentUser, ses, false); + } else { + authChecker.checkWriteAuthorizationControl(ses, currentUser, id, false); + String newPath = String.format("%s/%s", nodeToMove.getParent().getPath(), uniqueName); + nodeToMove.setProperty(NodeProperty.TITLE.toString(), uniqueName); + Utils.setPropertyOnChangeNode(nodeToMove, currentUser, ItemAction.RENAMED); + accountingHandler.createRename(item.getTitle(), uniqueName, ses.getNode(newPath), currentUser, ses, false); + ses.move(nodeToMove.getPath(), newPath); + } + ses.save(); + }finally { ses.getWorkspace().getLockManager().unlock(nodeToMove.getPath()); ses.getWorkspace().getLockManager().unlock(nodeToMove.getParent().getPath());