Bug fixes for publishing files

This commit is contained in:
Francesco Mangiacrapa 2020-01-31 12:27:14 +01:00
parent 3cf7c277d2
commit 555f022997
6 changed files with 63 additions and 11 deletions

View File

@ -180,7 +180,7 @@ public class Ckan2ZenodoViewManager {
// Updating list of file for publishing
List<ZenodoFile> publishingFile = getListFileToPublish();
zenodoItem.addFiles(publishingFile);
zenodoItem.setFiles(publishingFile);
return zenodoItem;

View File

@ -7,8 +7,8 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.publishfile.Pub
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.publishfile.PublishFilesFormView;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoFile;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
public class PublishFileViewManager {
@ -48,14 +48,20 @@ public class PublishFileViewManager {
public List<ZenodoFile> getSelectedFileToZenodoPublishing(){
List<PublishFileView> listOfPublFilesFormView = publishFileFormView.getListOfPublishingFileView();
GWT.log("Checking Files to publish: "+listOfPublFilesFormView);
List<ZenodoFile> lisFileToPublish = new ArrayList<ZenodoFile>();
for (PublishFileView publishFileView : listOfPublFilesFormView) {
if(publishFileView.isToPublish()) {
//THE FILE NAME SHOULD BE CHANGED BY USER, SO UPDATING IT
ZenodoFile file = publishFileView.getFile();
if(!publishFileView.getField_file_name().getValue().isEmpty()) {
file.setFilename(publishFileView.getField_file_name().getValue());
}
lisFileToPublish.add(publishFileView.getFile());
}
}
GWT.log("List of Files to publish (with publish ON): "+lisFileToPublish);
return lisFileToPublish;
}

View File

@ -78,7 +78,10 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
for (ZenodoFile zf : zenodoItem.getFiles()) {
for (CkanResource ckanResource : filteredResources) {
if(zf.getId().compareTo(ckanResource.getId())==0 && zf.getIsAlreadyPublished()==false) {
toUpload.add(ckanResource);
if(CkanToZenodoUtil.isNotEmpty(zf.getFilename())) {
ckanResource.setName(zf.getFilename()); //only the filename can be changed on clien-side
toUpload.add(ckanResource);
}
}
}
}
@ -113,7 +116,11 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
LOG.error(error, e);
String clientError = String.format("%s", error);
throw new Exception(clientError);
} catch (ZenodoException e) {
String error = "ZenodoException during upload to Zenodo the catalogue item: "+zenodoItem.getName();
LOG.error(error, e);
String clientError = String.format("%s", e.getMessage());
throw new Exception(clientError);
} catch (Exception e) {
String error = "Error during upload to Zenodo the catalogue item: "+zenodoItem.getName();
LOG.error(error, e);

View File

@ -61,4 +61,16 @@ public class CkanToZenodoUtil {
return new SerializableEnum<E>(selectedLicense, allLicenses);
}
/**
* Checks if is not empty.
*
* @param value the value
* @return true, if is not empty
*/
public static boolean isNotEmpty(String value) {
if(value!=null && !value.isEmpty())
return true;
return false;
}
}

View File

@ -571,9 +571,15 @@ public class ItemToZenodoConverter {
for (ZenodoAuthor zenodoAuthor : zenodoCreators) {
Creator creator = new Creator();
creator.setName(zenodoAuthor.getName());
creator.setAffiliation(zenodoAuthor.getAffiliation());
creator.setGnd(zenodoAuthor.getGnd());
creator.setOrcid(zenodoAuthor.getOrcid());
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getAffiliation())) {
creator.setAffiliation(zenodoAuthor.getAffiliation());
}
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getGnd())) {
creator.setGnd(zenodoAuthor.getGnd());
}
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getOrcid())) {
creator.setOrcid(zenodoAuthor.getOrcid());
}
listOfCreators.add(creator);
}
@ -595,9 +601,15 @@ public class ItemToZenodoConverter {
for (ZenodoAuthor zenodoAuthor : zenodoContributors) {
Contributor contributor = new Contributor();
contributor.setName(zenodoAuthor.getName());
contributor.setAffiliation(zenodoAuthor.getAffiliation());
contributor.setGnd(zenodoAuthor.getGnd());
contributor.setOrcid(zenodoAuthor.getOrcid());
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getAffiliation())) {
contributor.setAffiliation(zenodoAuthor.getAffiliation());
}
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getGnd())) {
contributor.setGnd(zenodoAuthor.getGnd());
}
if(CkanToZenodoUtil.isNotEmpty(zenodoAuthor.getOrcid())) {
contributor.setOrcid(zenodoAuthor.getOrcid());
}
Type type = null;
String theType = null;
try {

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -70,6 +71,20 @@ public class ZenodoItem implements Serializable {
}
}
/**
* Sets the files.
*
* @param files the new files
*/
public void setFiles(List<ZenodoFile> files) {
this.files = new ArrayList<ZenodoFile>();
if(files!=null) {
this.files.addAll(files);
}
}
/**
* Gets the created.
*