1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.claims;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
7
|
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.dom4j.Document;
|
11
|
import org.dom4j.Element;
|
12
|
import org.dom4j.Namespace;
|
13
|
import org.dom4j.QName;
|
14
|
import org.dom4j.io.SAXReader;
|
15
|
|
16
|
import com.googlecode.sarasvati.Arc;
|
17
|
import com.googlecode.sarasvati.NodeToken;
|
18
|
|
19
|
import eu.dnetlib.enabling.resultset.MappedResultSetFactory;
|
20
|
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils;
|
21
|
import eu.dnetlib.miscutils.functional.UnaryFunction;
|
22
|
import eu.dnetlib.msro.openaireplus.workflows.nodes.SetHdfsFileJobNode;
|
23
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
24
|
|
25
|
/**
|
26
|
* TODO: this class can be deleted when we are using the new claim database
|
27
|
*/
|
28
|
@Deprecated
|
29
|
public class DecapsuleClaimsJobNode extends SimpleJobNode {
|
30
|
|
31
|
/**
|
32
|
* logger.
|
33
|
*/
|
34
|
private static final Log log = LogFactory.getLog(SetHdfsFileJobNode.class);
|
35
|
|
36
|
private static final Namespace OAF_NS = new Namespace("oaf", "http://namespace.openaire.eu/oaf");
|
37
|
private static final double DEFAULT_TRUST = 0.9;
|
38
|
|
39
|
private String inputEprParam;
|
40
|
private String outputEprParam;
|
41
|
|
42
|
@Resource
|
43
|
private MappedResultSetFactory mappedResultSetFactory;
|
44
|
|
45
|
@Override
|
46
|
protected String execute(final NodeToken token) throws Exception {
|
47
|
final UnaryFunction<String, String> mapper = new UnaryFunction<String, String>() {
|
48
|
|
49
|
final SAXReader reader = new SAXReader();
|
50
|
|
51
|
@Override
|
52
|
public String evaluate(final String row) {
|
53
|
try {
|
54
|
final Document docRow = reader.read(new StringReader(row));
|
55
|
|
56
|
final String xml = docRow.valueOf("//ROW/FIELD[@name = 'xml']");
|
57
|
final String provenance = docRow.valueOf("//ROW/FIELD[@name = 'provenance']");
|
58
|
|
59
|
final Document doc = reader.read(new StringReader(xml));
|
60
|
final Element record = (Element) doc.selectSingleNode("//*[local-name() = 'record']");
|
61
|
final Element about = record.addElement(new QName("about"));
|
62
|
final Element dataInfo = about.addElement(new QName("datainfo", OAF_NS));
|
63
|
|
64
|
dataInfo.addElement(new QName("inferred", OAF_NS)).setText("false");
|
65
|
dataInfo.addElement(new QName("deletedbyinference", OAF_NS)).setText("false");
|
66
|
dataInfo.addElement(new QName("trust", OAF_NS)).setText(Double.toString(DEFAULT_TRUST));
|
67
|
dataInfo.addElement(new QName("inferenceprovenance", OAF_NS)).setText("");
|
68
|
|
69
|
final Element action = dataInfo.addElement(new QName("provenanceaction", OAF_NS));
|
70
|
action.addAttribute("schemename", "dnet:provenanceActions");
|
71
|
action.addAttribute("schemeid", "dnet:provenanceActions");
|
72
|
action.addAttribute("classname", provenance);
|
73
|
action.addAttribute("classid", provenance);
|
74
|
|
75
|
return doc.asXML();
|
76
|
} catch (Throwable e) {
|
77
|
log.error("Error parsing row: " + row, e);
|
78
|
throw new IllegalArgumentException("Error parsing row: " + row, e);
|
79
|
}
|
80
|
}
|
81
|
};
|
82
|
|
83
|
final W3CEndpointReference inputEpr = new EPRUtils().getEpr(token.getEnv().getAttribute(getInputEprParam()));
|
84
|
final W3CEndpointReference epr = mappedResultSetFactory.createMappedResultSet(inputEpr, mapper);
|
85
|
|
86
|
token.getEnv().setAttribute(getOutputEprParam(), epr.toString());
|
87
|
|
88
|
return Arc.DEFAULT_ARC;
|
89
|
}
|
90
|
|
91
|
public String getInputEprParam() {
|
92
|
return inputEprParam;
|
93
|
}
|
94
|
|
95
|
public void setInputEprParam(final String inputEprParam) {
|
96
|
this.inputEprParam = inputEprParam;
|
97
|
}
|
98
|
|
99
|
public String getOutputEprParam() {
|
100
|
return outputEprParam;
|
101
|
}
|
102
|
|
103
|
public void setOutputEprParam(final String outputEprParam) {
|
104
|
this.outputEprParam = outputEprParam;
|
105
|
}
|
106
|
|
107
|
}
|