Default translation management
This commit is contained in:
parent
18333060ec
commit
a44ae2b201
|
@ -3,6 +3,7 @@
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Enhancements
|
### Enhancements
|
||||||
- Default Ckan2Zenodo translation to comply with mandatory Zenodo fields (https://support.d4science.org/issues/19489)
|
- Default Ckan2Zenodo translation to comply with mandatory Zenodo fields (https://support.d4science.org/issues/19489)
|
||||||
|
- Ckan2Zenodo library to provide means to apply default translation only (https://support.d4science.org/issues/19490)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,18 @@ public interface Ckan2Zenodo {
|
||||||
*/
|
*/
|
||||||
public ZenodoDeposition translate(CkanItemDescriptor desc) throws InvalidItemException, ZenodoException, ConfigurationException, TransformationException;
|
public ZenodoDeposition translate(CkanItemDescriptor desc) throws InvalidItemException, ZenodoException, ConfigurationException, TransformationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces translation of passed @param desc without raising Configuration Exception
|
||||||
|
*
|
||||||
|
* @param desc
|
||||||
|
* @return *
|
||||||
|
* @throws TransformationException
|
||||||
|
* @throws ZenodoException
|
||||||
|
* @throws InvalidItemException
|
||||||
|
*/
|
||||||
|
public ZenodoDeposition forceTranslation(CkanItemDescriptor desc) throws InvalidItemException, ZenodoException, TransformationException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create / update metadata of @param toUpdate into the Zenodo instance declared in current VRE
|
* Create / update metadata of @param toUpdate into the Zenodo instance declared in current VRE
|
||||||
*
|
*
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.gcube.data.publishing.ckan2zenodo.clients.Zenodo;
|
||||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
import org.gcube.data.publishing.ckan2zenodo.model.CkanItemDescriptor;
|
||||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanRelatedIdentifier;
|
import org.gcube.data.publishing.ckan2zenodo.model.CkanRelatedIdentifier;
|
||||||
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
|
import org.gcube.data.publishing.ckan2zenodo.model.CkanResource;
|
||||||
import org.gcube.data.publishing.ckan2zenodo.model.UploadPolicy;
|
|
||||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
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.GcatException;
|
||||||
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
|
import org.gcube.data.publishing.ckan2zenodo.model.faults.InvalidItemException;
|
||||||
|
@ -47,14 +46,7 @@ public class Ckan2ZenodoImpl implements Ckan2Zenodo{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZenodoDeposition translate(CkanItemDescriptor desc) throws InvalidItemException, ZenodoException, ConfigurationException, TransformationException {
|
public ZenodoDeposition translate(CkanItemDescriptor desc) throws InvalidItemException, ZenodoException, ConfigurationException, TransformationException {
|
||||||
ZenodoDeposition toUpdate=null;
|
return translate(desc,false);
|
||||||
CkanRelatedIdentifier doi=desc.getZenodoDoi();
|
|
||||||
if(doi!=null) {
|
|
||||||
Zenodo z=getZenodo();
|
|
||||||
toUpdate=z.readDeposition(doi.getZenodoId());
|
|
||||||
}
|
|
||||||
Translator tr=new TransformerManager().getByProfile(desc.getProfile());
|
|
||||||
return tr.transform(desc, toUpdate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,6 +101,38 @@ public class Ckan2ZenodoImpl implements Ckan2Zenodo{
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ZenodoDeposition forceTranslation(CkanItemDescriptor desc) throws InvalidItemException, ZenodoException, TransformationException {
|
||||||
|
try {
|
||||||
|
return translate(desc,true);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
log.error("Unexpected Exception. ",e);
|
||||||
|
throw new InvalidItemException("Unexpected exception. Please try again later");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// LOGIC
|
||||||
|
|
||||||
|
private ZenodoDeposition translate(CkanItemDescriptor desc, boolean skipErrors) throws InvalidItemException, ZenodoException, ConfigurationException, TransformationException {
|
||||||
|
ZenodoDeposition toUpdate=null;
|
||||||
|
Translator tr=null;
|
||||||
|
try {
|
||||||
|
CkanRelatedIdentifier doi=desc.getZenodoDoi();
|
||||||
|
if(doi!=null) {
|
||||||
|
Zenodo z=getZenodo();
|
||||||
|
toUpdate=z.readDeposition(doi.getZenodoId());
|
||||||
|
}
|
||||||
|
tr=new TransformerManager().getByProfile(desc.getProfile());
|
||||||
|
}catch (InvalidItemException e) {
|
||||||
|
if(!skipErrors) throw e;
|
||||||
|
} catch (ZenodoException e) {
|
||||||
|
if(!skipErrors) throw e;
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
if(!skipErrors) tr=new Translator();
|
||||||
|
}
|
||||||
|
return tr.transform(desc, toUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class Translator {
|
||||||
// D4Science as contributor
|
// D4Science as contributor
|
||||||
Contributor d4Science=new Contributor(Contributor.Type.HostingInstitution);
|
Contributor d4Science=new Contributor(Contributor.Type.HostingInstitution);
|
||||||
d4Science.setName("D4Science");
|
d4Science.setName("D4Science");
|
||||||
|
contributors.add(d4Science);
|
||||||
|
|
||||||
meta.setContributors(contributors);
|
meta.setContributors(contributors);
|
||||||
meta.setCreators(creators);
|
meta.setCreators(creators);
|
||||||
|
|
|
@ -11,8 +11,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
public class TransformationTests {
|
public class TransformationTests {
|
||||||
|
|
||||||
static ObjectMapper mapper=null;
|
static ObjectMapper mapper=null;
|
||||||
|
@ -52,4 +50,6 @@ public class TransformationTests {
|
||||||
for(CkanResource filtered:t.filterResources(desc))
|
for(CkanResource filtered:t.filterResources(desc))
|
||||||
System.out.println("NAME : "+filtered.getName()+ " FORMAT : "+filtered.getFormat());
|
System.out.println("NAME : "+filtered.getName()+ " FORMAT : "+filtered.getFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue