1
|
package eu.dnetlib.msro.workflows.nodes;
|
2
|
|
3
|
import java.util.function.Function;
|
4
|
|
5
|
import eu.dnetlib.enabling.resultset.factory.ResultSetFactory;
|
6
|
import eu.dnetlib.msro.workflows.graph.Arc;
|
7
|
import eu.dnetlib.msro.workflows.procs.Env;
|
8
|
import eu.dnetlib.dli.resolver.model.DLIResolvedObject;
|
9
|
import eu.dnetlib.pid.resolver.parser.AbstractResolverParser;
|
10
|
import eu.dnetlib.resolver.parser.DMFResolverParser;
|
11
|
import eu.dnetlib.resolver.parser.PMFResolverParser;
|
12
|
import eu.dnetlib.resolver.parser.ScholixResolverParser;
|
13
|
import eu.dnetlib.rmi.common.ResultSet;
|
14
|
import eu.dnetlib.rmi.manager.MSROException;
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
import sun.util.logging.resources.logging_es;
|
17
|
|
18
|
/**
|
19
|
* Created by sandro on 10/10/16.
|
20
|
*/
|
21
|
public class FilterDLIRecordJobNode extends SimpleJobNode {
|
22
|
|
23
|
|
24
|
|
25
|
private final DMFResolverParser dmfResolverParser = new DMFResolverParser();
|
26
|
private final PMFResolverParser pmfResolverParser = new PMFResolverParser();
|
27
|
private final ScholixResolverParser scholixResolverParser = new ScholixResolverParser();
|
28
|
private String type;
|
29
|
private String inputEprParam;
|
30
|
private String outputEprParam;
|
31
|
@Autowired
|
32
|
private ResultSetFactory resultSetFactory;
|
33
|
|
34
|
@Override
|
35
|
protected String execute(final Env env) throws Exception {
|
36
|
|
37
|
final ResultSet<?> rsIn = env.getAttribute(this.inputEprParam, ResultSet.class);
|
38
|
|
39
|
if ((rsIn == null)) { throw new MSROException("InputEprParam (" + this.inputEprParam + ") not found in ENV"); }
|
40
|
|
41
|
ResultSet<String> outputResultSet;
|
42
|
|
43
|
switch (type) {
|
44
|
case "publication":
|
45
|
outputResultSet = this.resultSetFactory.map(rsIn, String.class, createMappingFuncion(pmfResolverParser));
|
46
|
break;
|
47
|
case "dataset":
|
48
|
outputResultSet = this.resultSetFactory.map(rsIn, String.class, createMappingFuncion(dmfResolverParser));
|
49
|
break;
|
50
|
case "unknown":
|
51
|
outputResultSet = this.resultSetFactory.map(rsIn, String.class, createMappingFuncion(scholixResolverParser));
|
52
|
break;
|
53
|
default:
|
54
|
throw new MSROException("unexpectd value of type");
|
55
|
}
|
56
|
|
57
|
env.setAttribute(this.outputEprParam, outputResultSet);
|
58
|
|
59
|
return Arc.DEFAULT_ARC;
|
60
|
}
|
61
|
|
62
|
private Function<String, String> createMappingFuncion(AbstractResolverParser parser) {
|
63
|
return it -> {
|
64
|
final DLIResolvedObject resolvedObject = (DLIResolvedObject) parser.parseObject(it);
|
65
|
if (resolvedObject != null) return it;
|
66
|
else return "<JUNK/>";
|
67
|
};
|
68
|
}
|
69
|
|
70
|
public String getType() {
|
71
|
return type;
|
72
|
}
|
73
|
|
74
|
public void setType(final String type) {
|
75
|
this.type = type;
|
76
|
}
|
77
|
|
78
|
public String getInputEprParam() {
|
79
|
return inputEprParam;
|
80
|
}
|
81
|
|
82
|
public void setInputEprParam(final String inputEprParam) {
|
83
|
this.inputEprParam = inputEprParam;
|
84
|
}
|
85
|
|
86
|
public String getOutputEprParam() {
|
87
|
return outputEprParam;
|
88
|
}
|
89
|
|
90
|
public void setOutputEprParam(final String outputEprParam) {
|
91
|
this.outputEprParam = outputEprParam;
|
92
|
}
|
93
|
}
|