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