diff --git a/distro/changelog.xml b/distro/changelog.xml index 3fd738f..a0f7846 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -3,7 +3,10 @@ date="${buildDate}"> Updated regular expression to validate Folder and File names - [Task #12911] Called getFullName for any user other than logged user + [Task #12911] Called getFullName for any user other than + logged user + + [Task #12909:] Provide public links for versioned files { public static Type TYPE = new Type(); 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 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; + } } \ No newline at end of file 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 696a00f..f171a55 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 @@ -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 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; + + } 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 813d00a..bff8ccc 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 @@ -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 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 callback); + + /** * Checks if is session expired. * @@ -489,10 +504,24 @@ public interface GWTWorkspaceServiceAsync { void deleteListItemsForIds(List ids, AsyncCallback> callback); + /** + * Copy items. + * + * @param idsItem the ids item + * @param destinationFolderId the destination folder id + * @param callback the callback + */ void copyItems( List idsItem, String destinationFolderId, AsyncCallback callback); + /** + * Move items. + * + * @param ids the ids + * @param destinationId the destination id + * @param callback the callback + */ void moveItems( List ids, String destinationId, AsyncCallback callback); @@ -768,6 +797,13 @@ public interface GWTWorkspaceServiceAsync { */ void isItemUnderSync(String itemId, AsyncCallback 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 callback); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java index 44ba610..ecf7a9d 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java @@ -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)); } } }); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetLink.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetLink.java index 61c399c..d09568b 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetLink.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetLink.java @@ -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() { - @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() { + + @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() { + + @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(); 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 6be71d5..53947d1 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 @@ -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()); + } + } + + } 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 78cd1ed..353a1e3 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 @@ -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");