1
|
package eu.dnetlib.msro.worker.nodes.transform;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
import org.springframework.core.io.ClassPathResource;
|
8
|
|
9
|
import com.googlecode.sarasvati.Arc;
|
10
|
import com.googlecode.sarasvati.NodeToken;
|
11
|
|
12
|
import eu.dnetlib.data.resultSet.ResultSetFactory;
|
13
|
import eu.dnetlib.miscutils.ApplyXslt;
|
14
|
import eu.dnetlib.msro.worker.nodes.SimpleJobNode;
|
15
|
import eu.dnetlib.rmi.objects.resultSet.ResultSet;
|
16
|
import eu.dnetlib.rmi.soap.exceptions.ManagerServiceException;
|
17
|
|
18
|
public class ApplyXsltJobNode extends SimpleJobNode {
|
19
|
|
20
|
private String inputResultSetParam;
|
21
|
private String outputResultSetParam;
|
22
|
private String xsltClasspath;
|
23
|
|
24
|
@Autowired
|
25
|
private ResultSetFactory resultSetFactory;
|
26
|
|
27
|
@Override
|
28
|
protected String execute(final NodeToken token) throws Exception {
|
29
|
@SuppressWarnings("unchecked")
|
30
|
final ResultSet<String> inputRs = (ResultSet<String>) token.getEnv().getTransientAttribute(inputResultSetParam);
|
31
|
if (inputRs == null) { throw new ManagerServiceException("InputResultSetParam (" + inputResultSetParam + ") not found in ENV"); }
|
32
|
|
33
|
final Map<String, String> xsltParams = new HashMap<String, String>();
|
34
|
|
35
|
for (String name : token.getFullEnv().getAttributeNames()) {
|
36
|
xsltParams.put(name.replaceAll(":", "_"), token.getFullEnv().getAttribute(name));
|
37
|
}
|
38
|
for (String name : token.getEnv().getAttributeNames()) {
|
39
|
xsltParams.put(name.replaceAll(":", "_"), token.getEnv().getAttribute(name));
|
40
|
}
|
41
|
|
42
|
xsltParams.putAll(parseJsonParameters(token));
|
43
|
|
44
|
final ResultSet<String> outputRs = resultSetFactory.transform(inputRs, new ApplyXslt(new ClassPathResource(xsltClasspath), xsltParams));
|
45
|
|
46
|
token.getEnv().setAttribute(outputResultSetParam, outputRs.toString());
|
47
|
|
48
|
return Arc.DEFAULT_ARC;
|
49
|
}
|
50
|
|
51
|
public String getXsltClasspath() {
|
52
|
return xsltClasspath;
|
53
|
}
|
54
|
|
55
|
public void setXsltClasspath(final String xsltClasspath) {
|
56
|
this.xsltClasspath = xsltClasspath;
|
57
|
}
|
58
|
|
59
|
public String getInputResultSetParam() {
|
60
|
return inputResultSetParam;
|
61
|
}
|
62
|
|
63
|
public void setInputResultSetParam(final String inputResultSetParam) {
|
64
|
this.inputResultSetParam = inputResultSetParam;
|
65
|
}
|
66
|
|
67
|
public String getOutputResultSetParam() {
|
68
|
return outputResultSetParam;
|
69
|
}
|
70
|
|
71
|
public void setOutputResultSetParam(final String outputResultSetParam) {
|
72
|
this.outputResultSetParam = outputResultSetParam;
|
73
|
}
|
74
|
|
75
|
}
|