Enhancement on file versioning #7006

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@142774 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-02-20 13:57:07 +00:00
parent 59e8f4e86e
commit 6aaa31fe2a
15 changed files with 159 additions and 74 deletions

View File

@ -91,6 +91,8 @@ import org.gcube.portlets.user.workspace.client.event.UpdatedVREPermissionEvent;
import org.gcube.portlets.user.workspace.client.event.UpdatedVREPermissionEventHandler;
import org.gcube.portlets.user.workspace.client.event.VRESettingPermissionEvent;
import org.gcube.portlets.user.workspace.client.event.VRESettingPermissionEventHandler;
import org.gcube.portlets.user.workspace.client.event.VersioningHistoryShowEvent;
import org.gcube.portlets.user.workspace.client.event.VersioningHistoryShowEventHandler;
import org.gcube.portlets.user.workspace.client.event.WebDavUrlEvent;
import org.gcube.portlets.user.workspace.client.event.WebDavUrlEventHandler;
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
@ -264,6 +266,19 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
});
eventBus.addHandler(VersioningHistoryShowEvent.TYPE, new VersioningHistoryShowEventHandler() {
@Override
public void onFileVersioning(VersioningHistoryShowEvent fileVersioningEvent) {
FileModel file = fileVersioningEvent.getTargetFileModel();
if(file==null)
return;
notifySubscriber(fileVersioningEvent);
}
});
eventBus.addHandler(UpdateWorkspaceSizeEvent.TYPE, new UpdateWorkspaceSizeEventHandler() {
@Override
@ -943,8 +958,10 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
try {
// Add currentContextId parameter
String currentContextId = GCubeClientContext.getCurrentContextId();
String currentUserId = GCubeClientContext.getCurrentUserId();
//String currentUserId = GCubeClientContext.getCurrentUserId();
String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&viewContent=true&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="+currentContextId;
if(fileDownloadEvent.getVersionId()!=null)
queryString+="&"+ConstantsExplorer.FILE_VERSION_ID+"="+fileDownloadEvent.getVersionId();
new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_blank", downloadHandlerCallback);
} catch (Exception e) {
@ -966,8 +983,10 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
try {
// Add currentContextId parameter
String currentContextId = GCubeClientContext.getCurrentContextId();
String currentUserId = GCubeClientContext.getCurrentUserId();
//String currentUserId = GCubeClientContext.getCurrentUserId();
String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="+currentContextId;
if(fileDownloadEvent.getVersionId()!=null)
queryString+="&"+ConstantsExplorer.FILE_VERSION_ID+"="+fileDownloadEvent.getVersionId();
new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET,ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_self", downloadHandlerCallback);
} catch (Exception e) {
explorerPanel.getAsycTreePanel().unmask();
@ -1366,10 +1385,6 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
if(dialogAddFolder.isValidForm()){
if(sourceFileModel.isDirectory()){
//
//TODO REMOVE
// System.out.println("description folder: "+dialogAddFolder.getDescription());
rpcWorkspaceService.createFolder(dialogAddFolder.getName(), dialogAddFolder.getDescription(), sourceFileModel, new AsyncCallback<FolderModel>(){
@ -1471,11 +1486,9 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
else
doClickPreview(imagePreviewEvent, 50, 50);
//ADDED 24/07/2013
if(imagePreviewEvent.getSourceFileModel()!=null){ //FILE CAN NOT LOADED IN TREE
notifySubscriber(new FileDownloadEvent(imagePreviewEvent.getSourceFileModel().getIdentifier(), imagePreviewEvent.getSourceFileModel().getName(), FileDownloadEvent.DownloadType.SHOW, false));
notifySubscriber(new FileDownloadEvent(imagePreviewEvent.getSourceFileModel().getIdentifier(), imagePreviewEvent.getSourceFileModel().getName(), FileDownloadEvent.DownloadType.SHOW, false, null));
}
}
@ -1840,6 +1853,9 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}else if(event instanceof UpdateWorkspaceSizeEvent){
sub.updateWorksapaceSize(true);
}else if(event instanceof VersioningHistoryShowEvent){
VersioningHistoryShowEvent historyVers = (VersioningHistoryShowEvent) event;
sub.versioningHistory(historyVers.getTargetFileModel());
}
}

View File

@ -231,6 +231,7 @@ public static enum WS_UPLOAD_TYPE {File, Archive};
public static final String VALIDATEITEM = "validateitem";
public static final String CURRENT_CONTEXT_ID = "contextID";
public static final String REDIRECTONERROR = "redirectonerror";
public static final String FILE_VERSION_ID = "fileversionid";
//UPLOAD SERVLET PARAMETERS
public static final String IS_OVERWRITE = "isOverwrite";
@ -238,6 +239,7 @@ public static enum WS_UPLOAD_TYPE {File, Archive};
public static final String ID_FOLDER = "idFolder";
public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement";
//PROPERTY
public static final String SPECIALFOLDERNAME = "SPECIALFOLDERNAME";
public static final String SPECIALFOLDERNAMEPROPERTIESFILE = "specialfoldername.properties";
@ -247,6 +249,7 @@ public static enum WS_UPLOAD_TYPE {File, Archive};
public static final int HEIGHT_DIALOG_SHARE_FOLDER = 445;
/**
* Log.
*

View File

@ -13,15 +13,24 @@ public class FileDownloadEvent extends GwtEvent<FileDownloadEventHandler> implem
private DownloadType downloadType;
private String itemName;
private boolean isFolder;
// private FileType fileType;
// public enum FileType {TREE, ATTACH};
public FileDownloadEvent(String itemIdentifier, String name, DownloadType downloadType, boolean isFolder) {
private String versionId;
/**
* Instantiates a new file download event.
*
* @param itemIdentifier the item identifier
* @param name the name
* @param downloadType the download type
* @param isFolder the is folder
* @param versionId the version id related to older version
*/
public FileDownloadEvent(String itemIdentifier, String name, DownloadType downloadType, boolean isFolder, String versionId) {
this.itemIdentifier = itemIdentifier;
this.downloadType = downloadType;
this.itemName = name;
this.isFolder = isFolder;
// this.fileType = fileType;
this.versionId = versionId;
}
@Override
@ -33,12 +42,12 @@ public class FileDownloadEvent extends GwtEvent<FileDownloadEventHandler> implem
protected void dispatch(FileDownloadEventHandler handler) {
handler.onFileDownloadEvent(this);
}
public String getDownloadTypeToString() {
return downloadType.toString();
}
public DownloadType getDownloadType() {
return downloadType;
}
@ -62,5 +71,14 @@ public class FileDownloadEvent extends GwtEvent<FileDownloadEventHandler> implem
public EventsTypeEnum getKey() {
return EventsTypeEnum.FILE_DOWNLAD_EVENT;
}
/**
* @return the versionId
*/
public String getVersionId() {
return versionId;
}
}

View File

@ -14,9 +14,9 @@ import com.google.gwt.event.shared.GwtEvent;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 20, 2017
*/
public class FileVersioningEvent extends GwtEvent<FileVersioningEventHandler> implements GuiEventInterface{
public class VersioningHistoryShowEvent extends GwtEvent<VersioningHistoryShowEventHandler> implements GuiEventInterface{
public static Type<FileVersioningEventHandler> TYPE = new Type<FileVersioningEventHandler>();
public static Type<VersioningHistoryShowEventHandler> TYPE = new Type<VersioningHistoryShowEventHandler>();
private FileModel targetFileModel;
private WorkspaceVersioningOperation workspaceVersioningOperation;
@ -27,7 +27,7 @@ public class FileVersioningEvent extends GwtEvent<FileVersioningEventHandler> im
* @param workspaceVersioningOperation the workspace versioning operation
* @param target the target
*/
public FileVersioningEvent(WorkspaceVersioningOperation workspaceVersioningOperation, FileModel target) {
public VersioningHistoryShowEvent(WorkspaceVersioningOperation workspaceVersioningOperation, FileModel target) {
this.workspaceVersioningOperation = workspaceVersioningOperation;
this.targetFileModel = target;
@ -37,7 +37,7 @@ public class FileVersioningEvent extends GwtEvent<FileVersioningEventHandler> im
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
*/
@Override
public Type<FileVersioningEventHandler> getAssociatedType() {
public Type<VersioningHistoryShowEventHandler> getAssociatedType() {
return TYPE;
}
@ -45,29 +45,10 @@ public class FileVersioningEvent extends GwtEvent<FileVersioningEventHandler> im
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
*/
@Override
protected void dispatch(FileVersioningEventHandler handler) {
protected void dispatch(VersioningHistoryShowEventHandler handler) {
handler.onFileVersioning(this);
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface#getKey()
*/
@Override
public EventsTypeEnum getKey() {
return EventsTypeEnum.FILE_VERSIONING_EVENT;
}
/**
* Sets the trash operation.
*
* @param workspaceVersioningOperation the new trash operation
*/
public void setTrashOperation(WorkspaceVersioningOperation workspaceVersioningOperation) {
this.workspaceVersioningOperation = workspaceVersioningOperation;
}
/**
* Gets the target file model.
*
@ -84,9 +65,17 @@ public class FileVersioningEvent extends GwtEvent<FileVersioningEventHandler> im
*
* @return the workspaceVersioningOperation
*/
public WorkspaceVersioningOperation getWorkspaceVersioningOperation() {
public WorkspaceVersioningOperation getVersioningOperation() {
return workspaceVersioningOperation;
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface#getKey()
*/
@Override
public EventsTypeEnum getKey() {
return EventsTypeEnum.FILE_VERSIONING_HISTORY_EVENT;
}
}

View File

@ -9,12 +9,12 @@ import com.google.gwt.event.shared.EventHandler;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 20, 2017
*/
public interface FileVersioningEventHandler extends EventHandler {
public interface VersioningHistoryShowEventHandler extends EventHandler {
/**
* On file versioning.
*
* @param fileVersioningEvent the file versioning event
*/
void onFileVersioning(FileVersioningEvent fileVersioningEvent);
void onFileVersioning(VersioningHistoryShowEvent fileVersioningEvent);
}

View File

@ -34,5 +34,5 @@ public enum EventsTypeEnum
UPDATED_VRE_PERMISSION,
UPDATE_WORKSPACE_SIZE,
ADD_ADMINISTRATOR_EVENT,
FILE_VERSIONING_EVENT;
FILE_VERSIONING_HISTORY_EVENT;
}

View File

@ -184,4 +184,13 @@ public interface SubscriberInterface {
*/
void updateWorksapaceSize(boolean delayCall);
/**
* Versioning history.
*
* @param file the file
*/
void versioningHistory(FileModel file);
}

View File

@ -445,5 +445,11 @@ public interface Icons extends ClientBundle {
@Source("icons/folder_public_remove.png")
ImageResource folderPublicRemove();
/**
* @return
*/
@Source("icons/versioning.png")
ImageResource versioning();
}

View File

@ -1352,6 +1352,16 @@ public class Resources {
return AbstractImagePrototype.create(ICONS.manageAdmin());
}
/**
* Gets the icon versioning.
*
* @return the icon versioning
*/
public static AbstractImagePrototype getIconVersioning() {
return AbstractImagePrototype.create(ICONS.versioning());
}
//ImageResources
/**
* Gets the image path separator.
@ -1416,6 +1426,7 @@ public class Resources {
return ICONS.delete2();
}
/**
* Gets the image attachs.
*

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

View File

@ -28,6 +28,7 @@ import org.gcube.portlets.user.workspace.shared.UserBean;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote;
import org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import com.google.gwt.user.client.rpc.RemoteService;
@ -738,4 +739,22 @@ public interface GWTWorkspaceService extends RemoteService{
* @return the allow access
*/
AllowAccess accessToFolderLink(String itemId) throws SessionExpiredException, Exception;
/**
* @param fileIdentifier
* @return
* @throws Exception
*/
List<FileModel> getVersionHistory(String fileIdentifier)
throws Exception;
/**
* @param currentVersion
* @param selectedVersion
* @param operation
* @return
* @throws Exception
*/
List<FileModel> performOperationOnVersionedFile(
FileModel currentVersion, FileModel selectedVersion,
WorkspaceVersioningOperation operation)
throws Exception;
}

View File

@ -27,6 +27,7 @@ import org.gcube.portlets.user.workspace.shared.UserBean;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote;
import org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -735,4 +736,12 @@ public interface GWTWorkspaceServiceAsync {
*/
void getServletContextPath(String protocol, AsyncCallback<String> callback);
void getVersionHistory(
String fileIdentifier, AsyncCallback<List<FileModel>> callback);
void performOperationOnVersionedFile(
FileModel currentVersion, FileModel olderVersion,
WorkspaceVersioningOperation operation,
AsyncCallback<List<FileModel>> callback);
}

View File

@ -540,7 +540,7 @@ public class ContextMenuTree {
for (final FileModel sel : listSelectedItems) {
eventBus.fireEvent(new FileDownloadEvent(sel.getIdentifier(), sel.getName(), DownloadType.SHOW, sel.isDirectory() || sel.isVreFolder()));
eventBus.fireEvent(new FileDownloadEvent(sel.getIdentifier(), sel.getName(), DownloadType.SHOW, sel.isDirectory() || sel.isVreFolder(), null));
}
}
});
@ -638,7 +638,7 @@ public class ContextMenuTree {
public void componentSelected(MenuEvent ce) {
for (FileModel sel : listSelectedItems) {
eventBus.fireEvent(new FileDownloadEvent(sel.getIdentifier(), sel.getName(), DownloadType.DOWNLOAD, sel.isDirectory() || sel.isVreFolder()));
eventBus.fireEvent(new FileDownloadEvent(sel.getIdentifier(), sel.getName(), DownloadType.DOWNLOAD, sel.isDirectory() || sel.isVreFolder(), null));
}
}
});

View File

@ -76,9 +76,16 @@ public class DownloadServlet extends HttpServlet{
boolean isValidItem = req.getParameter(ConstantsExplorer.VALIDATEITEM)==null?false:req.getParameter(ConstantsExplorer.VALIDATEITEM).equals("true");
boolean urlRedirectOnError = req.getParameter(ConstantsExplorer.REDIRECTONERROR)==null?false:req.getParameter(ConstantsExplorer.REDIRECTONERROR).equals("true");
String contextID = req.getParameter(ConstantsExplorer.CURRENT_CONTEXT_ID);
//String userID = req.getParameter(ConstantsExplorer.CURRENT_USER_ID);
String versionID = req.getParameter(ConstantsExplorer.FILE_VERSION_ID);
logger.debug("Input Params " +
"[id: "+itemId + ", " +
"viewContent: "+viewContent+", " +
ConstantsExplorer.VALIDATEITEM +": " +isValidItem+", " +
"urlRedirectOnError:" +urlRedirectOnError+", " +
"contextID: "+contextID+", " +
"versioID: "+versionID+"]");
logger.debug("Input Params [id: "+itemId + ", viewContent: "+viewContent+", "+ConstantsExplorer.VALIDATEITEM +": " +isValidItem+", urlRedirectOnError:" +urlRedirectOnError+", contextID: "+contextID+"]");
if(itemId==null || itemId.isEmpty()){
sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Item id is null");
return;
@ -238,16 +245,22 @@ public class DownloadServlet extends HttpServlet{
InputStream is = null;
OutputStream out = null;
try{
ExternalFile externalFile = (ExternalFile)folderItem;
ExternalFile externalFile = (ExternalFile) folderItem;
String mimeType = externalFile.getMimeType();
logger.trace("EXTERNAL_FILE DOWNLOAD FOR "+externalFile.getId());
String contentDisposition = viewContent?"inline":"attachment";
resp.setHeader("Content-Disposition", contentDisposition+"; filename=\"" + item.getName() + "\"" );
resp.setContentType(mimeType);
resp = setContentLength(resp, externalFile.getLength());
is = externalFile.getData();
if(versionID!=null){
logger.info("Downloading version id: "+versionID);
//TODO MUST BE ADDED SIZE FOR VERSIONED FILE
is = externalFile.downloadVersion(versionID);
}else{
resp = setContentLength(resp, externalFile.getLength());
is = externalFile.getData();
}
out = resp.getOutputStream();
IOUtils.copy(is, out);

View File

@ -3339,6 +3339,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
* @return the version history
* @throws Exception the exception
*/
@Override
public List<FileModel> getVersionHistory(String fileIdentifier) throws Exception{
workspaceLogger.info("Get Version History "+fileIdentifier);
@ -3367,39 +3368,31 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.error(error);
throw new Exception(error);
}
}
/**
* Perform operation on file versioned.
*
* @param currentVersion the current version
* @param selectedVersion the selected version
* @param operation the operation
* @return the list
* @throws Exception the exception
*/
public List<FileModel> performOperationOnFileVersioned(FileModel currentVersion, FileModel selectedVersion, WorkspaceVersioningOperation operation) throws Exception{
if(currentVersion == null || selectedVersion==null)
/* (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<FileModel> performOperationOnVersionedFile(FileModel currentVersion, FileModel olderVerison, WorkspaceVersioningOperation operation) throws Exception{
if(currentVersion == null || olderVerison==null)
throw new Exception("File Versioned is null");
workspaceLogger.info("Cuurent Version: "+currentVersion.getName()+", File Versioned "+selectedVersion.getName()+ " perform operation: "+operation);
workspaceLogger.info("Cuurent Version: "+currentVersion.getName()+", File Versioned "+olderVerison.getName()+ " 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;
}
@ -3410,7 +3403,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
case RESTORE: {
extFile.restoreVersion(selectedVersion.getIdentifier());
extFile.restoreVersion(olderVerison.getIdentifier());
return getVersionHistory(currentVersion.getIdentifier());
}
@ -3419,8 +3412,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
case DELETE_PERMANENTLY: {
extFile.removeVersion(selectedVersion.getIdentifier());
workspaceLogger.info("Version "+selectedVersion.getIdentifier() +" of "+currentVersion.getName()+" removed");
extFile.removeVersion(olderVerison.getIdentifier());
workspaceLogger.info("Version "+olderVerison.getIdentifier() +" of "+currentVersion.getName()+" removed");
return getVersionHistory(currentVersion.getIdentifier());
}
@ -3428,7 +3421,6 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
break;
}
}
return getVersionHistory(currentVersion.getIdentifier());