Package it.geosolutions.geobatch.flow.event.action

Examples of it.geosolutions.geobatch.flow.event.action.ActionException


            default:
                LOGGER.error("Single output file expected: found more than one:");
                for (FileSystemEvent ev : outQueue) {
                    LOGGER.error(" event: " + ev);
                }
                throw new ActionException(a, "Got more than one output file: " + outQueue);
        }
    }
View Full Code Here


        try {
            initialize();
        } catch (Exception e) {
            LOGGER.error("Exception during component initialization", e);
            throw new ActionException(this, "Exception during initialization");
        }



        final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>();
        while (!events.isEmpty()) {
            final FileSystemEvent ev = events.remove();

            try {
                if (ev != null) {
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("PublishingAction.execute(): working on incoming event: " + ev.getSource());
                    }

                    File xmlFile = ev.getSource(); // this is the input xml file
                    executeInternal(xmlFile);
                    ret.add(new FileSystemEvent(xmlFile, FileSystemEventType.FILE_ADDED));

                } else {
                    LOGGER.error("PublishingAction.execute(): Encountered a NULL event: SKIPPING...");
                    continue;
                }

            } catch (ActionException ex) { // ActionEx have already been processed
                LOGGER.error(ex.getMessage(), ex);
                throw ex;

            } catch (Exception ex) {
                final String message = "PublishingAction.execute(): Unable to produce the output: "
                        + ex.getLocalizedMessage();
                LOGGER.error(message, ex);
                throw new ActionException(this, message);
            }
        }

        return ret;
    }
View Full Code Here

        Request request = null;
        try {
            request = RequestJDOMReader.parseFile(xmlFile);
        } catch (Exception e) {
            throw new ActionException(this, "Exception parsing input file " + xmlFile.getName());
        }

        String layerName = request.getLayername();
        String year = request.getYear();
        String month = request.getMonth();
        String day = request.getDay();
       
        String filename = NameUtils.buildTifFileName(layerName, year, month, day);
       
        LOGGER.info("Input parameters : [layer=" + layerName + ", year=" + year + ", month=" + month + "]");


        // ****************************************
        // Load source Layer info
        //
        // ****************************************

        LOGGER.info("Searching source Layer " + layerName);

        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());
          }

        } catch (PostGisException e) {
            LOGGER.debug("Property settings : [Layer = " + layerName + ", year = " + year + ", month=" + month + "]");
            throw new ActionException(this, "Error while copying features", e );
        } catch(IOException e) {
            throw new ActionException(this, "Error while copying raster", e );
        } finally {
      PostGISUtils.quietDisposeStore(srcDS);
      PostGISUtils.quietDisposeStore(destDS);
    }

        // ****************************************
        // Copy GeoStoreUtil data
        // ----------
        // copy the resources related to the layer update
        // resource identified by layer, year and month to the
        // dissemination geostore
        // ****************************************

        // TODO: to complete using the setData

        try {
            LOGGER.info("Copying Geostore content");
            this.copyGeostoreData(srcGeostore, dstGeostore, layerName, year, month, day);
            LOGGER.debug("Geostore copy successfully completed");
        } catch (Exception e) {
            throw new ActionException(this, "Error while copying GeoStore content",e );
        }

        // ********************
        // Run stats
        // ********************
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Starting statistic processing");
        }
        this.listenerForwarder.progressing(80, "Starting statistic processing");

        FlowUtil flowUtil= new FlowUtil(getTempDir(), getConfigDir());
        try {
          File dissRasterFile = new File(dstPath, filename);
            flowUtil.runStatsAndScripts(layerName, year, month, day, dissRasterFile, dstGeostore);
        } catch (FlowException e) {
            throw new ActionException(this, e.getMessage(), e);
        }
       
        // ****************************************
        // Copy original data
        // ----------
View Full Code Here

        //===
        //=== Insert Layer if it does not exist

        Resource srcLayer = srcGeostore.searchLayer(layerName);
        if (srcLayer == null) {
            throw new ActionException(this, "Source Layer not found [layer:" + layerName + "]");
        }

        //=== COPY LAYER

        Resource dstLayer = dstGeostore.searchLayer(layerName);
        if( dstLayer == null) {
            LOGGER.info("Copying Layer into destination: " + srcLayer);
            RESTResource layer = FlowUtil.copyResource(srcLayer);
            dstGeostore.insert(layer);
        }

        //==================================================
        //=== LAYERUPDATE
        //===
        //=== Insert LayerUpdate if it does not exist

        Resource srcLayerUpdate = srcGeostore.searchLayerUpdate(layerName, year, month, day);
        if (srcLayerUpdate == null) {
            throw new ActionException(this, "Source LayerUpdate not found [layer:" + layerName + " year:" + year + " month:" + month + "]");
        }

        //=== COPY LAYERUPDATE

        Resource dstLayerUpdate = dstGeostore.searchLayerUpdate(layerName, year, month, day);
View Full Code Here

            LOGGER.info("Copying features ...");
            PostGISUtils.copyFeatures(srcDS, destDS, layer, year, month, day, true); // TODO: change to false
            LOGGER.info("Features successfully copied");

        } catch (PostGisException e) {
            throw new ActionException(this, "Error while copying features", e);
        } catch (IOException e) {
          throw new ActionException(this, "Error while copying features", e);
    }
    }
View Full Code Here

                     * changed; i.e.: - vector data are edited; - chart scripts are modified or inserted; - new statistics are
                     * added. Each doXXX methos manages one of this case
                     */
                    ReprocessRequest request = RequestReader.load(xmlFile);
                    if (request == null) {
                        throw new ActionException(this, "Could not parse input file:" + xmlFile.getName());
                    }

                    if (request instanceof ReprocessLayerRequest) {
                        reprocessLayer((ReprocessLayerRequest) request);

                    } else if (request instanceof ReprocessChartRequest) {
                        reprocessChart((ReprocessChartRequest) request);

                    } else if (request instanceof ReprocessStatsRequest) {
                        reprocessStats((ReprocessStatsRequest) request);

                    }

                    ret.add(new FileSystemEvent(xmlFile, FileSystemEventType.FILE_ADDED));

                } else {
                    LOGGER.error("Encountered a null event: skipping event");
                    continue;
                }

            } catch (ActionException ex) {
                LOGGER.error(ex.getMessage());
                listenerForwarder.failed(ex);
                throw ex;

            } catch (Exception ex) {
                LOGGER.error(ex.getMessage(), ex);
                listenerForwarder.failed(ex);
                throw new ActionException(this, ex.getMessage(), ex);
            }
        }

        return ret;
    }
View Full Code Here

        LOGGER.info("Searching " + layerName + " in Geostore");
        Resource layerRes = null;
        try {
            layerRes = geoStoreUtil.searchLayer(layerName);
        } catch (GeoStoreException e) {
            throw new ActionException(this, "Error while searching layer: " + layerName, e);
        }

        if (layerRes == null) {
            throw new ActionException(this, "Layer not found: " + layerName);
        }

        UNREDDLayer layer = new UNREDDLayer(layerRes);
        LOGGER.info(layerName + " found in the Staging Area Geostore");


        // ========================================
        // Load layerUpdate

        LOGGER.info("Searching layer update [" + layerName + ", " + year + "," + month + "]");

        Resource layerUpdatesRes = null;
        try {
            layerUpdatesRes = geoStoreUtil.searchLayerUpdate(layerName, year, month, day);
        } catch (GeoStoreException e) {
            throw new ActionException(this, "Error while searching LayerUpdate: " + layerName, e);
        }

        if (layerUpdatesRes == null) {
            LOGGER.warn("Missing Layer update [" + layerName + ", " + year + "," + month + "]");

            // create the missing LayerUpdate entry
            try {
                geoStoreUtil.insertLayerUpdate(layerName, year, month, day);
            } catch (GeoStoreException e) {
                throw new ActionException(this, "Error while inserting a LayerUpdate", e);
            }
        }

        try {
            layerUpdatesRes = geoStoreUtil.searchLayerUpdate(layerName, year, month, day);
        } catch (GeoStoreException e) {
            throw new ActionException(this, "LayerUpdate not createds: " + layerName, e);
        }

        UNREDDLayerUpdate layerUpdate = new UNREDDLayerUpdate(layerUpdatesRes);

        // ========================================
        // In case of update we should regenerate the tiff.
        // We have also retile, overview it and move it to the mosaic directory

        File rasterfile = null;
        String layerFormat = layer.getAttribute(Attributes.LAYERTYPE);

        if (UNREDDFormat.VECTOR.name().equals(layerFormat)) {

            rasterfile = reprocessVector(layer, layerUpdate);

        } else if (UNREDDFormat.RASTER.name().equals(layerFormat)) {

            File dir = new File(layer.getAttribute(UNREDDLayer.Attributes.MOSAICPATH));
            String filename = NameUtils.buildTifFileName(layerName, year, month, day);
            rasterfile = new File(dir, filename);

        } else {
            throw new ActionException(this, "Unrecognized layer format '"+layerFormat+"'");
        }

        // ========================================
        // Compute all related statsData and chartData

        try {
            FlowUtil flowUtil = new FlowUtil(getTempDir(), getConfigDir());
            flowUtil.runStatsAndScripts(layerName, year, month, day, rasterfile, geoStoreUtil);
        } catch (FlowException e) {
            throw new ActionException(this, e.getMessage(), e);
        }

    }
View Full Code Here

            RasterizeConfig rasterizeConfig = conf.getRasterizeConfig();
            GDALRasterize rasterize = new GDALRasterize(rasterizeConfig, conf.getConfigDir(), this.getTempDir());
            rasterFile = rasterize.run(layer, layerUpdate, conf.getPostGisConfig());

        } catch(Exception e) {
            throw new ActionException(this, "Exception while rasterizing: " + e.getMessage(), e);
        }

        // ========================================
        // Embed overviews
        // ========================================
        LOGGER.info("Embedding overviews for " + NameUtils.buildLayerUpdateName(layername, year, month, day) + " in " + rasterFile);

        GeotiffOverviewsEmbedderConfiguration ovCfg = conf.getOverviewsEmbedderConfiguration();

        try {
            GeoTiff.embedOverviews(ovCfg, rasterFile, getTempDir());
        } catch (Exception e) {
            throw new ActionException(this, "Exception while embedding overviews in " + rasterFile.getName(), e);
        }

        // ========================================
        // Move to mosaic dir
        // ========================================

        String mosaicPath = layer.getAttribute(Attributes.MOSAICPATH);

        String finalName = NameUtils.buildTifFileName(layername, year, month, day);
        File finalPath = new File(mosaicPath, finalName);
        if(finalPath.exists())
            LOGGER.info("Overwriting old raster:" + finalPath);
        else
            LOGGER.info("Old raster does not exist:" + finalPath);

        try {
            FileUtils.copyFile(rasterFile, finalPath);
        } catch(IOException e) {
            throw new ActionException(this, "Exception while moving raster (src: " + rasterFile + " dst:"+finalPath+')', e);
        }

        return finalPath;
    }
View Full Code Here

            ioe.printStackTrace();
                final String message = "StatisticsAction.execute(): Unable to produce the output: "
                        + ioe.getLocalizedMessage();
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(message);
                throw new ActionException(this, message);
            }
        }
       
        return ret;
    }
View Full Code Here

        fma.setTempDir(tempDir);

        File outFile = SingleFileActionExecutor.execute(fma, file);

        if(outFile == null)
            throw new ActionException(fma, "No output events from freemarker Action");

        return outFile;
    }
View Full Code Here

TOP

Related Classes of it.geosolutions.geobatch.flow.event.action.ActionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.