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

@ -68,12 +68,12 @@ public class Ckan2ZenodoImpl implements Ckan2Zenodo{
} }
if(toUpdate.getSubmitted()&&toUpdate.getState().equals("done")) if(toUpdate.getSubmitted()&&toUpdate.getState().equals("done"))
z.unlockPublished(toUpdate.getId()); z.unlockPublished(toUpdate.getId());
ZenodoDeposition updated=z.updateMetadata(toUpdate); ZenodoDeposition updated=z.updateMetadata(toUpdate);
if(toUpdate.getSubmitted()) if(toUpdate.getSubmitted())
return z.publish(updated); return z.publish(updated);
else return updated; else return updated;
} }
@Override @Override
@ -85,14 +85,14 @@ public class Ckan2ZenodoImpl implements Ckan2Zenodo{
@Override @Override
public Future<ZenodoDeposition> uploadFiles(Set<CkanResource> toUpload, ZenodoDeposition deposition) throws ZenodoException, ConfigurationException { public Future<ZenodoDeposition> uploadFiles(Set<CkanResource> toUpload, ZenodoDeposition deposition) throws ZenodoException, ConfigurationException {
final Zenodo z=getZenodo(); final Zenodo z=getZenodo();
UploadFilesCall call=new UploadFilesCall(toUpload,deposition,z); UploadFilesCall call=new UploadFilesCall(toUpload,deposition,z);
return FileUploaderManager.submitForDeposition(call); return FileUploaderManager.submitForDeposition(call);
} }
@Override @Override
public ZenodoDeposition publish(ZenodoDeposition dep, CkanItemDescriptor toUpdate) throws ZenodoException, ConfigurationException, InvalidItemException, MalformedURLException { public ZenodoDeposition publish(ZenodoDeposition dep, CkanItemDescriptor toUpdate) throws ZenodoException, ConfigurationException, InvalidItemException, MalformedURLException {
@ -102,10 +102,10 @@ public class Ckan2ZenodoImpl implements Ckan2Zenodo{
// Publishing to zenodo // Publishing to zenodo
ZenodoDeposition toReturn =z.publish(dep); ZenodoDeposition toReturn =z.publish(dep);
// Updateing item // Updateing item
if(toUpdate.getZenodoDoi()==null) {
toUpdate.setZenodoDoi(CkanRelatedIdentifier.getZenodo(toReturn.getDOIUrl())); toUpdate.setZenodoDoi(CkanRelatedIdentifier.getZenodo(toReturn.getDOIUrl()));
GCat.updateItem(toUpdate); GCat.updateItem(toUpdate);
}
return toReturn; return toReturn;
} }

View File

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