Package org.geotools.validation

Examples of org.geotools.validation.ValidationProcessor


    store.addFeatures( riverFeatures );
   
    //
    // SETUP
    //
    ValidationProcessor processor = new ValidationProcessor();

    // normally you load definition from file
    // Here we are doing it by hand   
    IsValidGeometryValidation geom = new IsValidGeometryValidation();
    geom.setName( "IsValidGeometry");
    geom.setDescription("IsValid geomtry check");
    geom.setTypeRef("*"); // works on any feature type
    processor.addValidation( geom );

    //
    // TESTING
    //
   
    // Create a ValidationResults callback object to receive
    // any warnings or errors
    //
    // Normally you implement this as a callback to your application;
    // here we will use a default implementation here that adds results to a list
    DefaultFeatureResults results = new DefaultFeatureResults();

    // test a featureCollection
    processor.runFeatureTests( "dataStoreId", roadFeatures, results);

    // and check the results
    System.out.println("Found "+ results.error.size() + " failires" );
    // validationExample end
}
View Full Code Here


    // validationExample2 start

    // set up a validation processor using two directories of
    // configuraiton files
    ValidationProcessor processor = new ValidationProcessor();
    processor.load( pluginDirectory, testSuiteDirectory );

    // normally you load definition from file
    // it will load all the files in the provided directories
    processor.load( pluginDirectory, testSuiteDirectory );

    DefaultFeatureResults results = new DefaultFeatureResults();

        // To run integrity tests (that compare several featureSources we need
    // to make a Map of FeatureSources.
    // the *key* is called the "typeRef" and will be used by test suites
    // to refer to look up a featureSource as needed
    Map<String,SimpleFeatureSource> map = new HashMap<String,SimpleFeatureSource>();
   
    // register in map so validation processor can find it
    map.put( "LAKES:lakes",  lakesFeatureSource );
    map.put( "STREAMS:streams", streamsFeatureSource );
    // optional shortlist of layers to check (these are usually the layers your
    // user modified)
    Set<Name> check = new HashSet<Name>();
    check.add( new NameImpl("LAKES:lakes"));
   
    processor.runIntegrityTests( check, map, null, results);

    // and check the results
    System.out.println("Found "+ results.error.size() + " failires" );
    // validationExample2 end
}
View Full Code Here

        FeatureCollection collection)
        throws IOException, WfsTransactionException {
       
        LOGGER.finer("FeatureValidation called on "+dsid+":"+type.getTypeName() );
       
        ValidationProcessor validation = request.getValidationProcessor();
    if (validation == null){
      //This is a bit hackish, as the validation processor should not
      //be null, but confDemo gives us a null processor right now, some
      //thing to do with no test element in the xml files in validation.
      //But I'm taking no validation process to mean that we can't do
      //any validation.  Hopefully this doesn't mess people up?
      //could mess up some validation stuff, but not everyone makes use
      //of that, and I don't want normal transaction stuff messed up. ch
            LOGGER.warning("ValidationProcessor unavailable");
      return;
    }
        final Map failed = new TreeMap();
        ValidationResults results = new ValidationResults() {
                String name;
                String description;
                public void setValidation(Validation validation) {
                    name = validation.getName();
                    description = validation.getDescription();
                }               
                public void error(Feature feature, String message) {
                    LOGGER.warning(name + ": " + message + " (" + description
                        + ")");
                    failed.put(feature.getID(),
                        name + ": " + message + " " + "(" + description + ")");
                }
                public void warning(Feature feature, String message) {
                    LOGGER.warning(name + ": " + message + " (" + description
                        + ")");
                }
            };

        try {
      // HACK: turned the collection into a feature reader for the validation processor
      FeatureReader fr = DataUtilities.reader(collection);
            validation.runFeatureTests(dsid, type, fr, results);
        } catch (Exception badIdea) {
            // ValidationResults should of handled stuff will redesign :-)
            throw new DataSourceException("Validation Failed", badIdea);
        }
View Full Code Here

    }

    protected void integrityValidation(Map stores, Envelope check)
        throws IOException, WfsTransactionException {
        Data catalog = request.getWFS().getData();
        ValidationProcessor validation = request.getValidationProcessor();
        if( validation == null ) {
            LOGGER.warning( "Validation Processor unavaialble" );
            return;
        }
        LOGGER.finer( "Required to validate "+stores.size()+" typeRefs" );
        LOGGER.finer( "within "+check );
        // go through each modified typeName
        // and ask what we need to check
        //
        Set typeRefs = new HashSet();               
        for (Iterator i = stores.keySet().iterator(); i.hasNext();) {
            String typeRef = (String) i.next();
            typeRefs.add( typeRef );
           
            Set dependencies = validation.getDependencies( typeRef );
            LOGGER.finer( "typeRef "+typeRef+" requires "+dependencies);           
            typeRefs.addAll( dependencies );
        }

        // Grab a source for each typeName we need to check
        // Grab from the provided stores - so we check against
        // the transaction
        //
        Map sources = new HashMap();

        for (Iterator i = typeRefs.iterator(); i.hasNext();) {
            String typeRef = (String) i.next();
            LOGGER.finer("Searching for required typeRef: " + typeRef );

            if (stores.containsKey( typeRef )) {
                LOGGER.finer(" found required typeRef: " + typeRef +" (it was already loaded)");               
                sources.put( typeRef, stores.get(typeRef));
            } else {
                // These will be using Transaction.AUTO_COMMIT
                // this is okay as they were not involved in our
                // Transaction...
                LOGGER.finer(" could not find typeRef: " + typeRef +" (we will now load it)");
                String split[] = typeRef.split(":");
                String dataStoreId = split[0];
                String typeName = split[1];
                LOGGER.finer(" going to look for dataStoreId:"+dataStoreId+" and typeName:"+typeName );               
               
                // FeatureTypeInfo meta = catalog.getFeatureTypeInfo(typeName);
                String uri = catalog.getDataStoreInfo( dataStoreId ).getNameSpace().getURI();
                LOGGER.finer(" sorry I mean uri: " + uri +" and typeName:"+typeName );
               
                FeatureTypeInfo meta = catalog.getFeatureTypeInfo( typeName, uri );
                if( meta == null ){
                  throw new IOException( "Could not find typeRef:"+typeRef +" for validation processor" );
                }
                LOGGER.finer(" loaded required typeRef: " + typeRef );               
                sources.put( typeRef, meta.getFeatureSource());                                               
            }
        }
        LOGGER.finer( "Total of "+sources.size()+" featureSource marshalled for testing" );
        final Map failed = new TreeMap();
        ValidationResults results = new ValidationResults() {
                String name;
                String description;

                public void setValidation(Validation validation) {
                    name = validation.getName();
                    description = validation.getDescription();
                }

                public void error(Feature feature, String message) {
                    LOGGER.warning(name + ": " + message + " (" + description
                        + ")");
                    if (feature == null) {
                        failed.put("ALL",
                                name + ": " + message + " " + "(" + description + ")");                       
                    } else {
                    failed.put(feature.getID(),
                        name + ": " + message + " " + "(" + description + ")");
                    }
                }

                public void warning(Feature feature, String message) {
                    LOGGER.warning(name + ": " + message + " (" + description
                        + ")");
                }
            };

        try {
          //should never be null, but confDemo is giving grief, and I
          //don't want transactions to mess up just because validation
          //stuff is messed up. ch
            LOGGER.finer("Runing integrity tests using validation processor ");
          validation.runIntegrityTests(stores.keySet(), sources, check, results);         
        } catch (Exception badIdea) {
            badIdea.printStackTrace();
            // ValidationResults should of handled stuff will redesign :-)
            throw new DataSourceException("Validation Failed", badIdea);
        }
View Full Code Here

      return gs;
    }

   
    public ValidationProcessor getValidationProcessor(){
      ValidationProcessor vp = getWFS().getValidation();
      return vp;
    }
View Full Code Here

    */
  }
 
  public void setup(TestValidationResults vr, Repository repo, Map plugins, Map testSuites) throws Exception
  {
    gv = new ValidationProcessor();
    gv.load(plugins, testSuites);
    results = vr;
    repository = repo;
    validator = new Validator(repository, gv);
   
View Full Code Here

TOP

Related Classes of org.geotools.validation.ValidationProcessor

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.