enhancements on trash

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@95583 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-05-13 09:10:54 +00:00
parent e7fd2b7a75
commit d6e721ea4e
10 changed files with 264 additions and 127 deletions

View File

@ -135,6 +135,7 @@ import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExterna
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTImageDocument;
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTUrlDocument;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEvent;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEventHandler;

View File

@ -249,7 +249,7 @@ public class FileModel extends BaseModelData implements Serializable {
}
private void setIsDirectory(boolean flag){
public void setIsDirectory(boolean flag){
set(ConstantsExplorer.ISDIRECTORY, flag);
}

View File

@ -3,7 +3,9 @@ package org.gcube.portlets.user.workspace.client.model;
import java.util.Date;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @May 12, 2014
*
*/
public class FileTrashedModel extends FileGridModel {
@ -16,7 +18,7 @@ public class FileTrashedModel extends FileGridModel {
private String orginalPath;
private Date deleteDate;
private InfoContactModel deleteUser;
private InfoContactModel deletedBy;
public static enum STOREINFO {ORIGINALPATH, DELETEDATE, DELETEUSER}
@ -46,12 +48,11 @@ public class FileTrashedModel extends FileGridModel {
* @param deleteDate
* @param deleteUser
*/
public FileTrashedModel(String orginalPath, Date deleteDate,
InfoContactModel deleteUser) {
public FileTrashedModel(String orginalPath, Date deleteDate, InfoContactModel deleteUser) {
super();
this.orginalPath = orginalPath;
this.deleteDate = deleteDate;
this.deleteUser = deleteUser;
this.deletedBy = deleteUser;
}
@ -69,47 +70,34 @@ public class FileTrashedModel extends FileGridModel {
super(identifier, name, creationDate, parent, size, isDirectory, isShared);
}
public String getOrginalPath() {
return orginalPath;
}
public Date getDeleteDate() {
return deleteDate;
}
public InfoContactModel getDeleteUser() {
return deleteUser;
return deletedBy;
}
public void setOrginalPath(String orginalPath) {
set(STOREINFO.ORIGINALPATH.toString(), orginalPath);
this.orginalPath = orginalPath;
}
public void setDeleteDate(Date deleteDate) {
set(STOREINFO.DELETEDATE.toString(), deleteDate);
this.deleteDate = deleteDate;
}
public void setDeleteUser(InfoContactModel deleteUser) {
set(STOREINFO.DELETEUSER.toString(), deleteUser);
this.deleteUser = deleteUser;
this.deletedBy = deleteUser;
set(STOREINFO.DELETEUSER.toString(), deleteUser.getName());
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -118,61 +106,13 @@ public class FileTrashedModel extends FileGridModel {
builder.append(", deleteDate=");
builder.append(deleteDate);
builder.append(", deleteUser=");
builder.append(deleteUser);
builder.append(", getSize()=");
builder.append(getSize());
builder.append(", getLastModification()=");
builder.append(getLastModification());
builder.append(", getDescription()=");
builder.append(getDescription());
builder.append(", isShareable()=");
builder.append(isShareable());
builder.append(", isMarkAsRead()=");
builder.append(isMarkAsRead());
builder.append(", getOwner()=");
builder.append(getOwner());
builder.append(", getOwnerFullName()=");
builder.append(getOwnerFullName());
builder.append(", getListUserSharing()=");
builder.append(getListUserSharing());
builder.append(", isShared()=");
builder.append(isShared());
builder.append(", isRoot()=");
builder.append(isRoot());
builder.append(", getIcon()=");
builder.append(getIcon());
builder.append(", getAbstractPrototypeIcon()=");
builder.append(getAbstractPrototypeIcon());
builder.append(", getStatus()=");
builder.append(getStatus());
builder.append(", getIdentifier()=");
builder.append(getIdentifier());
builder.append(", getShortcutCategory()=");
builder.append(getShortcutCategory());
builder.append(deletedBy);
builder.append(", getName()=");
builder.append(getName());
builder.append(", getParentFileModel()=");
builder.append(getParentFileModel());
builder.append(", isDirectory()=");
builder.append(isDirectory());
builder.append(", getType()=");
builder.append(getType());
builder.append(", getGXTFolderItemType()=");
builder.append(getGXTFolderItemType());
builder.append(", isVreFolder()=");
builder.append(isVreFolder());
builder.append(", toString()=");
builder.append(super.toString());
builder.append(", getProperties()=");
builder.append(getProperties());
builder.append(", getPropertyNames()=");
builder.append(getPropertyNames());
builder.append(", isAllowNestedValues()=");
builder.append(isAllowNestedValues());
builder.append(", getClass()=");
builder.append(getClass());
builder.append(", hashCode()=");
builder.append(hashCode());
builder.append("]");
return builder.toString();
}

View File

@ -17,7 +17,7 @@ import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
import org.gcube.portlets.user.workspace.client.model.SubTree;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.TrashOperationResult;
import org.gcube.portlets.user.workspace.shared.TrashContent;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
@ -219,15 +219,6 @@ public interface GWTWorkspaceService extends RemoteService{
*/
List<FileTrashedModel> getTrashContent() throws Exception;
/**
* @param trashItemId
* @param operation
* @return
* @throws Exception
*/
TrashOperationResult executeOperationOnTrash(String trashItemId,
WorkspaceTrashOperation operation) throws Exception;
/**
* @param folderId
* @return
@ -243,4 +234,21 @@ public interface GWTWorkspaceService extends RemoteService{
List<InfoContactModel> getUsersManagerToSharedFolder(String folderId)
throws Exception;
/**
* @param listTrashItemIds
* @param operation
* @return
* @throws Exception
*/
TrashContent updateTrashContent(WorkspaceTrashOperation operation) throws Exception;
/**
* @param listTrashItemIds
* @param operation
* @return
* @throws Exception
*/
TrashContent executeOperationOnTrash(List<String> listTrashItemIds,
WorkspaceTrashOperation operation) throws Exception;
}

View File

@ -16,7 +16,7 @@ import org.gcube.portlets.user.workspace.client.model.ScopeModel;
import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
import org.gcube.portlets.user.workspace.client.model.SubTree;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.shared.TrashOperationResult;
import org.gcube.portlets.user.workspace.shared.TrashContent;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
@ -190,9 +190,8 @@ public interface GWTWorkspaceServiceAsync {
void getTrashContent(AsyncCallback<List<FileTrashedModel>> callback);
void executeOperationOnTrash(String trashItemId,
WorkspaceTrashOperation operation,
AsyncCallback<TrashOperationResult> callback);
void updateTrashContent(WorkspaceTrashOperation operation,
AsyncCallback<TrashContent> callback);
void getACLsDescriptionForSharedFolderId(String folderId,
AsyncCallback<String> callback);
@ -200,4 +199,8 @@ public interface GWTWorkspaceServiceAsync {
void getUsersManagerToSharedFolder(String folderId,
AsyncCallback<List<InfoContactModel>> callback);
void executeOperationOnTrash(List<String> listTrashItemIds,
WorkspaceTrashOperation operation,
AsyncCallback<TrashContent> callback);
}

View File

@ -2197,50 +2197,66 @@ public class GWTWorkspaceBuilder {
public List<FileTrashedModel> buildGXTListTrashContent(WorkspaceTrashFolder trash) throws Exception
{
List<WorkspaceTrashItem> trashContent = trash.listTrashItems();
logger.info("Converting trash content, size is: "+ trashContent.size());
List<FileTrashedModel> listFileModel = new ArrayList<FileTrashedModel>();
try {
for (WorkspaceTrashItem trashedItem : trash.listTrashItems())
listFileModel.add(buildGXTTrashModelItem(trashedItem));
for (WorkspaceTrashItem trashedItem : trashContent)
try{
FileTrashedModel cti = buildGXTTrashModelItem(trashedItem);
listFileModel.add(cti);
}catch (Exception e) {
logger.warn("Error in server buildGXTListTrashContent, skipping conversion of trashedItem", e);
}
} catch (Exception e) {
logger.error("Error in server buildGXTListTrashContent", e);
String error = ConstantsExplorer.SERVER_ERROR +" get Trash content. "+e.getMessage();
throw new Exception(error);
}
logger.info("Returning trash content as FileTrashedModel, size is: "+ trashContent.size());
return listFileModel;
}
/**
*
* @param trashedItem
* @return
* @throws InternalErrorException
*/
public FileTrashedModel buildGXTTrashModelItem(WorkspaceTrashItem trashedItem) throws InternalErrorException{
FileTrashedModel fileTrashModel = null;
FileTrashedModel fileTrashModel = new FileTrashedModel();
fileTrashModel.setName(trashedItem.getName());
//TODO INCOMPLETED
/*switch (trashedItem.getType()) {
//SETTING PARENT
FileModel oldParent = new FileModel(trashedItem.getOriginalParentId(), "", true);
fileTrashModel.setOrginalPath(trashedItem.getDeletedFrom());
fileTrashModel.setParentFileModel(oldParent);
//SETTING DELETED BY
InfoContactModel deleteUser = buildGxtInfoContactFromPortalLogin(trashedItem.getDeletedBy());
fileTrashModel.setDeleteUser(deleteUser);
case TRASH_ITEM:
//TODO SETTING IS FOLDER
// fileGridModel = new FileGridModel(item.getId(), item.getName(), toDate(item.getCreationTime()), parentFileModel, folderItem.getLength(), false, false);
fileTrashModel = new FileTrashedModel(trashedItem.getId(), trashedItem.getName(), toDate(trashedItem.getLastModificationTime()), null, trashedItem.getLength(), false, trashedItem.isShared());
fileTrashModel.setOrginalPath(trashedItem.getOriginalParentId());
fileTrashModel.setDeleteDate(fileTrashModel.getDeleteDate());
InfoContactModel deleteUser = buildGxtInfoContactFromPortalLogin(trashedItem.getDeleteUser());
fileTrashModel.setDeleteUser(deleteUser);
FolderItem folderItem = (FolderItem) trashedItem;
fileTrashModel = (FileTrashedModel) setFolderItemType(fileTrashModel, folderItem);
break;
default:
logger.error("gxt conversion return null for trash item "+trashedItem.getName());
break;
}*/
//SETTING MIME TYPE
fileTrashModel.setType(trashedItem.getMimeType());
//SETTING IS DIRECTORY
fileTrashModel.setIsDirectory(trashedItem.isFolder());
//SETTING DELETE DATE
fileTrashModel.setDeleteDate(toDate(trashedItem.getDeletedTime()));
fileTrashModel.setShared(false);
logger.info("Converting return trash item: "+fileTrashModel);
return fileTrashModel;
}

View File

@ -39,6 +39,7 @@ import org.gcube.common.homelibrary.home.workspace.folder.items.ts.TimeSeries;
import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
import org.gcube.common.homelibrary.home.workspace.sharing.WorkspaceMessage;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategoryItemInterface;
@ -66,7 +67,8 @@ import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader;
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.TrashOperationResult;
import org.gcube.portlets.user.workspace.shared.TrashContent;
import org.gcube.portlets.user.workspace.shared.TrashOperationContent;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
@ -2874,8 +2876,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
* @throws Exception
*/
@Override
public TrashOperationResult executeOperationOnTrash(String trashItemId, WorkspaceTrashOperation operation) throws Exception{
workspaceLogger.trace("Get TrashContent: ");
public TrashContent updateTrashContent(WorkspaceTrashOperation operation) throws Exception{
workspaceLogger.info("Upate TrashContent with operation: "+operation);
Workspace workspace;
List<String> listErrors = null;
@ -2884,25 +2887,19 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspace = getWorkspace();
WorkspaceTrashFolder trash = workspace.getTrash();
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
TrashOperationResult result = new TrashOperationResult();
TrashContent result = new TrashContent();
switch (operation) {
case EMPTY_TRASH:
listErrors = trash.emptyTrash();
break;
case DELETE_PERMANENTLY:
break;
case RESTORE:
break;
case RESTORE_ALL:
listErrors = trash.restoreAll();
break;
case REFRESH:
result.setTrashContent(builder.buildGXTListTrashContent(trash));
return result;
@ -2926,8 +2923,111 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return result;
}catch (Exception e) {
workspaceLogger.error("Error in server TrashConten", e);
String error = ConstantsExplorer.SERVER_ERROR +" get Trash content. "+e.getMessage();
workspaceLogger.error("Error in server TrashContent", e);
String error = ConstantsExplorer.SERVER_ERROR +" update Trash content. "+e.getMessage();
throw new Exception(error);
}
}
/**
*
* @return
* @throws Exception
*/
@Override
public TrashContent executeOperationOnTrash(List<String> listTrashItemIds, WorkspaceTrashOperation operation) throws Exception{
workspaceLogger.info("Get TrashContent, operation: "+operation);
if(listTrashItemIds==null || listTrashItemIds.size()==0)
throw new Exception("List of Trash item ids is null or empty");
Workspace workspace;
List<String> listErrors = null;
try {
workspace = getWorkspace();
WorkspaceTrashFolder trash = workspace.getTrash();
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
TrashOperationContent result = new TrashOperationContent();
List<FileTrashedModel> listContentError = new ArrayList<FileTrashedModel>();
List<String> listUpdatedTrashIds = new ArrayList<String>();
switch (operation) {
case DELETE_PERMANENTLY:{
boolean deleted = false;
for (String trashItemId : listTrashItemIds) {
try{
WorkspaceTrashItem trashItem = trash.getTrashItemById(trashItemId);
if(trashItem!=null){
trashItem.deletePermanently();
listUpdatedTrashIds.add(trashItemId);
deleted = true;
}
}catch (Exception e) {
workspaceLogger.warn("Error on DELETE_PERMANENTLY the item : "+trashItemId, e);
FileTrashedModel fakeFile = new FileTrashedModel();
fakeFile.setIdentifier(trashItemId);
listContentError.add(fakeFile);
}
}
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:{
boolean restored = false;
for (String trashItemId : listTrashItemIds) {
try{
WorkspaceTrashItem trashItem = trash.getTrashItemById(trashItemId);
if(trashItem!=null){
trashItem.restore();
listUpdatedTrashIds.add(trashItemId);
restored = true;
}
}catch (Exception e) {
workspaceLogger.warn("Error on RESTORE the item : "+trashItemId, e);
FileTrashedModel fakeFile = new FileTrashedModel();
fakeFile.setIdentifier(trashItemId);
listContentError.add(fakeFile);
}
}
String label = listTrashItemIds.size()>1?"items":"item";
if(!restored)
throw new Exception("Sorry, an error occurred on restoring the trash "+label+", try again");
break;
}
}
// trash = workspace.getTrash();
// result.setTrashContent(builder.buildGXTListTrashContent(trash));
if(listErrors.size()>0){
for (String trashedItemId : listErrors) {
listContentError.add(builder.buildGXTTrashModelItemById(trashedItemId, trash));
}
result.setListErrors(listContentError);
}
result.setListTrashIds(listUpdatedTrashIds);
return result;
}catch (Exception e) {
workspaceLogger.error("Error in server executeOperationOnTrash", e);
String error = ConstantsExplorer.SERVER_ERROR +" update Trash content. "+e.getMessage();
throw new Exception(error);
}
}

View File

@ -13,7 +13,7 @@ import org.gcube.portlets.user.workspace.client.model.FileTrashedModel;
* @Feb 17, 2014
*
*/
public class TrashOperationResult implements Serializable{
public class TrashContent implements Serializable{
/**
*
@ -27,16 +27,14 @@ public class TrashOperationResult implements Serializable{
/**
*
*/
public TrashOperationResult() {
// TODO Auto-generated constructor stub
public TrashContent() {
}
/**
* @param trashContent
* @param listErrors
*/
public TrashOperationResult(List<FileTrashedModel> trashContent,
List<FileTrashedModel> listErrors) {
public TrashContent(List<FileTrashedModel> trashContent, List<FileTrashedModel> listErrors) {
this.trashContent = trashContent;
this.listErrors = listErrors;
}

View File

@ -0,0 +1,71 @@
/**
*
*/
package org.gcube.portlets.user.workspace.shared;
import java.util.List;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Feb 17, 2014
*
*/
public class TrashOperationContent extends TrashContent{
/**
*
*/
private static final long serialVersionUID = 3089944053784656200L;
private List<String> listTrashIds;
private WorkspaceTrashOperation operation;
/**
*
*/
public TrashOperationContent() {
}
/**
* @param trashContent
* @param listErrors
*/
public TrashOperationContent(WorkspaceTrashOperation operation, List<String> listTrashIds) {
this.listTrashIds = listTrashIds;
this.operation = operation;
}
public void setListTrashIds(List<String> listTrashIds) {
this.listTrashIds = listTrashIds;
}
public WorkspaceTrashOperation getOperation() {
return operation;
}
public void setOperation(WorkspaceTrashOperation operation) {
this.operation = operation;
}
public List<String> getListTrashIds() {
return listTrashIds;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("TrashOperationContent [listTrashIds=");
builder.append(listTrashIds);
builder.append(", operation=");
builder.append(operation);
builder.append(", trashContent=");
builder.append(trashContent);
builder.append(", listErrors=");
builder.append(listErrors);
builder.append("]");
return builder.toString();
}
}

View File

@ -15,7 +15,7 @@ import java.util.List;
public enum WorkspaceTrashOperation {
//SHOW TRASH WINDOW
SHOW("Show", "Show"),
SHOW("Show", "Show"),
//CALLING OPERATION SERVER
REFRESH("Refresh", "Refresh trash content"),