Doi management
This commit is contained in:
parent
b3865c791e
commit
c2481ec9af
1
pom.xml
1
pom.xml
|
@ -80,7 +80,6 @@
|
|||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.GcatException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.TransformationException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
|
||||
public interface Ckan2Zenodo {
|
||||
|
@ -24,32 +30,40 @@ public interface Ckan2Zenodo {
|
|||
*
|
||||
* @param itemName
|
||||
* @return
|
||||
* @throws GcatException
|
||||
*/
|
||||
public CkanItemDescriptor read(String itemName);
|
||||
public CkanItemDescriptor read(String itemName) throws GcatException;
|
||||
|
||||
/**
|
||||
* Translates @param desc into a ZenodoDeposition using mappings declared in current VRE
|
||||
* Translates @param desc into a ZenodoDeposition using mappings declared in current VRE and previous existing Zenodo Deposition if any
|
||||
*
|
||||
* @param desc
|
||||
* @return
|
||||
* @throws InvalidItemException
|
||||
* @throws ZenodoException
|
||||
* @throws ConfigurationException
|
||||
* @throws TransformationException
|
||||
*/
|
||||
public ZenodoDeposition translate(CkanItemDescriptor desc);
|
||||
public ZenodoDeposition translate(CkanItemDescriptor desc) throws InvalidItemException, ZenodoException, ConfigurationException, TransformationException;
|
||||
|
||||
/**
|
||||
* Create / update metadata of @param toUpdate into the Zenodo instance declared in current VRE
|
||||
*
|
||||
* @param toUpdate
|
||||
* @return
|
||||
* @throws ZenodoException
|
||||
*/
|
||||
public ZenodoDeposition updatedMetadata(ZenodoDeposition toUpdate);
|
||||
public ZenodoDeposition updatedMetadata(ZenodoDeposition toUpdate) throws ZenodoException;
|
||||
|
||||
/**
|
||||
* Filters ckan resources of @param desc by using mappings declared in current VRE
|
||||
*
|
||||
* @param desc
|
||||
* @return
|
||||
* @throws ConfigurationException
|
||||
* @throws TransformationException
|
||||
*/
|
||||
public CkanResource filterResources(CkanItemDescriptor desc);
|
||||
public List<CkanResource> filterResources(CkanItemDescriptor desc) throws ConfigurationException, TransformationException;
|
||||
|
||||
/**
|
||||
* Uploads @param toUpload resources associating them to given @param deposition
|
||||
|
@ -57,8 +71,9 @@ public interface Ckan2Zenodo {
|
|||
* @param toUpload
|
||||
* @param deposition
|
||||
* @return
|
||||
* @throws ZenodoException
|
||||
*/
|
||||
public Future<ZenodoDeposition> uploadFiles(Set<CkanResource> toUpload,ZenodoDeposition deposition);
|
||||
public Future<ZenodoDeposition> uploadFiles(Set<CkanResource> toUpload,ZenodoDeposition deposition) throws ZenodoException;
|
||||
|
||||
/**
|
||||
* Publishes @param dep, setting/updateing DOI reference into @param toUpdate
|
||||
|
@ -66,7 +81,8 @@ public interface Ckan2Zenodo {
|
|||
* @param dep
|
||||
* @param toUpdate
|
||||
* @return
|
||||
* @throws ZenodoException
|
||||
*/
|
||||
public ZenodoDeposition publish(ZenodoDeposition dep, CkanItemDescriptor toUpdate);
|
||||
public ZenodoDeposition publish(ZenodoDeposition dep, CkanItemDescriptor toUpdate) throws ZenodoException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,31 +1,119 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.clients.FileUploaderManager;
|
||||
import org.gcube.data.publishing.ckan2zenodo.clients.GCat;
|
||||
import org.gcube.data.publishing.ckan2zenodo.clients.Zenodo;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.ZenodoCredentials;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanRelatedIdentifier;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.GcatException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.TransformationException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
|
||||
public class Ckan2ZenodoImpl {
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
public static void publish(String itemName) throws MalformedURLException {
|
||||
// looking for gcat..
|
||||
GCat gCat=new GCat();
|
||||
// looking for item
|
||||
CkanItemDescriptor desc=gCat.getByID(itemName);
|
||||
|
||||
//transforming
|
||||
// ZenodoDeposition deposition=TransformerManager.transform(desc);
|
||||
|
||||
// publishing / update to zenodo
|
||||
Zenodo z=new Zenodo(getZenodoToken());
|
||||
|
||||
@Slf4j
|
||||
public class Ckan2ZenodoImpl implements Ckan2Zenodo{
|
||||
|
||||
@Override
|
||||
public CkanItemDescriptor read(String itemName) throws GcatException {
|
||||
try{
|
||||
return GCat.getByID(itemName);
|
||||
}catch(Throwable e) {
|
||||
log.warn("Unable to load "+itemName+" from gCat",e);
|
||||
throw new GcatException("Unable to load item from gCat");
|
||||
}
|
||||
}
|
||||
|
||||
private static final ZenodoCredentials getZenodoToken() {
|
||||
throw new RuntimeException();
|
||||
@Override
|
||||
public ZenodoDeposition translate(CkanItemDescriptor desc) throws InvalidItemException, ZenodoException, ConfigurationException, TransformationException {
|
||||
ZenodoDeposition toUpdate=null;
|
||||
CkanRelatedIdentifier doi=desc.getZenodoDoi();
|
||||
if(doi!=null) {
|
||||
Zenodo z=Zenodo.get();
|
||||
toUpdate=z.readDeposition(doi.getZenodoId());
|
||||
}
|
||||
Translator tr=new TransformerManager().getByProfile(desc.getProfile());
|
||||
return tr.transform(desc, toUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenodoDeposition updatedMetadata(ZenodoDeposition toUpdate) throws ZenodoException {
|
||||
if(toUpdate.getSubmitted())
|
||||
Zenodo.get().unlockPublished(toUpdate.getId());
|
||||
|
||||
return Zenodo.get().updateMetadata(toUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CkanResource> filterResources(CkanItemDescriptor desc) throws ConfigurationException, TransformationException {
|
||||
Translator tr=new TransformerManager().getByProfile(desc.getProfile());
|
||||
return tr.filterResources(desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<ZenodoDeposition> uploadFiles(Set<CkanResource> toUpload, ZenodoDeposition deposition) throws ZenodoException {
|
||||
final Zenodo z=Zenodo.get();
|
||||
|
||||
if(deposition.getSubmitted())
|
||||
Zenodo.get().unlockPublished(deposition.getId());
|
||||
|
||||
Callable<ZenodoDeposition> call=new Callable<ZenodoDeposition>() {
|
||||
@Override
|
||||
public ZenodoDeposition call() throws Exception {
|
||||
ZenodoDeposition dep=deposition;
|
||||
for(CkanResource r:toUpload) {
|
||||
try {
|
||||
dep.getFiles().add(z.uploadFile(dep, r.getName(), r.getUrl()));
|
||||
}catch(Throwable t) {
|
||||
throw new Exception("Unable to upload "+r.getName()+".",t);
|
||||
}
|
||||
}
|
||||
return z.readDeposition(dep.getId());
|
||||
}
|
||||
};
|
||||
|
||||
return FileUploaderManager.submitForDeposition(call);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenodoDeposition publish(ZenodoDeposition dep, CkanItemDescriptor toUpdate) throws ZenodoException {
|
||||
if(dep.getSubmitted())
|
||||
Zenodo.get().unlockPublished(dep.getId());
|
||||
|
||||
return Zenodo.get().publish(dep);
|
||||
}
|
||||
|
||||
|
||||
// public static void preview(String itemName) throws MalformedURLException {
|
||||
// // looking for gcat..
|
||||
// GCat gCat=new GCat();
|
||||
// // looking for item
|
||||
// CkanItemDescriptor desc=gCat.getByID(itemName);
|
||||
//
|
||||
// //transforming
|
||||
//// ZenodoDeposition deposition=TransformerManager.transform(desc);
|
||||
//
|
||||
// // publishing / update to zenodo
|
||||
// Zenodo z=new Zenodo(getZenodoToken());
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private static final ZenodoCredentials getZenodoToken() {
|
||||
// throw new RuntimeException();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.data.publishing.ckan2zenodo.commons.IS;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
||||
|
||||
import lombok.Synchronized;
|
||||
|
||||
|
@ -25,12 +26,12 @@ public class TransformerManager {
|
|||
return builder;
|
||||
}
|
||||
|
||||
public Translator getByProfile(String profile) throws Exception {
|
||||
public Translator getByProfile(String profile) throws ConfigurationException {
|
||||
for(GenericResource r: IS.queryForGenericResources("Ckan-Zenodo-Mappings")){
|
||||
if (r.profile().name().equals(profile))
|
||||
return new Translator(IS.readMappings(r),IS.readResourceFilters(r));
|
||||
}
|
||||
throw new Exception("No transformer found for profile "+profile);
|
||||
throw new ConfigurationException("No transformer found for profile "+profile);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.concurrent.Callable;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
|
@ -14,19 +13,22 @@ import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
|||
|
||||
public class FileUploaderManager {
|
||||
|
||||
static ExecutorService service=null;
|
||||
static ExecutorService uploadService=null;
|
||||
static ExecutorService requestService=null;
|
||||
|
||||
|
||||
static {
|
||||
service=Executors.newFixedThreadPool(Integer.parseInt(LocalConfiguration.getProperty(Configuration.THREAD_POOL_SIZE)));
|
||||
uploadService=Executors.newFixedThreadPool(Integer.parseInt(LocalConfiguration.getProperty(Configuration.THREAD_POOL_SIZE))*3);
|
||||
requestService=Executors.newFixedThreadPool(Integer.parseInt(LocalConfiguration.getProperty(Configuration.THREAD_POOL_SIZE)));
|
||||
}
|
||||
|
||||
public FutureTask<ZenodoDeposition> createTask(Callable<ZenodoDeposition> call ){
|
||||
return new FutureTask<ZenodoDeposition> (call);
|
||||
public static Future<ZenodoDeposition> submitForDeposition(Callable<ZenodoDeposition> call ){
|
||||
return requestService.submit(call);
|
||||
}
|
||||
|
||||
|
||||
public static Future<Response> submit(Callable<Response> call){
|
||||
return service.submit(call);
|
||||
public static Future<Response> submitForResponse(Callable<Response> call){
|
||||
return uploadService.submit(call);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,9 @@ public class Zenodo {
|
|||
private static final String PUBLISH_URL_PRE="deposit/depositions";
|
||||
private static final String PUBLISH_URL_POST="actions/publish";
|
||||
|
||||
private static final String UNLOCK_URL_PRE="deposit/depositions";
|
||||
private static final String UNLOCK_URL_POST="actions/edit";
|
||||
|
||||
private static final String ACCESS_TOKEN="access_token";
|
||||
|
||||
private static ObjectMapper mapper = new ObjectMapper();
|
||||
|
@ -58,6 +61,12 @@ public class Zenodo {
|
|||
}
|
||||
|
||||
|
||||
public static final Zenodo get() {
|
||||
// READ FROM IS
|
||||
throw new RuntimeException("IMPLEMENT THIS");
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
private ZenodoCredentials credentials;
|
||||
|
||||
|
@ -72,9 +81,9 @@ public class Zenodo {
|
|||
return client;
|
||||
}
|
||||
|
||||
public ZenodoDeposition readDeposition(String id) throws ZenodoException {
|
||||
public ZenodoDeposition readDeposition(Integer id) throws ZenodoException {
|
||||
Response resp= getWebClient().target(credentials.getBaseUrl()).
|
||||
path(DEPOSITION_BASE_URL).path(id).
|
||||
path(DEPOSITION_BASE_URL).path(id+"").
|
||||
queryParam(ACCESS_TOKEN, credentials.getKey()).request(CONTENT_TYPE)
|
||||
.get();
|
||||
return check(resp,ZenodoDeposition.class);
|
||||
|
@ -95,7 +104,7 @@ public class Zenodo {
|
|||
}
|
||||
}
|
||||
|
||||
public ZenodoDeposition updateMetadata(ZenodoDeposition dep) throws ZenodoException, JsonProcessingException {
|
||||
public ZenodoDeposition updateMetadata(ZenodoDeposition dep) throws ZenodoException {
|
||||
return updateMetadata(dep.getId(), dep.getMetadata());
|
||||
}
|
||||
|
||||
|
@ -141,7 +150,7 @@ public class Zenodo {
|
|||
|
||||
|
||||
log.debug("Submitting request to upload "+urlString+" to Manager");
|
||||
Future<Response> resp=FileUploaderManager.submit(call);
|
||||
Future<Response> resp=FileUploaderManager.submitForResponse(call);
|
||||
|
||||
try {
|
||||
return check(resp.get(),FileDeposition.class);
|
||||
|
@ -155,7 +164,8 @@ public class Zenodo {
|
|||
|
||||
}
|
||||
|
||||
private ZenodoDeposition updateMetadata(Integer depositionId,DepositionMetadata meta) throws ZenodoException, JsonProcessingException {
|
||||
private ZenodoDeposition updateMetadata(Integer depositionId,DepositionMetadata meta) throws ZenodoException {
|
||||
try{
|
||||
String serialized="{\"metadata\":"+Fixer.fixIncoming(mapper.writeValueAsString(meta))+"}";
|
||||
try {
|
||||
Response resp = getWebClient().target(credentials.getBaseUrl()).
|
||||
|
@ -167,6 +177,20 @@ public class Zenodo {
|
|||
log.debug("Error while tryin to update "+serialized);
|
||||
throw t;
|
||||
}
|
||||
}catch(JsonProcessingException e) {
|
||||
log.debug("Error while parsing "+meta,e);
|
||||
throw new ZenodoException("Internal error.",e);
|
||||
}
|
||||
}
|
||||
|
||||
public ZenodoDeposition unlockPublished(Integer depositionId) throws ZenodoException {
|
||||
Response resp = getWebClient().target(credentials.getBaseUrl()).
|
||||
path(UNLOCK_URL_PRE).
|
||||
path(depositionId+"").
|
||||
path(UNLOCK_URL_POST).
|
||||
queryParam(ACCESS_TOKEN, credentials.getKey()).request(CONTENT_TYPE)
|
||||
.post(Entity.json("{}"));
|
||||
return check(resp,ZenodoDeposition.class);
|
||||
}
|
||||
|
||||
public void deleteDeposition(Integer depositionId) throws ZenodoException {
|
||||
|
|
|
@ -2,18 +2,30 @@ package org.gcube.data.publishing.ckan2zenodo.model;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.commons.Parsing;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.jayway.jsonpath.ReadContext;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minidev.json.JSONObject;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CkanItemDescriptor {
|
||||
|
||||
static private ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper=Parsing.getMapper();
|
||||
}
|
||||
|
||||
|
||||
private static final String PROFILE="$.extras[?(@.key=='system:type')].value";
|
||||
private static final String TITLE="$.title";
|
||||
private static final String NOTES="$.notes";
|
||||
|
@ -30,6 +42,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";
|
||||
|
||||
|
||||
@NonNull
|
||||
@Getter
|
||||
|
@ -37,10 +51,10 @@ public class CkanItemDescriptor {
|
|||
|
||||
|
||||
@Getter(lazy=true)
|
||||
private final ReadContext document=document();
|
||||
private final DocumentContext document=document();
|
||||
|
||||
|
||||
private ReadContext document() {
|
||||
private DocumentContext document() {
|
||||
return JsonPath.parse(content);
|
||||
}
|
||||
|
||||
|
@ -112,4 +126,38 @@ public class CkanItemDescriptor {
|
|||
if(values==null) return null;
|
||||
return values.get(0);
|
||||
}
|
||||
|
||||
private String readRelatedIdentifierString() throws InvalidItemException {
|
||||
List<String> values=getDocument().read(ZENODO_DOI);
|
||||
if(values==null || values.isEmpty()) return null;
|
||||
if(values.size()>1) throw new InvalidItemException("Multiple Zenodo Doi found on item.");
|
||||
return values.get(0);
|
||||
}
|
||||
|
||||
public CkanRelatedIdentifier getZenodoDoi() throws InvalidItemException {
|
||||
try{
|
||||
String s=readRelatedIdentifierString();
|
||||
if(s==null) return null;
|
||||
return mapper.readValue(s, CkanRelatedIdentifier.class);
|
||||
}catch(InvalidItemException e) {
|
||||
throw e;
|
||||
}catch(Throwable t) {
|
||||
throw new InvalidItemException("Unable to parse item ",t);
|
||||
}
|
||||
}
|
||||
|
||||
public CkanItemDescriptor setZenodoDoi(CkanRelatedIdentifier toSet) throws InvalidItemException {
|
||||
if(readRelatedIdentifierString()!=null) throw new InvalidItemException("Item already contains Zenodo DOI");
|
||||
try{
|
||||
String serialized=mapper.writeValueAsString(toSet);
|
||||
JSONObject obj=new JSONObject();
|
||||
obj.put("key", "relatedIdentifier:Zenodo.DOI");
|
||||
obj.put("value", serialized);
|
||||
getDocument().add("$.extras",obj);
|
||||
content=getDocument().jsonString();
|
||||
return this;
|
||||
}catch(Throwable t) {
|
||||
throw new InvalidItemException("Unable to parse item ",t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class CkanRelatedIdentifier {
|
||||
|
||||
public static CkanRelatedIdentifier getZenodo(String doi) {
|
||||
return new CkanRelatedIdentifier("URL", "isReferencedBy", doi);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String relatedIdentifierType;
|
||||
@NonNull
|
||||
private String relationType;
|
||||
@NonNull
|
||||
private String link;
|
||||
|
||||
public Integer getZenodoId() {
|
||||
return Integer.parseInt(link.substring(link.lastIndexOf(".")+1));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo.model.faults;
|
||||
|
||||
public class GcatException extends Exception {
|
||||
|
||||
public GcatException() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public GcatException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
|
||||
super(arg0, arg1, arg2, arg3);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public GcatException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public GcatException(String arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public GcatException(Throwable arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.data.publishing.ckan2zenodo.model.faults;
|
||||
|
||||
public class InvalidItemException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 956698656847887456L;
|
||||
|
||||
public InvalidItemException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public InvalidItemException(String arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public InvalidItemException(Throwable arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public InvalidItemException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public InvalidItemException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
|
||||
super(arg0, arg1, arg2, arg3);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
|
@ -26,4 +26,5 @@ public class ZenodoDeposition {
|
|||
private Boolean submitted;
|
||||
private String title;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package org.gcube.tests;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.gcube.data.publishing.ckan2zenodo.Ckan2Zenodo;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.GcatException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.TransformationException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
|
||||
public class OneHitTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws GcatException, InvalidItemException, ZenodoException, ConfigurationException, TransformationException, InterruptedException, ExecutionException {
|
||||
TokenSetter.set("/pred4s/preprod/preVRE");
|
||||
Ckan2Zenodo client=Ckan2Zenodo.get();
|
||||
String toPublishItemName="my_item";
|
||||
|
||||
// Get the item representation
|
||||
CkanItemDescriptor item=client.read(toPublishItemName);
|
||||
|
||||
//Get a preview of the deposition to be published
|
||||
ZenodoDeposition preview=client.translate(item);
|
||||
|
||||
//Filter resources according to VRE policies
|
||||
List<CkanResource> toFilter=client.filterResources(item);
|
||||
|
||||
|
||||
//Eventually update values
|
||||
preview.getMetadata().setAccess_conditions("Ask me");
|
||||
|
||||
//Actually publish to zenodo :
|
||||
// Step 1 : metadata
|
||||
|
||||
preview=client.updatedMetadata(preview);
|
||||
|
||||
//Step 2 : publish Resources
|
||||
Future<ZenodoDeposition> future_Dep=client.uploadFiles(Collections.singleton(toFilter.get(0)), preview);
|
||||
preview=future_Dep.get();
|
||||
|
||||
//Finalize
|
||||
|
||||
client.publish(preview, item);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -9,8 +9,12 @@ import java.util.List;
|
|||
|
||||
import org.gcube.data.publishing.ckan2zenodo.Fixer;
|
||||
import org.gcube.data.publishing.ckan2zenodo.commons.Parsing;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanRelatedIdentifier;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.RelatedIdentifier;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -131,4 +135,16 @@ public class ParsingTests {
|
|||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void addDOI() throws InvalidItemException {
|
||||
String json=TestCommons.convertStreamToString(TransformationTests.class.getResourceAsStream("/ResearchObject.json"));
|
||||
CkanItemDescriptor desc=new CkanItemDescriptor(json);
|
||||
Assert.assertNull(desc.getZenodoDoi());
|
||||
desc.setZenodoDoi(new CkanRelatedIdentifier("URL", "isReferencedBy", "http://some.dumb.link.com"));
|
||||
CkanRelatedIdentifier id=desc.getZenodoDoi();
|
||||
Assert.assertNotNull(id);
|
||||
System.out.println(desc.getContent());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.gcube.data.publishing.ckan2zenodo.Translator;
|
|||
import org.gcube.data.publishing.ckan2zenodo.clients.Zenodo;
|
||||
import org.gcube.data.publishing.ckan2zenodo.commons.IS;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanRelatedIdentifier;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.ZenodoCredentials;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
||||
|
@ -20,10 +21,13 @@ import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata.Acc
|
|||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata.UploadType;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.FileDeposition;
|
||||
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
|
||||
public class ZenodoTests {
|
||||
|
||||
|
@ -43,7 +47,7 @@ public class ZenodoTests {
|
|||
|
||||
Zenodo z=new Zenodo(credentials);
|
||||
|
||||
System.out.println(z.readDeposition("426312"));
|
||||
System.out.println(z.readDeposition(426312));
|
||||
|
||||
|
||||
}
|
||||
|
@ -89,4 +93,48 @@ public class ZenodoTests {
|
|||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateExisting() throws ConfigurationException, Exception {
|
||||
// publish new
|
||||
Zenodo z=new Zenodo(credentials);
|
||||
|
||||
GenericResource res=Resources.unmarshal(GenericResource.class, TransformationTests.class.getResourceAsStream("/ResearchObject.xml"));
|
||||
ZenodoDeposition dep=z.createNew();
|
||||
Translator tran=new Translator(IS.readMappings(res),IS.readResourceFilters(res));
|
||||
dep=TestCommons.readAndTransform("/ResearchObject.json", tran,dep);
|
||||
dep=z.updateMetadata(dep);
|
||||
|
||||
System.out.println("Resulting Deposition with metadata : ");
|
||||
System.out.println();
|
||||
String json=TestCommons.convertStreamToString(TransformationTests.class.getResourceAsStream("/ResearchObject.json"));
|
||||
CkanItemDescriptor desc=new CkanItemDescriptor(json);
|
||||
|
||||
for(CkanResource cRes:tran.filterResources(desc)) {
|
||||
FileDeposition file=z.uploadFile(dep, cRes.getName(), cRes.getUrl());
|
||||
System.out.println("Published "+file);
|
||||
}
|
||||
dep=z.publish(dep);
|
||||
|
||||
desc.setZenodoDoi(CkanRelatedIdentifier.getZenodo(dep.getDoi()));
|
||||
|
||||
// Change title
|
||||
String fakeTitle="Dummy Title";
|
||||
|
||||
String modifiedJson=JsonPath.parse(desc.getContent()).put("$", "title", fakeTitle).jsonString();
|
||||
desc=new CkanItemDescriptor(modifiedJson);
|
||||
// Publish logic :
|
||||
|
||||
Assert.assertNotNull(desc);
|
||||
Assert.assertNotNull(desc.getZenodoDoi());
|
||||
Assert.assertEquals(fakeTitle, desc.getTitle());
|
||||
|
||||
dep=z.readDeposition(desc.getZenodoDoi().getZenodoId());
|
||||
dep=tran.transform(desc, dep);
|
||||
z.unlockPublished(dep.getId());
|
||||
System.out.println(z.updateMetadata(dep));
|
||||
dep=z.publish(dep);
|
||||
Assert.assertEquals(fakeTitle, dep.getTitle());
|
||||
System.out.println(dep);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue