1
|
package eu.dnetlib.resolver.mdstore.plugin;
|
2
|
|
3
|
import com.mongodb.DBObject;
|
4
|
import com.mongodb.client.MongoCollection;
|
5
|
import eu.dnetlib.pid.resolver.PIDResolver;
|
6
|
import eu.dnetlib.pid.resolver.mdstore.plugin.AbstractRecordResolver;
|
7
|
import eu.dnetlib.pid.resolver.mdstore.plugin.ResolverSerializer;
|
8
|
import eu.dnetlib.pid.resolver.model.ObjectType;
|
9
|
import eu.dnetlib.pid.resolver.model.PID;
|
10
|
import eu.dnetlib.wds.parser.WDSParser;
|
11
|
import eu.dnetlib.wds.resolver.WDSResolvedObject;
|
12
|
import eu.dnetlib.wds.resolver.serializers.WDSResolverSerializer;
|
13
|
import eu.dnetlib.wds.utils.WDSUtils;
|
14
|
import org.antlr.stringtemplate.StringTemplate;
|
15
|
import org.apache.commons.lang3.StringUtils;
|
16
|
|
17
|
import java.util.HashMap;
|
18
|
import java.util.List;
|
19
|
import java.util.Map;
|
20
|
import java.util.concurrent.BlockingQueue;
|
21
|
|
22
|
public class WDSRecordResolver extends AbstractRecordResolver {
|
23
|
|
24
|
|
25
|
private final WDSParser parser = new WDSParser();
|
26
|
|
27
|
public WDSRecordResolver(long ts) {
|
28
|
super(ts);
|
29
|
}
|
30
|
|
31
|
|
32
|
@Override
|
33
|
public String resolve(final String inputRecord) {
|
34
|
|
35
|
final WDSResolvedObject inputObject = (WDSResolvedObject) parser.parse(inputRecord);
|
36
|
if (inputObject == null) {
|
37
|
log.error("Error on parsing record the result is null, record: " + inputRecord);
|
38
|
return null;
|
39
|
}
|
40
|
|
41
|
if (inputObject != null && !StringUtils.isBlank(inputObject.getPid())) {
|
42
|
log.debug("trying to resolve " + inputObject.getPid());
|
43
|
}
|
44
|
|
45
|
boolean shouldUpdate = false;
|
46
|
|
47
|
final String newXML = resolveRelations(inputRecord, inputObject, shouldUpdate);
|
48
|
if (newXML != null) return newXML;
|
49
|
return null;
|
50
|
}
|
51
|
|
52
|
protected Map<String, ObjectType> tryToResolveRelation(final PID currentPid) {
|
53
|
if (currentPid.getId() != null && currentPid.getId().contains("wds_resolver")) {
|
54
|
return null;
|
55
|
}
|
56
|
log.debug("tryToResolveRelation " + currentPid);
|
57
|
|
58
|
for (PIDResolver resolver : pluginResolver) {
|
59
|
final WDSResolvedObject currentIdentifier = (WDSResolvedObject) resolver.retrievePID(currentPid.getId(), currentPid.getType(),offline);
|
60
|
|
61
|
|
62
|
if (currentIdentifier != null && !StringUtils.isBlank(currentIdentifier.getPid()) && currentIdentifier.getPid().toLowerCase().equals(currentPid.getId().toLowerCase())) {
|
63
|
final HashMap<String, ObjectType> result = new HashMap<>();
|
64
|
result.put("wds_resolver::" + WDSUtils.generateIdentifier(currentIdentifier.getPid(), currentIdentifier.getPidType()),
|
65
|
currentIdentifier.getType());
|
66
|
return result;
|
67
|
}
|
68
|
}
|
69
|
return null;
|
70
|
}
|
71
|
|
72
|
|
73
|
public void setPluginResolver(final List<PIDResolver> pluginResolver) {
|
74
|
this.pluginResolver = pluginResolver;
|
75
|
}
|
76
|
|
77
|
|
78
|
public BlockingQueue<DBObject> getInputQueue() {
|
79
|
return inputQueue;
|
80
|
}
|
81
|
|
82
|
public void setInputQueue(final BlockingQueue<DBObject> inputQueue) {
|
83
|
this.inputQueue = inputQueue;
|
84
|
}
|
85
|
|
86
|
public MongoCollection<DBObject> getOutputCollection() {
|
87
|
return outputCollection;
|
88
|
}
|
89
|
|
90
|
public void setOutputCollection(final MongoCollection<DBObject> outputCollection) {
|
91
|
this.outputCollection = outputCollection;
|
92
|
}
|
93
|
|
94
|
public void setSerializer(final ResolverSerializer serializer) {
|
95
|
final WDSResolverSerializer tmp = new WDSResolverSerializer();
|
96
|
tmp.setPmfTemplate(new StringTemplate(((WDSResolverSerializer) serializer).getPmfTemplate().getTemplate()));
|
97
|
tmp.setDmfTemplate(new StringTemplate(((WDSResolverSerializer) serializer).getDmfTemplate().getTemplate()));
|
98
|
this.serializer = tmp;
|
99
|
}
|
100
|
}
|