2019-11-22 16:31:50 +01:00
|
|
|
package org.gcube.data.publishing.ckan2zenodo;
|
|
|
|
|
2019-12-03 12:50:36 +01:00
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
|
|
|
import org.gcube.common.resources.gcore.GenericResource;
|
|
|
|
import org.gcube.data.publishing.ckan2zenodo.commons.IS;
|
2019-12-16 18:49:29 +01:00
|
|
|
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
2019-12-03 12:50:36 +01:00
|
|
|
|
|
|
|
import lombok.Synchronized;
|
2021-10-15 16:28:07 +02:00
|
|
|
import org.gcube.data.publishing.ckan2zenodo.model.parsing.Mappings;
|
2019-12-03 12:50:36 +01:00
|
|
|
|
|
|
|
|
2019-11-26 14:55:20 +01:00
|
|
|
public class TransformerManager {
|
2019-11-22 16:31:50 +01:00
|
|
|
|
2019-12-03 12:50:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
private static DocumentBuilder builder=null;
|
|
|
|
|
|
|
|
@Synchronized
|
|
|
|
private static DocumentBuilder getBuilder() throws ParserConfigurationException {
|
|
|
|
if(builder==null) {
|
|
|
|
DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
|
|
|
|
builder = factory.newDocumentBuilder();
|
|
|
|
}
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2019-12-16 18:49:29 +01:00
|
|
|
public Translator getByProfile(String profile) throws ConfigurationException {
|
2019-12-03 12:50:36 +01:00
|
|
|
for(GenericResource r: IS.queryForGenericResources("Ckan-Zenodo-Mappings")){
|
2021-10-15 16:28:07 +02:00
|
|
|
if (r.profile().name().equals(profile)) {
|
|
|
|
Mappings m = IS.readMappings(r);
|
|
|
|
if(m == null) return new Translator();
|
|
|
|
else return new Translator(m);
|
|
|
|
}
|
2019-12-03 12:50:36 +01:00
|
|
|
}
|
2020-07-10 16:09:09 +02:00
|
|
|
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.");
|
2019-12-03 12:50:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-05 11:56:51 +01:00
|
|
|
|
2019-11-22 16:31:50 +01:00
|
|
|
}
|