2019-12-06 17:23:52 +01:00
|
|
|
package org.gcube.portlets.widgets.ckan2zenodopublisher.server;
|
|
|
|
|
2019-12-09 17:17:05 +01:00
|
|
|
import org.gcube.data.publishing.ckan2zenodo.Ckan2ZenodoImpl;
|
|
|
|
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
|
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZendoPublisherWidgetConstant;
|
2019-12-06 17:23:52 +01:00
|
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherService;
|
2019-12-09 17:17:05 +01:00
|
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.server.converter.ItemConverter;
|
2019-12-09 11:56:04 +01:00
|
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.CatalogueItem;
|
2019-12-09 17:17:05 +01:00
|
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoItem;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2019-12-06 17:23:52 +01:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
2019-12-09 17:17:05 +01:00
|
|
|
public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet implements CkanToZenodoPublisherService {
|
2019-12-06 17:23:52 +01:00
|
|
|
|
2019-12-09 17:17:05 +01:00
|
|
|
private static Logger LOG = LoggerFactory.getLogger(CkanToZenodoPublisherServiceImpl.class);
|
2019-12-06 17:23:52 +01:00
|
|
|
|
2019-12-09 17:17:05 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String publishOnZenodo(CatalogueItem item) throws Exception {
|
2019-12-06 17:23:52 +01:00
|
|
|
|
2019-12-09 17:17:05 +01:00
|
|
|
try {
|
2019-12-09 15:42:22 +01:00
|
|
|
|
2019-12-09 17:17:05 +01:00
|
|
|
Ckan2ZenodoImpl.publish(item.getItemName());
|
|
|
|
return null;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error on publishing on Zenodo the catalogue item: "+item.getItemName();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ZenodoItem convertToZenodoItem(CatalogueItem item) throws Exception {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ZenodoDeposition zd = new ZenodoDeposition();
|
|
|
|
return ItemConverter.toZenodoItem(zd);
|
|
|
|
} catch (Exception e) {
|
|
|
|
String error = "Error on converting the catalogue item: "+item.getItemName();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-12-06 17:23:52 +01:00
|
|
|
}
|