Added enum of contributor types to manage fallback on empty list or null

contributors from mapping
This commit is contained in:
Francesco Mangiacrapa 2021-04-26 12:04:32 +02:00
parent 837eaa7dba
commit be5c8d800f
8 changed files with 90 additions and 133 deletions

View File

@ -1,11 +1,14 @@
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;
@ -110,16 +113,26 @@ public class CreatorView extends Composite {
if(this.author.getType()!=null) {
controls_author_type.setVisible(true);
FieldUtil.addValuesToListBox(field_author_type, this.author.getType().getSelectableValues());
FieldUtil.selectValueToListBox(field_author_type, Arrays.asList(this.author.getType().getSelectedValues().get(0)));
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);
}
}
if(this.userRole!=null) {
String userRoleToLowerCase = userRole.toLowerCase();
if(userRoleToLowerCase.startsWith("creator")) {
if(userRoleToLowerCase.startsWith(ZenodoCreator.USER_ROLE.toLowerCase())) {
InfoTextAndLabels.addTooltipForFieldKey("creators", field_cl_author);
}else if(userRoleToLowerCase.startsWith("contributor")) {
}else if(userRoleToLowerCase.startsWith(ZenodoContributor.USER_ROLE.toLowerCase())) {
InfoTextAndLabels.addTooltipForFieldKey("contributors", field_cl_author);
}else {
InfoTextAndLabels.addTooltipForFieldKey("authors", field_cl_author);

View File

@ -73,10 +73,11 @@ public class CreatorsFormView extends Composite implements FormValidator{
*
* @param listAuthors the list authors
*/
public CreatorsFormView(List<? extends ZenodoAuthor> listAuthors, Class theAuthorType) {
public CreatorsFormView(List<? extends ZenodoAuthor> listAuthors, Class theAuthorType, SerializableEnum<String> contributorTypeValues) {
initWidget(uiBinder.createAndBindUi(this));
this.listAuthors = listAuthors;
this.theAuthorType = theAuthorType;
this.contributorTypeValues = contributorTypeValues;
button_add_author.addClickHandler(new ClickHandler() {
@ -115,15 +116,16 @@ public class CreatorsFormView extends Composite implements FormValidator{
listCreatorView = new ArrayList<CreatorView>();
if(listAuthors!=null && listAuthors.size()>0) {
userRole = "Author";
userRole = ZenodoAuthor.USER_ROLE;
for (ZenodoAuthor creator : listAuthors) {
GWT.log("Author class is "+creator.getClass());
if (creator instanceof ZenodoContributor) {
userRole = "Contributor";
userRole = ZenodoContributor.USER_ROLE;
//overriding contributors types as defined into mapping
contributorTypeValues = new SerializableEnum<String>(Arrays.asList(creator.getType().getSelectableValues().get(0)), creator.getType().getSelectableValues());
}else if(creator instanceof ZenodoCreator) {
userRole = "Creator";
userRole = ZenodoCreator.USER_ROLE;
}
CreatorView view = new CreatorView(creator, userRole, eventBus, true);
listCreatorView.add(view);
@ -162,22 +164,20 @@ public class CreatorsFormView extends Composite implements FormValidator{
if(userRole == null) {
if (theAuthorType.equals(ZenodoCreator.class)) {
userRole = "Creator";
userRole = ZenodoCreator.USER_ROLE;
}else if(theAuthorType.equals(ZenodoContributor.class)) {
userRole = "Contributor";
userRole = ZenodoContributor.USER_ROLE;
}else
userRole = "Creator";
userRole = ZenodoCreator.USER_ROLE;
GWT.log("Empty list assigned the userRole: "+userRole);
}else {
//dead code???
if(userRole.compareToIgnoreCase("Contributor")==0) {
author = new ZenodoContributor();
((ZenodoContributor) author).setType(contributorTypeValues);
}
}
if(userRole.compareToIgnoreCase(ZenodoContributor.USER_ROLE)==0) {
author = new ZenodoContributor();
((ZenodoContributor) author).setType(contributorTypeValues);
}
CreatorView view = new CreatorView(author, userRole, eventBus,false);
listCreatorView.add(view);
fieldset_authors.add(view);

View File

@ -360,15 +360,24 @@ public class BasicInformationView extends Composite implements FormValidator {
listOfContributorsView = new ArrayList<CreatorsFormView>();
// ADDING AUTHORS
List<? extends ZenodoAuthor> authors = zenodoItem.getMetadata().getCreators();
GWT.log("Adding creators: " + authors);
CreatorsFormView authorView = new CreatorsFormView(authors, ZenodoCreator.class);
listOfCreatorsView.add(authorView);
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();
}
List<? extends ZenodoAuthor> contributors = zenodoItem.getMetadata().getContributors();
GWT.log("Adding contributors: " + contributors);
CreatorsFormView contributorView = new CreatorsFormView(contributors, ZenodoContributor.class);
listOfContributorsView.add(contributorView);
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();
}
for (CreatorsFormView cfv : listOfCreatorsView) {
fieldset_basic_informations.add(cfv);

View File

@ -254,7 +254,12 @@ 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());

View File

@ -10,6 +10,9 @@ 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

@ -19,6 +19,8 @@ public class ZenodoContributor extends ZenodoCreator{
private SerializableEnum<String> type;
public static final String USER_ROLE = "Contributor";
/**
* Instantiates a new zenodo contributor.
*/

View File

@ -23,6 +23,8 @@ 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

@ -6,36 +6,38 @@ 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;
private SerializableEnum<String> publication_type;
private SerializableEnum<String> image_type;
// to manage empty list or null contributors
private SerializableEnum<String> contributorsTypes;
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;
@ -44,9 +46,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;
@ -70,19 +72,18 @@ 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 String method; // TODO html
private SerializableEnum<LicenseBean> licenses;
/**
* Instantiates a new zenodo metadata.
*/
public ZenodoMetadata(){}
public ZenodoMetadata() {
}
/**
* Gets the upload type.
@ -93,7 +94,6 @@ public class ZenodoMetadata implements Serializable{
return upload_type;
}
/**
* Sets the upload type.
*
@ -103,6 +103,13 @@ public class ZenodoMetadata implements Serializable{
this.upload_type = upload_type;
}
public SerializableEnum<String> getContributorsTypes() {
return contributorsTypes;
}
public void setContributorsTypes(SerializableEnum<String> contributorsTypes) {
this.contributorsTypes = contributorsTypes;
}
/**
* Gets the publication type.
@ -113,7 +120,6 @@ public class ZenodoMetadata implements Serializable{
return publication_type;
}
/**
* Sets the publication type.
*
@ -123,7 +129,6 @@ public class ZenodoMetadata implements Serializable{
this.publication_type = publication_type;
}
/**
* Gets the image type.
*
@ -133,7 +138,6 @@ public class ZenodoMetadata implements Serializable{
return image_type;
}
/**
* Sets the image type.
*
@ -143,7 +147,6 @@ public class ZenodoMetadata implements Serializable{
this.image_type = image_type;
}
/**
* Gets the publication date.
*
@ -153,7 +156,6 @@ public class ZenodoMetadata implements Serializable{
return publication_date;
}
/**
* Sets the publication date.
*
@ -163,7 +165,6 @@ public class ZenodoMetadata implements Serializable{
this.publication_date = publication_date;
}
/**
* Gets the title.
*
@ -173,7 +174,6 @@ public class ZenodoMetadata implements Serializable{
return title;
}
/**
* Sets the title.
*
@ -183,7 +183,6 @@ public class ZenodoMetadata implements Serializable{
this.title = title;
}
/**
* Gets the creators.
*
@ -193,7 +192,6 @@ public class ZenodoMetadata implements Serializable{
return creators;
}
/**
* Sets the creators.
*
@ -203,7 +201,6 @@ public class ZenodoMetadata implements Serializable{
this.creators = creators;
}
/**
* Gets the description.
*
@ -213,7 +210,6 @@ public class ZenodoMetadata implements Serializable{
return description;
}
/**
* Sets the description.
*
@ -223,7 +219,6 @@ public class ZenodoMetadata implements Serializable{
this.description = description;
}
/**
* Gets the access right.
*
@ -233,7 +228,6 @@ public class ZenodoMetadata implements Serializable{
return access_right;
}
/**
* Sets the access right.
*
@ -243,7 +237,6 @@ public class ZenodoMetadata implements Serializable{
this.access_right = access_right;
}
/**
* Gets the embargo date.
*
@ -253,7 +246,6 @@ public class ZenodoMetadata implements Serializable{
return embargo_date;
}
/**
* Sets the embargo date.
*
@ -263,7 +255,6 @@ public class ZenodoMetadata implements Serializable{
this.embargo_date = embargo_date;
}
/**
* Gets the access conditions.
*
@ -273,7 +264,6 @@ public class ZenodoMetadata implements Serializable{
return access_conditions;
}
/**
* Sets the access conditions.
*
@ -283,7 +273,6 @@ public class ZenodoMetadata implements Serializable{
this.access_conditions = access_conditions;
}
/**
* Gets the doi.
*
@ -293,7 +282,6 @@ public class ZenodoMetadata implements Serializable{
return doi;
}
/**
* Sets the doi.
*
@ -303,7 +291,6 @@ public class ZenodoMetadata implements Serializable{
this.doi = doi;
}
/**
* Gets the preserve doi.
*
@ -313,7 +300,6 @@ public class ZenodoMetadata implements Serializable{
return preserve_doi;
}
/**
* Sets the preserve doi.
*
@ -323,7 +309,6 @@ public class ZenodoMetadata implements Serializable{
this.preserve_doi = preserve_doi;
}
/**
* Gets the keywords.
*
@ -333,7 +318,6 @@ public class ZenodoMetadata implements Serializable{
return keywords;
}
/**
* Sets the keywords.
*
@ -343,7 +327,6 @@ public class ZenodoMetadata implements Serializable{
this.keywords = keywords;
}
/**
* Gets the notes.
*
@ -353,7 +336,6 @@ public class ZenodoMetadata implements Serializable{
return notes;
}
/**
* Sets the notes.
*
@ -363,7 +345,6 @@ public class ZenodoMetadata implements Serializable{
this.notes = notes;
}
/**
* Gets the related identifiers.
*
@ -373,7 +354,6 @@ public class ZenodoMetadata implements Serializable{
return related_identifiers;
}
/**
* Sets the related identifiers.
*
@ -383,7 +363,6 @@ public class ZenodoMetadata implements Serializable{
this.related_identifiers = related_identifiers;
}
/**
* Gets the contributors.
*
@ -393,7 +372,6 @@ public class ZenodoMetadata implements Serializable{
return contributors;
}
/**
* Sets the contributors.
*
@ -403,7 +381,6 @@ public class ZenodoMetadata implements Serializable{
this.contributors = contributors;
}
/**
* Gets the references.
*
@ -413,7 +390,6 @@ public class ZenodoMetadata implements Serializable{
return references;
}
/**
* Sets the references.
*
@ -423,7 +399,6 @@ public class ZenodoMetadata implements Serializable{
this.references = references;
}
/**
* Gets the communities.
*
@ -433,7 +408,6 @@ public class ZenodoMetadata implements Serializable{
return communities;
}
/**
* Sets the communities.
*
@ -443,7 +417,6 @@ public class ZenodoMetadata implements Serializable{
this.communities = communities;
}
/**
* Gets the grants.
*
@ -453,7 +426,6 @@ public class ZenodoMetadata implements Serializable{
return grants;
}
/**
* Sets the grants.
*
@ -463,7 +435,6 @@ public class ZenodoMetadata implements Serializable{
this.grants = grants;
}
/**
* Gets the journal title.
*
@ -473,7 +444,6 @@ public class ZenodoMetadata implements Serializable{
return journal_title;
}
/**
* Sets the journal title.
*
@ -483,7 +453,6 @@ public class ZenodoMetadata implements Serializable{
this.journal_title = journal_title;
}
/**
* Gets the journal volume.
*
@ -493,7 +462,6 @@ public class ZenodoMetadata implements Serializable{
return journal_volume;
}
/**
* Sets the journal volume.
*
@ -503,7 +471,6 @@ public class ZenodoMetadata implements Serializable{
this.journal_volume = journal_volume;
}
/**
* Gets the journal issue.
*
@ -513,7 +480,6 @@ public class ZenodoMetadata implements Serializable{
return journal_issue;
}
/**
* Sets the journal issue.
*
@ -523,7 +489,6 @@ public class ZenodoMetadata implements Serializable{
this.journal_issue = journal_issue;
}
/**
* Gets the journal pages.
*
@ -533,7 +498,6 @@ public class ZenodoMetadata implements Serializable{
return journal_pages;
}
/**
* Sets the journal pages.
*
@ -543,7 +507,6 @@ public class ZenodoMetadata implements Serializable{
this.journal_pages = journal_pages;
}
/**
* Gets the conference title.
*
@ -553,7 +516,6 @@ public class ZenodoMetadata implements Serializable{
return conference_title;
}
/**
* Sets the conference title.
*
@ -563,7 +525,6 @@ public class ZenodoMetadata implements Serializable{
this.conference_title = conference_title;
}
/**
* Gets the conference acronym.
*
@ -573,7 +534,6 @@ public class ZenodoMetadata implements Serializable{
return conference_acronym;
}
/**
* Sets the conference acronym.
*
@ -583,7 +543,6 @@ public class ZenodoMetadata implements Serializable{
this.conference_acronym = conference_acronym;
}
/**
* Gets the conference dates.
*
@ -593,7 +552,6 @@ public class ZenodoMetadata implements Serializable{
return conference_dates;
}
/**
* Sets the conference dates.
*
@ -603,7 +561,6 @@ public class ZenodoMetadata implements Serializable{
this.conference_dates = conference_dates;
}
/**
* Gets the conference place.
*
@ -613,7 +570,6 @@ public class ZenodoMetadata implements Serializable{
return conference_place;
}
/**
* Sets the conference place.
*
@ -623,7 +579,6 @@ public class ZenodoMetadata implements Serializable{
this.conference_place = conference_place;
}
/**
* Gets the conference url.
*
@ -633,7 +588,6 @@ public class ZenodoMetadata implements Serializable{
return conference_url;
}
/**
* Sets the conference url.
*
@ -643,7 +597,6 @@ public class ZenodoMetadata implements Serializable{
this.conference_url = conference_url;
}
/**
* Gets the conference session.
*
@ -653,7 +606,6 @@ public class ZenodoMetadata implements Serializable{
return conference_session;
}
/**
* Sets the conference session.
*
@ -663,7 +615,6 @@ public class ZenodoMetadata implements Serializable{
this.conference_session = conference_session;
}
/**
* Gets the conference session part.
*
@ -673,7 +624,6 @@ public class ZenodoMetadata implements Serializable{
return conference_session_part;
}
/**
* Sets the conference session part.
*
@ -683,7 +633,6 @@ public class ZenodoMetadata implements Serializable{
this.conference_session_part = conference_session_part;
}
/**
* Gets the imprint publisher.
*
@ -693,7 +642,6 @@ public class ZenodoMetadata implements Serializable{
return imprint_publisher;
}
/**
* Sets the imprint publisher.
*
@ -703,7 +651,6 @@ public class ZenodoMetadata implements Serializable{
this.imprint_publisher = imprint_publisher;
}
/**
* Gets the imprint isbn.
*
@ -713,7 +660,6 @@ public class ZenodoMetadata implements Serializable{
return imprint_isbn;
}
/**
* Sets the imprint isbn.
*
@ -723,7 +669,6 @@ public class ZenodoMetadata implements Serializable{
this.imprint_isbn = imprint_isbn;
}
/**
* Gets the imprint place.
*
@ -733,7 +678,6 @@ public class ZenodoMetadata implements Serializable{
return imprint_place;
}
/**
* Sets the imprint place.
*
@ -743,7 +687,6 @@ public class ZenodoMetadata implements Serializable{
this.imprint_place = imprint_place;
}
/**
* Gets the partof title.
*
@ -753,7 +696,6 @@ public class ZenodoMetadata implements Serializable{
return partof_title;
}
/**
* Sets the partof title.
*
@ -763,7 +705,6 @@ public class ZenodoMetadata implements Serializable{
this.partof_title = partof_title;
}
/**
* Gets the partof pages.
*
@ -773,7 +714,6 @@ public class ZenodoMetadata implements Serializable{
return partof_pages;
}
/**
* Sets the partof pages.
*
@ -783,7 +723,6 @@ public class ZenodoMetadata implements Serializable{
this.partof_pages = partof_pages;
}
/**
* Gets the thesis supervisors.
*
@ -793,7 +732,6 @@ public class ZenodoMetadata implements Serializable{
return thesis_supervisors;
}
/**
* Sets the thesis supervisors.
*
@ -803,7 +741,6 @@ public class ZenodoMetadata implements Serializable{
this.thesis_supervisors = thesis_supervisors;
}
/**
* Gets the thesis university.
*
@ -813,7 +750,6 @@ public class ZenodoMetadata implements Serializable{
return thesis_university;
}
/**
* Sets the thesis university.
*
@ -823,7 +759,6 @@ public class ZenodoMetadata implements Serializable{
this.thesis_university = thesis_university;
}
/**
* Gets the subjects.
*
@ -833,7 +768,6 @@ public class ZenodoMetadata implements Serializable{
return subjects;
}
/**
* Sets the subjects.
*
@ -843,7 +777,6 @@ public class ZenodoMetadata implements Serializable{
this.subjects = subjects;
}
/**
* Gets the version.
*
@ -853,7 +786,6 @@ public class ZenodoMetadata implements Serializable{
return version;
}
/**
* Sets the version.
*
@ -863,7 +795,6 @@ public class ZenodoMetadata implements Serializable{
this.version = version;
}
/**
* Gets the language.
*
@ -873,7 +804,6 @@ public class ZenodoMetadata implements Serializable{
return language;
}
/**
* Sets the language.
*
@ -883,7 +813,6 @@ public class ZenodoMetadata implements Serializable{
this.language = language;
}
/**
* Gets the locations.
*
@ -893,7 +822,6 @@ public class ZenodoMetadata implements Serializable{
return locations;
}
/**
* Sets the locations.
*
@ -903,7 +831,6 @@ public class ZenodoMetadata implements Serializable{
this.locations = locations;
}
/**
* Gets the dates.
*
@ -913,7 +840,6 @@ public class ZenodoMetadata implements Serializable{
return dates;
}
/**
* Sets the dates.
*
@ -923,7 +849,6 @@ public class ZenodoMetadata implements Serializable{
this.dates = dates;
}
/**
* Gets the method.
*
@ -933,7 +858,6 @@ public class ZenodoMetadata implements Serializable{
return method;
}
/**
* Sets the method.
*
@ -942,7 +866,7 @@ public class ZenodoMetadata implements Serializable{
public void setMethod(String method) {
this.method = method;
}
/**
* Sets the licenses.
*
@ -951,7 +875,7 @@ public class ZenodoMetadata implements Serializable{
public void setLicenses(SerializableEnum<LicenseBean> licenses) {
this.licenses = licenses;
}
/**
* Gets the licenses.
*
@ -961,7 +885,6 @@ public class ZenodoMetadata implements Serializable{
return licenses;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -1056,5 +979,5 @@ public class ZenodoMetadata implements Serializable{
builder.append("]");
return builder.toString();
}
}