Revision 46596
Added by Alessia Bardi almost 7 years ago
SetCurrentOAIDBJobNode.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import javax.annotation.Resource; |
4 | 4 |
|
5 |
import org.apache.commons.lang.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
|
|
9 | 5 |
import com.googlecode.sarasvati.Arc; |
10 | 6 |
import com.googlecode.sarasvati.NodeToken; |
11 |
|
|
7 |
import eu.dnetlib.data.information.oai.utils.OAIParameterNames; |
|
12 | 8 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
13 | 9 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
14 | 10 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
11 |
import org.apache.commons.lang.StringUtils; |
|
12 |
import org.apache.commons.logging.Log; |
|
13 |
import org.apache.commons.logging.LogFactory; |
|
15 | 14 |
|
16 |
/** |
|
17 |
* The Class PrepareOaiDataJobNode. |
|
18 |
*/ |
|
19 | 15 |
public class SetCurrentOAIDBJobNode extends SimpleJobNode { |
20 | 16 |
|
21 | 17 |
/** The Constant log. */ |
... | ... | |
24 | 20 |
/** The service locator. */ |
25 | 21 |
@Resource |
26 | 22 |
private UniqueServiceLocator serviceLocator; |
23 |
// overrides the value in the env param |
|
24 |
private String oaiDbName; |
|
27 | 25 |
|
28 |
/** Target mongo database name. **/ |
|
29 |
private String oaiDBName; |
|
30 |
/** Name of the env property where to put the value of oaiDBName. **/ |
|
31 |
private String oaiDBNameParam; |
|
32 |
|
|
33 | 26 |
private String xpathToCurrentDB = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value = 'OAIPublisherConfigurationDSResourceType']//CONFIGURATION/CURRENTDB"; |
34 | 27 |
|
35 |
protected String getTheDBName(final NodeToken token) { |
|
36 |
if (StringUtils.isNotBlank(oaiDBName)) { |
|
37 |
return oaiDBName; |
|
38 |
} else { |
|
39 |
return token.getEnv().getAttribute(oaiDBNameParam); |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
/* |
|
44 |
* (non-Javadoc) |
|
45 |
* |
|
46 |
* @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken) |
|
47 |
*/ |
|
48 | 28 |
@Override |
49 | 29 |
protected String execute(final NodeToken token) throws Exception { |
50 |
String dbToSet = getTheDBName(token); |
|
30 |
String dbToSet = getTheOAIDBName(token);
|
|
51 | 31 |
log.fatal("Setting OAI Publisher to use db " + dbToSet); |
52 | 32 |
String xUpdate = "update value " + xpathToCurrentDB + " with '" + dbToSet + "'"; |
53 | 33 |
this.serviceLocator.getService(ISRegistryService.class).executeXUpdate(xUpdate); |
54 | 34 |
return Arc.DEFAULT_ARC; |
55 | 35 |
} |
56 | 36 |
|
57 |
public String getOaiDBName() {
|
|
58 |
return oaiDBName;
|
|
37 |
protected String getTheOAIDBName(final NodeToken token) {
|
|
38 |
return StringUtils.isNotBlank(oaiDbName)? oaiDbName : token.getEnv().getAttribute(OAIParameterNames.OAI_DB);
|
|
59 | 39 |
} |
60 | 40 |
|
61 |
public void setOaiDBName(final String oaiDBName) {
|
|
62 |
this.oaiDBName = oaiDBName;
|
|
41 |
public String getOaiDbName() {
|
|
42 |
return oaiDbName;
|
|
63 | 43 |
} |
64 | 44 |
|
65 |
public String getOaiDBNameParam() {
|
|
66 |
return oaiDBNameParam;
|
|
45 |
public void setOaiDbName(final String oaiDbName) {
|
|
46 |
this.oaiDbName = oaiDbName;
|
|
67 | 47 |
} |
68 | 48 |
|
69 |
public void setOaiDBNameParam(final String oaiDBNameParam) { |
|
70 |
this.oaiDBNameParam = oaiDBNameParam; |
|
71 |
} |
|
72 |
|
|
73 | 49 |
public String getXpathToCurrentDB() { |
74 | 50 |
return xpathToCurrentDB; |
75 | 51 |
} |
... | ... | |
78 | 54 |
this.xpathToCurrentDB = xpathToCurrentDB; |
79 | 55 |
|
80 | 56 |
} |
57 |
|
|
81 | 58 |
} |
Also available in: Unified diff
integrated changes from 'refactoring' branch