Project

General

Profile

1
package eu.dnetlib.msro.openaireplus.workflows.nodes.stats;
2

    
3
import java.util.List;
4

    
5
import com.googlecode.sarasvati.NodeToken;
6
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
7
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
8
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
9
import org.apache.commons.lang.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 NodeToken token) {
31
		final String xquery = token.getEnv().getAttribute(getXqueryForServiceIdParam());
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 (ISLookUpException e) {
39
			throw new RuntimeException(e);
40
		}
41
	}
42

    
43
	public String getPortalName(final NodeToken token) {
44
		if (StringUtils.isNotBlank(portal)) return portal;
45
		else return token.getEnv().getAttribute(portalParam);
46
	}
47

    
48
	public String getXqueryForServiceIdParam() {
49
		return xqueryForServiceIdParam;
50
	}
51

    
52
	public void setXqueryForServiceIdParam(final String xqueryForServiceIdParam) {
53
		this.xqueryForServiceIdParam = xqueryForServiceIdParam;
54
	}
55

    
56
	public String getPortal() {
57
		return portal;
58
	}
59

    
60
	public void setPortal(final String portal) {
61
		this.portal = portal;
62
	}
63

    
64
	public String getPortalParam() {
65
		return portalParam;
66
	}
67

    
68
	public void setPortalParam(final String portalParam) {
69
		this.portalParam = portalParam;
70
	}
71

    
72
}
(1-1/10)