#19058 revisited restore operation on trashed files

This commit is contained in:
Francesco Mangiacrapa 2020-05-19 17:22:22 +02:00
parent 1bac6d28a2
commit ead1e4dd8d
7 changed files with 199 additions and 76 deletions

View File

@ -8,9 +8,9 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
@ -36,8 +36,8 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

View File

@ -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;

View File

@ -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<String> listTrashItemIds, List<String> destinationFolderIds,
TrashOperationContent executeOperationOnTrash(List<String> listTrashItemIds, String destinationFolderId,
WorkspaceTrashOperation operation) throws Exception;

View File

@ -453,15 +453,16 @@ public interface GWTWorkspaceServiceAsync {
void updateTrashContent(WorkspaceTrashOperation operation, AsyncCallback<TrashContent> 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<String> listTrashItemIds, List<String> destinationFolderIds, WorkspaceTrashOperation operation,
void executeOperationOnTrash(List<String> listTrashItemIds, String destinationFolderId, WorkspaceTrashOperation operation,
AsyncCallback<TrashOperationContent> callback);
/**

View File

@ -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()
*/

View File

@ -20,27 +20,16 @@ public class TrashContent implements Serializable{
List<FileTrashedModel> trashContent;
List<FileTrashedModel> listErrors;
List<TrashOperationError> listErrors;
public TrashContent() {
}
public TrashContent(List<FileTrashedModel> trashContent, List<FileTrashedModel> listErrors) {
public TrashContent(List<FileTrashedModel> trashContent, List<TrashOperationError> 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<FileTrashedModel> getTrashContent() {
return trashContent;
}
@ -49,11 +38,18 @@ public class TrashContent implements Serializable{
this.trashContent = trashContent;
}
public List<FileTrashedModel> getListErrors() {
public List<TrashOperationError> getListErrors() {
return listErrors;
}
public void setListErrors(List<FileTrashedModel> listErrors) {
public void setListErrors(List<TrashOperationError> listErrors) {
this.listErrors = listErrors;
}
@Override
public String toString() {
return "TrashContent [trashContent=" + trashContent + ", listErrors=" + listErrors + "]";
}
}

View File

@ -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
+ "]";
}
}