if( ! dataFile.isFile()) {
throw new ActionException(this, "Could not read main data file " + dataFile);
}
/*****************/
GeoStoreUtil geostore = new GeoStoreUtil(cfg.getGeoStoreConfig(), this.getTempDir());
/******************
* Load Layer data
******************/
this.listenerForwarder.progressing(15, "Searching layer in GeoStore");
final Resource layerRes;
try {
layerRes = geostore.searchLayer(layername);
} catch(Exception e) {
throw new ActionException(this, "Error loading Layer "+layername, e);
}
if(layerRes == null)
throw new ActionException(this, "Layer not found: "+layername);
UNREDDLayer layer = new UNREDDLayer(layerRes);
LOGGER.info("Layer resource found ");
if( ! layer.getAttribute(Attributes.LAYERTYPE).equalsIgnoreCase(request.getFormat().getName()))
throw new ActionException(this, "Bad Layer format "
+ "(declared:"+ request.getFormat().getName()
+ ", expected:"+layer.getAttribute(Attributes.LAYERTYPE) );
// this attribute is read for moving the raster file to the destination directory, not for rasterization
String mosaicDirPath = layer.getAttribute(UNREDDLayer.Attributes.MOSAICPATH);
if( mosaicDirPath == null) {
throw new ActionException(this, "Null mosaic directory for layer: '" + layername + "'... check the layer configuration on geostore");
}
File mosaicDir = new File(mosaicDirPath);
if( ! mosaicDir.isDirectory() && ! mosaicDir.isAbsolute()) {
throw new ActionException(this, "Bad mosaic directory for layer '" + layername + "': " + mosaicDir + " doesn't exist... create it or check the layer configuration on geostore");
}
// ******************
// Check for LayerUpdate
// ******************
this.listenerForwarder.progressing(20, "Check for existing LayerUpdate in GeoStore");
Resource existingLayerUpdate = null;
try {
existingLayerUpdate = geostore.searchLayerUpdate(layername, year, month, day);
} catch (Exception e) {
LOGGER.debug("Parameter : [layerSnapshot=" + layerUpdateName + "]");
throw new ActionException(this, "Error searching for a LayerUpdate (layer:"+layername+" year:"+year+ " month:"+month+")", e);
}
if (existingLayerUpdate != null) {
throw new ActionException(this, "LayerUpdate already exists (layer:"+layername+" year:"+year+ " month:"+month+")");
}
/********************************
*
* Image processing
*
*******************************/
final File rasterFile;
if (request.getFormat() == UNREDDFormat.VECTOR ) {
rasterFile = processVector(dataFile, layername, year, month, day, layer, mosaicDir);
} else {
rasterFile = processRaster(dataFile, layer, mosaicDir, layername);
}
// *** Image processing has finished
// ********************
// Create LayerUpdate
// ********************
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Adding LayerUpdate into GeoStore");
}
this.listenerForwarder.progressing(70, "Adding LayerUpdate into GeoStore");
try {
geostore.insertLayerUpdate(layername, year, month, day);
} catch (Exception e) {
LOGGER.debug("Parameter : [layername=" + layername + ", year=" + year + ", month=" + month + "]");
throw new ActionException(this, "Error while inserting a LayerUpdate", e);
}