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;
|
|
|
|
|
|
|
|
|
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")){
|
|
|
|
if (r.profile().name().equals(profile))
|
2019-12-10 17:06:52 +01:00
|
|
|
return new Translator(IS.readMappings(r),IS.readResourceFilters(r));
|
2019-12-03 12:50:36 +01:00
|
|
|
}
|
2019-12-16 18:49:29 +01:00
|
|
|
throw new ConfigurationException("No transformer found for profile "+profile);
|
2019-12-03 12:50:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-05 11:56:51 +01:00
|
|
|
|
2019-11-22 16:31:50 +01:00
|
|
|
}
|