Compare commits

...

5 Commits

7 changed files with 314 additions and 214 deletions

View File

@ -4,6 +4,10 @@
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).
## [v1.1.4] - 2023-12-21
- Fixing `publication_date` issue [#26166]
## [v1.1.3] - 2023-07-25
- Fixing `null` issue, recompiling this component [#25275]

View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan2zenodo-publisher-widget</artifactId>
<packaging>jar</packaging>
<version>1.1.3</version>
<version>1.1.4</version>
<description>
gCube Ckan2Zenodo Publisher widget allows to publish D4Science catalogue's items on Zenodo

View File

@ -259,6 +259,8 @@ public class BasicInformationView extends Composite implements FormValidator {
InfoTextAndLabels.addTooltipForFieldKey("description", cl_description);
field_doi.setValue(zenodoItem.getDoi());
GWT.log("Filling form with: "+zenodoItem.getMetadata());
ZenodoMetadata zMeta = zenodoItem.getMetadata();
if (zMeta != null) {

View File

@ -123,6 +123,9 @@ public class Ckan2ZenodoViewManager {
meta.setDescription(basicForm.getField_description().getValue());
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();
GWT.log("Read creators from FORM: "+creators);
meta.setCreators(creators);

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.server;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -64,6 +65,8 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
PortalUtils.getCurrentToken(this.getThreadLocalRequest(), true);
}
LOG.debug("publishOnZenodo called with metadata: "+zenodoItem.getMetadata());
Ckan2Zenodo client = new Ckan2ZenodoImpl();
// Get the item representation
CkanItemDescriptor itemDescr = client.read(zenodoItem.getName());
@ -111,12 +114,22 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
// Step 1 : metadata
client = new Ckan2ZenodoImpl();
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);
// Step 2 : publish Resources
if (toUpload.size() > 0) {
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);
while (!future_Dep.isDone()) {
LOG.debug("Waiting for completed future computation (publishing of resources on Zenodo)...");
Thread.sleep(2000);
@ -126,6 +139,11 @@ public class CkanToZenodoPublisherServiceImpl extends RemoteServiceServlet imple
// Get the item representation
CkanItemDescriptor item = client.read(zenodoItem.getName());
//fixing issue #26166
LOG.debug("Publication_Date before publish is: " + thePublicationDate);
zenodoDepositionPreview.getMetadata().setPublication_date(thePublicationDate);
// Finalize
LOG.debug("Calling publish on Zenodo for: " + zenodoDepositionPreview);
zenodoDepositionPreview = client.publish(zenodoDepositionPreview, item);

View File

@ -35,8 +35,6 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoSubj
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class ItemToZenodoConverter.
*
@ -47,6 +45,7 @@ import org.slf4j.LoggerFactory;
public class ItemToZenodoConverter {
private static Logger LOG = LoggerFactory.getLogger(ItemToZenodoConverter.class);
/**
* **
*
@ -57,7 +56,6 @@ public class ItemToZenodoConverter {
* @return the zenodo item
*/
/**
* To zenodo item.
*
@ -95,7 +93,6 @@ public class ItemToZenodoConverter {
return zi;
}
/**
* Adds the files.
*
@ -135,8 +132,6 @@ public class ItemToZenodoConverter {
return listOfFiles;
}
/**
* To zenodo file.
*
@ -158,7 +153,6 @@ public class ItemToZenodoConverter {
return zf;
}
/**
* To zenodo file.
*
@ -183,7 +177,6 @@ public class ItemToZenodoConverter {
return zf;
}
/**
* To zenodo metadata.
*
@ -199,6 +192,9 @@ public class ItemToZenodoConverter {
zm.setAccess_conditions(depositionMetadata.getAccess_conditions());
zm.setDescription(depositionMetadata.getDescription());
// fixing bug #26165 on publication_date = null
zm.setPublication_date(depositionMetadata.getPublication_date());
// Access Type
AccessRights[] accessRight = null;
if (depositionMetadata.getAccess_right() != null) {
@ -275,7 +271,6 @@ public class ItemToZenodoConverter {
return zm;
}
/**
* To zenodo subjects.
*
@ -317,7 +312,6 @@ public class ItemToZenodoConverter {
return list;
}
/**
* To zenodo date intervals.
*
@ -337,7 +331,8 @@ public class ItemToZenodoConverter {
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;
@ -416,7 +411,6 @@ public class ItemToZenodoConverter {
return list;
}
/**
* To service file deposition.
*
@ -440,7 +434,6 @@ public class ItemToZenodoConverter {
return fileDep;
}
/**
* Update metadata info of deposition metadata.
*
@ -448,7 +441,8 @@ public class ItemToZenodoConverter {
* @param depositionMetadata the deposition metadata
* @return the deposition metadata
*/
public static DepositionMetadata updateMetadataInfoOfDepositionMetadata(ZenodoMetadata metadata, DepositionMetadata depositionMetadata) {
public static DepositionMetadata updateMetadataInfoOfDepositionMetadata(ZenodoMetadata metadata,
DepositionMetadata depositionMetadata) {
// description
String description = metadata.getDescription();
@ -569,7 +563,6 @@ public class ItemToZenodoConverter {
return depositionMetadata;
}
/**
* To creators.
*
@ -639,6 +632,4 @@ public class ItemToZenodoConverter {
return listOfContributors;
}
}

View File

@ -1,19 +1,101 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.time.Instant;
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 static String expression = "^\\/dataset(\\?([a-zA-Z0-9_.-]*.+))*";
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) {
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);
}
}