This commit is contained in:
Francesco Mangiacrapa 2020-01-14 12:28:20 +01:00
parent 371e5c8874
commit 1341b7b853
9 changed files with 185 additions and 100 deletions

View File

@ -106,7 +106,36 @@ public class CkanToZendoPublisherWidget {
}
if(allFormsAreValid) {
submitPublishOnZenodo();
//Submit publish on zenodo.
ZenodoItem zenodoItem = manager.getZenodoItemFromFieldsForm();
GWT.log("Publishing file: "+zenodoItem.getFiles());
ckanToZenodoService.publishOnZenodo(zenodoItem, new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
//modal.clear();
Alert erroLabel = new Alert();
erroLabel.setClose(false);
erroLabel.setType(AlertType.ERROR);
erroLabel.setText(caught.getLocalizedMessage());
modal.add(erroLabel);
Button close = new Button("Close");
close.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
modal.hide();
}
});
modal.add(close);
}
@Override
public void onSuccess(String result) {
String msg = "Publishing: \n\n"+result+"\n\nIs it right?";
Window.alert(msg);
}
});
}
}
});
@ -115,27 +144,6 @@ public class CkanToZendoPublisherWidget {
modal.add(modalFooter);
modal.show();
}
/**
* To zenodo item.
*
* @param item the item
*/
private void toZenodoItem(CatalogueItem item) {
ckanToZenodoService.convertToZenodoItem(item, new AsyncCallback<ZenodoItem>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(ZenodoItem result) {
}
});
}
/**
* Submit publish on zenodo.
@ -150,10 +158,12 @@ public class CkanToZendoPublisherWidget {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(String result) {
Window.alert(result);
}
});
}

View File

@ -138,4 +138,11 @@ public class BasicTabPanel extends Composite {
pager.getRight().setVisible(false);
}
}
public void enableAddFileTab(boolean bool) {
//acc_files.setActive(bool);
acc_files.setEnabled(bool);
pager.getRight().setVisible(bool);
}
}

View File

@ -171,22 +171,24 @@ public class CreatorsFormView extends Composite implements FormValidator{
boolean isValid = FieldUtil.isValidValue(value);
if(!isValid) {
FieldUtil.setControlGroup(cgAuthor, ControlGroupType.ERROR);
return "The author name is required";
return "The Author Name is required";
}
/*
String affiliation = FieldUtil.getTextValue(creatorView.getField_affiliation());
isValid = FieldUtil.isValidValue(affiliation);
if(!isValid) {
FieldUtil.setControlGroup(cgAuthor, ControlGroupType.ERROR);
return "The author affiliation is required";
return "The field affiliation is required";
}
String orcid = FieldUtil.getTextValue(creatorView.getField_orcid());
isValid = FieldUtil.isValidValue(orcid);
if(!isValid) {
FieldUtil.setControlGroup(cgAuthor, ControlGroupType.ERROR);
return "The author ORCID is required";
return "The field ORCID is required";
}
*/
}
return null;

View File

@ -165,20 +165,37 @@ public class BasicInformationView extends Composite implements FormValidator {
String title = zenodoItem.getTitle()!=null?zenodoItem.getTitle():zMeta.getTitle();
field_title.setValue(title); //Re.fill title to be sure
addValuesToListBox(field_upload_type, zMeta.getUpload_type().getSelectableValues());
selectValueToListBox(field_upload_type, zMeta.getUpload_type().getSelectedValues());
//Upload type
if(zMeta.getUpload_type()!=null) {
addValuesToListBox(field_upload_type, zMeta.getUpload_type().getSelectableValues());
selectValueToListBox(field_upload_type, zMeta.getUpload_type().getSelectedValues());
}else
field_upload_type.setEnabled(false);
//Publication Type
if(zMeta.getPublication_type()!=null) {
addValuesToListBox(field_publication_type, zMeta.getPublication_type().getSelectableValues());
selectValueToListBox(field_publication_type, zMeta.getPublication_type().getSelectedValues());
}else
field_publication_type.setEnabled(false);
addValuesToListBox(field_access_right, zMeta.getAccess_right().getSelectableValues());
selectValueToListBox(field_access_right, zMeta.getAccess_right().getSelectedValues());
if(zMeta.getAccess_right()!=null) {
addValuesToListBox(field_access_right, zMeta.getAccess_right().getSelectableValues());
selectValueToListBox(field_access_right, zMeta.getAccess_right().getSelectedValues());
}else
field_access_right.setEnabled(false);
addValuesToListBox(field_license, Arrays.asList(zMeta.getLicense().getId()));
selectValueToListBox(field_license, Arrays.asList(zMeta.getLicense().getId()));
if(zMeta.getLicense()!=null) {
addValuesToListBox(field_license, Arrays.asList(zMeta.getLicense().getId()));
selectValueToListBox(field_license, Arrays.asList(zMeta.getLicense().getId()));
}
field_license.setEnabled(false); //because is not changeable
if(zMeta.getKeywords()!=null && zMeta.getKeywords().size()>0) {
for (String keyword : zMeta.getKeywords()) {
the_tags_panel.addTagElement(keyword);
}
}
// ADDING AUTHORS
creatorsView = new CreatorsFormView(zenodoItem.getMetadata().getCreators());
@ -443,5 +460,15 @@ public class BasicInformationView extends Composite implements FormValidator {
}
/**
* Gets the list of keywords.
*
* @return the list of keywords
*/
public List<String> getListOfKeywords(){
return the_tags_panel.getTags();
}
}

View File

@ -10,7 +10,7 @@
<g:HTMLPanel>
<b:ControlGroup ui:field="tagsInsertGroup">
<b:ControlLabel for="tags" title="Item tag">
<font color="red">*</font>
<!-- <font color="red">*</font> -->
Keywords
</b:ControlLabel>
<b:Controls ui:field="controlAsTextBox">

View File

@ -13,6 +13,9 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoFile
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoMetadata;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.shared.HandlerManager;
/**
@ -20,117 +23,130 @@ import com.google.gwt.event.shared.HandlerManager;
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 19, 2019
* Dec 19, 2019
*/
public class Ckan2ZenodoViewManager {
private BasicTabPanel basicTabPanel;
public final static HandlerManager eventBus = new HandlerManager(null);
private List<FormValidator> forms = new ArrayList<FormValidator>();
private BasicInformationView basicForm;
private PublishFileViewManager publishFileVM;
private ZenodoItem zenodoItem;
/**
* Instantiates a new ckan 2 zenodo view manager.
*/
public Ckan2ZenodoViewManager() {
}
/**
* View for publishing.
*
* @param zenodoItem the zenodo item
* @return the basic tab panel
*/
public BasicTabPanel viewForPublishing(final ZenodoItem zenodoItem){
public BasicTabPanel viewForPublishing(final ZenodoItem zenodoItem) {
this.zenodoItem = zenodoItem;
basicTabPanel = new BasicTabPanel();
boolean isUpdate = false;
if(zenodoItem.getMetadata()!=null) {
isUpdate = zenodoItem.getMetadata().getDoi()!=null?true:false;
if (zenodoItem.getMetadata() != null) {
isUpdate = zenodoItem.getMetadata().getDoi() != null ? true : false;
}
//Basic Information
// Basic Information
int tabIndex = 0;
basicForm = new BasicInformationView(zenodoItem, isUpdate, tabIndex);
basicTabPanel.getAcc_basic_info().add(basicForm);
forms.add(basicForm);
//Files
tabIndex = 1;
publishFileVM = new PublishFileViewManager(zenodoItem.getFiles(), tabIndex);
basicTabPanel.getAcc_files().add(publishFileVM.getView());
// Files
if (zenodoItem.getFiles() != null && zenodoItem.getFiles().size() > 0) {
tabIndex = 1;
publishFileVM = new PublishFileViewManager(zenodoItem.getFiles(), tabIndex);
basicTabPanel.getAcc_files().add(publishFileVM.getView());
} else {
GWT.log("Hiding add files tab");
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
basicTabPanel.enableAddFileTab(false);
}
});
}
return basicTabPanel;
//return basePanel;
// return basePanel;
}
/**
* Gets the list forms.
*
* @return the list forms
*/
public List<FormValidator> getListForms(){
public List<FormValidator> getListForms() {
return forms;
}
/**
* Gets the list file to publish.
*
* @return the list file to publish
*/
public List<ZenodoFile> getListFileToPublish(){
return publishFileVM.getSelectedFileToZenodoPublishing();
public List<ZenodoFile> getListFileToPublish() {
if(publishFileVM!=null) {
return publishFileVM.getSelectedFileToZenodoPublishing();
}
return null; //Is null if any resource was attached to dataset
}
/**
* Gets the zenodo item from form.
*
* @return the zenodo item from form
*/
public ZenodoItem getZenodoItemFromFieldsForm(){
//Updating Basic Information
public ZenodoItem getZenodoItemFromFieldsForm() {
// Updating Basic Information
zenodoItem.setTitle(basicForm.getField_title().getValue());
zenodoItem.setDoi(basicForm.getField_doi().getValue());
//Updating Metadata
// Updating Metadata
ZenodoMetadata meta = zenodoItem.getMetadata();
meta.setDescription(basicForm.getField_description().getValue());
meta.setKeywords(basicForm.getTags()); //these are the keywords
meta.setKeywords(basicForm.getTags()); // these are the keywords
List<ZenodoCreator> creators = basicForm.getListOfCreators();
meta.setCreators(creators);
//upload type
// upload type
String uploadType = basicForm.getField_upload_type().getSelectedValue();
meta.setUpload_type(new SerializableEnum<>(Arrays.asList(uploadType), meta.getUpload_type().getSelectableValues()));
//publication type
if(uploadType!=null)
meta.setUpload_type(new SerializableEnum<>(Arrays.asList(uploadType), meta.getUpload_type().getSelectableValues()));
// publication type
String publicationType = basicForm.getField_publication_type().getSelectedValue();
meta.setPublication_type(new SerializableEnum<>(Arrays.asList(publicationType), meta.getPublication_type().getSelectableValues()));
//access right
if(publicationType!=null)
meta.setPublication_type(new SerializableEnum<>(Arrays.asList(publicationType), meta.getPublication_type().getSelectableValues()));
// access right
String accessRight = basicForm.getField_access_right().getSelectedValue();
meta.setAccess_right(new SerializableEnum<>(Arrays.asList(accessRight), meta.getAccess_right().getSelectableValues()));
if(accessRight!=null)
meta.setAccess_right(new SerializableEnum<>(Arrays.asList(accessRight), meta.getAccess_right().getSelectableValues()));
//keywords
meta.setKeywords(basicForm.getTags());
zenodoItem.setMetadata(meta);
//Updating list of file for publishing
// Updating list of file for publishing
List<ZenodoFile> publishingFile = getListFileToPublish();
zenodoItem.setFiles(publishingFile);
return zenodoItem;
}
}

View File

@ -1,9 +1,11 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.server;
import java.util.ArrayList;
import java.util.List;
import org.gcube.data.publishing.ckan2zenodo.Ckan2Zenodo;
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
import org.gcube.data.publishing.ckan2zenodo.model.faults.GcatException;
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
@ -39,6 +41,11 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
try {
if(isOutFromPortal()) {
PortalUtils.getCurrentContext(this.getThreadLocalRequest(), true);
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
}
ZenodoDeposition zdPreview=loadItemPreviewFromService(zenodoItem.getName());
//(EVENTUALLY) UPDATING INFO CHANGED BY FORM ON CLIENT-SIDE
@ -53,7 +60,8 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
}
zdPreview.setFiles(listOfFiles);
}
//Updating Deposition Metadata
//Updating Deposition Metadata potentially changed on client-side
ZenodoMetadata metadata = zenodoItem.getMetadata();
DepositionMetadata depositionMetadata = zdPreview.getMetadata();
depositionMetadata = ItemToZenodoConverter.updateMetadataInfoOfDepositionMetadata(metadata, depositionMetadata);
@ -65,9 +73,9 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
//Actually publish to zenodo :
// Step 1 : metadata
Ckan2Zenodo client= Ckan2Zenodo.get();
CkanItemDescriptor item=client.read(zenodoItem.getName());
zdPreview = client.updatedMetadata(zdPreview);
// Ckan2Zenodo client= Ckan2Zenodo.get();
// CkanItemDescriptor item=client.read(zenodoItem.getName());
// zdPreview = client.updatedMetadata(zdPreview);
//Step 2 : publish Resources
// Future<ZenodoDeposition> future_Dep=client.uploadFiles(Collections.singleton(toFilter.get(0)), zdPreview);
@ -76,12 +84,12 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
//Finalize
// Get the item representation
client.publish(zdPreview, item);
//client.publish(zdPreview, item);
return "OK";
return zdPreview.toString();
} catch (Exception e) {
String error = "Error on publishing on Zenodo the catalogue item: "+zenodoItem.getName();
String error = "Error when publishing on Zenodo the catalogue item: "+zenodoItem.getName();
LOG.error(error, e);
String clientError = String.format("%s. %s", error, CkanToZendoPublisherWidgetConstant.MSG_OF_ERROR_REFRESH_AND_TRY_AGAIN_OR_CONTACT_THE_SUPPORT);
throw new Exception(clientError);
@ -159,7 +167,12 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
CkanItemDescriptor itemDescr=client.read(itemName);
//Get a preview of the deposition to be published
return client.translate(itemDescr);
ZenodoDeposition zenodoDeposition = client.translate(itemDescr);
//Filter resources according to VRE policies
List<CkanResource> toFilter=client.filterResources(itemDescr);
return zenodoDeposition;
}
/**

View File

@ -87,7 +87,7 @@ public class ItemToZenodoConverter {
zi.setState(zenodoDeposition.getState());
zi.setSubmitted(zenodoDeposition.getSubmitted());
zi.setTitle(zenodoDeposition.getTitle());
zi.setMetadata(toZenodoMetadata(zenodoDeposition.getMetadata()));
LOG.debug("Converted item: "+zi);
@ -145,8 +145,8 @@ public class ItemToZenodoConverter {
//Publication Type
if(depositionMetadata.getPublication_type()!=null) {
PublicationType[] upType = { depositionMetadata.getPublication_type() };
SerializableEnum<String> sEnum = CkanToZenodoUtil.toSerializableEnum(upType, PublicationType.values());
PublicationType[] publicationType = { depositionMetadata.getPublication_type() };
SerializableEnum<String> sEnum = CkanToZenodoUtil.toSerializableEnum(publicationType, PublicationType.values());
zm.setPublication_type(sEnum);
}
@ -169,6 +169,7 @@ public class ItemToZenodoConverter {
zm.setThesis_university(depositionMetadata.getThesis_university());
zm.setTitle(depositionMetadata.getTitle());
zm.setVersion(depositionMetadata.getVersion());
zm.setNotes(depositionMetadata.getNotes());
return zm;
}
@ -441,21 +442,32 @@ public class ItemToZenodoConverter {
//upload type
SerializableEnum<String> uploadType = metadata.getUpload_type();
String theUploadTypeValue = uploadType.getSelectedValues().get(0);
LOG.debug("Set upload type: "+theUploadTypeValue);
depositionMetadata.setUpload_type(UploadType.valueOf(theUploadTypeValue));
LOG.debug("Read upload type: "+uploadType);
if(uploadType!=null) {
String theUploadTypeValue = uploadType.getSelectedValues().get(0);
LOG.debug("Set upload type: "+theUploadTypeValue);
depositionMetadata.setUpload_type(UploadType.valueOf(theUploadTypeValue));
}
//access right
SerializableEnum<String> accessRight = metadata.getAccess_right();
String theAccessRightValue = accessRight.getSelectedValues().get(0);
LOG.debug("Set access right: "+theAccessRightValue);
depositionMetadata.setAccess_right(AccessRights.valueOf(theAccessRightValue));
LOG.debug("Read access type: "+accessRight);
if(accessRight!=null) {
String theAccessRightValue = accessRight.getSelectedValues().get(0);
LOG.debug("Set access right: "+theAccessRightValue);
depositionMetadata.setAccess_right(AccessRights.valueOf(theAccessRightValue));
}
//publication type
SerializableEnum<String> publicationType = metadata.getPublication_type();
String thePublicationTypeValue = publicationType.getSelectedValues().get(0);
LOG.debug("Set publication type: "+thePublicationTypeValue);
depositionMetadata.setPublication_type(PublicationType.valueOf(thePublicationTypeValue));
LOG.debug("Read publication type: "+publicationType);
if(publicationType!=null) {
String thePublicationTypeValue = publicationType.getSelectedValues().get(0);
depositionMetadata.setPublication_type(PublicationType.valueOf(thePublicationTypeValue));
}
//keywords
depositionMetadata.setKeywords(metadata.getKeywords());
return depositionMetadata;
}

View File

@ -83,8 +83,6 @@ public class ZenodoMetadata implements Serializable{
public SerializableEnum<String> getPublication_type() {
if(publication_type==null)
return new SerializableEnum<>();
return publication_type;
}