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;
|
||||||
|
@ -36,19 +38,19 @@ import org.slf4j.LoggerFactory;
|
||||||
public class UnshareHandler {
|
public class UnshareHandler {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(UnshareHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(UnshareHandler.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AccountingHandler accountingHandler;
|
AccountingHandler accountingHandler;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Node2ItemConverter node2Item;
|
Node2ItemConverter node2Item;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AuthorizationChecker authChecker;
|
AuthorizationChecker authChecker;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Item2NodeConverter item2Node;
|
Item2NodeConverter item2Node;
|
||||||
|
|
||||||
public String unshare(Session ses, Set<String> users, Node sharedNode, String login) throws RepositoryException, StorageHubException{
|
public String unshare(Session ses, Set<String> users, Node sharedNode, String login) throws RepositoryException, StorageHubException{
|
||||||
Item item = node2Item.getItem(sharedNode, Excludes.ALL);
|
Item item = node2Item.getItem(sharedNode, Excludes.ALL);
|
||||||
if (!(item instanceof FolderItem) || !((FolderItem) item).isShared() || ((SharedFolder) item).isVreFolder())
|
if (!(item instanceof FolderItem) || !((FolderItem) item).isShared() || ((SharedFolder) item).isVreFolder())
|
||||||
|
@ -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);
|
||||||
|
|
||||||
ses.getWorkspace().getLockManager().lock(sharedNode.getPath(), true, true, 0,login);
|
try {
|
||||||
|
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);
|
||||||
|
@ -79,8 +86,13 @@ public class UnshareHandler {
|
||||||
throw new UserNotAuthorizedException("user "+login+" not authorized to unshare all");
|
throw new UserNotAuthorizedException("user "+login+" not authorized to unshare all");
|
||||||
|
|
||||||
Node sharedItemNode = ses.getNodeByIdentifier(item.getId());
|
Node sharedItemNode = ses.getNodeByIdentifier(item.getId());
|
||||||
|
|
||||||
ses.getWorkspace().getLockManager().lock(sharedItemNode.getPath(), true, true, 0,login);
|
try {
|
||||||
|
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");
|
||||||
|
@ -96,7 +108,7 @@ public class UnshareHandler {
|
||||||
adminNode.removeShare();
|
adminNode.removeShare();
|
||||||
|
|
||||||
unsharedNode = createUnsharedFolder(ses, parentNode, directoryName, item.getDescription(), login);
|
unsharedNode = createUnsharedFolder(ses, parentNode, directoryName, item.getDescription(), login);
|
||||||
|
|
||||||
List<Item> itemsToCopy = Utils.getItemList(sharedItemNode, Excludes.ALL, null, true, null);
|
List<Item> itemsToCopy = Utils.getItemList(sharedItemNode, Excludes.ALL, null, true, null);
|
||||||
|
|
||||||
for (Item itemCopy: itemsToCopy) {
|
for (Item itemCopy: itemsToCopy) {
|
||||||
|
@ -116,8 +128,8 @@ public class UnshareHandler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String unshareCaller(String login, Session ses, SharedFolder item) throws StorageHubException, RepositoryException{
|
private String unshareCaller(String login, Session ses, SharedFolder item) throws StorageHubException, RepositoryException{
|
||||||
|
|
||||||
|
@ -128,7 +140,7 @@ public class UnshareHandler {
|
||||||
throw new InvalidCallParameters("the folder is not shared with user "+login);
|
throw new InvalidCallParameters("the folder is not shared with user "+login);
|
||||||
|
|
||||||
Node sharedFolderNode =ses.getNodeByIdentifier(item.getId());
|
Node sharedFolderNode =ses.getNodeByIdentifier(item.getId());
|
||||||
|
|
||||||
String parentId = removeSharingForUser(login, ses, item);
|
String parentId = removeSharingForUser(login, ses, item);
|
||||||
|
|
||||||
AccessControlManager acm = ses.getAccessControlManager();
|
AccessControlManager acm = ses.getAccessControlManager();
|
||||||
|
@ -165,16 +177,16 @@ public class UnshareHandler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String unsharePartial(Set<String> usersToUnshare, String login, Session ses, SharedFolder item) throws StorageHubException, RepositoryException {
|
private String unsharePartial(Set<String> usersToUnshare, String login, Session ses, SharedFolder item) throws StorageHubException, RepositoryException {
|
||||||
authChecker.checkAdministratorControl(ses, (SharedFolder)item);
|
authChecker.checkAdministratorControl(ses, (SharedFolder)item);
|
||||||
if (usersToUnshare.contains(item.getOwner()))
|
if (usersToUnshare.contains(item.getOwner()))
|
||||||
throw new UserNotAuthorizedException("user "+login+" not authorized to unshare owner");
|
throw new UserNotAuthorizedException("user "+login+" not authorized to unshare owner");
|
||||||
|
|
||||||
Node sharedFolderNode =ses.getNodeByIdentifier(item.getId());
|
Node sharedFolderNode =ses.getNodeByIdentifier(item.getId());
|
||||||
|
|
||||||
AccessControlManager acm = ses.getAccessControlManager();
|
AccessControlManager acm = ses.getAccessControlManager();
|
||||||
JackrabbitAccessControlList acls = AccessControlUtils.getAccessControlList(acm, sharedFolderNode.getPath());
|
JackrabbitAccessControlList acls = AccessControlUtils.getAccessControlList(acm, sharedFolderNode.getPath());
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -96,9 +98,9 @@ public class ItemSharing {
|
||||||
throw new InvalidCallParameters("users is empty");
|
throw new InvalidCallParameters("users is empty");
|
||||||
|
|
||||||
Node nodeToShare = ses.getNodeByIdentifier(id);
|
Node nodeToShare = ses.getNodeByIdentifier(id);
|
||||||
|
|
||||||
boolean alreadyShared = false;
|
boolean alreadyShared = false;
|
||||||
|
|
||||||
Node sharedFolderNode;
|
Node sharedFolderNode;
|
||||||
if (!node2Item.checkNodeType(nodeToShare, SharedFolder.class))
|
if (!node2Item.checkNodeType(nodeToShare, SharedFolder.class))
|
||||||
sharedFolderNode= shareFolder(nodeToShare, ses);
|
sharedFolderNode= shareFolder(nodeToShare, ses);
|
||||||
|
@ -108,8 +110,11 @@ public class ItemSharing {
|
||||||
}
|
}
|
||||||
ses.save();
|
ses.save();
|
||||||
|
|
||||||
ses.getWorkspace().getLockManager().lock(sharedFolderNode.getPath(), true, true, 0,login);
|
try {
|
||||||
|
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();
|
||||||
|
@ -152,12 +157,12 @@ public class ItemSharing {
|
||||||
if (ses!=null)
|
if (ses!=null)
|
||||||
ses.logout();
|
ses.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Node shareFolder(Node node, Session ses) throws RepositoryException, BackendGenericError, StorageHubException{
|
private Node shareFolder(Node node, Session ses) throws RepositoryException, BackendGenericError, StorageHubException{
|
||||||
String login = AuthorizationProvider.instance.get().getClient().getId();
|
String login = AuthorizationProvider.instance.get().getClient().getId();
|
||||||
|
|
||||||
|
@ -189,10 +194,10 @@ public class ItemSharing {
|
||||||
userPath = itemToShare.getPath();
|
userPath = itemToShare.getPath();
|
||||||
userRootWSId = itemToShare.getParentId();
|
userRootWSId = itemToShare.getParentId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log.info("cloning directory to {} ",userPath);
|
log.info("cloning directory to {} ",userPath);
|
||||||
|
|
||||||
ses.getWorkspace().clone(ses.getWorkspace().getName(), sharedFolderNode.getPath(), userPath , false);
|
ses.getWorkspace().clone(ses.getWorkspace().getName(), sharedFolderNode.getPath(), userPath , false);
|
||||||
|
|
||||||
acls.addAccessControlEntry(AccessControlUtils.getPrincipal(ses, user), userPrivileges );
|
acls.addAccessControlEntry(AccessControlUtils.getPrincipal(ses, user), userPrivileges );
|
||||||
|
@ -232,8 +237,8 @@ public class ItemSharing {
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -102,7 +103,7 @@ public class ItemsCreator {
|
||||||
|
|
||||||
@Inject Node2ItemConverter node2Item;
|
@Inject Node2ItemConverter node2Item;
|
||||||
@Inject Item2NodeConverter item2Node;
|
@Inject Item2NodeConverter item2Node;
|
||||||
|
|
||||||
|
|
||||||
//@Path("/{id}/create/{type:(?!FILE)[^/?$]*}")
|
//@Path("/{id}/create/{type:(?!FILE)[^/?$]*}")
|
||||||
@POST
|
@POST
|
||||||
|
@ -120,21 +121,25 @@ public class ItemsCreator {
|
||||||
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||||
|
|
||||||
log.info("time to connect to repo {}",(System.currentTimeMillis()-start));
|
log.info("time to connect to repo {}",(System.currentTimeMillis()-start));
|
||||||
|
|
||||||
Node destination;
|
Node destination;
|
||||||
try {
|
try {
|
||||||
destination = ses.getNodeByIdentifier(id);
|
destination = ses.getNodeByIdentifier(id);
|
||||||
}catch(ItemNotFoundException inf) {
|
}catch(ItemNotFoundException inf) {
|
||||||
throw new IdNotFoundException(id);
|
throw new IdNotFoundException(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
||||||
throw new InvalidItemException("the destination item is not a folder");
|
throw new InvalidItemException("the destination item is not a folder");
|
||||||
|
|
||||||
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);
|
||||||
|
@ -142,7 +147,7 @@ public class ItemsCreator {
|
||||||
} finally {
|
} finally {
|
||||||
ses.getWorkspace().getLockManager().unlock(destination.getPath());
|
ses.getWorkspace().getLockManager().unlock(destination.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("item with id {} correctly created",newNode.getIdentifier());
|
log.info("item with id {} correctly created",newNode.getIdentifier());
|
||||||
toReturn = newNode.getIdentifier();
|
toReturn = newNode.getIdentifier();
|
||||||
}catch(StorageHubException she ){
|
}catch(StorageHubException she ){
|
||||||
|
@ -154,7 +159,7 @@ public class ItemsCreator {
|
||||||
}finally{
|
}finally{
|
||||||
if (ses!=null)
|
if (ses!=null)
|
||||||
ses.logout();
|
ses.logout();
|
||||||
|
|
||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
@ -167,25 +172,29 @@ public class ItemsCreator {
|
||||||
log.info("create Gcube item called");
|
log.info("create Gcube item called");
|
||||||
Session ses = null;
|
Session ses = null;
|
||||||
String toReturn = null;
|
String toReturn = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
final String login = AuthorizationProvider.instance.get().getClient().getId();
|
final String login = AuthorizationProvider.instance.get().getClient().getId();
|
||||||
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||||
|
|
||||||
Node destination;
|
Node destination;
|
||||||
try {
|
try {
|
||||||
destination = ses.getNodeByIdentifier(id);
|
destination = ses.getNodeByIdentifier(id);
|
||||||
}catch(ItemNotFoundException inf) {
|
}catch(ItemNotFoundException inf) {
|
||||||
throw new IdNotFoundException(id);
|
throw new IdNotFoundException(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
||||||
throw new InvalidItemException("the destination item is not a folder");
|
throw new InvalidItemException("the destination item is not a folder");
|
||||||
|
|
||||||
authChecker.checkWriteAuthorizationControl(ses, destination.getIdentifier(), true);
|
authChecker.checkWriteAuthorizationControl(ses, destination.getIdentifier(), true);
|
||||||
|
|
||||||
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
try {
|
||||||
|
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.createGcubeItemInternally(ses, destination, item.getName(), item.getDescription(), login, item, accountingHandler);
|
newNode = Utils.createGcubeItemInternally(ses, destination, item.getName(), item.getDescription(), login, item, accountingHandler);
|
||||||
|
@ -208,7 +217,7 @@ public class ItemsCreator {
|
||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||||
|
@ -228,18 +237,18 @@ public class ItemsCreator {
|
||||||
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||||
|
|
||||||
Node destination = ses.getNodeByIdentifier(id);
|
Node destination = ses.getNodeByIdentifier(id);
|
||||||
|
|
||||||
log.info("create file called with filename {} in dir {} ", name, destination.getPath() );
|
log.info("create file called with filename {} in dir {} ", name, destination.getPath() );
|
||||||
|
|
||||||
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
||||||
throw new InvalidItemException("the destination item is not a folder");
|
throw new InvalidItemException("the destination item is not a folder");
|
||||||
|
|
||||||
|
|
||||||
log.info("session: {}",ses.toString());
|
log.info("session: {}",ses.toString());
|
||||||
|
|
||||||
Node newNode = createFileItemInternally(ses, destination, stream, name, description, login);
|
Node newNode = createFileItemInternally(ses, destination, stream, name, description, login);
|
||||||
ses.save();
|
ses.save();
|
||||||
|
|
||||||
versionHandler.checkinContentNode(newNode, ses);
|
versionHandler.checkinContentNode(newNode, ses);
|
||||||
log.info("file with id {} correctly created",newNode.getIdentifier());
|
log.info("file with id {} correctly created",newNode.getIdentifier());
|
||||||
toReturn = newNode.getIdentifier();
|
toReturn = newNode.getIdentifier();
|
||||||
|
@ -259,12 +268,12 @@ public class ItemsCreator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -275,12 +284,17 @@ public class ItemsCreator {
|
||||||
|
|
||||||
log.debug("item prepared, fulfilling content");
|
log.debug("item prepared, fulfilling content");
|
||||||
log.debug("content prepared");
|
log.debug("content prepared");
|
||||||
|
|
||||||
Node newNode;
|
Node newNode;
|
||||||
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);
|
||||||
ses.getWorkspace().getLockManager().lock(newNode.getPath(), true, true, 0,login);
|
try {
|
||||||
|
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);
|
||||||
ses.getWorkspace().getLockManager().lock(destinationNode.getPath(), false, true, 0,login);
|
try {
|
||||||
|
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 {
|
||||||
|
@ -300,11 +318,11 @@ public class ItemsCreator {
|
||||||
versionHandler.makeVersionableContent(newNode, ses);
|
versionHandler.makeVersionableContent(newNode, ses);
|
||||||
accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), item.getContent().getMimeType(), ses, newNode, false);
|
accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), item.getContent().getMimeType(), ses, newNode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||||
|
@ -324,77 +342,78 @@ public class ItemsCreator {
|
||||||
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||||
|
|
||||||
Node destination = ses.getNodeByIdentifier(id);
|
Node destination = ses.getNodeByIdentifier(id);
|
||||||
|
|
||||||
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
||||||
throw new InvalidItemException("the destination item is not a folder");
|
throw new InvalidItemException("the destination item is not a folder");
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
Set<Node> fileNodes = new HashSet<>();
|
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<>();
|
||||||
|
|
||||||
|
|
||||||
HashMap<String, Node> directoryNodeMap = new HashMap<>();
|
HashMap<String, Node> directoryNodeMap = new HashMap<>();
|
||||||
|
|
||||||
try (ArchiveInputStream input = new ArchiveStreamFactory()
|
try (ArchiveInputStream input = new ArchiveStreamFactory()
|
||||||
.createArchiveInputStream(new BufferedInputStream(stream, 1024*64))){
|
.createArchiveInputStream(new BufferedInputStream(stream, 1024*64))){
|
||||||
ArchiveEntry entry;
|
ArchiveEntry entry;
|
||||||
while ((entry = input.getNextEntry()) != null) {
|
while ((entry = input.getNextEntry()) != null) {
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
|
String entirePath = entry.getName();
|
||||||
|
String name = entirePath.replaceAll("(.*/)*(.*)/", "$2");
|
||||||
|
String parentPath = entirePath.replaceAll("(.*/)*(.*)/", "$1");
|
||||||
|
log.debug("creating directory with entire path {}, name {}, parentPath {} ", entirePath, name, parentPath);
|
||||||
|
Node createdNode;
|
||||||
|
if (parentPath.isEmpty()) {
|
||||||
|
createdNode = Utils.createFolderInternally(ses, parentDirectoryNode, name, "", false, login, accountingHandler);
|
||||||
|
}else {
|
||||||
|
Node parentNode = directoryNodeMap.get(parentPath);
|
||||||
|
createdNode = Utils.createFolderInternally(ses, parentNode, name, "", false, login, accountingHandler);
|
||||||
|
}
|
||||||
|
directoryNodeMap.put(entirePath, createdNode);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
String entirePath = entry.getName();
|
String entirePath = entry.getName();
|
||||||
String name = entirePath.replaceAll("(.*/)*(.*)/", "$2");
|
String name = entirePath.replaceAll("(.*/)*(.*)", "$2");
|
||||||
String parentPath = entirePath.replaceAll("(.*/)*(.*)/", "$1");
|
String parentPath = entirePath.replaceAll("(.*/)*(.*)", "$1");
|
||||||
log.debug("creating directory with entire path {}, name {}, parentPath {} ", entirePath, name, parentPath);
|
log.debug("creating file with entire path {}, name {}, parentPath {} ", entirePath, name, parentPath);
|
||||||
Node createdNode;
|
Node fileNode = null;
|
||||||
if (parentPath.isEmpty()) {
|
if (parentPath.isEmpty())
|
||||||
createdNode = Utils.createFolderInternally(ses, parentDirectoryNode, name, "", false, login, accountingHandler);
|
fileNode = createFileItemInternally(ses, parentDirectoryNode, input, name, "", login);
|
||||||
}else {
|
else {
|
||||||
Node parentNode = directoryNodeMap.get(parentPath);
|
Node parentNode = directoryNodeMap.get(parentPath);
|
||||||
createdNode = Utils.createFolderInternally(ses, parentNode, name, "", false, login, accountingHandler);
|
fileNode = createFileItemInternally(ses, parentNode, input, name, "", login);
|
||||||
}
|
|
||||||
directoryNodeMap.put(entirePath, createdNode);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
String entirePath = entry.getName();
|
|
||||||
String name = entirePath.replaceAll("(.*/)*(.*)", "$2");
|
|
||||||
String parentPath = entirePath.replaceAll("(.*/)*(.*)", "$1");
|
|
||||||
log.debug("creating file with entire path {}, name {}, parentPath {} ", entirePath, name, parentPath);
|
|
||||||
Node fileNode = null;
|
|
||||||
if (parentPath.isEmpty())
|
|
||||||
fileNode = createFileItemInternally(ses, parentDirectoryNode, input, name, "", login);
|
|
||||||
else {
|
|
||||||
Node parentNode = directoryNodeMap.get(parentPath);
|
|
||||||
fileNode = createFileItemInternally(ses, parentNode, input, name, "", login);
|
|
||||||
}
|
|
||||||
fileNodes.add(fileNode);
|
|
||||||
}catch(Exception e) {
|
|
||||||
log.warn("error getting file {}",entry.getName(),e);
|
|
||||||
}
|
}
|
||||||
|
fileNodes.add(fileNode);
|
||||||
|
}catch(Exception e) {
|
||||||
|
log.warn("error getting file {}",entry.getName(),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ses.save();
|
|
||||||
for (Node node : fileNodes)
|
|
||||||
versionHandler.checkinContentNode(node, ses);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ses.save();
|
||||||
|
for (Node node : fileNodes)
|
||||||
|
versionHandler.checkinContentNode(node, ses);
|
||||||
|
toReturn = parentDirectoryNode.getIdentifier();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}catch(RepositoryException | ArchiveException | IOException re){
|
}catch(RepositoryException | ArchiveException | IOException re){
|
||||||
log.error("jcr error extracting archive", re);
|
log.error("jcr error extracting archive", re);
|
||||||
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error extracting archive", re));
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error extracting archive", re));
|
||||||
|
@ -412,7 +431,7 @@ public class ItemsCreator {
|
||||||
|
|
||||||
private ContentHandler getContentHandler(InputStream stream , String name, String path, String login) throws BackendGenericError {
|
private ContentHandler getContentHandler(InputStream stream , String name, String path, String login) throws BackendGenericError {
|
||||||
|
|
||||||
|
|
||||||
final MultipleOutputStream mos;
|
final MultipleOutputStream mos;
|
||||||
try{
|
try{
|
||||||
mos = new MultipleOutputStream(stream, 2);
|
mos = new MultipleOutputStream(stream, 2);
|
||||||
|
@ -489,7 +508,7 @@ public class ItemsCreator {
|
||||||
try {
|
try {
|
||||||
mos.startWriting();
|
mos.startWriting();
|
||||||
log.debug("TIMING: writing the stream - finished in {}",System.currentTimeMillis()-start);
|
log.debug("TIMING: writing the stream - finished in {}",System.currentTimeMillis()-start);
|
||||||
|
|
||||||
ContentHandler handler = detectorF.get();
|
ContentHandler handler = detectorF.get();
|
||||||
MetaInfo info = uploaderF.get();
|
MetaInfo info = uploaderF.get();
|
||||||
handler.getContent().setData(NodeConstants.CONTENT_NAME);
|
handler.getContent().setData(NodeConstants.CONTENT_NAME);
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -156,7 +158,7 @@ public class ItemsManager {
|
||||||
try{
|
try{
|
||||||
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||||
authChecker.checkReadAuthorizationControl(ses, id);
|
authChecker.checkReadAuthorizationControl(ses, id);
|
||||||
|
|
||||||
//NOT using the internal pattern matching of jcr because of title for shared folder
|
//NOT using the internal pattern matching of jcr because of title for shared folder
|
||||||
NodeIterator it = ses.getNodeByIdentifier(id).getNodes();
|
NodeIterator it = ses.getNodeByIdentifier(id).getNodes();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
|
@ -164,11 +166,11 @@ public class ItemsManager {
|
||||||
String nodeName = child.getName();
|
String nodeName = child.getName();
|
||||||
if (!child.hasProperty(NodeProperty.TITLE.toString())) continue;
|
if (!child.hasProperty(NodeProperty.TITLE.toString())) continue;
|
||||||
String title = child.getProperty(NodeProperty.TITLE.toString()).getString();
|
String title = child.getProperty(NodeProperty.TITLE.toString()).getString();
|
||||||
|
|
||||||
String cleanedName = name;
|
String cleanedName = name;
|
||||||
if (name.startsWith("*")) cleanedName = name.substring(1);
|
if (name.startsWith("*")) cleanedName = name.substring(1);
|
||||||
if (name.endsWith("*")) cleanedName = name.substring(0, name.length()-1);
|
if (name.endsWith("*")) cleanedName = name.substring(0, name.length()-1);
|
||||||
|
|
||||||
if ((name.startsWith("*") && (nodeName.endsWith(cleanedName) || title.endsWith(cleanedName))) || (name.endsWith("*") && (nodeName.startsWith(cleanedName) || title.startsWith(cleanedName)))
|
if ((name.startsWith("*") && (nodeName.endsWith(cleanedName) || title.endsWith(cleanedName))) || (name.endsWith("*") && (nodeName.startsWith(cleanedName) || title.startsWith(cleanedName)))
|
||||||
|| (nodeName.equals(cleanedName) || title.equals(cleanedName)))
|
|| (nodeName.equals(cleanedName) || title.equals(cleanedName)))
|
||||||
toReturn.add(node2Item.getItem(child, excludes));
|
toReturn.add(node2Item.getItem(child, excludes));
|
||||||
|
@ -280,7 +282,7 @@ public class ItemsManager {
|
||||||
@AuthorizationControl(allowed={"URIResolver"}, exception=MyAuthException.class)
|
@AuthorizationControl(allowed={"URIResolver"}, exception=MyAuthException.class)
|
||||||
public Response resolvePublicLink() {
|
public Response resolvePublicLink() {
|
||||||
InnerMethodName.instance.set("resolvePubliclink");
|
InnerMethodName.instance.set("resolvePubliclink");
|
||||||
|
|
||||||
log.warn("arrived id is {}",id);
|
log.warn("arrived id is {}",id);
|
||||||
Session ses = null;
|
Session ses = null;
|
||||||
try{
|
try{
|
||||||
|
@ -306,30 +308,30 @@ public class ItemsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String itemId = complexId;
|
String itemId = complexId;
|
||||||
String versionName = null;
|
String versionName = null;
|
||||||
|
|
||||||
if (complexId.contains(versionPrefix)) {
|
if (complexId.contains(versionPrefix)) {
|
||||||
String[] split = complexId.split(versionPrefix);
|
String[] split = complexId.split(versionPrefix);
|
||||||
itemId = split[0];
|
itemId = split[0];
|
||||||
versionName = split[1];
|
versionName = split[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
log.warn("item id to retrieve is {}",itemId);
|
log.warn("item id to retrieve is {}",itemId);
|
||||||
|
|
||||||
Node selectedNode = ses.getNodeByIdentifier(itemId);
|
Node selectedNode = ses.getNodeByIdentifier(itemId);
|
||||||
|
|
||||||
Item item = node2Item.getItem(selectedNode, Arrays.asList(NodeConstants.ACCOUNTING_NAME, NodeConstants.METADATA_NAME));
|
Item item = node2Item.getItem(selectedNode, Arrays.asList(NodeConstants.ACCOUNTING_NAME, NodeConstants.METADATA_NAME));
|
||||||
|
|
||||||
if (!(item instanceof AbstractFileItem)) throw new InvalidCallParameters("the choosen item is not a File");
|
if (!(item instanceof AbstractFileItem)) throw new InvalidCallParameters("the choosen item is not a File");
|
||||||
|
|
||||||
if (versionName!=null)
|
if (versionName!=null)
|
||||||
return downloadVersionInternal(ses, login, itemId, versionName, false);
|
return downloadVersionInternal(ses, login, itemId, versionName, false);
|
||||||
else
|
else
|
||||||
return downloadFileInternal(ses, (AbstractFileItem) item, login, true);
|
return downloadFileInternal(ses, (AbstractFileItem) item, login, true);
|
||||||
|
|
||||||
|
|
||||||
}catch(RepositoryException re ){
|
}catch(RepositoryException re ){
|
||||||
log.error("jcr error getting public link", re);
|
log.error("jcr error getting public link", re);
|
||||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||||
|
@ -490,7 +492,7 @@ public class ItemsManager {
|
||||||
|
|
||||||
for (Version version: jcrVersions) {
|
for (Version version: jcrVersions) {
|
||||||
boolean currentVersion = ((AbstractFileItem)currentItem).getContent().getStorageId().equals(version.getFrozenNode().getProperty(NodeProperty.STORAGE_ID.toString()).getString());
|
boolean currentVersion = ((AbstractFileItem)currentItem).getContent().getStorageId().equals(version.getFrozenNode().getProperty(NodeProperty.STORAGE_ID.toString()).getString());
|
||||||
|
|
||||||
versions.add(new org.gcube.common.storagehub.model.service.Version(version.getIdentifier(), version.getName(), version.getCreated(), currentVersion));
|
versions.add(new org.gcube.common.storagehub.model.service.Version(version.getIdentifier(), version.getName(), version.getCreated(), currentVersion));
|
||||||
}
|
}
|
||||||
}catch(RepositoryException re ){
|
}catch(RepositoryException re ){
|
||||||
|
@ -517,7 +519,7 @@ public class ItemsManager {
|
||||||
authChecker.checkReadAuthorizationControl(ses, id);
|
authChecker.checkReadAuthorizationControl(ses, id);
|
||||||
|
|
||||||
return downloadVersionInternal(ses, login, id, versionName, true);
|
return downloadVersionInternal(ses, login, id, versionName, true);
|
||||||
|
|
||||||
}catch(RepositoryException re ){
|
}catch(RepositoryException re ){
|
||||||
log.error("jcr error downloading version", re);
|
log.error("jcr error downloading version", re);
|
||||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||||
|
@ -568,7 +570,7 @@ public class ItemsManager {
|
||||||
}
|
}
|
||||||
throw new InvalidItemException("the version is not valid");
|
throw new InvalidItemException("the version is not valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}/anchestors")
|
@Path("{id}/anchestors")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@ -663,7 +665,7 @@ public class ItemsManager {
|
||||||
.header("Content-Type", "application/zip")
|
.header("Content-Type", "application/zip")
|
||||||
.header("Content-Length", -1l)
|
.header("Content-Length", -1l)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
accountingHandler.createReadObj(item.getTitle(), ses, ses.getNodeByIdentifier(item.getId()), false);
|
accountingHandler.createReadObj(item.getTitle(), ses, ses.getNodeByIdentifier(item.getId()), false);
|
||||||
}finally {
|
}finally {
|
||||||
if (ses!=null) ses.save();
|
if (ses!=null) ses.save();
|
||||||
|
@ -682,9 +684,9 @@ public class ItemsManager {
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response downloadFileInternal(Session ses, AbstractFileItem fileItem, String login, boolean withAccounting) throws RepositoryException {
|
private Response downloadFileInternal(Session ses, AbstractFileItem fileItem, String login, boolean withAccounting) throws RepositoryException {
|
||||||
|
|
||||||
final InputStream streamToWrite = Utils.getStorageClient(login).getClient().get().RFileAsInputStream(fileItem.getContent().getStorageId());
|
final InputStream streamToWrite = Utils.getStorageClient(login).getClient().get().RFileAsInputStream(fileItem.getContent().getStorageId());
|
||||||
|
|
||||||
if (withAccounting)
|
if (withAccounting)
|
||||||
|
@ -700,7 +702,7 @@ public class ItemsManager {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}/move")
|
@Path("{id}/move")
|
||||||
|
@ -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");
|
||||||
|
|
||||||
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, true, 0,login);
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(nodeToMove.getPath(), true, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(destination.getPath(), false, 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");
|
||||||
|
|
||||||
|
|
||||||
ses.getWorkspace().getLockManager().lock(nodeToMove.getPath(), true, true, 0,login);
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(nodeToMove.getParent().getPath(), false, true, 0,login);
|
ses.getWorkspace().getLockManager().lock(nodeToMove.getPath(), true, 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