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.lookup.rmi.ISLookUpService;
9
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
10
import eu.dnetlib.miscutils.datetime.DateUtils;
11
import eu.dnetlib.msro.rmi.MSROException;
12
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
13
import org.apache.commons.lang.StringUtils;
14
import org.apache.commons.logging.Log;
15
import org.apache.commons.logging.LogFactory;
16

    
17
/**
18
 * The Class PrepareOaiDataJobNode. Sets the OAI parameters in the env using the constants in OAIParameterNames, to be used by subsequent nodes.
19
 */
20
public class PrepareOaiDataJobNode extends SimpleJobNode {
21

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

    
25
	/** The service locator. */
26
	@Resource
27
	private UniqueServiceLocator serviceLocator;
28

    
29
	private String oaiDbName;
30
	private String oaiFormat;
31
	private String oaiLayout;
32
	private String oaiInterpretation;
33
	private String oaiSource;
34

    
35
	private boolean skipDuplicates = false;
36
	private String duplicateXPath;
37

    
38
	/*
39
	 * (non-Javadoc)
40
	 * 
41
	 * @see eu.dnetlib.msro.workflows.nodes.SimpleJobNode#execute(com.googlecode.sarasvati.NodeToken)
42
	 */
43
	@Override
44
	protected String execute(final NodeToken token) throws Exception {
45

    
46
		log.info("start preparing job");
47
		token.getEnv().setAttribute(OAIParameterNames.OAI_ACTION_DATE, DateUtils.now_ISO8601());
48
		setIfNotBlank(OAIParameterNames.OAI_DB, oaiDbName, token);
49
		setIfNotBlank(OAIParameterNames.OAI_FORMAT_NAME, oaiFormat, token);
50
		setIfNotBlank(OAIParameterNames.OAI_FORMAT_LAYOUT, oaiLayout, token);
51
		setIfNotBlank(OAIParameterNames.OAI_FORMAT_INTERPRETATION, oaiInterpretation, token);
52
		setIfNotBlank(OAIParameterNames.OAI_COLLECTON, oaiFormat + "-" + oaiLayout + "-" + oaiInterpretation, token);
53

    
54
		String configurationProfile = getConfigurationProfile();
55
		setIfNotBlank(OAIParameterNames.OAI_CONFIGURATION_PROFILE, configurationProfile, token);
56
		token.getEnv().setAttribute(OAIParameterNames.OAI_SKIP_DUPLICATES, String.valueOf(skipDuplicates));
57
		if(skipDuplicates) token.getEnv().setAttribute(OAIParameterNames.OAI_DUPLICATE_XPATH, duplicateXPath);
58
		return Arc.DEFAULT_ARC;
59
	}
60

    
61
	private void setIfNotBlank(final String attrName, final String attrValue, final NodeToken token){
62
		if(StringUtils.isNotBlank(attrValue))
63
			token.getEnv().setAttribute(attrName, attrValue);
64
	}
65

    
66
	/**
67
	 * Gets the configuration profile.
68
	 * 
69
	 * @return the configuration profile
70
	 * @throws MSROException
71
	 *             the MSRO exception
72
	 */
73
	private String getConfigurationProfile() throws MSROException {
74
		try {
75
			return this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(
76
					"//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value = 'OAIPublisherConfigurationDSResourceType']");
77
		} catch (Exception e) {
78
			throw new MSROException("Cannot find OAI configuration profile", e);
79
		}
80
	}
81

    
82
	public String getOaiDbName() {
83
		return oaiDbName;
84
	}
85

    
86
	public void setOaiDbName(final String oaiDbName) {
87
		this.oaiDbName = oaiDbName;
88
	}
89

    
90
	public String getOaiFormat() {
91
		return oaiFormat;
92
	}
93

    
94
	public void setOaiFormat(final String oaiFormat) {
95
		this.oaiFormat = oaiFormat;
96
	}
97

    
98
	public String getOaiLayout() {
99
		return oaiLayout;
100
	}
101

    
102
	public void setOaiLayout(final String oaiLayout) {
103
		this.oaiLayout = oaiLayout;
104
	}
105

    
106
	public String getOaiInterpretation() {
107
		return oaiInterpretation;
108
	}
109

    
110
	public void setOaiInterpretation(final String oaiInterpretation) {
111
		this.oaiInterpretation = oaiInterpretation;
112
	}
113

    
114
	public String getOaiSource() {
115
		return oaiSource;
116
	}
117

    
118
	public void setOaiSource(final String oaiSource) {
119
		this.oaiSource = oaiSource;
120
	}
121

    
122
	public boolean isSkipDuplicates() {
123
		return skipDuplicates;
124
	}
125

    
126
	public void setSkipDuplicates(final boolean skipDuplicates) {
127
		this.skipDuplicates = skipDuplicates;
128
	}
129

    
130
	public String getDuplicateXPath() {
131
		return duplicateXPath;
132
	}
133

    
134
	public void setDuplicateXPath(final String duplicateXPath) {
135
		this.duplicateXPath = duplicateXPath;
136
	}
137

    
138

    
139

    
140
}
(7-7/10)