refactoring
This commit is contained in:
parent
c386401b52
commit
1407556a85
|
@ -34,7 +34,8 @@ public class XsltTransformerFactory {
|
|||
|
||||
private final DnetServiceClientFactory clientFactory;
|
||||
|
||||
public static final String QNAME_BASE_URI = "http://eu/dnetlib/transform";
|
||||
public static final String QNAME_BASE_URI_COMMON = "http://eu/dnetlib/common";
|
||||
public static final String QNAME_BASE_URI_VOCS = "http://eu/dnetlib/vocabularies";
|
||||
|
||||
public XsltTransformerFactory(final DnetServiceClientFactory clientFactory) {
|
||||
this.clientFactory = clientFactory;
|
||||
|
@ -50,10 +51,10 @@ public class XsltTransformerFactory {
|
|||
|
||||
public RecordTransformer<String, String> getTransformerByXSLT(final String xsltText, final Map<String, Object> params) throws TransformationException {
|
||||
final Processor processor = new Processor(false);
|
||||
processor.registerExtensionFunction(new CalculateMd5());
|
||||
processor.registerExtensionFunction(new XsltDateCleaner());
|
||||
processor.registerExtensionFunction(new XsltPersonCleaner());
|
||||
processor.registerExtensionFunction(new XsltVocabularyCleaner(this.clientFactory.getClient(VocabularyClient.class)));
|
||||
processor.registerExtensionFunction(new CalculateMd5(QNAME_BASE_URI_COMMON, "md5"));
|
||||
processor.registerExtensionFunction(new XsltDateCleaner(QNAME_BASE_URI_COMMON, "isoDate"));
|
||||
processor.registerExtensionFunction(new XsltPersonCleaner(QNAME_BASE_URI_COMMON, "cleanPerson"));
|
||||
processor.registerExtensionFunction(new XsltVocabularyCleaner(QNAME_BASE_URI_VOCS, "clean", this.clientFactory.getClient(VocabularyClient.class)));
|
||||
|
||||
final List<XmlProcessingError> errorList = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -3,21 +3,16 @@ package eu.dnetlib.common.mapping.xslt.functions;
|
|||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import eu.dnetlib.common.mapping.xslt.XsltTransformerFactory;
|
||||
import net.sf.saxon.s9api.ExtensionFunction;
|
||||
import net.sf.saxon.s9api.ItemType;
|
||||
import net.sf.saxon.s9api.OccurrenceIndicator;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.SequenceType;
|
||||
import net.sf.saxon.s9api.XdmAtomicValue;
|
||||
import net.sf.saxon.s9api.XdmValue;
|
||||
|
||||
public class CalculateMd5 implements ExtensionFunction {
|
||||
public class CalculateMd5 extends DnetExtensionFunction {
|
||||
|
||||
@Override
|
||||
public QName getName() {
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/common", "md5");
|
||||
public CalculateMd5(final String uri, final String lexical) {
|
||||
super(uri, lexical);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +26,7 @@ public class CalculateMd5 implements ExtensionFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XdmValue call(final XdmValue[] xdmValues) throws SaxonApiException {
|
||||
public XdmValue call(final XdmValue[] xdmValues) {
|
||||
final XdmValue r = xdmValues[0];
|
||||
if (r.size() == 0) { return new XdmAtomicValue(""); }
|
||||
final String currentValue = xdmValues[0].itemAt(0).getStringValue();
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package eu.dnetlib.common.mapping.xslt.functions;
|
||||
|
||||
import net.sf.saxon.s9api.ExtensionFunction;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SequenceType;
|
||||
import net.sf.saxon.s9api.XdmValue;
|
||||
|
||||
public abstract class DnetExtensionFunction implements ExtensionFunction {
|
||||
|
||||
private final QName name;
|
||||
|
||||
public DnetExtensionFunction(final String uri, final String lexical) {
|
||||
this.name = new QName(uri, lexical);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final QName getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract SequenceType getResultType();
|
||||
|
||||
@Override
|
||||
public abstract SequenceType[] getArgumentTypes();
|
||||
|
||||
@Override
|
||||
public abstract XdmValue call(final XdmValue[] xdmValues);
|
||||
|
||||
}
|
|
@ -10,24 +10,19 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import com.github.sisyphsu.dateparser.DateParserUtils;
|
||||
|
||||
import eu.dnetlib.common.mapping.xslt.XsltTransformerFactory;
|
||||
import net.sf.saxon.s9api.ExtensionFunction;
|
||||
import net.sf.saxon.s9api.ItemType;
|
||||
import net.sf.saxon.s9api.OccurrenceIndicator;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.SequenceType;
|
||||
import net.sf.saxon.s9api.XdmAtomicValue;
|
||||
import net.sf.saxon.s9api.XdmValue;
|
||||
|
||||
@Component
|
||||
public class XsltDateCleaner implements ExtensionFunction {
|
||||
public class XsltDateCleaner extends DnetExtensionFunction {
|
||||
|
||||
public static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
|
||||
@Override
|
||||
public QName getName() {
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/dates", "dateISO");
|
||||
public XsltDateCleaner(final String uri, final String lexical) {
|
||||
super(uri, lexical);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,7 +38,7 @@ public class XsltDateCleaner implements ExtensionFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XdmValue call(final XdmValue[] xdmValues) throws SaxonApiException {
|
||||
public XdmValue call(final XdmValue[] xdmValues) {
|
||||
final XdmValue r = xdmValues[0];
|
||||
if (r.size() == 0) { return new XdmAtomicValue(""); }
|
||||
final String currentValue = xdmValues[0].itemAt(0).getStringValue();
|
||||
|
|
|
@ -9,22 +9,17 @@ import java.util.stream.Collectors;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import eu.dnetlib.common.mapping.xslt.XsltTransformerFactory;
|
||||
import net.sf.saxon.s9api.ExtensionFunction;
|
||||
import net.sf.saxon.s9api.ItemType;
|
||||
import net.sf.saxon.s9api.OccurrenceIndicator;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.SequenceType;
|
||||
import net.sf.saxon.s9api.XdmAtomicValue;
|
||||
import net.sf.saxon.s9api.XdmValue;
|
||||
|
||||
@Component
|
||||
public class XsltPersonCleaner implements ExtensionFunction {
|
||||
public class XsltPersonCleaner extends DnetExtensionFunction {
|
||||
|
||||
@Override
|
||||
public QName getName() {
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/persons", "normalize");
|
||||
public XsltPersonCleaner(final String uri, final String lexical) {
|
||||
super(uri, lexical);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +35,7 @@ public class XsltPersonCleaner implements ExtensionFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XdmValue call(final XdmValue[] xdmValues) throws SaxonApiException {
|
||||
public XdmValue call(final XdmValue[] xdmValues) {
|
||||
final XdmValue r = xdmValues[0];
|
||||
if (r.size() == 0) { return new XdmAtomicValue(""); }
|
||||
final String currentValue = xdmValues[0].itemAt(0).getStringValue();
|
||||
|
|
|
@ -6,24 +6,22 @@ import java.util.Map;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import eu.dnetlib.common.clients.VocabularyClient;
|
||||
import eu.dnetlib.common.mapping.xslt.XsltTransformerFactory;
|
||||
import eu.dnetlib.domain.vocabulary.Synonym;
|
||||
import net.sf.saxon.s9api.ExtensionFunction;
|
||||
import net.sf.saxon.s9api.ItemType;
|
||||
import net.sf.saxon.s9api.OccurrenceIndicator;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.SequenceType;
|
||||
import net.sf.saxon.s9api.XdmAtomicValue;
|
||||
import net.sf.saxon.s9api.XdmValue;
|
||||
|
||||
public class XsltVocabularyCleaner implements ExtensionFunction {
|
||||
public class XsltVocabularyCleaner extends DnetExtensionFunction {
|
||||
|
||||
private static final String SEPARATOR = "@#@";
|
||||
|
||||
private final Map<String, String> termsMap = new HashMap<>();
|
||||
|
||||
public XsltVocabularyCleaner(final VocabularyClient vocabularyClient) {
|
||||
public XsltVocabularyCleaner(final String uri, final String lexical, final VocabularyClient vocabularyClient) {
|
||||
super(uri, lexical);
|
||||
|
||||
vocabularyClient.listVocs().forEach(voc -> {
|
||||
vocabularyClient.listTerms(voc.getId()).forEach(term -> {
|
||||
for (final Synonym s : term.getSynonyms()) {
|
||||
|
@ -35,11 +33,6 @@ public class XsltVocabularyCleaner implements ExtensionFunction {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getName() {
|
||||
return new QName(XsltTransformerFactory.QNAME_BASE_URI + "/vocs", "clean");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceType getResultType() {
|
||||
return SequenceType.makeSequenceType(ItemType.STRING, OccurrenceIndicator.ONE_OR_MORE);
|
||||
|
@ -54,7 +47,7 @@ public class XsltVocabularyCleaner implements ExtensionFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public XdmValue call(final XdmValue[] xdmValues) throws SaxonApiException {
|
||||
public XdmValue call(final XdmValue[] xdmValues) {
|
||||
final XdmValue r = xdmValues[0];
|
||||
if (r.size() == 0) { return new XdmAtomicValue(""); }
|
||||
final String currentValue = xdmValues[0].itemAt(0).getStringValue();
|
||||
|
|
Loading…
Reference in New Issue