Project

General

Profile

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

    
3
import java.util.List;
4

    
5
import org.apache.commons.lang.StringUtils;
6

    
7
import com.googlecode.sarasvati.NodeToken;
8

    
9
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
10
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
11
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
12

    
13
/**
14
 * Abstract BBJob node for sending BB messages to the StatsManagerService. Subclasses must implement the prepareJob method.
15
 * 
16
 * @author alessia
17
 * 
18
 */
19
public abstract class AbstractStatsJobNode extends BlackboardJobNode {
20

    
21
	private String xqueryForServiceIdParam;
22
	/**
23
	 * BB parameter defining which is the portal affected by the action. Overrides the value in the env parameter below.
24
	 */
25
	private String portal;
26
	/**
27
	 * 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
28
	 * in the workflow.
29
	 */
30
	private String portalParam;
31

    
32
	@Override
33
	protected String obtainServiceId(final NodeToken token) {
34
		final String xquery = token.getEnv().getAttribute(getXqueryForServiceIdParam());
35
		List<String> statsServiceIds;
36
		try {
37
			statsServiceIds = getServiceLocator().getService(ISLookUpService.class).quickSearchProfile(xquery);
38
			if (statsServiceIds.size() > 1) throw new RuntimeException("Too many StatsManagerService ids found using query: " + xquery);
39
			if (statsServiceIds.size() < 1) throw new RuntimeException("StatsManagerService id not found using query: " + xquery);
40
			return statsServiceIds.get(0);
41
		} catch (ISLookUpException e) {
42
			throw new RuntimeException(e);
43
		}
44
	}
45

    
46
	public String getPortalName(final NodeToken token) {
47
		if (StringUtils.isNotBlank(portal)) return portal;
48
		else return token.getEnv().getAttribute(portalParam);
49
	}
50

    
51
	public String getXqueryForServiceIdParam() {
52
		return xqueryForServiceIdParam;
53
	}
54

    
55
	public void setXqueryForServiceIdParam(final String xqueryForServiceIdParam) {
56
		this.xqueryForServiceIdParam = xqueryForServiceIdParam;
57
	}
58

    
59
	public String getPortal() {
60
		return portal;
61
	}
62

    
63
	public void setPortal(final String portal) {
64
		this.portal = portal;
65
	}
66

    
67
	public String getPortalParam() {
68
		return portalParam;
69
	}
70

    
71
	public void setPortalParam(final String portalParam) {
72
		this.portalParam = portalParam;
73
	}
74

    
75
}
(1-1/10)