From cee9e25722428212b3f00754b33e5438da5bf720 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 18 Apr 2016 16:17:48 +0000 Subject: [PATCH] refs #3483: TDM - improve the quality of the error messages for Rules https://support.d4science.org/issues/3483 Fixed Rules share git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-portlet@128126 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 6 +- distro/changelog.xml | 3 +- pom.xml | 24 +++ .../user/td/client/TabularDataController.java | 146 ++++++++++++++---- .../client/TabularDataControllerMessages.java | 47 +++--- .../client/template/TemplateShareDialog.java | 36 +++-- .../TabularDataControllerMessages.properties | 4 + ...abularDataControllerMessages_es.properties | 6 +- ...abularDataControllerMessages_it.properties | 6 +- 9 files changed, 216 insertions(+), 62 deletions(-) diff --git a/.classpath b/.classpath index 792d383..6557bc4 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -45,5 +45,5 @@ - + diff --git a/distro/changelog.xml b/distro/changelog.xml index 9ed5668..1849220 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,7 +1,8 @@ - Fix back button behavior [issue #3249] + Fixed back button behavior [issue #3249] + Fixed share of rules [Ticket #3483] diff --git a/pom.xml b/pom.xml index 55a99ae..22fba1f 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,17 @@ 1.0.1 runtime + org.gcube.contentmanagement @@ -169,6 +180,19 @@ + + org.gcube.portal diff --git a/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java b/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java index 080fa62..f28e7e9 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java +++ b/src/main/java/org/gcube/portlets/user/td/client/TabularDataController.java @@ -143,6 +143,10 @@ public class TabularDataController { private TabularDataControllerMessages msgs; private CommonMessages msgsCommon; + private enum CheckFor { + ApplyColumnRule, ApplyTableRule, ApplyTemplate; + } + public TabularDataController() { eventBus = new SimpleEventBus(); initMessages(); @@ -795,7 +799,7 @@ public class TabularDataController { eventBus.fireEvent(new UIStateEvent(UIStateType.WIZARD_OPEN)); } - public void doRibbonCommand(RibbonEvent event) { + private void doRibbonCommand(RibbonEvent event) { RibbonType type = event.getRibbonType(); Log.trace("doRibbonEvent ribbonType: " + type); try { @@ -1084,8 +1088,8 @@ public class TabularDataController { } - // TODO - public void doBackgroundRequestCommand(BackgroundRequestEvent event) { + + private void doBackgroundRequestCommand(BackgroundRequestEvent event) { BackgroundRequestType type = event.getBackgroundRequestType(); Log.trace("doBackgroundRequestEvent BackgroundRequestType: " + type); try { @@ -1746,9 +1750,8 @@ public class TabularDataController { public void onSuccess() { Log.debug("Template Apply call"); if (trId != null) { - TemplateApplyDialog taDialog = new TemplateApplyDialog( - trId, eventBus); - taDialog.show(); + retrieveTabResourceInformation(CheckFor.ApplyTemplate); + } else { Log.error("TRId is null"); UtilsGXT3.alert(msgsCommon.error(), @@ -1763,11 +1766,33 @@ public class TabularDataController { } + private void openTemplateApplyIsOwner(final TabResource tabResource) { + if (userInfo.getUsername().compareTo(tabResource.getOwnerLogin()) == 0) { + GWT.runAsync(new RunAsyncCallback() { + public void onSuccess() { + TemplateApplyDialog taDialog = new TemplateApplyDialog( + trId, eventBus); + taDialog.show(); + } + + public void onFailure(Throwable reason) { + asyncCodeLoadingFailed(reason); + } + + }); + } else { + UtilsGXT3.info(msgsCommon.attention(), + msgs.attentionNotOwnerTemplateApply()); + } + + } + private void openTemplateShare() { GWT.runAsync(new RunAsyncCallback() { public void onSuccess() { Log.debug("Template Share call"); - TemplateShareDialog tsDialog = new TemplateShareDialog(eventBus); + TemplateShareDialog tsDialog = new TemplateShareDialog( + userInfo, eventBus); tsDialog.show(); } @@ -1784,7 +1809,7 @@ public class TabularDataController { public void onSuccess() { Log.debug("Open Share Window"); @SuppressWarnings("unused") - TRShare trShare = new TRShare(trId, eventBus); + TRShare trShare = new TRShare(userInfo, trId, eventBus); } public void onFailure(Throwable reason) { @@ -1847,7 +1872,7 @@ public class TabularDataController { GWT.runAsync(new RunAsyncCallback() { public void onSuccess() { Log.debug("Request Open Share Rule Dialog"); - RuleShareDialog cfDialog = new RuleShareDialog(eventBus); + RuleShareDialog cfDialog = new RuleShareDialog(userInfo, eventBus); cfDialog.show(); } @@ -1873,24 +1898,83 @@ public class TabularDataController { } private void openOnColumnApplyRule() { - GWT.runAsync(new RunAsyncCallback() { - public void onSuccess() { - Log.debug("Request Open On Column Apply Rule Dialog"); - if (trId != null) { + Log.debug("Request Open On Column Apply Rule Dialog"); + if (trId != null) { + retrieveTabResourceInformation(CheckFor.ApplyColumnRule); + } else { + Log.error("TRId is null"); + UtilsGXT3.alert(msgsCommon.error(), + msgs.noCurrentTabularResourcePresent()); + } + + } + + private void retrieveTabResourceInformation(final CheckFor checkFor) { + TDGWTServiceAsync.INSTANCE.getTabResourceInformation(trId, + new AsyncCallback() { + + public void onSuccess(TabResource tabResource) { + Log.info("Retrieved TR: " + tabResource); + if (checkFor == null) { + UtilsGXT3.alert(msgsCommon.error(), + "Error retrieving tabular resource informations!"); + Log.error("CheckFor is null"); + return; + } + switch (checkFor) { + case ApplyColumnRule: + openOnColumnApplyRuleIsOwner(tabResource); + break; + case ApplyTableRule: + openOnTableApplyRuleIsOwner(tabResource); + break; + case ApplyTemplate: + openTemplateApplyIsOwner(tabResource); + break; + default: + break; + } + } + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + if (caught instanceof TDGWTIsLockedException) { + Log.error(caught.getLocalizedMessage()); + UtilsGXT3.alert(msgsCommon.errorLocked(), + caught.getLocalizedMessage()); + } else { + Log.error("Error retrienving properties: " + + caught.getLocalizedMessage()); + } + + } + } + + }); + } + + private void openOnColumnApplyRuleIsOwner(final TabResource tabResource) { + if (userInfo.getUsername().compareTo(tabResource.getOwnerLogin()) == 0) { + GWT.runAsync(new RunAsyncCallback() { + public void onSuccess() { RuleOnColumnApplyDialog raDialog = new RuleOnColumnApplyDialog( trId, eventBus); raDialog.show(); - } else { - Log.error("TRId is null"); - UtilsGXT3.alert(msgsCommon.error(), - msgs.noCurrentTabularResourcePresent()); } - } - public void onFailure(Throwable reason) { - asyncCodeLoadingFailed(reason); - } - }); + public void onFailure(Throwable reason) { + asyncCodeLoadingFailed(reason); + } + + }); + } else { + UtilsGXT3.info(msgsCommon.attention(), + msgs.attentionNotOwnerRuleApply()); + } + } private void openOnTableNewRule() { @@ -1935,10 +2019,20 @@ public class TabularDataController { } - // TODO private void openOnTableApplyRule() { Log.debug("Request Open On Table Apply Rule Dialog"); if (trId != null) { + retrieveTabResourceInformation(CheckFor.ApplyTableRule); + } else { + Log.error("TRId is null"); + UtilsGXT3.alert(msgsCommon.error(), + msgs.noCurrentTabularResourcePresent()); + } + + } + + private void openOnTableApplyRuleIsOwner(TabResource tabResource) { + if (userInfo.getUsername().compareTo(tabResource.getOwnerLogin()) == 0) { GWT.runAsync(new RunAsyncCallback() { public void onSuccess() { openWizard(); @@ -1975,11 +2069,9 @@ public class TabularDataController { asyncCodeLoadingFailed(reason); } }); - } else { - Log.error("TRId is null"); - UtilsGXT3.alert(msgsCommon.error(), - msgs.noCurrentTabularResourcePresent()); + UtilsGXT3.info(msgsCommon.attention(), + msgs.attentionNotOwnerRuleApply()); } } diff --git a/src/main/java/org/gcube/portlets/user/td/client/TabularDataControllerMessages.java b/src/main/java/org/gcube/portlets/user/td/client/TabularDataControllerMessages.java index 1495053..bde472e 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/TabularDataControllerMessages.java +++ b/src/main/java/org/gcube/portlets/user/td/client/TabularDataControllerMessages.java @@ -21,63 +21,70 @@ public interface TabularDataControllerMessages extends Messages { @DefaultMessage("Error in close TR: {0}") String errorInCloseTR(String localizedMessage); - + @DefaultMessage("Error in set Active TR: {0}") String errorInSetActiveTR(String localizedMessage); - + @DefaultMessage("Confirm") String confirm(); - + @DefaultMessage("Are you sure you want to delete the tabular resource?") String areYouSureYouWantToDeleteTheTabularResource(); - + @DefaultMessage("No tabular resource present") String noTabularResourcePresent(); - + @DefaultMessage("No current tabular resource present!") String noCurrentTabularResourcePresent(); - + @DefaultMessage("SDMX Import") String sdmxImport(); - + @DefaultMessage("CSV Export") String csvExport(); - + @DefaultMessage("JSON Export") String jsonExport(); - + @DefaultMessage("SDMX Export") String sdmxExport(); - + @DefaultMessage("Extract Codelist") String extractCodelist(); - + @DefaultMessage("Codelist Mapping Import") String codelistMappingImport(); - + @DefaultMessage("Union") String union(); - + @DefaultMessage("Replace By External Columns") String replaceByExternalColumns(); - + @DefaultMessage("Charts Creation") String chartsCreation(); - + @DefaultMessage("Map Creation") String mapCreation(); - + @DefaultMessage("CSV Import") String csvImport(); - + @DefaultMessage("Error on set Tabular Resource: {0}") String errorOnSetTabularResource(String localizedMessage); - + @DefaultMessage("No row selected!") String noRowSelected(); - + @DefaultMessage("No cell selected!") String noCellSelected(); - + + @DefaultMessage("In order to apply a template you must be the owner of the tabular resource. " + + "You are not the owner of this tabular resource!") + String attentionNotOwnerTemplateApply(); + + @DefaultMessage("In order to apply a rule you must be the owner of the tabular resource." + + "You are not the owner of this tabular resource!") + String attentionNotOwnerRuleApply(); } diff --git a/src/main/java/org/gcube/portlets/user/td/client/template/TemplateShareDialog.java b/src/main/java/org/gcube/portlets/user/td/client/template/TemplateShareDialog.java index 3d26056..5bc5b23 100644 --- a/src/main/java/org/gcube/portlets/user/td/client/template/TemplateShareDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/client/template/TemplateShareDialog.java @@ -2,9 +2,13 @@ package org.gcube.portlets.user.td.client.template; import org.gcube.portlets.user.td.client.resource.TabularDataResources; import org.gcube.portlets.user.td.gwtservice.shared.template.TemplateData; +import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo; import org.gcube.portlets.user.td.sharewidget.client.TemplateShare; +import org.gcube.portlets.user.td.widgetcommonevent.client.CommonMessages; +import org.gcube.portlets.user.td.wizardwidget.client.util.UtilsGXT3; import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.core.client.GWT; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.widget.core.client.Window; import com.sencha.gxt.widget.core.client.event.SelectEvent; @@ -18,14 +22,17 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; */ public class TemplateShareDialog extends Window { private static final String WIDTH = "850px"; - private static final String HEIGHT = "530px"; - + private static final String HEIGHT = "530px"; + private EventBus eventBus; + private UserInfo userInfo; + private CommonMessages msgsCommon; - public TemplateShareDialog(EventBus eventBus) { + public TemplateShareDialog(UserInfo userInfo, EventBus eventBus) { this.eventBus = eventBus; + this.userInfo = userInfo; + initMessages(); initWindow(); - TemplateSharePanel templateDeletePanel = new TemplateSharePanel(this, eventBus); add(templateDeletePanel); @@ -44,6 +51,11 @@ public class TemplateShareDialog extends Window { } + private void initMessages() { + //msgs = GWT.create(TabularDataControllerMessages.class); + msgsCommon = GWT.create(CommonMessages.class); + } + /** * {@inheritDoc} */ @@ -64,13 +76,19 @@ public class TemplateShareDialog extends Window { hide(); } - public void templateShare(TemplateData templateData) { Log.debug("Share Window"); - @SuppressWarnings("unused") - TemplateShare templateShare = new TemplateShare(templateData, eventBus); - close(); + if (userInfo.getUsername().compareTo(templateData.getOwnerLogin()) == 0) { + @SuppressWarnings("unused") + TemplateShare templateShare = new TemplateShare(userInfo, + templateData, eventBus); + close(); + } else { + UtilsGXT3 + .info(msgsCommon.attention(), + "In order to share a template you must be the owner of the template. " + + "You are not the owner of this template!"); + } } - } diff --git a/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages.properties b/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages.properties index 53c8db1..c866748 100644 --- a/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages.properties +++ b/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages.properties @@ -21,3 +21,7 @@ mapCreation = Map Creation errorOnSetTabularResource = Error on set Tabular Resource: {0} noRowSelected = No row selected! noCellSelected = No cell selected! +attentionNotOwnerTemplateApply = In order to apply a template you must be the owner of the Tabular Resource. \ +You are not the owner of this Tabular Resource! +attentionNotOwnerRuleApply = In order to apply a rule you must be the owner of the Tabular Resource. \ +You are not the owner of this Tabular Resource! diff --git a/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages_es.properties b/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages_es.properties index 70cc5ff..492e26a 100644 --- a/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages_es.properties +++ b/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages_es.properties @@ -20,4 +20,8 @@ chartsCreation = Crea gráfico mapCreation = Crea Mapa errorOnSetTabularResource = Error en poner la Tabular Resource: {0} noRowSelected = Ninguna línea seleccionada! -noCellSelected = Ninguna célula selezionata! \ No newline at end of file +noCellSelected = Ninguna célula selezionata! +attentionNotOwnerTemplateApply = Con el fin de aplicar una plantilla que debe ser el propietario de la Tabular Resource. \ +Usted no es el propietario de este Tablurar Resource! +attentionNotOwnerRuleApply = Con el fin de aplicar una regla debe ser el propietario de la Tabular Resource. \ +Usted no es el propietario de este Tabular Resource! \ No newline at end of file diff --git a/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages_it.properties b/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages_it.properties index bf0ab44..f43b467 100644 --- a/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages_it.properties +++ b/src/main/resources/org/gcube/portlets/user/td/client/TabularDataControllerMessages_it.properties @@ -20,4 +20,8 @@ chartsCreation = Crea Grafico mapCreation = Crea Mappa errorOnSetTabularResource = Errore nel settare la Tabular Resource: {0} noRowSelected = Nessuna riga selezionata! -noCellSelected = Nessuna cella selezionata! \ No newline at end of file +noCellSelected = Nessuna cella selezionata! +attentionNotOwnerTemplateApply = Per poter applicare un template bisogna essere il proprietario della Tabular Resource. \ +Non sei il proprietario di questa Tabular Resource! +attentionNotOwnerRuleApply = Per poter applicare una rule bisogna essere il proprietario della Tabular Resource. \ +Non sei il proprietario di questa Tabular Resource! \ No newline at end of file