File infoXmlFile = new File(unzipDir, INFO_XML);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Reading XML parameters from " + infoXmlFile);
}
Request request = null;
try {
request = RequestJDOMReader.parseFile(infoXmlFile);
} catch (Exception e) {
throw new ActionException(this, "Error reading info.xml file, Are you sure to have built the input zip pkg in the right way? Note that all the content must be placed in the zip root folder, no any other subfolder are allowed..." , e);
}
if(request.getFormat() == null) {
throw new ActionException(this, "the format cannot be null.");
}
final String layername = request.getLayername();
if (layername==null)
throw new ActionException(this, "the layername cannot be null.");
final String year = request.getYear();
if (year==null)
throw new ActionException(this, "the year cannot be null.");
if( ! year.matches("\\d{4}")) {
throw new ActionException(this, "Bad format for year parameter ("+year+")");
}
final String month = request.getMonth();
if(month!= null && ! month.matches("\\d\\d?") )
throw new ActionException(this, "Bad format for month parameter ("+month+")");
final String day = request.getDay();
if(month!= null && ! month.matches("\\d\\d?") )
throw new ActionException(this, "Bad format for month parameter ("+day+")");
final String srcFilename = request.buildFileName();
// build the name of the snapshot
final String layerUpdateName = NameUtils.buildLayerUpdateName(layername, year, month, day);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Info: layername:" + layername + " year:"+year + " month:"+month + " day:"+day);
}
this.listenerForwarder.progressing(12, "Info from xml file: layername:" + layername + " year:"+year + " month:"+month + " day:"+day);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("XML parameter settings : [layer name = " + layername + "], [year = " + year + "], [month = " + month + "], [day = " + day + "], [ file name = " + srcFilename + "]");
LOGGER.debug("XML parameter settings : [layer update name = " + layerUpdateName + "]");
}
File unzippedDataDir = new File(unzipDir, DATA_DIR_NAME);
File dataFile = new File(unzippedDataDir, srcFilename);
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);