The widget can be also called from outside the workspace now

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@128994 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-06 15:24:52 +00:00
parent 66fd421732
commit 1e95f70f5f
14 changed files with 787 additions and 232 deletions

View File

@ -1,4 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
lastWarOutDir=/home/costantino/workspace/ckan-metadata-publisher-widget/target/ckan-metadata-publisher-widget-1.0.0-SNAPSHOT lastWarOutDir=/home/costantino/workspace/ckan-metadata-publisher-widget/target/ckan-metadata-publisher-widget-1.0.0-SNAPSHOT
warSrcDir=src/main/webapp warSrcDir=src/main/webapp
warSrcDirIsOutput=false warSrcDirIsOutput=false

View File

@ -1,4 +0,0 @@
Manifest-Version: 1.0
Implementation-Title: Gwt-Tour
Implementation-Version: 2.0.0-SNAPSHOT

View File

@ -1,13 +0,0 @@
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# Print only messages of level TRACE or above in the package org.gcube
log4j.logger.org.gcube=TRACE
log4j.logger.org.gcube.application.framework.core.session=INFO
log4j.logger.com.netflix.astyanax.connectionpool=ERROR
log4j.logger.org.gcube.portal.databook.server.DBCassandraAstyanaxImpl=TRACE
log4j.logger.org.gcube.common=ERROR

12
pom.xml
View File

@ -56,6 +56,11 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency> <dependency>
<groupId>com.google.gwt</groupId> <groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId> <artifactId>gwt-servlet</artifactId>
@ -150,10 +155,15 @@
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.dataaccess</groupId>
<artifactId>ckan-util-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId> <artifactId>common-scope-maps</artifactId>
<scope>runtime</scope> <scope>compile</scope>
<!-- put at provided for deploying --> <!-- put at provided for deploying -->
</dependency> </dependency>
<dependency> <dependency>

View File

@ -22,9 +22,9 @@ public class CKanMetadataPublisher implements EntryPoint {
private void startExample() { private void startExample() {
String idFolderWorkspace = "06bc1ca7-bf1b-4797-b0a4-cb8a55a9c189"; String idFolderWorkspace = "8b67fc1f-940d-4512-b783-105fba11c270";
String owner = "costantino.perciante"; String owner = "costantino.perciante";
RootPanel.get("ckan-metadata-publisher-div").add(new EditMetadataForm(idFolderWorkspace, owner)); RootPanel.get("ckan-metadata-publisher-div").add(new EditMetadataForm(owner));
} }
} }

View File

@ -14,7 +14,25 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("ckanservices") @RemoteServiceRelativePath("ckanservices")
public interface CKanPublisherService extends RemoteService { public interface CKanPublisherService extends RemoteService {
/**
* Retrieve the list of licenses to show to the user.
* @return a LicenseBean on success, <b>null</b> on error.
*/
LicensesBean getLicenses(); LicensesBean getLicenses();
/**
* Retrieve a partially filled bean given a folder id and its owner.
* @param folderId
* @param owner
* @return @return a DatasetMetadataBean on success, <b>null</b> on error.
*/
DatasetMetadataBean getDatasetBean(String folderId, String owner); DatasetMetadataBean getDatasetBean(String folderId, String owner);
/**
* Try to create such dataset starting from the information contained into the toCreate bean.
* @param toCreate
* @return <b>true</b> on success, <b>false</b> otherwise
*/
boolean createCKanDataset(DatasetMetadataBean toCreate);
} }

View File

@ -12,9 +12,27 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
*/ */
public interface CKanPublisherServiceAsync { public interface CKanPublisherServiceAsync {
/**
* Retrieve the list of licenses to show to the user.
* @return a LicenseBean on success, <b>null</b> on error.
*/
void getLicenses(AsyncCallback<LicensesBean> callback); void getLicenses(AsyncCallback<LicensesBean> callback);
/**
* Retrieve a partially filled bean given a folder id and its owner.
* @param folderId
* @param owner
* @return @return a DatasetMetadataBean on success, <b>null</b> on error.
*/
void getDatasetBean(String folderId, String owner, void getDatasetBean(String folderId, String owner,
AsyncCallback<DatasetMetadataBean> callback); AsyncCallback<DatasetMetadataBean> callback);
/**
* Try to create such dataset starting from the information contained into the toCreate bean.
* @param toCreate
* @return <b>true</b> on success, <b>false</b> otherwise
*/
void createCKanDataset(DatasetMetadataBean toCreate,
AsyncCallback<Boolean> callback);
} }

View File

@ -14,6 +14,10 @@ import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
/**
* A custom field entry that has two textboxes, one for the key value and the other for the value.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class CustomFieldEntry extends Composite { public class CustomFieldEntry extends Composite {
private static CustomFieldEntryUiBinder uiBinder = GWT private static CustomFieldEntryUiBinder uiBinder = GWT
@ -27,22 +31,32 @@ public class CustomFieldEntry extends Composite {
@UiField InputAddOn valueFieldPrepend; @UiField InputAddOn valueFieldPrepend;
@UiField Button removeCustomField; @UiField Button removeCustomField;
//inserted values
private String value;
private String key;
private boolean isCustomCreatedByUser;
// event bus // event bus
private HandlerManager eventBus; private HandlerManager eventBus;
public CustomFieldEntry(HandlerManager eventBus) { public CustomFieldEntry(HandlerManager eventBus, String key, String value, boolean isCustomCreatedByUser) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
// save information
this.eventBus = eventBus; this.eventBus = eventBus;
this.value = value;
this.key = key;
this.isCustomCreatedByUser = isCustomCreatedByUser;
// remove the first appendbox
if(!isCustomCreatedByUser){
this.valueFieldPrepend.removeFromParent();
this.keyFieldPrepend.setPrependText(key + ":");
((TextBox)this.keyFieldPrepend.getWidget(1)).setText(value);
}else{
// do nothing, the user should fill key and value pair
} }
/**
* Check if it has been added by the user during form creation or comes from the workspace
* @return
*/
private boolean isCreatedCustomField(){
return valueFieldPrepend.isAttached();
} }
/** /**
@ -51,10 +65,13 @@ public class CustomFieldEntry extends Composite {
*/ */
public String getKey(){ public String getKey(){
if(isCreatedCustomField()) if(isCustomCreatedByUser){
return ((TextBox)keyFieldPrepend.getWidget(1)).getValue();
else return ((TextBox)this.keyFieldPrepend.getWidget(1)).getText();
return valueFieldPrepend.get
}
return key;
} }
@ -64,11 +81,13 @@ public class CustomFieldEntry extends Composite {
*/ */
public String getValue(){ public String getValue(){
if(isCreatedCustomField()) if(isCustomCreatedByUser){
return ((TextBox)valueFieldPrepend.getWidget(1)).getValue();
else
return valueFieldPrepend.getWidgetIndex(1).get
return ((TextBox)this.valueFieldPrepend.getWidget(1)).getText();
}
return value;
} }
@UiHandler("removeCustomField") @UiHandler("removeCustomField")

View File

@ -7,18 +7,20 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.commons.lang.StringEscapeUtils;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEvent; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEvent;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.Span;
import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.AlertBlock;
import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.CheckBox;
import com.github.gwtbootstrap.client.ui.ControlGroup; import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.Label; import com.github.gwtbootstrap.client.ui.HelpBlock;
import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.TextBox;
@ -33,6 +35,7 @@ import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder; 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.uibinder.client.UiHandler; import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
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.FlowPanel; import com.google.gwt.user.client.ui.FlowPanel;
@ -63,6 +66,7 @@ public class EditMetadataForm extends Composite{
@UiField ListBox licenseListbox; @UiField ListBox licenseListbox;
@UiField ListBox visibilityListbox; @UiField ListBox visibilityListbox;
@UiField ListBox searchableListbox; @UiField ListBox searchableListbox;
@UiField ListBox organizationsListbox;
@UiField TextBox versionTextbox; @UiField TextBox versionTextbox;
@UiField TextBox authorTextbox; @UiField TextBox authorTextbox;
@UiField TextBox authorEmailTextbox; @UiField TextBox authorEmailTextbox;
@ -70,9 +74,11 @@ public class EditMetadataForm extends Composite{
@UiField TextBox maintainerEmailTextbox; @UiField TextBox maintainerEmailTextbox;
@UiField ControlGroup customFields; @UiField ControlGroup customFields;
@UiField Button addCustomFieldButton; @UiField Button addCustomFieldButton;
@UiField CheckBox addResourcesCheckBox;
@UiField Button createButton; @UiField Button createButton;
@UiField Button resetButton; @UiField Button resetButton;
@UiField AlertBlock infoBlock; @UiField AlertBlock infoBlock;
@UiField AlertBlock onCreateAlertBlock;
// tags list // tags list
private List<String> tagsList = new ArrayList<String>(); private List<String> tagsList = new ArrayList<String>();
@ -84,11 +90,110 @@ public class EditMetadataForm extends Composite{
private final HandlerManager eventBus = new HandlerManager(null); private final HandlerManager eventBus = new HandlerManager(null);
// added custom field entries // added custom field entries
List<CustomFieldEntry> customFieldEntries = new ArrayList<CustomFieldEntry>(); List<CustomFieldEntry> customFieldEntriesList = new ArrayList<CustomFieldEntry>();
// dataset metadata bean // dataset metadata bean
private DatasetMetadataBean receivedBean; private DatasetMetadataBean receivedBean;
/**
* Invoked in the most general case
* @param owner
*/
public EditMetadataForm(String user) {
initWidget(uiBinder.createAndBindUi(this));
// bind on events
bind();
// set info block
setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true);
// disable create button
createButton.setEnabled(false);
resetButton.setEnabled(false);
// get back the licenses and the metadata information
ckanServices.getDatasetBean(null, user, new AsyncCallback<DatasetMetadataBean>() {
@Override
public void onSuccess(DatasetMetadataBean bean) {
if(bean != null){
// save it
receivedBean = bean;
// fill the form
versionTextbox.setText(String.valueOf(bean.getVersion()));
authorTextbox.setText(bean.getAuthor());
authorEmailTextbox.setText(bean.getAuthorEmail());
maintainerTextbox.setText(bean.getMaintainer());
maintainerEmailTextbox.setText(bean.getMaintainerEmail());
// set organizations
List<String> organizations = bean.getOrganizationList();
for (String organization : organizations) {
organizationsListbox.addItem(organization);
}
// try to retrieve the licenses
setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true);
ckanServices.getLicenses(new AsyncCallback<LicensesBean>() {
@Override
public void onSuccess(LicensesBean lBean) {
if(lBean != null && !lBean.getLicenses().isEmpty()){
licenseBean = lBean;
// fill the listbox
for(String license: licenseBean.getLicenses()){
licenseListbox.addItem(license);
}
// everything went ok
setAlertBlock("", AlertType.ERROR, false);
createButton.setEnabled(true);
resetButton.setEnabled(true);
}else{
setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true);
}
}
@Override
public void onFailure(Throwable caught) {
setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true);
}
});
}else{
setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true);
}
}
@Override
public void onFailure(Throwable caught) {
setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true);
}
});
}
/**
* Invoked when the workspace is used.
* @param idFolderWorkspace
* @param owner
*/
public EditMetadataForm(String idFolderWorkspace, String owner) { public EditMetadataForm(String idFolderWorkspace, String owner) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
@ -100,6 +205,7 @@ public class EditMetadataForm extends Composite{
// disable create button // disable create button
createButton.setEnabled(false); createButton.setEnabled(false);
resetButton.setEnabled(false);
// get back the licenses and the metadata information from the workspace // get back the licenses and the metadata information from the workspace
ckanServices.getDatasetBean(idFolderWorkspace, owner, new AsyncCallback<DatasetMetadataBean>() { ckanServices.getDatasetBean(idFolderWorkspace, owner, new AsyncCallback<DatasetMetadataBean>() {
@ -121,10 +227,21 @@ public class EditMetadataForm extends Composite{
maintainerTextbox.setText(bean.getMaintainer()); maintainerTextbox.setText(bean.getMaintainer());
maintainerEmailTextbox.setText(bean.getMaintainerEmail()); maintainerEmailTextbox.setText(bean.getMaintainerEmail());
// set organizations
List<String> organizations = bean.getOrganizationList();
for (String organization : organizations) {
organizationsListbox.addItem(organization);
}
// retrieve custom fields // retrieve custom fields
Map<String, String> customFieldsMap = bean.getCustomFields(); Map<String, String> customFieldsMap = bean.getCustomFields();
if(customFields != null){ GWT.log("Custom fields is " + customFieldsMap);
if(customFieldsMap != null){
// get the keys and put them as tags // get the keys and put them as tags
Iterator<Entry<String, String>> iteratorOverCustomField = customFieldsMap.entrySet().iterator(); Iterator<Entry<String, String>> iteratorOverCustomField = customFieldsMap.entrySet().iterator();
@ -134,19 +251,12 @@ public class EditMetadataForm extends Composite{
.next(); .next();
// these are fixed key, variable value custom fields // these are fixed key, variable value custom fields
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus); CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, entry.getKey(), entry.getValue(), false);
customFieldEntriesList.add(toAdd);
// remove the first appendbox
toAdd.valueFieldPrepend.removeFromParent();
toAdd.keyFieldPrepend.setPrependText(entry.getKey() + ":");
((TextBox)toAdd.keyFieldPrepend.getWidget(1)).setText(entry.getValue());
customFieldEntries.add(toAdd);
customFields.add(toAdd); customFields.add(toAdd);
final ListItem item = new ListItem(); // add as tag
Label label = new Label(entry.getKey()); addTagElement(entry.getKey());
item.add(label);
} }
} }
@ -172,6 +282,7 @@ public class EditMetadataForm extends Composite{
// everything went ok // everything went ok
setAlertBlock("", AlertType.ERROR, false); setAlertBlock("", AlertType.ERROR, false);
createButton.setEnabled(true); createButton.setEnabled(true);
resetButton.setEnabled(true);
}else{ }else{
setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true); setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true);
@ -214,7 +325,7 @@ public class EditMetadataForm extends Composite{
@Override @Override
public void onRemoveEntry(DeleteCustomFieldEvent event) { public void onRemoveEntry(DeleteCustomFieldEvent event) {
customFieldEntries.remove(event.getRemovedEntry()); customFieldEntriesList.remove(event.getRemovedEntry());
customFields.remove(event.getRemovedEntry()); customFields.remove(event.getRemovedEntry());
} }
@ -225,8 +336,8 @@ public class EditMetadataForm extends Composite{
@UiHandler("addCustomFieldButton") @UiHandler("addCustomFieldButton")
void addCustomFieldEvent(ClickEvent e){ void addCustomFieldEvent(ClickEvent e){
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus); CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, "", "", true);
customFieldEntries.add(toAdd); customFieldEntriesList.add(toAdd);
customFields.add(toAdd); customFields.add(toAdd);
} }
@ -243,13 +354,15 @@ public class EditMetadataForm extends Composite{
String title = titleTextBox.getValue(); String title = titleTextBox.getValue();
String description = descriptionTextarea.getText(); String description = descriptionTextarea.getText();
String selectedLicense = licenseListbox.getSelectedItemText(); String selectedLicense = licenseListbox.getSelectedItemText();
String visibility = visibilityListbox.getValue(); String visibility = visibilityListbox.getSelectedItemText();
String searchable = searchableListbox.getValue(); String searchable = searchableListbox.getSelectedItemText();
long version = Long.valueOf(versionTextbox.getValue()); long version = Long.valueOf(versionTextbox.getValue());
String author = authorTextbox.getValue(); String author = authorTextbox.getValue();
String authorEmail = authorEmailTextbox.getValue(); String authorEmail = authorEmailTextbox.getValue();
String maintainer = maintainerTextbox.getValue(); String maintainer = maintainerTextbox.getValue();
String maintainerEmail = maintainerEmailTextbox.getValue(); String maintainerEmail = maintainerEmailTextbox.getValue();
String chosenOrganization = organizationsListbox.getSelectedItemText();
boolean addResources = addResourcesCheckBox.getValue();
// fill the bean // fill the bean
receivedBean.setAuthor(author); receivedBean.setAuthor(author);
@ -263,11 +376,13 @@ public class EditMetadataForm extends Composite{
receivedBean.setTitle(title); receivedBean.setTitle(title);
receivedBean.setSearchable(searchable.equals("Yes")); receivedBean.setSearchable(searchable.equals("Yes"));
receivedBean.setTags(tagsList); receivedBean.setTags(tagsList);
receivedBean.setSelectedOrganization(chosenOrganization);
receivedBean.setAddResources(addResources);
Map<String, String> customFieldsMap = new HashMap<String, String>(); Map<String, String> customFieldsMap = new HashMap<String, String>();
// prepare custom fields // prepare custom fields
for(CustomFieldEntry customEntry : customFieldEntries){ for(CustomFieldEntry customEntry : customFieldEntriesList){
String key = customEntry.getKey(); String key = customEntry.getKey();
String value = customEntry.getValue(); String value = customEntry.getValue();
@ -277,10 +392,64 @@ public class EditMetadataForm extends Composite{
receivedBean.setCustomFields(customFieldsMap); receivedBean.setCustomFields(customFieldsMap);
// TODO invoke remote service // invoke the create method
createButton.setEnabled(false);
resetButton.setEnabled(false);
onCreateAlertBlock.setText("Trying to create dataset, please wait");
onCreateAlertBlock.setVisible(true);
ckanServices.createCKanDataset(receivedBean, new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
if(result){
alertOnCreate("Dataset correctly created!", AlertType.SUCCESS);
}else{
alertOnCreate("Unable to create this dataset, please retry later", AlertType.ERROR);
} }
}
@Override
public void onFailure(Throwable caught) {
alertOnCreate("Unable to create this dataset, please retry later", AlertType.ERROR);
}
});
}
}
/**
* On create show alert box and enable buttons
* @param text
* @param type
*/
private void alertOnCreate(String text, AlertType type){
onCreateAlertBlock.setText(text);
onCreateAlertBlock.setType(type);
onCreateAlertBlock.setVisible(true);
createButton.setEnabled(true);
resetButton.setEnabled(true);
// hide after some seconds
Timer t = new Timer() {
@Override
public void run() {
onCreateAlertBlock.setVisible(false);
}
};
t.schedule(2000);
} }
/** /**
@ -288,7 +457,8 @@ public class EditMetadataForm extends Composite{
* @return true on success * @return true on success
*/ */
private boolean validateData() { private boolean validateData() {
// TODO Auto-generated method stub
return true; return true;
} }
@ -306,10 +476,10 @@ public class EditMetadataForm extends Composite{
removeTags(); removeTags();
// delete custom fields // delete custom fields
for (CustomFieldEntry customField : customFieldEntries) { for (CustomFieldEntry customField : customFieldEntriesList) {
customField.removeFromParent(); customField.removeFromParent();
} }
customFieldEntries.clear(); customFieldEntriesList.clear();
} }
@ -372,6 +542,32 @@ public class EditMetadataForm extends Composite{
} }
} }
/**
* Add the tag as an element
*/
private void addTagElement(final String tag){
if(tagsList.contains(tag))
return;
final ListItem displayItem = new ListItem();
displayItem.setStyleName("tag-style");
Span p = new Span(tag);
Span span = new Span("x");
span.setTitle("Remove this tag");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeListItem(displayItem, tag);
}
});
span.setStyleName("tag-style-x");
displayItem.add(p);
displayItem.add(span);
tagsPanel.add(displayItem);
tagsList.add(tag);
}
/** /**
* Remove a tag from the list * Remove a tag from the list

View File

@ -93,8 +93,9 @@
Tags: Tags:
</b:ControlLabel> </b:ControlLabel>
<b:Controls> <b:Controls>
<b:TextBox alternateSize="LARGE" placeholder="Enter one or more tag for the dataset" <b:TextBox alternateSize="LARGE"
b:id="tags" ui:field="tagsEnterTextBox" /> placeholder="Enter one or more tag for the dataset" b:id="tags"
ui:field="tagsEnterTextBox" />
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
@ -151,16 +152,14 @@
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<!-- <b:ControlGroup> --> <b:ControlGroup>
<!-- <b:ControlLabel for="source" title="Dataset source"> --> <b:ControlLabel for="organization" title="Organizations">Publish in:</b:ControlLabel>
<!-- Source: --> <b:Controls>
<!-- </b:ControlLabel> --> <b:ListBox b:id="organization" alternateSize="LARGE"
<!-- <b:Controls> --> title="Publish in this organization" ui:field="organizationsListbox">
<!-- <b:TextBox alternateSize="LARGE" --> </b:ListBox>
<!-- placeholder="http://example.com/dataset.json" b:id="source" --> </b:Controls>
<!-- title="Dataset source" ui:field="sourceTextbox" /> --> </b:ControlGroup>
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<b:ControlGroup> <b:ControlGroup>
<b:ControlLabel for="version" title="Dataset version"> <b:ControlLabel for="version" title="Dataset version">
@ -234,6 +233,25 @@
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<b:ControlGroup>
<b:Controls>
<b:CheckBox
title="Automatically add the folder content to the dataset as resource"
checked="true" ui:field="addResourcesCheckBox">
<b>Add folder content as resources</b>
</b:CheckBox>
<span style="float:right; width:256px; color: #aaaaaa;">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" />
Automatically add folder' files as resources of the dataset
</span>
</b:Controls>
</b:ControlGroup>
<!-- Alert block on create -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="onCreateAlertBlock" styleName="{style.block-alert-style}">
</b:AlertBlock>
<b:Button title="Create dataset" ui:field="createButton" <b:Button title="Create dataset" ui:field="createButton"
type="PRIMARY" block="true">Create</b:Button> type="PRIMARY" block="true">Create</b:Button>

View File

@ -1,33 +1,40 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.server; package org.gcube.portlets.widgets.ckandatapublisherwidget.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem; import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.dataaccess.ckanutillibrary.CKanUtilsFactory;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
import eu.trentorise.opendata.jackan.CheckedCkanClient; import eu.trentorise.opendata.jackan.CheckedCkanClient;
import eu.trentorise.opendata.jackan.CkanClient;
import eu.trentorise.opendata.jackan.model.CkanDataset;
import eu.trentorise.opendata.jackan.model.CkanLicense; import eu.trentorise.opendata.jackan.model.CkanLicense;
import eu.trentorise.opendata.jackan.model.CkanOrganization;
import eu.trentorise.opendata.jackan.model.CkanPair;
import eu.trentorise.opendata.jackan.model.CkanResource;
import eu.trentorise.opendata.jackan.model.CkanTag;
/** /**
* Server side of the data publisher. * Server side of the data publisher.
@ -37,64 +44,87 @@ import eu.trentorise.opendata.jackan.model.CkanLicense;
public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService{ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService{
// Logger // Logger
private static final Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
//dev user
public static final String defaultUserId = "test.user";
//dev vre
private static final String vreID = "/gcube/devsec/devVRE";
/** /**
* when packaging test will fail if the user is not set to test.user * Get the current scope (/gcube is returned if in development)
* @return .
*/
public String getDevelopmentUser() {
String user = defaultUserId;
// user = "costantino.perciante";
return user;
}
/**
* Retrieve the ckan portal url by querying the IS
* @return * @return
*/ */
private String getCKANUrlFromIS(){ private String getCurrentScope(){
// TODO if(isWithinPortal())
return "https://ckan-d-d4s.d4science.org/"; return ScopeProvider.instance.get();
else
return "/gcube";
} }
/** /**
* Retrieve the API_KEY of the current user * Return the ckan catalogue url for this scope.
* @return * @return
*/ */
private String getCKANApikeyFromUser(String username){ private String getCatalogueUrl(){
// TODO logger.info("Request for catalogue url");
return "803ada7f-2080-493f-8a99-3e593e880d94";
try{
String currentScope = getCurrentScope();
return "https://" + CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getCatalogueUrl();
}catch(Exception e){
logger.error("Failed to retrieve catalogue url information", e);
}
return null;
}
/**
* Retrieve the api key for this user
* @param owner
* @return
*/
private String getCKANApikeyFromUser(String owner) {
logger.info("Request for user api key");
try{
String currentScope = getCurrentScope();
return CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getApiKeyFromUser(owner);
}catch(Exception e){
logger.error("Failed to retrieve api key for user " + owner, e);
}
return null;
} }
/** /**
* the current ASLSession * Retrieve the list of organizations in which the user can publish
* @return the session * @param owner
* @return
*/ */
private ASLSession getASLSession() { private List<String> getUserOrganizationsList(String owner) {
String sessionID = this.getThreadLocalRequest().getSession().getId(); logger.info("Request for user " + owner + " organizations list");
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) { try{
String currentScope = getCurrentScope();
List<CkanOrganization> ckanOrgs = CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getOrganizationsByUser(owner);
logger.warn("USER IS NULL setting " + defaultUserId + " and Running OUTSIDE PORTAL"); logger.debug("Organizations are " + ckanOrgs);
user = getDevelopmentUser();
SessionManager.getInstance().getASLSession(sessionID, user).setScope(vreID);
List<String> orgsName = new ArrayList<String>();
for (CkanOrganization ckanOrganization : ckanOrgs) {
orgsName.add(ckanOrganization.getName());
logger.debug("Organization name is " + ckanOrganization.getName());
} }
return SessionManager.getInstance().getASLSession(sessionID, user); return orgsName;
}catch(Exception e){
logger.error("Failed to retrieve user's organizations", e);
}
return null;
} }
/** /**
@ -112,27 +142,51 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
} }
/**
* Find a license id given the license text.
* @param chosenLicense
* @return
*/
private String findLicenseIdByLicense(String chosenLicense) {
logger.info("Requested license id");
String ckanPortalUrl = getCatalogueUrl();
CkanClient client = new CkanClient(ckanPortalUrl);
//retrieve the list of available licenses
List<CkanLicense> licenses = client.getLicenseList();
for (CkanLicense ckanLicense : licenses) {
if(ckanLicense.getTitle().equals(chosenLicense))
return ckanLicense.getId();
}
return null;
}
@Override @Override
public LicensesBean getLicenses() { public LicensesBean getLicenses() {
logger.debug("Request for CKAN licenses"); logger.info("Request for CKAN licenses");
// get the url and the api key of the user // get the url and the api key of the user
String ckanPortalUrl = getCKANUrlFromIS(); String ckanPortalUrl = getCatalogueUrl();
String apiKey = getCKANApikeyFromUser(""); // TODO
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();
CheckedCkanClient checkedClient = new CheckedCkanClient(ckanPortalUrl, apiKey); CkanClient client = new CkanClient(ckanPortalUrl);
//retrieve the list of available licenses //retrieve the list of available licenses
List<CkanLicense> licenses = checkedClient.getLicenseList(); List<CkanLicense> licenses = client.getLicenseList();
for (CkanLicense ckanLicense : licenses) { for (CkanLicense ckanLicense : licenses) {
result.add(ckanLicense.getTitle()); result.add(ckanLicense.getTitle());
logger.debug("License is " + ckanLicense.getTitle()); logger.debug("License is " + ckanLicense.getTitle() + " and id " + ckanLicense.getId());
} }
// return the bean
return new LicensesBean(result); return new LicensesBean(result);
} }
@ -140,21 +194,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
public DatasetMetadataBean getDatasetBean(String folderId, String owner){ public DatasetMetadataBean getDatasetBean(String folderId, String owner){
DatasetMetadataBean bean = null; DatasetMetadataBean bean = null;
ScopeProvider.instance.set("/gcube/devsec/devVRE");
logger.info("Bean request for " + folderId + " and " + owner);
if(isWithinPortal()){ if(isWithinPortal()){
try{ try{
logger.debug("Request dataset metadata bean for folder with id " + folderId logger.debug("Request dataset metadata bean for folder with id " + folderId
+ " whose owner is " + owner); + " whose owner is " + owner);
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(owner).getWorkspace();
WorkspaceItem retrievedItem = ws.getItem(folderId);
// get usermanager (liferay) // get usermanager (liferay)
UserManager liferUserManager = new LiferayUserManager(); UserManager liferUserManager = new LiferayUserManager();
GCubeUser userOwner = liferUserManager.getUserByUsername(owner); GCubeUser userOwner = liferUserManager.getUserByUsername(owner);
@ -164,42 +211,89 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean = new DatasetMetadataBean(); bean = new DatasetMetadataBean();
bean.setId(folderId); bean.setId(folderId);
bean.setDescription(retrievedItem.getDescription()); bean.setOwnerFolderInWorkspace(owner);
bean.setVersion(1); bean.setVersion(1);
bean.setTitle(retrievedItem.getName());
bean.setAuthor(userOwner.getFullname()); bean.setAuthor(userOwner.getFullname());
bean.setAuthorEmail(userOwner.getEmail()); bean.setAuthorEmail(userOwner.getEmail());
bean.setMaintainer(userOwner.getFullname()); bean.setMaintainer(userOwner.getFullname());
bean.setMaintainerEmail(userOwner.getEmail()); bean.setMaintainerEmail(userOwner.getEmail());
bean.setSource(retrievedItem.getPublicLink(true)); bean.setOrganizationList(getUserOrganizationsList(owner));
if(folderId != null && !folderId.isEmpty()){
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(owner).getWorkspace();
WorkspaceItem retrievedItem = ws.getItem(folderId);
// set some info
bean.setTitle(retrievedItem.getName());
bean.setDescription(retrievedItem.getDescription());
// retrieve gcube items of the folder // retrieve gcube items of the folder
Map<String, String> folderItems = getGcubeItemProperties(retrievedItem); Map<String, String> folderItems = getGcubeItemProperties(retrievedItem);
bean.setCustomFields(folderItems); bean.setCustomFields(folderItems);
// check the resources within the folder (skip subdirectories)
List<String> childrenIds = new ArrayList<String>();
for (WorkspaceItem file : retrievedItem.getChildren()) {
if(!file.isFolder()) // ok, it's a file
childrenIds.add(file.getId());
}
bean.setResourcesIds(childrenIds);
}
}catch(Exception e){ }catch(Exception e){
logger.error("Error while retrieving folder information", e); logger.error("Error while retrieving folder information", e);
} }
}else{ }else{
try{
bean = new DatasetMetadataBean(); bean = new DatasetMetadataBean();
bean.setId(folderId); bean.setId(folderId);
bean.setDescription("This is a fantastic description"); bean.setDescription("This is a fantastic description");
bean.setVersion(1); bean.setVersion(1);
bean.setTitle("Dataset name"); bean.setTitle("dataset-" + Calendar.getInstance().getTimeInMillis());
bean.setAuthor("Costantino Perciante"); bean.setAuthor("Costantino Perciante");
bean.setAuthorEmail("costantino.perciante@isti.cnr.it"); bean.setAuthorEmail("costantino.perciante@isti.cnr.it");
bean.setMaintainer("Costantino Perciante"); bean.setMaintainer("Costantino Perciante");
bean.setMaintainerEmail("costantino.perciante@isti.cnr.it"); bean.setMaintainerEmail("costantino.perciante@isti.cnr.it");
bean.setSource("https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace"); bean.setOrganizationList(getUserOrganizationsList(owner));
bean.setOwnerFolderInWorkspace(owner);
if(folderId != null && !folderId.isEmpty()){
ScopeProvider.instance.set("/gcube");
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(owner).getWorkspace();
WorkspaceItem retrievedItem = ws.getItem(folderId);
// retrieve gcube items of the folder // retrieve gcube items of the folder
Map<String, String> folderItems = new HashMap<String, String>(); Map<String, String> folderItems = getGcubeItemProperties(retrievedItem);
folderItems.put("tag1", "asds");
folderItems.put("tag2", "asdsdaxcxcs");
folderItems.put("tag3", "asasdads");
bean.setCustomFields(folderItems); bean.setCustomFields(folderItems);
// check the resources within the folder (skip subdirectories)
List<String> childrenIds = new ArrayList<String>();
for (WorkspaceItem file : retrievedItem.getChildren()) {
if(!file.isFolder()) // ok, it's a file
childrenIds.add(file.getId());
}
bean.setResourcesIds(childrenIds);
}
}catch(Exception e){
logger.error("Error while building bean into dev mode", e);
}
} }
return bean; return bean;
@ -231,4 +325,155 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return null; return null;
} }
@Override
public boolean createCKanDataset(DatasetMetadataBean toCreate) {
// retrieve ckan's catalog url
String ckanPortalUrl = getCatalogueUrl();
// retrieve the owner of the original folder into the workspace
String owner = toCreate.getOwnerFolderInWorkspace();
// retrieve the api key for this user
String apiKey = getCKANApikeyFromUser(owner);
logger.info("Trying to create the dataset described by this bean " + toCreate + " into CKAN catalog at url " + ckanPortalUrl);
// Checked client
CheckedCkanClient client = new CheckedCkanClient(ckanPortalUrl, apiKey);
// create the base dataset and fill it
CkanDataset dataset = new CkanDataset();
// set dataset info (same id as the folder)
dataset.setId(toCreate.getId());
// get the name from the title
dataset.setName(nameFromTitle(toCreate.getTitle()));
dataset.setTitle(toCreate.getTitle());
CkanOrganization orgTest = client.getOrganization(toCreate.getSelectedOrganization());
dataset.setOwnerOrg(orgTest.getId());
dataset.setAuthor(toCreate.getAuthor());
dataset.setAuthorEmail(toCreate.getAuthorEmail());
dataset.setMaintainer(toCreate.getMaintainer());
dataset.setMaintainerEmail(toCreate.getMaintainerEmail());
dataset.setVersion(String.valueOf(toCreate.getVersion()));
dataset.setNotes(toCreate.getDescription());
logger.info("Searchable is " + toCreate.isSearchable() + " and visible is " + toCreate.getVisibility());
dataset.setPriv(false);
dataset.setOpen(toCreate.getVisibility());
// iterate over the licenses to find the id of the chosen one
String chosenLicense = toCreate.getLicense();
String licenseId = findLicenseIdByLicense(chosenLicense);
dataset.setLicenseId(licenseId);
// set the tags, if any
if(toCreate.getTags() != null && !toCreate.getTags().isEmpty()){
// convert to ckan tags
List<CkanTag> ckanTags = new ArrayList<CkanTag>(toCreate.getTags().size());
for (String stringTag : toCreate.getTags()) {
ckanTags.add(new CkanTag(stringTag));
}
dataset.setTags(ckanTags);
}
// set the custom fields, if any
if(toCreate.getCustomFields() != null && !toCreate.getCustomFields().isEmpty()){
// iterate and create
Iterator<Entry<String, String>> iterator = toCreate.getCustomFields().entrySet().iterator();
List<CkanPair> extras = new ArrayList<CkanPair>(toCreate.getCustomFields().entrySet().size());
while (iterator.hasNext()) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
extras.add(new CkanPair(entry.getKey(), entry.getValue()));
}
dataset.setExtras(extras);
}
// check if we need to add the resources
if(toCreate.isAddResources()){
logger.debug("We need to add resources to the dataset");
try{
ScopeProvider.instance.set("/gcube");
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(toCreate.getOwnerFolderInWorkspace()).getWorkspace();
List<CkanResource> resources = new ArrayList<CkanResource>();
for(String resourceId: toCreate.getResourcesIds()){
FolderItem item = (FolderItem)ws.getItem(resourceId);
CkanResource newResource = new CkanResource();
newResource.setDescription(item.getDescription());
newResource.setId(item.getId());
newResource.setUrl(item.getPublicLink(false));
newResource.setName(item.getName());
newResource.setMimetype(item.getMimeType());
resources.add(newResource);
}
// add to the dataset
dataset.setResources(resources);
}catch(Exception e){
logger.error("Unable to add those resources to the dataset", e);
}
}
// try to create
CkanDataset res = null;
try{
res = client.createDataset(dataset);
}catch(Exception e){
// try to update
logger.error("Error while creating the dataset, probably it already exists. Trying to update it..", e);
res = client.updateDataset(dataset);
}
if(res != null)
logger.debug("Dataset created/updated " + res.getId());
else{
logger.error("Dataset described by " + toCreate + " not created!");
return false;
}
return true;
}
/**
* Generate the catalogue's dataset name from its title
* @param title
* @return
*/
private String nameFromTitle(String title) {
String convertedName = title.replaceAll(" ", "-");
convertedName = convertedName.toLowerCase();
if(convertedName.endsWith("-"))
convertedName = convertedName.substring(0, convertedName.length() - 2);
return convertedName;
}
} }

View File

@ -18,6 +18,8 @@ import java.util.Map;
* <li> version -> during creation it is going to be 1.0 * <li> version -> during creation it is going to be 1.0
* <li> author, maintainer -> folder's owner * <li> author, maintainer -> folder's owner
* <li> custom fields -> gcube items <key, value> couple * <li> custom fields -> gcube items <key, value> couple
* <li> organizationsList -> list of organizations to which the user belong (and in which
* he wants to publish)
* </ul> * </ul>
* @author Costantino Perciante at ISTI-CNR * @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it) * (costantino.perciante@isti.cnr.it)
@ -35,10 +37,15 @@ public class DatasetMetadataBean implements Serializable {
private boolean searchable; // true or false private boolean searchable; // true or false
private String source; // url of the folder in the workspace private String source; // url of the folder in the workspace
private long version; // version 1, 2 ... private long version; // version 1, 2 ...
private String author; // folder's owner private String author; // folder's owner fullname
private String authorEmail; // folder's email owner private String authorEmail; // folder's email owner
private String maintainer; private String maintainer;
private String maintainerEmail; private String maintainerEmail;
private String ownerFolderInWorkspace; // owner of the folder into the workspace
private List<String> organizationList; // list of organization in which the user is present and could create the dataset
private String selectedOrganization;
private List<String> resourcesIds; // in case of workspace, this is the list of children's ids
private boolean addResources; // if true, add these files as resources to the dataset
public DatasetMetadataBean(){ public DatasetMetadataBean(){
super(); super();
@ -48,6 +55,7 @@ public class DatasetMetadataBean implements Serializable {
* @param id * @param id
* @param title * @param title
* @param description * @param description
* @param customFields
* @param tags * @param tags
* @param license * @param license
* @param visibility * @param visibility
@ -58,16 +66,23 @@ public class DatasetMetadataBean implements Serializable {
* @param authorEmail * @param authorEmail
* @param maintainer * @param maintainer
* @param maintainerEmail * @param maintainerEmail
* @param ownerFolderInWorkspace
* @param organizationList
* @param selectedOrganization
*/ */
public DatasetMetadataBean(String id, String title, String description, public DatasetMetadataBean(String id, String title, String description,
Map<String, String> customFields, String license, boolean visibility, Map<String, String> customFields, List<String> tags,
boolean searchable, String source, long version, String author, String license, boolean visibility, boolean searchable,
String authorEmail, String maintainer, String maintainerEmail) { String source, long version, String author, String authorEmail,
String maintainer, String maintainerEmail,
String ownerFolderInWorkspace, List<String> organizationList,
String selectedOrganization) {
super(); super();
this.id = id; this.id = id;
this.title = title; this.title = title;
this.description = description; this.description = description;
this.customFields = customFields; this.customFields = customFields;
this.tags = tags;
this.license = license; this.license = license;
this.visibility = visibility; this.visibility = visibility;
this.searchable = searchable; this.searchable = searchable;
@ -77,6 +92,9 @@ public class DatasetMetadataBean implements Serializable {
this.authorEmail = authorEmail; this.authorEmail = authorEmail;
this.maintainer = maintainer; this.maintainer = maintainer;
this.maintainerEmail = maintainerEmail; this.maintainerEmail = maintainerEmail;
this.ownerFolderInWorkspace = ownerFolderInWorkspace;
this.organizationList = organizationList;
this.selectedOrganization = selectedOrganization;
} }
public String getId() { public String getId() {
@ -87,6 +105,14 @@ public class DatasetMetadataBean implements Serializable {
this.id = id; this.id = id;
} }
public void setOwnerFolderInWorkspace(String ownerFolderInWorkspace) {
this.ownerFolderInWorkspace = ownerFolderInWorkspace;
}
public String getOwnerFolderInWorkspace(){
return ownerFolderInWorkspace;
}
public String getTitle() { public String getTitle() {
return title; return title;
} }
@ -191,6 +217,38 @@ public class DatasetMetadataBean implements Serializable {
this.maintainerEmail = maintainerEmail; this.maintainerEmail = maintainerEmail;
} }
public List<String> getOrganizationList() {
return organizationList;
}
public void setOrganizationList(List<String> organizationList) {
this.organizationList = organizationList;
}
public String getSelectedOrganization() {
return selectedOrganization;
}
public void setSelectedOrganization(String selectedOrganization) {
this.selectedOrganization = selectedOrganization;
}
public List<String> getResourcesIds() {
return resourcesIds;
}
public void setResourcesIds(List<String> resourcesIds) {
this.resourcesIds = resourcesIds;
}
public boolean isAddResources() {
return addResources;
}
public void setAddResources(boolean addResources) {
this.addResources = addResources;
}
@Override @Override
public String toString() { public String toString() {
return "DatasetMetadataBean [id=" + id + ", title=" + title return "DatasetMetadataBean [id=" + id + ", title=" + title
@ -199,6 +257,11 @@ public class DatasetMetadataBean implements Serializable {
+ ", visibility=" + visibility + ", searchable=" + searchable + ", visibility=" + visibility + ", searchable=" + searchable
+ ", source=" + source + ", version=" + version + ", author=" + ", source=" + source + ", version=" + version + ", author="
+ author + ", authorEmail=" + authorEmail + ", maintainer=" + author + ", authorEmail=" + authorEmail + ", maintainer="
+ maintainer + ", maintainerEmail=" + maintainerEmail + "]"; + maintainer + ", maintainerEmail=" + maintainerEmail
+ ", ownerFolderInWorkspace=" + ownerFolderInWorkspace
+ ", organizationList=" + organizationList
+ ", selectedOrganization=" + selectedOrganization
+ ", resourcesIds=" + resourcesIds + ", addResources="
+ addResources + "]";
} }
} }

View File

@ -10,7 +10,6 @@
<set-property name="bootstrap.responsiveDesign" value="true" /> <set-property name="bootstrap.responsiveDesign" value="true" />
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' /> <inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name="org.gcube.portlets.user.workspace.WorkspaceTree" />
<!-- Specify the app entry point class. --> <!-- Specify the app entry point class. -->
<entry-point <entry-point

View File

@ -1,67 +1,52 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client; package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException; import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.scope.api.ScopeProvider;
import eu.trentorise.opendata.jackan.CheckedCkanClient; import org.junit.Test;
import eu.trentorise.opendata.jackan.CkanClient;
import eu.trentorise.opendata.jackan.model.CkanUser;
public class Tests { public class Tests {
//@Test //@Test
public static void test() throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException { public void test() throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException, ItemNotFoundException{
// String username ="costantino.perciante"; ScopeProvider.instance.set("/gcube");
// ScopeProvider.instance.set("/gcube/devsec/devVRE");
//
// Workspace ws = HomeLibrary
// .getHomeManagerFactory()
// .getHomeManager()
// .getHome(username).getWorkspace();
//
// System.out.println("Created workspace reference");
//
// WorkspaceFolder rootFolder = ws.getRoot();
// System.out.println("Root folder has id " + rootFolder.getId());
//
// List<WorkspaceItem> children = rootFolder.getChildren();
//
// for (WorkspaceItem workspaceItem : children) {
// System.out.println("Children with name " + workspaceItem.getName() + " and id " + workspaceItem.getId());
// }
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome("costantino.perciante").getWorkspace();
// get the url and the api key of the user List<WorkspaceItem> childrens = ws.getRoot().getChildren();
String ckanPortalUrl = "https://ckan-d-d4s.d4science.org/";
String apiKey = "803ada7f-2080-493f-8a99-3e593e880d94";
List<String> result = new ArrayList<String>(); for (WorkspaceItem workspaceItem : childrens) {
if(workspaceItem.getName().equals("CkanTest1137")){
CheckedCkanClient checkedClient = new CheckedCkanClient(ckanPortalUrl, apiKey); System.out.println("Dir has id " + workspaceItem.getId());
CkanClient client = new CkanClient(ckanPortalUrl);
List<CkanUser> list = client.getUserList(); List<? extends WorkspaceItem> files = workspaceItem.getChildren();
for (CkanUser ckanUser : list) { for (WorkspaceItem file : files) {
System.out.println("User -> " + ckanUser.getId() + " with fullname " + ckanUser.getFullname() + " and name " + ckanUser.getName() + " password " + ckanUser.getPassword()); if(!file.isFolder()) // ok, it's a file
System.out.println("item id is " + file.getId());
} }
} }
}
public static void main(String[] args) { // CheckedCkanClient client = new CheckedCkanClient("http://ckan-d-d4s.d4science.org", "803ada7f-2080-493f-8a99-3e593e880d94");
// try { //
// test(); // CkanDataset dataset = client.getDataset("34d9cc5a-9ddb-40a1-9747-8490acd318d3");
// } catch (WorkspaceFolderNotFoundException | InternalErrorException // //client.deleteDataset("34d9cc5a-9ddb-40a1-9747-8490acd318d3");
// | HomeNotFoundException | UserNotFoundException e) { // System.out.println("Dataset exists " + dataset.getName());
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
} }
} }