Always update of DOI
This commit is contained in:
parent
f929862f94
commit
1c051bab6f
|
@ -68,12 +68,12 @@ public class Ckan2ZenodoImpl implements Ckan2Zenodo{
|
|||
}
|
||||
if(toUpdate.getSubmitted()&&toUpdate.getState().equals("done"))
|
||||
z.unlockPublished(toUpdate.getId());
|
||||
|
||||
|
||||
ZenodoDeposition updated=z.updateMetadata(toUpdate);
|
||||
if(toUpdate.getSubmitted())
|
||||
return z.publish(updated);
|
||||
else return updated;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,14 +85,14 @@ public class Ckan2ZenodoImpl implements Ckan2Zenodo{
|
|||
@Override
|
||||
public Future<ZenodoDeposition> uploadFiles(Set<CkanResource> toUpload, ZenodoDeposition deposition) throws ZenodoException, ConfigurationException {
|
||||
final Zenodo z=getZenodo();
|
||||
|
||||
|
||||
UploadFilesCall call=new UploadFilesCall(toUpload,deposition,z);
|
||||
|
||||
return FileUploaderManager.submitForDeposition(call);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ZenodoDeposition publish(ZenodoDeposition dep, CkanItemDescriptor toUpdate) throws ZenodoException, ConfigurationException, InvalidItemException, MalformedURLException {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
@ -148,18 +148,23 @@ public class CkanItemDescriptor {
|
|||
}
|
||||
}
|
||||
|
||||
public CkanItemDescriptor setZenodoDoi(CkanRelatedIdentifier toSet) throws InvalidItemException {
|
||||
if(readRelatedIdentifierString()!=null) throw new InvalidItemException("Item already contains Zenodo DOI");
|
||||
public CkanItemDescriptor setZenodoDoi(CkanRelatedIdentifier toSet) throws InvalidItemException {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue