Revision 42977
Added by Alessia Bardi over 8 years ago
modules/dnet-openaireplus-workflows/trunk/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/index/SwitchIndexesJobNode.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
private static final Log log = LogFactory.getLog(SwitchIndexesJobNode.class); |
23 | 23 |
|
24 |
private String xqueryForServiceIdParam; |
|
25 |
|
|
26 | 24 |
@Override |
27 | 25 |
protected String execute(final NodeToken token) throws Exception { |
28 | 26 |
Queue<String> q = (Queue<String>) token.getEnv().getTransientAttribute("searchService_ids"); |
... | ... | |
37 | 35 |
String id = q.poll(); |
38 | 36 |
log.debug("Polled id: "+id); |
39 | 37 |
log.debug("And now the queue is "+q); |
40 |
String xquery = "/RESOURCE_PROFILE[./HEADER/RESOURCE_IDENTIFIER/@value = '"+id+"']"; |
|
41 |
token.getEnv().setAttribute(getXqueryForServiceIdParam(), xquery); |
|
42 |
log.debug("Asking to switch on profile identified by: "+xquery); |
|
38 |
token.getEnv().setAttribute("search_service_ID", id); |
|
39 |
log.debug("Asking to switch on profile with id: "+id); |
|
43 | 40 |
//updating the queue for next iteration |
44 | 41 |
token.getEnv().setTransientAttribute("searchService_ids", q); |
45 | 42 |
return "switch"; |
... | ... | |
47 | 44 |
} |
48 | 45 |
|
49 | 46 |
|
50 |
public String getXqueryForServiceIdParam() { |
|
51 |
return xqueryForServiceIdParam; |
|
52 |
} |
|
53 |
|
|
54 |
public void setXqueryForServiceIdParam(final String xqueryForServiceIdParam) { |
|
55 |
this.xqueryForServiceIdParam = xqueryForServiceIdParam; |
|
56 |
} |
|
57 |
|
|
58 | 47 |
} |
modules/dnet-openaireplus-workflows/trunk/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/index/SwitchSearchServiceJobNode.java | ||
---|---|---|
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 |
* SwitchSearchServiceJobNode switches the index used by a SearchService whose profile id is in 'search_service_ID' env param. |
|
17 |
* |
|
18 |
* @author claudio, alessia |
|
19 |
* |
|
20 |
*/ |
|
21 |
public class SwitchSearchServiceJobNode extends BlackboardJobNode { |
|
22 |
|
|
23 |
private static final Log log = LogFactory.getLog(SwitchSearchServiceJobNode.class); |
|
24 |
private static final String BB_ACTION_SWITCH_INDEX = "UpdateIndex"; |
|
25 |
|
|
26 |
private String inputIndexIdParam; |
|
27 |
|
|
28 |
private String outputIndexIdParam; |
|
29 |
|
|
30 |
|
|
31 |
@Override |
|
32 |
protected String obtainServiceId(final NodeToken token) { |
|
33 |
final String id = token.getEnv().getAttribute("search_service_ID"); |
|
34 |
if(StringUtils.isBlank(id)) throw new RuntimeException("No id found in env attribute 'search_service_ID'"); |
|
35 |
else return id; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
40 |
job.setAction(BB_ACTION_SWITCH_INDEX); |
|
41 |
String indexId = token.getEnv().getAttribute(getInputIndexIdParam()); |
|
42 |
|
|
43 |
checkParam(getInputIndexIdParam(), "output indexId param is missing"); |
|
44 |
checkParam(indexId, "indexId is required to perform switch"); |
|
45 |
log.info("Switching "+obtainServiceId(token)+" to index "+indexId); |
|
46 |
job.getParameters().put(getOutputIndexIdParam(), indexId); |
|
47 |
} |
|
48 |
|
|
49 |
private void checkParam(final String param, final String msg) throws MSROException { |
|
50 |
if (StringUtils.isBlank(param)) throw new MSROException(msg); |
|
51 |
} |
|
52 |
|
|
53 |
public String getInputIndexIdParam() { |
|
54 |
return inputIndexIdParam; |
|
55 |
} |
|
56 |
|
|
57 |
public void setInputIndexIdParam(final String inputIndexIdParam) { |
|
58 |
this.inputIndexIdParam = inputIndexIdParam; |
|
59 |
} |
|
60 |
|
|
61 |
public String getOutputIndexIdParam() { |
|
62 |
return outputIndexIdParam; |
|
63 |
} |
|
64 |
|
|
65 |
public void setOutputIndexIdParam(final String outputIndexIdParam) { |
|
66 |
this.outputIndexIdParam = outputIndexIdParam; |
|
67 |
} |
|
68 |
|
|
69 |
} |
modules/dnet-openaireplus-workflows/trunk/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/index/SwitchIndexJobNode.java | ||
---|---|---|
18 | 18 |
* SwitchIndexJobNode performs index switch. |
19 | 19 |
* |
20 | 20 |
* @author claudio |
21 |
* |
|
21 |
* @deprecated |
|
22 |
* @see eu.dnetlib.msro.openaireplus.workflows.nodes.index.SwitchSearchServiceJobNode |
|
23 |
* @see eu.dnetlib.msro.openaireplus.workflows.nodes.index.SwitchIndexesJobNode |
|
22 | 24 |
*/ |
25 |
@Deprecated |
|
23 | 26 |
public class SwitchIndexJobNode extends BlackboardJobNode { |
24 | 27 |
|
25 | 28 |
private static final Log log = LogFactory.getLog(SwitchIndexJobNode.class); |
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/test/profiles/openaireplus/workflows/provision/index.switch.multiple.xml | ||
---|---|---|
36 | 36 |
</NODE> |
37 | 37 |
<NODE name="switches" type="SwitchIndexes"> |
38 | 38 |
<DESCRIPTION>switch index</DESCRIPTION> |
39 |
<PARAMETERS> |
|
40 |
<PARAM name="xqueryForServiceIdParam" type="string" managedBy="system" required="true">xqueryForSearchService</PARAM> |
|
41 |
</PARAMETERS> |
|
39 |
<PARAMETERS></PARAMETERS> |
|
42 | 40 |
<ARCS> |
43 | 41 |
<ARC name="switch" to="switch" /> |
44 | 42 |
<ARC to="success" /> |
45 | 43 |
</ARCS> |
46 | 44 |
</NODE> |
47 | 45 |
|
48 |
<NODE name="switch" type="SwitchIndex">
|
|
46 |
<NODE name="switch" type="SwitchSearchService">
|
|
49 | 47 |
<DESCRIPTION>switch index</DESCRIPTION> |
50 | 48 |
<PARAMETERS> |
51 |
<PARAM name="xqueryForServiceIdParam" type="string" managedBy="system" required="true">xqueryForSearchService</PARAM> |
|
52 | 49 |
<PARAM name="inputIndexIdParam" type="string" managedBy="system" required="true">index_id</PARAM> |
53 | 50 |
<PARAM name="outputIndexIdParam" type="string" managedBy="system" required="true">IndexId</PARAM> |
54 | 51 |
</PARAMETERS> |
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/msro/openaireplus/workflows/applicationContext-msro-openaire-nodes.xml | ||
---|---|---|
141 | 141 |
<bean id="wfNodeSwitchIndexes" |
142 | 142 |
class="eu.dnetlib.msro.openaireplus.workflows.nodes.index.SwitchIndexesJobNode" |
143 | 143 |
scope="prototype"/> |
144 |
<bean id="wfNodeSwitchSearchService" |
|
145 |
class="eu.dnetlib.msro.openaireplus.workflows.nodes.index.SwitchSearchServiceJobNode" |
|
146 |
scope="prototype"/> |
|
144 | 147 |
|
145 | 148 |
<!-- DEDUP --> |
146 | 149 |
|
Also available in: Unified diff
It is useless to perform an xquery by id to get the id of a profile: now using 'search_service_ID' env parameter