Compare commits

...

3 Commits

9 changed files with 189 additions and 79 deletions

View File

@ -3,7 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7

16
CHANGELOG.md Normal file
View File

@ -0,0 +1,16 @@
# Changelog
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.0.0-SNAPSHOT] - 2020-07-07
#### New Features
[#19528] Ckan GUI to always allow zenodo publishing
## [v0.0.1] - 2019-12-06
[#18236] First Release

View File

@ -15,7 +15,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan2zenodo-publisher-widget</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<version>1.0.0-SNAPSHOT</version>
<description>
gCube Ckan2Zenodo Publisher widget allows to publish D4Science catalogue's items on Zenodo

View File

@ -101,6 +101,25 @@ public class CkanToZendoPublisherWidget {
modal.remove(loader);
manager = new Ckan2ZenodoViewManager();
basicTabPanel = manager.viewForPublishing(result);
//In case of error on translating it shows an alert
GWT.log("Translate Error is: "+result.getTranslateError());
if(result.getTranslateError()!=null) {
Alert alert = new Alert(result.getTranslateError().getError());
alert.setClose(true);
switch (result.getTranslateError().getErrorType()) {
case INFO:
alert.setType(AlertType.INFO);
break;
case WARN:
alert.setType(AlertType.WARNING);
break;
case ERROR:
default:
alert.setType(AlertType.ERROR);
break;
}
modal.add(alert);
}
modal.add(basicTabPanel);
buttonPublish.setEnabled(true);
}

View File

@ -10,7 +10,6 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

View File

@ -2,6 +2,7 @@
.ckan2zenodo-modal-style {
width: 1200px !important;
margin-left: -600px !important;
position: absolute;
}
.ckan2zenodo-modal-style input, textarea {

View File

@ -13,7 +13,6 @@ import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
import org.gcube.data.publishing.ckan2zenodo.model.faults.GcatException;
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
import org.gcube.data.publishing.ckan2zenodo.model.faults.TransformationException;
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata;
@ -22,6 +21,8 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublis
import org.gcube.portlets.widgets.ckan2zenodopublisher.server.configuration.ZenodoFieldsDescriptionsReader;
import org.gcube.portlets.widgets.ckan2zenodopublisher.server.converter.ItemToZenodoConverter;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.CatalogueItem;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.ItemTranslateError;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.ItemTranslateError.ERROR_TYPE;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.ZenodoError;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoFile;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
@ -59,7 +60,18 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
}
ZenodoDeposition zenodoDepositionPreview=loadItemPreviewFromService(zenodoItem.getName());
Ckan2Zenodo client = new Ckan2ZenodoImpl();
// Get the item representation
CkanItemDescriptor itemDescr = client.read(zenodoItem.getName());
// Get a preview of the deposition to be published
ZenodoDeposition zenodoDepositionPreview = null;
try {
zenodoDepositionPreview = client.translate(itemDescr);
} catch (ConfigurationException e) {
LOG.info("Using forceTranslation for: " + itemDescr.getItemUrl());
zenodoDepositionPreview = client.forceTranslation(itemDescr);
}
//(EVENTUALLY) UPDATING BASIC INFO CHANGED BY FORM ON CLIENT-SIDE
//Basic info
zenodoDepositionPreview.setTitle(zenodoItem.getTitle());
@ -91,7 +103,7 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
//Actually publish to zenodo :
// Step 1 : metadata
Ckan2Zenodo client= new Ckan2ZenodoImpl();
client= new Ckan2ZenodoImpl();
LOG.debug("Calling updatedMetadta for: "+zenodoDepositionPreview);
zenodoDepositionPreview = client.updatedMetadata(zenodoDepositionPreview);
@ -150,15 +162,31 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
}
//Get a preview of the deposition to be published
ZenodoDeposition zdPreview=loadItemPreviewFromService(item.getItemId());
Ckan2Zenodo client = new Ckan2ZenodoImpl();
// Get the item representation
CkanItemDescriptor itemDescr = client.read(item.getItemId());
// Get a preview of the deposition to be published
ZenodoDeposition zdDeposition = null;
ItemTranslateError itemTrError = null;
try {
zdDeposition = client.translate(itemDescr);
} catch (ConfigurationException e) {
LOG.info(ConfigurationException.class.getSimpleName() + " thrown, trying to use forceTranslation for: "
+ itemDescr.getName());
itemTrError = new ItemTranslateError(e.getMessage(), ERROR_TYPE.INFO);
zdDeposition = client.forceTranslation(itemDescr);
}
//Loading Filtered resources according to VRE policies
List<CkanResource> filteredResources = loadFilterResources(item.getItemId());
LOG.debug("Loaded filtered resources: "+filteredResources);
//Converting ZenodoDeposition to ZenodoItem
ZenodoItem zenodoItem = ItemToZenodoConverter.toZenodoItem(zdPreview);
ZenodoItem zenodoItem = ItemToZenodoConverter.toZenodoItem(zdDeposition);
//Adding ItemTranslateError eventually occurred by calling client.translate
zenodoItem.setTranslateError(itemTrError);
//Adding the filtered resources
List<ZenodoFile> resources = ItemToZenodoConverter.toZenodoFiles(filteredResources, false);
@ -214,29 +242,6 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
}
/**
* Load item preview from service.
*
* @param itemName the item name
* @return the zenodo deposition
* @throws GcatException the gcat exception
* @throws InvalidItemException the invalid item exception
* @throws ZenodoException the zenodo exception
* @throws ConfigurationException the configuration exception
* @throws TransformationException the transformation exception
*/
private ZenodoDeposition loadItemPreviewFromService(String itemName) throws GcatException, InvalidItemException, ZenodoException, ConfigurationException, TransformationException {
Ckan2Zenodo client= new Ckan2ZenodoImpl();
// Get the item representation
CkanItemDescriptor itemDescr=client.read(itemName);
//Get a preview of the deposition to be published
return client.translate(itemDescr);
}
/**
* Load filter resources.
*
@ -248,7 +253,7 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
*/
private List<CkanResource> loadFilterResources(String itemName) throws GcatException, ConfigurationException, TransformationException {
Ckan2Zenodo client= new Ckan2ZenodoImpl();
Ckan2Zenodo client = new Ckan2ZenodoImpl();
// Get the item representation
CkanItemDescriptor itemDescr=client.read(itemName);
//Filter resources according to VRE policies

View File

@ -0,0 +1,76 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.shared;
import java.io.Serializable;
/**
* The Class ItemTranslateError.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Jul 6, 2020
*/
public class ItemTranslateError implements Serializable {
/**
*
*/
private static final long serialVersionUID = 6350511079411561892L;
private String error;
private ERROR_TYPE errorType;
/**
* The Enum ERROR_TYPE.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Jul 6, 2020
*/
public static enum ERROR_TYPE {
INFO, WARN, ERROR
}
/**
* Instantiates a new zenodo translate error.
*/
ItemTranslateError() {
}
/**
* Instantiates a new zenodo translate error.
*
* @param error the error
* @param errorType the error type
*/
public ItemTranslateError(String error, ERROR_TYPE errorType) {
super();
this.error = error;
this.errorType = errorType;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public ERROR_TYPE getErrorType() {
if(error==null)
return ERROR_TYPE.ERROR;
return errorType;
}
public void setErrorType(ERROR_TYPE errorType) {
this.errorType = errorType;
}
@Override
public String toString() {
return "ItemTranslateError [error=" + error + ", errorType=" + errorType + "]";
}
}

View File

@ -5,20 +5,21 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.ItemTranslateError;
/**
* The Class ZenodoItem.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 9, 2019
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Jul 6, 2020
*/
public class ZenodoItem implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3623554371253293861L;
private static final long serialVersionUID = 4007154127458109015L;
private Date created;
private String doi;
private List<ZenodoFile> files;
@ -31,7 +32,9 @@ public class ZenodoItem implements Serializable {
private String state;
private Boolean submitted;
private String title;
private String name; //this is the dataset name
private String name; // this is the dataset name
private ItemTranslateError translateError;
/**
* Instantiates a new zenodo item.
@ -63,24 +66,23 @@ public class ZenodoItem implements Serializable {
* @param files the files
*/
public void addFiles(List<ZenodoFile> files) {
if(this.files==null) {
if (this.files == null) {
this.files = files;
}else {
} else {
this.files.addAll(files);
}
}
/**
* Sets the files.
*
* @param files the new files
*/
public void setFiles(List<ZenodoFile> files) {
this.files = new ArrayList<ZenodoFile>();
if(files!=null) {
if (files != null) {
this.files.addAll(files);
}
}
@ -292,42 +294,32 @@ public class ZenodoItem implements Serializable {
this.name = name;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
/**
* Gets the translate error.
*
* @return the translate error
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ZenodoItem [created=");
builder.append(created);
builder.append(", doi=");
builder.append(doi);
builder.append(", files=");
builder.append(files);
builder.append(", id=");
builder.append(id);
builder.append(", metadata=");
builder.append(metadata);
builder.append(", modified=");
builder.append(modified);
builder.append(", owner=");
builder.append(owner);
builder.append(", record_id=");
builder.append(record_id);
builder.append(", record_url=");
builder.append(record_url);
builder.append(", state=");
builder.append(state);
builder.append(", submitted=");
builder.append(submitted);
builder.append(", title=");
builder.append(title);
builder.append(", name=");
builder.append(name);
builder.append("]");
return builder.toString();
public ItemTranslateError getTranslateError() {
return translateError;
}
/**
* Sets the translate error.
*
* @param translateError the new translate error
*/
public void setTranslateError(ItemTranslateError translateError) {
this.translateError = translateError;
}
@Override
public String toString() {
return "ZenodoItem [created=" + created + ", doi=" + doi + ", files=" + files + ", id=" + id + ", metadata="
+ metadata + ", modified=" + modified + ", owner=" + owner + ", record_id=" + record_id
+ ", record_url=" + record_url + ", state=" + state + ", submitted=" + submitted + ", title=" + title
+ ", name=" + name + ", translateError=" + translateError + "]";
}
}