Package org.geoserver.catalog

Examples of org.geoserver.catalog.FeatureTypeInfo


     * @throws NoSuchElementException
     */
    static public String findFeatureTypeDirName(SimpleFeatureType featureType) {
        String name = featureType.getTypeName();
        String namespace = featureType.getName().getNamespaceURI();
        FeatureTypeInfo ftInfo = null;
        Catalog data = getCatalog();
        if(namespace != null) {
            NamespaceInfo nsInfo = data.getNamespaceByURI(namespace);
            if(nsInfo != null)
                ftInfo = data.getFeatureTypeByName( nsInfo.getPrefix(), name);
        }
        if(ftInfo == null)
            ftInfo = data.getFeatureTypeByName(name);
        if(ftInfo == null)
            return null;
        String dirName = ftInfo.getMetadata().get("dirName",String.class);
        if ( dirName == null ) {
            dirName = ftInfo.getNamespace().getPrefix() + "_" + ftInfo.getName();
        }
       
        return dirName;
    }
View Full Code Here


        DataStoreInfo ds = cFactory.createDataStore();
        ds.setWorkspace( ws );
        ds.setName( "foo" );
        catalog.add( ds );
       
        FeatureTypeInfo ft = cFactory.createFeatureType();
        ft.setStore( ds );
        ft.setNamespace( ns );
        ft.setName( "ft" );
        ft.setAbstract( "abstract");
        ft.setSRS( "EPSG:4326");
        ft.setNativeCRS( CRS.decode( "EPSG:4326") );
       
        ByteArrayOutputStream out = out();
        persister.save( ft, out );
       
        persister.setCatalog( catalog );
        ft = persister.load( in( out ), FeatureTypeInfo.class );
        assertNotNull( ft );
       
        assertEquals( "ft", ft.getName() );
        assertEquals( ds, ft.getStore() );
        assertEquals( ns, ft.getNamespace() );
        assertEquals( "EPSG:4326", ft.getSRS() );
        assertTrue( CRS.equalsIgnoreMetadata( CRS.decode( "EPSG:4326"), ft.getNativeCRS() ) );
    }
View Full Code Here

        DataStoreInfo ds = cFactory.createDataStore();
        ds.setWorkspace( ws );
        ds.setName( "foo" );
        catalog.add( ds );
       
        FeatureTypeInfo ft = cFactory.createFeatureType();
        ft.setStore( ds );
        ft.setNamespace( ns );
        ft.setName( "ft" );
        ft.setAbstract( "abstract");
        ft.setSRS( "EPSG:4326");
        ft.setNativeCRS( CRS.decode( "EPSG:4326") );
        catalog.add( ft );
       
        StyleInfo s = cFactory.createStyle();
        s.setName( "style" );
        s.setFilename( "style.sld" );
View Full Code Here

            }

            LegacyFeatureTypeInfoReader ftInfoReader = new LegacyFeatureTypeInfoReader();
            try {
                ftInfoReader.read(ftInfoFile);
                FeatureTypeInfo featureType = readFeatureType(ftInfoReader, featureTypeDirectory);
                if ( featureType == null ) {
                    continue;
                }
                catalog.add(featureType);
               
                LOGGER.info( "Loaded feature type '" + featureType.getPrefixedName() + "'" );
               
                // create a wms layer for the feature type
                LayerInfo layer = factory.createLayer();
                layer.setResource(featureType);
                layer.setName(featureType.getName());
                layer.setPath(ftInfoReader.wmsPath());
                if ( layer.getPath() == null ) {
                    layer.setPath( "/" );
                }
                layer.setType(LayerInfo.Type.VECTOR);
              
                String defaultStyleName = ftInfoReader.defaultStyle();
                if ( defaultStyleName != null ) {
                    StyleInfo style = catalog.getStyleByName(defaultStyleName);
                    if ( style != null ) {
                        layer.setDefaultStyle(style);
                    }
                }
                List<String> styles = ftInfoReader.styles();
                if(styles != null) {
                    for (String styleName : styles) {
                        StyleInfo style = catalog.getStyleByName(styleName);
                        if ( style != null ) {
                            layer.getStyles().add(style);
                        }
                    }
                }
               
                Map legendURL = ftInfoReader.legendURL();
                if( legendURL != null ) {
                    LegendInfo legend = factory.createLegend();
                    legend.setHeight( (Integer) legendURL.get( "height" ) );
                    legend.setWidth( (Integer) legendURL.get( "width" ) );
                    legend.setFormat( (String) legendURL.get( "format" ) );
                    legend.setOnlineResource( (String) legendURL.get( "onlineResource" ) );
                    layer.setLegend( legend );
                }
               
                layer.setEnabled(featureType.isEnabled());
                catalog.add(layer);
            } catch( Exception e ) {
                LOGGER.warning( "Error loadin '" + featureTypeDirectory.getName() + "/info.xml', ignoring" );
                LOGGER.log( Level.INFO, "", e );
                continue;
View Full Code Here

     * @return
     * @throws Exception
     */
    FeatureTypeInfo readFeatureType(LegacyFeatureTypeInfoReader ftInfoReader, File ftDirectory) throws Exception {
        CatalogFactory factory = catalog.getFactory();
        FeatureTypeInfo featureType = factory.createFeatureType();
       
        featureType.setNativeName(ftInfoReader.name());
        if ( ftInfoReader.alias() != null ) {
            featureType.setName( ftInfoReader.alias() );   
        }
        else {
            featureType.setName( ftInfoReader.name() );
        }
       
        featureType.setSRS("EPSG:" + ftInfoReader.srs());
       
        ProjectionPolicy pp = ProjectionPolicy.get( ftInfoReader.srsHandling() );
        featureType.setProjectionPolicy(pp);
       
        featureType.setTitle(ftInfoReader.title());
        featureType.setAbstract(ftInfoReader.abstrct());
        featureType.getKeywords().addAll(ftInfoReader.keywords());
       
        for ( Map m : ftInfoReader.metadataLinks() ) {
            MetadataLinkInfo link = factory.createMetadataLink();
            link.setContent( (String) m.get( null ) );
            link.setMetadataType( (String) m.get( "metadataType" ) );
            link.setType( (String) m.get( "type" ) );
            featureType.getMetadataLinks().add( link );
        }
       
        featureType.setLatLonBoundingBox(new ReferencedEnvelope(
                ftInfoReader.latLonBoundingBox(),
                DefaultGeographicCRS.WGS84));
        featureType.setEnabled(true);
        featureType.setMaxFeatures(ftInfoReader.maxFeatures());
        featureType.getMetadata().put( "dirName", ftInfoReader.parentDirectoryName() );
        featureType.getMetadata().put( "indexingEnabled", ftInfoReader.searchable() );
        featureType.getMetadata().put( "cachingEnabled", ftInfoReader.cachingEnabled() );
        featureType.getMetadata().put( "cacheAgeMax", ftInfoReader.cacheAgeMax() );
        featureType.getMetadata().put( "kml.regionateAttribute", ftInfoReader.regionateAttribute() );
        featureType.getMetadata().put( "kml.regionateStrategy", ftInfoReader.regionateStrategy() );
        featureType.getMetadata().put( "kml.regionateFeatureLimit", ftInfoReader.regionateFeatureLimit());

        //link to datastore
        String dataStoreName = ftInfoReader.dataStore();
        DataStoreInfo dataStore = catalog.getDataStoreByName( dataStoreName );
        if ( dataStore == null ) {
            LOGGER.warning( "Ignoring feature type: '" + ftInfoReader.parentDirectoryName()
                + "', data store '" + dataStoreName + "'  not found");
            return null;
        }
        featureType.setStore(dataStore);
       
        // link to namespace
        String prefix = dataStore.getWorkspace().getName();
        featureType.setNamespace(catalog.getNamespaceByPrefix(prefix));   
       
        if ( featureType.isEnabled() && !dataStore.isEnabled() ) {
            LOGGER.info( "Ignoring feature type: '" + ftInfoReader.parentDirectoryName()
                    + "', data store is disabled");
            featureType.setEnabled(false);
        }
       
        if ( featureType.isEnabled() ) {
            Exception error = null;
           
            //native crs
            DataAccess<? extends FeatureType, ? extends Feature> ds = null;
            try {
                ds = dataStore.getDataStore(null);
            }
            catch( Exception e ) {
                LOGGER.warning( "Ignoring feature type: '" + featureType.getName()
                        + "', error occured connecting to data store: " + e.getMessage() );
                LOGGER.log( Level.INFO, "", e );
                error = e;
            }
            
            if ( error == null ) {
                try {
                    //load the native feature type, and generate attributes from that
                    FeatureType ft = ds.getSchema(featureType.getQualifiedNativeName());
                    featureType.setNativeCRS(ft.getCoordinateReferenceSystem());
                }
                catch( Exception e ) {
                    LOGGER.warning( "Ignoring feature type: '" + featureType.getNativeName()
                            + "', error occured loading schema: " + e.getMessage() );
                    LOGGER.log(Level.INFO, "", e );
                    error = e;
                }
            }
           
            if ( error == null ) {
                //native bounds
                Envelope nativeBBOX = ftInfoReader.nativeBoundingBox();
                if ( nativeBBOX != null ) {
                    featureType.setNativeBoundingBox(new ReferencedEnvelope(nativeBBOX,featureType.getNativeCRS()));
                }
            }
           
            if ( error != null ) {
                featureType.setEnabled(false);
            }
        }
       
        return featureType;
    }
View Full Code Here

        return request;
    }
   
    public void testSingle() throws Exception {
        Catalog catalog = getCatalog();
        FeatureTypeInfo meta = getFeatureTypeInfo(MockData.BASIC_POLYGONS);

        ByteArrayOutputStream output = new ByteArrayOutputStream();

        XmlSchemaEncoder response = new XmlSchemaEncoder.V11(getGeoServer());
        response.write(new FeatureTypeInfo[] { meta }, output, request());
View Full Code Here

        assertEquals(1, types.getLength());
    }

    public void testWithDifferntNamespaces() throws Exception {

        FeatureTypeInfo meta1 = getFeatureTypeInfo(MockData.BASIC_POLYGONS);
        FeatureTypeInfo meta2 = getFeatureTypeInfo(MockData.POLYGONS);
       
        ByteArrayOutputStream output = new ByteArrayOutputStream();

        XmlSchemaEncoder response = new XmlSchemaEncoder.V11(getGeoServer());
        response.write(new FeatureTypeInfo[] { meta1, meta2 }, output, request());
View Full Code Here

        assertTrue( catalog.getFeatureTypes().isEmpty() );
       
        catalog.add( ft );
        assertEquals( 1, catalog.getFeatureTypes().size() );
       
        FeatureTypeInfo ft2 = catalog.getFactory().createFeatureType();
        try {
            catalog.add(ft2);
            fail( "adding with no name should throw exception");
        }
        catch( Exception e ) {}
       
        ft2.setName("ft2Name");
        try {
            catalog.add(ft2);
            fail( "adding with no store should throw exception");
        }
        catch( Exception e ) {}
       
        ft2.setStore( ds );
        catalog.add( ft2 );
       
        FeatureTypeInfo ft3 = catalog.getFactory().createFeatureType();
        ft3.setName( "ft3Name");
        try {
            catalog.getFeatureTypes().add( ft3 );
            fail( "adding directly should throw an exception");
        }
        catch( Exception e ) {}
View Full Code Here

        assertTrue( catalog.getFeatureTypes().isEmpty() );
    }
   
    public void testGetFeatureTypeById() {
        catalog.add( ft );
        FeatureTypeInfo  ft2 = catalog.getFeatureType(ft.getId());
       
        assertNotNull(ft2);
        assertFalse( ft == ft2 );
        assertEquals( ft, ft2 );
    }
View Full Code Here

        assertEquals( ft, ft2 );
    }

    public void testGetFeatureTypeByName() {
        catalog.add( ft );
        FeatureTypeInfo  ft2 = catalog.getFeatureTypeByName(ft.getName());
       
        assertNotNull(ft2);
        assertFalse( ft == ft2 );
        assertEquals( ft, ft2 );
       
        NamespaceInfo ns2 = catalog.getFactory().createNamespace();
        ns2.setPrefix( "ns2Prefix" );
        ns2.setURI( "ns2URI" );
        catalog.add( ns2 );
       
        FeatureTypeInfo ft3 = catalog.getFactory().createFeatureType();
        ft3.setName( "ft3Name" );
        ft3.setStore( ds );
        ft3.setNamespace( ns2 );
        catalog.add( ft3 );
       
        FeatureTypeInfo ft4 = catalog.getFeatureTypeByName(ns2.getPrefix(), ft3.getName() );
        assertNotNull(ft4);
        assertFalse( ft4 == ft3 );
        assertEquals( ft3, ft4 );
       
        ft4 = catalog.getFeatureTypeByName(ns2.getURI(), ft3.getName() );
View Full Code Here

TOP

Related Classes of org.geoserver.catalog.FeatureTypeInfo

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.