in progress

This commit is contained in:
Francesco Mangiacrapa 2024-02-12 16:52:06 +01:00
parent d562070704
commit 301c19d369
12 changed files with 290 additions and 190 deletions

View File

@ -59,11 +59,12 @@ public interface CKanPublisherService extends RemoteService {
* Add this resource to the dataset whose id is datasetId. * 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 datasetId the dataset id
* @return the resource element bean * @return the resource element bean
* @throws Exception the exception * @throws Exception the exception
*/ */
ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) throws Exception; ResourceElementBean addResourceToDataset(ResourceElementBean resource, String organizationName, String datasetId) throws Exception;
/** /**
* Delete this resource from the dataset with id datasetId. * Delete this resource from the dataset with id datasetId.

View File

@ -49,10 +49,11 @@ public interface CKanPublisherServiceAsync {
* Add this resource to the dataset whose id is datasetId. * 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 datasetId the dataset id
* @param callback the callback * @param callback the callback
*/ */
void addResourceToDataset(ResourceElementBean resource, String datasetId, void addResourceToDataset(ResourceElementBean resource, String organizationName, String datasetId,
AsyncCallback<ResourceElementBean> callback); AsyncCallback<ResourceElementBean> callback);
/** /**

View File

@ -2,25 +2,30 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
import com.github.gwtbootstrap.client.ui.Button;
import com.google.gwt.event.shared.GwtEvent; import com.google.gwt.event.shared.GwtEvent;
/** /**
* Deleted resource event. * Deleted resource event.
*
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/ */
public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> { public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> {
public static Type<DeleteResourceEventHandler> TYPE = new Type<DeleteResourceEventHandler>(); public static Type<DeleteResourceEventHandler> TYPE = new Type<DeleteResourceEventHandler>();
private ResourceElementBean resource; private ResourceElementBean resource;
public DeleteResourceEvent(ResourceElementBean resource) { private Button deleteButton;
public DeleteResourceEvent(Button deleteButton, ResourceElementBean resource) {
this.resource = resource; this.resource = resource;
this.deleteButton = deleteButton;
} }
public ResourceElementBean getResource() { public ResourceElementBean getResource() {
return resource; return resource;
} }
@Override @Override
public Type<DeleteResourceEventHandler> getAssociatedType() { public Type<DeleteResourceEventHandler> getAssociatedType() {
return TYPE; return TYPE;
@ -31,4 +36,19 @@ public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> {
handler.onDeletedResource(this); handler.onDeletedResource(this);
} }
public Button getDeleteButton() {
return deleteButton;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DeleteResourceEvent [resource=");
builder.append(resource);
builder.append(", deleteButton=");
builder.append(deleteButton);
builder.append("]");
return builder.toString();
}
} }

View File

@ -1301,15 +1301,15 @@ public class CreateDatasetForm extends Composite {
addedResources.setHeading("Added Resource"); addedResources.setHeading("Added Resource");
tabPanel.add(addedResources); tabPanel.add(addedResources);
// add tabs to resources panel
tabPanel.selectTab(0);
// form container // form container
AddResourceContainer container = new AddResourceContainer(datasetUrl); AddResourceContainer container = new AddResourceContainer(datasetUrl);
container.add(tabPanel); container.add(tabPanel);
// add the new content of the main panel // add the new content of the main panel
createDatasetMainPanel.add(container); createDatasetMainPanel.add(container);
// add tabs to resources panel
tabPanel.selectTab(0);
} }
}); });
} catch (Exception e2) { } catch (Exception e2) {

View File

@ -161,7 +161,11 @@ public class UpdateDatasetForm extends Composite {
@UiField @UiField
HorizontalPanel goToDatasetButtonPanel; HorizontalPanel goToDatasetButtonPanel;
@UiField @UiField
Button addResourcesButton; Button addResourcesButtonStep1;
@UiField
Button addResourcesButtonStep3;
@UiField @UiField
SimplePanel workspaceResourcesContainer; SimplePanel workspaceResourcesContainer;
@UiField @UiField
@ -323,7 +327,8 @@ public class UpdateDatasetForm extends Composite {
private WizardCreator wizCreator; private WizardCreator wizCreator;
private boolean isWorkspaceRequest = false; private boolean isWorkspaceRequest = false;
private String datasetIdOrName; private String datasetIdOrName = null;
private DatasetBean theDataset = null;
/** /**
* Instantiates a new update dataset form. * Instantiates a new update dataset form.
@ -387,6 +392,7 @@ public class UpdateDatasetForm extends Composite {
// disable continue button // disable continue button
continueButton.setEnabled(false); continueButton.setEnabled(false);
resetButton.setEnabled(false); resetButton.setEnabled(false);
addResourcesButtonStep1.setEnabled(false);
// hide tags panel // hide tags panel
tagsPanel.setVisible(false); tagsPanel.setVisible(false);
@ -415,34 +421,35 @@ public class UpdateDatasetForm extends Composite {
} }
@Override @Override
public void onSuccess(final DatasetBean bean) { public void onSuccess(final DatasetBean datasetBean) {
GWT.log("getDatasetBeanForUpdate returns: " + bean); GWT.log("getDatasetBeanForUpdate returns: " + datasetBean);
theDataset = datasetBean;
if (bean == null) { if (datasetBean == null) {
setAlertBlock("Error while retrieving information.", AlertType.ERROR, true); setAlertBlock("Error while retrieving information.", AlertType.ERROR, true);
} else { } else {
// save it // save it
receivedBean = bean; receivedBean = datasetBean;
// fill the form // fill the form
titleTextBox.setText(bean.getTitle()); titleTextBox.setText(datasetBean.getTitle());
descriptionTextarea.setText(bean.getDescription()); descriptionTextarea.setText(datasetBean.getDescription());
versionTextbox.setText(String.valueOf(bean.getVersion())); versionTextbox.setText(String.valueOf(datasetBean.getVersion()));
authorTextbox.setText(bean.getAuthorFullName()); authorTextbox.setText(datasetBean.getAuthorFullName());
authorEmailTextbox.setText(bean.getAuthorEmail()); authorEmailTextbox.setText(datasetBean.getAuthorEmail());
maintainerTextbox.setText(bean.getMaintainer()); maintainerTextbox.setText(datasetBean.getMaintainer());
maintainerEmailTextbox.setText(bean.getMaintainerEmail()); maintainerEmailTextbox.setText(datasetBean.getMaintainerEmail());
setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true); setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true);
// vocabulary list of tags has preemption // vocabulary list of tags has preemption
List<String> vocabularyTags = bean.getTagsVocabulary(); List<String> vocabularyTags = datasetBean.getTagsVocabulary();
if (vocabularyTags != null) { if (vocabularyTags != null) {
tagsPanel.setVocabulary(vocabularyTags); tagsPanel.setVocabulary(vocabularyTags);
if (bean.getTags() != null) { if (datasetBean.getTags() != null) {
for (String tag : bean.getTags()) { for (String tag : datasetBean.getTags()) {
tagsPanel.addTagElement(tag); tagsPanel.addTagElement(tag);
} }
@ -452,7 +459,7 @@ public class UpdateDatasetForm extends Composite {
// THIS BLOCK is it required? Probably not. // THIS BLOCK is it required? Probably not.
// retrieve custom fields // retrieve custom fields
Map<String, List<String>> customFieldsMap = bean.getCustomFields(); Map<String, List<String>> customFieldsMap = datasetBean.getCustomFields();
// TODO Check if these tags are ok for the vocabulary // TODO Check if these tags are ok for the vocabulary
if (customFieldsMap != null && vocabularyTags == null) { if (customFieldsMap != null && vocabularyTags == null) {
// get the keys and put them as tags // get the keys and put them as tags
@ -496,13 +503,13 @@ public class UpdateDatasetForm extends Composite {
// } // }
// The resource root is the folder id. Es. ID of the Workspace Root folder. // The resource root is the folder id. Es. ID of the Workspace Root folder.
if (bean.getResourceRoot() != null) { if (datasetBean.getResourceRoot() != null) {
resourcesSelectByWEMainPanel = new SelectResourceByWEMainPanel( resourcesSelectByWEMainPanel = new SelectResourceByWEMainPanel(
bean.getResourceRoot()); datasetBean.getResourceRoot());
} }
// set organizations // set organizations
List<OrganizationBean> organizations = bean.getOrganizationList(); List<OrganizationBean> organizations = datasetBean.getOrganizationList();
for (OrganizationBean organization : organizations) { for (OrganizationBean organization : organizations) {
organizationsListbox.addItem(organization.getTitle()); organizationsListbox.addItem(organization.getTitle());
@ -525,6 +532,9 @@ public class UpdateDatasetForm extends Composite {
// get the name of the organization from the title // get the name of the organization from the title
final String orgName = nameTitleOrganizationMap final String orgName = nameTitleOrganizationMap
.get(organizationsListbox.getSelectedItemText()); .get(organizationsListbox.getSelectedItemText());
//Putting the selected Organization into bena
theDataset.setSelectedOrganization(orgName);
// force tags // force tags
// setAlertBlock("Checking for tags vocabulary, please wait...", AlertType.INFO, true); // setAlertBlock("Checking for tags vocabulary, please wait...", AlertType.INFO, true);
@ -552,7 +562,7 @@ public class UpdateDatasetForm extends Composite {
setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true); setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true);
// perform remote request of profiles for the selected organization // perform remote request of profiles for the selected organization
ckanServices.getProfileForUpdate(orgName, bean.getChosenType(), bean.getId(), ckanServices.getProfileForUpdate(orgName, datasetBean.getChosenType(), datasetBean.getId(),
new AsyncCallback<MetadataProfileBeanForUpdate>() { new AsyncCallback<MetadataProfileBeanForUpdate>() {
@Override @Override
@ -649,8 +659,9 @@ public class UpdateDatasetForm extends Composite {
false); false);
continueButton.setEnabled(true); continueButton.setEnabled(true);
resetButton.setEnabled(true); resetButton.setEnabled(true);
addResourcesButtonStep1.setEnabled(true);
manageAddResources(bean, manageAddResources(datasetBean,
datasetIdOrName); datasetIdOrName);
} }
} }
@ -733,6 +744,8 @@ public class UpdateDatasetForm extends Composite {
// get the name of the organization from the title // get the name of the organization from the title
String selectedOrganizationTitle = organizationsListbox.getSelectedItemText(); String selectedOrganizationTitle = organizationsListbox.getSelectedItemText();
final String orgName = nameTitleOrganizationMap.get(selectedOrganizationTitle); final String orgName = nameTitleOrganizationMap.get(selectedOrganizationTitle);
theDataset.setSelectedOrganization(orgName);
// try to retrieve the profiles // try to retrieve the profiles
setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true); setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true);
@ -955,13 +968,6 @@ public class UpdateDatasetForm extends Composite {
for (MetadataFieldWrapper metadataFieldWrapper : fieldsForThisCategory) { for (MetadataFieldWrapper metadataFieldWrapper : fieldsForThisCategory) {
/*
* MetaDataFieldSkeleton fieldWidget; try { fieldWidget = new
* MetaDataFieldSkeleton(metadataFieldWrapper, eventBus);
* cp.addField(fieldWidget); listOfMetadataFields.add(fieldWidget); } catch
* (Exception e) { GWT.log("Unable to build such widget", e); }
*/
MetaDataField fieldWidget; MetaDataField fieldWidget;
try { try {
fieldWidget = new MetaDataField(metadataFieldWrapper, eventBus, operation); fieldWidget = new MetaDataField(metadataFieldWrapper, eventBus, operation);
@ -979,13 +985,6 @@ public class UpdateDatasetForm extends Composite {
CategoryPanel extrasCategory = new CategoryPanel("Other", null); CategoryPanel extrasCategory = new CategoryPanel("Other", null);
for (MetadataFieldWrapper field : fields) { for (MetadataFieldWrapper field : fields) {
/*
* MetaDataFieldSkeleton fieldWidget; try { fieldWidget = new
* MetaDataFieldSkeleton(field, eventBus); extrasCategory.addField(fieldWidget);
* listOfMetadataFields.add(fieldWidget); } catch (Exception e) {
* GWT.log("Unable to build such widget", e); }
*/
MetaDataField fieldWidget; MetaDataField fieldWidget;
try { try {
fieldWidget = new MetaDataField(field, eventBus, operation); fieldWidget = new MetaDataField(field, eventBus, operation);
@ -1382,65 +1381,49 @@ public class UpdateDatasetForm extends Composite {
} }
} }
private void manageAddResources(final DatasetBean theDatasetBean, String datasetUrl) { private void manageAddResources(final DatasetBean theDatasetBean, final String datasetUrl) {
// if we are in the "general case" we need to show a form for adding resources // if we are in the "general case" we need to show a form for adding resources
if (!isWorkspaceRequest) { if (!isWorkspaceRequest) {
try { try {
// show the add resources button // show the add resources button
addResourcesButton.setVisible(true); addResourcesButtonStep1.setVisible(true);
addResourcesButtonStep3.setVisible(true);
final AddedResourcesSummary addedResourcesSummary = initTabManageResourcePanel(theDatasetBean, datasetUrl);
final AddedResourcesSummary addedResourcesSummary = initTabManageResourcePanel(theDatasetBean,
datasetUrl);
final List<ResourceElementBean> resources = theDatasetBean.getCkanResources(); final List<ResourceElementBean> resources = theDatasetBean.getCkanResources();
GWT.log("Resources are: " + resources); GWT.log("Resources are: " + resources);
if (resources != null if (resources != null && resources.size() > 0) {
&& resources.size() > 0) {
GWT.log("Executing are: " + resources); GWT.log("Executing are: " + resources);
for (ResourceElementBean reb : theDatasetBean.getCkanResources()) { for (ResourceElementBean reb : theDatasetBean.getCkanResources()) {
eventBus.fireEvent(new AddResourceEvent(reb)); addedResourcesSummary.getEventBus().fireEvent(new AddResourceEvent(reb));
//addedResourcesSummary.getEventBus().fireEvent(new AddResourceEvent(reb));
} }
} }
// NB!!! addResourcesButton must be clicked once
// Scheduler.get().scheduleDeferred(new ScheduledCommand() { addResourcesButtonStep1.addClickHandler(new ClickHandler() {
// @Override
// public void execute() {
// GWT.log("Executing are: " + resources);
//
// if (resources != null
// && resources.size() > 0) {
//
// for (ResourceElementBean reb : theDatasetBean.getCkanResources()) {
// addedResourcesSummary.getEventBus().fireEvent(new AddResourceEventProfile(reb));
// }
// }
// }
// });
addResourcesButton.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
// remove content of the main panel manageResourcesOnFire(datasetUrl);
createDatasetMainPanel.clear();
tabPanel.selectTab(0);
// form container
AddResourceContainer container = new AddResourceContainer(datasetUrl);
container.add(tabPanel);
// add the new content of the main panel
createDatasetMainPanel.add(container);
} }
}); });
addResourcesButtonStep3.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
manageResourcesOnFire(datasetUrl);
}
});
} catch (Exception e2) { } catch (Exception e2) {
// silent // silent
} }
@ -1448,20 +1431,35 @@ public class UpdateDatasetForm extends Composite {
} }
} }
private void manageResourcesOnFire(String datasetUrl) {
// remove content of the main panel
createDatasetMainPanel.clear();
// form container
AddResourceContainer container = new AddResourceContainer(datasetUrl);
container.add(tabPanel);
// add the new content of the main panel
createDatasetMainPanel.add(container);
tabPanel.selectTab(0);
}
private AddedResourcesSummary initTabManageResourcePanel(final DatasetBean theDatasetBean, String datasetUrl) { private AddedResourcesSummary initTabManageResourcePanel(final DatasetBean theDatasetBean, String datasetUrl) {
// TabPanelException // TabPanelException
if(tabPanel!=null) if (tabPanel != null)
tabPanel.clear(); tabPanel.clear();
tabPanel = new TabPanel(Tabs.LEFT); tabPanel = new TabPanel(Tabs.LEFT);
tabPanel.setWidth("100%"); tabPanel.setWidth("100%");
// add the form // add the form
resourceForm = new AddResourceToDataset(eventBus, theDatasetBean.getId(), resourceForm = new AddResourceToDataset(eventBus, theDatasetBean.getId(), theDatasetBean.getTitle(),
theDatasetBean.getTitle(), theDatasetBean.getSelectedOrganization(), owner, datasetUrl); theDatasetBean.getSelectedOrganization(), owner, datasetUrl);
// tab for the form // tab for the form
Tab formContainer = new Tab(); Tab formContainer = new Tab();
@ -1475,15 +1473,8 @@ public class UpdateDatasetForm extends Composite {
addedResources.add(addedResourcesSummary); addedResources.add(addedResourcesSummary);
addedResources.setHeading("Added Resource"); addedResources.setHeading("Added Resource");
tabPanel.add(addedResources); tabPanel.add(addedResources);
return addedResourcesSummary; return addedResourcesSummary;
// add tabs to resources panel
// tabPanel.selectTab(0);
// // form container
// AddResourceContainer container = new AddResourceContainer(datasetUrl);
// container.add(tabPanel);
} }
/** /**

View File

@ -337,6 +337,10 @@
<b:Button title="Continue" ui:field="continueButton" <b:Button title="Continue" ui:field="continueButton"
type="PRIMARY" block="true">Continue</b:Button> type="PRIMARY" block="true">Continue</b:Button>
<b:Button title="Reset" ui:field="resetButton" block="true">Reset</b:Button> <b:Button title="Reset" ui:field="resetButton" block="true">Reset</b:Button>
<b:Button title="Manage resources of the item"
block="true" type="INFO" visible="true"
ui:field="addResourcesButtonStep1">Manage Resources</b:Button>
</b:Fieldset> </b:Fieldset>
</b:Form> </b:Form>
@ -368,6 +372,7 @@
<b:Button title="Go Back" ui:field="goBackButtonFirstStep" <b:Button title="Go Back" ui:field="goBackButtonFirstStep"
block="true">Go block="true">Go
Back</b:Button> Back</b:Button>
</b:Fieldset> </b:Fieldset>
</b:Form> </b:Form>
@ -425,16 +430,16 @@
styleName="{style.the-margin-gotoitem}"></b:Button> styleName="{style.the-margin-gotoitem}"></b:Button>
</g:HorizontalPanel> </g:HorizontalPanel>
<b:Button title="Manage resources of the item"
block="true" type="PRIMARY" visible="false"
ui:field="addResourcesButton">Manage Resources</b:Button>
<b:Button title="Update Item" ui:field="updateButton" <b:Button title="Update Item" ui:field="updateButton"
type="PRIMARY" block="true">Create</b:Button> type="PRIMARY" block="true">Update</b:Button>
<b:Button title="Go Back" ui:field="goBackButtonSecondStep" <b:Button title="Go Back" ui:field="goBackButtonSecondStep"
block="true">Go block="true">Go
Back</b:Button> Back</b:Button>
<b:Button title="Manage resources of the item"
block="true" type="INFO" visible="true"
ui:field="addResourcesButtonStep3">Manage Resources</b:Button>
</b:Fieldset> </b:Fieldset>
</b:Form> </b:Form>

View File

@ -61,7 +61,7 @@ public class AddResourceToDataset extends Composite{
@UiField ControlGroup nameControlGroup; @UiField ControlGroup nameControlGroup;
@UiField FlowPanel infoPanel; @UiField FlowPanel infoPanel;
public AddResourceToDataset(HandlerManager eventBus, String datasetId, String datasetTitle, String datasetOrg, String owner, final String datasetUrl) { public AddResourceToDataset(HandlerManager eventBus, final String datasetId, String datasetTitle, final String datasetOrg, String owner, final String datasetUrl) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
// save bus // save bus
this.eventBus = eventBus; this.eventBus = eventBus;
@ -137,7 +137,7 @@ public class AddResourceToDataset extends Composite{
infoPanel.add(loader); infoPanel.add(loader);
// try to create // try to create
ckanServices.addResourceToDataset(resource, datasetId, new AsyncCallback<ResourceElementBean>() { ckanServices.addResourceToDataset(resource, datasetOrg, datasetId, new AsyncCallback<ResourceElementBean>() {
@Override @Override
public void onSuccess(ResourceElementBean result) { public void onSuccess(ResourceElementBean result) {

View File

@ -12,8 +12,10 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElement
import com.github.gwtbootstrap.client.ui.Accordion; import com.github.gwtbootstrap.client.ui.Accordion;
import com.github.gwtbootstrap.client.ui.AccordionGroup; import com.github.gwtbootstrap.client.ui.AccordionGroup;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Paragraph; import com.github.gwtbootstrap.client.ui.Paragraph;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
@ -22,6 +24,7 @@ import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
@ -46,8 +49,14 @@ public class AddedResourcesSummary extends Composite {
@UiField @UiField
VerticalPanel addResourcesPanel; VerticalPanel addResourcesPanel;
@UiField
Alert alertMessage;
public AddedResourcesSummary(HandlerManager eventBus) { public AddedResourcesSummary(HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
alertMessage.setType(AlertType.ERROR);
alertMessage.setClose(true);
// save bus // save bus
this.eventBus = eventBus; this.eventBus = eventBus;
// bind on add resource event // bind on add resource event
@ -75,23 +84,31 @@ public class AddedResourcesSummary extends Composite {
Accordion accordion = new Accordion(); Accordion accordion = new Accordion();
AccordionGroup accordionGroup = new AccordionGroup(); AccordionGroup accordionGroup = new AccordionGroup();
accordionGroup.setHeading("* " + justAddedResource.getName()); accordionGroup.setHeading("* " + justAddedResource.getName());
accordionGroup.getHeading().getElement().getStyle().setBackgroundColor("#FFEDBE");
accordion.add(accordionGroup); accordion.add(accordionGroup);
// add sub-info such as url and description // add sub-info such as url and description
Paragraph pUrl = new Paragraph(); Paragraph pUrl = new Paragraph();
pUrl.setText("URL : " + justAddedResource.getUrl()); if (justAddedResource.getUrl() != null) {
pUrl.setText("URL:");
HTML htmlLink = new HTML();
htmlLink.setHTML(
"<a href=" + justAddedResource.getUrl() + ">" + justAddedResource.getUrl() + "</a>");
// pUrl.add(pUrl);
pUrl.add(htmlLink);
}
Paragraph pDescription = new Paragraph(); Paragraph pDescription = new Paragraph();
pDescription.setText("Description : " + justAddedResource.getDescription()); pDescription.setText("Description : " + justAddedResource.getDescription());
// button to delete the resource // button to delete the resource
Button deleteButton = new Button(); final Button deleteButton = new Button();
deleteButton.setText("Delete"); deleteButton.setText("Delete");
deleteButton.addClickHandler(new ClickHandler() { deleteButton.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
eventBus.fireEvent(new DeleteResourceEvent(justAddedResource)); eventBus.fireEvent(new DeleteResourceEvent(deleteButton, justAddedResource));
} }
}); });
@ -113,11 +130,15 @@ public class AddedResourcesSummary extends Composite {
eventBus.addHandler(DeleteResourceEvent.TYPE, new DeleteResourceEventHandler() { eventBus.addHandler(DeleteResourceEvent.TYPE, new DeleteResourceEventHandler() {
@Override @Override
public void onDeletedResource(DeleteResourceEvent deleteResourceEvent) { public void onDeletedResource(final DeleteResourceEvent deleteResourceEvent) {
GWT.log("onDeletedResource resource event: " + deleteResourceEvent); GWT.log("onDeletedResource resource event: " + deleteResourceEvent);
// to delete // to delete
ResourceElementBean toDelete = deleteResourceEvent.getResource(); final ResourceElementBean toDelete = deleteResourceEvent.getResource();
Button toDeleteButton = deleteResourceEvent.getDeleteButton();
toDeleteButton.setEnabled(false);
// find it // find it
for (int i = 0; i < addedResources.size(); i++) { for (int i = 0; i < addedResources.size(); i++) {
@ -135,16 +156,24 @@ public class AddedResourcesSummary extends Composite {
public void onSuccess(Boolean result) { public void onSuccess(Boolean result) {
if (result) { if (result) {
// remove from the list
addedResources.remove(toDelete);
alertMessage.setType(AlertType.SUCCESS);
alertMessage.setHTML("The resource described by " + toDelete.getName()
+ " has been deleted!");
widget.removeFromParent(); widget.removeFromParent();
} else {
alertMessage.setVisible(true);
alertMessage.setHTML("Sorry, the resource described by "
+ toDelete.getName() + " cannot be deleted");
} }
// remove from the list
addedResources.remove(toDelete);
} }
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
toDeleteButton.setEnabled(false);
alertMessage.setVisible(true);
alertMessage.setHTML(caught.getMessage());
} }
}); });

View File

@ -1,8 +1,12 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:g="urn:import:com.google.gwt.user.client.ui"> xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel> <g:HTMLPanel>
<h3>Added Resources</h3> <h3>Added Resources</h3>
<g:VerticalPanel ui:field="addResourcesPanel" width="100%"></g:VerticalPanel> <g:VerticalPanel ui:field="addResourcesPanel"
width="100%">
<b:Alert visible="false" ui:field="alertMessage"></b:Alert>
</g:VerticalPanel>
</g:HTMLPanel> </g:HTMLPanel>
</ui:UiBinder> </ui:UiBinder>

View File

@ -389,8 +389,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// UPDATED By Francesco // UPDATED By Francesco
// String vreName = scope.substring(scope.lastIndexOf("/") + 1, scope.length()); // String vreName = scope.substring(scope.lastIndexOf("/") + 1, scope.length());
// logger.debug("In dev mode using the scope: " + scope + " and VRE name: " + vreName); // logger.debug("In dev mode using the scope: " + scope + " and VRE name: " + vreName);
bean.setOrganizationList( final OrganizationBean ckanOrganizationBean = new OrganizationBean(ckanOrganization.getTitle(),
Arrays.asList(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName(), true))); ckanOrganization.getName(), true);
bean.setOrganizationList(Arrays.asList(ckanOrganizationBean));
List<CkanTag> listDatasetTags = dataset.getTags(); List<CkanTag> listDatasetTags = dataset.getTags();
@ -426,7 +427,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
if (resources != null) { if (resources != null) {
List<ResourceElementBean> list = new ArrayList<ResourceElementBean>(resources.size()); List<ResourceElementBean> list = new ArrayList<ResourceElementBean>(resources.size());
for (CkanResource ckanResource : resources) { for (CkanResource ckanResource : resources) {
ResourceElementBean reb = PublisherCatalogueConveter.toResourceElementBean(ckanResource); ResourceElementBean reb = PublisherCatalogueConveter.toResourceElementBean(ckanResource,
ckanOrganizationBean.getName());
list.add(reb); list.add(reb);
} }
bean.setResources(list); bean.setResources(list);
@ -640,7 +642,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
if (listCurrentResources != null) { if (listCurrentResources != null) {
resources = new ArrayList<ResourceBean>(listCurrentResources.size()); resources = new ArrayList<ResourceBean>(listCurrentResources.size());
for (CkanResource ckanResource : listCurrentResources) { for (CkanResource ckanResource : listCurrentResources) {
ResourceBean reb = PublisherCatalogueConveter.toResourceBean(ckanResource); String orgName = null; // not required here
ResourceBean reb = PublisherCatalogueConveter.toResourceBean(ckanResource, orgName);
resources.add(reb); resources.add(reb);
} }
} }
@ -714,13 +717,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
/** /**
* Adds the resource to dataset. * Adds the resource to dataset.
* *
* @param resource the resource * @param resource the resource
* @param datasetId the dataset id * @param organizationName the organization name
* @param datasetId the dataset id
* @return the resource element bean * @return the resource element bean
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) throws Exception { public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String organizationName,
String datasetId) throws Exception {
logger.info("called addResourceToDataset"); logger.info("called addResourceToDataset");
devModeSetContexts(); devModeSetContexts();
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
@ -735,14 +740,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// organization name in which the dataset was created // organization name in which the dataset was created
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
DataCatalogue catalogue = getCatalogue(scope); DataCatalogue catalogue = getCatalogue(scope);
String resourceId = catalogue.addResourceToDataset(resourceBean, resource.getOrganizationNameDatasetParent(), CkanResource theCreatedResource = catalogue.addResource(resourceBean, datasetId,
username); resource.getOrganizationNameDatasetParent(), username);
if (resourceId != null) { if (theCreatedResource != null) {
logger.info("Resource " + resource.getName() + " is now available"); logger.info("Resource " + resource.getName() + " is now available");
// set its id and turn it to the client
resource.setOriginalIdInWorkspace(resourceId); ResourceElementBean reb = PublisherCatalogueConveter.toResourceElementBean(theCreatedResource,
return resource; organizationName);
return reb;
} }
logger.debug("No resource created"); logger.debug("No resource created");
@ -767,14 +774,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
DataCatalogue catalogue = getCatalogue(scope); DataCatalogue catalogue = getCatalogue(scope);
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), username); deleted = catalogue.deleteResourceFromDataset(resource.getCkanResourceID(), username);
if (deleted) { if (deleted) {
logger.info("Resource described by " + resource + " deleted"); logger.info("Resource described by " + resource + " deleted");
} else } else
logger.error("Resource described by " + resource + " NOT deleted"); logger.error("Resource described by " + resource + " NOT deleted");
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while trying to delete resource described by " + resource, e); String error = "Sorry, an error occurred while trying to delete resource described by "
throw new Exception("Error while trying to delete resource." + e.getMessage()); + resource.getName();
logger.error(error, e);
throw new Exception(error + ". Error is: " + e.getMessage());
} }
return deleted; return deleted;

View File

@ -4,31 +4,42 @@ import org.gcube.datacatalogue.utillibrary.shared.ResourceBean;
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanResource; import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanResource;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
/**
* The Class PublisherCatalogueConveter.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Feb 12, 2024
*/
public class PublisherCatalogueConveter { public class PublisherCatalogueConveter {
/** /**
* To resource element bean. * To resource element bean.
* *
* @param ckanResource the ckan resource * @param ckanResource the ckan resource
* @param orgNameParent the org name parent
* @return the resource element bean * @return the resource element bean
*/ */
public static ResourceElementBean toResourceElementBean(CkanResource ckanResource) { public static ResourceElementBean toResourceElementBean(CkanResource ckanResource, String orgNameParent) {
ResourceElementBean reb = new ResourceElementBean(); ResourceElementBean reb = new ResourceElementBean();
reb.setCkanResourceID(ckanResource.getId());
reb.setName(ckanResource.getName()); reb.setName(ckanResource.getName());
reb.setDescription(ckanResource.getDescription()); reb.setDescription(ckanResource.getDescription());
reb.setEditableName(ckanResource.getName()); reb.setEditableName(ckanResource.getName());
reb.setUrl(ckanResource.getUrl()); reb.setUrl(ckanResource.getUrl());
reb.setMimeType(ckanResource.getMimetype()); reb.setMimeType(ckanResource.getMimetype());
reb.setOrganizationNameDatasetParent(orgNameParent);
return reb; return reb;
} }
/** /**
* To resource bean. * To resource bean.
* *
* @param ckanResource the ckan resource * @param ckanResource the ckan resource
* @param orgNameParent the org name parent
* @return the resource bean * @return the resource bean
*/ */
public static ResourceBean toResourceBean(CkanResource ckanResource) { public static ResourceBean toResourceBean(CkanResource ckanResource, String orgNameParent) {
ResourceBean reb = new ResourceBean(); ResourceBean reb = new ResourceBean();
reb.setName(ckanResource.getName()); reb.setName(ckanResource.getName());
reb.setDescription(ckanResource.getDescription()); reb.setDescription(ckanResource.getDescription());

View File

@ -6,74 +6,77 @@ import java.util.List;
import com.google.gwt.user.client.rpc.IsSerializable; import com.google.gwt.user.client.rpc.IsSerializable;
import com.google.gwt.view.client.ProvidesKey; import com.google.gwt.view.client.ProvidesKey;
/** /**
* A resource element bean. Contains part of the logic used into the TwinColumn widget * A resource element bean. Contains part of the logic used into the TwinColumn
* widget
*
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
* *
* @author revisited by Francesco Mangiacrapa * @author revisited by Francesco Mangiacrapa
*/ */
public class ResourceElementBean implements Comparable<ResourceElementBean>, Serializable, IsSerializable{ public class ResourceElementBean implements Comparable<ResourceElementBean>, Serializable, IsSerializable {
/** The Constant serialVersionUID. */ /** The Constant serialVersionUID. */
private static final long serialVersionUID = -1230871392599580669L; private static final long serialVersionUID = -1230871392599580669L;
/** The name. */ /** The name. */
private String name; private String name;
/** The editable name. */ /** The editable name. */
private String editableName; private String editableName;
/** The to be added. */ /** The to be added. */
private boolean toBeAdded; private boolean toBeAdded;
/** The is folder. */ /** The is folder. */
private boolean isFolder; private boolean isFolder;
/** The full path. */ /** The full path. */
private String fullPath; private String fullPath;
/** The original id in workspace. */ /** The original id in workspace. */
private String originalIdInWorkspace; private String originalIdInWorkspace;
private String rootIdInWorkspace; private String rootIdInWorkspace;
/** The mime type. */ /** The mime type. */
private String mimeType; private String mimeType;
/** The url. */ /** The url. */
private String url; private String url;
/** The description. */ /** The description. */
private String description; private String description;
/** The organization name dataset parent. */ /** The organization name dataset parent. */
private String organizationNameDatasetParent; // the organization name in which the parent dataset was created private String organizationNameDatasetParent; // the organization name in which the parent dataset was created
/** The parent. */ /** The parent. */
private ResourceElementBean parent; private ResourceElementBean parent;
/** The children size. */ /** The children size. */
private Integer childrenSize; private Integer childrenSize;
// /** The to publish. */ // /** The to publish. */
private List<ResourceElementBean> toPublish; //Resources that must be published private List<ResourceElementBean> toPublish; // Resources that must be published
/** The next id. */ /** The next id. */
// to generate the GWT identifiers // to generate the GWT identifiers
private static int nextId = 0; private static int nextId = 0;
/** The identifier GWT. */ /** The identifier GWT. */
// identifier of this instance // identifier of this instance
private int identifierGWT; private int identifierGWT;
private String ckanResourceID;
/** /**
* The key provider that provides the unique ID of a bean. * The key provider that provides the unique ID of a bean.
*/ */
public static final ProvidesKey<ResourceElementBean> KEY_PROVIDER = new ProvidesKey<ResourceElementBean>() { public static final ProvidesKey<ResourceElementBean> KEY_PROVIDER = new ProvidesKey<ResourceElementBean>() {
@Override @Override
public Object getKey(ResourceElementBean item) { public Object getKey(ResourceElementBean item) {
return item == null ? null : item.identifierGWT; return item == null ? null : item.ckanResourceID;
} }
}; };
@ -97,7 +100,7 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
/** /**
* Default constructor. * Default constructor.
*/ */
public ResourceElementBean(){ public ResourceElementBean() {
super(); super();
this.identifierGWT = nextId; this.identifierGWT = nextId;
nextId++; nextId++;
@ -106,17 +109,13 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
/** /**
* Instantiates a new resource element bean. * Instantiates a new resource element bean.
* *
* @param parent the parent * @param parent the parent
* @param name the name * @param name the name
* @param isFolder the is folder * @param isFolder the is folder
* @param childrenSize the children size * @param childrenSize the children size
* @param fullPath the full path * @param fullPath the full path
*/ */
public ResourceElementBean( public ResourceElementBean(ResourceElementBean parent, String name, boolean isFolder, Integer childrenSize,
ResourceElementBean parent,
String name,
boolean isFolder,
Integer childrenSize,
String fullPath) { String fullPath) {
this.identifierGWT = nextId; this.identifierGWT = nextId;
nextId++; nextId++;
@ -130,22 +129,20 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
/** /**
* Instantiates a new resource element bean. * Instantiates a new resource element bean.
* *
* @param name the name * @param name the name
* @param toBeAdded the to be added * @param toBeAdded the to be added
* @param isFolder the is folder * @param isFolder the is folder
* @param parent the parent * @param parent the parent
* @param childrenSize the children size * @param childrenSize the children size
* @param fullPath the full path * @param fullPath the full path
* @param originalIdInWorkspace the original id in workspace * @param originalIdInWorkspace the original id in workspace
* @param mimeType the mime type * @param mimeType the mime type
* @param url the url * @param url the url
* @param description the description * @param description the description
* @param organizationNameDatasetParent the organization name dataset parent * @param organizationNameDatasetParent the organization name dataset parent
*/ */
public ResourceElementBean(String name, boolean toBeAdded, public ResourceElementBean(String name, boolean toBeAdded, boolean isFolder, ResourceElementBean parent,
boolean isFolder, ResourceElementBean parent, Integer childrenSize, String fullPath, String originalIdInWorkspace, String mimeType, String url,
Integer childrenSize, String fullPath,
String originalIdInWorkspace, String mimeType, String url,
String description, String organizationNameDatasetParent) { String description, String organizationNameDatasetParent) {
super(); super();
this.identifierGWT = nextId; this.identifierGWT = nextId;
@ -162,11 +159,34 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
this.description = description; this.description = description;
this.organizationNameDatasetParent = organizationNameDatasetParent; this.organizationNameDatasetParent = organizationNameDatasetParent;
} }
public int getBeanID(){ /**
* Gets the bean ID.
*
* @return the bean ID
*/
public int getBeanID() {
return identifierGWT; return identifierGWT;
} }
/**
* Gets the ckan resource ID.
*
* @return the ckan resource ID
*/
public String getCkanResourceID() {
return ckanResourceID;
}
/**
* Sets the ckan resource ID.
*
* @param ckanResourceID the new ckan resource ID
*/
public void setCkanResourceID(String ckanResourceID) {
this.ckanResourceID = ckanResourceID;
}
/** /**
* Gets the parent. * Gets the parent.
* *
@ -289,8 +309,7 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
* *
* @param organizationNameDatasetParent the new organization name dataset parent * @param organizationNameDatasetParent the new organization name dataset parent
*/ */
public void setOrganizationNameDatasetParent( public void setOrganizationNameDatasetParent(String organizationNameDatasetParent) {
String organizationNameDatasetParent) {
this.organizationNameDatasetParent = organizationNameDatasetParent; this.organizationNameDatasetParent = organizationNameDatasetParent;
} }
@ -383,7 +402,7 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
public void setEditableName(String newName) { public void setEditableName(String newName) {
this.editableName = newName; this.editableName = newName;
} }
/** /**
* Gets the to publish. * Gets the to publish.
* *
@ -412,7 +431,7 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
public boolean equals(Object o) { public boolean equals(Object o) {
boolean toReturn = false; boolean toReturn = false;
if (o instanceof ResourceElementBean) { if (o instanceof ResourceElementBean) {
toReturn = identifierGWT == ((ResourceElementBean) o).identifierGWT; toReturn = identifierGWT == ((ResourceElementBean) o).identifierGWT;
} }
return toReturn; return toReturn;
@ -429,16 +448,30 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath); int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath);
return toReturn; return toReturn;
} }
/**
* Gets the root id in workspace.
*
* @return the root id in workspace
*/
public String getRootIdInWorkspace() { public String getRootIdInWorkspace() {
return rootIdInWorkspace; return rootIdInWorkspace;
} }
/**
* Sets the root id in workspace.
*
* @param rootIdInWorkspace the new root id in workspace
*/
public void setRootIdInWorkspace(String rootIdInWorkspace) { public void setRootIdInWorkspace(String rootIdInWorkspace) {
this.rootIdInWorkspace = rootIdInWorkspace; this.rootIdInWorkspace = rootIdInWorkspace;
} }
/**
* To string.
*
* @return the string
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -471,9 +504,5 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }