Package org.geoserver.catalog

Examples of org.geoserver.catalog.CatalogBuilder


        }
       
        File uploadedFile = handleFileUpload(datastore, format, directory);

        //create a builder to help build catalog objects
        CatalogBuilder builder = new CatalogBuilder(catalog);
        builder.setWorkspace( catalog.getWorkspaceByName( workspace ) );
       
        //check if the datastore already exists, if not auto configure one
        DataStoreInfo info = catalog.getDataStoreByName( datastore );
       
        boolean add = false;
        if ( info == null ) {
            LOGGER.info("Auto-configuring datastore: " + datastore);
           
            info = builder.buildDataStore( datastore );
            add = true;
        }
        else {
            LOGGER.info("Using existing datastore: " + datastore);
        }
       
        builder.setStore(info);
       
        //update the connection parameters to point to the new file
        Map connectionParameters = info.getConnectionParameters();
        for ( Param p : factory.getParametersInfo() ) {
            //the nasty url / file hack
            if ( File.class == p.type || URL.class == p.type ) {
                File f = uploadedFile;
               
                if ( "directory".equals( p.key ) ) {
                    //set the value to be the directory
                    f = directory;
                }
               
                //convert to the required type
                //TODO: use geotools converter
                Object converted = null;
                if ( URI.class.equals( p.type  ) ) {
                    converted = f.toURI();
                }
                else if ( URL.class.equals( p.type ) ) {
                    try {
                        converted = f.toURL();
                    }
                    catch (MalformedURLException e) {
                    }
                }
                //Converters.convert( f.getAbsolutePath(), p.type );
               
                if ( converted != null ) {
                    connectionParameters.put( p.key, converted );   
                }
                else {
                    connectionParameters.put( p.key, f );
                }
               
                continue;
            }
           
            if ( p.required ) {
                try {
                    p.lookUp( connectionParameters );
                }
                catch( Exception e ) {
                    //set the sample value
                    connectionParameters.put( p.key, p.sample );
                }   
            }
        }
       
        // set the namespace uri
        NamespaceInfo namespace = catalog.getNamespaceByPrefix( info.getWorkspace().getName() );
        connectionParameters.put( "namespace", namespace.getURI() );
       
        // ensure the parameters are valid
        if ( !factory.canProcess( connectionParameters ) ) {
            //TODO: log the parameters at the debug level
            throw new RestletException( "Unable to configure datastore, bad parameters.", Status.SERVER_ERROR_INTERNAL );
        }
       
        //add or update the datastore info
        if ( add ) {
            catalog.add( info );
        }
        else {
            catalog.save( info );
        }
       
        //check configure parameter, if set to none to not try to configure
        // data feature types
        String configure = form.getFirstValue( "configure" );
        if ( "none".equalsIgnoreCase( configure ) ) {
            getResponse().setStatus( Status.SUCCESS_CREATED );
            return;
        }
       
        //load the datastore
        try {
            DataStore ds = (DataStore) info.getDataStore(null);
           
            String[] featureTypeNames = ds.getTypeNames();
            for ( int i = 0; i < featureTypeNames.length; i++ ) {
               
                //unless configure specified "all", only configure the first feature type
                if ( !"all".equalsIgnoreCase( configure ) && i > 0 ) {
                    break;
                }
               
                FeatureSource fs = ds.getFeatureSource(featureTypeNames[i]);
                FeatureTypeInfo ftinfo = null;
                if ( add ) {
                    //auto configure the feature type as well
                    ftinfo = builder.buildFeatureType(fs);
                    builder.lookupSRS(ftinfo, true);
                    builder.setupBounds(ftinfo);
                }
                else {
                    ftinfo = catalog.getFeatureTypeByName( namespace.getPrefix(), featureTypeNames[i] );
                }
               
                //update the bounds
                ReferencedEnvelope bounds = fs.getBounds();
                ftinfo.setNativeBoundingBox( bounds );
               
                //TODO: set lat lon bounding box
                if ( add ) {
                    catalog.add( ftinfo );
                   
                    //add a layer for the feature type as well
                    catalog.add(builder.buildLayer(ftinfo));
                  
                }
                else {
                    catalog.save( ftinfo );
                }
View Full Code Here


       
        coverage.setEnabled(true);
        catalog.add( coverage );
       
        //create a layer for the coverage
        catalog.add(new CatalogBuilder(catalog).buildLayer(coverage));
       
        LOGGER.info( "POST coverage " + coveragestore + "," + coverage.getName() );
        return coverage.getName();
    }
View Full Code Here

        String coveragestore = getAttribute("coveragestore");
        String coverage = getAttribute("coverage");
       
        CoverageStoreInfo cs = catalog.getCoverageStoreByName(workspace, coveragestore);
        CoverageInfo original = catalog.getCoverageByCoverageStore( cs,  coverage );
        new CatalogBuilder(catalog).updateCoverage(original,c);
        catalog.save( original );
       
        LOGGER.info( "PUT coverage " + coveragestore + "," + coverage );
    }
View Full Code Here

        if ("yes".equalsIgnoreCase(form.getFirstValue("overviews")) ) {
            /* TODO: Add overviews here */;
        }
           
        //create a builder to help build catalog objects
        CatalogBuilder builder = new CatalogBuilder(catalog);
        builder.setWorkspace( catalog.getWorkspaceByName( workspace ) );
       
        //create the coverage store
        CoverageStoreInfo info = catalog.getCoverageStoreByName(workspace, coveragestore);
        boolean add = false;
        if ( info == null ) {
            //create a new coverage store
            LOGGER.info("Auto-configuring coverage store: " + coveragestore);
           
            info = builder.buildCoverageStore(coveragestore);
            add = true;
        }
        else {
            //use the existing
            LOGGER.info("Using existing coverage store: " + coveragestore);
        }
       
        info.setType(coverageFormat.getName());
        if (!isExternal) {
            info.setURL("file:data/" + coveragestore + "/" + uploadedFile.getName() );
        }
        else {
            try {
                info.setURL( uploadedFile.toURL().toExternalForm());
            } catch (MalformedURLException e) {
                throw new RestletException( "url error", Status.SERVER_ERROR_INTERNAL, e );
            }
        }
       
        //add or update the datastore info
        if ( add ) {
            catalog.add( info );
        }
        else {
            catalog.save( info );
        }
       
        builder.setStore(info);
       
        //check configure parameter, if set to none to not try to configure coverage
        String configure = form.getFirstValue( "configure" );
        if ( "none".equalsIgnoreCase( configure ) ) {
            getResponse().setStatus( Status.SUCCESS_CREATED );
            return;
        }
       
        String coverage = uploadedFile.getName();
        if ( coverage.indexOf( '.') != -1 ) {
            coverage = coverage.substring( 0, coverage.indexOf( '.') );
        }
       
        try {
            AbstractGridCoverage2DReader reader =
                (AbstractGridCoverage2DReader) ((AbstractGridFormat) coverageFormat).getReader(uploadedFile.toURL());
            if ( reader == null ) {
                throw new RestletException( "Could not aquire reader for coverage.", Status.SERVER_ERROR_INTERNAL );
            }
           
            CoverageInfo cinfo = builder.buildCoverage( reader );
           
            //check if the name of the coverage was specified
            String coverageName = form.getFirstValue("coverageName");
            if ( coverageName != null ) {
                cinfo.setName( coverageName );
            }
           
            if ( !add ) {
                //update the existing
                CoverageInfo existing = catalog.getCoverageByCoverageStore(info,
                    coverageName != null ? coverageName : coverage );
                if ( existing == null ) {
                    //grab the first if there is only one
                    List<CoverageInfo> coverages = catalog.getCoveragesByCoverageStore( info);
                    if ( coverages.size() == 1 ) {
                        existing = coverages.get(0);
                    }
                    if ( coverages.size() == 0 ) {
                        //no coverages yet configured, change add flag and continue on
                        add = true;
                    }
                    else {
                        // multiple coverages, and one to configure not specified
                        throw new RestletException( "Unable to determine coverage to configure.", Status.SERVER_ERROR_INTERNAL);
                    }
                }
               
                if ( existing != null ) {
                    builder.updateCoverage(existing,cinfo);
                    catalog.save( existing );
                    cinfo = existing;
                }
            }
           
            //do some post configuration, if srs is not known or unset, transform to 4326
            if ("UNKNOWN".equals(cinfo.getSRS())) {
                //CoordinateReferenceSystem sourceCRS = cinfo.getBoundingBox().getCoordinateReferenceSystem();
                //CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326", true);
                //ReferencedEnvelope re = cinfo.getBoundingBox().transform(targetCRS, true);
                cinfo.setSRS( "EPSG:4326" );
                //cinfo.setCRS( targetCRS );
                //cinfo.setBoundingBox( re );
            }

            //add/save
            if ( add ) {
                catalog.add( cinfo );
               
                LayerInfo layerInfo = builder.buildLayer( cinfo );
                //JD: commenting this out, these sorts of edits should be handled
                // with a second PUT request on the created coverage
                /*
                String styleName = form.getFirstValue("style");
                if ( styleName != null ) {
View Full Code Here

       
        if ( object instanceof StyleInfo ) {
            StyleInfo s = (StyleInfo) object;
            StyleInfo original = catalog.getStyleByName( style );
    
            new CatalogBuilder( catalog ).updateStyle( original, s );
            catalog.save( original );
        }
        else if ( object instanceof Style ) {
            StyleInfo s = catalog.getStyleByName( style );
            catalog.getResourcePool().writeStyle( s, (Style) object, true );
View Full Code Here

        else {
            featureType.setNamespace( catalog.getNamespaceByPrefix( workspace ) );
        }
        featureType.setEnabled(true);
       
        CatalogBuilder cb = new CatalogBuilder(catalog);
        cb.initFeatureType( featureType );
       
        if ( featureType.getStore() == null ) {
            //get from requests
            DataStoreInfo ds = catalog.getDataStoreByName( workspace, dataStore );
            featureType.setStore( ds );
        }
       
        NamespaceInfo ns = featureType.getNamespace();
        if ( ns != null && !ns.getPrefix().equals( workspace ) ) {
            //TODO: change this once the two can be different and we untie namespace
            // from workspace
            LOGGER.warning( "Namespace: " + ns.getPrefix() + " does not match workspace: " + workspace + ", overriding." );
            ns = null;
        }
       
        if ( ns == null){
            //infer from workspace
            ns = catalog.getNamespaceByPrefix( workspace );
            featureType.setNamespace( ns );
        }
       
        featureType.setEnabled(true);
        catalog.add( featureType );
       
        //create a layer for the feature type
        catalog.add(new CatalogBuilder(catalog).buildLayer(featureType));
       
        LOGGER.info( "POST feature type" + dataStore + "," + featureType.getName() );
        return featureType.getName();
    }
View Full Code Here

        String datastore = getAttribute("datastore");
        String featuretype = getAttribute("featuretype");
       
        DataStoreInfo ds = catalog.getDataStoreByName(workspace, datastore);
        FeatureTypeInfo original = catalog.getFeatureTypeByDataStore( ds,  featuretype );
        new CatalogBuilder(catalog).updateFeatureType(original,ft);
        catalog.save( original );
       
        LOGGER.info( "PUT feature type" + datastore + "," + featuretype );
    }
View Full Code Here

            //ensure this is not a name change
            if ( workspace.getName() != null && !workspace.getName().equals( original.getName() ) ) {
                throw new RestletException( "Can't change the name of a workspace.", Status.CLIENT_ERROR_FORBIDDEN );
            }
           
            new CatalogBuilder(catalog).updateWorkspace( original, workspace );
            catalog.save( original );
        }
       
        LOGGER.info( "PUT workspace " + ws );
    }
View Full Code Here

        String workspace = getAttribute("workspace");
        String coveragestore = getAttribute("coveragestore");
       
        CoverageStoreInfo cs = (CoverageStoreInfo) object;
        CoverageStoreInfo original = catalog.getCoverageStoreByName(workspace, coveragestore);
        new CatalogBuilder( catalog ).updateCoverageStore( original, cs );
       
        catalog.save( original );
       
        LOGGER.info( "PUT coverage store " + workspace + "," + coveragestore );
    }
View Full Code Here

            //ensure this is not a prefix change
            if ( namespace.getPrefix() != null && !namespace.getPrefix().equals( original.getPrefix() ) ) {
                throw new RestletException( "Can't change the prefix of a namespace.", Status.CLIENT_ERROR_FORBIDDEN );
            }

            new CatalogBuilder(catalog).updateNamespace( original, namespace );
            catalog.save( original );
        }
        LOGGER.info( "PUT namespace " + namespace);
    }
View Full Code Here

TOP

Related Classes of org.geoserver.catalog.CatalogBuilder

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.