diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorView.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorView.java index 14e25ed..f641e9e 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorView.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorView.java @@ -91,14 +91,16 @@ public class CreatorView extends Composite { if(this.userRole!=null) { field_cl_author.add(new HTML("* "+userRole)); + remove_author.setText("Remove "+userRole); }else { //default role is Author field_cl_author.add(new HTML("* Author")); + remove_author.setText("Remove Author"); } if(this.author!=null) { - setField_name(InfoTextAndLabels.validValue(author.getName())); - setField_affiliation(InfoTextAndLabels.validValue(author.getAffiliation())); - setField_orcid(InfoTextAndLabels.validValue(author.getOrcid())); + setField_name(InfoTextAndLabels.validValue(this.author.getName())); + setField_affiliation(InfoTextAndLabels.validValue(this.author.getAffiliation())); + setField_orcid(InfoTextAndLabels.validValue(this.author.getOrcid())); if(this.author.getType()!=null) { controls_author_type.setVisible(true); @@ -106,6 +108,8 @@ public class CreatorView extends Composite { FieldUtil.selectValueToListBox(field_author_type, Arrays.asList(this.author.getType().getSelectedValues().get(0))); } } + + GWT.log("Created creator view with author: "+this.author); } @@ -120,7 +124,6 @@ public class CreatorView extends Composite { this(author, userRole); this.eventBus = eventBus; - remove_author.addClickHandler(new ClickHandler() { @Override @@ -220,5 +223,25 @@ public class CreatorView extends Composite { public ZenodoAuthor getAuthor() { return author; } + + public ListBox getField_author_type() { + return field_author_type; + } + + + /** + * Gets the author type value. + * + * @return the author type value + */ + public String getAuthorTypeValue(){ + + String authorTypeSelected = null; + if(controls_author_type.isVisible()) { + authorTypeSelected = field_author_type.getValue(); + } + return authorTypeSelected; + + } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorsFormView.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorsFormView.java index 61287df..ef8f818 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorsFormView.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorsFormView.java @@ -1,11 +1,11 @@ package org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.authors; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.gcube.portlets.widgets.ckan2zenodopublisher.client.events.RemoveCreatorEvent; import org.gcube.portlets.widgets.ckan2zenodopublisher.client.events.RemoveCreatorEventHandler; -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.client.view.FormValidator; import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum; @@ -112,11 +112,10 @@ public class CreatorsFormView extends Composite implements FormValidator{ userRole = "Author"; for (ZenodoAuthor creator : listAuthors) { - GWT.log("author is "+creator.getClass()); + GWT.log("Author class is "+creator.getClass()); if (creator instanceof ZenodoContributor) { - GWT.log("author is a ZenodoContributor"); userRole = "Contributor"; - contributorTypeValues = creator.getType(); + contributorTypeValues = new SerializableEnum(Arrays.asList(creator.getType().getSelectableValues().get(0)), creator.getType().getSelectableValues()); }else if(creator instanceof ZenodoCreator) { userRole = "Creator"; } @@ -190,9 +189,15 @@ public class CreatorsFormView extends Composite implements FormValidator{ for (CreatorView creatorView : listCreatorView) { ZenodoAuthor author = creatorView.getAuthor(); + GWT.log("Read ZenodoAuthor: "+author); 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); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/basicinformation/BasicInformationView.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/basicinformation/BasicInformationView.java index 69fd331..e79c98d 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/basicinformation/BasicInformationView.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/basicinformation/BasicInformationView.java @@ -210,9 +210,11 @@ public class BasicInformationView extends Composite implements FormValidator { listOfContributorsView = new ArrayList(); // ADDING AUTHORS + GWT.log("Adding creators: "+zenodoItem.getMetadata().getCreators()); CreatorsFormView authorView = new CreatorsFormView(zenodoItem.getMetadata().getCreators()); listOfCreatorsView.add(authorView); + GWT.log("Adding contributors: "+zenodoItem.getMetadata().getContributors()); CreatorsFormView contributorView = new CreatorsFormView(zenodoItem.getMetadata().getContributors()); listOfContributorsView.add(contributorView); diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/view/Ckan2ZenodoViewManager.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/view/Ckan2ZenodoViewManager.java index 5ea8176..0c1be89 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/view/Ckan2ZenodoViewManager.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/view/Ckan2ZenodoViewManager.java @@ -124,9 +124,11 @@ public class Ckan2ZenodoViewManager { meta.setKeywords(basicForm.getTags()); // these are the keywords List creators = basicForm.getListOfCreators(); + GWT.log("Read creators from FORM: "+creators); meta.setCreators(creators); List contributors = basicForm.getListOfContributors(); + GWT.log("Read contributors from FORM: "+contributors); meta.setContributors(contributors); // upload type diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/CkanToZenodoPublisherServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/CkanToZenodoPublisherServiceImpl.java index 71a9729..b5b1d15 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/CkanToZenodoPublisherServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/CkanToZenodoPublisherServiceImpl.java @@ -85,7 +85,7 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple //Actually publish to zenodo : // Step 1 : metadata - Ckan2Zenodo client= new Ckan2ZenodoImpl(); + /*Ckan2Zenodo client= new Ckan2ZenodoImpl(); zenodoDepositionPreview = client.updatedMetadata(zenodoDepositionPreview); //Step 2 : publish Resources @@ -98,19 +98,19 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple } zenodoDepositionPreview = future_Dep.get(180,TimeUnit.SECONDS); } + // Get the item representation CkanItemDescriptor item=client.read(zenodoItem.getName()); - //Finalize - client.publish(zenodoDepositionPreview, item); + client.publish(zenodoDepositionPreview, item);*/ return zenodoDepositionPreview.toString(); - }catch (TimeoutException e) { +/* }catch (TimeoutException e) { String error = "I'm waiting too time for publishing on Zenodo the catalogue item: "+zenodoItem.getName()+". Check by yourself the result later"; LOG.error(error, e); String clientError = String.format("%s", error); throw new Exception(clientError); - +*/ } catch (Exception e) { String error = "Error when publishing on Zenodo the catalogue item: "+zenodoItem.getName(); LOG.error(error, e); diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/converter/ItemToZenodoConverter.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/converter/ItemToZenodoConverter.java index 564aa11..6ec436c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/converter/ItemToZenodoConverter.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/server/converter/ItemToZenodoConverter.java @@ -6,6 +6,7 @@ import java.util.List; import org.gcube.data.publishing.ckan2zenodo.model.CkanResource; import org.gcube.data.publishing.ckan2zenodo.model.zenodo.Community; import org.gcube.data.publishing.ckan2zenodo.model.zenodo.Contributor; +import org.gcube.data.publishing.ckan2zenodo.model.zenodo.Contributor.Type; import org.gcube.data.publishing.ckan2zenodo.model.zenodo.Creator; import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DateInterval; import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata; @@ -20,6 +21,7 @@ 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; import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoCreator; @@ -438,14 +440,99 @@ public class ItemToZenodoConverter { LOG.debug("Read publication type: "+publicationType); if(publicationType!=null) { String thePublicationTypeValue = publicationType.getSelectedValues().get(0); + LOG.debug("Set publication type: "+thePublicationTypeValue); depositionMetadata.setPublication_type(PublicationType.valueOf(thePublicationTypeValue)); } + //creators + List creators = null; + List zenodoCreators = metadata.getCreators(); + LOG.debug("Read Creators: "+zenodoCreators); + if(zenodoCreators!=null) { + creators = toCreators(zenodoCreators); + } + LOG.debug("Set Creators: "+creators); + depositionMetadata.setCreators(creators); + + //contributors + List contributors = null; + List zenodoContributors = metadata.getContributors(); + LOG.debug("Read Contributors: "+zenodoContributors); + if(zenodoContributors!=null) { + contributors = toContributors(zenodoContributors); + } + + if(LOG.isDebugEnabled()) { + for (Contributor contributor : contributors) { + LOG.debug("Set contributor: name "+contributor.getName() + " type "+contributor.getType()); + } + } + + depositionMetadata.setContributors(contributors); + //keywords depositionMetadata.setKeywords(metadata.getKeywords()); return depositionMetadata; } + + + /** + * To creators. + * + * @param zenodoCreators the zenodo creators + * @return the list + */ + public static List toCreators(List zenodoCreators){ + + if(zenodoCreators==null) + return null; + + List listOfCreators = new ArrayList<>(zenodoCreators.size()); + for (ZenodoAuthor zenodoAuthor : zenodoCreators) { + Creator creator = new Creator(); + creator.setName(zenodoAuthor.getName()); + creator.setAffiliation(zenodoAuthor.getAffiliation()); + creator.setGnd(zenodoAuthor.getGnd()); + creator.setOrcid(zenodoAuthor.getOrcid()); + listOfCreators.add(creator); + } + + return listOfCreators; + } + + /** + * To contributors. + * + * @param zenodoContributors the zenodo contributors + * @return the list + */ + public static List toContributors(List zenodoContributors){ + + if(zenodoContributors==null) + return null; + + List listOfContributors = new ArrayList(zenodoContributors.size()); + for (ZenodoAuthor zenodoAuthor : zenodoContributors) { + Contributor contributor = new Contributor(); + contributor.setName(zenodoAuthor.getName()); + contributor.setAffiliation(zenodoAuthor.getAffiliation()); + contributor.setGnd(zenodoAuthor.getGnd()); + contributor.setOrcid(zenodoAuthor.getOrcid()); + Type type = null; + String theType = null; + try { + theType = zenodoAuthor.getType().getSelectedValues().get(0); + type = Type.valueOf(theType); + }catch (Exception e) { + LOG.error("No able to convert "+theType + " as value of "+Type.class.getName()); + } + contributor.setType(type); + listOfContributors.add(contributor); + } + + return listOfContributors; + } diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoAuthor.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoAuthor.java index c0f1001..e509b62 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoAuthor.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoAuthor.java @@ -45,6 +45,14 @@ public interface ZenodoAuthor { * @return the type */ public SerializableEnum getType(); + + + /** + * Sets the type. + * + * @param type the new type + */ + public void setType(SerializableEnum type); /** * Sets the name. diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoContributor.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoContributor.java index efb4b5f..3bc6fcf 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoContributor.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoContributor.java @@ -57,14 +57,13 @@ public class ZenodoContributor extends ZenodoCreator{ } - /* (non-Javadoc) - * @see org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoCreator#toString() - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ZenodoContributor [type="); builder.append(type); + builder.append(", toString()="); + builder.append(super.toString()); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoCreator.java b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoCreator.java index 58e930d..d26bcf9 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoCreator.java +++ b/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/shared/wrapped/ZenodoCreator.java @@ -119,6 +119,11 @@ public class ZenodoCreator implements ZenodoAuthor, Serializable{ public SerializableEnum getType() { return null; } + + @Override + public void setType(SerializableEnum type) { + //empty + } /* (non-Javadoc) * @see java.lang.Object#toString()