Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Francesco Mangiacrapa | c807442378 | |
Francesco Mangiacrapa | 114c753ca4 | |
Francesco Mangiacrapa | 88975d12f4 | |
Francesco Mangiacrapa | 74dcfe6e9c | |
Francesco Mangiacrapa | 4eb65dc4ed |
|
@ -4,6 +4,10 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v1.1.4] - 2023-12-21
|
||||||
|
|
||||||
|
- Fixing `publication_date` issue [#26166]
|
||||||
|
|
||||||
## [v1.1.3] - 2023-07-25
|
## [v1.1.3] - 2023-07-25
|
||||||
|
|
||||||
- Fixing `null` issue, recompiling this component [#25275]
|
- Fixing `null` issue, recompiling this component [#25275]
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -14,7 +14,7 @@
|
||||||
<groupId>org.gcube.portlets.widgets</groupId>
|
<groupId>org.gcube.portlets.widgets</groupId>
|
||||||
<artifactId>ckan2zenodo-publisher-widget</artifactId>
|
<artifactId>ckan2zenodo-publisher-widget</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.1.3</version>
|
<version>1.1.4</version>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
gCube Ckan2Zenodo Publisher widget allows to publish D4Science catalogue's items on Zenodo
|
gCube Ckan2Zenodo Publisher widget allows to publish D4Science catalogue's items on Zenodo
|
||||||
|
|
|
@ -259,6 +259,8 @@ public class BasicInformationView extends Composite implements FormValidator {
|
||||||
InfoTextAndLabels.addTooltipForFieldKey("description", cl_description);
|
InfoTextAndLabels.addTooltipForFieldKey("description", cl_description);
|
||||||
field_doi.setValue(zenodoItem.getDoi());
|
field_doi.setValue(zenodoItem.getDoi());
|
||||||
|
|
||||||
|
GWT.log("Filling form with: "+zenodoItem.getMetadata());
|
||||||
|
|
||||||
ZenodoMetadata zMeta = zenodoItem.getMetadata();
|
ZenodoMetadata zMeta = zenodoItem.getMetadata();
|
||||||
if (zMeta != null) {
|
if (zMeta != null) {
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,9 @@ public class Ckan2ZenodoViewManager {
|
||||||
meta.setDescription(basicForm.getField_description().getValue());
|
meta.setDescription(basicForm.getField_description().getValue());
|
||||||
meta.setKeywords(basicForm.getTags()); // these are the keywords
|
meta.setKeywords(basicForm.getTags()); // these are the keywords
|
||||||
|
|
||||||
|
//Setting publication date fxing #26166
|
||||||
|
meta.setPublication_date(basicForm.getField_publication_date().getValue());
|
||||||
|
|
||||||
List<ZenodoCreator> creators = basicForm.getListOfCreators();
|
List<ZenodoCreator> creators = basicForm.getListOfCreators();
|
||||||
GWT.log("Read creators from FORM: "+creators);
|
GWT.log("Read creators from FORM: "+creators);
|
||||||
meta.setCreators(creators);
|
meta.setCreators(creators);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.portlets.widgets.ckan2zenodopublisher.server;
|
package org.gcube.portlets.widgets.ckan2zenodopublisher.server;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -64,6 +65,8 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
|
||||||
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
|
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG.debug("publishOnZenodo called with metadata: "+zenodoItem.getMetadata());
|
||||||
|
|
||||||
Ckan2Zenodo client = new Ckan2ZenodoImpl();
|
Ckan2Zenodo client = new Ckan2ZenodoImpl();
|
||||||
// Get the item representation
|
// Get the item representation
|
||||||
CkanItemDescriptor itemDescr = client.read(zenodoItem.getName());
|
CkanItemDescriptor itemDescr = client.read(zenodoItem.getName());
|
||||||
|
@ -111,12 +114,22 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
|
||||||
// Step 1 : metadata
|
// Step 1 : metadata
|
||||||
client = new Ckan2ZenodoImpl();
|
client = new Ckan2ZenodoImpl();
|
||||||
LOG.debug("Calling updatedMetadata for: " + zenodoDepositionPreview);
|
LOG.debug("Calling updatedMetadata for: " + zenodoDepositionPreview);
|
||||||
|
|
||||||
|
//fixing issue #26166
|
||||||
|
Date thePublicationDate = zenodoDepositionPreview.getMetadata().getPublication_date();
|
||||||
|
LOG.debug("Publication_Date before update is: " + thePublicationDate);
|
||||||
|
|
||||||
zenodoDepositionPreview = client.updatedMetadata(zenodoDepositionPreview);
|
zenodoDepositionPreview = client.updatedMetadata(zenodoDepositionPreview);
|
||||||
|
|
||||||
// Step 2 : publish Resources
|
// Step 2 : publish Resources
|
||||||
if (toUpload.size() > 0) {
|
if (toUpload.size() > 0) {
|
||||||
LOG.debug("Trying to publish the set of CKAN resources: " + toUpload.toString());
|
LOG.debug("Trying to publish the set of CKAN resources: " + toUpload.toString());
|
||||||
|
|
||||||
|
//fixing issue #26166
|
||||||
|
zenodoDepositionPreview.getMetadata().setPublication_date(thePublicationDate);
|
||||||
|
LOG.debug("Publication_Date before uploadFiles is: " + zenodoDepositionPreview.getMetadata().getPublication_date());
|
||||||
Future<ZenodoDeposition> future_Dep = client.uploadFiles(toUpload, zenodoDepositionPreview);
|
Future<ZenodoDeposition> future_Dep = client.uploadFiles(toUpload, zenodoDepositionPreview);
|
||||||
|
|
||||||
while (!future_Dep.isDone()) {
|
while (!future_Dep.isDone()) {
|
||||||
LOG.debug("Waiting for completed future computation (publishing of resources on Zenodo)...");
|
LOG.debug("Waiting for completed future computation (publishing of resources on Zenodo)...");
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
|
@ -126,6 +139,11 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
|
||||||
|
|
||||||
// Get the item representation
|
// Get the item representation
|
||||||
CkanItemDescriptor item = client.read(zenodoItem.getName());
|
CkanItemDescriptor item = client.read(zenodoItem.getName());
|
||||||
|
|
||||||
|
//fixing issue #26166
|
||||||
|
LOG.debug("Publication_Date before publish is: " + thePublicationDate);
|
||||||
|
zenodoDepositionPreview.getMetadata().setPublication_date(thePublicationDate);
|
||||||
|
|
||||||
// Finalize
|
// Finalize
|
||||||
LOG.debug("Calling publish on Zenodo for: " + zenodoDepositionPreview);
|
LOG.debug("Calling publish on Zenodo for: " + zenodoDepositionPreview);
|
||||||
zenodoDepositionPreview = client.publish(zenodoDepositionPreview, item);
|
zenodoDepositionPreview = client.publish(zenodoDepositionPreview, item);
|
||||||
|
|
|
@ -35,8 +35,6 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoSubj
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class ItemToZenodoConverter.
|
* The Class ItemToZenodoConverter.
|
||||||
*
|
*
|
||||||
|
@ -47,6 +45,7 @@ import org.slf4j.LoggerFactory;
|
||||||
public class ItemToZenodoConverter {
|
public class ItemToZenodoConverter {
|
||||||
|
|
||||||
private static Logger LOG = LoggerFactory.getLogger(ItemToZenodoConverter.class);
|
private static Logger LOG = LoggerFactory.getLogger(ItemToZenodoConverter.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* **
|
* **
|
||||||
*
|
*
|
||||||
|
@ -57,7 +56,6 @@ public class ItemToZenodoConverter {
|
||||||
* @return the zenodo item
|
* @return the zenodo item
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To zenodo item.
|
* To zenodo item.
|
||||||
*
|
*
|
||||||
|
@ -95,7 +93,6 @@ public class ItemToZenodoConverter {
|
||||||
return zi;
|
return zi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the files.
|
* Adds the files.
|
||||||
*
|
*
|
||||||
|
@ -135,8 +132,6 @@ public class ItemToZenodoConverter {
|
||||||
return listOfFiles;
|
return listOfFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To zenodo file.
|
* To zenodo file.
|
||||||
*
|
*
|
||||||
|
@ -158,7 +153,6 @@ public class ItemToZenodoConverter {
|
||||||
return zf;
|
return zf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To zenodo file.
|
* To zenodo file.
|
||||||
*
|
*
|
||||||
|
@ -183,7 +177,6 @@ public class ItemToZenodoConverter {
|
||||||
return zf;
|
return zf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To zenodo metadata.
|
* To zenodo metadata.
|
||||||
*
|
*
|
||||||
|
@ -199,6 +192,9 @@ public class ItemToZenodoConverter {
|
||||||
zm.setAccess_conditions(depositionMetadata.getAccess_conditions());
|
zm.setAccess_conditions(depositionMetadata.getAccess_conditions());
|
||||||
zm.setDescription(depositionMetadata.getDescription());
|
zm.setDescription(depositionMetadata.getDescription());
|
||||||
|
|
||||||
|
// fixing bug #26165 on publication_date = null
|
||||||
|
zm.setPublication_date(depositionMetadata.getPublication_date());
|
||||||
|
|
||||||
// Access Type
|
// Access Type
|
||||||
AccessRights[] accessRight = null;
|
AccessRights[] accessRight = null;
|
||||||
if (depositionMetadata.getAccess_right() != null) {
|
if (depositionMetadata.getAccess_right() != null) {
|
||||||
|
@ -275,7 +271,6 @@ public class ItemToZenodoConverter {
|
||||||
return zm;
|
return zm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To zenodo subjects.
|
* To zenodo subjects.
|
||||||
*
|
*
|
||||||
|
@ -317,7 +312,6 @@ public class ItemToZenodoConverter {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To zenodo date intervals.
|
* To zenodo date intervals.
|
||||||
*
|
*
|
||||||
|
@ -337,7 +331,8 @@ public class ItemToZenodoConverter {
|
||||||
types = CkanToZenodoUtil.toSerializableEnum(rel, DateInterval.Type.values());
|
types = CkanToZenodoUtil.toSerializableEnum(rel, DateInterval.Type.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
list.add(new ZenodoDateInterval(dateInterval.getStart(), dateInterval.getEnd(), types, dateInterval.getDescription()));
|
list.add(new ZenodoDateInterval(dateInterval.getStart(), dateInterval.getEnd(), types,
|
||||||
|
dateInterval.getDescription()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
@ -416,7 +411,6 @@ public class ItemToZenodoConverter {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To service file deposition.
|
* To service file deposition.
|
||||||
*
|
*
|
||||||
|
@ -440,7 +434,6 @@ public class ItemToZenodoConverter {
|
||||||
return fileDep;
|
return fileDep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update metadata info of deposition metadata.
|
* Update metadata info of deposition metadata.
|
||||||
*
|
*
|
||||||
|
@ -448,7 +441,8 @@ public class ItemToZenodoConverter {
|
||||||
* @param depositionMetadata the deposition metadata
|
* @param depositionMetadata the deposition metadata
|
||||||
* @return the deposition metadata
|
* @return the deposition metadata
|
||||||
*/
|
*/
|
||||||
public static DepositionMetadata updateMetadataInfoOfDepositionMetadata(ZenodoMetadata metadata, DepositionMetadata depositionMetadata) {
|
public static DepositionMetadata updateMetadataInfoOfDepositionMetadata(ZenodoMetadata metadata,
|
||||||
|
DepositionMetadata depositionMetadata) {
|
||||||
|
|
||||||
// description
|
// description
|
||||||
String description = metadata.getDescription();
|
String description = metadata.getDescription();
|
||||||
|
@ -569,7 +563,6 @@ public class ItemToZenodoConverter {
|
||||||
return depositionMetadata;
|
return depositionMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To creators.
|
* To creators.
|
||||||
*
|
*
|
||||||
|
@ -639,6 +632,4 @@ public class ItemToZenodoConverter {
|
||||||
return listOfContributors;
|
return listOfContributors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,101 @@
|
||||||
package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
|
package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.time.Instant;
|
||||||
import java.util.regex.Pattern;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.Entity;
|
||||||
|
|
||||||
|
import org.gcube.data.publishing.ckan2zenodo.Fixer;
|
||||||
|
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
|
||||||
|
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata;
|
||||||
|
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
public class Tester {
|
public class Tester {
|
||||||
|
|
||||||
public static String expression = "^\\/dataset(\\?([a-zA-Z0-9_.-]*.+))*";
|
public static String expression = "^\\/dataset(\\?([a-zA-Z0-9_.-]*.+))*";
|
||||||
public static String toMatch = "/dataset?systemtype=E39_Actor&groups=huma_num___nakala";
|
public static String toMatch = "/dataset?systemtype=E39_Actor&groups=huma_num___nakala";
|
||||||
|
|
||||||
|
private static ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||||
|
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
|
||||||
|
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||||
|
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
// Pattern p = Pattern.compile(expression);
|
||||||
|
// Matcher m = p.matcher(toMatch);
|
||||||
|
// boolean b = m.matches();
|
||||||
|
//
|
||||||
|
// System.out.println(b);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Pattern p = Pattern.compile(expression);
|
|
||||||
Matcher m = p.matcher(toMatch);
|
|
||||||
boolean b = m.matches();
|
|
||||||
|
|
||||||
System.out.println(b);
|
//ObjectMapper mapper = new ObjectMapper();
|
||||||
|
ZenodoDeposition zed = new ZenodoDeposition();
|
||||||
|
DepositionMetadata metadata = new DepositionMetadata();
|
||||||
|
metadata.setPublication_date(Date.from(Instant.now()));
|
||||||
|
//zed.setMetadata(metadata);
|
||||||
|
|
||||||
|
String serialized;
|
||||||
|
try {
|
||||||
|
System.out.println("init json: "+mapper.writeValueAsString(metadata));
|
||||||
|
|
||||||
|
serialized = "{\"metadata\":"+Fixer.fixIncoming(mapper.writeValueAsString(metadata))+"}";
|
||||||
|
System.out.println("serialized: "+serialized);
|
||||||
|
|
||||||
|
Entity<String> JSON = Entity.json(serialized);
|
||||||
|
System.out.println("JSON: "+JSON);
|
||||||
|
ZenodoDeposition object = mapper.readValue(Fixer.fixIncoming(serialized), ZenodoDeposition.class);
|
||||||
|
System.out.println("ZenodoDeposition: "+object);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//System.out.println(metadata.getPublication_date());
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// updateMetadata(metadata);
|
||||||
|
// } catch (ZenodoException e) {
|
||||||
|
// // TODO Auto-generated catch block
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ZenodoDeposition updateMetadata(DepositionMetadata meta) throws ZenodoException {
|
||||||
|
try{
|
||||||
|
String serialized="{\"metadata\":"+Fixer.fixIncoming(mapper.writeValueAsString(meta))+"}";
|
||||||
|
System.out.println("serialized: "+serialized);
|
||||||
|
try {
|
||||||
|
// Response resp = getWebClient().target(credentials.getBaseUrl()).
|
||||||
|
// path(DEPOSITION_BASE_URL).path(depositionId+"").
|
||||||
|
// queryParam(ACCESS_TOKEN, credentials.getKey()).request(CONTENT_TYPE)
|
||||||
|
// .put(Entity.json(serialized));
|
||||||
|
// return check(resp,ZenodoDeposition.class);
|
||||||
|
|
||||||
|
Entity<String> JSON = Entity.json(serialized);
|
||||||
|
System.out.println("JSON: "+JSON);
|
||||||
|
return mapper.readValue(Fixer.fixIncoming(serialized), ZenodoDeposition.class);
|
||||||
|
}catch(Throwable t) {
|
||||||
|
System.out.println("Error while tryin to update "+serialized);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}catch(JsonProcessingException e) {
|
||||||
|
System.out.println("Error while parsing "+meta + " " +e);
|
||||||
|
throw new ZenodoException("Internal error.",e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue