From dde28ced0cc6e4ee35b50e37a7495181ca96a01a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 16 Feb 2024 15:35:09 +0100 Subject: [PATCH] Intragrated with the Workspace (Select file from Workspace) --- pom.xml | 5 + .../client/CKanPublisherService.java | 10 + .../client/CKanPublisherServiceAsync.java | 17 +- .../events/WorkspaceItemSelectedEvent.java | 51 +++++ .../WorkspaceItemSelectedEventHandler.java | 20 ++ .../client/ui/form/CreateDatasetForm.java | 2 - .../client/ui/form/UpdateDatasetForm.java | 26 --- .../ui/resources/AddResourceToDataset.java | 201 +++++++++++++----- .../ui/resources/AddResourceToDataset.ui.xml | 14 +- .../ui/resources/DialogWorkspaceExplorer.java | 113 ++++++++++ .../resources/DialogWorkspaceExplorer.ui.xml | 24 +++ .../server/CKANPublisherServicesImpl.java | 50 +++-- 12 files changed, 429 insertions(+), 104 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEvent.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/DialogWorkspaceExplorer.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/DialogWorkspaceExplorer.ui.xml diff --git a/pom.xml b/pom.xml index 37f6994..74aab4f 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,11 @@ gcubedatacatalogue-metadata-discovery [3.0.0, 4.0.0-SNAPSHOT) + + org.gcube.portlets.user + uri-resolver-manager + [1.0.0, 2.0.0-SNAPSHOT) + junit junit diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java index 026bb42..00f7d57 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java @@ -162,4 +162,14 @@ public interface CKanPublisherService extends RemoteService { * @throws Exception the exception */ DatasetBean updateCKANDataset(DatasetBean toUpdate) throws Exception; + + /** + * Gets the public link for file item id. + * + * @param itemId the item id + * @param shortenUrl the shorten url + * @return the public link for file item id + * @throws Exception the exception + */ + String getPublicLinkForFileItemId(String itemId, boolean shortenUrl) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java index 778880e..154111a 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherServiceAsync.java @@ -48,10 +48,10 @@ public interface CKanPublisherServiceAsync { /** * Add this resource to the dataset whose id is datasetId. * - * @param resource the resource + * @param resource the resource * @param organizationName the organization name - * @param datasetId the dataset id - * @param callback the callback + * @param datasetId the dataset id + * @param callback the callback */ void addResourceToDataset(ResourceElementBean resource, String organizationName, String datasetId, AsyncCallback callback); @@ -167,4 +167,15 @@ public interface CKanPublisherServiceAsync { * @throws Exception the exception */ void updateCKANDataset(DatasetBean toUpdate, AsyncCallback callaback); + + /** + * Gets the public link for file item id. + * + * @param itemId the item id + * @param shortenUrl the shorten url + * @param callaback the callaback + * @return the public link for file item id + * @throws Exception the exception + */ + void getPublicLinkForFileItemId(String itemId, boolean shortenUrl, AsyncCallback callaback); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEvent.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEvent.java new file mode 100644 index 0000000..0f2c98c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEvent.java @@ -0,0 +1,51 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events; + +import org.gcube.portlets.widgets.wsexplorer.shared.Item; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class WorkspaceItemSelectedEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 16, 2024 + */ +public class WorkspaceItemSelectedEvent extends GwtEvent { + public static Type TYPE = new Type(); + + private Item item; + + /** + * Instantiates a new workspace item selected event. + * + * @param resource the resource + */ + public WorkspaceItemSelectedEvent(Item item) { + this.item = item; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(WorkspaceItemSelectedEventHandler handler) { + handler.onSelectedItem(this); + } + + public Item getItem() { + return item; + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEventHandler.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEventHandler.java new file mode 100644 index 0000000..146860f --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/events/WorkspaceItemSelectedEventHandler.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events; + +import com.google.gwt.event.shared.EventHandler; + +/** + * The Interface WorkspaceItemSelectedEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Feb 16, 2024 + */ +public interface WorkspaceItemSelectedEventHandler extends EventHandler { + + /** + * On selected item. + * + * @param workspaceItemSelectedEvent the workspace item selected event + */ + void onSelectedItem(WorkspaceItemSelectedEvent workspaceItemSelectedEvent); +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index dae9806..cf31936 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -20,7 +20,6 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCu import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.ReloadDatasetPageEvent; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.ReloadDatasetPageEventHandler; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.CustomFieldEntry; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.AddResourceToDataset; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.ManageResources; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.WizardCreator; @@ -46,7 +45,6 @@ import com.github.gwtbootstrap.client.ui.Icon; import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.Paragraph; import com.github.gwtbootstrap.client.ui.Popover; -import com.github.gwtbootstrap.client.ui.TabPanel; import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.constants.AlertType; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.java index ccacf09..2af62b5 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/UpdateDatasetForm.java @@ -1014,26 +1014,6 @@ public class UpdateDatasetForm extends Composite { actionsAfterOnContinue(); else { actionsAfterOnContinue(); -// alertOnContinue("Checking if a item with such title already exists, please wait...", AlertType.INFO); -// final String orgName = nameTitleOrganizationMap.get(organizationsListbox.getSelectedItemText()); -// ckanServices.datasetIdAlreadyExists(titleTextBox.getText(), orgName, new AsyncCallback() { -// -// @Override -// public void onSuccess(Boolean result) { -// if (result) { -// alertOnContinue("Sorry but an item with such title already exists, try to change it", -// AlertType.WARNING); -// } else { -// actionsAfterOnContinue(); -// } -// } -// -// @Override -// public void onFailure(Throwable caught) { -// alertOnContinue("Sorry but there was a problem while checking if the inserted data are correct", -// AlertType.ERROR); -// } -// }); } } } @@ -1399,10 +1379,6 @@ public class UpdateDatasetForm extends Composite { ManageResources manageResources = new ManageResources(eventBusPublisherWidget, theDatasetBean, datasetUrl); - // form container -// AddResourceContainer container = new AddResourceContainer(datasetUrl); -// container.add(tabPanel); - // add the new content of the main panel createDatasetMainPanel.add(manageResources); @@ -1414,8 +1390,6 @@ public class UpdateDatasetForm extends Composite { manageResources.getEventBus().fireEvent(new AddResourceEvent(reb)); } } - - // ((NavLink) tabPanel.getWidget(1)).setActive(true); } /** diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java index c008a61..5261dab 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java @@ -4,9 +4,12 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherSe import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEvent; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.ReloadDatasetPageEvent; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.WorkspaceItemSelectedEvent; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.WorkspaceItemSelectedEventHandler; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.LoaderIcon; +import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.ControlGroup; @@ -15,6 +18,7 @@ import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; @@ -25,20 +29,21 @@ import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.DialogBox; import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Widget; /** * Form used to add resource(s) to a dataset + * * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) */ -public class AddResourceToDataset extends Composite{ +public class AddResourceToDataset extends Composite { - private static AddResourceToDatasetUiBinder uiBinder = GWT - .create(AddResourceToDatasetUiBinder.class); + private static AddResourceToDatasetUiBinder uiBinder = GWT.create(AddResourceToDatasetUiBinder.class); - interface AddResourceToDatasetUiBinder extends - UiBinder { + interface AddResourceToDatasetUiBinder extends UiBinder { } // bus to alert the dataset form about this new resource @@ -52,30 +57,46 @@ public class AddResourceToDataset extends Composite{ private final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class); - @UiField TextBox resourceUrlTextBox; - @UiField TextBox resourceNameTextBox; - @UiField TextArea resourceDescriptionTextArea; - @UiField Button addResourceButton; - @UiField AlertBlock infoBlock; - @UiField Button goToDatasetButton; - @UiField ControlGroup urlControlGroup; - @UiField ControlGroup nameControlGroup; - @UiField FlowPanel infoPanel; + @UiField + TextBox resourceUrlTextBox; + @UiField + TextBox resourceNameTextBox; + @UiField + TextArea resourceDescriptionTextArea; + @UiField + Button addResourceButton; + @UiField + AlertBlock infoBlock; + @UiField + Button goToDatasetButton; + @UiField + ControlGroup urlControlGroup; + @UiField + ControlGroup nameControlGroup; + @UiField + FlowPanel infoPanel; + @UiField + Button buttoSelectFromWorkspace; + @UiField + Alert alertInfoURL; - public AddResourceToDataset(HandlerManager eventBus, final String datasetId, String datasetTitle, final String datasetOrg, final String datasetUrl) { + FlowPanel alertPanel = new FlowPanel(); + + public AddResourceToDataset(HandlerManager eventBus, final String datasetId, String datasetTitle, + final String datasetOrg, final String datasetUrl) { initWidget(uiBinder.createAndBindUi(this)); // save bus this.eventBus = eventBus; // save dataset id (it is needed when we will add resources) this.datasetId = datasetId; this.datasetOrg = datasetOrg; - + String title = datasetTitle; String link = ""; link += title.length() > 90 ? title.substring(0, 90) + "..." : title; - goToDatasetButton.setTitle("Go to the item: "+title); + goToDatasetButton.setTitle("Go to the item: " + title); goToDatasetButton.setText(link); - // goToDatasetButton.setHref(datasetUrl); + // goToDatasetButton.setHref(datasetUrl); goToDatasetButton.addClickHandler(new ClickHandler() { @Override @@ -83,11 +104,69 @@ public class AddResourceToDataset extends Composite{ Window.open(datasetUrl, "_blank", ""); } }); + + alertInfoURL.setType(AlertType.WARNING); + + infoBlock.add(alertPanel); + + bind(); + + addResourceButton.setEnabled(true); + + } + + private void bind() { + + eventBus.addHandler(WorkspaceItemSelectedEvent.TYPE, new WorkspaceItemSelectedEventHandler() { + + @Override + public void onSelectedItem(final WorkspaceItemSelectedEvent workspaceItemSelectedEvent) { + + if (workspaceItemSelectedEvent.getItem() != null) { + LoaderIcon loader = new LoaderIcon("Getting public link..."); + showAlert(null, loader, AlertType.INFO, false, true); + + ckanServices.getPublicLinkForFileItemId(workspaceItemSelectedEvent.getItem().getId(), true, + new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + showAlert(caught.getMessage(), null, AlertType.ERROR, false, true); + + } + + @Override + public void onSuccess(String result) { + showAlert("", null, null, false, false); + resourceUrlTextBox.setText(result); + resourceNameTextBox.setText(workspaceItemSelectedEvent.getItem().getName()); + } + }); + } + + } + }); + + } + + @UiHandler("buttoSelectFromWorkspace") + void onSelectFromWorkspaceClick(ClickEvent e) { + + final DialogBox dialog = new DialogBox(false); + dialog.setText("Select file from Workspace..."); + + dialog.getElement().getStyle().setWidth(700, Unit.PX); + dialog.getElement().getStyle().setZIndex(10000); + dialog.setHeight("400px"); + + DialogWorkspaceExplorer dbw = new DialogWorkspaceExplorer(dialog, eventBus); + dialog.add(dbw); + dialog.center(); } @UiHandler("addResourceButton") - void onAddButtonClick(ClickEvent e){ - + void onAddButtonClick(ClickEvent e) { + infoBlock.setVisible(false); urlControlGroup.setType(ControlGroupType.NONE); nameControlGroup.setType(ControlGroupType.NONE); @@ -95,7 +174,7 @@ public class AddResourceToDataset extends Composite{ // validation if (resourceUrlTextBox.getText().isEmpty()) { - showAlert("'URL' field cannot be empty", AlertType.ERROR); + showAlert("'URL' field cannot be empty", null, AlertType.ERROR, true, true); urlControlGroup.setType(ControlGroupType.ERROR); return; } @@ -103,40 +182,31 @@ public class AddResourceToDataset extends Composite{ // validation if (resourceNameTextBox.getText().isEmpty() || resourceNameTextBox.getText().isEmpty()) { - showAlert("'Name' field cannot be empty", AlertType.ERROR); + showAlert("'Name' field cannot be empty", null, AlertType.ERROR, true, true); nameControlGroup.setType(ControlGroupType.ERROR); return; } - - //THE URL must be HTTPS, see #21068 - if(!(resourceUrlTextBox.getText().toLowerCase().startsWith("https://"))){ - showAlert("The URL must be HTTPS, so start with \"https://\" (e.g. https://your-resource.com)", AlertType.ERROR); + + // THE URL must be HTTPS, see #21068 + if (!(resourceUrlTextBox.getText().toLowerCase().startsWith("https://"))) { + showAlert("The URL must be HTTPS, so start with \"https://\" (e.g. https://your-resource.com)", null, + AlertType.ERROR, true, true); urlControlGroup.setType(ControlGroupType.ERROR); return; - + } // collect data and build up the bean - final ResourceElementBean resource = - new ResourceElementBean( - resourceNameTextBox.getText(), - true, - false, - null, - null, - null, - null, - null, - resourceUrlTextBox.getText(), - resourceDescriptionTextArea.getText(), - datasetOrg); + final ResourceElementBean resource = new ResourceElementBean(resourceNameTextBox.getText(), true, false, null, + null, null, null, null, resourceUrlTextBox.getText(), resourceDescriptionTextArea.getText(), + datasetOrg); // disable add button addResourceButton.setEnabled(false); LoaderIcon loader = new LoaderIcon("Adding resource, please wait..."); infoPanel.add(loader); - + // try to create ckanServices.addResourceToDataset(resource, datasetOrg, datasetId, new AsyncCallback() { @@ -144,8 +214,8 @@ public class AddResourceToDataset extends Composite{ public void onSuccess(ResourceElementBean result) { infoPanel.clear(); - if(result != null){ - showAlert("Resource created correctly", AlertType.SUCCESS); + if (result != null) { + showAlert("Resource created correctly", null, AlertType.SUCCESS, true, true); eventBus.fireEvent(new AddResourceEvent(result)); eventBus.fireEvent(new ReloadDatasetPageEvent(datasetId)); @@ -154,16 +224,17 @@ public class AddResourceToDataset extends Composite{ resourceNameTextBox.setText(""); resourceDescriptionTextArea.setText(""); - } - else - showAlert("Unable to add this resource. Check that the url is correct", AlertType.ERROR); + } else + showAlert("Unable to add this resource. Check that the url is correct", null, AlertType.ERROR, true, + true); } @Override public void onFailure(Throwable caught) { infoPanel.clear(); - showAlert("Unable to add this resource, sorry. Error is: " + caught.getMessage(), AlertType.ERROR); + showAlert("Unable to add this resource, sorry. Error is: " + caught.getMessage(), null, AlertType.ERROR, + true, true); } }); @@ -172,27 +243,39 @@ public class AddResourceToDataset extends Composite{ /** * Show error/success after resource creation attempt. + * * @param text * @param type */ - protected void showAlert(String text, AlertType type) { + protected void showAlert(String text, LoaderIcon loader, AlertType type, boolean scheduleHide, boolean setVisible) { + + alertPanel.clear(); - infoBlock.setText(text); infoBlock.setType(type); - infoBlock.setVisible(true); - addResourceButton.setEnabled(true); + infoBlock.setVisible(setVisible); - // hide after some seconds - Timer t = new Timer() { + if (scheduleHide) { + // hide after some seconds + Timer t = new Timer() { - @Override - public void run() { + @Override + public void run() { - infoBlock.setVisible(false); + infoBlock.setVisible(false); - } - }; + } + }; + + t.schedule(8000); + } + + if (text != null) { + alertPanel.add(new HTML(text)); + } + + if (loader != null) { + alertPanel.add(loader); + } - t.schedule(8000); } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml index b9a2d94..3914f08 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml @@ -44,6 +44,11 @@ vertical-align: middle; font-weight: bold; } + + .background_gray { + background-color: #fcfcfc !important; + background-color: gray !important; + } - The URL of the resource you are - publishing (only HTTPS URLs are allowed). If your resource is a + + Select from Workspace + + The URL of the resource you are + publishing (only HTTPS + URLs are allowed). If your resource is a file that you own on your desktop, please upload that file to your workspace and generate a diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/DialogWorkspaceExplorer.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/DialogWorkspaceExplorer.java new file mode 100644 index 0000000..1ecba44 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/DialogWorkspaceExplorer.java @@ -0,0 +1,113 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources; + +import java.util.Arrays; +import java.util.List; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.WorkspaceItemSelectedEvent; +import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener; +import org.gcube.portlets.widgets.wsexplorer.client.select.WorkspaceExplorerSelectPanel; +import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria; +import org.gcube.portlets.widgets.wsexplorer.shared.Item; +import org.gcube.portlets.widgets.wsexplorer.shared.ItemType; + +import com.github.gwtbootstrap.client.ui.Button; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.Widget; + +public class DialogWorkspaceExplorer extends Composite { + + private static DialogBoxWorkspaceUiBinder uiBinder = GWT.create(DialogBoxWorkspaceUiBinder.class); + + interface DialogBoxWorkspaceUiBinder extends UiBinder { + } + + @UiField + Button okButton; + + @UiField + Button cancelButton; + + @UiField + FlowPanel panelContainer; + + private DialogBox dialogBox; + + private Item selectedItem; + + private HandlerManager eventBus; + + public DialogWorkspaceExplorer(DialogBox dialog, HandlerManager eventBus) { + initWidget(uiBinder.createAndBindUi(this)); + this.dialogBox = dialog; + this.eventBus = eventBus; + + FilterCriteria filterCriteria = null; + List selectableTypes = Arrays.asList(ItemType.DOCUMENT, ItemType.EXTERNAL_IMAGE, + ItemType.EXTERNAL_FILE, ItemType.EXTERNAL_PDF_FILE, ItemType.EXTERNAL_URL, ItemType.REPORT_TEMPLATE, + ItemType.REPORT, ItemType.CSV, ItemType.MOVIE, ItemType.ZIP, ItemType.RAR, ItemType.HTML, ItemType.XML, + ItemType.TEXT_PLAIN, ItemType.DOCUMENT, ItemType.PRESENTATION, ItemType.SPREADSHEET, ItemType.METADATA, + ItemType.PDF_DOCUMENT, ItemType.IMAGE_DOCUMENT, ItemType.URL_DOCUMENT, ItemType.GCUBE_ITEM, + ItemType.TIME_SERIES + + ); + + WorkspaceExplorerSelectPanel selectDialog = new WorkspaceExplorerSelectPanel("Select the file...", + filterCriteria, selectableTypes); + selectDialog.setWidth("700px"); + selectDialog.setHeight("370px"); + + WorskpaceExplorerSelectNotificationListener listener = new WorskpaceExplorerSelectNotificationListener() { + + @Override + public void onSelectedItem(Item item) { + GWT.log("onSelectedItem: " + item); + selectedItem = item; + } + + @Override + public void onFailed(Throwable throwable) { + GWT.log("onFailed.."); + + } + + @Override + public void onAborted() { + GWT.log("onAborted.."); + + } + + @Override + public void onNotValidSelection() { + GWT.log("onNotValidSelection.."); + + } + }; + + selectDialog.addWorkspaceExplorerSelectNotificationListener(listener); + + panelContainer.add(selectDialog); + } + + @UiHandler("okButton") + void onOKClick(ClickEvent e) { + + if(selectedItem!=null) { + eventBus.fireEvent(new WorkspaceItemSelectedEvent(selectedItem)); + dialogBox.hide(); + } + } + + @UiHandler("cancelButton") + void onCancelClick(ClickEvent e) { + dialogBox.hide(); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/DialogWorkspaceExplorer.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/DialogWorkspaceExplorer.ui.xml new file mode 100644 index 0000000..8bf188b --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/DialogWorkspaceExplorer.ui.xml @@ -0,0 +1,24 @@ + + + + .select_button { + margin: 5px; + float: right; + } + + .cancel_button { + margin: 5px; + margin-left: 10px; + float: right; + } + + + + Cancel + Select + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 7b166fb..8236439 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -31,6 +31,8 @@ import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanLicense; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanOrganization; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanResource; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanTag; +import org.gcube.portlets.user.uriresolvermanager.UriResolverManager; +import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.CatalogueRoleManager; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.DiscoverTagsList; @@ -387,8 +389,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C CkanOrganization ckanOrganization = dataset.getOrganization(); // UPDATED By Francesco -// String vreName = scope.substring(scope.lastIndexOf("/") + 1, scope.length()); -// logger.debug("In dev mode using the scope: " + scope + " and VRE name: " + vreName); final OrganizationBean ckanOrganizationBean = new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName(), true); bean.setOrganizationList(Arrays.asList(ckanOrganizationBean)); @@ -413,15 +413,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // Vocabulary Tags from Generi Resources bean.setTagsVocabulary(discoverTagsVocabulary(scopePerCurrentUrl)); - // By default setting the root folder ID for updating the Resources on the - // client-side - // TODO LOAD THE WORKSPACE ROOT - /* - * Workspace workspace = getWorkspaceFromStorageHub(); - * WorkspaceUtils.toWorkspaceResource(workspace.getRoot().getId(), userName, - * bean, workspace); - */ - // Settings the CKAN resources List resources = dataset.getResources(); if (resources != null) { @@ -1091,7 +1082,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.warn("Dev mode detected"); toReturn = Arrays.asList(); } - + logger.info("Returning user's groups: " + toReturn); return toReturn; } @@ -1274,6 +1265,41 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C } + /** + * Gets the public link for file item id. + * + * @param itemId the item id + * @param shortenUrl the shorten url + * @return the public link for file item id + * @throws Exception the exception + */ + @Override + public String getPublicLinkForFileItemId(String itemId, boolean shortenUrl) throws Exception { + logger.debug("get Public Link For ItemId: " + itemId); + //String scopePerCurrentUrl = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest()); + String theLink = null; + try { + GenericUtils.getCurrentContext(getThreadLocalRequest(), true); + UriResolverManager resolver = new UriResolverManager("SHUB"); + Map params = new HashMap(); + params.put("id", itemId); + theLink = resolver.getLink(params, true); + logger.info("Returning public link: "+theLink); + } catch (UriResolverMapException e) { + logger.error("UriResolverMapException", e); + throw new Exception("Sorry an error occurred on getting the link " + e.getMessage()); + } catch (IllegalArgumentException e) { + logger.error("Failed to check the user's role", e); + throw new Exception("Sorry an error occurred on getting the link " + e.getMessage()); + } catch (Exception e) { + logger.error("Failed to check the user's role", e); + throw new Exception("Sorry an error occurred on getting the link " + e.getMessage()); + } + + return theLink; + + } + /** * Gets the reserverd system fields. *