Always update of DOI

This commit is contained in:
Fabio Sinibaldi 2020-02-03 18:38:52 +01:00
parent f929862f94
commit 1c051bab6f
2 changed files with 22 additions and 17 deletions

View File

@ -102,10 +102,10 @@ public class Ckan2ZenodoImpl implements Ckan2Zenodo{
// Publishing to zenodo
ZenodoDeposition toReturn =z.publish(dep);
// Updateing item
if(toUpdate.getZenodoDoi()==null) {
toUpdate.setZenodoDoi(CkanRelatedIdentifier.getZenodo(toReturn.getDOIUrl()));
GCat.updateItem(toUpdate);
}
toUpdate.setZenodoDoi(CkanRelatedIdentifier.getZenodo(toReturn.getDOIUrl()));
GCat.updateItem(toUpdate);
return toReturn;
}

View File

@ -44,8 +44,8 @@ public class CkanItemDescriptor {
private static final String MAINTAINER="$.maintainer";
private static final String ITEM_URL="$.extras[?(@.key=='Item URL')].value";
private static final String NAME="$.name";
private static final String ZENODO_DOI="$.extras[?(@.key=='relatedIdentifier:Zenodo.DOI')].value";
private static final String ZENODO_DOI="$.extras[?(@.key=='relatedIdentifier:Zenodo.DOI')]";
private static final String ZENODO_DOI_VALUE="$.extras[?(@.key=='relatedIdentifier:Zenodo.DOI')].value";
@NonNull
@Getter
@ -130,7 +130,7 @@ public class CkanItemDescriptor {
}
private String readRelatedIdentifierString() throws InvalidItemException {
List<String> values=getDocument().read(ZENODO_DOI);
List<String> values=getDocument().read(ZENODO_DOI_VALUE);
if(values==null || values.isEmpty()) return null;
if(values.size()>1) throw new InvalidItemException("Multiple Zenodo Doi found on item.");
return values.get(0);
@ -149,17 +149,22 @@ public class CkanItemDescriptor {
}
public CkanItemDescriptor setZenodoDoi(CkanRelatedIdentifier toSet) throws InvalidItemException {
if(readRelatedIdentifierString()!=null) throw new InvalidItemException("Item already contains Zenodo DOI");
try{
String serialized=mapper.writeValueAsString(toSet);
if(readRelatedIdentifierString()!=null) {
getDocument().put(ZENODO_DOI, "value", serialized);
}else {
JSONObject obj=new JSONObject();
obj.put("key", "relatedIdentifier:Zenodo.DOI");
obj.put("value", serialized);
getDocument().add("$.extras",obj);
content=getDocument().jsonString();
content=getDocument().jsonString();}
return this;
}catch(Throwable t) {
throw new InvalidItemException("Unable to parse item ",t);
throw new InvalidItemException("Unable to set DOI",t);
}
}
}