Package org.geoserver.catalog.impl

Examples of org.geoserver.catalog.impl.CatalogImpl


        Document dom = dom( in( out ) );
        assertEquals( "wmsLayer", dom.getDocumentElement().getNodeName() );
    }
   
    public void testLayer() throws Exception {
        Catalog catalog = new CatalogImpl();
        CatalogFactory cFactory = catalog.getFactory();
       
        WorkspaceInfo ws = cFactory.createWorkspace();
        ws.setName( "foo" );
        catalog.add( ws );
       
        NamespaceInfo ns = cFactory.createNamespace();
        ns.setPrefix( "acme" );
        ns.setURI( "http://acme.org" );
        catalog.add( ns );
       
        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" );
        catalog.add( s );
       
        LayerInfo l = cFactory.createLayer();
        // TODO: reinstate when layer/publish slipt is actually in place
        // l.setName( "layer" );
        l.setResource( ft );
        l.setDefaultStyle( s );
        catalog.add( l );
       
        ByteArrayOutputStream out = out();
        persister.save( l, out );
       
        persister.setCatalog( catalog );
View Full Code Here


        //assertNotNull( l.getStyles() );
       
    }
   
    public void testVirtualTable() throws Exception {
        Catalog catalog = new CatalogImpl();
        CatalogFactory cFactory = catalog.getFactory();
       
        WorkspaceInfo ws = cFactory.createWorkspace();
        ws.setName( "foo" );
        catalog.add( ws );
       
        NamespaceInfo ns = cFactory.createNamespace();
        ns.setPrefix( "acme" );
        ns.setURI( "http://acme.org" );
        catalog.add( ns );
       
        DataStoreInfo ds = cFactory.createDataStore();
        ds.setWorkspace( ws );
        ds.setName( "foo" );
        catalog.add( ds );
       
        VirtualTable vt = new VirtualTable("riverReduced",
                "select a, b, c * %mulparam% \n from table \n where x > 1 %andparam%");
        vt.addGeometryMetadatata("geom", LineString.class, 4326);
        vt.setPrimaryKeyColumns(Arrays.asList("a", "b"));
        vt.addParameter(new VirtualTableParameter("mulparam", "1", new RegexpValidator("\\d+")));
        vt.addParameter(new VirtualTableParameter("andparam", null));
       
        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") );
        ft.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt);
        catalog.add( ft );
       
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        persister.save(ft, out);
       
        // System.out.println(out.toString());
View Full Code Here

        //look for catalog.xml, if it exists assume we are dealing with
        // an old data directory
        File f = resourceLoader.find( "catalog.xml" );
        if ( f == null ) {
            //assume 2.x style data directory
            CatalogImpl catalog2 = (CatalogImpl) readCatalog( xp );
            ((CatalogImpl)catalog).sync( catalog2 );
        } else {
            // import old style catalog, register the persister now so that we start
            // with a new version of the catalog
            CatalogImpl catalog2 = (CatalogImpl) readLegacyCatalog( f, xp );
            ((CatalogImpl)catalog).sync( catalog2 );
        }
    }
View Full Code Here

   
    /**
     * Reads the catalog from disk.
     */
    Catalog readCatalog( XStreamPersister xp ) throws Exception {
        Catalog catalog = new CatalogImpl();
        catalog.setResourceLoader(resourceLoader);
        xp.setCatalog( catalog );
       
        CatalogFactory factory = catalog.getFactory();
      
        //styles
        File styles = resourceLoader.find( "styles" );
        for ( File sf : list(styles,new SuffixFileFilter(".xml") ) ) {
            try {
                //handle the .xml.xml case
                if (new File(styles,sf.getName()+".xml").exists()) {
                    continue;
                }
               
                StyleInfo s = depersist( xp, sf, StyleInfo.class );
                catalog.add( s );
               
                LOGGER.info( "Loaded style '" + s.getName() + "'" );
            }
            catch( Exception e ) {
                LOGGER.log( Level.WARNING, "Failed to load style from file '" + sf.getName() + "'" , e );
            }
        }
       
        //workspaces, stores, and resources
        File workspaces = resourceLoader.find( "workspaces" );
        if ( workspaces != null ) {
            //do a first quick scan over all workspaces, setting the default
            File dws = new File(workspaces, "default.xml");
            WorkspaceInfo defaultWorkspace = null;
            if (dws.exists()) {
                try {
                    defaultWorkspace = depersist(xp, dws, WorkspaceInfo.class);
                    LOGGER.info("Loaded default workspace " + defaultWorkspace.getName());
                }
                catch( Exception e ) {
                    LOGGER.log(Level.WARNING, "Failed to load default workspace", e);
                }
            }
            else {
                LOGGER.warning("No default workspace was found.");
            }
           
            for ( File wsd : list(workspaces, DirectoryFileFilter.INSTANCE ) ) {
                File f = new File( wsd, "workspace.xml");
                if ( !f.exists() ) {
                    continue;
                }
               
                WorkspaceInfo ws = null;
                try {
                    ws = depersist( xp, f, WorkspaceInfo.class );
                    catalog.add( ws );   
                }
                catch( Exception e ) {
                    LOGGER.log( Level.WARNING, "Failed to load workspace '" + wsd.getName() + "'" , e );
                    continue;
                }
               
                LOGGER.info( "Loaded workspace '" + ws.getName() +"'");
               
                //load the namespace
                File nsf = new File( wsd, "namespace.xml" );
                NamespaceInfo ns = null;
                if ( nsf.exists() ) {
                    try {
                        ns = depersist( xp, nsf, NamespaceInfo.class );
                        catalog.add( ns );
                    }
                    catch( Exception e ) {
                        LOGGER.log( Level.WARNING, "Failed to load namespace for '" + wsd.getName() + "'" , e );
                    }
                }
               
                //set the default workspace, this value might be null in the case of coming from a
                // 2.0.0 data directory. See http://jira.codehaus.org/browse/GEOS-3440
                if (defaultWorkspace != null ) {
                    if (ws.getName().equals(defaultWorkspace.getName())) {
                        catalog.setDefaultWorkspace(ws);
                        if (ns != null) {
                            catalog.setDefaultNamespace(ns);
                        }
                    }
                }
                else {
                    //create the default.xml file
                    defaultWorkspace = catalog.getDefaultWorkspace();
                    if (defaultWorkspace != null) {
                        try {
                            persist(xp, defaultWorkspace, dws);   
                        }
                        catch( Exception e ) {
                            LOGGER.log( Level.WARNING, "Failed to persist default workspace '" +
                                wsd.getName() + "'" , e );
                        }
                       
                    }
                }
               
            }
           
            for ( File wsd : list(workspaces, DirectoryFileFilter.INSTANCE ) ) {
               
                //load the stores for this workspace
                for ( File sd : list(wsd, DirectoryFileFilter.INSTANCE) ) {
                    File f = new File( sd, "datastore.xml");
                    if ( f.exists() ) {
                        //load as a datastore
                        DataStoreInfo ds = null;
                        try {   
                            ds = depersist( xp, f, DataStoreInfo.class );
                            catalog.add( ds );
                           
                            LOGGER.info( "Loaded data store '" + ds.getName() +"'");
                           
                            if (ds.isEnabled()) {
                                //connect to the datastore to determine if we should disable it
                                try {
                                    ds.getDataStore(null);
                                }
                                catch( Throwable t ) {
                                    LOGGER.warning( "Error connecting to '" + ds.getName() + "'. Disabling." );
                                    LOGGER.log( Level.INFO, "", t );
                                   
                                    ds.setError(t);
                                    ds.setEnabled(false);
                                }
                            }
                        }
                        catch( Exception e ) {
                            LOGGER.log( Level.WARNING, "Failed to load data store '" + sd.getName() +"'", e);
                            continue;
                        }
                       
                        //load feature types
                        for ( File ftd : list(sd,DirectoryFileFilter.INSTANCE) ) {
                            f = new File( ftd, "featuretype.xml" );
                            if( f.exists() ) {
                                FeatureTypeInfo ft = null;
                                try {
                                    ft = depersist(xp,f,FeatureTypeInfo.class);
                                }
                                catch( Exception e ) {
                                    LOGGER.log( Level.WARNING, "Failed to load feature type '" + ftd.getName() +"'", e);
                                    continue;
                                }
                               
                                catalog.add( ft );
                               
                                LOGGER.info( "Loaded feature type '" + ds.getName() +"'");
                               
                                f = new File( ftd, "layer.xml" );
                                if ( f.exists() ) {
                                    try {
                                        LayerInfo l = depersist(xp, f, LayerInfo.class );
                                        catalog.add( l );
                                       
                                        LOGGER.info( "Loaded layer '" + l.getName() + "'" );
                                    }
                                    catch( Exception e ) {
                                        LOGGER.log( Level.WARNING, "Failed to load layer for feature type '" + ft.getName() +"'", e);
                                    }
                                }
                            }
                            else {
                                LOGGER.warning( "Ignoring feature type directory " + ftd.getAbsolutePath() );
                            }
                        }
                    } else {
                        //look for a coverage store
                        f = new File( sd, "coveragestore.xml" );
                        if ( f.exists() ) {
                            CoverageStoreInfo cs = null;
                            try {
                                cs = depersist( xp, f, CoverageStoreInfo.class );
                                catalog.add( cs );
                           
                                LOGGER.info( "Loaded coverage store '" + cs.getName() +"'");
                            }
                            catch( Exception e ) {
                                LOGGER.log( Level.WARNING, "Failed to load coverage store '" + sd.getName() +"'", e);
                                continue;
                            }
                           
                            //load coverages
                            for ( File cd : list(sd,DirectoryFileFilter.INSTANCE) ) {
                                f = new File( cd, "coverage.xml" );
                                if( f.exists() ) {
                                    CoverageInfo c = null;
                                    try {
                                        c = depersist(xp,f,CoverageInfo.class);
                                        catalog.add( c );
                                       
                                        LOGGER.info( "Loaded coverage '" + cs.getName() +"'");
                                    }
                                    catch( Exception e ) {
                                        LOGGER.log( Level.WARNING, "Failed to load coverage '" + cd.getName() +"'", e);
                                        continue;
                                    }
                                   
                                    f = new File( cd, "layer.xml" );
                                    if ( f.exists() ) {
                                        try {
                                            LayerInfo l = depersist(xp, f, LayerInfo.class );
                                            catalog.add( l );
                                           
                                            LOGGER.info( "Loaded layer '" + l.getName() + "'" );
                                        }
                                        catch( Exception e ) {
                                            LOGGER.log( Level.WARNING, "Failed to load layer coverage '" + c.getName() +"'", e);
                                        }
                                    }
                                }
                                else {
                                    LOGGER.warning( "Ignoring coverage directory " + cd.getAbsolutePath() );
                                }
                            }
                        } else {
                            f = new File( sd, "wmsstore.xml" );
                            if(f.exists()) {
                                WMSStoreInfo wms = null;
                                try {
                                    wms = depersist( xp, f, WMSStoreInfo.class );
                                    catalog.add( wms );
                               
                                    LOGGER.info( "Loaded wmsstore '" + wms.getName() +"'");
                                } catch( Exception e ) {
                                    LOGGER.log( Level.WARNING, "Failed to load wms store '" + sd.getName() +"'", e);
                                    continue;
                                }
                               
                                //load wms layers
                                for ( File cd : list(sd,DirectoryFileFilter.INSTANCE) ) {
                                    f = new File( cd, "wmslayer.xml" );
                                    if( f.exists() ) {
                                        WMSLayerInfo wl = null;
                                        try {
                                            wl = depersist(xp,f,WMSLayerInfo.class);
                                            catalog.add( wl );
                                           
                                            LOGGER.info( "Loaded wms layer'" + wl.getName() +"'");
                                        }
                                        catch( Exception e ) {
                                            LOGGER.log( Level.WARNING, "Failed to load wms layer '" + cd.getName() +"'", e);
                                            continue;
                                        }
                                       
                                        f = new File( cd, "layer.xml" );
                                        if ( f.exists() ) {
                                            try {
                                                LayerInfo l = depersist(xp, f, LayerInfo.class );
                                                catalog.add( l );
                                               
                                                LOGGER.info( "Loaded layer '" + l.getName() + "'" );
                                            }
                                            catch( Exception e ) {
                                                LOGGER.log( Level.WARNING, "Failed to load cascaded wms layer '" + wl.getName() +"'", e);
                                            }
                                        }
                                    }
                                    else {
                                        LOGGER.warning( "Ignoring coverage directory " + cd.getAbsolutePath() );
                                    }
                                }
                            } else {
                                LOGGER.warning( "Ignoring store directory '" + sd.getName() "'");
                                continue;
                            }
                        }
                    }
                }
            }
        }
        else {
            LOGGER.warning( "No 'workspaces' directory found, unable to load any stores." );
        }

        //namespaces
       
        //layergroups
        File layergroups = resourceLoader.find( "layergroups" );
        if ( layergroups != null ) {
            for ( File lgf : list( layergroups, new SuffixFileFilter( ".xml" ) ) ) {
                try {
                    LayerGroupInfo lg = depersist( xp, lgf, LayerGroupInfo.class );
                    if(lg.getLayers() == null || lg.getLayers().size() == 0) {
                        LOGGER.warning("Skipping empty layer group '" + lg.getName() + "', it is invalid");
                        continue;
                    }
                    catalog.add( lg );
                   
                    LOGGER.info( "Loaded layer group '" + lg.getName() + "'" );   
                }
                catch( Exception e ) {
                    LOGGER.log( Level.WARNING, "Failed to load layer group '" + lgf.getName() + "'", e );
View Full Code Here

   
    /**
     * Reads the legacy (1.x) catalog from disk.
     */
    Catalog readLegacyCatalog(File f, XStreamPersister xp) throws Exception {
        Catalog catalog2 = new CatalogImpl();
        catalog2.setResourceLoader(resourceLoader);
       
        //add listener now as a converter which will convert from the old style
        // data directory to the new
        GeoServerPersister p = new GeoServerPersister( resourceLoader, xp );
        if ( !legacy ) {
            catalog2.addListener( p );
        }
       
        LegacyCatalogImporter importer = new LegacyCatalogImporter(catalog2);
        importer.setResourceLoader(resourceLoader);
        importer.imprt(resourceLoader.getBaseDirectory());
       
        if ( !legacy ) {
            catalog2.removeListener( p );
        }
       
        if ( !legacy ) {
            //copy files from old feature type directories to new
            File featureTypesDir = resourceLoader.find( "featureTypes" );
View Full Code Here

            assertEquals("NoLayerRequested", e.getCode());
        }
    }

    public void testGetRequest() throws Exception {
        CatalogImpl catalog = new CatalogImpl();
        geoServerImpl.setCatalog(catalog);
        NamespaceInfoImpl ns = new NamespaceInfoImpl();
        ns.setPrefix("topp");
        ns.setURI("http//www.geoserver.org");

        WorkspaceInfoImpl workspace = new WorkspaceInfoImpl();
        workspace.setId("fakeWs");
        workspace.setName("fakeWs");

        DataStoreInfoImpl dataStoreInfo = new DataStoreInfoImpl(catalog);
        dataStoreInfo.setName("fakeDs");
        dataStoreInfo.setId("fakeDs");
        dataStoreInfo.setWorkspace(workspace);

        FeatureTypeInfoImpl featureTypeInfo = new FeatureTypeInfoImpl(catalog);
        featureTypeInfo.setNamespace(ns);
        featureTypeInfo.setName("states");
        featureTypeInfo.setStore(dataStoreInfo);

        final LayerInfoImpl layerInfo = new LayerInfoImpl();
        layerInfo.setResource(featureTypeInfo);
        layerInfo.setId("states");
        layerInfo.setName("states");

        catalog.add(ns);
        catalog.add(workspace);
        catalog.add(dataStoreInfo);
        catalog.add(featureTypeInfo);
        catalog.add(layerInfo);

        params.put("VERSION", "1.1.1");

        CoverageStoreInfoImpl coverageStoreInfo = new CoverageStoreInfoImpl(catalog);
        coverageStoreInfo.setId("coverageStore");
        coverageStoreInfo.setName("coverageStore");
        coverageStoreInfo.setWorkspace(workspace);

        CoverageInfoImpl coverageInfo = new CoverageInfoImpl(catalog);
        coverageInfo.setNamespace(ns);
        coverageInfo.setName("fakeCoverage");
        coverageInfo.setStore(coverageStoreInfo);

        LayerInfoImpl layerInfo2 = new LayerInfoImpl();
        layerInfo2.setResource(coverageInfo);
        layerInfo2.setId("fakeCoverage");
        layerInfo2.setName("fakeCoverage");

        catalog.add(coverageStoreInfo);
        catalog.add(coverageInfo);
        catalog.add(layerInfo2);

        params.put("LAYERS", "topp:states,topp:fakeCoverage");
        Map<String, Object> kvp = new HashMap<String, Object>(params);
        kvp.put("LAYERS", Arrays.asList(new MapLayerInfo(layerInfo), new MapLayerInfo(layerInfo2)));
        DescribeLayerRequest describeRequest = getRequest(params, kvp);
View Full Code Here

        // namespaces.put(TEST_NS_PREFIX, TEST_NAMESPACE);
        // XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
        XPATH = XMLUnit.newXpathEngine();

        GeoServerImpl geoServerImpl = new GeoServerImpl();
        catalog = new CatalogImpl();
        geoServerImpl.setCatalog(catalog);
        NamespaceInfoImpl ns = new NamespaceInfoImpl();
        ns.setPrefix(TEST_NS_PREFIX);
        ns.setURI(TEST_NAMESPACE);
View Full Code Here

        geosConfig.setGlobal(geosInfo);

        wmsInfo = new WMSInfoImpl();
        geosConfig.add(wmsInfo);

        catalog = new CatalogImpl();
        geosConfig.setCatalog(catalog);

        wmsConfig = new WMS(geosConfig);

        req = new GetCapabilitiesRequest();
View Full Code Here

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
        // use the dataSource we just created
        context.getBean(Config.class).real = dataSource;
        configDb = context.getBean(ConfigDatabase.class);

        catalog = new CatalogImpl();
        configDb.setCatalog(catalog);
        configDb.initDb(null);
    }
View Full Code Here

        testSupport.tearDown();
    }

    @Override
    protected Catalog createCatalog() {
        CatalogImpl catalogImpl = new CatalogImpl();
        catalogImpl.setFacade(facade);
        return catalogImpl;
    }
View Full Code Here

TOP

Related Classes of org.geoserver.catalog.impl.CatalogImpl

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.