Revision 46596
Added by Alessia Bardi almost 7 years ago
PrepareOaiDataJobNode.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import javax.annotation.Resource; |
4 | 4 |
|
5 |
import org.apache.commons.logging.Log; |
|
6 |
import org.apache.commons.logging.LogFactory; |
|
7 |
|
|
8 | 5 |
import com.googlecode.sarasvati.Arc; |
9 | 6 |
import com.googlecode.sarasvati.NodeToken; |
10 |
|
|
7 |
import eu.dnetlib.data.information.oai.utils.OAIParameterNames; |
|
11 | 8 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
12 | 9 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
13 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
14 | 10 |
import eu.dnetlib.msro.rmi.MSROException; |
15 | 11 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
12 |
import org.apache.commons.lang.StringUtils; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
16 | 15 |
|
17 | 16 |
/** |
18 |
* The Class PrepareOaiDataJobNode. |
|
17 |
* The Class PrepareOaiDataJobNode. Sets the OAI parameters in the env using the constants in OAIParameterNames, to be used by subsequent nodes.
|
|
19 | 18 |
*/ |
20 | 19 |
public class PrepareOaiDataJobNode extends SimpleJobNode { |
21 | 20 |
|
... | ... | |
26 | 25 |
@Resource |
27 | 26 |
private UniqueServiceLocator serviceLocator; |
28 | 27 |
|
29 |
/** Target mongo oai store collection name. **/ |
|
30 |
private String oaiStoreCollectionParam; |
|
28 |
private String oaiDbName; |
|
29 |
private String oaiFormat; |
|
30 |
private String oaiLayout; |
|
31 |
private String oaiInterpretation; |
|
32 |
private String oaiSource; |
|
31 | 33 |
|
32 |
/** Target mongo database name. **/ |
|
33 |
private String oaiDBName; |
|
34 |
/** Name of the env property where to put the value of oaiDBName. **/ |
|
35 |
private String oaiDBNameParam; |
|
36 |
|
|
37 |
private String formatParam = "oai_format"; |
|
38 |
|
|
39 |
private String layoutParam = "oai_layout"; |
|
40 |
|
|
41 |
private String interpretationParam = "oai_interpretation"; |
|
42 |
|
|
43 |
private boolean skipDuplicates = false; |
|
44 |
private String duplicateXPath; |
|
45 |
|
|
46 | 34 |
/* |
47 | 35 |
* (non-Javadoc) |
48 | 36 |
* |
... | ... | |
52 | 40 |
protected String execute(final NodeToken token) throws Exception { |
53 | 41 |
|
54 | 42 |
log.info("start preparing job"); |
43 |
setIfNotBlank(OAIParameterNames.OAI_DB, oaiDbName, token); |
|
44 |
setIfNotBlank(OAIParameterNames.OAI_FORMAT_NAME, oaiFormat, token); |
|
45 |
setIfNotBlank(OAIParameterNames.OAI_FORMAT_LAYOUT, oaiLayout, token); |
|
46 |
setIfNotBlank(OAIParameterNames.OAI_FORMAT_INTERPRETATION, oaiInterpretation, token); |
|
47 |
setIfNotBlank(OAIParameterNames.OAI_COLLECTON, oaiFormat + "-" + oaiLayout + "-" + oaiInterpretation, token); |
|
55 | 48 |
|
56 |
// set the target mongo collection name |
|
57 |
String format = token.getEnv().getAttribute(getFormatParam()); |
|
58 |
String interpretation = token.getEnv().getAttribute(getInterpretationParam()); |
|
59 |
String layout = token.getEnv().getAttribute(getLayoutParam()); |
|
60 |
token.getEnv().setAttribute(getOaiStoreCollectionParam(), format + "-" + layout + "-" + interpretation); |
|
61 |
|
|
62 | 49 |
String configurationProfile = getConfigurationProfile(); |
63 |
token.getEnv().setAttribute("oaiConfiguration", configurationProfile); |
|
64 |
token.getEnv().setAttribute("oai.feed.date", DateUtils.now_ISO8601()); |
|
65 |
|
|
66 |
token.getEnv().setAttribute(getOaiDBNameParam(), getOaiDBName()); |
|
67 |
|
|
68 |
// services.publisher.oai. |
|
69 |
// duplicates |
|
70 |
token.getEnv().setAttribute("services.publisher.oai.skipDuplicates", skipDuplicates); |
|
71 |
token.getEnv().setAttribute("services.publisher.oai.duplicateXPath", duplicateXPath); |
|
72 |
|
|
50 |
setIfNotBlank(OAIParameterNames.OAI_CONFIGURATION_PROFILE, configurationProfile, token); |
|
73 | 51 |
return Arc.DEFAULT_ARC; |
74 | 52 |
} |
75 | 53 |
|
54 |
private void setIfNotBlank(final String attrName, final String attrValue, final NodeToken token){ |
|
55 |
if(StringUtils.isNotBlank(attrValue)) |
|
56 |
token.getEnv().setAttribute(attrName, attrValue); |
|
57 |
} |
|
58 |
|
|
76 | 59 |
/** |
77 | 60 |
* Gets the configuration profile. |
78 | 61 |
* |
... | ... | |
89 | 72 |
} |
90 | 73 |
} |
91 | 74 |
|
92 |
/** |
|
93 |
* Gets the oai store collection param. |
|
94 |
* |
|
95 |
* @return the oai store collection param |
|
96 |
*/ |
|
97 |
public String getOaiStoreCollectionParam() { |
|
98 |
return oaiStoreCollectionParam; |
|
75 |
public String getOaiDbName() { |
|
76 |
return oaiDbName; |
|
99 | 77 |
} |
100 | 78 |
|
101 |
/** |
|
102 |
* Sets the oai store collection param. |
|
103 |
* |
|
104 |
* @param oaiStoreCollectionParam |
|
105 |
* the new oai store collection param |
|
106 |
*/ |
|
107 |
public void setOaiStoreCollectionParam(final String oaiStoreCollectionParam) { |
|
108 |
this.oaiStoreCollectionParam = oaiStoreCollectionParam; |
|
79 |
public void setOaiDbName(final String oaiDbName) { |
|
80 |
this.oaiDbName = oaiDbName; |
|
109 | 81 |
} |
110 | 82 |
|
111 |
public String getOaiDBName() {
|
|
112 |
return oaiDBName;
|
|
83 |
public String getOaiFormat() {
|
|
84 |
return oaiFormat;
|
|
113 | 85 |
} |
114 | 86 |
|
115 |
public void setOaiDBName(final String oaiDBName) {
|
|
116 |
this.oaiDBName = oaiDBName;
|
|
87 |
public void setOaiFormat(final String oaiFormat) {
|
|
88 |
this.oaiFormat = oaiFormat;
|
|
117 | 89 |
} |
118 | 90 |
|
119 |
public String getOaiDBNameParam() {
|
|
120 |
return oaiDBNameParam;
|
|
91 |
public String getOaiLayout() {
|
|
92 |
return oaiLayout;
|
|
121 | 93 |
} |
122 | 94 |
|
123 |
public void setOaiDBNameParam(final String oaiDBNameParam) {
|
|
124 |
this.oaiDBNameParam = oaiDBNameParam;
|
|
95 |
public void setOaiLayout(final String oaiLayout) {
|
|
96 |
this.oaiLayout = oaiLayout;
|
|
125 | 97 |
} |
126 | 98 |
|
127 |
public String getFormatParam() {
|
|
128 |
return formatParam;
|
|
99 |
public String getOaiInterpretation() {
|
|
100 |
return oaiInterpretation;
|
|
129 | 101 |
} |
130 | 102 |
|
131 |
public void setFormatParam(final String formatParam) {
|
|
132 |
this.formatParam = formatParam;
|
|
103 |
public void setOaiInterpretation(final String oaiInterpretation) {
|
|
104 |
this.oaiInterpretation = oaiInterpretation;
|
|
133 | 105 |
} |
134 | 106 |
|
135 |
public String getLayoutParam() {
|
|
136 |
return layoutParam;
|
|
107 |
public String getOaiSource() {
|
|
108 |
return oaiSource;
|
|
137 | 109 |
} |
138 | 110 |
|
139 |
public void setLayoutParam(final String layoutParam) {
|
|
140 |
this.layoutParam = layoutParam;
|
|
111 |
public void setOaiSource(final String oaiSource) {
|
|
112 |
this.oaiSource = oaiSource;
|
|
141 | 113 |
} |
142 | 114 |
|
143 |
public String getInterpretationParam() { |
|
144 |
return interpretationParam; |
|
145 |
} |
|
146 | 115 |
|
147 |
public void setInterpretationParam(final String interpretationParam) { |
|
148 |
this.interpretationParam = interpretationParam; |
|
149 |
} |
|
150 |
|
|
151 |
public boolean isSkipDuplicates() { |
|
152 |
return skipDuplicates; |
|
153 |
} |
|
154 |
|
|
155 |
public void setSkipDuplicates(final boolean skipDuplicates) { |
|
156 |
this.skipDuplicates = skipDuplicates; |
|
157 |
} |
|
158 |
|
|
159 |
public String getDuplicateXPath() { |
|
160 |
return duplicateXPath; |
|
161 |
} |
|
162 |
|
|
163 |
public void setDuplicateXPath(final String duplicateXPath) { |
|
164 |
this.duplicateXPath = duplicateXPath; |
|
165 |
} |
|
166 |
|
|
167 | 116 |
} |
Also available in: Unified diff
integrated changes from 'refactoring' branch