[#21263] manage empty mapping for creators/contributors

This commit is contained in:
Francesco Mangiacrapa 2021-04-23 17:10:15 +02:00
parent cecd6e82cc
commit 837eaa7dba
5 changed files with 104 additions and 37 deletions

View File

@ -4,6 +4,15 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.0.2-SNAPSHOT] - 2021-04-23
**Bug fixes**
[#21263] manage empty mapping for creators/contributors
**Enhancements**
[#21153] ported to maven-portal-bom 3.6.1
## [v1.0.1] - 2021-03-09
[#20935] just to include new range 1.x, 2.0 of ckan2zenodo-library

View File

@ -15,7 +15,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan2zenodo-publisher-widget</artifactId>
<packaging>jar</packaging>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
<description>
gCube Ckan2Zenodo Publisher widget allows to publish D4Science catalogue's items on Zenodo
@ -44,7 +44,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.0</version>
<version>3.6.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@ -24,6 +24,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
// TODO: Auto-generated Javadoc
/**
* The Class CreatorView.
*
@ -75,23 +76,29 @@ 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) {
public CreatorView(ZenodoAuthor author, String userRole, Boolean isMandatoryField) {
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("<font color='red'>*</font>&nbsp;"+userRole));
field_cl_author.add(new HTML(fieldLabel+"&nbsp;"+userRole));
remove_author.setText("Remove "+userRole);
}else { //default role is Author
field_cl_author.add(new HTML("<font color='red'>*</font>&nbsp;Author"));
field_cl_author.add(new HTML(fieldLabel+"&nbsp;Author"));
remove_author.setText("Remove Author");
}
@ -107,12 +114,16 @@ public class CreatorView extends Composite {
}
}
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);
if(this.userRole!=null) {
String userRoleToLowerCase = userRole.toLowerCase();
if(userRoleToLowerCase.startsWith("creator")) {
InfoTextAndLabels.addTooltipForFieldKey("creators", field_cl_author);
}else if(userRoleToLowerCase.startsWith("contributor")) {
InfoTextAndLabels.addTooltipForFieldKey("contributors", field_cl_author);
}else {
InfoTextAndLabels.addTooltipForFieldKey("authors", field_cl_author);
}
}
GWT.log("Created creator view with author: "+this.author);
@ -125,9 +136,10 @@ 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) {
this(author, userRole);
public CreatorView(ZenodoAuthor author, String userRole, HandlerManager eventBus, Boolean isFieldMandatory) {
this(author, userRole, isFieldMandatory);
this.eventBus = eventBus;
remove_author.addClickHandler(new ClickHandler() {
@ -148,6 +160,16 @@ 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.
@ -230,6 +252,11 @@ 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,15 +64,19 @@ 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) {
public CreatorsFormView(List<? extends ZenodoAuthor> listAuthors, Class theAuthorType) {
initWidget(uiBinder.createAndBindUi(this));
this.listAuthors = listAuthors;
this.theAuthorType = theAuthorType;
button_add_author.addClickHandler(new ClickHandler() {
@ -105,6 +109,8 @@ public class CreatorsFormView extends Composite implements FormValidator{
*/
private void addAuthorsToView() {
GWT.log("Adding listAuthors: "+listAuthors);
if(listCreatorView==null)
listCreatorView = new ArrayList<CreatorView>();
@ -119,7 +125,7 @@ public class CreatorsFormView extends Composite implements FormValidator{
}else if(creator instanceof ZenodoCreator) {
userRole = "Creator";
}
CreatorView view = new CreatorView(creator, userRole, eventBus);
CreatorView view = new CreatorView(creator, userRole, eventBus, true);
listCreatorView.add(view);
fieldset_authors.add(view);
}
@ -146,18 +152,33 @@ 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.compareToIgnoreCase("Contributor")==0) {
author = new ZenodoContributor();
((ZenodoContributor) author).setType(contributorTypeValues);
if(userRole == null) {
if (theAuthorType.equals(ZenodoCreator.class)) {
userRole = "Creator";
}else if(theAuthorType.equals(ZenodoContributor.class)) {
userRole = "Contributor";
}else
userRole = "Creator";
GWT.log("Empty list assigned the userRole: "+userRole);
}else {
//dead code???
if(userRole.compareToIgnoreCase("Contributor")==0) {
author = new ZenodoContributor();
((ZenodoContributor) author).setType(contributorTypeValues);
}
}
CreatorView view = new CreatorView(author, userRole, eventBus);
CreatorView view = new CreatorView(author, userRole, eventBus,false);
listCreatorView.add(view);
fieldset_authors.add(view);
@ -190,15 +211,20 @@ 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);
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");
}
return listAuthors;
@ -223,11 +249,14 @@ public class CreatorsFormView extends Composite implements FormValidator{
for (CreatorView creatorView : listCreatorView) {
ControlGroup cgAuthor = creatorView.getControlGroup_Author();
FieldUtil.setControlGroup(cgAuthor, ControlGroupType.NONE);
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";
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";
}
}
/*

View File

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