1
|
package eu.dnetlib.msro.workflows.util;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
import org.springframework.beans.factory.annotation.Required;
|
9
|
|
10
|
import com.google.common.collect.Lists;
|
11
|
|
12
|
import eu.dnetlib.miscutils.functional.UnaryFunction;
|
13
|
import eu.dnetlib.msro.rmi.MSROException;
|
14
|
import eu.dnetlib.msro.workflows.util.ValidNodeValuesFetcher.DnetParamValue;
|
15
|
|
16
|
public abstract class ValidNodeValuesFetcher implements UnaryFunction<List<DnetParamValue>, Map<String, String>> {
|
17
|
|
18
|
private String name;
|
19
|
|
20
|
private static final Log log = LogFactory.getLog(ValidNodeValuesFetcher.class);
|
21
|
|
22
|
public class DnetParamValue implements Comparable<DnetParamValue> {
|
23
|
|
24
|
private String id;
|
25
|
private String name;
|
26
|
|
27
|
public DnetParamValue(final String id, final String name) {
|
28
|
this.id = id;
|
29
|
this.name = name;
|
30
|
}
|
31
|
|
32
|
public String getId() {
|
33
|
return id;
|
34
|
}
|
35
|
|
36
|
public String getName() {
|
37
|
return name;
|
38
|
}
|
39
|
|
40
|
@Override
|
41
|
public int compareTo(final DnetParamValue o) {
|
42
|
return getName().compareTo(o.getName());
|
43
|
}
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
final public List<DnetParamValue> evaluate(final Map<String, String> params) {
|
48
|
try {
|
49
|
return obtainValues(params);
|
50
|
} catch (Throwable e) {
|
51
|
log.error("Error obtaing values", e);
|
52
|
return Lists.newArrayList();
|
53
|
}
|
54
|
}
|
55
|
|
56
|
abstract protected List<DnetParamValue> obtainValues(Map<String, String> params) throws Exception;
|
57
|
|
58
|
public String getName() {
|
59
|
return name;
|
60
|
}
|
61
|
|
62
|
@Required
|
63
|
public void setName(final String name) {
|
64
|
this.name = name;
|
65
|
}
|
66
|
|
67
|
protected void verifyParams(final Map<String, String> params, final String... pnames) throws MSROException {
|
68
|
for (String s : pnames) {
|
69
|
if (!params.containsKey(s)) { throw new MSROException("Parameter not found: " + s); }
|
70
|
}
|
71
|
}
|
72
|
}
|