From 3095ff46d25f5a88c153c4e5f871f22e5ccb0216 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Wed, 22 Feb 2017 10:36:28 +0000 Subject: [PATCH] Versioning #7006 first release git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@144060 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/model/FileVersionModel.java | 8 +- .../client/rpc/GWTWorkspaceService.java | 30 +++- .../client/rpc/GWTWorkspaceServiceAsync.java | 10 +- .../server/GWTWorkspaceServiceImpl.java | 151 +++++++++--------- .../shared/WorkspaceVersioningOperation.java | 2 +- 5 files changed, 106 insertions(+), 95 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/model/FileVersionModel.java b/src/main/java/org/gcube/portlets/user/workspace/client/model/FileVersionModel.java index 4c2ab52..9e8b194 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/model/FileVersionModel.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/model/FileVersionModel.java @@ -1,10 +1,7 @@ package org.gcube.portlets.user.workspace.client.model; -import java.io.Serializable; import java.util.Date; -import com.google.gwt.user.client.rpc.IsSerializable; - /** * The Class FileVersionModel. @@ -12,12 +9,13 @@ import com.google.gwt.user.client.rpc.IsSerializable; * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * Feb 20, 2017 */ -public class FileVersionModel extends FileModel implements IsSerializable, Serializable { +public class FileVersionModel extends FileModel { + /** * */ - private static final long serialVersionUID = -607019966965449963L; + private static final long serialVersionUID = 4645522942385738974L; public static final String PATH = "path"; public static final String USER_VERSIONING = "user_versioning"; public static final String CREATED = "created"; 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 11d524b..c3a6bac 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 @@ -139,7 +139,7 @@ public interface GWTWorkspaceService extends RemoteService{ * * @param category the category * @return the smart folder results by category - * @throws Exception + * @throws Exception the exception */ List getSmartFolderResultsByCategory( GXTCategorySmartFolder category) throws Exception; @@ -738,16 +738,32 @@ public interface GWTWorkspaceService extends RemoteService{ * * @param itemId the item id * @return the allow access + * @throws SessionExpiredException the session expired exception + * @throws Exception the exception */ AllowAccess accessToFolderLink(String itemId) throws SessionExpiredException, Exception; + + /** - * @param fileIdentifier - * @return - * @throws Exception + * Perform operation on versioned file. + * + * @param fileId the file id + * @param olderVersionIDs the older version i ds + * @param operation the operation + * @return the list + * @throws Exception the exception */ - List getVersionHistory(String fileIdentifier) - throws Exception; List performOperationOnVersionedFile( - FileModel currentVersion, List selectedVersion, + String fileId, List olderVersionIDs, WorkspaceVersioningOperation operation) throws Exception; + + + /** + * Gets the version history. + * + * @param fileIdentifier the file identifier + * @return the version history + * @throws Exception the exception + */ + List getVersionHistory(String fileIdentifier) 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 062e014..89a3f8b 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 @@ -748,16 +748,8 @@ public interface GWTWorkspaceServiceAsync { void getVersionHistory( String fileIdentifier, AsyncCallback> callback); - /** - * Perform operation on versioned file. - * - * @param currentVersion the current version - * @param selectedVersion the selected version - * @param operation the operation - * @param callback the callback - */ void performOperationOnVersionedFile( - FileModel currentVersion, List selectedVersion, + String fileId, List olderVersionIds, WorkspaceVersioningOperation 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 1cb3f64..17bf5cf 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 @@ -3373,79 +3373,6 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } - - /* (non-Javadoc) - * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#performOperationOnVersionedFile(org.gcube.portlets.user.workspace.client.model.FileModel, org.gcube.portlets.user.workspace.client.model.FileModel, org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation) - */ - @Override - public List performOperationOnVersionedFile(FileModel currentVersion, List olderVersions, WorkspaceVersioningOperation operation) throws Exception{ - - if(currentVersion == null || olderVersions==null || olderVersions.size()==0) - throw new Exception("File Versioned is null"); - - workspaceLogger.info("Cuurent Version: "+currentVersion.getName()+", File Versioned "+olderVersions+ " perform operation: "+operation); - - try { - - Workspace workspace = getWorkspace(); - WorkspaceItem fileHL = workspace.getItem(currentVersion.getIdentifier()); - if(fileHL instanceof ExternalFile){ - ExternalFile extFile = (ExternalFile) fileHL; - - switch (operation) { - - case DOWNLOAD: { - //IMPLEMENTED CLIENT-SIDE - break; - } - - case EMPTY_OLDER_VERSIONS:{ - //TODO - //extFile.(selectedVersion.getIdentifier());; - } - - case RESTORE: { - for (FileVersionModel olderVerison : olderVersions) { - extFile.restoreVersion(olderVerison.getIdentifier()); - } - return getVersionHistory(currentVersion.getIdentifier()); - - } - - case REFRESH: { - return getVersionHistory(currentVersion.getIdentifier()); - } - - case DELETE_PERMANENTLY: { - for (FileVersionModel olderVerison : olderVersions) { - extFile.removeVersion(olderVerison.getIdentifier()); - workspaceLogger.info("Version "+olderVerison.getIdentifier() +" of "+currentVersion.getName()+" removed"); - } - return getVersionHistory(currentVersion.getIdentifier()); - } - - default:{ - - break; - } - } - - return getVersionHistory(currentVersion.getIdentifier()); - - }else - throw new FileNotVersionedException("Selected file is not versioned"); - - }catch (Exception e) { - - if (e instanceof FileNotVersionedException) - throw new Exception(e.getMessage()); - workspaceLogger.error("Error in server during perform operation on versioning of: "+currentVersion.getName(), e); - String error = ConstantsExplorer.SERVER_ERROR +" updating versioning of "+currentVersion.getName(); - throw new Exception(error); - } - } - - /* (non-Javadoc) * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#executeOperationOnTrash(java.util.List, org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation) */ @@ -4085,4 +4012,82 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT throw new Exception(error); } } + + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#performOperationOnVersionedFile(java.lang.String, java.util.List, org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation) + */ + @Override + public List performOperationOnVersionedFile( + String fileId, List olderVersionIDs, + WorkspaceVersioningOperation operation) throws Exception { + + if(fileId == null || olderVersionIDs==null || olderVersionIDs.size()==0) + throw new Exception("File Versioned is null"); + + workspaceLogger.info("File Id: "+fileId+", Ids Version: "+olderVersionIDs+ " perform operation: "+operation); + + try { + + Workspace workspace = getWorkspace(); + WorkspaceItem fileHL = workspace.getItem(fileId); + if(fileHL instanceof ExternalFile){ + ExternalFile extFile = (ExternalFile) fileHL; + + switch (operation) { + + case DOWNLOAD: { + //IMPLEMENTED CLIENT-SIDE + break; + } + + case DELETE_ALL_OLDER_VERSIONS:{ + //MUST BE OPTIMIZED HL-SIDE + for (String olderVersionId : olderVersionIDs) { + extFile.removeVersion(olderVersionId); + workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" removed"); + } + return getVersionHistory(fileId); + } + + case RESTORE: { + for (String olderVersionId : olderVersionIDs) { + extFile.restoreVersion(olderVersionId); + workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" restored"); + } + return getVersionHistory(fileId); + + } + + case REFRESH: { + return getVersionHistory(fileId); + } + + case DELETE_PERMANENTLY: { + for (String olderVersionId : olderVersionIDs) { + extFile.removeVersion(olderVersionId); + workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" removed"); + } + return getVersionHistory(fileId); + } + + default:{ + + break; + } + } + + return getVersionHistory(fileId); + + }else + throw new FileNotVersionedException("Selected file is not versioned"); + + }catch (Exception e) { + + if (e instanceof FileNotVersionedException) + throw new Exception(e.getMessage()); + workspaceLogger.error("Error in server during perform operation on versioning on file id: "+fileId, e); + String error = ConstantsExplorer.SERVER_ERROR +" updating versioning of file id: "+fileId; + throw new Exception(error); + } + } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/WorkspaceVersioningOperation.java b/src/main/java/org/gcube/portlets/user/workspace/shared/WorkspaceVersioningOperation.java index 459f793..6ca2dd2 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/shared/WorkspaceVersioningOperation.java +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/WorkspaceVersioningOperation.java @@ -22,7 +22,7 @@ public enum WorkspaceVersioningOperation { RESTORE("Restore", "Restore the file to the selected version"), DOWNLOAD("Download", "Download the version of the selected file"), DELETE_PERMANENTLY("Delete Permanently", "Delete Permanently the version for the selected file"), - EMPTY_OLDER_VERSIONS("Empty Old Versions", "Empty definitively all older versions of the file"); + DELETE_ALL_OLDER_VERSIONS("Delete all older versions", "Delete definitively all older versions of the file"); public String label; public String operationDescription;