1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
|
7
|
import org.apache.commons.lang.StringUtils;
|
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.Node;
|
13
|
import org.dom4j.io.SAXReader;
|
14
|
|
15
|
import com.googlecode.sarasvati.Arc;
|
16
|
import com.googlecode.sarasvati.NodeToken;
|
17
|
|
18
|
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
|
19
|
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode;
|
20
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
21
|
import eu.dnetlib.msro.workflows.resultset.ProcessCountingResultSetFactory;
|
22
|
import eu.dnetlib.msro.workflows.util.ProgressProvider;
|
23
|
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider;
|
24
|
|
25
|
public class ProcessContextsJobNode extends SimpleJobNode implements ProgressJobNode {
|
26
|
|
27
|
private String eprParam;
|
28
|
private String contextObj;
|
29
|
private ResultsetProgressProvider progressProvider;
|
30
|
private String contextId;
|
31
|
private String contextLabel;
|
32
|
private String contextType;
|
33
|
|
34
|
private static final Log log = LogFactory.getLog(ProcessContextsJobNode.class);
|
35
|
|
36
|
@Resource
|
37
|
private ResultSetClientFactory resultSetClientFactory;
|
38
|
|
39
|
@Resource
|
40
|
private ProcessCountingResultSetFactory processCountingResultSetFactory;
|
41
|
|
42
|
@Override
|
43
|
protected String execute(final NodeToken token) throws Exception {
|
44
|
|
45
|
final ContextDesc context = new ContextDesc(contextId, contextLabel, contextType);
|
46
|
|
47
|
final String epr = token.getEnv().getAttribute(eprParam);
|
48
|
|
49
|
this.progressProvider = processCountingResultSetFactory.createProgressProvider(token.getProcess(), epr);
|
50
|
|
51
|
final SAXReader reader = new SAXReader();
|
52
|
|
53
|
for (String s : resultSetClientFactory.getClient(progressProvider.getEpr())) {
|
54
|
final Document doc = reader.read(new StringReader(s));
|
55
|
|
56
|
final String openaireId = doc.valueOf("/fundingtree/*[starts-with(local-name(),'funding_level_')]/id");
|
57
|
if (!context.getDbEntries().containsKey(openaireId)) {
|
58
|
log.info("Found funding: " + openaireId);
|
59
|
context.getDbEntries().put(openaireId, s);
|
60
|
|
61
|
final ContextPart part = calculatePart(doc.selectSingleNode("//funding_level_0"));
|
62
|
if (context.getCategories().containsKey(part.getId())) {
|
63
|
for (ContextPart p : part.getParts().values()) {
|
64
|
context.getCategories().get(part.getId()).addPart(p);;
|
65
|
}
|
66
|
} else {
|
67
|
context.getCategories().put(part.getId(), part);
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
|
72
|
token.getEnv().setTransientAttribute(contextObj, context);
|
73
|
|
74
|
return Arc.DEFAULT_ARC;
|
75
|
}
|
76
|
|
77
|
private ContextPart calculatePart(final Node node) {
|
78
|
|
79
|
final String newId = contextId + "::" + StringUtils.substringAfter(node.valueOf("./id"), "::");
|
80
|
|
81
|
final ContextPart part = new ContextPart(newId, node.valueOf("./description"));
|
82
|
|
83
|
part.getParams().put("name", node.valueOf("./name"));
|
84
|
part.getParams().put("openaireId", node.valueOf("./id"));
|
85
|
part.getParams().put("class", node.valueOf("./class"));
|
86
|
|
87
|
final Element parent = node.getParent() != null ? node.getParent().getParent() : null;
|
88
|
|
89
|
if (parent != null && parent.getName().startsWith("funding_level_")) {
|
90
|
final ContextPart p = calculatePart(parent);
|
91
|
part.getParts().put(p.getId(), p);
|
92
|
}
|
93
|
return part;
|
94
|
}
|
95
|
|
96
|
public String getEprParam() {
|
97
|
return eprParam;
|
98
|
}
|
99
|
|
100
|
public void setEprParam(final String eprParam) {
|
101
|
this.eprParam = eprParam;
|
102
|
}
|
103
|
|
104
|
public String getContextObj() {
|
105
|
return contextObj;
|
106
|
}
|
107
|
|
108
|
public void setContextObj(final String contextObj) {
|
109
|
this.contextObj = contextObj;
|
110
|
}
|
111
|
|
112
|
@Override
|
113
|
public ProgressProvider getProgressProvider() {
|
114
|
return progressProvider;
|
115
|
}
|
116
|
|
117
|
public String getContextId() {
|
118
|
return contextId;
|
119
|
}
|
120
|
|
121
|
public void setContextId(final String contextId) {
|
122
|
this.contextId = contextId;
|
123
|
}
|
124
|
|
125
|
public String getContextLabel() {
|
126
|
return contextLabel;
|
127
|
}
|
128
|
|
129
|
public void setContextLabel(final String contextLabel) {
|
130
|
this.contextLabel = contextLabel;
|
131
|
}
|
132
|
|
133
|
public String getContextType() {
|
134
|
return contextType;
|
135
|
}
|
136
|
|
137
|
public void setContextType(final String contextType) {
|
138
|
this.contextType = contextType;
|
139
|
}
|
140
|
}
|