|
|
|
@ -64,6 +64,7 @@ import org.gcube.portlets.user.workspace.shared.SHUBOperationNotAllowedException
|
|
|
|
|
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
|
|
|
|
|
import org.gcube.portlets.user.workspace.shared.TrashContent;
|
|
|
|
|
import org.gcube.portlets.user.workspace.shared.TrashOperationContent;
|
|
|
|
|
import org.gcube.portlets.user.workspace.shared.TrashOperationError;
|
|
|
|
|
import org.gcube.portlets.user.workspace.shared.UserBean;
|
|
|
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceOperationResult;
|
|
|
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
|
|
|
|
@ -86,11 +87,11 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Auto-generated Javadoc
|
|
|
|
|
/**
|
|
|
|
|
* The Class GWTWorkspaceServiceImpl.
|
|
|
|
|
*
|
|
|
|
@ -926,26 +927,18 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#
|
|
|
|
|
* executeOperationOnTrash(java.util.List,
|
|
|
|
|
* org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute operation on trash.
|
|
|
|
|
*
|
|
|
|
|
* @param listTrashItemIds
|
|
|
|
|
* the list trash item ids
|
|
|
|
|
* @param operation
|
|
|
|
|
* the operation
|
|
|
|
|
* @param listTrashItemIds the list trash item ids
|
|
|
|
|
* @param destinationFolderId the destination folder id
|
|
|
|
|
* @param operation the operation
|
|
|
|
|
* @return the trash operation content
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* the exception
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public TrashOperationContent executeOperationOnTrash(List<String> listTrashItemIds, List<String> destinationFolderIds,
|
|
|
|
|
public TrashOperationContent executeOperationOnTrash(List<String> listTrashItemIds, String destinationFolderId,
|
|
|
|
|
WorkspaceTrashOperation operation) throws Exception {
|
|
|
|
|
|
|
|
|
|
workspaceLogger.info("Get TrashContent, operation: " + operation);
|
|
|
|
@ -953,7 +946,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
if (listTrashItemIds == null || listTrashItemIds.size() == 0)
|
|
|
|
|
throw new Exception("List of Trash item ids is null or empty");
|
|
|
|
|
|
|
|
|
|
List<FileTrashedModel> listContentError = new ArrayList<FileTrashedModel>();
|
|
|
|
|
List<TrashOperationError> listOperationError = new ArrayList<TrashOperationError>();
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace = getWorkspaceFromStorageHub();
|
|
|
|
@ -968,67 +961,70 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
|
|
|
|
|
case DELETE_PERMANENTLY: {
|
|
|
|
|
|
|
|
|
|
boolean deleted = false;
|
|
|
|
|
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem trashedItem = null;
|
|
|
|
|
for (String trashItemId : listTrashItemIds) {
|
|
|
|
|
try {
|
|
|
|
|
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem trashedItem = workspace
|
|
|
|
|
trashedItem = workspace
|
|
|
|
|
.getItem(trashItemId);
|
|
|
|
|
if (trashedItem != null && trashedItem.isTrashed()) {
|
|
|
|
|
workspace.deleteItem(trashedItem.getId());
|
|
|
|
|
listUpdatedTrashIds.add(trashItemId);
|
|
|
|
|
deleted = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
workspaceLogger.warn("Error on DELETE_PERMANENTLY the item : " + trashItemId, e);
|
|
|
|
|
|
|
|
|
|
workspaceLogger.warn("Error occurred on "+WorkspaceTrashOperation.DELETE_PERMANENTLY+" the item : " + trashItemId, e);
|
|
|
|
|
FileTrashedModel fakeFile = new FileTrashedModel();
|
|
|
|
|
fakeFile.setIdentifier(trashItemId);
|
|
|
|
|
listContentError.add(fakeFile);
|
|
|
|
|
String itemName = trashedItem!=null?trashedItem.getName():"item";
|
|
|
|
|
fakeFile.setName(itemName);
|
|
|
|
|
String itemRefMsg = trashedItem.isFolder()?"folder":"file";
|
|
|
|
|
itemRefMsg+=" '"+itemName+"'";
|
|
|
|
|
String errorMsg = "Error occurred on deleting permanently the "+itemRefMsg;
|
|
|
|
|
if(e instanceof UserNotAuthorizedException) {
|
|
|
|
|
errorMsg = String.format("Insufficent privileges for you to delete permanently the %s", itemRefMsg);
|
|
|
|
|
}
|
|
|
|
|
TrashOperationError error = new TrashOperationError(fakeFile,WorkspaceTrashOperation.DELETE_PERMANENTLY,errorMsg);
|
|
|
|
|
listOperationError.add(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String label = listTrashItemIds.size() > 1 ? "items" : "item";
|
|
|
|
|
if (!deleted)
|
|
|
|
|
throw new Exception(
|
|
|
|
|
"Sorry, an error occurred on deleting permanently the trash " + label + ", try again");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case RESTORE: {
|
|
|
|
|
|
|
|
|
|
if(destinationFolderId==null)
|
|
|
|
|
throw new Exception("Wrong call, the destionFolderId is null");
|
|
|
|
|
|
|
|
|
|
boolean restored = false;
|
|
|
|
|
int index = 0;
|
|
|
|
|
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem trashedItem = null;
|
|
|
|
|
for (String trashItemId : listTrashItemIds) {
|
|
|
|
|
try {
|
|
|
|
|
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem trashedItem = workspace
|
|
|
|
|
.getItem(trashItemId);
|
|
|
|
|
trashedItem = workspace.getItem(trashItemId);
|
|
|
|
|
if (trashedItem != null && trashedItem.isTrashed()) {
|
|
|
|
|
String destFolderId = null;
|
|
|
|
|
try {
|
|
|
|
|
destFolderId = destinationFolderIds!=null && destinationFolderIds.get(index)!=null?destinationFolderIds.get(index):null;
|
|
|
|
|
}catch (IndexOutOfBoundsException e) {
|
|
|
|
|
workspaceLogger.debug("No destination folder Id at index: "+index);
|
|
|
|
|
}
|
|
|
|
|
String destFolderId = destinationFolderId;
|
|
|
|
|
workspaceLogger.info("Trying to restore the item id: "+trashedItem.getId()+", in the folder id: "+destFolderId);
|
|
|
|
|
workspace.restoreThrashItem(trashedItem.getId(), destFolderId);
|
|
|
|
|
listUpdatedTrashIds.add(trashItemId);
|
|
|
|
|
restored = true;
|
|
|
|
|
//restored = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
workspaceLogger.warn("Error on RESTORE the item : " + trashItemId, e);
|
|
|
|
|
|
|
|
|
|
workspaceLogger.warn("Error occurred on "+WorkspaceTrashOperation.RESTORE+" the item : " + trashItemId, e);
|
|
|
|
|
FileTrashedModel fakeFile = new FileTrashedModel();
|
|
|
|
|
fakeFile.setIdentifier(trashItemId);
|
|
|
|
|
listContentError.add(fakeFile);
|
|
|
|
|
String itemName = trashedItem!=null?trashedItem.getName():trashItemId;
|
|
|
|
|
fakeFile.setName(itemName);
|
|
|
|
|
String itemRefMsg = trashedItem.isFolder()?"folder":"file";
|
|
|
|
|
itemRefMsg+=" '"+itemName+"'";
|
|
|
|
|
String errorMsg = "Error occurred on restoring the "+itemRefMsg;
|
|
|
|
|
if(e instanceof UserNotAuthorizedException) {
|
|
|
|
|
errorMsg = String.format("Insufficent privileges for you to restore the %s in the selected folder", itemRefMsg);
|
|
|
|
|
}
|
|
|
|
|
TrashOperationError error = new TrashOperationError(fakeFile,WorkspaceTrashOperation.RESTORE,errorMsg);
|
|
|
|
|
listOperationError.add(error);
|
|
|
|
|
}
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
String label = listTrashItemIds.size() > 1 ? "items" : "item";
|
|
|
|
|
|
|
|
|
|
if (!restored)
|
|
|
|
|
throw new Exception("Sorry, an error occurred on restoring the trash " + label + ", try again");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1036,8 +1032,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!listContentError.isEmpty()) {
|
|
|
|
|
result.setListErrors(listContentError);
|
|
|
|
|
if (!listOperationError.isEmpty()) {
|
|
|
|
|
result.setListErrors(listOperationError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.setListTrashIds(listUpdatedTrashIds);
|
|
|
|
@ -1045,7 +1041,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
workspaceLogger.error("Error in server executeOperationOnTrash", e);
|
|
|
|
|
workspaceLogger.error("Error occured on performing trash operation", e);
|
|
|
|
|
String error = ConstantsExplorer.SERVER_ERROR + " updating the trash content. " + e.getMessage();
|
|
|
|
|
throw new Exception(error);
|
|
|
|
|
}
|
|
|
|
@ -1663,6 +1659,15 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the public link for file item id to version.
|
|
|
|
|
*
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @param version the version
|
|
|
|
|
* @param shortenUrl the shorten url
|
|
|
|
|
* @return the public link for file item id to version
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* (non-Javadoc)
|
|
|
|
|
*
|
|
|
|
@ -1875,6 +1880,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the item for file grid.
|
|
|
|
|
*
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @return the item for file grid
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemForFileGrid(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
@ -1906,6 +1918,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the item for file tree.
|
|
|
|
|
*
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @return the item for file tree
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemForFileTree(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
@ -1937,6 +1956,15 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the image by id.
|
|
|
|
|
*
|
|
|
|
|
* @param identifier the identifier
|
|
|
|
|
* @param isInteralImage the is interal image
|
|
|
|
|
* @param fullDetails the full details
|
|
|
|
|
* @return the image by id
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getImageById(java.lang.String, boolean, boolean)
|
|
|
|
|
*/
|
|
|
|
@ -2043,6 +2071,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the item creation date by id.
|
|
|
|
|
*
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @return the item creation date by id
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemCreationDateById(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
@ -2121,6 +2156,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load last modification date by id.
|
|
|
|
|
*
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @return the date
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#loadLastModificationDateById(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
@ -2153,6 +2195,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getParentByItemId(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* Gets the parent by item id.
|
|
|
|
|
*
|
|
|
|
|
* @param identifier the identifier
|
|
|
|
|
* @return the parent by item id
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
//TODO NEED TO TEST IT
|
|
|
|
|
@Override
|
|
|
|
|
public FileModel getParentByItemId(String identifier) throws Exception {
|
|
|
|
@ -2253,6 +2302,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the item description by id.
|
|
|
|
|
*
|
|
|
|
|
* @param identifier the identifier
|
|
|
|
|
* @return the item description by id
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemDescriptionById(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
@ -2280,6 +2336,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the user workspace size.
|
|
|
|
|
*
|
|
|
|
|
* @return the user workspace size
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getUserWorkspaceSize()
|
|
|
|
|
*/
|
|
|
|
|