ItemLockedException used on lock error
git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/data-access/storagehub-webapp/1.0@178706 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
59b2fbdefc
commit
f4fd2cf6b0
|
@ -10,6 +10,7 @@ import javax.inject.Singleton;
|
||||||
import javax.jcr.Node;
|
import javax.jcr.Node;
|
||||||
import javax.jcr.RepositoryException;
|
import javax.jcr.RepositoryException;
|
||||||
import javax.jcr.Session;
|
import javax.jcr.Session;
|
||||||
|
import javax.jcr.lock.LockException;
|
||||||
import javax.jcr.security.AccessControlEntry;
|
import javax.jcr.security.AccessControlEntry;
|
||||||
import javax.jcr.security.AccessControlManager;
|
import javax.jcr.security.AccessControlManager;
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ import org.gcube.common.storagehub.model.Excludes;
|
||||||
import org.gcube.common.storagehub.model.NodeConstants;
|
import org.gcube.common.storagehub.model.NodeConstants;
|
||||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.ItemLockedException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
|
@ -61,7 +63,12 @@ public class UnshareHandler {
|
||||||
if (users==null || users.size()==0 || usersInSharedFolder.size()<=1)
|
if (users==null || users.size()==0 || usersInSharedFolder.size()<=1)
|
||||||
return unshareAll(login, ses, sharedItem);
|
return unshareAll(login, ses, sharedItem);
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(sharedNode.getPath(), true, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(sharedNode.getPath(), true, true, 0,login);
|
||||||
|
}catch (LockException e) {
|
||||||
|
throw new ItemLockedException(e);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (users.size()==1 && users.contains(login))
|
if (users.size()==1 && users.contains(login))
|
||||||
return unshareCaller(login, ses, sharedItem);
|
return unshareCaller(login, ses, sharedItem);
|
||||||
|
@ -80,7 +87,12 @@ public class UnshareHandler {
|
||||||
|
|
||||||
Node sharedItemNode = ses.getNodeByIdentifier(item.getId());
|
Node sharedItemNode = ses.getNodeByIdentifier(item.getId());
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(sharedItemNode.getPath(), true, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(sharedItemNode.getPath(), true, true, 0,login);
|
||||||
|
}catch (LockException e) {
|
||||||
|
throw new ItemLockedException(e);
|
||||||
|
}
|
||||||
|
|
||||||
Node unsharedNode;
|
Node unsharedNode;
|
||||||
try {
|
try {
|
||||||
log.debug("user list is empty, I'm going to remove also the shared dir");
|
log.debug("user list is empty, I'm going to remove also the shared dir");
|
||||||
|
|
|
@ -7,6 +7,7 @@ import javax.inject.Inject;
|
||||||
import javax.jcr.Node;
|
import javax.jcr.Node;
|
||||||
import javax.jcr.RepositoryException;
|
import javax.jcr.RepositoryException;
|
||||||
import javax.jcr.Session;
|
import javax.jcr.Session;
|
||||||
|
import javax.jcr.lock.LockException;
|
||||||
import javax.jcr.security.AccessControlManager;
|
import javax.jcr.security.AccessControlManager;
|
||||||
import javax.jcr.security.Privilege;
|
import javax.jcr.security.Privilege;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
@ -29,6 +30,7 @@ import org.gcube.common.storagehub.model.acls.AccessType;
|
||||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
||||||
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.ItemLockedException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
@ -108,8 +110,11 @@ public class ItemSharing {
|
||||||
}
|
}
|
||||||
ses.save();
|
ses.save();
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(sharedFolderNode.getPath(), true, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(sharedFolderNode.getPath(), true, true, 0,login);
|
||||||
|
}catch (LockException e) {
|
||||||
|
throw new ItemLockedException(e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
AccessControlManager acm = ses.getAccessControlManager();
|
AccessControlManager acm = ses.getAccessControlManager();
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
||||||
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.ItemLockedException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
|
@ -133,8 +134,12 @@ public class ItemsCreator {
|
||||||
|
|
||||||
authChecker.checkWriteAuthorizationControl(ses, destination.getIdentifier(), true);
|
authChecker.checkWriteAuthorizationControl(ses, destination.getIdentifier(), true);
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
||||||
|
}catch (LockException le) {
|
||||||
|
throw new ItemLockedException(le);
|
||||||
|
}
|
||||||
|
|
||||||
Node newNode;
|
Node newNode;
|
||||||
try {
|
try {
|
||||||
newNode = Utils.createFolderInternally(ses, destination, name, description, hidden, login, accountingHandler);
|
newNode = Utils.createFolderInternally(ses, destination, name, description, hidden, login, accountingHandler);
|
||||||
|
@ -184,7 +189,11 @@ public class ItemsCreator {
|
||||||
|
|
||||||
authChecker.checkWriteAuthorizationControl(ses, destination.getIdentifier(), true);
|
authChecker.checkWriteAuthorizationControl(ses, destination.getIdentifier(), true);
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
||||||
|
}catch (LockException le) {
|
||||||
|
throw new ItemLockedException(le);
|
||||||
|
}
|
||||||
|
|
||||||
Node newNode;
|
Node newNode;
|
||||||
try {
|
try {
|
||||||
|
@ -264,7 +273,7 @@ public class ItemsCreator {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Node createFileItemInternally(Session ses, Node destinationNode, InputStream stream, String name, String description, String login) throws RepositoryException, UserNotAuthorizedException, BackendGenericError{
|
private Node createFileItemInternally(Session ses, Node destinationNode, InputStream stream, String name, String description, String login) throws RepositoryException, UserNotAuthorizedException, ItemLockedException, BackendGenericError{
|
||||||
|
|
||||||
ContentHandler handler = getContentHandler(stream , name, destinationNode.getPath(), login);
|
ContentHandler handler = getContentHandler(stream , name, destinationNode.getPath(), login);
|
||||||
|
|
||||||
|
@ -280,7 +289,12 @@ public class ItemsCreator {
|
||||||
try {
|
try {
|
||||||
newNode = ses.getNode(org.gcube.common.storagehub.model.Paths.append(org.gcube.common.storagehub.model.Paths.getPath(destinationNode.getPath()), name).toPath());
|
newNode = ses.getNode(org.gcube.common.storagehub.model.Paths.append(org.gcube.common.storagehub.model.Paths.getPath(destinationNode.getPath()), name).toPath());
|
||||||
authChecker.checkWriteAuthorizationControl(ses, newNode.getIdentifier(), false);
|
authChecker.checkWriteAuthorizationControl(ses, newNode.getIdentifier(), false);
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(newNode.getPath(), true, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(newNode.getPath(), true, true, 0,login);
|
||||||
|
}catch (LockException le) {
|
||||||
|
throw new ItemLockedException(le);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
versionHandler.checkoutContentNode(newNode, ses);
|
versionHandler.checkoutContentNode(newNode, ses);
|
||||||
log.trace("replacing content of class {}",item.getContent().getClass());
|
log.trace("replacing content of class {}",item.getContent().getClass());
|
||||||
|
@ -291,7 +305,11 @@ public class ItemsCreator {
|
||||||
}
|
}
|
||||||
}catch(PathNotFoundException pnf) {
|
}catch(PathNotFoundException pnf) {
|
||||||
authChecker.checkWriteAuthorizationControl(ses, destinationNode.getIdentifier(), true);
|
authChecker.checkWriteAuthorizationControl(ses, destinationNode.getIdentifier(), true);
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(destinationNode.getPath(), false, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(destinationNode.getPath(), false, true, 0,login);
|
||||||
|
}catch (LockException le) {
|
||||||
|
throw new ItemLockedException(le);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
newNode = item2Node.getNode(destinationNode, item);
|
newNode = item2Node.getNode(destinationNode, item);
|
||||||
}finally {
|
}finally {
|
||||||
|
@ -330,11 +348,19 @@ public class ItemsCreator {
|
||||||
|
|
||||||
authChecker.checkWriteAuthorizationControl(ses, destination.getIdentifier() , true);
|
authChecker.checkWriteAuthorizationControl(ses, destination.getIdentifier() , true);
|
||||||
|
|
||||||
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
|
||||||
Node parentDirectoryNode = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parentDirectoryNode = Utils.createFolderInternally(ses, destination, parentFolderName, "", false, login, accountingHandler);
|
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
||||||
|
}catch (LockException le) {
|
||||||
|
throw new ItemLockedException(le);
|
||||||
|
}
|
||||||
|
|
||||||
|
Node parentDirectoryNode = Utils.createFolderInternally(ses, destination, parentFolderName, "", false, login, accountingHandler);
|
||||||
|
try {
|
||||||
|
if (ses.getWorkspace().getLockManager().isLocked(destination.getPath()))
|
||||||
|
ses.getWorkspace().getLockManager().unlock(destination.getPath());
|
||||||
|
} catch (Throwable t){
|
||||||
|
log.warn("error unlocking {}", destination.getPath(), t);
|
||||||
|
}
|
||||||
|
|
||||||
Set<Node> fileNodes = new HashSet<>();
|
Set<Node> fileNodes = new HashSet<>();
|
||||||
|
|
||||||
|
@ -386,14 +412,7 @@ public class ItemsCreator {
|
||||||
versionHandler.checkinContentNode(node, ses);
|
versionHandler.checkinContentNode(node, ses);
|
||||||
toReturn = parentDirectoryNode.getIdentifier();
|
toReturn = parentDirectoryNode.getIdentifier();
|
||||||
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (ses.getWorkspace().getLockManager().isLocked(destination.getPath()))
|
|
||||||
ses.getWorkspace().getLockManager().unlock(destination.getPath());
|
|
||||||
} catch (Throwable t){
|
|
||||||
log.warn("error unlocking {}", destination.getPath(), t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch(RepositoryException | ArchiveException | IOException re){
|
}catch(RepositoryException | ArchiveException | IOException re){
|
||||||
log.error("jcr error extracting archive", re);
|
log.error("jcr error extracting archive", re);
|
||||||
|
|
|
@ -25,6 +25,7 @@ import javax.jcr.Node;
|
||||||
import javax.jcr.NodeIterator;
|
import javax.jcr.NodeIterator;
|
||||||
import javax.jcr.RepositoryException;
|
import javax.jcr.RepositoryException;
|
||||||
import javax.jcr.Session;
|
import javax.jcr.Session;
|
||||||
|
import javax.jcr.lock.LockException;
|
||||||
import javax.jcr.version.Version;
|
import javax.jcr.version.Version;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
@ -57,6 +58,7 @@ import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
||||||
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.ItemLockedException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
|
@ -739,8 +741,12 @@ public class ItemsManager {
|
||||||
if (item.isShared() && (!destinationItem.isShared() || !getSharedParentNode(nodeToMove).getIdentifier().equals(getSharedParentNode(destination).getIdentifier())))
|
if (item.isShared() && (!destinationItem.isShared() || !getSharedParentNode(nodeToMove).getIdentifier().equals(getSharedParentNode(destination).getIdentifier())))
|
||||||
throw new InvalidCallParameters("shared Item cannot be moved in a different shared folder or in a private folder");
|
throw new InvalidCallParameters("shared Item cannot be moved in a different shared folder or in a private folder");
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
||||||
ses.getWorkspace().getLockManager().lock(nodeToMove.getPath(), true, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(nodeToMove.getPath(), true, true, 0,login);
|
||||||
|
}catch (LockException e) {
|
||||||
|
throw new ItemLockedException(e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String uniqueName =(Utils.checkExistanceAndGetUniqueName(ses, destination, nodeToMove.getName()));
|
String uniqueName =(Utils.checkExistanceAndGetUniqueName(ses, destination, nodeToMove.getName()));
|
||||||
String newPath = String.format("%s/%s",destination.getPath(), uniqueName);
|
String newPath = String.format("%s/%s",destination.getPath(), uniqueName);
|
||||||
|
@ -797,9 +803,12 @@ public class ItemsManager {
|
||||||
if (item instanceof FolderItem)
|
if (item instanceof FolderItem)
|
||||||
throw new InvalidItemException("folder cannot be copied");
|
throw new InvalidItemException("folder cannot be copied");
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
||||||
ses.getWorkspace().getLockManager().lock(nodeToCopy.getPath(), true, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(nodeToCopy.getPath(), true, true, 0,login);
|
||||||
|
}catch (LockException e) {
|
||||||
|
throw new ItemLockedException(e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String uniqueName = Utils.checkExistanceAndGetUniqueName(ses, destination, newFileName);
|
String uniqueName = Utils.checkExistanceAndGetUniqueName(ses, destination, newFileName);
|
||||||
String newPath= String.format("%s/%s", destination.getPath(), uniqueName);
|
String newPath= String.format("%s/%s", destination.getPath(), uniqueName);
|
||||||
|
@ -871,8 +880,13 @@ public class ItemsManager {
|
||||||
throw new InvalidItemException("protected folder cannot be renamed");
|
throw new InvalidItemException("protected folder cannot be renamed");
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(nodeToMove.getPath(), true, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(nodeToMove.getPath(), true, true, 0,login);
|
||||||
ses.getWorkspace().getLockManager().lock(nodeToMove.getParent().getPath(), false, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(nodeToMove.getParent().getPath(), false, true, 0,login);
|
||||||
|
}catch (LockException e) {
|
||||||
|
throw new ItemLockedException(e);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String uniqueName = Utils.checkExistanceAndGetUniqueName(ses, nodeToMove.getParent(), newName);
|
String uniqueName = Utils.checkExistanceAndGetUniqueName(ses, nodeToMove.getParent(), newName);
|
||||||
|
|
||||||
|
@ -919,8 +933,11 @@ public class ItemsManager {
|
||||||
|
|
||||||
final Node nodeToUpdate = ses.getNodeByIdentifier(id);
|
final Node nodeToUpdate = ses.getNodeByIdentifier(id);
|
||||||
|
|
||||||
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(nodeToUpdate.getPath(), false, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(nodeToUpdate.getPath(), false, true, 0,login);
|
||||||
|
}catch (LockException e) {
|
||||||
|
throw new ItemLockedException(e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
item2Node.updateMetadataNode(nodeToUpdate, metadata.getMap(), login);
|
item2Node.updateMetadataNode(nodeToUpdate, metadata.getMap(), login);
|
||||||
ses.save();
|
ses.save();
|
||||||
|
|
Loading…
Reference in New Issue