edit_facility_26115 #3
|
@ -59,11 +59,12 @@ public interface CKanPublisherService extends RemoteService {
|
|||
* Add this resource to the dataset whose id is datasetId.
|
||||
*
|
||||
* @param resource the resource
|
||||
* @param organizationName the organization name
|
||||
* @param datasetId the dataset id
|
||||
* @return the resource element bean
|
||||
* @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.
|
||||
|
|
|
@ -49,10 +49,11 @@ public interface CKanPublisherServiceAsync {
|
|||
* Add this resource to the dataset whose id is datasetId.
|
||||
*
|
||||
* @param resource the resource
|
||||
* @param organizationName the organization name
|
||||
* @param datasetId the dataset id
|
||||
* @param callback the callback
|
||||
*/
|
||||
void addResourceToDataset(ResourceElementBean resource, String datasetId,
|
||||
void addResourceToDataset(ResourceElementBean resource, String organizationName, String datasetId,
|
||||
AsyncCallback<ResourceElementBean> callback);
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,25 +2,30 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
|
|||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
/**
|
||||
* Deleted resource event.
|
||||
*
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> {
|
||||
public static Type<DeleteResourceEventHandler> TYPE = new Type<DeleteResourceEventHandler>();
|
||||
|
||||
private ResourceElementBean resource;
|
||||
|
||||
public DeleteResourceEvent(ResourceElementBean resource) {
|
||||
|
||||
private Button deleteButton;
|
||||
|
||||
public DeleteResourceEvent(Button deleteButton, ResourceElementBean resource) {
|
||||
this.resource = resource;
|
||||
this.deleteButton = deleteButton;
|
||||
}
|
||||
|
||||
public ResourceElementBean getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Type<DeleteResourceEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
|
@ -31,4 +36,19 @@ public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> {
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1301,15 +1301,15 @@ public class CreateDatasetForm extends Composite {
|
|||
addedResources.setHeading("Added Resource");
|
||||
tabPanel.add(addedResources);
|
||||
|
||||
// add tabs to resources panel
|
||||
tabPanel.selectTab(0);
|
||||
|
||||
// form container
|
||||
AddResourceContainer container = new AddResourceContainer(datasetUrl);
|
||||
container.add(tabPanel);
|
||||
|
||||
// add the new content of the main panel
|
||||
createDatasetMainPanel.add(container);
|
||||
|
||||
// add tabs to resources panel
|
||||
tabPanel.selectTab(0);
|
||||
}
|
||||
});
|
||||
} catch (Exception e2) {
|
||||
|
|
|
@ -161,7 +161,11 @@ public class UpdateDatasetForm extends Composite {
|
|||
@UiField
|
||||
HorizontalPanel goToDatasetButtonPanel;
|
||||
@UiField
|
||||
Button addResourcesButton;
|
||||
Button addResourcesButtonStep1;
|
||||
|
||||
@UiField
|
||||
Button addResourcesButtonStep3;
|
||||
|
||||
@UiField
|
||||
SimplePanel workspaceResourcesContainer;
|
||||
@UiField
|
||||
|
@ -323,7 +327,8 @@ public class UpdateDatasetForm extends Composite {
|
|||
private WizardCreator wizCreator;
|
||||
|
||||
private boolean isWorkspaceRequest = false;
|
||||
private String datasetIdOrName;
|
||||
private String datasetIdOrName = null;
|
||||
private DatasetBean theDataset = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new update dataset form.
|
||||
|
@ -387,6 +392,7 @@ public class UpdateDatasetForm extends Composite {
|
|||
// disable continue button
|
||||
continueButton.setEnabled(false);
|
||||
resetButton.setEnabled(false);
|
||||
addResourcesButtonStep1.setEnabled(false);
|
||||
|
||||
// hide tags panel
|
||||
tagsPanel.setVisible(false);
|
||||
|
@ -415,34 +421,35 @@ public class UpdateDatasetForm extends Composite {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(final DatasetBean bean) {
|
||||
GWT.log("getDatasetBeanForUpdate returns: " + bean);
|
||||
public void onSuccess(final DatasetBean datasetBean) {
|
||||
GWT.log("getDatasetBeanForUpdate returns: " + datasetBean);
|
||||
theDataset = datasetBean;
|
||||
|
||||
if (bean == null) {
|
||||
if (datasetBean == null) {
|
||||
|
||||
setAlertBlock("Error while retrieving information.", AlertType.ERROR, true);
|
||||
} else {
|
||||
|
||||
// save it
|
||||
receivedBean = bean;
|
||||
receivedBean = datasetBean;
|
||||
|
||||
// fill the form
|
||||
titleTextBox.setText(bean.getTitle());
|
||||
descriptionTextarea.setText(bean.getDescription());
|
||||
versionTextbox.setText(String.valueOf(bean.getVersion()));
|
||||
authorTextbox.setText(bean.getAuthorFullName());
|
||||
authorEmailTextbox.setText(bean.getAuthorEmail());
|
||||
maintainerTextbox.setText(bean.getMaintainer());
|
||||
maintainerEmailTextbox.setText(bean.getMaintainerEmail());
|
||||
titleTextBox.setText(datasetBean.getTitle());
|
||||
descriptionTextarea.setText(datasetBean.getDescription());
|
||||
versionTextbox.setText(String.valueOf(datasetBean.getVersion()));
|
||||
authorTextbox.setText(datasetBean.getAuthorFullName());
|
||||
authorEmailTextbox.setText(datasetBean.getAuthorEmail());
|
||||
maintainerTextbox.setText(datasetBean.getMaintainer());
|
||||
maintainerEmailTextbox.setText(datasetBean.getMaintainerEmail());
|
||||
|
||||
setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true);
|
||||
|
||||
// vocabulary list of tags has preemption
|
||||
List<String> vocabularyTags = bean.getTagsVocabulary();
|
||||
List<String> vocabularyTags = datasetBean.getTagsVocabulary();
|
||||
if (vocabularyTags != null) {
|
||||
tagsPanel.setVocabulary(vocabularyTags);
|
||||
if (bean.getTags() != null) {
|
||||
for (String tag : bean.getTags()) {
|
||||
if (datasetBean.getTags() != null) {
|
||||
for (String tag : datasetBean.getTags()) {
|
||||
tagsPanel.addTagElement(tag);
|
||||
}
|
||||
|
||||
|
@ -452,7 +459,7 @@ public class UpdateDatasetForm extends Composite {
|
|||
// THIS BLOCK is it required? Probably not.
|
||||
|
||||
// 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
|
||||
if (customFieldsMap != null && vocabularyTags == null) {
|
||||
// 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.
|
||||
if (bean.getResourceRoot() != null) {
|
||||
if (datasetBean.getResourceRoot() != null) {
|
||||
resourcesSelectByWEMainPanel = new SelectResourceByWEMainPanel(
|
||||
bean.getResourceRoot());
|
||||
datasetBean.getResourceRoot());
|
||||
}
|
||||
|
||||
// set organizations
|
||||
List<OrganizationBean> organizations = bean.getOrganizationList();
|
||||
List<OrganizationBean> organizations = datasetBean.getOrganizationList();
|
||||
|
||||
for (OrganizationBean organization : organizations) {
|
||||
organizationsListbox.addItem(organization.getTitle());
|
||||
|
@ -525,6 +532,9 @@ public class UpdateDatasetForm extends Composite {
|
|||
// get the name of the organization from the title
|
||||
final String orgName = nameTitleOrganizationMap
|
||||
.get(organizationsListbox.getSelectedItemText());
|
||||
|
||||
//Putting the selected Organization into bena
|
||||
theDataset.setSelectedOrganization(orgName);
|
||||
|
||||
// force tags
|
||||
// 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);
|
||||
|
||||
// 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>() {
|
||||
|
||||
@Override
|
||||
|
@ -649,8 +659,9 @@ public class UpdateDatasetForm extends Composite {
|
|||
false);
|
||||
continueButton.setEnabled(true);
|
||||
resetButton.setEnabled(true);
|
||||
addResourcesButtonStep1.setEnabled(true);
|
||||
|
||||
manageAddResources(bean,
|
||||
manageAddResources(datasetBean,
|
||||
datasetIdOrName);
|
||||
}
|
||||
}
|
||||
|
@ -733,6 +744,8 @@ public class UpdateDatasetForm extends Composite {
|
|||
// get the name of the organization from the title
|
||||
String selectedOrganizationTitle = organizationsListbox.getSelectedItemText();
|
||||
final String orgName = nameTitleOrganizationMap.get(selectedOrganizationTitle);
|
||||
|
||||
theDataset.setSelectedOrganization(orgName);
|
||||
|
||||
// try to retrieve the profiles
|
||||
setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true);
|
||||
|
@ -955,13 +968,6 @@ public class UpdateDatasetForm extends Composite {
|
|||
|
||||
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;
|
||||
try {
|
||||
fieldWidget = new MetaDataField(metadataFieldWrapper, eventBus, operation);
|
||||
|
@ -979,13 +985,6 @@ public class UpdateDatasetForm extends Composite {
|
|||
CategoryPanel extrasCategory = new CategoryPanel("Other", null);
|
||||
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;
|
||||
try {
|
||||
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 (!isWorkspaceRequest) {
|
||||
|
||||
try {
|
||||
// show the add resources button
|
||||
addResourcesButton.setVisible(true);
|
||||
|
||||
final AddedResourcesSummary addedResourcesSummary = initTabManageResourcePanel(theDatasetBean, datasetUrl);
|
||||
|
||||
addResourcesButtonStep1.setVisible(true);
|
||||
addResourcesButtonStep3.setVisible(true);
|
||||
|
||||
final AddedResourcesSummary addedResourcesSummary = initTabManageResourcePanel(theDatasetBean,
|
||||
datasetUrl);
|
||||
|
||||
final List<ResourceElementBean> resources = theDatasetBean.getCkanResources();
|
||||
GWT.log("Resources are: " + resources);
|
||||
|
||||
if (resources != null
|
||||
&& resources.size() > 0) {
|
||||
|
||||
if (resources != null && resources.size() > 0) {
|
||||
GWT.log("Executing are: " + resources);
|
||||
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() {
|
||||
// @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() {
|
||||
addResourcesButtonStep1.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
// remove content of the main panel
|
||||
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);
|
||||
manageResourcesOnFire(datasetUrl);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
addResourcesButtonStep3.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
manageResourcesOnFire(datasetUrl);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e2) {
|
||||
// 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) {
|
||||
// TabPanelException
|
||||
|
||||
if(tabPanel!=null)
|
||||
|
||||
if (tabPanel != null)
|
||||
tabPanel.clear();
|
||||
|
||||
|
||||
tabPanel = new TabPanel(Tabs.LEFT);
|
||||
tabPanel.setWidth("100%");
|
||||
|
||||
// add the form
|
||||
|
||||
resourceForm = new AddResourceToDataset(eventBus, theDatasetBean.getId(),
|
||||
theDatasetBean.getTitle(), theDatasetBean.getSelectedOrganization(), owner, datasetUrl);
|
||||
resourceForm = new AddResourceToDataset(eventBus, theDatasetBean.getId(), theDatasetBean.getTitle(),
|
||||
theDatasetBean.getSelectedOrganization(), owner, datasetUrl);
|
||||
|
||||
// tab for the form
|
||||
Tab formContainer = new Tab();
|
||||
|
@ -1475,15 +1473,8 @@ public class UpdateDatasetForm extends Composite {
|
|||
addedResources.add(addedResourcesSummary);
|
||||
addedResources.setHeading("Added Resource");
|
||||
tabPanel.add(addedResources);
|
||||
|
||||
|
||||
return addedResourcesSummary;
|
||||
|
||||
// add tabs to resources panel
|
||||
// tabPanel.selectTab(0);
|
||||
|
||||
// // form container
|
||||
// AddResourceContainer container = new AddResourceContainer(datasetUrl);
|
||||
// container.add(tabPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -337,6 +337,10 @@
|
|||
<b:Button title="Continue" ui:field="continueButton"
|
||||
type="PRIMARY" block="true">Continue</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:Form>
|
||||
|
@ -368,6 +372,7 @@
|
|||
<b:Button title="Go Back" ui:field="goBackButtonFirstStep"
|
||||
block="true">Go
|
||||
Back</b:Button>
|
||||
|
||||
</b:Fieldset>
|
||||
</b:Form>
|
||||
|
||||
|
@ -425,16 +430,16 @@
|
|||
styleName="{style.the-margin-gotoitem}"></b:Button>
|
||||
</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"
|
||||
type="PRIMARY" block="true">Create</b:Button>
|
||||
type="PRIMARY" block="true">Update</b:Button>
|
||||
|
||||
<b:Button title="Go Back" ui:field="goBackButtonSecondStep"
|
||||
block="true">Go
|
||||
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:Form>
|
||||
|
|
|
@ -61,7 +61,7 @@ public class AddResourceToDataset extends Composite{
|
|||
@UiField ControlGroup nameControlGroup;
|
||||
@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));
|
||||
// save bus
|
||||
this.eventBus = eventBus;
|
||||
|
@ -137,7 +137,7 @@ public class AddResourceToDataset extends Composite{
|
|||
infoPanel.add(loader);
|
||||
|
||||
// try to create
|
||||
ckanServices.addResourceToDataset(resource, datasetId, new AsyncCallback<ResourceElementBean>() {
|
||||
ckanServices.addResourceToDataset(resource, datasetOrg, datasetId, new AsyncCallback<ResourceElementBean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ResourceElementBean result) {
|
||||
|
|
|
@ -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.AccordionGroup;
|
||||
import com.github.gwtbootstrap.client.ui.Alert;
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
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.event.dom.client.ClickEvent;
|
||||
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.user.client.rpc.AsyncCallback;
|
||||
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.Widget;
|
||||
|
||||
|
@ -46,8 +49,14 @@ public class AddedResourcesSummary extends Composite {
|
|||
@UiField
|
||||
VerticalPanel addResourcesPanel;
|
||||
|
||||
@UiField
|
||||
Alert alertMessage;
|
||||
|
||||
public AddedResourcesSummary(HandlerManager eventBus) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
|
||||
alertMessage.setType(AlertType.ERROR);
|
||||
alertMessage.setClose(true);
|
||||
// save bus
|
||||
this.eventBus = eventBus;
|
||||
// bind on add resource event
|
||||
|
@ -75,23 +84,31 @@ public class AddedResourcesSummary extends Composite {
|
|||
Accordion accordion = new Accordion();
|
||||
AccordionGroup accordionGroup = new AccordionGroup();
|
||||
accordionGroup.setHeading("* " + justAddedResource.getName());
|
||||
accordionGroup.getHeading().getElement().getStyle().setBackgroundColor("#FFEDBE");
|
||||
accordion.add(accordionGroup);
|
||||
|
||||
// add sub-info such as url and description
|
||||
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();
|
||||
pDescription.setText("Description : " + justAddedResource.getDescription());
|
||||
|
||||
// button to delete the resource
|
||||
Button deleteButton = new Button();
|
||||
final Button deleteButton = new Button();
|
||||
deleteButton.setText("Delete");
|
||||
deleteButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
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() {
|
||||
|
||||
@Override
|
||||
public void onDeletedResource(DeleteResourceEvent deleteResourceEvent) {
|
||||
public void onDeletedResource(final DeleteResourceEvent deleteResourceEvent) {
|
||||
GWT.log("onDeletedResource resource event: " + deleteResourceEvent);
|
||||
|
||||
// to delete
|
||||
ResourceElementBean toDelete = deleteResourceEvent.getResource();
|
||||
final ResourceElementBean toDelete = deleteResourceEvent.getResource();
|
||||
|
||||
Button toDeleteButton = deleteResourceEvent.getDeleteButton();
|
||||
|
||||
toDeleteButton.setEnabled(false);
|
||||
|
||||
// find it
|
||||
for (int i = 0; i < addedResources.size(); i++) {
|
||||
|
@ -135,16 +156,24 @@ public class AddedResourcesSummary extends Composite {
|
|||
public void onSuccess(Boolean 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();
|
||||
} else {
|
||||
alertMessage.setVisible(true);
|
||||
alertMessage.setHTML("Sorry, the resource described by "
|
||||
+ toDelete.getName() + " cannot be deleted");
|
||||
}
|
||||
|
||||
// remove from the list
|
||||
addedResources.remove(toDelete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
toDeleteButton.setEnabled(false);
|
||||
alertMessage.setVisible(true);
|
||||
alertMessage.setHTML(caught.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<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">
|
||||
<g:HTMLPanel>
|
||||
<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>
|
||||
</ui:UiBinder>
|
|
@ -389,8 +389,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
// 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);
|
||||
bean.setOrganizationList(
|
||||
Arrays.asList(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName(), true)));
|
||||
final OrganizationBean ckanOrganizationBean = new OrganizationBean(ckanOrganization.getTitle(),
|
||||
ckanOrganization.getName(), true);
|
||||
bean.setOrganizationList(Arrays.asList(ckanOrganizationBean));
|
||||
|
||||
List<CkanTag> listDatasetTags = dataset.getTags();
|
||||
|
||||
|
@ -426,7 +427,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
if (resources != null) {
|
||||
List<ResourceElementBean> list = new ArrayList<ResourceElementBean>(resources.size());
|
||||
for (CkanResource ckanResource : resources) {
|
||||
ResourceElementBean reb = PublisherCatalogueConveter.toResourceElementBean(ckanResource);
|
||||
ResourceElementBean reb = PublisherCatalogueConveter.toResourceElementBean(ckanResource,
|
||||
ckanOrganizationBean.getName());
|
||||
list.add(reb);
|
||||
}
|
||||
bean.setResources(list);
|
||||
|
@ -640,7 +642,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
if (listCurrentResources != null) {
|
||||
resources = new ArrayList<ResourceBean>(listCurrentResources.size());
|
||||
for (CkanResource ckanResource : listCurrentResources) {
|
||||
ResourceBean reb = PublisherCatalogueConveter.toResourceBean(ckanResource);
|
||||
String orgName = null; // not required here
|
||||
ResourceBean reb = PublisherCatalogueConveter.toResourceBean(ckanResource, orgName);
|
||||
resources.add(reb);
|
||||
}
|
||||
}
|
||||
|
@ -714,13 +717,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
/**
|
||||
* Adds the resource to dataset.
|
||||
*
|
||||
* @param resource the resource
|
||||
* @param datasetId the dataset id
|
||||
* @param resource the resource
|
||||
* @param organizationName the organization name
|
||||
* @param datasetId the dataset id
|
||||
* @return the resource element bean
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@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");
|
||||
devModeSetContexts();
|
||||
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
|
||||
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
|
||||
DataCatalogue catalogue = getCatalogue(scope);
|
||||
String resourceId = catalogue.addResourceToDataset(resourceBean, resource.getOrganizationNameDatasetParent(),
|
||||
username);
|
||||
CkanResource theCreatedResource = catalogue.addResource(resourceBean, datasetId,
|
||||
resource.getOrganizationNameDatasetParent(), username);
|
||||
|
||||
if (resourceId != null) {
|
||||
if (theCreatedResource != null) {
|
||||
logger.info("Resource " + resource.getName() + " is now available");
|
||||
// set its id and turn it to the client
|
||||
resource.setOriginalIdInWorkspace(resourceId);
|
||||
return resource;
|
||||
|
||||
ResourceElementBean reb = PublisherCatalogueConveter.toResourceElementBean(theCreatedResource,
|
||||
organizationName);
|
||||
|
||||
return reb;
|
||||
}
|
||||
|
||||
logger.debug("No resource created");
|
||||
|
@ -767,14 +774,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
|
||||
DataCatalogue catalogue = getCatalogue(scope);
|
||||
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), username);
|
||||
deleted = catalogue.deleteResourceFromDataset(resource.getCkanResourceID(), username);
|
||||
if (deleted) {
|
||||
logger.info("Resource described by " + resource + " deleted");
|
||||
} else
|
||||
logger.error("Resource described by " + resource + " NOT deleted");
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while trying to delete resource described by " + resource, e);
|
||||
throw new Exception("Error while trying to delete resource." + e.getMessage());
|
||||
String error = "Sorry, an error occurred while trying to delete resource described by "
|
||||
+ resource.getName();
|
||||
logger.error(error, e);
|
||||
throw new Exception(error + ". Error is: " + e.getMessage());
|
||||
}
|
||||
return deleted;
|
||||
|
||||
|
|
|
@ -4,31 +4,42 @@ import org.gcube.datacatalogue.utillibrary.shared.ResourceBean;
|
|||
import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanResource;
|
||||
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 {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static ResourceElementBean toResourceElementBean(CkanResource ckanResource) {
|
||||
public static ResourceElementBean toResourceElementBean(CkanResource ckanResource, String orgNameParent) {
|
||||
ResourceElementBean reb = new ResourceElementBean();
|
||||
reb.setCkanResourceID(ckanResource.getId());
|
||||
reb.setName(ckanResource.getName());
|
||||
reb.setDescription(ckanResource.getDescription());
|
||||
reb.setEditableName(ckanResource.getName());
|
||||
reb.setUrl(ckanResource.getUrl());
|
||||
reb.setMimeType(ckanResource.getMimetype());
|
||||
reb.setOrganizationNameDatasetParent(orgNameParent);
|
||||
return reb;
|
||||
}
|
||||
|
||||
/**
|
||||
* To resource bean.
|
||||
*
|
||||
* @param ckanResource the ckan resource
|
||||
* @param ckanResource the ckan resource
|
||||
* @param orgNameParent the org name parent
|
||||
* @return the resource bean
|
||||
*/
|
||||
public static ResourceBean toResourceBean(CkanResource ckanResource) {
|
||||
public static ResourceBean toResourceBean(CkanResource ckanResource, String orgNameParent) {
|
||||
ResourceBean reb = new ResourceBean();
|
||||
reb.setName(ckanResource.getName());
|
||||
reb.setDescription(ckanResource.getDescription());
|
||||
|
|
|
@ -6,74 +6,77 @@ import java.util.List;
|
|||
import com.google.gwt.user.client.rpc.IsSerializable;
|
||||
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 revisited by Francesco Mangiacrapa
|
||||
*/
|
||||
public class ResourceElementBean implements Comparable<ResourceElementBean>, Serializable, IsSerializable{
|
||||
public class ResourceElementBean implements Comparable<ResourceElementBean>, Serializable, IsSerializable {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = -1230871392599580669L;
|
||||
|
||||
|
||||
/** The name. */
|
||||
private String name;
|
||||
|
||||
|
||||
/** The editable name. */
|
||||
private String editableName;
|
||||
|
||||
|
||||
/** The to be added. */
|
||||
private boolean toBeAdded;
|
||||
|
||||
|
||||
/** The is folder. */
|
||||
private boolean isFolder;
|
||||
|
||||
|
||||
/** The full path. */
|
||||
private String fullPath;
|
||||
|
||||
|
||||
/** The original id in workspace. */
|
||||
private String originalIdInWorkspace;
|
||||
|
||||
|
||||
private String rootIdInWorkspace;
|
||||
|
||||
|
||||
/** The mime type. */
|
||||
private String mimeType;
|
||||
|
||||
|
||||
/** The url. */
|
||||
private String url;
|
||||
|
||||
|
||||
/** The description. */
|
||||
private String description;
|
||||
|
||||
|
||||
/** The organization name dataset parent. */
|
||||
private String organizationNameDatasetParent; // the organization name in which the parent dataset was created
|
||||
|
||||
|
||||
/** The parent. */
|
||||
private ResourceElementBean parent;
|
||||
|
||||
|
||||
/** The children size. */
|
||||
private Integer childrenSize;
|
||||
|
||||
|
||||
// /** The to publish. */
|
||||
private List<ResourceElementBean> toPublish; //Resources that must be published
|
||||
private List<ResourceElementBean> toPublish; // Resources that must be published
|
||||
|
||||
/** The next id. */
|
||||
// to generate the GWT identifiers
|
||||
private static int nextId = 0;
|
||||
|
||||
|
||||
/** The identifier GWT. */
|
||||
// identifier of this instance
|
||||
private int identifierGWT;
|
||||
|
||||
private String ckanResourceID;
|
||||
|
||||
/**
|
||||
* The key provider that provides the unique ID of a bean.
|
||||
*/
|
||||
public static final ProvidesKey<ResourceElementBean> KEY_PROVIDER = new ProvidesKey<ResourceElementBean>() {
|
||||
@Override
|
||||
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.
|
||||
*/
|
||||
public ResourceElementBean(){
|
||||
public ResourceElementBean() {
|
||||
super();
|
||||
this.identifierGWT = nextId;
|
||||
nextId++;
|
||||
|
@ -106,17 +109,13 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
/**
|
||||
* Instantiates a new resource element bean.
|
||||
*
|
||||
* @param parent the parent
|
||||
* @param name the name
|
||||
* @param isFolder the is folder
|
||||
* @param parent the parent
|
||||
* @param name the name
|
||||
* @param isFolder the is folder
|
||||
* @param childrenSize the children size
|
||||
* @param fullPath the full path
|
||||
* @param fullPath the full path
|
||||
*/
|
||||
public ResourceElementBean(
|
||||
ResourceElementBean parent,
|
||||
String name,
|
||||
boolean isFolder,
|
||||
Integer childrenSize,
|
||||
public ResourceElementBean(ResourceElementBean parent, String name, boolean isFolder, Integer childrenSize,
|
||||
String fullPath) {
|
||||
this.identifierGWT = nextId;
|
||||
nextId++;
|
||||
|
@ -130,22 +129,20 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
/**
|
||||
* Instantiates a new resource element bean.
|
||||
*
|
||||
* @param name the name
|
||||
* @param toBeAdded the to be added
|
||||
* @param isFolder the is folder
|
||||
* @param parent the parent
|
||||
* @param childrenSize the children size
|
||||
* @param fullPath the full path
|
||||
* @param originalIdInWorkspace the original id in workspace
|
||||
* @param mimeType the mime type
|
||||
* @param url the url
|
||||
* @param description the description
|
||||
* @param name the name
|
||||
* @param toBeAdded the to be added
|
||||
* @param isFolder the is folder
|
||||
* @param parent the parent
|
||||
* @param childrenSize the children size
|
||||
* @param fullPath the full path
|
||||
* @param originalIdInWorkspace the original id in workspace
|
||||
* @param mimeType the mime type
|
||||
* @param url the url
|
||||
* @param description the description
|
||||
* @param organizationNameDatasetParent the organization name dataset parent
|
||||
*/
|
||||
public ResourceElementBean(String name, boolean toBeAdded,
|
||||
boolean isFolder, ResourceElementBean parent,
|
||||
Integer childrenSize, String fullPath,
|
||||
String originalIdInWorkspace, String mimeType, String url,
|
||||
public ResourceElementBean(String name, boolean toBeAdded, boolean isFolder, ResourceElementBean parent,
|
||||
Integer childrenSize, String fullPath, String originalIdInWorkspace, String mimeType, String url,
|
||||
String description, String organizationNameDatasetParent) {
|
||||
super();
|
||||
this.identifierGWT = nextId;
|
||||
|
@ -162,11 +159,34 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
this.description = description;
|
||||
this.organizationNameDatasetParent = organizationNameDatasetParent;
|
||||
}
|
||||
|
||||
public int getBeanID(){
|
||||
|
||||
/**
|
||||
* Gets the bean ID.
|
||||
*
|
||||
* @return the bean ID
|
||||
*/
|
||||
public int getBeanID() {
|
||||
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.
|
||||
*
|
||||
|
@ -289,8 +309,7 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
*
|
||||
* @param organizationNameDatasetParent the new organization name dataset parent
|
||||
*/
|
||||
public void setOrganizationNameDatasetParent(
|
||||
String organizationNameDatasetParent) {
|
||||
public void setOrganizationNameDatasetParent(String organizationNameDatasetParent) {
|
||||
this.organizationNameDatasetParent = organizationNameDatasetParent;
|
||||
}
|
||||
|
||||
|
@ -383,7 +402,7 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
public void setEditableName(String newName) {
|
||||
this.editableName = newName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the to publish.
|
||||
*
|
||||
|
@ -412,7 +431,7 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
public boolean equals(Object o) {
|
||||
boolean toReturn = false;
|
||||
if (o instanceof ResourceElementBean) {
|
||||
toReturn = identifierGWT == ((ResourceElementBean) o).identifierGWT;
|
||||
toReturn = identifierGWT == ((ResourceElementBean) o).identifierGWT;
|
||||
}
|
||||
|
||||
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);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the root id in workspace.
|
||||
*
|
||||
* @return the root id in workspace
|
||||
*/
|
||||
public String getRootIdInWorkspace() {
|
||||
return rootIdInWorkspace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the root id in workspace.
|
||||
*
|
||||
* @param rootIdInWorkspace the new root id in workspace
|
||||
*/
|
||||
public void setRootIdInWorkspace(String rootIdInWorkspace) {
|
||||
this.rootIdInWorkspace = rootIdInWorkspace;
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -471,9 +504,5 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue