Project

General

Profile

1
package eu.dnetlib.msro.oai.workflows.nodes;
2

    
3
import javax.annotation.Resource;
4

    
5
import com.googlecode.sarasvati.Arc;
6
import com.googlecode.sarasvati.NodeToken;
7
import eu.dnetlib.data.information.oai.utils.OAIParameterNames;
8
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
9
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
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;
14

    
15
public class SetCurrentOAIDBJobNode extends SimpleJobNode {
16

    
17
	/** The Constant log. */
18
	private static final Log log = LogFactory.getLog(SetCurrentOAIDBJobNode.class); // NOPMD by marko on 11/24/08 5:02 PM
19

    
20
	/** The service locator. */
21
	@Resource
22
	private UniqueServiceLocator serviceLocator;
23
	// overrides the value in the env param
24
	private String oaiDbName;
25

    
26
	private String xpathToCurrentDB = "//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value = 'OAIPublisherConfigurationDSResourceType']//CONFIGURATION/CURRENTDB";
27

    
28
	@Override
29
	protected String execute(final NodeToken token) throws Exception {
30
		String dbToSet = getTheOAIDBName(token);
31
		log.fatal("Setting OAI Publisher to use db " + dbToSet);
32
		String xUpdate = "update value " + xpathToCurrentDB + " with '" + dbToSet + "'";
33
		this.serviceLocator.getService(ISRegistryService.class).executeXUpdate(xUpdate);
34
		return Arc.DEFAULT_ARC;
35
	}
36

    
37
	protected String getTheOAIDBName(final NodeToken token) {
38
		return StringUtils.isNotBlank(oaiDbName)? oaiDbName : token.getEnv().getAttribute(OAIParameterNames.OAI_DB);
39
	}
40

    
41
	public String getOaiDbName() {
42
		return oaiDbName;
43
	}
44

    
45
	public void setOaiDbName(final String oaiDbName) {
46
		this.oaiDbName = oaiDbName;
47
	}
48

    
49
	public String getXpathToCurrentDB() {
50
		return xpathToCurrentDB;
51
	}
52

    
53
	public void setXpathToCurrentDB(final String xpathToCurrentDB) {
54
		this.xpathToCurrentDB = xpathToCurrentDB;
55

    
56
	}
57

    
58
}
(9-9/10)