Resource srcLayer = srcGeostore.searchLayer(layerName);
if(srcLayer == null) {
throw new ActionException(this, "Source Layer not found [" + layerName+ "]");
}
UNREDDLayer layerResource = new UNREDDLayer(srcLayer);
String srcPath = layerResource.getAttribute(UNREDDLayer.Attributes.MOSAICPATH);
String dstPath = layerResource.getAttribute(UNREDDLayer.Attributes.DISSMOSAICPATH);
LOGGER.info(layerName + " found in the Staging Area Geostore");
// TODO ***** add layer in destination if it does not exist
LOGGER.error("TODO: add layer in destination if it does not exist");
// ****************************************
// check source layer update
//
// ****************************************
LOGGER.info("Searching source LayerUpdate [" + layerName + ", " + year + "," + month + "]");
Resource srcLayerUpdatesSA = srcGeostore.searchLayerUpdate(layerName, year, month, day);
if (srcLayerUpdatesSA == null) {
throw new ActionException(this, "Source LayerUpdate not found [" + layerName + ", " + year + "," + month + "]");
}
LOGGER.info("Source LayerUpdate found [" + layerName + ", " + year + "," + month + "]");
boolean isVector = request.getFormat().equals(UNREDDFormat.VECTOR);
DataStore srcDS=null,destDS=null;
try {
srcDS=PostGISUtils.createDatastore(conf.getSrcPostGisConfig());
destDS=PostGISUtils.createDatastore(conf.getDstPostGisConfig());
if (isVector) {
// ****************************************
// Copy the features and raster data
// ----------
// Copy feats identified by layer, year and month
// from the staging area postgis db to the dissemination db
// in case update is set on true we should
// firstly remove the old features from the dissemination db.
// This controls will be made directly in the updatePostGIS method.
//
// After features copy copy the raster data from staging mosaic path to dissemination mosaic path.
// Altought the mosaic_path destination This tiff is not a mosaic granule but is needed for dynamic stats.
// ****************************************
LOGGER.info("The request is VECTOR format based:");
LOGGER.info("Updating PostGIS...");
updatePostGIS(srcDS, destDS, layerName, year, month, day);
LOGGER.info("Copy raster data used for dynamic stats...");
this.copyRaster(srcPath, dstPath, layerName, year, month, day);
}
else {
// ****************************************
// Copy the raster
// ----------
// copies the raster located into the mosaic
// staging area directory to the dissemination mosaic.
// This operation is performed both in case of a first publishing
// and successive ones
//
// ****************************************
LOGGER.info("The request is RASTER format based:");
LOGGER.info("Update the mosaic...");
File srcRasterFile = new File(srcPath, filename);
File mosaicDir = new File(dstPath);
String style = layerResource.getAttribute(UNREDDLayer.Attributes.LAYERSTYLE);
if(style==null || style.isEmpty()){
style = DEFAULT_MOSAIC_STYLE;
}
StringBuilder msg = new StringBuilder();
msg.append("Publishing the Mosaic Granule with Style -> ");
msg.append(style);
LOGGER.info(msg.toString());
//create bounding box with values setted on GeoStore
double [] bbox = new double[4];
bbox[0] = Double.valueOf(layerResource.getAttribute(Attributes.RASTERX0));
bbox[1] = Double.valueOf(layerResource.getAttribute(Attributes.RASTERY0));
bbox[2] = Double.valueOf(layerResource.getAttribute(Attributes.RASTERX1));
bbox[3] = Double.valueOf(layerResource.getAttribute(Attributes.RASTERY1));
Mosaic mosaic = new Mosaic(conf.getDstGeoServerConfig(), mosaicDir, getTempDir(), getConfigDir());
mosaic.add(conf.getDstGeoServerConfig().getWorkspace(), layerName, srcRasterFile, "EPSG:4326", bbox, style, conf.getDatastorePath());
}