Project

General

Profile

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

    
3
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
4
import eu.dnetlib.msro.workflows.graph.Arc;
5
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
6
import eu.dnetlib.msro.workflows.procs.Env;
7
import eu.dnetlib.oai.utils.OAIParameterNames;
8
import eu.dnetlib.rmi.enabling.ISRegistryService;
9
import org.apache.commons.lang3.StringUtils;
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.springframework.beans.factory.annotation.Autowired;
13

    
14
/**
15
 * The Class PrepareOaiDataJobNode.
16
 */
17
public class SetCurrentOAIDBJobNode extends SimpleJobNode {
18

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

    
22
	/** The service locator. */
23
	@Autowired
24
	private UniqueServiceLocator serviceLocator;
25

    
26
	// overrides the value in the env param
27
	private String oaiDbName;
28

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

    
31
	protected String getTheOAIDBName(final Env env) {
32
		return StringUtils.isNotBlank(oaiDbName)? oaiDbName : env.getAttribute(OAIParameterNames.OAI_DB, String.class);
33
	}
34

    
35

    
36
	/*
37
	 * (non-Javadoc)
38
	 *
39
	 * @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken)
40
	 */
41
	@Override
42
	protected String execute(final Env env) throws Exception {
43
		String dbToSet = getTheOAIDBName(env);
44
		log.fatal("Setting OAI Publisher to use db " + dbToSet);
45
		String xUpdate = "update value " + xpathToCurrentDB + " with '" + dbToSet + "'";
46
		this.serviceLocator.getService(ISRegistryService.class).executeXUpdate(xUpdate);
47
		return Arc.DEFAULT_ARC;
48
	}
49

    
50
	public String getOaiDbName() {
51
		return oaiDbName;
52
	}
53

    
54
	public void setOaiDbName(final String oaiDbName) {
55
		this.oaiDbName = oaiDbName;
56
	}
57

    
58
	public String getXpathToCurrentDB() {
59
		return xpathToCurrentDB;
60
	}
61

    
62
	public void setXpathToCurrentDB(final String xpathToCurrentDB) {
63
		this.xpathToCurrentDB = xpathToCurrentDB;
64

    
65
	}
66

    
67
}
(9-9/10)