From 55a487142e482c98faa5da94cdb0508587bd21a9 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 22 Apr 2015 12:18:37 +0000 Subject: [PATCH] Added the sharing of rules git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-share-widget@114326 82a268e6-3cf1-43bd-a215-b396298e98cf --- TemplateShare.java | 130 ++++++++++++++++++ .../user/td/sharewidget/client/RuleShare.java | 125 +++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 TemplateShare.java create mode 100644 src/main/java/org/gcube/portlets/user/td/sharewidget/client/RuleShare.java diff --git a/TemplateShare.java b/TemplateShare.java new file mode 100644 index 0000000..975b0ad --- /dev/null +++ b/TemplateShare.java @@ -0,0 +1,130 @@ +package org.gcube.portlets.user.td.sharewidget.client; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts; +import org.gcube.portlets.user.td.gwtservice.shared.share.ShareTemplate; +import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; +import org.gcube.portlets.user.td.sharewidget.client.util.UtilsGXT3; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; +import org.gcube.portlets.widgets.workspacesharingwidget.client.WorkspaceSmartSharingController; +import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.SmartShare; +import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel; +import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel; + +import com.allen_sauer.gwt.log.client.Log; +import com.extjs.gxt.ui.client.event.BaseEvent; +import com.extjs.gxt.ui.client.event.Events; +import com.extjs.gxt.ui.client.event.Listener; +import com.extjs.gxt.ui.client.widget.Dialog; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.web.bindery.event.shared.EventBus; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class TemplateShare { + + private EventBus eventBus; + private TemplateData templateData; + private ShareTemplate shareTemplate; + + public TemplateShare(TemplateData templateData, EventBus eventBus) { + this.templateData=templateData; + this.eventBus = eventBus; + + shareWindow(); + } + + + + + /** + * Call Window + */ + protected void shareWindow() { + + FileModel file = new FileModel(String.valueOf(templateData.getId()), templateData.getName(), false); + + List listAlreadySharedContact = new ArrayList(); + for (Contacts contacts : templateData.getContacts()) { + CredentialModel cm = new CredentialModel(null, contacts.getLogin(), + false); + listAlreadySharedContact.add(cm); + } + + WorkspaceSmartSharingController controller = new WorkspaceSmartSharingController( + file, listAlreadySharedContact, false, true); + + final SmartShare sharingWindow = controller.getSharingDialog(); + + sharingWindow.show(); + + sharingWindow.getButtonById(Dialog.OK).addListener(Events.Select, + new Listener() { + + @Override + public void handleEvent(BaseEvent be) { + + if (sharingWindow.isValidForm(true)) { + shareCall(sharingWindow + .getSharedListUsersCredential()); + + } + + } + }); + + } + + protected void shareCall(List credentials) { + ArrayList listContacts = new ArrayList(); + for (CredentialModel cred : credentials) { + Contacts cont = new Contacts(cred.getId(), cred.getLogin(), + cred.isGroup()); + listContacts.add(cont); + } + shareTemplate=new ShareTemplate(templateData,listContacts); + + TDGWTServiceAsync.INSTANCE.setShareTemplate(shareTemplate, + new AsyncCallback() { + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.debug("Share Error: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Error sharing template", + "Error sharing template: " + + caught.getLocalizedMessage()); + } + } + + public void onSuccess(Void result) { + Log.debug("Template Shared: " + + shareTemplate.getTemplateData().getId()); + UtilsGXT3.info("Shared", "Template is shared"); + /* + ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED; + ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( + ChangeTableRequestType.SHARE, trId, why); + eventBus.fireEvent(changeTableRequestEvent);*/ + + } + + }); + + } + + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/sharewidget/client/RuleShare.java b/src/main/java/org/gcube/portlets/user/td/sharewidget/client/RuleShare.java new file mode 100644 index 0000000..a2809ea --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/sharewidget/client/RuleShare.java @@ -0,0 +1,125 @@ +package org.gcube.portlets.user.td.sharewidget.client; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData; +import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts; +import org.gcube.portlets.user.td.gwtservice.shared.share.ShareRule; +import org.gcube.portlets.user.td.sharewidget.client.util.UtilsGXT3; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; +import org.gcube.portlets.widgets.workspacesharingwidget.client.WorkspaceSmartSharingController; +import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.SmartShare; +import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel; +import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel; + +import com.allen_sauer.gwt.log.client.Log; +import com.extjs.gxt.ui.client.event.BaseEvent; +import com.extjs.gxt.ui.client.event.Events; +import com.extjs.gxt.ui.client.event.Listener; +import com.extjs.gxt.ui.client.widget.Dialog; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.web.bindery.event.shared.EventBus; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class RuleShare { + + private EventBus eventBus; + private RuleDescriptionData ruleDescriptionData; + private ShareRule shareRule; + + public RuleShare(RuleDescriptionData ruleData, EventBus eventBus) { + this.ruleDescriptionData=ruleData; + this.eventBus = eventBus; + + shareWindow(); + } + + + + + /** + * Call Window + */ + protected void shareWindow() { + + FileModel file = new FileModel(String.valueOf(ruleDescriptionData.getId()), ruleDescriptionData.getName(), false); + + List listAlreadySharedContact = new ArrayList(); + for (Contacts contacts : ruleDescriptionData.getContacts()) { + CredentialModel cm = new CredentialModel(null, contacts.getLogin(), + false); + listAlreadySharedContact.add(cm); + } + + WorkspaceSmartSharingController controller = new WorkspaceSmartSharingController( + file, listAlreadySharedContact, false, true); + + final SmartShare sharingWindow = controller.getSharingDialog(); + + sharingWindow.show(); + + sharingWindow.getButtonById(Dialog.OK).addListener(Events.Select, + new Listener() { + + @Override + public void handleEvent(BaseEvent be) { + + if (sharingWindow.isValidForm(true)) { + shareCall(sharingWindow + .getSharedListUsersCredential()); + + } + + } + }); + + } + + protected void shareCall(List credentials) { + ArrayList listContacts = new ArrayList(); + for (CredentialModel cred : credentials) { + Contacts cont = new Contacts(cred.getId(), cred.getLogin(), + cred.isGroup()); + listContacts.add(cont); + } + shareRule=new ShareRule(ruleDescriptionData,listContacts); + + TDGWTServiceAsync.INSTANCE.setShareRule(shareRule, + new AsyncCallback() { + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + Log.debug("Share Error: " + + caught.getLocalizedMessage()); + UtilsGXT3.alert("Error sharing rule", + "Error sharing rule: " + + caught.getLocalizedMessage()); + } + } + + public void onSuccess(Void result) { + Log.debug("Rule Shared: " + + shareRule.getRuleDescriptionData().getId()); + UtilsGXT3.info("Shared", "Rule is shared"); + + } + + }); + + } + + + +} \ No newline at end of file