Fixed creators/contributors view and submit

This commit is contained in:
Francesco Mangiacrapa 2020-01-16 12:26:36 +01:00
parent 3e938addad
commit 6fd20c127d
9 changed files with 147 additions and 16 deletions

View File

@ -91,14 +91,16 @@ public class CreatorView extends Composite {
if(this.userRole!=null) {
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("<font color='red'>*</font>&nbsp;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;
}
}

View File

@ -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<String>(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);
}

View File

@ -210,9 +210,11 @@ 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());
listOfCreatorsView.add(authorView);
GWT.log("Adding contributors: "+zenodoItem.getMetadata().getContributors());
CreatorsFormView contributorView = new CreatorsFormView(zenodoItem.getMetadata().getContributors());
listOfContributorsView.add(contributorView);

View File

@ -124,9 +124,11 @@ public class Ckan2ZenodoViewManager {
meta.setKeywords(basicForm.getTags()); // these are the keywords
List<ZenodoCreator> creators = basicForm.getListOfCreators();
GWT.log("Read creators from FORM: "+creators);
meta.setCreators(creators);
List<ZenodoContributor> contributors = basicForm.getListOfContributors();
GWT.log("Read contributors from FORM: "+contributors);
meta.setContributors(contributors);
// upload type

View File

@ -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);

View File

@ -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<Creator> creators = null;
List<? extends ZenodoAuthor> zenodoCreators = metadata.getCreators();
LOG.debug("Read Creators: "+zenodoCreators);
if(zenodoCreators!=null) {
creators = toCreators(zenodoCreators);
}
LOG.debug("Set Creators: "+creators);
depositionMetadata.setCreators(creators);
//contributors
List<Contributor> contributors = null;
List<? extends ZenodoAuthor> 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<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());
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<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());
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;
}

View File

@ -45,6 +45,14 @@ public interface ZenodoAuthor {
* @return the type
*/
public SerializableEnum<String> getType();
/**
* Sets the type.
*
* @param type the new type
*/
public void setType(SerializableEnum<String> type);
/**
* Sets the name.

View File

@ -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();
}

View File

@ -119,6 +119,11 @@ public class ZenodoCreator implements ZenodoAuthor, Serializable{
public SerializableEnum<String> getType() {
return null;
}
@Override
public void setType(SerializableEnum<String> type) {
//empty
}
/* (non-Javadoc)
* @see java.lang.Object#toString()