ckan2zenodo-publisher-widget/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/view/Ckan2ZenodoViewManager.java

195 lines
6.1 KiB
Java
Raw Normal View History

2019-12-16 17:51:37 +01:00
package org.gcube.portlets.widgets.ckan2zenodopublisher.client.view;
2020-01-09 16:00:46 +01:00
import java.util.ArrayList;
2020-01-13 17:48:41 +01:00
import java.util.Arrays;
2020-01-21 17:07:05 +01:00
import java.util.Date;
2020-01-09 16:00:46 +01:00
import java.util.List;
2019-12-19 17:41:50 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.BasicTabPanel;
2019-12-17 11:37:56 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.basicinformation.BasicInformationView;
2020-01-13 17:48:41 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.SerializableEnum;
2020-01-15 17:51:22 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoContributor;
2020-01-13 17:48:41 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoCreator;
2020-01-10 17:07:03 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoFile;
2019-12-16 17:51:37 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
2020-01-13 17:48:41 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoMetadata;
2019-12-16 17:51:37 +01:00
2020-01-14 12:28:20 +01:00
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.core.shared.GWT;
2019-12-19 17:41:50 +01:00
import com.google.gwt.event.shared.HandlerManager;
/**
* The Class Ckan2ZenodoViewManager.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
2020-01-14 12:28:20 +01:00
* Dec 19, 2019
2019-12-19 17:41:50 +01:00
*/
2019-12-16 17:51:37 +01:00
public class Ckan2ZenodoViewManager {
2020-01-14 12:28:20 +01:00
2019-12-19 17:41:50 +01:00
private BasicTabPanel basicTabPanel;
2019-12-20 16:36:49 +01:00
2019-12-19 17:41:50 +01:00
public final static HandlerManager eventBus = new HandlerManager(null);
2020-01-14 12:28:20 +01:00
2020-01-09 16:00:46 +01:00
private List<FormValidator> forms = new ArrayList<FormValidator>();
2020-01-10 17:07:03 +01:00
private BasicInformationView basicForm;
private PublishFileViewManager publishFileVM;
2020-01-13 17:48:41 +01:00
private ZenodoItem zenodoItem;
2020-01-14 12:28:20 +01:00
2019-12-19 17:41:50 +01:00
/**
* Instantiates a new ckan 2 zenodo view manager.
*/
2019-12-16 17:51:37 +01:00
public Ckan2ZenodoViewManager() {
}
2020-01-14 12:28:20 +01:00
2019-12-19 17:41:50 +01:00
/**
* View for publishing.
*
* @param zenodoItem the zenodo item
2020-01-09 16:00:46 +01:00
* @return the basic tab panel
2019-12-19 17:41:50 +01:00
*/
2020-01-14 12:28:20 +01:00
public BasicTabPanel viewForPublishing(final ZenodoItem zenodoItem) {
2020-01-13 17:48:41 +01:00
this.zenodoItem = zenodoItem;
2019-12-20 12:11:14 +01:00
basicTabPanel = new BasicTabPanel();
2020-01-14 12:28:20 +01:00
2019-12-18 18:08:05 +01:00
boolean isUpdate = false;
2020-01-14 12:28:20 +01:00
if (zenodoItem.getMetadata() != null) {
2020-01-27 17:56:16 +01:00
isUpdate = zenodoItem.getMetadata().getDoi() != null || zenodoItem.getDoi() != null? true : false;
2019-12-18 18:08:05 +01:00
}
2020-01-14 12:28:20 +01:00
// Basic Information
2019-12-19 17:41:50 +01:00
int tabIndex = 0;
2020-01-10 17:07:03 +01:00
basicForm = new BasicInformationView(zenodoItem, isUpdate, tabIndex);
2019-12-19 17:41:50 +01:00
basicTabPanel.getAcc_basic_info().add(basicForm);
2020-01-09 16:00:46 +01:00
forms.add(basicForm);
2020-01-14 12:28:20 +01:00
// 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);
}
});
}
2019-12-20 16:36:49 +01:00
return basicTabPanel;
2020-01-14 12:28:20 +01:00
// return basePanel;
2020-01-09 16:00:46 +01:00
}
2019-12-20 16:36:49 +01:00
2020-01-09 16:00:46 +01:00
/**
* Gets the list forms.
*
* @return the list forms
*/
2020-01-14 12:28:20 +01:00
public List<FormValidator> getListForms() {
2020-01-09 16:00:46 +01:00
return forms;
2019-12-16 17:51:37 +01:00
}
2020-01-10 17:07:03 +01:00
/**
* Gets the list file to publish.
*
* @return the list file to publish
*/
2020-01-14 12:28:20 +01:00
public List<ZenodoFile> getListFileToPublish() {
if(publishFileVM!=null) {
return publishFileVM.getSelectedFileToZenodoPublishing();
}
return null; //Is null if any resource was attached to dataset
2020-01-10 17:07:03 +01:00
}
2020-01-14 12:28:20 +01:00
2020-01-13 17:48:41 +01:00
/**
* Gets the zenodo item from form.
*
* @return the zenodo item from form
*/
2020-01-14 12:28:20 +01:00
public ZenodoItem getZenodoItemFromFieldsForm() {
// Updating Basic Information
2020-01-13 17:48:41 +01:00
zenodoItem.setTitle(basicForm.getField_title().getValue());
zenodoItem.setDoi(basicForm.getField_doi().getValue());
2020-01-14 12:28:20 +01:00
// Updating Metadata
2020-01-13 17:48:41 +01:00
ZenodoMetadata meta = zenodoItem.getMetadata();
meta.setDescription(basicForm.getField_description().getValue());
2020-01-14 12:28:20 +01:00
meta.setKeywords(basicForm.getTags()); // these are the keywords
2020-01-15 17:51:22 +01:00
//Setting publication date fxing #26166
meta.setPublication_date(basicForm.getField_publication_date().getValue());
2020-01-13 17:48:41 +01:00
List<ZenodoCreator> creators = basicForm.getListOfCreators();
GWT.log("Read creators from FORM: "+creators);
2020-01-13 17:48:41 +01:00
meta.setCreators(creators);
2020-01-15 17:51:22 +01:00
List<ZenodoContributor> contributors = basicForm.getListOfContributors();
GWT.log("Read contributors from FORM: "+contributors);
2020-01-15 17:51:22 +01:00
meta.setContributors(contributors);
2020-01-13 17:48:41 +01:00
2020-01-14 12:28:20 +01:00
// upload type
2020-01-13 17:48:41 +01:00
String uploadType = basicForm.getField_upload_type().getSelectedValue();
2020-01-14 12:28:20 +01:00
if(uploadType!=null)
meta.setUpload_type(new SerializableEnum<>(Arrays.asList(uploadType), meta.getUpload_type().getSelectableValues()));
2020-01-14 12:28:20 +01:00
// publication type
if(basicForm.getCg_publication_type().isVisible()) {
//sets the publication_type only if the field is visible
String publicationType = basicForm.getField_publication_type().getSelectedValue();
if(publicationType!=null)
meta.setPublication_type(new SerializableEnum<>(Arrays.asList(publicationType), meta.getPublication_type().getSelectableValues()));
}
//image type
if(basicForm.getCg_image_type().isVisible()) {
//sets the image_type only if the field is visible
String imageType = basicForm.getField_image_type().getSelectedValue();
if(imageType!=null) {
meta.setImage_type(new SerializableEnum<>(Arrays.asList(imageType), meta.getImage_type().getSelectableValues()));
}
}
2020-01-14 12:28:20 +01:00
// access right
2020-01-13 17:48:41 +01:00
String accessRight = basicForm.getField_access_right().getSelectedValue();
2020-01-14 12:28:20 +01:00
if(accessRight!=null)
meta.setAccess_right(new SerializableEnum<>(Arrays.asList(accessRight), meta.getAccess_right().getSelectableValues()));
2020-01-21 17:07:05 +01:00
//license
String licenseId = basicForm.getField_license().getSelectedValue();
if(licenseId!=null) {
//LicenseDTO licenseBean = new LicenseDTO(licenseId, null, null);
2023-07-28 11:16:23 +02:00
List<String> licenses = new ArrayList<String>();
licenses.add(licenseId);
meta.setLicenseIDs(licenses);
2023-07-27 15:09:39 +02:00
//meta.setLicenses(Arrays.asList(licenseBean));
2020-01-21 17:07:05 +01:00
}
//embargo date
Date embargoDate = basicForm.getEmbargoDate();
if(embargoDate!=null)
meta.setEmbargo_date(embargoDate);
// access condition
String accessCondition = basicForm.getField_access_conditions().getValue();
if(accessCondition!=null)
meta.setAccess_conditions(accessCondition);
2020-01-13 17:48:41 +01:00
zenodoItem.setMetadata(meta);
2020-01-14 12:28:20 +01:00
// Updating list of file for publishing
2020-01-13 17:48:41 +01:00
List<ZenodoFile> publishingFile = getListFileToPublish();
2020-01-31 12:27:14 +01:00
zenodoItem.setFiles(publishingFile);
2020-01-14 12:28:20 +01:00
2020-01-13 17:48:41 +01:00
return zenodoItem;
2020-01-14 12:28:20 +01:00
2020-01-13 17:48:41 +01:00
}
2019-12-16 17:51:37 +01:00
}