Project

General

Profile

1
package eu.dnetlib.msro.workflows.nodes.hostedby;
2

    
3
import java.io.StringReader;
4
import java.util.function.UnaryOperator;
5

    
6
import eu.dnetlib.enabling.resultset.factory.ResultSetFactory;
7
import eu.dnetlib.msro.workflows.graph.Arc;
8
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
9
import eu.dnetlib.msro.workflows.procs.Env;
10
import eu.dnetlib.rmi.common.ResultSet;
11
import org.dom4j.Document;
12
import org.dom4j.Element;
13
import org.dom4j.io.SAXReader;
14
import org.springframework.beans.factory.annotation.Autowired;
15

    
16
// TODO: Auto-generated Javadoc
17

    
18
/**
19
 * The Class FindHostedByJonbNode.
20
 */
21
public class FindHostedByJobNode extends SimpleJobNode {
22

    
23
	private final String unknown_repo_id = "openaire____::1256f046-bf1f-4afc-8b47-d0b147148b18";
24
	/**
25
	 * The input epr param.
26
	 */
27
	private String inputEprParam;
28
	/**
29
	 * The output epr param.
30
	 */
31
	private String outputEprParam;
32
	/**
33
	 * The counters param.
34
	 */
35
	private String countersParam;
36
	/**
37
	 * The mapped result set factory.
38
	 */
39
	@Autowired
40
	private ResultSetFactory resultSetFactory;
41

    
42
	/*
43
	 * (non-Javadoc)
44
	 *
45
	 * @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken)
46
	 */
47
	@Override
48
	protected String execute(final Env env) throws Exception {
49
		final ResultSet<?> inputEpr = env.getAttribute(this.inputEprParam, ResultSet.class);
50
		final HostedByCounters counters = new HostedByCounters();
51

    
52
		final SAXReader reader = new SAXReader();
53

    
54
		final UnaryOperator<String> hostedByMapFunction = input -> {
55
			try {
56
				final Document doc = reader.read(new StringReader(input));
57
				final Element node = (Element) doc.selectSingleNode("//*[local-name()='hostedBy']");
58
				if (node != null) {
59
					final String hostedById = node.attributeValue("id");
60
					if (!hostedById.equals(FindHostedByJobNode.this.unknown_repo_id)) {
61
						counters.increaseCounter(hostedById);
62
					}
63
				}
64
			} catch (final Exception e) {
65

    
66
			}
67

    
68
			return input;
69
		};
70

    
71
		final ResultSet<String> epr = this.resultSetFactory.map(inputEpr, String.class,
72
				hostedByMapFunction);
73

    
74
		env.setAttribute(this.outputEprParam, epr);
75
		env.setAttribute(getCountersParam(), counters);
76

    
77
		return Arc.DEFAULT_ARC;
78
	}
79

    
80
	/**
81
	 * @return the inputEprParam
82
	 */
83
	public String getInputEprParam() {
84
		return this.inputEprParam;
85
	}
86

    
87
	/**
88
	 * @param inputEprParam the inputEprParam to set
89
	 */
90
	public void setInputEprParam(final String inputEprParam) {
91
		this.inputEprParam = inputEprParam;
92
	}
93

    
94
	/**
95
	 * @return the outputEprParam
96
	 */
97
	public String getOutputEprParam() {
98
		return this.outputEprParam;
99
	}
100

    
101
	/**
102
	 * @param outputEprParam the outputEprParam to set
103
	 */
104
	public void setOutputEprParam(final String outputEprParam) {
105
		this.outputEprParam = outputEprParam;
106
	}
107

    
108
	/**
109
	 * @return the countersParam
110
	 */
111
	public String getCountersParam() {
112
		return this.countersParam;
113
	}
114

    
115
	/**
116
	 * @param countersParam the countersParam to set
117
	 */
118
	public void setCountersParam(final String countersParam) {
119
		this.countersParam = countersParam;
120
	}
121

    
122
}
(1-1/7)