Compare commits

..

3 Commits

27 changed files with 689 additions and 1019 deletions

View File

@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=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.8
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -4,43 +4,7 @@
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.1.4] - 2023-12-21
- Fixing `publication_date` issue [#26166]
## [v1.1.3] - 2023-07-25
- Fixing `null` issue, recompiling this component [#25275]
## [v1.1.2] - 2022-10-27
**Enhancements**
- [#24038] Moved to GWT 2.9.0
- Moved to maven-portal-bom 3.6.4
## [v1.1.0] - 2021-10-05
**New Features**
[#19988] Integrated with `checkEnvironment` reporting the status of "Upload to Zenodo" facility
Moved to `maven-portal-bom` 3.6.3
## [v1.0.2] - 2021-04-26
**Bug fixes**
[#21263] manage empty mapping for creators/contributors
**Enhancements**
[#21153] ported to maven-portal-bom 3.6.1
Improved modal height
## [v1.0.1] - 2021-03-09
[#20935] just to include new range 1.x, 2.0 of ckan2zenodo-library
## [v1.0.0] - 2020-08-26
## [v1.0.0-SNAPSHOT] - 2020-07-07
#### New Features

35
pom.xml
View File

@ -7,14 +7,15 @@
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.2.0</version>
<version>1.1.0</version>
<relativePath />
</parent>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan2zenodo-publisher-widget</artifactId>
<packaging>jar</packaging>
<version>1.1.4</version>
<version>1.0.0-SNAPSHOT</version>
<description>
gCube Ckan2Zenodo Publisher widget allows to publish D4Science catalogue's items on Zenodo
@ -30,10 +31,10 @@
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.10.0</gwtVersion>
<gwtVersion>2.7.0</gwtVersion>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@ -43,7 +44,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.4</version>
<version>3.6.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -57,18 +58,6 @@
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>
@ -82,8 +71,7 @@
<dependency>
<groupId>org.gcube.data.publishing</groupId>
<artifactId>ckan2zenodo-library</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0)</version>
<scope>compile</scope>
<version>[0.0.1, 1.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
@ -130,15 +118,6 @@
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- REQUIRED FOR JDK_11 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -12,7 +12,6 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.client.view.FormValidator
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.view.LoaderIcon;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.CatalogueItem;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.ZenodoError;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.DOI_dv;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
import com.github.gwtbootstrap.client.ui.Alert;
@ -31,8 +30,6 @@ import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
@ -100,7 +97,6 @@ public class CkanToZendoPublisherWidget {
@Override
public void onSuccess(ZenodoItem result) {
GWT.log("Zenodo item returned is: "+result);
loader.setVisible(false);
modal.remove(loader);
manager = new Ckan2ZenodoViewManager();
@ -158,7 +154,7 @@ public class CkanToZendoPublisherWidget {
if(!isValid)
allFormsAreValid = false;
}
if(allFormsAreValid) {
buttonPublish.setEnabled(false);
basicTabPanel.getElement().getStyle().setOpacity(0.5);
@ -167,7 +163,7 @@ public class CkanToZendoPublisherWidget {
//Submit publish on zenodo.
ZenodoItem zenodoItem = manager.getZenodoItemFromFieldsForm();
GWT.log("Publishing file: "+zenodoItem.getFiles());
ckanToZenodoService.publishOnZenodo(zenodoItem, new AsyncCallback<DOI_dv>() {
ckanToZenodoService.publishOnZenodo(zenodoItem, new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
@ -183,7 +179,7 @@ public class CkanToZendoPublisherWidget {
}
@Override
public void onSuccess(DOI_dv doi_dv) {
public void onSuccess(String doi) {
buttonPublish.setEnabled(false);
basicTabPanel.getElement().getStyle().setOpacity(1.0);
try {
@ -192,28 +188,16 @@ public class CkanToZendoPublisherWidget {
// TODO: handle exception
}
String msg = "The item has been uploaded to Zenodo correctly";
if(doi!=null)
msg+=" "+doi;
Alert infoLabel = new Alert();
infoLabel.setClose(false);
infoLabel.setType(AlertType.INFO);
infoLabel.setText(msg);
Modal modal = new Modal(true, true);
modal.setCloseVisible(true);
modal.setTitle("Item uploaded to Zenodo!");
modal.add(infoLabel);
if(doi_dv!=null) {
FlowPanel dF = new FlowPanel();
dF.add(new HTML("DOI: "+doi_dv.getDoi()));
FlowPanel dFU = new FlowPanel();
dFU.add(new HTML("DOI URL: <a href='"+doi_dv.getDoi_url()+"' target='_blank'>"+doi_dv.getDoi_url()+"</a>"));
modal.add(dF);
modal.add(dFU);
}
modal.show();
//showResults(Arrays.asList(infoLabel.asWidget()));
showResults(Arrays.asList(infoLabel.asWidget()));
}
});
@ -256,18 +240,14 @@ public class CkanToZendoPublisherWidget {
}
JSONValue theMessage = theErrorJSON.get("message");
String theErrors = null;
try {
JSONValue theError = theErrorJSON.get("errors");
theErrors = theError.toString();
}catch (Exception e) {
//silent
}
String toReport = "Message reported from Zenodo: " + theMessage.toString();
if(theErrors!=null)
toReport+= " Errors: "+theErrors;
return toReport;
return "Error reported from Zenodo: " + theMessage.toString();
// //GWT.log("array: "+array.toString());
// JSONObject theErrorValue = (JSONObject) array.get(0);
// //GWT.log("theErrorValue: "+theErrorValue.toString());
// JSONValue theMessage = theErrorValue.get("message");
// //GWT.log("message: "+message.toString());
// return "Error reported from Zenodo: " + theMessage.toString();
}
}catch (Exception e) {
return message;

View File

@ -3,7 +3,6 @@ package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
import java.util.Map;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.CatalogueItem;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.DOI_dv;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
import com.google.gwt.user.client.rpc.RemoteService;
@ -14,43 +13,35 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 28, 2020
* Jan 28, 2020
*/
@RemoteServiceRelativePath("ckantozenodo")
public interface CkanToZenodoPublisherService extends RemoteService {
/**
* Convert to zenodo item.
*
* @param item the item
* @return the zenodo item
* @throws Exception the exception
*/
ZenodoItem convertToZenodoItem(CatalogueItem item) throws Exception;
/**
* Convert to zenodo item.
*
* @param item the item
* @return the zenodo item
* @throws Exception the exception
*/
ZenodoItem convertToZenodoItem(CatalogueItem item) throws Exception;
/**
* Publish on zenodo.
*
* @param zenodoItem the zenodo item
* @return the DOI of published Zenodo Item
* @throws Exception the exception
*/
DOI_dv publishOnZenodo(ZenodoItem zenodoItem) throws Exception;
/**
* Publish on zenodo.
*
* @param zenodoItem the zenodo item
* @return the DOI of published Zenodo Item
* @throws Exception the exception
*/
String publishOnZenodo(ZenodoItem zenodoItem) throws Exception;
/**
* Read fields descriptions.
*
* @return the map
* @throws Exception the exception
*/
Map<String, String> readFieldsDescriptions() throws Exception;
/**
* Check zenodo environment.
*
* @return the true is Zenodo environment is configured in the operating scope,
* false otherwise
*/
Boolean checkZenodoEnvironment();
/**
* Read fields descriptions.
*
* @return the map
* @throws Exception the exception
*/
Map<String, String> readFieldsDescriptions() throws Exception;
}

View File

@ -3,7 +3,6 @@ package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
import java.util.Map;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.CatalogueItem;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.DOI_dv;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
import com.google.gwt.core.client.GWT;
@ -34,11 +33,9 @@ public interface CkanToZenodoPublisherServiceAsync {
void convertToZenodoItem(CatalogueItem item, AsyncCallback<ZenodoItem> callback);
void publishOnZenodo(ZenodoItem zenodoItem, AsyncCallback<DOI_dv> callback);
void publishOnZenodo(ZenodoItem zenodoItem, AsyncCallback<String> callback);
void readFieldsDescriptions(AsyncCallback<Map<String, String>> callback);
void checkZenodoEnvironment(AsyncCallback<Boolean> callback);
}

View File

@ -1,14 +1,11 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.authors;
import java.util.Arrays;
import java.util.List;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.events.RemoveCreatorEvent;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.utils.InfoTextAndLabels;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.view.FieldUtil;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoAuthor;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoContributor;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoCreator;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
@ -27,7 +24,6 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
// TODO: Auto-generated Javadoc
/**
* The Class CreatorView.
*
@ -79,29 +75,23 @@ public class CreatorView extends Composite {
private String userRole; //Can be: Creator, Contributor etc..
private ZenodoAuthor author;
private boolean isMandatoryField;
/**
* Instantiates a new creator view.
*
* @param author the author
* @param userRole the user role
* @param isMandatoryField the is mandatory field
*/
public CreatorView(ZenodoAuthor author, String userRole, Boolean isMandatoryField) {
public CreatorView(ZenodoAuthor author, String userRole) {
initWidget(uiBinder.createAndBindUi(this));
GWT.log("Creating CreatorView for author: "+author+", userRole: "+userRole);
this.userRole = userRole;
this.author = author;
this.isMandatoryField = isMandatoryField == null? false:isMandatoryField;
String fieldLabel = isMandatoryField?"<font color='red'>*</font>":"";
if(this.userRole!=null) {
field_cl_author.add(new HTML(fieldLabel+"&nbsp;"+userRole));
field_cl_author.add(new HTML("<font color='red'>*</font>&nbsp;"+userRole));
remove_author.setText("Remove "+userRole);
}else { //default role is Author
field_cl_author.add(new HTML(fieldLabel+"&nbsp;Author"));
field_cl_author.add(new HTML("<font color='red'>*</font>&nbsp;Author"));
remove_author.setText("Remove Author");
}
@ -113,30 +103,16 @@ public class CreatorView extends Composite {
if(this.author.getType()!=null) {
controls_author_type.setVisible(true);
FieldUtil.addValuesToListBox(field_author_type, this.author.getType().getSelectableValues());
List<String> listSelectedValues = this.author.getType().getSelectedValues();
if(listSelectedValues==null || listSelectedValues.isEmpty()) {
//if no type is selected (e.g. when no contributor is returned), selecting the first value of selectable values
listSelectedValues = Arrays.asList(this.author.getType().getSelectableValues().get(0));
}else
//selecting the first value of selected values
listSelectedValues = Arrays.asList(this.author.getType().getSelectedValues().get(0));
FieldUtil.selectValueToListBox(field_author_type, listSelectedValues);
FieldUtil.selectValueToListBox(field_author_type, Arrays.asList(this.author.getType().getSelectedValues().get(0)));
}
}
if(this.userRole!=null) {
String userRoleToLowerCase = userRole.toLowerCase();
if(userRoleToLowerCase.startsWith(ZenodoCreator.USER_ROLE.toLowerCase())) {
InfoTextAndLabels.addTooltipForFieldKey("creators", field_cl_author);
}else if(userRoleToLowerCase.startsWith(ZenodoContributor.USER_ROLE.toLowerCase())) {
InfoTextAndLabels.addTooltipForFieldKey("contributors", field_cl_author);
}else {
InfoTextAndLabels.addTooltipForFieldKey("authors", field_cl_author);
}
if(userRole.toLowerCase().startsWith("creator")) {
InfoTextAndLabels.addTooltipForFieldKey("creators", field_cl_author);
}else if(userRole.toLowerCase().startsWith("contributor")) {
InfoTextAndLabels.addTooltipForFieldKey("contributors", field_cl_author);
}else {
InfoTextAndLabels.addTooltipForFieldKey("authors", field_cl_author);
}
GWT.log("Created creator view with author: "+this.author);
@ -149,10 +125,9 @@ public class CreatorView extends Composite {
* @param author the author
* @param userRole the user role
* @param eventBus the event bus
* @param isFieldMandatory the is field mandatory
*/
public CreatorView(ZenodoAuthor author, String userRole, HandlerManager eventBus, Boolean isFieldMandatory) {
this(author, userRole, isFieldMandatory);
public CreatorView(ZenodoAuthor author, String userRole, HandlerManager eventBus) {
this(author, userRole);
this.eventBus = eventBus;
remove_author.addClickHandler(new ClickHandler() {
@ -173,16 +148,6 @@ public class CreatorView extends Composite {
public void setVisibleRemoveCreator(boolean visible) {
remove_author.setVisible(visible);
}
/**
* Checks if is mandatory field.
*
* @return true, if is mandatory field
*/
public boolean isMandatoryField() {
return isMandatoryField;
}
/**
* Gets the field name.
@ -265,11 +230,6 @@ public class CreatorView extends Composite {
return author;
}
/**
* Gets the field author type.
*
* @return the field author type
*/
public ListBox getField_author_type() {
return field_author_type;
}

View File

@ -64,20 +64,15 @@ public class CreatorsFormView extends Composite implements FormValidator{
private SerializableEnum<String> contributorTypeValues;
//Used as defaultRole in case of empty listAuthors
private Class theAuthorType;
/**
* Instantiates a new creators form view.
*
* @param listAuthors the list authors
*/
public CreatorsFormView(List<? extends ZenodoAuthor> listAuthors, Class theAuthorType, SerializableEnum<String> contributorTypeValues) {
public CreatorsFormView(List<? extends ZenodoAuthor> listAuthors) {
initWidget(uiBinder.createAndBindUi(this));
this.listAuthors = listAuthors;
this.theAuthorType = theAuthorType;
this.contributorTypeValues = contributorTypeValues;
button_add_author.addClickHandler(new ClickHandler() {
@ -110,24 +105,21 @@ public class CreatorsFormView extends Composite implements FormValidator{
*/
private void addAuthorsToView() {
GWT.log("Adding listAuthors: "+listAuthors);
if(listCreatorView==null)
listCreatorView = new ArrayList<CreatorView>();
if(listAuthors!=null && listAuthors.size()>0) {
userRole = ZenodoAuthor.USER_ROLE;
userRole = "Author";
for (ZenodoAuthor creator : listAuthors) {
GWT.log("Author class is "+creator.getClass());
if (creator instanceof ZenodoContributor) {
userRole = ZenodoContributor.USER_ROLE;
//overriding contributors types as defined into mapping
userRole = "Contributor";
contributorTypeValues = new SerializableEnum<String>(Arrays.asList(creator.getType().getSelectableValues().get(0)), creator.getType().getSelectableValues());
}else if(creator instanceof ZenodoCreator) {
userRole = ZenodoCreator.USER_ROLE;
userRole = "Creator";
}
CreatorView view = new CreatorView(creator, userRole, eventBus, true);
CreatorView view = new CreatorView(creator, userRole, eventBus);
listCreatorView.add(view);
fieldset_authors.add(view);
}
@ -154,32 +146,18 @@ public class CreatorsFormView extends Composite implements FormValidator{
* Adds the empty creator.
*/
private void addEmptyCreator() {
GWT.log("adding empty creator");
if(listCreatorView==null)
listCreatorView = new ArrayList<CreatorView>();
ZenodoAuthor author = null;
if(userRole == null) {
if (theAuthorType.equals(ZenodoCreator.class)) {
userRole = ZenodoCreator.USER_ROLE;
}else if(theAuthorType.equals(ZenodoContributor.class)) {
userRole = ZenodoContributor.USER_ROLE;
}else
userRole = ZenodoCreator.USER_ROLE;
GWT.log("Empty list assigned the userRole: "+userRole);
}
if(userRole.compareToIgnoreCase(ZenodoContributor.USER_ROLE)==0) {
if(userRole.compareToIgnoreCase("Contributor")==0) {
author = new ZenodoContributor();
((ZenodoContributor) author).setType(contributorTypeValues);
}else
author = new ZenodoCreator();
}
CreatorView view = new CreatorView(author, userRole, eventBus,false);
CreatorView view = new CreatorView(author, userRole, eventBus);
listCreatorView.add(view);
fieldset_authors.add(view);
@ -207,28 +185,22 @@ public class CreatorsFormView extends Composite implements FormValidator{
*/
public List<? extends ZenodoAuthor> readListOfCreatorsFromView(){
List<ZenodoAuthor> listAuthors = new ArrayList<>();
List<ZenodoAuthor> listAuthors = new ArrayList<>(listCreatorView.size());
for (CreatorView creatorView : listCreatorView) {
ZenodoAuthor author = creatorView.getAuthor();
GWT.log("Read ZenodoAuthor: "+author);
boolean isValid = FieldUtil.isValidValue(creatorView.getField_name().getValue());
if(isValid) {
GWT.log("The fielName is valid going to add it to list of Authors");
author.setName(creatorView.getField_name().getValue());
author.setAffiliation(creatorView.getField_affiliation().getValue());
author.setOrcid(creatorView.getField_orcid().getValue());
String typeSelected = creatorView.getAuthorTypeValue();
if(typeSelected!=null && !typeSelected.isEmpty()) {
author.setType(new SerializableEnum<>(Arrays.asList(typeSelected), null));
}
listAuthors.add(author);
}else
GWT.log("The fielName is null or empty skpping he/she from list of Authors");
author.setName(creatorView.getField_name().getValue());
author.setAffiliation(creatorView.getField_affiliation().getValue());
author.setOrcid(creatorView.getField_orcid().getValue());
String typeSelected = creatorView.getAuthorTypeValue();
if(typeSelected!=null && !typeSelected.isEmpty()) {
author.setType(new SerializableEnum<>(Arrays.asList(typeSelected), null));
}
listAuthors.add(author);
}
GWT.log("returning list of authors: "+listAuthors);
return listAuthors;
}
@ -251,14 +223,11 @@ public class CreatorsFormView extends Composite implements FormValidator{
for (CreatorView creatorView : listCreatorView) {
ControlGroup cgAuthor = creatorView.getControlGroup_Author();
FieldUtil.setControlGroup(cgAuthor, ControlGroupType.NONE);
if(creatorView.isMandatoryField()) {
String value = FieldUtil.getTextValue(creatorView.getField_name());
boolean isValid = FieldUtil.isValidValue(value);
if(!isValid) {
FieldUtil.setControlGroup(cgAuthor, ControlGroupType.ERROR);
return "The field "+userRole+" Name is required";
}
String value = FieldUtil.getTextValue(creatorView.getField_name());
boolean isValid = FieldUtil.isValidValue(value);
if(!isValid) {
FieldUtil.setControlGroup(cgAuthor, ControlGroupType.ERROR);
return "The field "+userRole+" Name is required";
}
/*

View File

@ -258,8 +258,6 @@ public class BasicInformationView extends Composite implements FormValidator {
field_description.setValue(zenodoItem.getMetadata().getDescription());
InfoTextAndLabels.addTooltipForFieldKey("description", cl_description);
field_doi.setValue(zenodoItem.getDoi());
GWT.log("Filling form with: "+zenodoItem.getMetadata());
ZenodoMetadata zMeta = zenodoItem.getMetadata();
if (zMeta != null) {
@ -329,19 +327,20 @@ public class BasicInformationView extends Composite implements FormValidator {
InfoTextAndLabels.addTooltipForFieldKey("access_conditions", cl_access_conditions);
// License
if (zMeta.getLicenseIDs() != null) {
//List<String> listLicensesIds = null;
List<String> selectedLicensesId = FieldUtil.toZenodoIds(zMeta.getLicenseIDs());
if(selectedLicensesId!=null) {
FieldUtil.addValuesToListBox(field_license, selectedLicensesId);
if (zMeta.getLicenses() != null) {
List<String> listLicensesIds = null;
List<String> selectedLicensesId = FieldUtil.toZenodoIds(zMeta.getLicenses().getSelectedValues());
if(zMeta.getLicenses().getSelectableValues()!=null) {
listLicensesIds = FieldUtil.toZenodoIds(zMeta.getLicenses().getSelectableValues());
FieldUtil.addValuesToListBox(field_license, listLicensesIds);
field_license.setEnabled(true);
}else {
//Exception case on missing list of selectable license ids
//FieldUtil.addValuesToListBox(field_license, selectedLicensesId);
FieldUtil.addValuesToListBox(field_license, selectedLicensesId);
field_license.setEnabled(false); //only one license id is available
}
//FieldUtil.selectValueToListBox(field_license, selectedLicensesId);
FieldUtil.selectValueToListBox(field_license, selectedLicensesId);
}else
field_license.setEnabled(false);
@ -361,24 +360,13 @@ public class BasicInformationView extends Composite implements FormValidator {
listOfContributorsView = new ArrayList<CreatorsFormView>();
// ADDING AUTHORS
try {
List<? extends ZenodoAuthor> authors = zenodoItem.getMetadata().getCreators();
GWT.log("Adding creators: " + authors);
CreatorsFormView authorView = new CreatorsFormView(authors, ZenodoCreator.class, zenodoItem.getMetadata().getContributorsTypes());
listOfCreatorsView.add(authorView);
}catch (Exception e) {
//silent
e.printStackTrace();
}
GWT.log("Adding creators: " + zenodoItem.getMetadata().getCreators());
CreatorsFormView authorView = new CreatorsFormView(zenodoItem.getMetadata().getCreators());
listOfCreatorsView.add(authorView);
try {
List<? extends ZenodoAuthor> contributors = zenodoItem.getMetadata().getContributors();
GWT.log("Adding contributors: " + contributors);
CreatorsFormView contributorView = new CreatorsFormView(contributors, ZenodoContributor.class, zenodoItem.getMetadata().getContributorsTypes());
listOfContributorsView.add(contributorView);
}catch (Exception e) {
e.printStackTrace();
}
GWT.log("Adding contributors: " + zenodoItem.getMetadata().getContributors());
CreatorsFormView contributorView = new CreatorsFormView(zenodoItem.getMetadata().getContributors());
listOfContributorsView.add(contributorView);
for (CreatorsFormView cfv : listOfCreatorsView) {
fieldset_basic_informations.add(cfv);
@ -555,9 +543,6 @@ public class BasicInformationView extends Composite implements FormValidator {
*/
public List<ZenodoCreator> getListOfCreators() {
List<ZenodoCreator> listOfCreators = new ArrayList<>();
if(listOfCreatorsView==null) {
return listOfCreators;
}
for (CreatorsFormView cfv : listOfCreatorsView) {
List<? extends ZenodoAuthor> listOfUsers = cfv.readListOfCreatorsFromView();
for (ZenodoAuthor zenodoAuthor : listOfUsers) {
@ -574,15 +559,11 @@ public class BasicInformationView extends Composite implements FormValidator {
*/
public List<ZenodoContributor> getListOfContributors() {
List<ZenodoContributor> listOfContributors = new ArrayList<>();
if(listOfContributorsView==null) {
return listOfContributors;
}
for (CreatorsFormView cfv : listOfContributorsView) {
List<? extends ZenodoAuthor> listOfUsers = cfv.readListOfCreatorsFromView();
for (ZenodoAuthor zenodoAuthor : listOfUsers) {
listOfContributors.add((ZenodoContributor) zenodoAuthor);
}
}
return listOfContributors;
}

View File

@ -8,6 +8,7 @@ import java.util.List;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.BasicTabPanel;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.basicinformation.BasicInformationView;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.LicenseBean;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoContributor;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoCreator;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoFile;
@ -123,9 +124,6 @@ public class Ckan2ZenodoViewManager {
meta.setDescription(basicForm.getField_description().getValue());
meta.setKeywords(basicForm.getTags()); // these are the keywords
//Setting publication date fxing #26166
meta.setPublication_date(basicForm.getField_publication_date().getValue());
List<ZenodoCreator> creators = basicForm.getListOfCreators();
GWT.log("Read creators from FORM: "+creators);
meta.setCreators(creators);
@ -164,11 +162,8 @@ public class Ckan2ZenodoViewManager {
//license
String licenseId = basicForm.getField_license().getSelectedValue();
if(licenseId!=null) {
//LicenseDTO licenseBean = new LicenseDTO(licenseId, null, null);
List<String> licenses = new ArrayList<String>();
licenses.add(licenseId);
meta.setLicenseIDs(licenses);
//meta.setLicenses(Arrays.asList(licenseBean));
LicenseBean licenseBean = new LicenseBean(licenseId, null, null);
meta.setLicenses(new SerializableEnum<LicenseBean>(Arrays.asList(licenseBean),null));
}
//embargo date

View File

@ -3,6 +3,9 @@ package org.gcube.portlets.widgets.ckan2zenodopublisher.client.view;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.ZenodoLicense;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.LicenseBean;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.TextBox;
@ -95,18 +98,17 @@ public class FieldUtil {
/**
* To zenodo ids.
* TODO Must passed an object License
*
* @param listLicenses the list licenses
* @return the list
*/
public static List<String> toZenodoIds(List<String> listLicenses){
public static List<String> toZenodoIds(List<LicenseBean> listLicenses){
if(listLicenses==null)
return null;
List<String> licenses = new ArrayList<String>(listLicenses.size());
for (String zenodoLicense : listLicenses) {
licenses.add(zenodoLicense);
for (ZenodoLicense zenodoLicense : listLicenses) {
licenses.add(zenodoLicense.getId());
}
return licenses;

View File

@ -17,16 +17,16 @@
}
.ckan2zenodo-modal-style .modal-body {
height: 600px;
max-height: 600px;
height: 800px;
max-height: 800px;
}
.ckan2zenodo-modal-style .form-horizontal {
height: 95%;
height: 645px;
}
.ckan2zenodo-modal-style .nav-tabs {
height: 95%;
height: 645px;
}
.ckan2zenodo-modal-style .pager {

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.server;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -16,7 +15,6 @@ 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.TransformationException;
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
import org.gcube.data.publishing.ckan2zenodo.model.report.EnvironmentReport;
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata;
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherService;
@ -26,7 +24,6 @@ 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.DOI_dv;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoFile;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoMetadata;
@ -41,32 +38,28 @@ import com.liferay.portal.service.UserLocalServiceUtil;
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 15, 2020
* Jan 15, 2020
*/
@SuppressWarnings("serial")
public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet implements CkanToZenodoPublisherService {
private static Logger LOG = LoggerFactory.getLogger(CkanToZenodoPublisherServiceImpl.class);
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.
* CkanToZenodoPublisherService#publishOnZenodo(org.gcube.portlets.widgets.
* ckan2zenodopublisher.shared.wrapped.ZenodoItem)
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherService#publishOnZenodo(org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem)
*/
@Override
public DOI_dv publishOnZenodo(ZenodoItem zenodoItem) throws Exception {
LOG.info("publishOnZenodo called");
public String publishOnZenodo(ZenodoItem zenodoItem) throws Exception {
try {
if (isOutFromPortal()) {
if(isOutFromPortal()) {
PortalUtils.getCurrentContext(this.getThreadLocalRequest(), true);
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
}
LOG.debug("publishOnZenodo called with metadata: "+zenodoItem.getMetadata());
Ckan2Zenodo client = new Ckan2ZenodoImpl();
// Get the item representation
CkanItemDescriptor itemDescr = client.read(zenodoItem.getName());
@ -78,119 +71,97 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
LOG.info("Using forceTranslation for: " + itemDescr.getItemUrl());
zenodoDepositionPreview = client.forceTranslation(itemDescr);
}
// (EVENTUALLY) UPDATING BASIC INFO CHANGED BY FORM ON CLIENT-SIDE
// Basic info
//(EVENTUALLY) UPDATING BASIC INFO CHANGED BY FORM ON CLIENT-SIDE
//Basic info
zenodoDepositionPreview.setTitle(zenodoItem.getTitle());
// Updating Deposition Metadata potentially changed on client-side
//Updating Deposition Metadata potentially changed on client-side
ZenodoMetadata metadata = zenodoItem.getMetadata();
DepositionMetadata depositionMetadata = zenodoDepositionPreview.getMetadata();
depositionMetadata = ItemToZenodoConverter.updateMetadataInfoOfDepositionMetadata(metadata,
depositionMetadata);
depositionMetadata = ItemToZenodoConverter.updateMetadataInfoOfDepositionMetadata(metadata, depositionMetadata);
zenodoDepositionPreview.setMetadata(depositionMetadata);
// Loading Filtered resources according to VRE policies
//Loading Filtered resources according to VRE policies
List<CkanResource> filteredResources = loadFilterResources(zenodoItem.getName());
HashSet<CkanResource> toUpload = new HashSet<CkanResource>();
// Adding for publishing only the resources selected on clien-side
if (zenodoItem.getFiles() != null) {
//Adding for publishing only the resources selected on clien-side
if(zenodoItem.getFiles()!=null) {
for (ZenodoFile zf : zenodoItem.getFiles()) {
for (CkanResource ckanResource : filteredResources) {
if (zf.getId().compareTo(ckanResource.getId()) == 0 && zf.getIsAlreadyPublished() == false) {
if (CkanToZenodoUtil.isNotEmpty(zf.getFilename())) {
ckanResource.setName(zf.getFilename()); // only the filename can be changed on
// clien-side
if(zf.getId().compareTo(ckanResource.getId())==0 && zf.getIsAlreadyPublished()==false) {
if(CkanToZenodoUtil.isNotEmpty(zf.getFilename())) {
ckanResource.setName(zf.getFilename()); //only the filename can be changed on clien-side
toUpload.add(ckanResource);
}
}
}
}
}
// Actually publish to zenodo :
//Actually publish to zenodo :
// Step 1 : metadata
client = new Ckan2ZenodoImpl();
LOG.debug("Calling updatedMetadata for: " + zenodoDepositionPreview);
//fixing issue #26166
Date thePublicationDate = zenodoDepositionPreview.getMetadata().getPublication_date();
LOG.debug("Publication_Date before update is: " + thePublicationDate);
client= new Ckan2ZenodoImpl();
LOG.debug("Calling updatedMetadta for: "+zenodoDepositionPreview);
zenodoDepositionPreview = client.updatedMetadata(zenodoDepositionPreview);
// Step 2 : publish Resources
if (toUpload.size() > 0) {
LOG.debug("Trying to publish the set of CKAN resources: " + toUpload.toString());
//fixing issue #26166
zenodoDepositionPreview.getMetadata().setPublication_date(thePublicationDate);
LOG.debug("Publication_Date before uploadFiles is: " + zenodoDepositionPreview.getMetadata().getPublication_date());
Future<ZenodoDeposition> future_Dep = client.uploadFiles(toUpload, zenodoDepositionPreview);
while (!future_Dep.isDone()) {
LOG.debug("Waiting for completed future computation (publishing of resources on Zenodo)...");
Thread.sleep(2000);
//Step 2 : publish Resources
if(toUpload.size()>0) {
LOG.debug("Trying to publish the set of CKAN resources: "+toUpload.toString());
Future<ZenodoDeposition> future_Dep=client.uploadFiles(toUpload, zenodoDepositionPreview);
while(!future_Dep.isDone()) {
LOG.debug("Waiting for completed future computation (publishing of resources on Zenodo)...");
Thread.sleep(2000);
}
zenodoDepositionPreview = future_Dep.get(600, TimeUnit.SECONDS);
zenodoDepositionPreview = future_Dep.get(600,TimeUnit.SECONDS);
}
// Get the item representation
CkanItemDescriptor item = client.read(zenodoItem.getName());
//fixing issue #26166
LOG.debug("Publication_Date before publish is: " + thePublicationDate);
zenodoDepositionPreview.getMetadata().setPublication_date(thePublicationDate);
// Finalize
LOG.debug("Calling publish on Zenodo for: " + zenodoDepositionPreview);
// Get the item representation
CkanItemDescriptor item=client.read(zenodoItem.getName());
//Finalize
LOG.debug("Calling publish on Zenodo for: "+zenodoDepositionPreview);
zenodoDepositionPreview = client.publish(zenodoDepositionPreview, item);
return new DOI_dv(zenodoDepositionPreview.getDoi(), zenodoDepositionPreview.getDoi_url());
// throw new ZenodoException();
} catch (TimeoutException e) {
return zenodoDepositionPreview.getDoi();
//throw new ZenodoException();
}catch (TimeoutException e) {
String error = "I'm waiting too time to upload the files to Zenodo. Check by yourself the result later";
LOG.error(error, e);
String clientError = String.format("%s", error);
throw new Exception(clientError);
} catch (ZenodoException e) {
String error = ZenodoException.class.getName() + " during upload to Zenodo the catalogue item: "
+ zenodoItem.getName();
String error = ZenodoException.class.getName()+" during upload to Zenodo the catalogue item: "+zenodoItem.getName();
LOG.error(error, e);
// String clientError = String.format("%s", e.getRemoteMessage());
//String clientError = String.format("%s", e.getRemoteMessage());
ZenodoError zenodoError = new ZenodoError(e);
zenodoError.setRemoteMessage(e.getRemoteMessage());
zenodoError.setResponseHTTPCode(e.getResponseHTTPCode());
throw zenodoError;
} catch (Exception e) {
String error = "Error during upload to Zenodo the catalogue item: " + zenodoItem.getName();
String error = "Error during upload to Zenodo the catalogue item: "+zenodoItem.getName();
LOG.error(error, e);
String clientError = String.format("%s. %s", error, e.getMessage());
throw new Exception(clientError);
}
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.
* CkanToZenodoPublisherService#convertToZenodoItem(org.gcube.portlets.widgets.
* ckan2zenodopublisher.shared.CatalogueItem)
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherService#convertToZenodoItem(org.gcube.portlets.widgets.ckan2zenodopublisher.shared.CatalogueItem)
*/
@Override
public ZenodoItem convertToZenodoItem(CatalogueItem item) throws Exception {
LOG.info("convertToZenodoItem called");
try {
if (isOutFromPortal()) {
try {
if(isOutFromPortal()) {
PortalUtils.getCurrentContext(this.getThreadLocalRequest(), true);
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
}
Ckan2Zenodo client = new Ckan2ZenodoImpl();
// Get the item representation
CkanItemDescriptor itemDescr = client.read(item.getItemId());
@ -199,77 +170,69 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
ItemTranslateError itemTrError = null;
try {
zdDeposition = client.translate(itemDescr);
} catch (ConfigurationException | TransformationException e) {
} 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);
LOG.debug("Loaded filtered resources: "+filteredResources);
// Converting ZenodoDeposition to ZenodoItem
//Converting ZenodoDeposition to ZenodoItem
ZenodoItem zenodoItem = ItemToZenodoConverter.toZenodoItem(zdDeposition);
// Adding ItemTranslateError eventually occurred by calling client.translate
//Adding ItemTranslateError eventually occurred by calling client.translate
zenodoItem.setTranslateError(itemTrError);
// Adding the filtered resources
//Adding the filtered resources
List<ZenodoFile> resources = ItemToZenodoConverter.toZenodoFiles(filteredResources, false);
zenodoItem.addFiles(resources);
// I'M SETTING THE ID BECAUSE THE NAME IS NULL INTO BEAN PASSED FROM PORTLET
// SIDE
// TODO I'M WAITING FOR itemName retrieved from ckan2zenodo library
zenodoItem.setName(item.getItemId());
LOG.debug("zenodoItem getLicenses as list: " + zenodoItem.getMetadata().getLicenseIDs());
//LOG.debug("setting licenses at null");
//zenodoItem.getMetadata().setLicenseIDs(null);
LOG.debug("Returning item: " + zenodoItem);
//I'M SETTING THE ID BECAUSE THE NAME IS NULL INTO BEAN PASSED FROM PORTLET SIDE
//TODO I'M WAITING FOR itemName retrieved from ckan2zenodo library
zenodoItem.setName(item.getItemId());
LOG.debug("Returning item: "+zenodoItem);
return zenodoItem;
} catch (ZenodoException e) {
String error = ZenodoException.class.getName() + " on converting the catalogue item with id: "
+ item.getItemId();
String error = ZenodoException.class.getName()+" on converting the catalogue item with id: "+item.getItemId();
LOG.error(error, e);
// String clientError = String.format("%s. %s", error, e.getRemoteMessage());
//String clientError = String.format("%s. %s", error, e.getRemoteMessage());
ZenodoError zenodoError = new ZenodoError(e);
zenodoError.setRemoteMessage(e.getRemoteMessage());
zenodoError.setResponseHTTPCode(e.getResponseHTTPCode());
throw zenodoError;
} catch (Exception e) {
String error = "Error on converting the catalogue item with id: " + item.getItemId();
String error = "Error on converting the catalogue item with id: "+item.getItemId();
LOG.error(error, e);
String clientError = String.format("%s. %s", error, e.getMessage());
throw new Exception(clientError);
}
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.
* CkanToZenodoPublisherService#convertToZenodoItem(org.gcube.portlets.widgets.
* ckan2zenodopublisher.shared.CatalogueItem)
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherService#convertToZenodoItem(org.gcube.portlets.widgets.ckan2zenodopublisher.shared.CatalogueItem)
*/
@Override
public Map<String, String> readFieldsDescriptions() throws Exception {
LOG.info("readFieldsDescriptions called");
try {
if (isOutFromPortal()) {
try {
if(isOutFromPortal()) {
PortalUtils.getCurrentContext(this.getThreadLocalRequest(), true);
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
}
return ZenodoFieldsDescriptionsReader.readProperties();
} catch (Exception e) {
String error = "Unable to read the file of properties with the fields desciptions";
LOG.error(error, e);
@ -278,51 +241,25 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
}
}
@Override
public Boolean checkZenodoEnvironment() {
LOG.info("checkZenodoEnvironment called");
boolean isZenodoConfigured = false;
try {
if (isOutFromPortal()) {
PortalUtils.getCurrentContext(this.getThreadLocalRequest(), true);
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
}
LOG.info("readFieldsDescriptions called");
Ckan2Zenodo client = new Ckan2ZenodoImpl();
EnvironmentReport report = client.checkEnvironment();
LOG.info("EnvironmentReport returned: " + report);
isZenodoConfigured = report.isok();
} catch (Exception e) {
LOG.error("Error occurred during checkEnvironment: ", e);
}
LOG.info("Is Zenodo Environment configured? " + isZenodoConfigured);
return isZenodoConfigured;
}
/**
* Load filter resources.
*
* @param itemName the item name
* @return the list
* @throws GcatException the gcat exception
* @throws ConfigurationException the configuration exception
* @throws GcatException the gcat exception
* @throws ConfigurationException the configuration exception
* @throws TransformationException the transformation exception
*/
private List<CkanResource> loadFilterResources(String itemName)
throws GcatException, ConfigurationException, TransformationException {
private List<CkanResource> loadFilterResources(String itemName) throws GcatException, ConfigurationException, TransformationException {
Ckan2Zenodo client = new Ckan2ZenodoImpl();
// Get the item representation
CkanItemDescriptor itemDescr = client.read(itemName);
// Filter resources according to VRE policies
CkanItemDescriptor itemDescr=client.read(itemName);
//Filter resources according to VRE policies
return client.filterResources(itemDescr);
}
/**
* Online or in development mode?.
*
@ -332,10 +269,10 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
try {
UserLocalServiceUtil.getService();
return false;
} catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
}
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
LOG.debug("Development Mode ON");
return true;
}
}
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.ZenodoLicense;
/**
@ -47,6 +48,20 @@ public class CkanToZenodoUtil {
return new SerializableEnum<String>(selectedValues, values);
}
/**
* To serializable enum.
*
* @param <E> the element type
* @param selectedLicense the selected license
* @param allLicenses the all licenses
* @return the serializable enum
*/
public static <E extends ZenodoLicense> SerializableEnum<E> toSerializableEnum(List<E> selectedLicense, List<E> allLicenses) {
return new SerializableEnum<E>(selectedLicense, allLicenses);
}
/**
* Checks if is not empty.
*

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.server.converter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@ -22,6 +23,7 @@ import org.gcube.data.publishing.ckan2zenodo.model.zenodo.Subject;
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
import org.gcube.portlets.widgets.ckan2zenodopublisher.server.CkanToZenodoUtil;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.LicenseBean;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoAuthor;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoCommunity;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoContributor;
@ -35,17 +37,18 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoSubj
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class ItemToZenodoConverter.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 10, 2019
* Dec 10, 2019
*/
public class ItemToZenodoConverter {
private static Logger LOG = LoggerFactory.getLogger(ItemToZenodoConverter.class);
/**
* **
*
@ -55,7 +58,8 @@ public class ItemToZenodoConverter {
* @param zenodoDeposition the zenodo deposition
* @return the zenodo item
*/
/**
* To zenodo item.
*
@ -63,108 +67,112 @@ public class ItemToZenodoConverter {
* @return the zenodo item
*/
public static ZenodoItem toZenodoItem(ZenodoDeposition zenodoDeposition) {
if (zenodoDeposition == null)
if(zenodoDeposition==null)
return null;
LOG.debug("Converting item: " + zenodoDeposition);
LOG.debug("Converting item: "+zenodoDeposition);
ZenodoItem zi = new ZenodoItem();
zi.setId(zenodoDeposition.getId());
zi.setDoi(zenodoDeposition.getDoi());
zi.setCreated(zenodoDeposition.getCreated());
// Add files already published in the deposition
List<ZenodoFile> files = toZenodoFiles(zenodoDeposition.getFiles(), true);
//Add files already published in the deposition
List<ZenodoFile> files = toZenodoFiles(zenodoDeposition.getFiles(),true);
zi.addFiles(files);
zi.setModified(zenodoDeposition.getModified());
zi.setOwner(zenodoDeposition.getOwner());
zi.setRecord_id(zenodoDeposition.getRecord_id());
zi.setRecord_url(zenodoDeposition.getRecord_url() != null ? zenodoDeposition.getRecord_url().toString() : null);
zi.setRecord_url(zenodoDeposition.getRecord_url()!=null?zenodoDeposition.getRecord_url().toString():null);
zi.setState(zenodoDeposition.getState());
zi.setSubmitted(zenodoDeposition.getSubmitted());
zi.setTitle(zenodoDeposition.getTitle());
zi.setMetadata(toZenodoMetadata(zenodoDeposition.getMetadata()));
LOG.debug("Converted item: " + zi);
LOG.debug("Converted item: "+zi);
return zi;
}
/**
* Adds the files.
*
* @param files the files
* @param files the files
* @param filesAlreadyPublished the files already published
* @return the list
*/
private static List<ZenodoFile> toZenodoFiles(ArrayList<FileDeposition> files, boolean filesAlreadyPublished) {
if (files == null)
if(files==null)
return null;
List<ZenodoFile> listOfFiles = new ArrayList<ZenodoFile>(files.size());
for (FileDeposition fileDeposition : files) {
listOfFiles.add(toZenodoFile(fileDeposition, filesAlreadyPublished));
}
return listOfFiles;
}
/**
* To zenodo files.
*
* @param filteredResources the filtered resources
* @param filteredResources the filtered resources
* @param filesAlreadyPublished the files already published
* @return the list
*/
public static List<ZenodoFile> toZenodoFiles(List<CkanResource> filteredResources, boolean filesAlreadyPublished) {
if (filteredResources == null)
if(filteredResources==null)
return null;
List<ZenodoFile> listOfFiles = new ArrayList<ZenodoFile>(filteredResources.size());
for (CkanResource ckanResource : filteredResources) {
listOfFiles.add(toZenodoFile(ckanResource, filesAlreadyPublished));
listOfFiles.add(toZenodoFile(ckanResource,filesAlreadyPublished));
}
return listOfFiles;
}
/**
* To zenodo file.
*
* @param fileDeposition the file deposition
* @param fileDeposition the file deposition
* @param fileAlreadyPublished the file already published
* @return the zenodo file
*/
public static ZenodoFile toZenodoFile(FileDeposition fileDeposition, boolean fileAlreadyPublished) {
if (fileDeposition == null)
if(fileDeposition==null)
return null;
ZenodoFile zf = new ZenodoFile();
zf.setId(fileDeposition.getId());
zf.setFilename(fileDeposition.getFilename());
zf.setFilesize(fileDeposition.getFilesize() + "");
zf.setFilesize(fileDeposition.getFilesize()+"");
zf.setChecksum(fileDeposition.getChecksum());
zf.setIsAlreadyPublished(fileAlreadyPublished);
return zf;
}
/**
* To zenodo file.
*
* @param ckanResource the ckan resource
* @param ckanResource the ckan resource
* @param fileAlreadyPublished the file already published
* @return the zenodo file
*/
public static ZenodoFile toZenodoFile(CkanResource ckanResource, boolean fileAlreadyPublished) {
if (ckanResource == null)
if(ckanResource==null)
return null;
ZenodoFile zf = new ZenodoFile();
zf.setId(ckanResource.getId());
zf.setFilename(ckanResource.getName());
@ -176,72 +184,67 @@ public class ItemToZenodoConverter {
zf.setIsAlreadyPublished(fileAlreadyPublished);
return zf;
}
/**
* To zenodo metadata.
*
* @param depositionMetadata the deposition metadata
* @return the zenodo metadata
*/
public static ZenodoMetadata toZenodoMetadata(DepositionMetadata depositionMetadata) {
if (depositionMetadata == null)
public static ZenodoMetadata toZenodoMetadata(DepositionMetadata depositionMetadata){
if(depositionMetadata==null)
return null;
ZenodoMetadata zm = new ZenodoMetadata();
zm.setAccess_conditions(depositionMetadata.getAccess_conditions());
zm.setDescription(depositionMetadata.getDescription());
// fixing bug #26165 on publication_date = null
zm.setPublication_date(depositionMetadata.getPublication_date());
// Access Type
//Access Type
AccessRights[] accessRight = null;
if (depositionMetadata.getAccess_right() != null) {
if(depositionMetadata.getAccess_right()!=null) {
AccessRights[] theAccessRight = { depositionMetadata.getAccess_right() };
accessRight = theAccessRight;
}
zm.setAccess_right(CkanToZenodoUtil.toSerializableEnum(accessRight, AccessRights.values()));
// Upload Type
//Upload Type
UploadType[] uploadType = null;
if (depositionMetadata.getUpload_type() != null) {
if(depositionMetadata.getUpload_type()!=null) {
UploadType[] theUploadType = { depositionMetadata.getUpload_type() };
uploadType = theUploadType;
}
zm.setUpload_type(CkanToZenodoUtil.toSerializableEnum(uploadType, UploadType.values()));
// Publication Type
//Publication Type
PublicationType[] publicationType = null;
if (depositionMetadata.getPublication_type() != null) {
if(depositionMetadata.getPublication_type()!=null) {
PublicationType[] thepublicationType = { depositionMetadata.getPublication_type() };
publicationType = thepublicationType;
}
zm.setPublication_type(CkanToZenodoUtil.toSerializableEnum(publicationType, PublicationType.values()));
// Image Type
//Image Type
ImageType[] imageType = null;
if (depositionMetadata.getImage_type() != null) {
if(depositionMetadata.getImage_type()!=null) {
ImageType[] theImageType = { depositionMetadata.getImage_type() };
imageType = theImageType;
}
zm.setImage_type(CkanToZenodoUtil.toSerializableEnum(imageType, ImageType.values()));
// Licenses
List<String> selectedLicenses = null;
if (depositionMetadata.getLicense() != null) {
selectedLicenses = new ArrayList<String>();
selectedLicenses.add(depositionMetadata.getLicense()); // NEED TO ADD ALL LICENSES
//Licenses
List<LicenseBean> selectedLicenses = null;
if(depositionMetadata.getLicense()!=null) {
selectedLicenses = Arrays.asList(new LicenseBean(depositionMetadata.getLicense(),depositionMetadata.getLicense(), null));
}
if (selectedLicenses != null) {
zm.setLicenseIDs(selectedLicenses);
zm.setLicenses(CkanToZenodoUtil.toSerializableEnum(selectedLicenses, null)); //NEED TO ADD ALL LICENSES
if(depositionMetadata.getEmbargo_date()!=null) {
}
if (depositionMetadata.getEmbargo_date() != null) {
}
zm.setKeywords(depositionMetadata.getKeywords());
zm.setCommunities(toZenodoCommunities(depositionMetadata.getCommunities()));
zm.setConference_acronym(depositionMetadata.getConference_acronym());
@ -251,12 +254,7 @@ public class ItemToZenodoConverter {
zm.setConference_session_part(depositionMetadata.getConference_session_part());
zm.setConference_title(depositionMetadata.getConference_title());
zm.setConference_url(depositionMetadata.getConference_url());
zm.setContributors(toZenodoContributors(depositionMetadata.getContributors()));
// to manage empty or null contributors from mapping
zm.setContributorsTypes(CkanToZenodoUtil.toSerializableEnum(null, Contributor.Type.values()));
zm.setCreators(toZenodoCreators(depositionMetadata.getCreators()));
zm.setDates(toZenodoDateIntervals(depositionMetadata.getDates()));
zm.setEmbargo_date(depositionMetadata.getEmbargo_date());
@ -267,10 +265,11 @@ public class ItemToZenodoConverter {
zm.setTitle(depositionMetadata.getTitle());
zm.setVersion(depositionMetadata.getVersion());
zm.setNotes(depositionMetadata.getNotes());
return zm;
}
/**
* To zenodo subjects.
*
@ -278,15 +277,15 @@ public class ItemToZenodoConverter {
* @return the list
*/
private static List<ZenodoSubject> toZenodoSubjects(List<Subject> subjects) {
if (subjects == null)
if(subjects==null)
return null;
List<ZenodoSubject> list = new ArrayList<ZenodoSubject>(subjects.size());
for (Subject sub : subjects) {
ZenodoSubject zs = new ZenodoSubject(sub.getTerm(), sub.getIdentifier(), sub.getScheme());
list.add(zs);
}
return list;
}
@ -297,21 +296,22 @@ public class ItemToZenodoConverter {
* @return the list
*/
private static List<ZenodoRelatedIdentifier> toRelatedIdentifiers(List<RelatedIdentifier> related_identifiers) {
if (related_identifiers == null)
if(related_identifiers==null)
return null;
List<ZenodoRelatedIdentifier> list = new ArrayList<ZenodoRelatedIdentifier>(related_identifiers.size());
for (RelatedIdentifier relatedIdentifier : related_identifiers) {
Relation[] rel = { relatedIdentifier.getRelation() };
SerializableEnum<String> sEnum = CkanToZenodoUtil.toSerializableEnum(rel, Relation.values());
SerializableEnum<String> sEnum = CkanToZenodoUtil.toSerializableEnum(rel, Relation.values());
ZenodoRelatedIdentifier zdi = new ZenodoRelatedIdentifier(relatedIdentifier.getIdentifier(), sEnum);
list.add(zdi);
}
return list;
}
/**
* To zenodo date intervals.
*
@ -319,22 +319,21 @@ public class ItemToZenodoConverter {
* @return the list
*/
private static List<ZenodoDateInterval> toZenodoDateIntervals(List<DateInterval> dateIntervals) {
if (dateIntervals == null)
if(dateIntervals==null)
return null;
List<ZenodoDateInterval> list = new ArrayList<ZenodoDateInterval>(dateIntervals.size());
for (DateInterval dateInterval : dateIntervals) {
SerializableEnum<String> types = null;
if (dateInterval.getType() != null) {
if(dateInterval.getType()!=null) {
DateInterval.Type[] rel = { dateInterval.getType() };
types = CkanToZenodoUtil.toSerializableEnum(rel, DateInterval.Type.values());
}
list.add(new ZenodoDateInterval(dateInterval.getStart(), dateInterval.getEnd(), types,
dateInterval.getDescription()));
list.add(new ZenodoDateInterval(dateInterval.getStart(), dateInterval.getEnd(), types, dateInterval.getDescription()));
}
return list;
}
@ -345,18 +344,18 @@ public class ItemToZenodoConverter {
* @return the list
*/
public static List<ZenodoCommunity> toZenodoCommunities(List<Community> communities) {
if (communities == null)
if(communities==null)
return null;
List<ZenodoCommunity> list = new ArrayList<ZenodoCommunity>(communities.size());
for (Community community : communities) {
list.add(new ZenodoCommunity(community.getIdentifier()));
}
return list;
}
/**
* To zenodo contributors.
*
@ -364,10 +363,10 @@ public class ItemToZenodoConverter {
* @return the list
*/
public static List<ZenodoContributor> toZenodoContributors(List<Contributor> contributors) {
if (contributors == null)
if(contributors==null)
return null;
List<ZenodoContributor> list = new ArrayList<ZenodoContributor>(contributors.size());
for (Contributor contr : contributors) {
ZenodoContributor zc = new ZenodoContributor();
@ -376,17 +375,17 @@ public class ItemToZenodoConverter {
zc.setName(contr.getName());
zc.setOrcid(contr.getOrcid());
SerializableEnum<String> types = null;
if (contr.getType() != null) {
if(contr.getType()!=null) {
Contributor.Type[] rel = { contr.getType() };
types = CkanToZenodoUtil.toSerializableEnum(rel, Contributor.Type.values());
}
zc.setType(types);
list.add(zc);
}
return list;
}
/**
* To zenodo creators.
*
@ -394,10 +393,10 @@ public class ItemToZenodoConverter {
* @return the list
*/
public static List<ZenodoCreator> toZenodoCreators(List<Creator> creators) {
if (creators == null)
if(creators==null)
return null;
List<ZenodoCreator> list = new ArrayList<ZenodoCreator>(creators.size());
for (Creator contr : creators) {
ZenodoCreator zc = new ZenodoCreator();
@ -407,10 +406,11 @@ public class ItemToZenodoConverter {
zc.setOrcid(contr.getOrcid());
list.add(zc);
}
return list;
}
/**
* To service file deposition.
*
@ -418,203 +418,197 @@ public class ItemToZenodoConverter {
* @return the file deposition
*/
public static FileDeposition toServiceFileDeposition(ZenodoFile zenodoFile) {
if (zenodoFile == null)
if(zenodoFile==null)
return null;
FileDeposition fileDep = new FileDeposition();
fileDep.setId(zenodoFile.getId());
fileDep.setFilename(zenodoFile.getFilename());
try {
fileDep.setFilesize(Integer.parseInt(zenodoFile.getFilesize()));
} catch (Exception e) {
}catch (Exception e) {
// TODO: handle exception
}
fileDep.setChecksum(zenodoFile.getChecksum());
return fileDep;
}
/**
* Update metadata info of deposition metadata.
*
* @param metadata the metadata
* @param metadata the metadata
* @param depositionMetadata the deposition metadata
* @return the deposition metadata
*/
public static DepositionMetadata updateMetadataInfoOfDepositionMetadata(ZenodoMetadata metadata,
DepositionMetadata depositionMetadata) {
// description
String description = metadata.getDescription();
LOG.debug("Read description: " + description);
if (description != null) {
depositionMetadata.setDescription(description);
}
// upload type
public static DepositionMetadata updateMetadataInfoOfDepositionMetadata(ZenodoMetadata metadata, DepositionMetadata depositionMetadata) {
//upload type
SerializableEnum<String> uploadType = metadata.getUpload_type();
LOG.debug("Read upload type: " + uploadType);
if (uploadType != null && uploadType.getSelectedValues() != null) {
LOG.debug("Read upload type: "+uploadType);
if(uploadType!=null && uploadType.getSelectedValues()!=null) {
String theUploadTypeValue = uploadType.getSelectedValues().get(0);
LOG.debug("Set upload type: " + theUploadTypeValue);
LOG.debug("Set upload type: "+theUploadTypeValue);
depositionMetadata.setUpload_type(UploadType.valueOf(theUploadTypeValue));
}
// access right
//access right
SerializableEnum<String> accessRight = metadata.getAccess_right();
LOG.debug("Read access type: " + accessRight);
if (accessRight != null && accessRight.getSelectedValues() != null) {
LOG.debug("Read access type: "+accessRight);
if(accessRight!=null && accessRight.getSelectedValues()!=null) {
try {
String theAccessRightValue = accessRight.getSelectedValues().get(0);
LOG.debug("Set access right: " + theAccessRightValue);
LOG.debug("Set access right: "+theAccessRightValue);
depositionMetadata.setAccess_right(AccessRights.valueOf(theAccessRightValue));
} catch (Exception e) {
LOG.warn("Set access right error: ", e);
}catch (Exception e) {
LOG.warn("Set access right error: ",e);
}
}
// publication type
//publication type
SerializableEnum<String> publicationType = metadata.getPublication_type();
LOG.debug("Read publication type: " + publicationType);
if (publicationType != null && publicationType.getSelectedValues() != null) {
LOG.debug("Read publication type: "+publicationType);
if(publicationType!=null && publicationType.getSelectedValues()!=null) {
try {
String thePublicationTypeValue = publicationType.getSelectedValues().get(0);
LOG.debug("Set publication type: " + thePublicationTypeValue);
LOG.debug("Set publication type: "+thePublicationTypeValue);
depositionMetadata.setPublication_type(PublicationType.valueOf(thePublicationTypeValue));
} catch (Exception e) {
LOG.warn("Set publication type error: ", e);
}catch (Exception e) {
LOG.warn("Set publication type error: ",e);
}
}
// image type
//image type
SerializableEnum<String> imageType = metadata.getImage_type();
LOG.debug("Read image type: " + imageType);
if (imageType != null && imageType.getSelectedValues() != null) {
LOG.debug("Read image type: "+imageType);
if(imageType!=null && imageType.getSelectedValues()!=null) {
try {
String imageTypeValue = imageType.getSelectedValues().get(0);
LOG.debug("Set image type: " + imageTypeValue);
LOG.debug("Set image type: "+imageTypeValue);
depositionMetadata.setImage_type(ImageType.valueOf(imageTypeValue));
} catch (Exception e) {
LOG.warn("Set image type error: ", e);
}catch (Exception e) {
LOG.warn("Set image type error: ",e);
}
}
// embargo_date
//embargo_date
Date embargoDate = metadata.getEmbargo_date();
LOG.debug("Read embargo date: " + imageType);
if (embargoDate != null) {
LOG.debug("Read embargo date: "+imageType);
if(embargoDate!=null) {
try {
LOG.debug("Set embargo date: " + embargoDate);
LOG.debug("Set embargo date: "+embargoDate);
depositionMetadata.setEmbargo_date(embargoDate);
} catch (Exception e) {
LOG.warn("Set embargo date error: ", e);
}catch (Exception e) {
LOG.warn("Set embargo date error: ",e);
}
}
// access conditions
//access conditions
String accessConditions = metadata.getAccess_conditions();
LOG.debug("Read access conditions: " + accessConditions);
if (accessConditions != null) {
LOG.debug("Set access conditions: " + accessConditions);
LOG.debug("Read access conditions: "+accessConditions);
if(accessConditions!=null) {
LOG.debug("Set access conditions: "+accessConditions);
depositionMetadata.setAccess_conditions(accessConditions);
}
// license
List<String> licenses = metadata.getLicenseIDs();
LOG.debug("Read licenses: " + licenses);
if (licenses != null && licenses.size() > 0) {
//license
SerializableEnum<LicenseBean> licenses = metadata.getLicenses();
LOG.debug("Read licenses: "+licenses);
if(licenses!=null) {
try {
String lB = licenses.get(0);
LOG.debug("Set license: " + lB);
depositionMetadata.setLicense(lB);
} catch (Exception e) {
LOG.warn("Set license error: ", e);
LicenseBean lB = licenses.getSelectedValues().get(0);
LOG.debug("Set license: "+lB);
depositionMetadata.setLicense(lB.getId());
}catch (Exception e) {
LOG.warn("Set license error: ",e);
}
}
// creators
//creators
List<Creator> creators = null;
List<? extends ZenodoAuthor> zenodoCreators = metadata.getCreators();
LOG.debug("Read Creators: " + zenodoCreators);
if (zenodoCreators != null) {
LOG.debug("Read Creators: "+zenodoCreators);
if(zenodoCreators!=null) {
creators = toCreators(zenodoCreators);
}
LOG.debug("Set Creators: " + creators);
LOG.debug("Set Creators: "+creators);
depositionMetadata.setCreators(creators);
// contributors
//contributors
List<Contributor> contributors = null;
List<? extends ZenodoAuthor> zenodoContributors = metadata.getContributors();
LOG.debug("Read Contributors: " + zenodoContributors);
if (zenodoContributors != null) {
LOG.debug("Read Contributors: "+zenodoContributors);
if(zenodoContributors!=null) {
contributors = toContributors(zenodoContributors);
}
if (LOG.isDebugEnabled()) {
if(LOG.isDebugEnabled()) {
for (Contributor contributor : contributors) {
LOG.debug("Set contributor: name " + contributor.getName() + " type " + contributor.getType());
LOG.debug("Set contributor: name "+contributor.getName() + " type "+contributor.getType());
}
}
depositionMetadata.setContributors(contributors);
// keywords
//keywords
depositionMetadata.setKeywords(metadata.getKeywords());
return depositionMetadata;
}
/**
* To creators.
*
* @param zenodoCreators the zenodo creators
* @return the list
*/
public static List<Creator> toCreators(List<? extends ZenodoAuthor> zenodoCreators) {
if (zenodoCreators == null)
public static List<Creator> toCreators(List<? extends ZenodoAuthor> zenodoCreators){
if(zenodoCreators==null)
return null;
List<Creator> listOfCreators = new ArrayList<>(zenodoCreators.size());
for (ZenodoAuthor zenodoAuthor : zenodoCreators) {
Creator creator = new Creator();
creator.setName(zenodoAuthor.getName());
if (CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getAffiliation())) {
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getAffiliation())) {
creator.setAffiliation(zenodoAuthor.getAffiliation());
}
if (CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getGnd())) {
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getGnd())) {
creator.setGnd(zenodoAuthor.getGnd());
}
if (CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getOrcid())) {
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getOrcid())) {
creator.setOrcid(zenodoAuthor.getOrcid());
}
listOfCreators.add(creator);
}
return listOfCreators;
}
/**
* To contributors.
*
* @param zenodoContributors the zenodo contributors
* @return the list
*/
public static List<Contributor> toContributors(List<? extends ZenodoAuthor> zenodoContributors) {
if (zenodoContributors == null)
public static List<Contributor> toContributors(List<? extends ZenodoAuthor> zenodoContributors){
if(zenodoContributors==null)
return null;
List<Contributor> listOfContributors = new ArrayList<Contributor>(zenodoContributors.size());
for (ZenodoAuthor zenodoAuthor : zenodoContributors) {
Contributor contributor = new Contributor();
contributor.setName(zenodoAuthor.getName());
if (CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getAffiliation())) {
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getAffiliation())) {
contributor.setAffiliation(zenodoAuthor.getAffiliation());
}
if (CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getGnd())) {
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getGnd())) {
contributor.setGnd(zenodoAuthor.getGnd());
}
if (CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getOrcid())) {
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getOrcid())) {
contributor.setOrcid(zenodoAuthor.getOrcid());
}
Type type = null;
@ -622,14 +616,16 @@ public class ItemToZenodoConverter {
try {
theType = zenodoAuthor.getType().getSelectedValues().get(0);
type = Type.valueOf(theType);
} catch (Exception e) {
LOG.error("I'm not able to convert " + theType + " as value of " + Type.class.getName());
}catch (Exception e) {
LOG.error("I'm not able to convert "+theType + " as value of "+Type.class.getName());
}
contributor.setType(type);
listOfContributors.add(contributor);
}
return listOfContributors;
}
}

View File

@ -32,7 +32,7 @@ public class ItemTranslateError implements Serializable {
/**
* Instantiates a new zenodo translate error.
*/
public ItemTranslateError() {
ItemTranslateError() {
}
/**

View File

@ -0,0 +1,34 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.shared;
/**
* The Interface ZenodoLicense.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 21, 2020
*/
public interface ZenodoLicense {
/**
* Gets the id.
*
* @return the id
*/
String getId();
/**
* Gets the title.
*
* @return the title
*/
String getTitle();
/**
* Gets the url.
*
* @return the url
*/
String getUrl();
}

View File

@ -1,92 +0,0 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped;
import java.io.Serializable;
/**
* The Class DOI_dv.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jul 28, 2023
*/
public class DOI_dv implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String doi;
private String doi_url;
/**
* Instantiates a new DO I dv.
*/
public DOI_dv() {
}
/**
* Instantiates a new DO I dv.
*
* @param doi the doi
* @param doi_url the doi url
*/
public DOI_dv(String doi, String doi_url) {
super();
this.doi = doi;
this.doi_url = doi_url;
}
/**
* Gets the doi.
*
* @return the doi
*/
public String getDoi() {
return doi;
}
/**
* Gets the doi url.
*
* @return the doi url
*/
public String getDoi_url() {
return doi_url;
}
/**
* Sets the doi.
*
* @param doi the new doi
*/
public void setDoi(String doi) {
this.doi = doi;
}
/**
* Sets the doi url.
*
* @param doi_url the new doi url
*/
public void setDoi_url(String doi_url) {
this.doi_url = doi_url;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DOI_dv [doi=");
builder.append(doi);
builder.append(", doi_url=");
builder.append(doi_url);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,98 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped;
import java.io.Serializable;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.ZenodoLicense;
/**
* A license bean like the ckan's one.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 13, 2020
*/
public class LicenseBean implements Serializable, ZenodoLicense{
/**
*
*/
private static final long serialVersionUID = 6618784269251750489L;
private String id;
private String title;
private String url;
/**
* Instantiates a new license bean.
*/
public LicenseBean() {
super();
}
/**
* Instantiates a new license bean.
*
* @param id the id
* @param title the title
* @param url the url
*/
public LicenseBean(String id, String title, String url) {
super();
this.id = id;
this.title = title;
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
return obj.getClass().equals(this.getClass()) && ((LicenseBean)obj).getTitle().equals(this.title);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("LicenseBean [id=");
builder.append(id);
builder.append(", title=");
builder.append(title);
builder.append(", url=");
builder.append(url);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,71 +0,0 @@
//package org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped;
//
//import java.io.Serializable;
//
///**
// * A license bean like the ckan's one.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
// *
// * Jan 13, 2020
// */
//public class LicenseDTO implements Serializable {
//
// /**
// *
// */
// private static final long serialVersionUID = 8796338619448833841L;
// private String id;
// private String title;
// private String url;
//
// /**
// * Instantiates a new license bean.
// */
// public LicenseDTO() {
// }
//
// public LicenseDTO(String id, String title, String url) {
// this.id = id;
// this.title = title;
// this.url = url;
// }
//
// public String getId() {
// return id;
// }
//
// public String getTitle() {
// return title;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public void setTitle(String title) {
// this.title = title;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("LicenseDTO [id=");
// builder.append(id);
// builder.append(", title=");
// builder.append(title);
// builder.append(", url=");
// builder.append(url);
// builder.append("]");
// return builder.toString();
// }
//
//}

View File

@ -10,9 +10,6 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum;
* Jan 15, 2020
*/
public interface ZenodoAuthor {
public static final String USER_ROLE = "Author";
/**
* Gets the name.

View File

@ -1,7 +1,5 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped;
import java.io.Serializable;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum;
@ -12,7 +10,7 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum;
*
* Jan 15, 2020
*/
public class ZenodoContributor extends ZenodoCreator implements Serializable {
public class ZenodoContributor extends ZenodoCreator{
/**
*
@ -21,8 +19,6 @@ public class ZenodoContributor extends ZenodoCreator implements Serializable {
private SerializableEnum<String> type;
public static final String USER_ROLE = "Contributor";
/**
* Instantiates a new zenodo contributor.
*/

View File

@ -23,8 +23,6 @@ public class ZenodoCreator implements ZenodoAuthor, Serializable{
private String affiliation;
private String orcid;
private String gnd;
public static final String USER_ROLE = "Creator";
/**
* Instantiates a new zenodo creator.

View File

@ -28,7 +28,7 @@ public class ZenodoDateInterval implements Serializable {
/**
* Instantiates a new zenodo date interval.
*/
public ZenodoDateInterval() {
ZenodoDateInterval() {
}
/**

View File

@ -1,34 +0,0 @@
//package org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped;
//
//
///**
// * The Interface ZenodoLicense.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
// *
// * Jan 21, 2020
// */
//public interface ZenodoLicense {
//
// /**
// * Gets the id.
// *
// * @return the id
// */
// String getId();
//
// /**
// * Gets the title.
// *
// * @return the title
// */
// String getTitle();
//
// /**
// * Gets the url.
// *
// * @return the url
// */
// String getUrl();
//
//}

View File

@ -6,38 +6,36 @@ import java.util.List;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum;
/**
* The Class ZenodoMetadata.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 20, 2020
* Jan 20, 2020
*/
public class ZenodoMetadata implements Serializable {
public class ZenodoMetadata implements Serializable{
/**
*
*/
private static final long serialVersionUID = -1885238190029199362L;
private SerializableEnum<String> upload_type;
private SerializableEnum<String> publication_type;
private SerializableEnum<String> image_type;
// to manage empty list or null contributors
private SerializableEnum<String> contributorsTypes;
private SerializableEnum<String> publication_type;
private SerializableEnum<String> image_type;
private Date publication_date;
private String title;
private List<ZenodoCreator> creators;
private List<ZenodoContributor> contributors;
private List<ZenodoCreator> thesis_supervisors;
private String description; // TODO HTML
private SerializableEnum<String> access_right;
private Date embargo_date;
@ -46,9 +44,9 @@ public class ZenodoMetadata implements Serializable {
private Boolean preserve_doi;
private List<String> keywords;
private String notes; // TODO HTML
private List<ZenodoRelatedIdentifier> related_identifiers;
private List<String> references;
private List<ZenodoCommunity> communities;
private List<ZenodoGrant> grants;
@ -72,20 +70,19 @@ public class ZenodoMetadata implements Serializable {
private String thesis_university;
private List<ZenodoSubject> subjects;
private String version;
private String language; // https://www.loc.gov/standards/iso639-2/php/code_list.php
private String language; //https://www.loc.gov/standards/iso639-2/php/code_list.php
private List<ZenodoLocation> locations;
private List<ZenodoDateInterval> dates;
private String method; // TODO html
// private SerializableEnum<String> licenseIDs;
private List<String> licenseIDs;
private String method; //TODO html
private SerializableEnum<LicenseBean> licenses;
/**
* Instantiates a new zenodo metadata.
*/
public ZenodoMetadata() {
}
public ZenodoMetadata(){}
/**
* Gets the upload type.
@ -96,6 +93,7 @@ public class ZenodoMetadata implements Serializable {
return upload_type;
}
/**
* Sets the upload type.
*
@ -105,23 +103,6 @@ public class ZenodoMetadata implements Serializable {
this.upload_type = upload_type;
}
/**
* Gets the contributors types.
*
* @return the contributors types
*/
public SerializableEnum<String> getContributorsTypes() {
return contributorsTypes;
}
/**
* Sets the contributors types.
*
* @param contributorsTypes the new contributors types
*/
public void setContributorsTypes(SerializableEnum<String> contributorsTypes) {
this.contributorsTypes = contributorsTypes;
}
/**
* Gets the publication type.
@ -132,6 +113,7 @@ public class ZenodoMetadata implements Serializable {
return publication_type;
}
/**
* Sets the publication type.
*
@ -141,6 +123,7 @@ public class ZenodoMetadata implements Serializable {
this.publication_type = publication_type;
}
/**
* Gets the image type.
*
@ -150,6 +133,7 @@ public class ZenodoMetadata implements Serializable {
return image_type;
}
/**
* Sets the image type.
*
@ -159,6 +143,7 @@ public class ZenodoMetadata implements Serializable {
this.image_type = image_type;
}
/**
* Gets the publication date.
*
@ -168,6 +153,7 @@ public class ZenodoMetadata implements Serializable {
return publication_date;
}
/**
* Sets the publication date.
*
@ -177,6 +163,7 @@ public class ZenodoMetadata implements Serializable {
this.publication_date = publication_date;
}
/**
* Gets the title.
*
@ -186,6 +173,7 @@ public class ZenodoMetadata implements Serializable {
return title;
}
/**
* Sets the title.
*
@ -195,6 +183,7 @@ public class ZenodoMetadata implements Serializable {
this.title = title;
}
/**
* Gets the creators.
*
@ -204,6 +193,7 @@ public class ZenodoMetadata implements Serializable {
return creators;
}
/**
* Sets the creators.
*
@ -213,6 +203,7 @@ public class ZenodoMetadata implements Serializable {
this.creators = creators;
}
/**
* Gets the description.
*
@ -222,6 +213,7 @@ public class ZenodoMetadata implements Serializable {
return description;
}
/**
* Sets the description.
*
@ -231,6 +223,7 @@ public class ZenodoMetadata implements Serializable {
this.description = description;
}
/**
* Gets the access right.
*
@ -240,6 +233,7 @@ public class ZenodoMetadata implements Serializable {
return access_right;
}
/**
* Sets the access right.
*
@ -249,6 +243,7 @@ public class ZenodoMetadata implements Serializable {
this.access_right = access_right;
}
/**
* Gets the embargo date.
*
@ -258,6 +253,7 @@ public class ZenodoMetadata implements Serializable {
return embargo_date;
}
/**
* Sets the embargo date.
*
@ -267,6 +263,7 @@ public class ZenodoMetadata implements Serializable {
this.embargo_date = embargo_date;
}
/**
* Gets the access conditions.
*
@ -276,6 +273,7 @@ public class ZenodoMetadata implements Serializable {
return access_conditions;
}
/**
* Sets the access conditions.
*
@ -285,6 +283,7 @@ public class ZenodoMetadata implements Serializable {
this.access_conditions = access_conditions;
}
/**
* Gets the doi.
*
@ -294,6 +293,7 @@ public class ZenodoMetadata implements Serializable {
return doi;
}
/**
* Sets the doi.
*
@ -303,6 +303,7 @@ public class ZenodoMetadata implements Serializable {
this.doi = doi;
}
/**
* Gets the preserve doi.
*
@ -312,6 +313,7 @@ public class ZenodoMetadata implements Serializable {
return preserve_doi;
}
/**
* Sets the preserve doi.
*
@ -321,6 +323,7 @@ public class ZenodoMetadata implements Serializable {
this.preserve_doi = preserve_doi;
}
/**
* Gets the keywords.
*
@ -330,6 +333,7 @@ public class ZenodoMetadata implements Serializable {
return keywords;
}
/**
* Sets the keywords.
*
@ -339,6 +343,7 @@ public class ZenodoMetadata implements Serializable {
this.keywords = keywords;
}
/**
* Gets the notes.
*
@ -348,6 +353,7 @@ public class ZenodoMetadata implements Serializable {
return notes;
}
/**
* Sets the notes.
*
@ -357,6 +363,7 @@ public class ZenodoMetadata implements Serializable {
this.notes = notes;
}
/**
* Gets the related identifiers.
*
@ -366,6 +373,7 @@ public class ZenodoMetadata implements Serializable {
return related_identifiers;
}
/**
* Sets the related identifiers.
*
@ -375,6 +383,7 @@ public class ZenodoMetadata implements Serializable {
this.related_identifiers = related_identifiers;
}
/**
* Gets the contributors.
*
@ -384,6 +393,7 @@ public class ZenodoMetadata implements Serializable {
return contributors;
}
/**
* Sets the contributors.
*
@ -393,6 +403,7 @@ public class ZenodoMetadata implements Serializable {
this.contributors = contributors;
}
/**
* Gets the references.
*
@ -402,6 +413,7 @@ public class ZenodoMetadata implements Serializable {
return references;
}
/**
* Sets the references.
*
@ -411,6 +423,7 @@ public class ZenodoMetadata implements Serializable {
this.references = references;
}
/**
* Gets the communities.
*
@ -420,6 +433,7 @@ public class ZenodoMetadata implements Serializable {
return communities;
}
/**
* Sets the communities.
*
@ -429,6 +443,7 @@ public class ZenodoMetadata implements Serializable {
this.communities = communities;
}
/**
* Gets the grants.
*
@ -438,6 +453,7 @@ public class ZenodoMetadata implements Serializable {
return grants;
}
/**
* Sets the grants.
*
@ -447,6 +463,7 @@ public class ZenodoMetadata implements Serializable {
this.grants = grants;
}
/**
* Gets the journal title.
*
@ -456,6 +473,7 @@ public class ZenodoMetadata implements Serializable {
return journal_title;
}
/**
* Sets the journal title.
*
@ -465,6 +483,7 @@ public class ZenodoMetadata implements Serializable {
this.journal_title = journal_title;
}
/**
* Gets the journal volume.
*
@ -474,6 +493,7 @@ public class ZenodoMetadata implements Serializable {
return journal_volume;
}
/**
* Sets the journal volume.
*
@ -483,6 +503,7 @@ public class ZenodoMetadata implements Serializable {
this.journal_volume = journal_volume;
}
/**
* Gets the journal issue.
*
@ -492,6 +513,7 @@ public class ZenodoMetadata implements Serializable {
return journal_issue;
}
/**
* Sets the journal issue.
*
@ -501,6 +523,7 @@ public class ZenodoMetadata implements Serializable {
this.journal_issue = journal_issue;
}
/**
* Gets the journal pages.
*
@ -510,6 +533,7 @@ public class ZenodoMetadata implements Serializable {
return journal_pages;
}
/**
* Sets the journal pages.
*
@ -519,6 +543,7 @@ public class ZenodoMetadata implements Serializable {
this.journal_pages = journal_pages;
}
/**
* Gets the conference title.
*
@ -528,6 +553,7 @@ public class ZenodoMetadata implements Serializable {
return conference_title;
}
/**
* Sets the conference title.
*
@ -537,6 +563,7 @@ public class ZenodoMetadata implements Serializable {
this.conference_title = conference_title;
}
/**
* Gets the conference acronym.
*
@ -546,6 +573,7 @@ public class ZenodoMetadata implements Serializable {
return conference_acronym;
}
/**
* Sets the conference acronym.
*
@ -555,6 +583,7 @@ public class ZenodoMetadata implements Serializable {
this.conference_acronym = conference_acronym;
}
/**
* Gets the conference dates.
*
@ -564,6 +593,7 @@ public class ZenodoMetadata implements Serializable {
return conference_dates;
}
/**
* Sets the conference dates.
*
@ -573,6 +603,7 @@ public class ZenodoMetadata implements Serializable {
this.conference_dates = conference_dates;
}
/**
* Gets the conference place.
*
@ -582,6 +613,7 @@ public class ZenodoMetadata implements Serializable {
return conference_place;
}
/**
* Sets the conference place.
*
@ -591,6 +623,7 @@ public class ZenodoMetadata implements Serializable {
this.conference_place = conference_place;
}
/**
* Gets the conference url.
*
@ -600,6 +633,7 @@ public class ZenodoMetadata implements Serializable {
return conference_url;
}
/**
* Sets the conference url.
*
@ -609,6 +643,7 @@ public class ZenodoMetadata implements Serializable {
this.conference_url = conference_url;
}
/**
* Gets the conference session.
*
@ -618,6 +653,7 @@ public class ZenodoMetadata implements Serializable {
return conference_session;
}
/**
* Sets the conference session.
*
@ -627,6 +663,7 @@ public class ZenodoMetadata implements Serializable {
this.conference_session = conference_session;
}
/**
* Gets the conference session part.
*
@ -636,6 +673,7 @@ public class ZenodoMetadata implements Serializable {
return conference_session_part;
}
/**
* Sets the conference session part.
*
@ -645,6 +683,7 @@ public class ZenodoMetadata implements Serializable {
this.conference_session_part = conference_session_part;
}
/**
* Gets the imprint publisher.
*
@ -654,6 +693,7 @@ public class ZenodoMetadata implements Serializable {
return imprint_publisher;
}
/**
* Sets the imprint publisher.
*
@ -663,6 +703,7 @@ public class ZenodoMetadata implements Serializable {
this.imprint_publisher = imprint_publisher;
}
/**
* Gets the imprint isbn.
*
@ -672,6 +713,7 @@ public class ZenodoMetadata implements Serializable {
return imprint_isbn;
}
/**
* Sets the imprint isbn.
*
@ -681,6 +723,7 @@ public class ZenodoMetadata implements Serializable {
this.imprint_isbn = imprint_isbn;
}
/**
* Gets the imprint place.
*
@ -690,6 +733,7 @@ public class ZenodoMetadata implements Serializable {
return imprint_place;
}
/**
* Sets the imprint place.
*
@ -699,6 +743,7 @@ public class ZenodoMetadata implements Serializable {
this.imprint_place = imprint_place;
}
/**
* Gets the partof title.
*
@ -708,6 +753,7 @@ public class ZenodoMetadata implements Serializable {
return partof_title;
}
/**
* Sets the partof title.
*
@ -717,6 +763,7 @@ public class ZenodoMetadata implements Serializable {
this.partof_title = partof_title;
}
/**
* Gets the partof pages.
*
@ -726,6 +773,7 @@ public class ZenodoMetadata implements Serializable {
return partof_pages;
}
/**
* Sets the partof pages.
*
@ -735,6 +783,7 @@ public class ZenodoMetadata implements Serializable {
this.partof_pages = partof_pages;
}
/**
* Gets the thesis supervisors.
*
@ -744,6 +793,7 @@ public class ZenodoMetadata implements Serializable {
return thesis_supervisors;
}
/**
* Sets the thesis supervisors.
*
@ -753,6 +803,7 @@ public class ZenodoMetadata implements Serializable {
this.thesis_supervisors = thesis_supervisors;
}
/**
* Gets the thesis university.
*
@ -762,6 +813,7 @@ public class ZenodoMetadata implements Serializable {
return thesis_university;
}
/**
* Sets the thesis university.
*
@ -771,6 +823,7 @@ public class ZenodoMetadata implements Serializable {
this.thesis_university = thesis_university;
}
/**
* Gets the subjects.
*
@ -780,6 +833,7 @@ public class ZenodoMetadata implements Serializable {
return subjects;
}
/**
* Sets the subjects.
*
@ -789,6 +843,7 @@ public class ZenodoMetadata implements Serializable {
this.subjects = subjects;
}
/**
* Gets the version.
*
@ -798,6 +853,7 @@ public class ZenodoMetadata implements Serializable {
return version;
}
/**
* Sets the version.
*
@ -807,6 +863,7 @@ public class ZenodoMetadata implements Serializable {
this.version = version;
}
/**
* Gets the language.
*
@ -816,6 +873,7 @@ public class ZenodoMetadata implements Serializable {
return language;
}
/**
* Sets the language.
*
@ -825,6 +883,7 @@ public class ZenodoMetadata implements Serializable {
this.language = language;
}
/**
* Gets the locations.
*
@ -834,6 +893,7 @@ public class ZenodoMetadata implements Serializable {
return locations;
}
/**
* Sets the locations.
*
@ -843,6 +903,7 @@ public class ZenodoMetadata implements Serializable {
this.locations = locations;
}
/**
* Gets the dates.
*
@ -852,6 +913,7 @@ public class ZenodoMetadata implements Serializable {
return dates;
}
/**
* Sets the dates.
*
@ -861,6 +923,7 @@ public class ZenodoMetadata implements Serializable {
this.dates = dates;
}
/**
* Gets the method.
*
@ -870,6 +933,7 @@ public class ZenodoMetadata implements Serializable {
return method;
}
/**
* Sets the method.
*
@ -878,30 +942,26 @@ public class ZenodoMetadata implements Serializable {
public void setMethod(String method) {
this.method = method;
}
/**
* Sets the license IDs.
* Sets the licenses.
*
* @param licensesIDs the new license IDs
* @param licenses the new licenses
*/
public void setLicenseIDs(List<String> licensesIDs) {
this.licenseIDs = licensesIDs;
public void setLicenses(SerializableEnum<LicenseBean> licenses) {
this.licenses = licenses;
}
/**
* Gets the licenses.
*
* @return the licenses
*/
public SerializableEnum<LicenseBean> getLicenses() {
return licenses;
}
/**
* Gets the license IDs.
*
* @return the license IDs
*/
public List<String> getLicenseIDs() {
return licenseIDs;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -991,10 +1051,10 @@ public class ZenodoMetadata implements Serializable {
builder.append(dates);
builder.append(", method=");
builder.append(method);
builder.append(", licenseIDs=");
builder.append(licenseIDs);
builder.append(", licenses=");
builder.append(licenses);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,102 +1,20 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
import java.time.Instant;
import java.util.Date;
import javax.ws.rs.client.Entity;
import org.gcube.data.publishing.ckan2zenodo.Fixer;
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata;
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Tester {
public static String expression = "^\\/dataset(\\?([a-zA-Z0-9_.-]*.+))*";
public static String toMatch = "/dataset?systemtype=E39_Actor&groups=huma_num___nakala";
private static ObjectMapper mapper = new ObjectMapper();
static {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
mapper.setSerializationInclusion(Include.NON_NULL);
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
// public static void main(String[] args) {
// Pattern p = Pattern.compile(expression);
// Matcher m = p.matcher(toMatch);
// boolean b = m.matches();
//
// System.out.println(b);
//
// }
public static void main(String[] args) {
Pattern p = Pattern.compile(expression);
Matcher m = p.matcher(toMatch);
boolean b = m.matches();
//ObjectMapper mapper = new ObjectMapper();
ZenodoDeposition zed = new ZenodoDeposition();
DepositionMetadata metadata = new DepositionMetadata();
metadata.setPublication_date(Date.from(Instant.now()));
//zed.setMetadata(metadata);
String serialized;
try {
System.out.println("init json: "+mapper.writeValueAsString(metadata));
serialized = "{\"metadata\":"+Fixer.fixIncoming(mapper.writeValueAsString(metadata))+"}";
System.out.println("serialized: "+serialized);
Entity<String> JSON = Entity.json(serialized);
System.out.println("JSON: "+JSON);
ZenodoDeposition object = mapper.readValue(Fixer.fixIncoming(serialized), ZenodoDeposition.class);
System.out.println("ZenodoDeposition: "+object);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(metadata.getPublication_date());
// try {
// updateMetadata(metadata);
// } catch (ZenodoException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
private static ZenodoDeposition updateMetadata(DepositionMetadata meta) throws ZenodoException {
try{
String serialized="{\"metadata\":"+Fixer.fixIncoming(mapper.writeValueAsString(meta))+"}";
System.out.println("serialized: "+serialized);
try {
// Response resp = getWebClient().target(credentials.getBaseUrl()).
// path(DEPOSITION_BASE_URL).path(depositionId+"").
// queryParam(ACCESS_TOKEN, credentials.getKey()).request(CONTENT_TYPE)
// .put(Entity.json(serialized));
// return check(resp,ZenodoDeposition.class);
Entity<String> JSON = Entity.json(serialized);
System.out.println("JSON: "+JSON);
return mapper.readValue(Fixer.fixIncoming(serialized), ZenodoDeposition.class);
}catch(Throwable t) {
System.out.println("Error while tryin to update "+serialized);
return null;
}
}catch(JsonProcessingException e) {
System.out.println("Error while parsing "+meta + " " +e);
throw new ZenodoException("Internal error.",e);
}
System.out.println(b);
}
}