41 lines
1.1 KiB
Java
41 lines
1.1 KiB
Java
package org.gcube.data.publishing.ckan2zenodo;
|
|
|
|
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;
|
|
import org.gcube.data.publishing.ckan2zenodo.model.faults.ConfigurationException;
|
|
|
|
import lombok.Synchronized;
|
|
|
|
|
|
public class TransformerManager {
|
|
|
|
|
|
|
|
private static DocumentBuilder builder=null;
|
|
|
|
@Synchronized
|
|
private static DocumentBuilder getBuilder() throws ParserConfigurationException {
|
|
if(builder==null) {
|
|
DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
|
|
builder = factory.newDocumentBuilder();
|
|
}
|
|
return builder;
|
|
}
|
|
|
|
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 ConfigurationException("No transformer found for profile "+profile);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|