1
|
package eu.dnetlib.msro.workflows.nodes.index;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
6
|
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
|
7
|
import eu.dnetlib.msro.workflows.procs.Env;
|
8
|
import eu.dnetlib.msro.workflows.procs.Token;
|
9
|
import eu.dnetlib.rmi.enabling.ISLookUpException;
|
10
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
11
|
import eu.dnetlib.rmi.manager.MSROException;
|
12
|
import org.apache.commons.lang3.StringUtils;
|
13
|
|
14
|
/**
|
15
|
* SwitchIndexJobNode performs index switch.
|
16
|
*
|
17
|
* @author claudio
|
18
|
*/
|
19
|
public class SwitchIndexJobNode extends BlackboardJobNode {
|
20
|
|
21
|
private static final String BB_ACTION_SWITCH_INDEX = "UpdateIndex";
|
22
|
|
23
|
private String inputIndexIdParam;
|
24
|
|
25
|
private String outputIndexIdParam;
|
26
|
|
27
|
private String xqueryForServiceIdParam;
|
28
|
|
29
|
@Override
|
30
|
protected String obtainServiceId(final Env env) {
|
31
|
final String xquery = env.getAttribute(getXqueryForServiceIdParam(), String.class);
|
32
|
List<String> searchServiceIds;
|
33
|
try {
|
34
|
searchServiceIds = getServiceLocator().getService(ISLookUpService.class).quickSearchProfile(xquery);
|
35
|
if (searchServiceIds.size() > 1) { throw new RuntimeException("Too many SearchService ids found using query: " + xquery); }
|
36
|
if (searchServiceIds.size() < 1) { throw new RuntimeException("SearchService id not found using query: " + xquery); }
|
37
|
return searchServiceIds.get(0);
|
38
|
} catch (final ISLookUpException e) {
|
39
|
throw new RuntimeException(e);
|
40
|
}
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
protected void prepareJob(final BlackboardJob job, final Token token) throws Exception {
|
45
|
job.setAction(BB_ACTION_SWITCH_INDEX);
|
46
|
final String indexId = token.getEnv().getAttribute(getInputIndexIdParam(), String.class);
|
47
|
|
48
|
checkParam(getInputIndexIdParam(), "output indexId param is missing");
|
49
|
checkParam(indexId, "indexId is required to perform switch");
|
50
|
|
51
|
job.getParameters().put(getOutputIndexIdParam(), indexId);
|
52
|
}
|
53
|
|
54
|
private void checkParam(final String param, final String msg) throws MSROException {
|
55
|
if (StringUtils.isBlank(param)) { throw new MSROException(msg); }
|
56
|
}
|
57
|
|
58
|
public String getInputIndexIdParam() {
|
59
|
return this.inputIndexIdParam;
|
60
|
}
|
61
|
|
62
|
public void setInputIndexIdParam(final String inputIndexIdParam) {
|
63
|
this.inputIndexIdParam = inputIndexIdParam;
|
64
|
}
|
65
|
|
66
|
public String getOutputIndexIdParam() {
|
67
|
return this.outputIndexIdParam;
|
68
|
}
|
69
|
|
70
|
public void setOutputIndexIdParam(final String outputIndexIdParam) {
|
71
|
this.outputIndexIdParam = outputIndexIdParam;
|
72
|
}
|
73
|
|
74
|
public String getXqueryForServiceIdParam() {
|
75
|
return this.xqueryForServiceIdParam;
|
76
|
}
|
77
|
|
78
|
public void setXqueryForServiceIdParam(final String xqueryForServiceIdParam) {
|
79
|
this.xqueryForServiceIdParam = xqueryForServiceIdParam;
|
80
|
}
|
81
|
|
82
|
}
|