Revision 42184
Added by Michele Artini about 8 years ago
OAIConfigurationStringReader.java | ||
---|---|---|
3 | 3 |
import java.io.IOException; |
4 | 4 |
import java.util.List; |
5 | 5 |
import java.util.stream.Collectors; |
6 |
|
|
6 | 7 |
import javax.annotation.Resource; |
7 | 8 |
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
|
|
8 | 12 |
import com.google.common.collect.Lists; |
13 |
|
|
9 | 14 |
import eu.dnetlib.oai.PublisherField; |
10 | 15 |
import eu.dnetlib.oai.info.SetInfo; |
11 |
import eu.dnetlib.oai.publisher.OaiPublisherRuntimeException; |
|
12 | 16 |
import eu.dnetlib.rmi.provision.MDFInfo; |
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
17 |
import eu.dnetlib.rmi.provision.OaiPublisherRuntimeException; |
|
15 | 18 |
|
16 | 19 |
/** |
17 | 20 |
* Instances of this class reads the OAI configuration from a string, which is the configuration profile passed in as a string. |
... | ... | |
27 | 30 |
private OAIConfigurationParser configurationParser; |
28 | 31 |
|
29 | 32 |
public OAIConfigurationStringReader() { |
30 |
oaiConfiguration = null; |
|
33 |
this.oaiConfiguration = null;
|
|
31 | 34 |
} |
32 | 35 |
|
33 | 36 |
public OAIConfigurationStringReader(final String profile) { |
... | ... | |
37 | 40 |
public void readConfiguration(final String profile) { |
38 | 41 |
log.debug(profile); |
39 | 42 |
try { |
40 |
oaiConfiguration = configurationParser.getConfiguration(profile);
|
|
41 |
} catch (IOException e) { |
|
43 |
this.oaiConfiguration = this.configurationParser.getConfiguration(profile);
|
|
44 |
} catch (final IOException e) {
|
|
42 | 45 |
throw new OaiPublisherRuntimeException("Could not read OAI configuration profile", e); |
43 | 46 |
} |
44 | 47 |
} |
... | ... | |
49 | 52 |
|
50 | 53 |
@Override |
51 | 54 |
public List<SetInfo> getSets() { |
52 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getSetsMap().values()); |
|
53 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
55 |
if (isConfigurationLoaded()) { |
|
56 |
return Lists.newArrayList(this.oaiConfiguration.getSetsMap().values()); |
|
57 |
} else { |
|
58 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
59 |
} |
|
54 | 60 |
} |
55 | 61 |
|
56 | 62 |
@Override |
57 | 63 |
public List<SetInfo> getSets(final boolean onlyEnabled) { |
58 | 64 |
|
59 |
if (isConfigurationLoaded()) return
|
|
60 |
this.oaiConfiguration.getSetsMap().values().stream().
|
|
61 |
filter(it -> onlyEnabled ? it.isEnabled() : true).collect(
|
|
62 |
Collectors.toList());
|
|
63 |
|
|
64 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded");
|
|
65 |
if (isConfigurationLoaded()) {
|
|
66 |
return this.oaiConfiguration.getSetsMap().values().stream().filter(it -> onlyEnabled ? it.isEnabled() : true).collect(
|
|
67 |
Collectors.toList());
|
|
68 |
} else {
|
|
69 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
70 |
}
|
|
65 | 71 |
} |
66 | 72 |
|
67 | 73 |
@Override |
68 | 74 |
public List<String> getSetSpecs() { |
69 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getSetsMap().keySet()); |
|
70 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
75 |
if (isConfigurationLoaded()) { |
|
76 |
return Lists.newArrayList(this.oaiConfiguration.getSetsMap().keySet()); |
|
77 |
} else { |
|
78 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
79 |
} |
|
71 | 80 |
} |
72 | 81 |
|
73 | 82 |
@Override |
74 | 83 |
public List<String> getSetSpecs(final boolean onlyEnabled) { |
75 | 84 |
if (isConfigurationLoaded()) { |
76 |
if (!onlyEnabled) return this.getSetSpecs();
|
|
77 |
List<SetInfo> enabled = this.getSets(true); |
|
85 |
if (!onlyEnabled) { return this.getSetSpecs(); }
|
|
86 |
final List<SetInfo> enabled = this.getSets(true);
|
|
78 | 87 |
return enabled.stream().map(it -> it.getSetSpec()).collect(Collectors.toList()); |
79 | 88 |
|
80 |
} else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
89 |
} else { |
|
90 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
91 |
} |
|
81 | 92 |
} |
82 | 93 |
|
83 | 94 |
@Override |
84 | 95 |
public List<MDFInfo> getSourceMetadataFormats() { |
85 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getSourcesMDF().stream().collect(Collectors.toList()); |
|
86 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
96 |
if (isConfigurationLoaded()) { |
|
97 |
return this.oaiConfiguration.getSourcesMDF().stream().collect(Collectors.toList()); |
|
98 |
} else { |
|
99 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
100 |
} |
|
87 | 101 |
} |
88 | 102 |
|
89 | 103 |
@Override |
90 | 104 |
public SetInfo getSetInfo(final String setSpec) { |
91 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getSetsMap().get(setSpec); |
|
92 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
105 |
if (isConfigurationLoaded()) { |
|
106 |
return this.oaiConfiguration.getSetsMap().get(setSpec); |
|
107 |
} else { |
|
108 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
109 |
} |
|
93 | 110 |
} |
94 | 111 |
|
95 | 112 |
@Override |
96 | 113 |
public List<MDFInfo> getMetadataFormatInfo() { |
97 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getMdFormatsMap().values()); |
|
98 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
114 |
if (isConfigurationLoaded()) { |
|
115 |
return Lists.newArrayList(this.oaiConfiguration.getMdFormatsMap().values()); |
|
116 |
} else { |
|
117 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
118 |
} |
|
99 | 119 |
} |
100 | 120 |
|
101 | 121 |
@Override |
102 | 122 |
public List<MDFInfo> getMetadataFormatInfo(final boolean onlyEnabled) { |
103 | 123 |
if (isConfigurationLoaded()) { |
104 |
if (!onlyEnabled) return this.getMetadataFormatInfo();
|
|
105 |
else return this.oaiConfiguration.getMdFormatsMap().values().
|
|
106 |
stream().
|
|
107 |
filter(it -> onlyEnabled ? it.isEnabled() : true).
|
|
108 |
collect(Collectors.toList());
|
|
124 |
if (!onlyEnabled) {
|
|
125 |
return this.getMetadataFormatInfo();
|
|
126 |
} else {
|
|
127 |
return this.oaiConfiguration.getMdFormatsMap().values().stream().filter(it -> onlyEnabled ? it.isEnabled() : true).collect(Collectors.toList());
|
|
128 |
}
|
|
109 | 129 |
|
110 |
} else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
130 |
} else { |
|
131 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
132 |
} |
|
111 | 133 |
} |
112 | 134 |
|
113 | 135 |
@Override |
114 | 136 |
public MDFInfo getMetadataFormatInfo(final String mdPrefix) { |
115 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getMdFormatsMap().get(mdPrefix); |
|
116 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
137 |
if (isConfigurationLoaded()) { |
|
138 |
return this.oaiConfiguration.getMdFormatsMap().get(mdPrefix); |
|
139 |
} else { |
|
140 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
141 |
} |
|
117 | 142 |
} |
118 | 143 |
|
119 | 144 |
@Override |
120 | 145 |
public List<PublisherField> getFields() { |
121 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getFields(); |
|
122 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
146 |
if (isConfigurationLoaded()) { |
|
147 |
return this.oaiConfiguration.getFields(); |
|
148 |
} else { |
|
149 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
150 |
} |
|
123 | 151 |
} |
124 | 152 |
|
125 | 153 |
@Override |
126 | 154 |
public List<PublisherField> getFields(final String format, final String interpretation, final String layout) { |
127 |
if (isConfigurationLoaded()) return Lists.newArrayList(this.oaiConfiguration.getFieldsFor(format, layout, interpretation)); |
|
128 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
155 |
if (isConfigurationLoaded()) { |
|
156 |
return Lists.newArrayList(this.oaiConfiguration.getFieldsFor(format, layout, interpretation)); |
|
157 |
} else { |
|
158 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
159 |
} |
|
129 | 160 |
} |
130 | 161 |
|
131 | 162 |
@Override |
132 | 163 |
public List<String> getFieldNames() { |
133 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getFieldNames(); |
|
134 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
164 |
if (isConfigurationLoaded()) { |
|
165 |
return this.oaiConfiguration.getFieldNames(); |
|
166 |
} else { |
|
167 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
168 |
} |
|
135 | 169 |
} |
136 | 170 |
|
137 | 171 |
@Override |
138 | 172 |
public List<MDFInfo> getFormatsServedBy(final String sourceFormatName, final String sourceFormatLayout, final String sourceFormatInterpretation) { |
139 | 173 |
if (isConfigurationLoaded()) { |
140 | 174 |
return this.oaiConfiguration.getMdFormatsMap().values().stream() |
141 |
.filter(mdf -> |
|
142 |
(mdf.getSourceFormatName() == sourceFormatName) && (mdf.getSourceFormatLayout() == sourceFormatLayout) |
|
143 |
&& (mdf.getSourceFormatInterpretation() == sourceFormatInterpretation)) |
|
175 |
.filter(mdf -> (mdf.getSourceFormatName() == sourceFormatName) && (mdf.getSourceFormatLayout() == sourceFormatLayout) |
|
176 |
&& (mdf.getSourceFormatInterpretation() == sourceFormatInterpretation)) |
|
144 | 177 |
.collect(Collectors.toList()); |
145 |
} else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
178 |
} else { |
|
179 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
180 |
} |
|
146 | 181 |
} |
147 | 182 |
|
148 | 183 |
@Override |
149 | 184 |
public String getIdScheme() { |
150 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getIdScheme(); |
|
151 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
185 |
if (isConfigurationLoaded()) { |
|
186 |
return this.oaiConfiguration.getIdScheme(); |
|
187 |
} else { |
|
188 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
189 |
} |
|
152 | 190 |
} |
153 | 191 |
|
154 | 192 |
@Override |
155 | 193 |
public String getIdNamespace() { |
156 |
if (isConfigurationLoaded()) return this.oaiConfiguration.getIdNamespace(); |
|
157 |
else throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
194 |
if (isConfigurationLoaded()) { |
|
195 |
return this.oaiConfiguration.getIdNamespace(); |
|
196 |
} else { |
|
197 |
throw new OaiPublisherRuntimeException("Configuration is not loaded"); |
|
198 |
} |
|
158 | 199 |
} |
159 | 200 |
|
160 | 201 |
public OAIConfiguration getOaiConfiguration() { |
161 |
return oaiConfiguration; |
|
202 |
return this.oaiConfiguration;
|
|
162 | 203 |
} |
163 | 204 |
|
164 | 205 |
public void setOaiConfiguration(final OAIConfiguration oaiConfiguration) { |
... | ... | |
166 | 207 |
} |
167 | 208 |
|
168 | 209 |
public OAIConfigurationParser getConfigurationParser() { |
169 |
return configurationParser; |
|
210 |
return this.configurationParser;
|
|
170 | 211 |
} |
171 | 212 |
|
172 | 213 |
public void setConfigurationParser(final OAIConfigurationParser configurationParser) { |
Also available in: Unified diff
oai import