diff --git a/.classpath b/.classpath index 84af7c2..3bdd95d 100644 --- a/.classpath +++ b/.classpath @@ -8,9 +8,9 @@ + - @@ -36,8 +36,8 @@ - + diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index 65d796e..2a6bd5b 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -121,7 +121,6 @@ import org.gcube.portlets.user.workspace.client.view.windows.DialogAddUrl; import org.gcube.portlets.user.workspace.client.view.windows.DialogGetInfo; import org.gcube.portlets.user.workspace.client.view.windows.DialogGetLink; import org.gcube.portlets.user.workspace.client.view.windows.DialogGetLink.Link_Type; -import org.gcube.portlets.user.workspace.client.view.windows.DialogInfoboot; import org.gcube.portlets.user.workspace.client.view.windows.DialogShareLink; import org.gcube.portlets.user.workspace.client.view.windows.DialogShareableLink; import org.gcube.portlets.user.workspace.client.view.windows.DialogText; diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java index 39194fb..7ea5780 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java @@ -492,18 +492,17 @@ public interface GWTWorkspaceService extends RemoteService { */ TrashContent updateTrashContent(WorkspaceTrashOperation operation) throws Exception; + /** * 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 */ - TrashOperationContent executeOperationOnTrash(List listTrashItemIds, List destinationFolderIds, + TrashOperationContent executeOperationOnTrash(List listTrashItemIds, String destinationFolderId, WorkspaceTrashOperation operation) throws Exception; diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java index 1d87aae..f040300 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java @@ -453,15 +453,16 @@ public interface GWTWorkspaceServiceAsync { void updateTrashContent(WorkspaceTrashOperation operation, AsyncCallback callback); + /** * Execute operation on trash. * * @param listTrashItemIds the list trash item ids - * @param destinationFolderIds the destination folder ids + * @param destinationFolderId the destination folder id * @param operation the operation * @param callback the callback */ - void executeOperationOnTrash(List listTrashItemIds, List destinationFolderIds, WorkspaceTrashOperation operation, + void executeOperationOnTrash(List listTrashItemIds, String destinationFolderId, WorkspaceTrashOperation operation, AsyncCallback callback); /** diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index 0236413..03e03d4 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -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 listTrashItemIds, List destinationFolderIds, + public TrashOperationContent executeOperationOnTrash(List 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 listContentError = new ArrayList(); + List listOperationError = new ArrayList(); 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() */ diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/TrashContent.java b/src/main/java/org/gcube/portlets/user/workspace/shared/TrashContent.java index ac3543e..33b3884 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/shared/TrashContent.java +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/TrashContent.java @@ -20,27 +20,16 @@ public class TrashContent implements Serializable{ List trashContent; - List listErrors; + List listErrors; public TrashContent() { } - public TrashContent(List trashContent, List listErrors) { + public TrashContent(List trashContent, List listErrors) { this.trashContent = trashContent; this.listErrors = listErrors; } - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("TrashOperationResult [trashContent="); - builder.append(trashContent); - builder.append(", listErrors="); - builder.append(listErrors); - builder.append("]"); - return builder.toString(); - } - public List getTrashContent() { return trashContent; } @@ -49,11 +38,18 @@ public class TrashContent implements Serializable{ this.trashContent = trashContent; } - public List getListErrors() { + public List getListErrors() { return listErrors; } - public void setListErrors(List listErrors) { + public void setListErrors(List listErrors) { this.listErrors = listErrors; } + + @Override + public String toString() { + return "TrashContent [trashContent=" + trashContent + ", listErrors=" + listErrors + "]"; + } + + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/TrashOperationError.java b/src/main/java/org/gcube/portlets/user/workspace/shared/TrashOperationError.java new file mode 100644 index 0000000..41dfdac --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/TrashOperationError.java @@ -0,0 +1,66 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.shared; + +import java.io.Serializable; + +import org.gcube.portlets.user.workspace.client.model.FileTrashedModel; + +/** + * The Class TrashOperationContent. + * + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) May 18, 2020 + */ +public class TrashOperationError implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -5792786687183945714L; + private FileTrashedModel trashedFile; + private WorkspaceTrashOperation operation; + private String erroMsg; + + public TrashOperationError() { + + } + + public TrashOperationError(FileTrashedModel trashedFile, WorkspaceTrashOperation operation, String erroMsg) { + super(); + this.trashedFile = trashedFile; + this.operation = operation; + this.erroMsg = erroMsg; + } + + public FileTrashedModel getTrashedFile() { + return trashedFile; + } + + public void setTrashedFile(FileTrashedModel trashedFile) { + this.trashedFile = trashedFile; + } + + public WorkspaceTrashOperation getOperation() { + return operation; + } + + public void setOperation(WorkspaceTrashOperation operation) { + this.operation = operation; + } + + public String getErroMsg() { + return erroMsg; + } + + public void setErroMsg(String erroMsg) { + this.erroMsg = erroMsg; + } + + @Override + public String toString() { + return "TrashOperationError [trashedFile=" + trashedFile + ", operation=" + operation + ", erroMsg=" + erroMsg + + "]"; + } + +}