Francesco Mangiacrapa 5 years ago
parent 35ff7512b1
commit 48d3f2f3c9

@ -186,33 +186,33 @@
</dependency>
<!-- HOME LIBRARY -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>home-library-model</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>home-library-jcr</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <artifactId>asm-debug-all</artifactId> -->
<!-- <groupId>org.ow2.asm</groupId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>home-library</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <artifactId>asm-all</artifactId> -->
<!-- <groupId>asm</groupId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>home-library-model</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>home-library-jcr</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <artifactId>asm-debug-all</artifactId> -->
<!-- <groupId>org.ow2.asm</groupId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>home-library</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <artifactId>asm-all</artifactId> -->
<!-- <groupId>asm</groupId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
@ -220,6 +220,13 @@
<version>[0.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>switch-button-widget</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>

@ -31,6 +31,8 @@
<inherits name='org.gcube.portlets.widgets.wsexplorer.WorkspaceExplorer' />
<inherits name='org.gcube.portlets.widgets.switchbutton.SwitchButton' />
<inherits name='org.gcube.portlets.widgets.wsthreddssync.WsThreddsWidget' />
<inherits

@ -122,6 +122,7 @@ import org.gcube.portlets.user.workspace.client.view.windows.DialogGetInfo;
import org.gcube.portlets.user.workspace.client.view.windows.DialogGetLink;
import org.gcube.portlets.user.workspace.client.view.windows.DialogGetLink.Link_Type;
import org.gcube.portlets.user.workspace.client.view.windows.DialogShareLink;
import org.gcube.portlets.user.workspace.client.view.windows.DialogShareableLink;
import org.gcube.portlets.user.workspace.client.view.windows.DialogText;
import org.gcube.portlets.user.workspace.client.view.windows.ImagesPreviewController;
import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplayMessage;
@ -921,11 +922,15 @@ 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(), getPublicLinkEvent.getVersion(), Link_Type.PUBLIC_LINK,
false);
dialog.show();
// DialogGetLink dialog = new DialogGetLink("Copy to clipboard Public Link: Ctrl+C",
// getPublicLinkEvent.getSourceFile(), getPublicLinkEvent.getVersion(), Link_Type.PUBLIC_LINK,
// false);
// dialog.show();
new DialogShareableLink(getPublicLinkEvent.getSourceFile(), getPublicLinkEvent.getVersion());
}
}
});

@ -0,0 +1,467 @@
package org.gcube.portlets.user.workspace.client.view.windows;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer.WsPortletInitOperation;
import org.gcube.portlets.user.workspace.client.event.RefreshFolderEvent;
import org.gcube.portlets.user.workspace.client.event.SessionExpiredEvent;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.shared.PublicLink;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.widgets.switchbutton.client.SwitchButton;
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
import com.extjs.gxt.ui.client.util.Format;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.Fieldset;
import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.ModalFooter;
import com.github.gwtbootstrap.client.ui.Row;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.Well;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class DialogShareableLink.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Sep 19, 2019
*/
public class DialogShareableLink extends Composite {
private static DialogShareableLinkUiBinder uiBinder = GWT.create(DialogShareableLinkUiBinder.class);
private Modal modalBox = new Modal();
@UiField
ControlGroup cgPublicLink;
// @UiField
// ControlGroup cgRemovePublicLink;
@UiField
ControlGroup cgPrivateLink;
@UiField
TextBox textPublicLink;
@UiField
TextBox textPrivateLink;
// @UiField
// Button removePublicLink;
@UiField
Alert errorAlert;
@UiField
Alert actionAlert;
@UiField
Well alertFilePublicLink;
@UiField
Well alertFolderPublicLink;
@UiField
Fieldset fieldSet;
@UiField
SwitchButton switchButton;
@UiField
Row filedEnableDisableSharing;
@UiField
Label labelLinkSharing;
@UiField
HTMLPanel panelFieldsContainer;
private FileModel fileItem;
private String fileVersion;
private boolean itemIsPublicStatus;
/**
* The Interface DialogShareableLinkUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Sep 19, 2019
*/
interface DialogShareableLinkUiBinder extends UiBinder<Widget, DialogShareableLink> {
}
/**
* Instantiates a new dialog shareable link.
*
* @param item the item
* @param version the version
*/
public DialogShareableLink(FileModel item, String version) {
initWidget(uiBinder.createAndBindUi(this));
this.fileItem = item;
this.fileVersion = version;
this.actionAlert.setAnimation(true);
showShareableLinkOptions(item, version);
//getElement().setClassName("gwt-DialogBoxNew");
modalBox.setTitle("Get Shareable Link to: "+Format.ellipse(item.getName(), 15));
ModalFooter modalFooter = new ModalFooter();
final Button buttClose = new Button("Close");
modalFooter.add(buttClose);
switchButton.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
GWT.log("Switch to: "+event.getValue());
acessToFolderLink(fileItem, event.getValue());
}
});
buttClose.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
modalBox.hide();
}
});
modalBox.add(this);
modalBox.add(modalFooter);
modalBox.show();
}
/**
* Show shareable link options.
*
* @param item the item
* @param version the version
*/
public void showShareableLinkOptions(FileModel item, String version) {
//cgRemovePublicLink.setVisible(false);
cgPrivateLink.setVisible(false);
cgPublicLink.setVisible(true);
alertFilePublicLink.setVisible(false);
alertFolderPublicLink.setVisible(false);
filedEnableDisableSharing.setVisible(false);
panelFieldsContainer.setVisible(false);
showMessage("", false);
this.itemIsPublicStatus = item.isPublic();
if(item.isDirectory()) { //CASE FOLDER - MANAGING AS PUBLIC LINK TO FOLDER
switchButton.setValue(item.isPublic());
//IT IS PRIVATE LINK
if(item.isPublic()) { //CASE PUBLIC FOLDER
alertFolderPublicLink.setVisible(true);
//cgRemovePublicLink.setVisible(true);
filedEnableDisableSharing.setVisible(true);
labelLinkSharing.setText("Anyone with the Public Link can access to the content");
panelFieldsContainer.setVisible(true);
acessToFolderLink(item, true);
}
if(item.isShared()) { //CASE SHARED FOLDER
panelFieldsContainer.setVisible(true);
cgPrivateLink.setVisible(true);
loadAndShowPrivateLink(item, textPrivateLink);
if(!item.isPublic()) { //THE FOLDER IS NOT PUBLIC
cgPublicLink.setVisible(false);
filedEnableDisableSharing.setVisible(true);
labelLinkSharing.setText("");
//labelLinkSharing.setText("Only your cowokers (sharing members) can access to the content");
}
}
//THE FOLDER IS PRIVATE - NO SHARED AND NO PUBLIC
if(!item.isPublic() && !item.isShared()) {
filedEnableDisableSharing.setVisible(true);
alertFolderPublicLink.setVisible(true);
labelLinkSharing.setText("The folder is private, not shared");
}
}else { //CASE FILE - MANAGING AS PUBLIC LINK TO FILE
panelFieldsContainer.setVisible(true);
alertFilePublicLink.setVisible(true);
if(!item.isPublic()) { //THE FILE IS PRIVATE
if(version!=null && !version.isEmpty()) {
showPublicLinkForFileItemIdToVersion(item, textPublicLink, version);
}else {
loadAndShowPublicLinkForItem(item, textPublicLink);
}
}else {
//???
}
}
}
/**
* Load and show private link.
*
* @param item the item
* @param toTextBox the to text box
*/
private void loadAndShowPrivateLink(FileModel item, TextBox toTextBox) {
String currentUrl = portalURL();
int lastChar = currentUrl.lastIndexOf("?");
currentUrl = lastChar > -1 ? currentUrl.substring(0, lastChar) : currentUrl;
String shareLinkUrl = currentUrl + "?" + ConstantsExplorer.GET_ITEMID_PARAMETER + "=" + item.getIdentifier();
shareLinkUrl += "&" + ConstantsExplorer.GET_OPERATION_PARAMETER + "=" + WsPortletInitOperation.gotofolder;
toTextBox.setText(shareLinkUrl);
}
/**
* Portal url.
*
* @return the string
*/
public static native String portalURL()/*-{
return $wnd.location.href;
}-*/;
/**
* Load and show public link for item.
*
* @param item the item
* @param toTextBox the to text box
*/
private void loadAndShowPublicLinkForItem(FileModel item, final TextBox toTextBox) {
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemId(item.getIdentifier(), true,
new AsyncCallback<PublicLink>() {
@Override
public void onSuccess(PublicLink publicLink) {
String toURL = publicLink.getShortURL() != null && !publicLink.getShortURL().isEmpty()
? publicLink.getShortURL()
: publicLink.getCompleteURL();
toTextBox.setValue(toURL);
}
@Override
public void onFailure(Throwable caught) {
if (caught instanceof SessionExpiredException) {
GWT.log("Session expired");
AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
return;
}
//new MessageBoxAlert("Error", caught.getMessage(), null);
//toTextBox.setText(caught.getMessage());
showError(caught.getMessage());
}
});
}
/**
* Show public link for file item id to version.
*
* @param item the item
* @param toTextBox the to text box
* @param version the version
*/
private void showPublicLinkForFileItemIdToVersion(FileModel item, final TextBox toTextBox, final String version) {
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFileItemIdToVersion(item.getIdentifier(),
version, true, new AsyncCallback<PublicLink>() {
@Override
public void onSuccess(PublicLink publicLink) {
String toURL = getValidURL(publicLink);
toTextBox.setValue(toURL);
}
@Override
public void onFailure(Throwable caught) {
if (caught instanceof SessionExpiredException) {
GWT.log("Session expired");
AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
return;
}
//new MessageBoxAlert("Error", caught.getMessage(), null);
showError(caught.getMessage());
}
});
}
/**
* Show error.
*
* @param msg the msg
*/
private void showError(String msg) {
errorAlert.setVisible(true);
errorAlert.setText(msg);
}
/**
* Gets the valid URL.
*
* @param publicLink the public link
* @return the valid URL
*/
private String getValidURL(PublicLink publicLink) {
if(publicLink==null)
return "Error on getting a valid shareble link";
return publicLink.getShortURL() != null && !publicLink.getShortURL().isEmpty()
? publicLink.getShortURL()
: publicLink.getCompleteURL();
}
/**
* Acess to folder link.
*
* @param item the item
* @param setAsPublic the set as public
*/
private void acessToFolderLink(final FileModel item, final boolean setAsPublic) {
panelFieldsContainer.setVisible(false);
WorkspaceSharingServiceAsync.INSTANCE.accessToFolderLink(item.getIdentifier(),
new AsyncCallback<AllowAccess>() {
@Override
public void onFailure(Throwable caught) {
panelFieldsContainer.setVisible(false);
if (caught instanceof SessionExpiredException) {
GWT.log("Session expired");
AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
return;
}
showError(caught.getMessage());
}
@Override
public void onSuccess(AllowAccess result) {
panelFieldsContainer.setVisible(true);
GWT.log("AllowAccess? " + result);
if (result.getAccessGranted()) {
String msg = setAsPublic ? "Getting" : "Removing";
msg = msg + " Public Link... permissions granted";
showMessage(msg, true);
allowAccessToFolderLink(item.getIdentifier(), setAsPublic);
} else {
showError("Permission Denied!" + " "+result.getAccessAllowDenyMotivation());
}
}
});
}
/**
* Show message.
*
* @param msg the msg
* @param visible the visible
*/
private void showMessage(String msg, boolean visible) {
actionAlert.setVisible(visible);
actionAlert.setText(msg==null?"":msg);
}
/**
* Allow access to folder link.
*
* @param folderId
* the folder id
* @param setIsPublic
* the set is public
*/
protected void allowAccessToFolderLink(String folderId, final boolean setIsPublic) {
AppControllerExplorer.rpcWorkspaceService.markFolderAsPublicForFolderItemId(folderId, setIsPublic,
new AsyncCallback<PublicLink>() {
@Override
public void onSuccess(PublicLink publicLink) {
if (!setIsPublic && publicLink == null) {
String msg = "Public Link to the folder '" + fileItem.getName() + "' removed correctly";
showMessage(msg, true);
AppControllerExplorer.getEventBus().fireEvent(new RefreshFolderEvent(fileItem.getParentFileModel(), true, false, false));
//REFRESHING ONLY ON CHANGING STATUS
if(itemIsPublicStatus) {
//HERE THE PREVIOUS STATUS WAS ISPUBLIC = TRUE
fileItem.setIsPublic(false);
showShareableLinkOptions(fileItem,fileVersion);
}
return;
}
textPublicLink.setValue(publicLink.getCompleteURL());
// txtShortURL.setValue(publicLink.getShortURL());
// selectTxt();
Timer t = new Timer() {
@Override
public void run() {
GWT.log("Runing refresh after wait: " + AppControllerExplorer.delayTime);
AppControllerExplorer.getEventBus()
.fireEvent(new RefreshFolderEvent(fileItem.getParentFileModel(), true, false, false));
}
};
t.schedule(AppControllerExplorer.delayTime);
showMessage("", false);
//REFRESHING ONLY ON CHANGING STATUS
if(!itemIsPublicStatus) {
//HERE THE PREVIOUS STATUS WAS ISPUBLIC = FALSE
fileItem.setIsPublic(true);
showShareableLinkOptions(fileItem,fileVersion);
}
}
@Override
public void onFailure(Throwable caught) {
panelFieldsContainer.setVisible(false);
if (caught instanceof SessionExpiredException) {
GWT.log("Session expired");
AppControllerExplorer.getEventBus().fireEvent(new SessionExpiredEvent());
return;
}
showError(caught.getMessage());
}
});
}
}

@ -0,0 +1,109 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:citem="urn:import:org.gcube.portlets.widgets.switchbutton.client">
<ui:style>
.textbox-width {
width: 200px;
}
.back-color-info {
background-color: #fafaff !important;
}
.margin-bottom-20 {
margin-bottom: 20px;
}
.padding-left-30 {
padding-left: 30px;
margin-top: 5px;
}
.text-bold {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<b:Form type="HORIZONTAL">
<b:Row ui:field="filedEnableDisableSharing"
addStyleNames="{style.margin-bottom-20}">
<b:Column size="1">
<b:Label type="INFO">Link Sharing</b:Label>
</b:Column>
<b:Column size="2">
<citem:SwitchButton ui:field="switchButton"></citem:SwitchButton>
</b:Column>
<b:Row>
<b:Column size="4" addStyleNames="{style.padding-left-30}">
<g:Label ui:field="labelLinkSharing"></g:Label>
</b:Column>
</b:Row>
</b:Row>
<b:Fieldset ui:field="fieldSet">
<!-- <b:Alert close="false" ui:field="actionAlert" type="ERROR" -->
<!-- visible="false"></b:Alert> -->
<b:Alert ui:field="actionAlert" close="false" type="INFO"
visible="false">
<b:Icon type="ROTATE_RIGHT" spin="true" />
</b:Alert>
<g:HTMLPanel ui:field="panelFieldsContainer">
<!-- <b:Legend>sharing....</b:Legend> -->
<b:ControlGroup ui:field="cgPublicLink">
<b:Well ui:field="alertFolderPublicLink" visible="false">By sharing
via Public
Link
to folder with
your coworkers you will
enact anyone
with the
link to
view the
content, no login will be
requested</b:Well>
<b:Well ui:field="alertFilePublicLink" visible="false">By sharing a
Public Link
to
file your coworkers can download it.
No login will be
requested.
The link will always point to the version
of file at the
time of
public link creation</b:Well>
<b:ControlLabel>Public Link</b:ControlLabel>
<b:Controls>
<b:InputAddOn prependIcon="GLOBE">
<b:TextBox ui:field="textPublicLink" readOnly="true">
</b:TextBox>
</b:InputAddOn>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="cgPrivateLink">
<b:Well>
By sharing via Private Link
with
your
coworkers you will
enact users (only the members belonging to the shared folder),
after login, to access
the
content</b:Well>
<b:ControlLabel>Private Link</b:ControlLabel>
<b:Controls>
<b:InputAddOn prependIcon="LINK">
<b:TextBox ui:field="textPrivateLink" readOnly="true">
</b:TextBox>
</b:InputAddOn>
</b:Controls>
</b:ControlGroup>
</g:HTMLPanel>
</b:Fieldset>
<b:Alert close="false" ui:field="errorAlert" type="ERROR"
visible="false"></b:Alert>
</b:Form>
</g:HTMLPanel>
</ui:UiBinder>
Loading…
Cancel
Save