Examples of PostGisException


Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

        DataStore ret = null;
        try {
            ret = (DataStore)DataStoreFinder.getDataStore(cfg.buildGeoToolsMap());
        } catch (IOException ex) {
            throw new PostGisException("Can't create PostGIS datastore ["+cfg+"]", ex);
        }
        if ( ret == null ) {
            LOGGER.error("DataStore not found: " + cfg);
            throw new PostGisException("DataStore not found: " + cfg);
        }
        return ret;
    }
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

        FileDataStore ret = null;
        try {
            ret = FileDataStoreFinder.getDataStore(shapeFile);
        } catch (IOException ex) {
            throw new PostGisException("Can't create shapeFile datastore ["+shapeFile+"]", ex);
        }
        if ( ret == null ) {
            LOGGER.error("DataStore not found for " + shapeFile);
            throw new PostGisException("DataStore not found: " + shapeFile);
        }
        return ret;
    }
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

           
            SimpleFeatureSource featureSource = srcStore.getFeatureSource();
            SimpleFeatureCollection sfc = (SimpleFeatureCollection) featureSource.getFeatures();
            return enrichAndAddFeatures(sfc, dstPg, layer, year, month, day, true);
        } catch (IOException ex) {
            throw new PostGisException("Error copying features: " + ex.getMessage(), ex);
        } finally {
            quietDisposeStore(srcStore);
        }
    }
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

                  dstDs.createSchema(sft);
 
 
              } else {
                  LOGGER.error("An exception was raised when connecting to " + layer);
                  throw new PostGisException("The layer " + layer + " does not exist in the dissemintation system", e);
              }
 
          }
           
            Filter filter = (Filter) FF.equals(FF.property(YEARATTRIBUTENAME), FF.literal(Integer.parseInt(year)));
            if (month != null) {
                Filter monthFilter = (Filter) FF.equals(FF.property(MONTHATTRIBUTENAME), FF.literal(Integer.parseInt(month)));
                filter = (Filter) FF.and(filter, monthFilter);
            }
           
            if (day != null) {
                Filter dayFilter = (Filter) FF.equals(FF.property(DAYATTRIBUTENAME), FF.literal(Integer.parseInt(day)));
                filter = (Filter) FF.and(filter, dayFilter);
            }

            LOGGER.info("Filter: " + filter);
           
            final SimpleFeatureCollection filteredSF = srcFs.getFeatures(filter);

          if (filteredSF == null || (filteredSF != null && filteredSF.isEmpty())) {
              LOGGER.warn(" The filtered collection is empty. Skip copying");
              return;
          }
          LOGGER.info("The filtered collection is not empty. Starting copy " + filteredSF.size() + " features");
          copyFeatures(layer, filteredSF, dstDs);
      } catch (Exception e) {
        LOGGER.error("The source layer " + layer + " cannot be accessed. Maybe it does not exist. Skip execution", e);
        throw new PostGisException("Source layer " + layer + " cannot be accessed.");
      }

    }
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

            boolean layerExists = existFeatureTable(dstDs, layer);
            if( ! layerExists ) {
                if(forceCreation) {
                    fsLayer = createEnrichedSchema(dstDs, (SimpleFeatureType) sourceFC.getSchema(), layer);
                } else {
                    throw new PostGisException("The layer " + layer + " does not exist");
                }
            } else {
                fsLayer =  dstDs.getFeatureSource(layer);
                checkAttributesMatch(sourceFC, ((JDBCFeatureStore)dstDs.getFeatureSource(layer)).getFeatureSource());
            }

          //== schemas are ok: transfer data
 
          int iYear = Integer.parseInt(year);
          int iMonth = month==null? -1 : Integer.parseInt(month);
          int iDay = day==null? -1 : Integer.parseInt(day);
          Date date = new Date(iYear-1900, iMonth==-1?0:iMonth-1, iDay==-1?1:iDay);
 
          SimpleFeatureStore featureStoreData = (SimpleFeatureStore) fsLayer;
 
          // update the layer store with the new SimpleFeature coming from the shape file
          // data are saved itemsForPage elements at time

            SimpleFeatureType dstSchema = dstDs.getSchema(layer);
            featureStoreData.setTransaction(tx);
            SimpleFeatureType srcSchema = sourceFC.getSchema();
            List<AttributeDescriptor> srcAttributeDescriptor = srcSchema.getAttributeDescriptors();

            SimpleFeatureBuilder featureBuilderData = new SimpleFeatureBuilder(dstSchema);
            SimpleFeatureIterator featureIterator = sourceFC.features();
            boolean hasFinished = false;
            int i = 0;
            Set<String> loggedMissingAttrib = new HashSet<String>();
            while (!hasFinished) { // TODO: refacotr this nested loop!!!

              //DamianoGiampaoli 03/11/2014
              //TEST IT!!!
              // Due to the upgrade needed from the Geotools 8-SNAPSHOT to geotools 10.8 in order to support GeoBatch 1.4.x
              // The add(SimpleFeature) method of SimpleFeatureCollection cannot be used anymore so a List<SimpleFeature> must be used.
                //SimpleFeatureCollection sfcData = FeatureCollections.newCollection();
                List<SimpleFeature> sfcData = new ArrayList<SimpleFeature>();
               
                boolean exitForIntermediateSaving = false;

                while (featureIterator.hasNext() && !exitForIntermediateSaving) {
                    i++;

                    exitForIntermediateSaving = ((i % ITEM_X_PAGE) == 0);

                    SimpleFeature sf = featureIterator.next();
                    SimpleFeature data = featureBuilderData.buildFeature(sf.getID());
                    for (int j = 0; j < srcAttributeDescriptor.size(); j++) {
                        String srcName = srcAttributeDescriptor.get(j).getLocalName();
                        String dstName = srcName.toLowerCase(); // FIXME: this is a worksroung for SHP 2 PG attrib name conversion. make it general!

                        Property p = sf.getProperty(srcName);
                        if( p!= null) // be lenient about inexistent attributes: consistency checks have already bben performed.
                            data.setAttribute(dstName, sf.getAttribute(srcName));
                        else {
                            if(LOGGER.isDebugEnabled() && ! loggedMissingAttrib.contains(srcName) ) {
                                LOGGER.debug("Skipping attrib "+srcName+" in feature #"+i);
                                loggedMissingAttrib.add(srcName);
                            }
                        }
                    }

                    data.setAttribute(YEARATTRIBUTENAME, iYear);
                    if(iMonth != -1){
                        data.setAttribute(MONTHATTRIBUTENAME, month);
                    }
                    if(iDay != -1){
                        data.setAttribute(DAYATTRIBUTENAME, day);
                    }
                    data.setAttribute(DATEATTRIBUTENAME, date);
                    sfcData.add(data);

                }
                if (!exitForIntermediateSaving) {
                    hasFinished = true;
                }
                SimpleFeatureCollection featureCollection = new ListFeatureCollection(srcSchema, sfcData);
                featureStoreData.addFeatures(featureCollection);
            }
           
            tx.commit();
            LOGGER.info("Copied " + i + " features for "+ layer+"/"+year+"/"+month+"/"+day+ " to " + dstPg);
            return i;

        } catch (Exception e) {
            quietRollbackTransaction(tx);
            LOGGER.error("Exception while copying shp into db", e);
            throw new PostGisException("Exception while copying shp into db", e);
        } finally {
          // clean up
            quietCloseTransaction(tx);
            quietDisposeStore(dstDs);
        }
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

                }
            }

            return fsLayer;
        } catch (IOException e) {
            throw new PostGisException("Error while creating table " + layer+ ": " + e.getMessage(), e);
        }
    }
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

        }

        // todo: should also check for missing [attribs in dst but not in src] attribs?

        if(sbErr.length() > 0)
            throw new PostGisException("Schema mismatch: " + sbErr);
    }
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

        ds.createSchema(sft);
        return true;
      }
    } catch (IOException e) {
      LOGGER.error(e.getMessage(), e);
      throw new PostGisException(e.getMessage());
    }
    return false;

  }   
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

            store.removeFeatures(filter);
            tx.commit();
        } catch (Exception e) {
            quietRollbackTransaction(tx);
            LOGGER.error("An exception was raised when deleting features from " + layer + "", e);
            throw new PostGisException("An exception was raised when deleting features from " + layer, e);
        } finally {
            quietCloseTransaction(tx);
        }
    }
View Full Code Here

Examples of it.geosolutions.geobatch.unredd.script.exception.PostGisException

        SimpleFeatureSource fsDestLayer = null;
        try {
            fsDestLayer = dstDS.getFeatureSource(layer);
        } catch (Exception e) {
            LOGGER.error("Destination layer " +layer + " does not exist:" + e.getMessage(), e);
            throw new PostGisException("Destination layer " +layer + " does not exist:" + e.getMessage(), e);
        }

        final SimpleFeatureStore featureStoreData = (SimpleFeatureStore) fsDestLayer;
        SimpleFeatureIterator iterator = null;
        final Transaction tx = new DefaultTransaction();
        featureStoreData.setTransaction(tx);
        // update the layer store with the new SimpleFeature coming from the shape file
        // data are saved itemsForPage elements at time
       
        try {
         
          // open iterator
            iterator = sourceFC.features();
          // prepare feature holder
          final ListFeatureCollection lfc= new ListFeatureCollection(sourceFC.getSchema());
          int count=0;
          int numPag = sourceFC.size() / ITEM_X_PAGE;
          int currentPage = 0;
          LOGGER.info("Page size: " + ITEM_X_PAGE + ", Page amount: " + numPag);
          while (iterator.hasNext()) {

              // copy over
               final SimpleFeature sf = iterator.next();
               lfc.add(sf);
//               LOGGER.debug("Feature " + count + " - page: " + currentPage);
               // paging check
               if(count++>=ITEM_X_PAGE){
                 // commit to relief load from destination DB
                   featureStoreData.addFeatures(lfc);                      
                   tx.commit();
                   lfc.clear();
                   count=0;
//                   System.gc();
                   LOGGER.debug("Page" + currentPage++ + "/" + numPag + " committed... ");

               }
            }
          LOGGER.info("Commit latest features...");
            if(!lfc.isEmpty()){
            // commit to relief load from destination DB
              featureStoreData.addFeatures(lfc);
            
              // final commit
              tx.commit();   
            }
        } catch (Exception e) {
            quietRollbackTransaction(tx);
            LOGGER.error("An exception was raised when executing storing into the database");

            throw new PostGisException("An exception was raised when executing storing into the database", e);
        } finally {
          // close transaction
            quietCloseTransaction(tx);
           
            // close iterator
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.