1
|
package eu.dnetlib.msro.workflows.nodes.stats;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
|
6
|
import eu.dnetlib.msro.workflows.procs.Env;
|
7
|
import eu.dnetlib.rmi.enabling.ISLookUpException;
|
8
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
9
|
import org.apache.commons.lang3.StringUtils;
|
10
|
|
11
|
/**
|
12
|
* Abstract BBJob node for sending BB messages to the StatsManagerService. Subclasses must implement the prepareJob method.
|
13
|
*
|
14
|
* @author alessia
|
15
|
*/
|
16
|
public abstract class AbstractStatsJobNode extends BlackboardJobNode {
|
17
|
|
18
|
private String xqueryForServiceIdParam;
|
19
|
/**
|
20
|
* BB parameter defining which is the portal affected by the action. Overrides the value in the env parameter below.
|
21
|
*/
|
22
|
private String portal;
|
23
|
/**
|
24
|
* Name of the env parameter where to find the target portal value. It is used only if the portal parameter above is not explicitly set
|
25
|
* in the workflow.
|
26
|
*/
|
27
|
private String portalParam;
|
28
|
|
29
|
@Override
|
30
|
protected String obtainServiceId(final Env env) {
|
31
|
final String xquery = env.getAttribute(getXqueryForServiceIdParam(), String.class);
|
32
|
List<String> statsServiceIds;
|
33
|
try {
|
34
|
statsServiceIds = getServiceLocator().getService(ISLookUpService.class).quickSearchProfile(xquery);
|
35
|
if (statsServiceIds.size() > 1) { throw new RuntimeException("Too many StatsManagerService ids found using query: " + xquery); }
|
36
|
if (statsServiceIds.size() < 1) { throw new RuntimeException("StatsManagerService id not found using query: " + xquery); }
|
37
|
return statsServiceIds.get(0);
|
38
|
} catch (final ISLookUpException e) {
|
39
|
throw new RuntimeException(e);
|
40
|
}
|
41
|
}
|
42
|
|
43
|
public String getPortalName(final Env env) {
|
44
|
if (StringUtils.isNotBlank(this.portal)) {
|
45
|
return this.portal;
|
46
|
} else {
|
47
|
return env.getAttribute(this.portalParam, String.class);
|
48
|
}
|
49
|
}
|
50
|
|
51
|
public String getXqueryForServiceIdParam() {
|
52
|
return this.xqueryForServiceIdParam;
|
53
|
}
|
54
|
|
55
|
public void setXqueryForServiceIdParam(final String xqueryForServiceIdParam) {
|
56
|
this.xqueryForServiceIdParam = xqueryForServiceIdParam;
|
57
|
}
|
58
|
|
59
|
public String getPortal() {
|
60
|
return this.portal;
|
61
|
}
|
62
|
|
63
|
public void setPortal(final String portal) {
|
64
|
this.portal = portal;
|
65
|
}
|
66
|
|
67
|
public String getPortalParam() {
|
68
|
return this.portalParam;
|
69
|
}
|
70
|
|
71
|
public void setPortalParam(final String portalParam) {
|
72
|
this.portalParam = portalParam;
|
73
|
}
|
74
|
|
75
|
}
|