Project

General

Profile

1
package eu.dnetlib.msro.openaireplus.workflows.nodes.index;
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.enabling.tools.blackboard.BlackboardJob;
9
import eu.dnetlib.msro.rmi.MSROException;
10
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
11
import org.apache.commons.lang.StringUtils;
12
import org.apache.commons.logging.Log;
13
import org.apache.commons.logging.LogFactory;
14

    
15
/**
16
 * SwitchIndexJobNode performs index switch.
17
 *
18
 * @author claudio
19
 * @see eu.dnetlib.msro.openaireplus.workflows.nodes.index.SwitchSearchServiceJobNode
20
 * @see eu.dnetlib.msro.openaireplus.workflows.nodes.index.SwitchIndexesJobNode
21
 * @deprecated
22
 */
23
@Deprecated
24
public class SwitchIndexJobNode extends BlackboardJobNode {
25

    
26
	private static final Log log = LogFactory.getLog(SwitchIndexJobNode.class);
27
	private static final String BB_ACTION_SWITCH_INDEX = "UpdateIndex";
28

    
29
	private String inputIndexIdParam;
30

    
31
	private String outputIndexIdParam;
32

    
33
	private String xqueryForServiceIdParam;
34

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

    
49
	@Override
50
	protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception {
51
		job.setAction(BB_ACTION_SWITCH_INDEX);
52
		String indexId = token.getEnv().getAttribute(getInputIndexIdParam());
53

    
54
		checkParam(getInputIndexIdParam(), "output indexId param is missing");
55
		checkParam(indexId, "indexId is required to perform switch");
56
		log.info("Switching " + obtainServiceId(token) + " to index " + indexId);
57
		job.getParameters().put(getOutputIndexIdParam(), indexId);
58
	}
59

    
60
	private void checkParam(final String param, final String msg) throws MSROException {
61
		if (StringUtils.isBlank(param)) throw new MSROException(msg);
62
	}
63

    
64
	public String getInputIndexIdParam() {
65
		return inputIndexIdParam;
66
	}
67

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

    
72
	public String getOutputIndexIdParam() {
73
		return outputIndexIdParam;
74
	}
75

    
76
	public void setOutputIndexIdParam(final String outputIndexIdParam) {
77
		this.outputIndexIdParam = outputIndexIdParam;
78
	}
79

    
80
	public String getXqueryForServiceIdParam() {
81
		return xqueryForServiceIdParam;
82
	}
83

    
84
	public void setXqueryForServiceIdParam(final String xqueryForServiceIdParam) {
85
		this.xqueryForServiceIdParam = xqueryForServiceIdParam;
86
	}
87

    
88
}
(8-8/10)