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

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


        File outFile = SingleFileActionExecutor.execute(tea, inputFile);
        // taskexec just returns the input file

        if ( errorFile.length() != 0) {
            // error file is NOT empty
            throw new ActionException(tea, "Error in gdal_rasterize; check the error file " + errorFile.getAbsolutePath() + " for more information");
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Rasterization successfully performed");
        }
View Full Code Here


                    int height = conf.getRetileH();
                    int width = conf.getRetileW();

          String layername = conf.getLayername();
         
          if (layername==null) throw new ActionException(this, "the layer name cannot be empty");
          if (rasterpixelheight==0.0d || rasterpixelwidth==0.0d) throw new ActionException(this, "the raster pixel size is wrong");
         
          FileSystemEvent fileEvent=(FileSystemEvent)ev;
          File file = fileEvent.getSource();
          FileDataStore store = null;
          // this action can be used also getting a simpleFeatureCollection from another resource than a file
          // in this case the features field is not null but it is filled externally
                    if (features==null) {
                       
              store = FileDataStoreFinder.getDataStore(file);
              if (store==null) throw new ActionException(this, "the layer "+file.getCanonicalPath()+" cannot be found. Skip execution.");
                        FeatureSource featureSource = store.getFeatureSource();
                        SimpleFeatureType schema = (SimpleFeatureType) featureSource.getSchema();
                        Query query = new Query( schema.getTypeName(), Filter.INCLUDE );
                        query.setCoordinateSystem(CRS.decode("EPSG:4326", true));
                        features = (SimpleFeatureCollection) featureSource.getFeatures( query );
                       
          //    features = (SimpleFeatureCollection) featureSource.getFeatures();
                    }
                   
          //CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
          CoordinateReferenceSystem crs = features.getSchema().getCoordinateReferenceSystem();
          ReferencedEnvelope bounds = new ReferencedEnvelope(rasterx0, rasterx1, rastery0, rastery1,crs);

              Dimension gridDim = new Dimension(rasterpixelwidth, rasterpixelheight);

              String covName = layername;
              ProgressListener monitor = null;

              GridCoverage2D cov = VectorToRasterProcess.process(features, rasterAttribName, gridDim, bounds, covName, monitor);
              LOGGER.debug("CRS :"+cov.getCoordinateReferenceSystem().toWKT());
//              System.out.println(cov.toString());

//          Map<String, Object> attribute = new HashMap<String, Object>();
//          attribute.put("rasterAttribName", rasterAttribName);
//          if (rasterCqlFilter!=null) attribute.put("rasterCqlFilter", rasterCqlFilter);
          File tmpTiff = null;
          if (conf.getFilename()!=null)
              tmpTiff = new File(conf.getWorkingDirectory(),conf.getFilename());
          else 
              tmpTiff =   new File(conf.getWorkingDirectory(),"testcov.tif");
          GeoTiffWriter writer = null;
          try {
                        writer = new GeoTiffWriter(tmpTiff);
                       
            if (height>0 && width>0) {
              GeoTiffWriteParams params = new GeoTiffWriteParams();
             
                            params.setTilingMode(TIFFImageWriteParam.MODE_EXPLICIT);
                            params.setTiling(conf.getRetileH(), conf.getRetileW());
                            ParameterValue<GeoToolsWriteParams> value = GeoTiffFormat.GEOTOOLS_WRITE_PARAMS.createValue();
                            value.setValue(params);
                            writer.write(cov, new GeneralParameterValue[]{value});
                        }
                        else
                          writer.write(cov, null );
          } catch (IOException e) {
            // TODO Auto-generated catch block
            LOGGER.error("An exception was raised executing the RasterizeAction",e);
            throw new ActionException(this,"An exception was raised executing the RasterizeAction");
                    }
                    finally {
                    //  if (writer!=null) writer.dispose();
                  FileSystemEvent fileSystemInsertEvent = new FileSystemEvent(tmpTiff, FileSystemEventType.FILE_ADDED);
              ret.add(fileSystemInsertEvent);
              if (store!=null) store.dispose();
                    }
         
          // add the event to the return


        } else {
          if (LOGGER.isErrorEnabled()) {
            LOGGER.error("RasterizeAction.execute(): Encountered a NULL event: SKIPPING...");
          }
          continue;
        }
      } catch (Throwable ioe) {
        ioe.printStackTrace();
        final String message = "RasterizeAction.execute(): Unable to produce the output: "
            + ioe.getLocalizedMessage();
        // LOGGER.error(message, ioe);
        if (LOGGER.isErrorEnabled())
          LOGGER.error(message);
        throw new ActionException(this, message);
      }
    }

    return ret;
  }
View Full Code Here

                            break;
                        case DELETE:
                            this.doDelete(inputFile);
                            break;
            default:
                            throw new ActionException(this, "GeostoreAction.execute(): unknown operation " + operation);
            }

                    if(outFile != null) {
                        FileSystemEvent fileSystemInsertEvent = new FileSystemEvent(outFile, FileSystemEventType.FILE_ADDED);
                        ret.add(fileSystemInsertEvent);
                    }

        } else {
            LOGGER.error("GeostoreAction.execute(): Encountered a NULL event: SKIPPING...");
          continue;
        }
      } catch (ActionException ex) {
                throw ex; // pass through local exceptions

      } catch (Exception ex) {

        final String message = "SearchAction.execute(): Unable to produce the output: "
            + ex.getLocalizedMessage();
        // LOGGER.error(message, ioe);
        if (LOGGER.isErrorEnabled())
          LOGGER.error(message, ex);
        throw new ActionException(this, message);
      }
    }

    return ret;
  }
View Full Code Here

                    int height = conf.getRetileH();
                    int width = conf.getRetileW();

          String layername = conf.getLayername();
         
          if (layername==null) throw new ActionException(this, "the layer name cannot be empty");
          if (rasterpixelheight==0.0d || rasterpixelwidth==0.0d) throw new ActionException(this, "the raster pixel size is wrong");
         
          FileSystemEvent fileEvent=(FileSystemEvent)ev;
          File file = fileEvent.getSource();
          FileDataStore store = null;
          // this action can be used also getting a simpleFeatureCollection from another resource than a file
          // in this case the features field is not null but it is filled externally
                    if (features==null) {
                       
              store = FileDataStoreFinder.getDataStore(file);
              if (store==null) throw new ActionException(this, "the layer "+file.getCanonicalPath()+" cannot be found. Skip execution.");
                        FeatureSource featureSource = store.getFeatureSource();
                        SimpleFeatureType schema = (SimpleFeatureType) featureSource.getSchema();
                        Query query = new Query( schema.getTypeName(), Filter.INCLUDE );
                        query.setCoordinateSystem(CRS.decode("EPSG:4326", true));
                        features = (SimpleFeatureCollection) featureSource.getFeatures( query );
                       
          //    features = (SimpleFeatureCollection) featureSource.getFeatures();
                    }
                   
          //CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
          CoordinateReferenceSystem crs = features.getSchema().getCoordinateReferenceSystem();
          ReferencedEnvelope bounds = new ReferencedEnvelope(rasterx0, rasterx1, rastery0, rastery1,crs);

              Dimension gridDim = new Dimension(rasterpixelwidth, rasterpixelheight);

              String covName = layername;
              ProgressListener monitor = null;

              GridCoverage2D cov = VectorToRasterProcess.process(features, rasterAttribName, gridDim, bounds, covName, monitor);
              LOGGER.debug("CRS :"+cov.getCoordinateReferenceSystem().toWKT());
//              System.out.println(cov.toString());

//          Map<String, Object> attribute = new HashMap<String, Object>();
//          attribute.put("rasterAttribName", rasterAttribName);
//          if (rasterCqlFilter!=null) attribute.put("rasterCqlFilter", rasterCqlFilter);
          File tmpTiff = null;
          if (conf.getFilename()!=null)
              tmpTiff = new File(conf.getWorkingDirectory(),conf.getFilename());
          else 
              tmpTiff =   new File(conf.getWorkingDirectory(),"testcov.tif");
          GeoTiffWriter writer = null;
          try {
                        writer = new GeoTiffWriter(tmpTiff);
                       
            if (height>0 && width>0) {
              GeoTiffWriteParams params = new GeoTiffWriteParams();
             
                            params.setTilingMode(TIFFImageWriteParam.MODE_EXPLICIT);
                            params.setTiling(conf.getRetileH(), conf.getRetileW());
                            ParameterValue<GeoToolsWriteParams> value = GeoTiffFormat.GEOTOOLS_WRITE_PARAMS.createValue();
                            value.setValue(params);
                            writer.write(cov, new GeneralParameterValue[]{value});
                        }
                        else
                          writer.write(cov, null );
          } catch (IOException e) {
            // TODO Auto-generated catch block
            LOGGER.error("An exception was raised executing the RasterizeAction",e);
            throw new ActionException(this,"An exception was raised executing the RasterizeAction");
                    }
                    finally {
                    //  if (writer!=null) writer.dispose();
                  FileSystemEvent fileSystemInsertEvent = new FileSystemEvent(tmpTiff, FileSystemEventType.FILE_ADDED);
              ret.add(fileSystemInsertEvent);
              if (store!=null) store.dispose();
                    }
         
          // add the event to the return


        } else {
          if (LOGGER.isErrorEnabled()) {
            LOGGER.error("RasterizeAction.execute(): Encountered a NULL event: SKIPPING...");
          }
          continue;
        }
      } catch (Throwable ioe) {
        ioe.printStackTrace();
        final String message = "RasterizeAction.execute(): Unable to produce the output: "
            + ioe.getLocalizedMessage();
        // LOGGER.error(message, ioe);
        if (LOGGER.isErrorEnabled())
          LOGGER.error(message);
        throw new ActionException(this, message);
      }
    }

    return ret;
  }
View Full Code Here

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

        return ret;
    }
View Full Code Here

        if ( cfg.getOriginalDataTargetDir() == null || ! cfg.getOriginalDataTargetDir().canWrite() || ! cfg.getOriginalDataTargetDir().isDirectory()){
            LOGGER.warn("OriginalDataTargetDir is not setted or has been wrong specified or GeoBatch doesn't have write permissions");
        }

        if(cfg.getRetilerConfiguration() == null){
            throw new ActionException(this, "RetilerConfiguration not set");
        }

        if(cfg.getGeoStoreConfig() == null){
            throw new ActionException(this, "GeoStoreConfiguration not set");
        }

        if(cfg.getPostGisConfig() == null){
            throw new ActionException(this, "PostGisConfiguration not set");
        }

        if(cfg.getGeoServerConfig() == null){
            LOGGER.warn("GeoServer config is null. GeoServer data will not be refreshed");
        }
View Full Code Here

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

        }

        // *** 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);
        }

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

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

        /*************************
         * Copy orig data
         *************************/
 
View Full Code Here

            rasterFile = GeoTiff.retile(cfg.getRetilerConfiguration(), dataFile, getTempDir()); // retile replaces the original input file

            LOGGER.info("Retiling completed into " + rasterFile);

        } catch (Exception e) {
            throw new ActionException(this, "Error while retiling " + dataFile, e);
        }
        // === embedOverviews
        LOGGER.info("Starting overviews");
        this.listenerForwarder.progressing(40, "Starting overviews");
        try {
            rasterFile = GeoTiff.embedOverviews(cfg.getOverviewsEmbedderConfiguration(), rasterFile, getTempDir());
        } catch (Exception e) {
            throw new ActionException(this, "Error creating overviews on " + rasterFile, e);
        }
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Geoserver mosaic update started "+cfg);
        }
        this.listenerForwarder.progressing(60, "Adding new time coordinate in GeoServer");
        // Publish data on GeoServer
        // mosaic action will
        //  - copy the raster into the mosaic dir (with current filename)
        //  - add the granule in the tile db
        try {
           
            String style = layer.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());
           
            double [] bbox = new double[4];
            bbox[0] = Double.valueOf(layer.getAttribute(Attributes.RASTERX0));
            bbox[1] = Double.valueOf(layer.getAttribute(Attributes.RASTERY0));
            bbox[2] = Double.valueOf(layer.getAttribute(Attributes.RASTERX1));
            bbox[3] = Double.valueOf(layer.getAttribute(Attributes.RASTERY1));
           
            Mosaic mosaic = new Mosaic(cfg.getGeoServerConfig(), mosaicDir, getTempDir(), getConfigDir());
            mosaic.add(cfg.getGeoServerConfig().getWorkspace(), layername, rasterFile, "EPSG:4326", bbox, style, cfg.getDatastorePath());
       
        } catch (Exception e) {
            this.listenerForwarder.progressing(60, "Error in ImageMosaic: " + e.getMessage());
            LOGGER.error("Error in ImageMosaic: " + e.getMessage(), e);
            throw new ActionException(this, "Error updating mosaic " + rasterFile.getName(), e);
        }
       
        File expectedMosaicTile = new File(mosaicDir, dataFile.getName());
        if(expectedMosaicTile.exists()) {
            if(LOGGER.isInfoEnabled()) {
View Full Code Here

        try {
            int cp = PostGISUtils.shapeToPostGis(dataFile, cfg.getPostGisConfig(), layername, year, month, day);
            this.listenerForwarder.progressing(29, "Copied "+cp+ " features");
        } catch (PostGisException e) {
            LOGGER.error("Error ingesting shapefile: " + e.getMessage());
            throw new ActionException(this, "Error ingesting shapefile: " + e.getMessage(), e);
        }

        File rasterFile;
        LOGGER.info("Starting rasterization");
        this.listenerForwarder.progressing(30, "Starting rasterization");
        try {
            GDALRasterize rasterize = new GDALRasterize( cfg.getRasterizeConfig(), cfg.getConfigDir(), getTempDir());
            rasterFile = rasterize.run(layer, new UNREDDLayerUpdate(layername, year, month, day), dataFile);
        } catch (Exception e) {
            throw new ActionException(this, "Error while rasterizing "+dataFile+": " + e.getMessage(), e);
        }

        LOGGER.info("Starting overviews");
        this.listenerForwarder.progressing(40, "Starting overviews");
        try {
            rasterFile = GeoTiff.embedOverviews(cfg.getOverviewsEmbedderConfiguration(), rasterFile, getTempDir());
        } catch (Exception e) {
            throw new ActionException(this, "Error creating overviews on " + rasterFile, e);
        }

        //=== Move final raster file into its mosaic dir
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Moving raster file into mosaic dir");
        }
        this.listenerForwarder.progressing(50, "Copying raster into mosaic dir");
        String finalRasterName = NameUtils.buildTifFileName(layername, year, month, day);
        File destFile = new File(mosaicDir, finalRasterName);
        if(destFile.exists())
            throw new ActionException(this, "Destination file in mosaic dir already exists " + destFile);
        FileUtils.copyFile(rasterFile, destFile);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Raster file moved into mosaic dir: " + destFile);
        }
        return rasterFile;
View Full Code Here

            }

            LOGGER.info("Zip extracted in " + unzipDir);

        } catch (Exception e) {
            throw new ActionException(this, "Error extracting from " + inputZipFile, e);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
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.