Task #12909: Provide public links for versioned files
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@176389 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
371882be82
commit
de65a96c72
|
@ -3,7 +3,10 @@
|
|||
date="${buildDate}">
|
||||
<Change>Updated regular expression to validate Folder and File names
|
||||
</Change>
|
||||
<Change>[Task #12911] Called getFullName for any user other than logged user
|
||||
<Change>[Task #12911] Called getFullName for any user other than
|
||||
logged user
|
||||
</Change>
|
||||
<Change>[Task #12909:] Provide public links for versioned files
|
||||
</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-23-0"
|
||||
|
|
|
@ -439,13 +439,13 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
|||
eventBus.addHandler(VersioningHistoryShowEvent.TYPE, new VersioningHistoryShowEventHandler() {
|
||||
|
||||
@Override
|
||||
public void onFileVersioning(VersioningHistoryShowEvent fileVersioningEvent) {
|
||||
public void onFileVersioning(VersioningHistoryShowEvent versioningHistoryEvent) {
|
||||
|
||||
FileModel file = fileVersioningEvent.getTargetFileModel();
|
||||
FileModel file = versioningHistoryEvent.getTargetFileModel();
|
||||
if(file==null)
|
||||
return;
|
||||
|
||||
notifySubscriber(fileVersioningEvent);
|
||||
notifySubscriber(versioningHistoryEvent);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -497,7 +497,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
|||
// TODO Auto-generated method stub
|
||||
if(getFolderLinkEvent.getSourceFile()!=null){
|
||||
GWT.log("getFolderLinkEvent.getSourceFile() "+getFolderLinkEvent.getSourceFile());
|
||||
DialogGetLink dialog = new DialogGetLink("Copy to clipboard Folder Link: Ctrl+C", getFolderLinkEvent.getSourceFile(), Link_Type.FOLDER_LINK, getFolderLinkEvent.isSetPublic());
|
||||
DialogGetLink dialog = new DialogGetLink("Copy to clipboard Folder Link: Ctrl+C", getFolderLinkEvent.getSourceFile(), null, Link_Type.FOLDER_LINK, getFolderLinkEvent.isSetPublic());
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
@ -882,7 +882,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
|||
public void onGetPublicLink(GetPublicLinkEvent getPublicLinkEvent) {
|
||||
// TODO Auto-generated method stub
|
||||
if(getPublicLinkEvent.getSourceFile()!=null){
|
||||
DialogGetLink dialog = new DialogGetLink("Copy to clipboard Public Link: Ctrl+C", getPublicLinkEvent.getSourceFile(), Link_Type.PUBLIC_LINK, false);
|
||||
DialogGetLink dialog = new DialogGetLink("Copy to clipboard Public Link: Ctrl+C", getPublicLinkEvent.getSourceFile(), getPublicLinkEvent.getVersion(), Link_Type.PUBLIC_LINK, false);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,32 +4,64 @@ import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* The Class GetPublicLinkEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Jan 8, 2019
|
||||
*/
|
||||
public class GetPublicLinkEvent extends GwtEvent<GetPublicLinkEventHandler> {
|
||||
public static Type<GetPublicLinkEventHandler> TYPE = new Type<GetPublicLinkEventHandler>();
|
||||
|
||||
private FileModel targetFile = null;
|
||||
|
||||
public GetPublicLinkEvent(FileModel target) {
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* Instantiates a new gets the public link event.
|
||||
*
|
||||
* @param target the target
|
||||
* @param version the version
|
||||
*/
|
||||
public GetPublicLinkEvent(FileModel target, String version) {
|
||||
this.targetFile = target;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
|
||||
*/
|
||||
@Override
|
||||
public Type<GetPublicLinkEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(GetPublicLinkEventHandler handler) {
|
||||
handler.onGetPublicLink(this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source file.
|
||||
*
|
||||
* @return the source file
|
||||
*/
|
||||
public FileModel getSourceFile() {
|
||||
return targetFile;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the version.
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
public String getVersion() {
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
|
@ -80,7 +80,6 @@ public interface GWTWorkspaceService extends RemoteService{
|
|||
/**
|
||||
* Gets the root for tree.
|
||||
*
|
||||
* @param scopeId the scope id
|
||||
* @return the root for tree
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
@ -780,6 +779,7 @@ public interface GWTWorkspaceService extends RemoteService{
|
|||
List<GcubeVRE> getListOfVREsForLoggedUser()
|
||||
throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is item under sync.
|
||||
*
|
||||
|
@ -791,5 +791,18 @@ public interface GWTWorkspaceService extends RemoteService{
|
|||
throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
PublicLink getPublicLinkForFileItemIdToVersion(
|
||||
String itemId, String version, boolean shortenUrl) throws Exception;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public interface GWTWorkspaceServiceAsync {
|
|||
/**
|
||||
* Gets the root for tree.
|
||||
*
|
||||
* @param scopeId the scope id
|
||||
* @param folder the folder
|
||||
* @param callback the callback
|
||||
* @return the root for tree
|
||||
*/
|
||||
|
@ -473,6 +473,21 @@ public interface GWTWorkspaceServiceAsync {
|
|||
void getPublicLinkForFileItemId(String itemId, boolean shortenUrl,
|
||||
AsyncCallback<PublicLink> callback);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the public link for file item id to version.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @param version the version
|
||||
* @param shortenUrl the shorten url
|
||||
* @param callback the callback
|
||||
* @return the public link for file item id to version
|
||||
*/
|
||||
void getPublicLinkForFileItemIdToVersion(String itemId, String version, boolean shortenUrl,
|
||||
AsyncCallback<PublicLink> callback);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is session expired.
|
||||
*
|
||||
|
@ -489,10 +504,24 @@ public interface GWTWorkspaceServiceAsync {
|
|||
void deleteListItemsForIds(List<String> ids,
|
||||
AsyncCallback<List<GarbageItem>> callback);
|
||||
|
||||
/**
|
||||
* Copy items.
|
||||
*
|
||||
* @param idsItem the ids item
|
||||
* @param destinationFolderId the destination folder id
|
||||
* @param callback the callback
|
||||
*/
|
||||
void copyItems(
|
||||
List<String> idsItem, String destinationFolderId,
|
||||
AsyncCallback<WorkspaceOperationResult> callback);
|
||||
|
||||
/**
|
||||
* Move items.
|
||||
*
|
||||
* @param ids the ids
|
||||
* @param destinationId the destination id
|
||||
* @param callback the callback
|
||||
*/
|
||||
void moveItems(
|
||||
List<String> ids, String destinationId,
|
||||
AsyncCallback<WorkspaceOperationResult> callback);
|
||||
|
@ -768,6 +797,13 @@ public interface GWTWorkspaceServiceAsync {
|
|||
*/
|
||||
void isItemUnderSync(String itemId, AsyncCallback<Boolean> callback);
|
||||
|
||||
/**
|
||||
* Gets the link for send to switch board.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @param callback the callback
|
||||
* @return the link for send to switch board
|
||||
*/
|
||||
void getLinkForSendToSwitchBoard(String itemId, AsyncCallback<String> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ public class ContextMenuTree {
|
|||
public void componentSelected(MenuEvent ce) {
|
||||
|
||||
for (FileModel sel : listSelectedItems) {
|
||||
eventBus.fireEvent(new GetPublicLinkEvent(sel));
|
||||
eventBus.fireEvent(new GetPublicLinkEvent(sel, null));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -48,15 +48,17 @@ public class DialogGetLink extends Dialog {
|
|||
*/
|
||||
public enum Link_Type {PUBLIC_LINK, FOLDER_LINK};
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new dialog get link.
|
||||
*
|
||||
* @param headingTxt the heading txt
|
||||
* @param item the item
|
||||
* @param version the version
|
||||
* @param type the type
|
||||
* @param setAsPublic the set as public
|
||||
*/
|
||||
public DialogGetLink(String headingTxt, final FileModel item, Link_Type type, boolean setAsPublic) {
|
||||
public DialogGetLink(String headingTxt, final FileModel item, String version, Link_Type type, boolean setAsPublic) {
|
||||
this.item = item;
|
||||
this.setAsPublic = setAsPublic;
|
||||
setButtonAlign(HorizontalAlignment.CENTER);
|
||||
|
@ -101,27 +103,54 @@ public class DialogGetLink extends Dialog {
|
|||
setIcon(Resources.getIconPublicLink());
|
||||
|
||||
if(item.getIdentifier()!=null && !item.getIdentifier().isEmpty()){
|
||||
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(item.getIdentifier(), true, new AsyncCallback<PublicLink>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(PublicLink publicLink) {
|
||||
vp.unmask();
|
||||
txtCompleteURL.setValue(publicLink.getCompleteURL());
|
||||
txtShortURL.setValue(publicLink.getShortURL());
|
||||
selectTxt();
|
||||
}
|
||||
if(version==null || version.isEmpty()){
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
vp.unmask();
|
||||
if(caught instanceof SessionExpiredException){
|
||||
GWT.log("Session expired");
|
||||
AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
|
||||
return;
|
||||
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(item.getIdentifier(), true, new AsyncCallback<PublicLink>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(PublicLink publicLink) {
|
||||
vp.unmask();
|
||||
txtCompleteURL.setValue(publicLink.getCompleteURL());
|
||||
txtShortURL.setValue(publicLink.getShortURL());
|
||||
selectTxt();
|
||||
}
|
||||
new MessageBoxAlert("Error", caught.getMessage(), null);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
vp.unmask();
|
||||
if(caught instanceof SessionExpiredException){
|
||||
GWT.log("Session expired");
|
||||
AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
|
||||
return;
|
||||
}
|
||||
new MessageBoxAlert("Error", caught.getMessage(), null);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
|
||||
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemIdToVersion(item.getIdentifier(), version, true, new AsyncCallback<PublicLink>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(PublicLink publicLink) {
|
||||
vp.unmask();
|
||||
txtCompleteURL.setValue(publicLink.getCompleteURL());
|
||||
txtShortURL.setValue(publicLink.getShortURL());
|
||||
selectTxt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
vp.unmask();
|
||||
if(caught instanceof SessionExpiredException){
|
||||
GWT.log("Session expired");
|
||||
AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
|
||||
return;
|
||||
}
|
||||
new MessageBoxAlert("Error", caught.getMessage(), null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}else{
|
||||
txtCompleteURL.unmask();
|
||||
|
|
|
@ -4532,6 +4532,54 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getPublicLinkForFileItemIdToVersion(java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
@Override
|
||||
public PublicLink getPublicLinkForFileItemIdToVersion(
|
||||
String itemId, String version, boolean shortenUrl) throws Exception {
|
||||
|
||||
workspaceLogger.trace("get Public Link For ItemId: "+ itemId + " at the version: "+version);
|
||||
try{
|
||||
|
||||
if(itemId==null)
|
||||
throw new Exception("Sorry, The Public Link for empty item is unavailable (itemId is null)");
|
||||
|
||||
org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace = getWorkspaceFromStorageHub();
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem wsItem = workspace.getItem(itemId);
|
||||
|
||||
if(wsItem==null)
|
||||
throw new Exception("Sorry, The Public Link for empty item is unavailable");
|
||||
|
||||
if(wsItem.getType().equals(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType.FILE_ITEM)){
|
||||
|
||||
URL publicLink = workspace.getPublicLinkForFile(itemId, version);
|
||||
|
||||
if(publicLink==null || publicLink.toString()==null)
|
||||
throw new Exception("Sorry, public link on "+wsItem.getName() +" is not available");
|
||||
|
||||
String shortURL = null;
|
||||
String httpURL = publicLink.toString();
|
||||
|
||||
if(shortenUrl){
|
||||
shortURL = getShortUrl(httpURL);
|
||||
shortURL = shortURL!=null?shortURL:"not available";
|
||||
}
|
||||
|
||||
return new PublicLink(httpURL, shortURL);
|
||||
|
||||
}else{
|
||||
workspaceLogger.warn("ItemId: "+ itemId +" is not a file, sent exception Public Link unavailable");
|
||||
throw new Exception("Sorry, The Public Link for selected item is unavailable");
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
workspaceLogger.error("Error getPublicLinkForFileItemIdToVersion for item: "+itemId+" at the version: "+version, e);
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public enum WorkspaceVersioningOperation {
|
|||
REFRESH("Refresh", "Refresh history of versioning"),
|
||||
//RESTORE("Restore", "Restore the file to the selected version"),
|
||||
DOWNLOAD("Download", "Download the version of the selected file"),
|
||||
PUBLIC_LINK("Public Link", "Get the public link of the file at the selected version"),
|
||||
DELETE_PERMANENTLY("Delete Permanently", "Delete Permanently the version for the selected file"),
|
||||
DELETE_ALL_OLDER_VERSIONS("Delete all versions permanently", "Delete definitively all versions of the file");
|
||||
|
||||
|
|
Loading…
Reference in New Issue