29
29
package uk .ac .rdg .resc .edal .ncwms ;
30
30
31
31
import java .io .IOException ;
32
+ import java .lang .reflect .InvocationTargetException ;
32
33
33
34
import net .sf .ehcache .Cache ;
34
35
import net .sf .ehcache .Element ;
@@ -91,15 +92,12 @@ public NcwmsCatalogue(NcwmsConfig config) throws IOException {
91
92
/*
92
93
* Configure cache
93
94
*/
94
- CacheConfiguration cacheConfig = new CacheConfiguration (CACHE_NAME ,
95
- cacheInfo .getNumberOfDatasets ())
96
- .memoryStoreEvictionPolicy (EVICTION_POLICY )
97
- .persistence (new PersistenceConfiguration ()
98
- .strategy (PERSISTENCE_STRATEGY ))
99
- .transactionalMode (TRANSACTIONAL_MODE );
95
+ CacheConfiguration cacheConfig = new CacheConfiguration (CACHE_NAME , cacheInfo .getNumberOfDatasets ())
96
+ .memoryStoreEvictionPolicy (EVICTION_POLICY )
97
+ .persistence (new PersistenceConfiguration ().strategy (PERSISTENCE_STRATEGY ))
98
+ .transactionalMode (TRANSACTIONAL_MODE );
100
99
if (cacheInfo .getElementLifetimeMinutes () > 0 ) {
101
- cacheConfig .setTimeToLiveSeconds (
102
- (long ) (cacheInfo .getElementLifetimeMinutes () * 60 ));
100
+ cacheConfig .setTimeToLiveSeconds ((long ) (cacheInfo .getElementLifetimeMinutes () * 60 ));
103
101
} else {
104
102
cacheConfig .eternal (true );
105
103
}
@@ -112,8 +110,8 @@ public NcwmsCatalogue(NcwmsConfig config) throws IOException {
112
110
}
113
111
114
112
/**
115
- * @return The NcwmsConfig object used by this catalogue. Package-private
116
- * since this should not be accessed by external users
113
+ * @return The NcwmsConfig object used by this catalogue. Package-private since
114
+ * this should not be accessed by external users
117
115
*/
118
116
public NcwmsConfig getConfig () {
119
117
return (NcwmsConfig ) super .getConfig ();
@@ -126,15 +124,12 @@ public void updateDynamicDatasetCache(NcwmsDynamicCacheInfo cacheInfo) {
126
124
/*
127
125
* Create cache
128
126
*/
129
- CacheConfiguration cacheConfig = new CacheConfiguration (CACHE_NAME ,
130
- cacheInfo .getNumberOfDatasets ())
131
- .memoryStoreEvictionPolicy (EVICTION_POLICY )
132
- .persistence (
133
- new PersistenceConfiguration ().strategy (PERSISTENCE_STRATEGY ))
134
- .transactionalMode (TRANSACTIONAL_MODE );
127
+ CacheConfiguration cacheConfig = new CacheConfiguration (CACHE_NAME , cacheInfo .getNumberOfDatasets ())
128
+ .memoryStoreEvictionPolicy (EVICTION_POLICY )
129
+ .persistence (new PersistenceConfiguration ().strategy (PERSISTENCE_STRATEGY ))
130
+ .transactionalMode (TRANSACTIONAL_MODE );
135
131
if (cacheInfo .getElementLifetimeMinutes () > 0 ) {
136
- cacheConfig
137
- .setTimeToLiveSeconds ((long ) (cacheInfo .getElementLifetimeMinutes () * 60 ));
132
+ cacheConfig .setTimeToLiveSeconds ((long ) (cacheInfo .getElementLifetimeMinutes () * 60 ));
138
133
} else {
139
134
cacheConfig .eternal (true );
140
135
}
@@ -150,8 +145,7 @@ public void updateDynamicDatasetCache(NcwmsDynamicCacheInfo cacheInfo) {
150
145
} else {
151
146
dynamicDatasetCache .getCacheConfiguration ().eternal (true );
152
147
}
153
- dynamicDatasetCache .getCacheConfiguration ()
154
- .setMaxEntriesInCache (cacheInfo .getNumberOfDatasets ());
148
+ dynamicDatasetCache .getCacheConfiguration ().setMaxEntriesInCache (cacheInfo .getNumberOfDatasets ());
155
149
}
156
150
}
157
151
@@ -180,17 +174,16 @@ public Dataset getDatasetFromId(String datasetId) {
180
174
return dataset ;
181
175
} else {
182
176
/*
183
- * We may have a dynamic dataset. First check the dynamic dataset
184
- * cache.
177
+ * We may have a dynamic dataset. First check the dynamic dataset cache.
185
178
*/
186
179
Element element = dynamicDatasetCache .get (datasetId );
187
180
if (element != null && element .getObjectValue () != null ) {
188
181
return (Dataset ) element .getObjectValue ();
189
182
}
190
183
191
184
/*
192
- * Check to see if we have a dynamic service defined which this
193
- * dataset ID can map to
185
+ * Check to see if we have a dynamic service defined which this dataset ID can
186
+ * map to
194
187
*/
195
188
NcwmsDynamicService dynamicService = getDynamicServiceFromLayerName (datasetId );
196
189
if (dynamicService == null || dynamicService .isDisabled ()) {
@@ -209,8 +202,8 @@ public Dataset getDatasetFromId(String datasetId) {
209
202
String datasetPath = datasetId .substring (dynamicService .getAlias ().length () + 1 );
210
203
211
204
/*
212
- * Check if we allow this path or if it is disallowed by the dynamic
213
- * dataset regex
205
+ * Check if we allow this path or if it is disallowed by the dynamic dataset
206
+ * regex
214
207
*/
215
208
if (!dynamicService .getIdMatchPattern ().matcher (datasetPath ).matches ()) {
216
209
return null ;
@@ -223,8 +216,7 @@ public Dataset getDatasetFromId(String datasetId) {
223
216
title = title .substring (1 );
224
217
225
218
try {
226
- DatasetFactory datasetFactory = DatasetFactory
227
- .forName (dynamicService .getDataReaderClass ());
219
+ DatasetFactory datasetFactory = DatasetFactory .forName (dynamicService .getDataReaderClass ());
228
220
Dataset dynamicDataset = datasetFactory .createDataset (datasetId , datasetUrl );
229
221
/*
230
222
* Store in the cache
@@ -233,8 +225,9 @@ public Dataset getDatasetFromId(String datasetId) {
233
225
dynamicDatasetCache .put (new Element (datasetId , dynamicDataset ));
234
226
}
235
227
return dynamicDataset ;
236
- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException
237
- | IOException | EdalException e ) {
228
+ } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
229
+ | EdalException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
230
+ | SecurityException e ) {
238
231
/*
239
232
* TODO log error
240
233
*/
@@ -250,11 +243,11 @@ public EnhancedVariableMetadata getLayerMetadata(final VariableMetadata variable
250
243
return super .getLayerMetadata (variableMetadata );
251
244
} catch (EdalLayerNotFoundException e ) {
252
245
/*
253
- * The layer is not defined in the XmlDataCatalogue. However, we may
254
- * still have a dynamic dataset
246
+ * The layer is not defined in the XmlDataCatalogue. However, we may still have
247
+ * a dynamic dataset
255
248
*/
256
- final String layerName = getLayerNameMapper ()
257
- . getLayerName ( variableMetadata . getDataset (). getId (), variableMetadata .getId ());
249
+ final String layerName = getLayerNameMapper (). getLayerName ( variableMetadata . getDataset (). getId (),
250
+ variableMetadata .getId ());
258
251
259
252
final NcwmsDynamicService dynamicService = getDynamicServiceFromLayerName (layerName );
260
253
if (dynamicService == null ) {
@@ -276,8 +269,8 @@ public String getTitle() {
276
269
277
270
@ Override
278
271
public PlottingStyleParameters getDefaultPlottingParameters () {
279
- return new PlottingStyleParameters (null , ColourPalette .DEFAULT_PALETTE_NAME ,
280
- null , null , null , false , ColourPalette .MAX_NUM_COLOURS , 1f );
272
+ return new PlottingStyleParameters (null , ColourPalette .DEFAULT_PALETTE_NAME , null , null , null ,
273
+ false , ColourPalette .MAX_NUM_COLOURS , 1f );
281
274
}
282
275
283
276
@ Override
@@ -321,8 +314,7 @@ private NcwmsDynamicService getDynamicServiceFromLayerName(String layerName) {
321
314
dynamicService = testDynamicService ;
322
315
}
323
316
}
324
- if (dynamicService == null
325
- || !dynamicService .getIdMatchPattern ().matcher (layerName ).matches ()) {
317
+ if (dynamicService == null || !dynamicService .getIdMatchPattern ().matcher (layerName ).matches ()) {
326
318
return null ;
327
319
}
328
320
return dynamicService ;
@@ -346,8 +338,7 @@ public String getDatasetTitle(String datasetId) {
346
338
} else if (getDynamicServiceFromLayerName (datasetId ) != null ) {
347
339
return "Dynamic service from " + datasetId ;
348
340
} else {
349
- throw new EdalLayerNotFoundException (
350
- datasetId + " does not refer to an existing dataset" );
341
+ throw new EdalLayerNotFoundException (datasetId + " does not refer to an existing dataset" );
351
342
}
352
343
}
353
344
@@ -404,11 +395,9 @@ public boolean isDisabled(String layerName) {
404
395
}
405
396
406
397
private VariableConfig getXmlVariable (String layerName ) {
407
- DatasetConfig datasetInfo = config
408
- .getDatasetInfo (getLayerNameMapper ().getDatasetIdFromLayerName (layerName ));
398
+ DatasetConfig datasetInfo = config .getDatasetInfo (getLayerNameMapper ().getDatasetIdFromLayerName (layerName ));
409
399
if (datasetInfo != null ) {
410
- return datasetInfo
411
- .getVariableById (getLayerNameMapper ().getVariableIdFromLayerName (layerName ));
400
+ return datasetInfo .getVariableById (getLayerNameMapper ().getVariableIdFromLayerName (layerName ));
412
401
} else {
413
402
return null ;
414
403
}
0 commit comments