From c211fb4a22b5416799900095f186ac259e450443 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 26 Aug 2020 11:11:42 +0200 Subject: [PATCH] merged with branch #19528 --- .settings/org.eclipse.jdt.core.prefs | 2 + CHANGELOG.md | 16 ++++ pom.xml | 2 +- .../client/CkanToZendoPublisherWidget.java | 19 +++++ .../ui/publishfile/PublishFilesFormView.java | 1 - .../public/CkanToZenodoPublisher.css | 1 + .../CkanToZenodoPublisherServiceImpl.java | 67 ++++++++------- .../shared/ItemTranslateError.java | 76 +++++++++++++++++ .../shared/wrapped/ZenodoItem.java | 84 +++++++++---------- 9 files changed, 189 insertions(+), 79 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/ItemTranslateError.java diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index a5c7673..43c8195 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6621d64 --- /dev/null +++ b/CHANGELOG.md @@ -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 diff --git a/pom.xml b/pom.xml index 7bfebb0..2031a27 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.gcube.portlets.widgets ckan2zenodo-publisher-widget jar - 0.1.0 + 1.0.0-SNAPSHOT gCube Ckan2Zenodo Publisher widget allows to publish D4Science catalogue's items on Zenodo diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/CkanToZendoPublisherWidget.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/CkanToZendoPublisherWidget.java index d6adf56..2747342 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/CkanToZendoPublisherWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/CkanToZendoPublisherWidget.java @@ -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); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/publishfile/PublishFilesFormView.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/publishfile/PublishFilesFormView.java index dd8ff4c..86f5201 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/publishfile/PublishFilesFormView.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/publishfile/PublishFilesFormView.java @@ -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; diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/public/CkanToZenodoPublisher.css b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/public/CkanToZenodoPublisher.css index e083da3..82ab41c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/public/CkanToZenodoPublisher.css +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/public/CkanToZenodoPublisher.css @@ -2,6 +2,7 @@ .ckan2zenodo-modal-style { width: 1200px !important; margin-left: -600px !important; + position: absolute; } .ckan2zenodo-modal-style input, textarea { diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/CkanToZenodoPublisherServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/CkanToZenodoPublisherServiceImpl.java index 2abf129..f0c20af 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/CkanToZenodoPublisherServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/CkanToZenodoPublisherServiceImpl.java @@ -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 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 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 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 diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/ItemTranslateError.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/ItemTranslateError.java new file mode 100644 index 0000000..6aeaf3c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/ItemTranslateError.java @@ -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 + "]"; + } + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoItem.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoItem.java index 1c31c30..712efea 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoItem.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoItem.java @@ -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 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 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 files) { - + this.files = new ArrayList(); - 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 + "]"; + } + + }