1
|
package eu.dnetlib.data.resultSet.cleaner;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import org.apache.commons.lang.StringUtils;
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
|
8
|
import com.google.common.base.Function;
|
9
|
import com.google.common.collect.Lists;
|
10
|
|
11
|
import eu.dnetlib.enabling.datastructures.AtomicCleaningRule;
|
12
|
import eu.dnetlib.enabling.datastructures.CleaningRule;
|
13
|
import eu.dnetlib.enabling.is.client.InformationServiceClient;
|
14
|
|
15
|
public class CleanerFactory {
|
16
|
|
17
|
@Autowired
|
18
|
private InformationServiceClient isClient;
|
19
|
|
20
|
public Cleaner createCleaner(final CleaningRule rule) {
|
21
|
|
22
|
final List<XPathCleaningRule> xpathRules = Lists.transform(rule.getRules(), new Function<AtomicCleaningRule, XPathCleaningRule>() {
|
23
|
|
24
|
@Override
|
25
|
public XPathCleaningRule apply(final AtomicCleaningRule r) {
|
26
|
if (StringUtils.isNotBlank(r.getGroovy().trim())) {
|
27
|
return new GroovyRule(r.getGroovy(), r.getXpath(), r.isStrict());
|
28
|
} else {
|
29
|
return new VocabularyRule(r.getVocabularies(), r.getXpath(), r.isStrict(), isClient);
|
30
|
}
|
31
|
}
|
32
|
});
|
33
|
|
34
|
return new Cleaner(xpathRules);
|
35
|
}
|
36
|
}
|