331: WS: Get Public Link enhancements

Task-Url: https://support.d4science.org/issues/331

Updated Dialog Get Public Link to show complete and short URL

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@115822 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-03 10:18:27 +00:00
parent 3b09a96e09
commit 055305905f
5 changed files with 130 additions and 31 deletions

View File

@ -18,6 +18,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.ExtendedWorkspaceACL;
import org.gcube.portlets.user.workspace.shared.PublicLink;
import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.TrashContent;
@ -178,7 +179,7 @@ public interface GWTWorkspaceService extends RemoteService{
* @return
* @throws Exception
*/
String getPublicLinkForFolderItemId(String itemId, boolean shortenUrl)
PublicLink getPublicLinkForFolderItemId(String itemId, boolean shortenUrl)
throws Exception;
boolean isSessionExpired() throws Exception;

View File

@ -18,6 +18,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.ExtendedWorkspaceACL;
import org.gcube.portlets.user.workspace.shared.PublicLink;
import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL;
import org.gcube.portlets.user.workspace.shared.TrashContent;
import org.gcube.portlets.user.workspace.shared.TrashOperationContent;
@ -167,7 +168,7 @@ public interface GWTWorkspaceServiceAsync {
void getShortUrl(String longUrl, AsyncCallback<String> callback);
void getPublicLinkForFolderItemId(String itemId, boolean shortenUrl,
AsyncCallback<String> callback);
AsyncCallback<PublicLink> callback);
/**
*

View File

@ -2,14 +2,15 @@ package org.gcube.portlets.user.workspace.client.view.windows;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
import org.gcube.portlets.user.workspace.client.resources.Resources;
import org.gcube.portlets.user.workspace.shared.PublicLink;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -20,9 +21,10 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
*/
public class DialogPublicLink extends Dialog {
private TextField<String> txt;
private TextField<String> txtCompleteURL;
private TextField<String> txtShortURL;
private int widht = 450;
private int height = 150;
private int height = 170;
private VerticalPanel vp = new VerticalPanel();
// private Label label = new Label();
@ -42,38 +44,47 @@ public class DialogPublicLink extends Dialog {
// label.setText(msgTitle);
// label.setStyleName("myWebDavStyle");
VerticalPanel vp1 = new VerticalPanel();
vp1.setStyleAttribute("margin-top", "8px");
txtCompleteURL = new TextField<String>();
txtCompleteURL.setStyleAttribute("margin-top", "1px");
txtCompleteURL.setWidth(widht-20);
txtCompleteURL.setReadOnly(true);
txtCompleteURL.mask("Getting Link...");
vp1.add(new Label("Link"));
vp1.add(txtCompleteURL);
txt = new TextArea();
// txt.setStyleAttribute("padding-top", "3px");
txt.setWidth(widht-20);
txt.setHeight(height-74);
// txt.setFieldLabel(msgTitle);
txt.setReadOnly(true);
txt.mask("Shortening link...");
VerticalPanel vp2 = new VerticalPanel();
vp2.setStyleAttribute("margin-top", "8px");
txtShortURL = new TextField<String>();
txtShortURL.setStyleAttribute("margin-top", "1px");
txtShortURL.setWidth(widht-20);
txtShortURL.mask("Getting Link...");
vp2.add(new Label("Short Link"));
vp2.add(txtShortURL);
if(itemId!=null && !itemId.isEmpty()){
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFolderItemId(itemId, true, new AsyncCallback<String>() {
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFolderItemId(itemId, true, new AsyncCallback<PublicLink>() {
@Override
public void onSuccess(String url) {
txt.unmask();
txt.setValue(url);
public void onSuccess(PublicLink publicLink) {
txtCompleteURL.unmask();
txtShortURL.unmask();
txtCompleteURL.setValue(publicLink.getCompleteURL());
txtShortURL.setValue(publicLink.getShortURL());
selectTxt();
}
@Override
public void onFailure(Throwable caught) {
txt.unmask();
txtCompleteURL.unmask();
txtShortURL.unmask();
new MessageBoxAlert("Error", caught.getMessage(), null);
}
});
}else{
txt.unmask();
txtCompleteURL.unmask();
new MessageBoxAlert("Error", "The item identifier is null", null);
}
@ -88,20 +99,22 @@ public class DialogPublicLink extends Dialog {
// vp.add(label);
vp.add(txt);
vp.add(vp1);
vp.add(vp2);
setFocusWidget(txtCompleteURL);
setFocusWidget(txt);
add(vp);
}
public String getTxtValue() {
return txt.getValue();
return txtCompleteURL.getValue();
}
public void selectTxt(){
if(txt.getValue()!=null)
txt.select(0, txt.getValue().length());
if(txtCompleteURL.getValue()!=null)
txtCompleteURL.select(0, txtCompleteURL.getValue().length());
}
}

View File

@ -71,6 +71,7 @@ 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.ExtendedWorkspaceACL;
import org.gcube.portlets.user.workspace.shared.PublicLink;
import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.TrashContent;
@ -2576,7 +2577,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
* @throws Exception the exception
*/
@Override
public String getPublicLinkForFolderItemId(String itemId, boolean shortenUrl) throws Exception{
public PublicLink getPublicLinkForFolderItemId(String itemId, boolean shortenUrl) throws Exception{
workspaceLogger.trace("get Public Link For ItemId: "+ itemId);
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
@ -2607,10 +2608,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
if(!HttpRequestUtil.urlExists(uriRequest+"&validation=true"))
throw new Exception("Sorry, The Public Link for selected file is unavailable");
if(shortenUrl)
uriRequest = getShortUrl(uriRequest);
String shortURL = null;
return uriRequest;
if(shortenUrl)
shortURL = getShortUrl(uriRequest);
return new PublicLink(uriRequest, shortURL);
}
else
throw new Exception("Sorry, The Uri resolver service is temporarily unavailable. Please try again later");

View File

@ -0,0 +1,81 @@
/**
*
*/
package org.gcube.portlets.user.workspace.shared;
import java.io.Serializable;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jul 3, 2015
*/
public class PublicLink implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8157172818802297440L;
private String completeURL;
private String shortURL;
public PublicLink() {
}
/**
* @param completeURL
* @param shortURL
*/
public PublicLink(String completeURL, String shortURL) {
super();
this.completeURL = completeURL;
this.shortURL = shortURL;
}
/**
* @return the completeURL
*/
public String getCompleteURL() {
return completeURL;
}
/**
* @return the shortURL
*/
public String getShortURL() {
return shortURL;
}
/**
* @param completeURL
* the completeURL to set
*/
public void setCompleteURL(String completeURL) {
this.completeURL = completeURL;
}
/**
* @param shortURL
* the shortURL to set
*/
public void setShortURL(String shortURL) {
this.shortURL = shortURL;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PublicLink [completeURL=");
builder.append(completeURL);
builder.append(", shortURL=");
builder.append(shortURL);
builder.append("]");
return builder.toString();
}
}