This commit is contained in:
Fabio Sinibaldi 2021-10-15 16:28:07 +02:00
parent 191b69d0ce
commit 3d3034fa4e
3 changed files with 27 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import org.gcube.data.publishing.ckan2zenodo.commons.IS;
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
import lombok.Synchronized;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mappings;
public class TransformerManager {
@ -28,8 +29,11 @@ public class TransformerManager {
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));
if (r.profile().name().equals(profile)) {
Mappings m = IS.readMappings(r);
if(m == null) return new Translator();
else return new Translator(m);
}
}
throw new ConfigurationException("No specific mapping for the catalogue item has been configured. "
+ "By continuing with the upload some metadata might not be upload to Zenodo.");

View File

@ -5,6 +5,7 @@ import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.JAXBContext;
@ -17,6 +18,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mapping;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mappings;
import org.gcube.data.publishing.ckan2zenodo.model.parsing.ResourceFilter;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
@ -60,9 +62,10 @@ public class IS {
Unmarshaller um=JAXBContext.newInstance(Mappings.class).createUnmarshaller();
return (Mappings) um.unmarshal(new StreamSource(new StringReader(body)));
Mappings m= (Mappings) um.unmarshal(new StreamSource(new StringReader(body)));
if(m.getMappings()==null) m.setMappings(Collections.emptyList());
if(m.getResourceFilters()==null||m.getResourceFilters().getFilters().isEmpty()) m.setResourceFilters(ResourceFilter.PASS_ALL);
return m;
}catch(Throwable t) {
log.debug("Error while parsing mapping from resource "+res.id()+" name : "+res.profile().name(),t);
throw new ConfigurationException("Invaild mapping resource "+res.id()+" name : "+res.profile().name(),t);

View File

@ -2,12 +2,15 @@ package org.gcube.tests;
import org.gcube.data.publishing.ckan2zenodo.Ckan2Zenodo;
import org.gcube.data.publishing.ckan2zenodo.Ckan2ZenodoImpl;
import org.gcube.data.publishing.ckan2zenodo.model.faults.*;
import org.gcube.data.publishing.ckan2zenodo.model.report.EnvironmentReport;
import org.junit.Assume;
import org.junit.Test;
public class EnvironmentCheckTests {
String context="/pred4s/preprod/preVRE";
@Test
public void failCheckEnvironemnt(){
TokenSetter.set("/gcube");
@ -19,10 +22,21 @@ public class EnvironmentCheckTests {
@Test
public void okCheckEnvironemnt(){
TokenSetter.set("/pred4s/preprod/preVRE");
TokenSetter.set(context);
Ckan2Zenodo client=new Ckan2ZenodoImpl();
EnvironmentReport report=client.checkEnvironment();
Assume.assumeTrue(report.isok());
System.out.println(report);
}
@Test
public void checkMappings() throws GcatException, TransformationException, ConfigurationException, InvalidItemException, ZenodoException {
TokenSetter.set(context);
Ckan2Zenodo client=new Ckan2ZenodoImpl();
client.translate(client.read("knime_workflow_with_joined_consumer_phase_and_dose_response_model"));
// client.translate(client.read("lwr_in_prevre"));
client.translate(client.read("xyextractor_in_prevre"));
}
}