Package org.geoserver.catalog

Examples of org.geoserver.catalog.CatalogBuilder


        tb.init((SimpleFeatureType) fs2.getSchema());
        tb.add("num", Integer.class);
        tb.remove("boundedBy");
        store.createSchema(tb.buildFeatureType());
       
        CatalogBuilder cb = new CatalogBuilder(cat);
        cb.setStore(ds);
       
        FeatureStore fs = (FeatureStore) store.getFeatureSource("Fifteen");
        addFeatures(fs, fs1.getFeatures());
       
        FeatureTypeInfo ft = cb.buildFeatureType(fs);
        cat.add(ft);
       
        fs = (FeatureStore) store.getFeatureSource("Seven");
        addFeatures(fs, fs2.getFeatures());
       
        ft = cb.buildFeatureType(fs);
        cat.add(ft);
    }
View Full Code Here


    @Override
    public List<ImportTask> list(ImportData data, Catalog catalog, ProgressMonitor monitor)
            throws IOException {
        File file = getFileFromData(data);
        CatalogBuilder cb = new CatalogBuilder(catalog);
        String baseName = typeNameFromFile(file);
        CatalogFactory factory = catalog.getFactory();

        Collection<SimpleFeatureType> featureTypes = parseFeatureTypes(baseName, file);
        List<ImportTask> result = new ArrayList<ImportTask>(featureTypes.size());
        for (SimpleFeatureType featureType : featureTypes) {
            String name = featureType.getName().getLocalPart();
            FeatureTypeInfo ftinfo = factory.createFeatureType();
            ftinfo.setEnabled(true);
            ftinfo.setNativeName(name);
            ftinfo.setName(name);
            ftinfo.setTitle(name);
            ftinfo.setNamespace(catalog.getDefaultNamespace());
            List<AttributeTypeInfo> attributes = ftinfo.getAttributes();
            for (AttributeDescriptor ad : featureType.getAttributeDescriptors()) {
                AttributeTypeInfo att = factory.createAttribute();
                att.setName(ad.getLocalName());
                att.setBinding(ad.getType().getBinding());
                attributes.add(att);
            }

            LayerInfo layer = cb.buildLayer((ResourceInfo) ftinfo);
            ResourceInfo resource = layer.getResource();
            resource.setSRS(KML_SRS);
            resource.setNativeCRS(KML_CRS);
            resource.setNativeBoundingBox(EMPTY_BOUNDS);
            resource.setLatLonBoundingBox(EMPTY_BOUNDS);
View Full Code Here

        tb.remove("surfaceProperty");
        tb.remove("curveProperty");
        tb.remove("uriProperty");
        store.createSchema(tb.buildFeatureType());
       
        CatalogBuilder cb = new CatalogBuilder(cat);
        cb.setStore(ds);
       
        FeatureStore fs = (FeatureStore) store.getFeatureSource("Forests");
        fs.addFeatures(fs1.getFeatures());
        addFeature(fs,"MULTIPOLYGON (((0.008151604330777 -0.0023208963631571, 0.0086527358638763 -0.0012374917185382, 0.0097553137885805 -0.0004505798694767, 0.0156132468328575 0.001226912691216, 0.0164282119026783 0.0012863836826631, 0.0171241513076058 0.0011195104764988, 0.0181763809803841 0.0003258121477801, 0.018663180519973 -0.0007914339515293, 0.0187 -0.0054, 0.0185427596344991 -0.0062643098258021, 0.0178950534559435 -0.0072336706251426, 0.0166538015456463 -0.0078538015456464, 0.0160336706251426 -0.0090950534559435, 0.0150643098258021 -0.0097427596344991, 0.0142 -0.0099, 0.0086 -0.0099, 0.0077356901741979 -0.0097427596344991, 0.0067663293748574 -0.0090950534559435, 0.0062572403655009 -0.0082643098258021, 0.0061 -0.0074, 0.0061055767515099 -0.0046945371967831, 0.0062818025956546 -0.0038730531083409, 0.0066527358638763 -0.0032374917185382, 0.0072813143786463 -0.0026800146279973, 0.008151604330777 -0.0023208963631571)))",
            "110", "Foo Forest");
        addFeature(fs, "MULTIPOLYGON (((-0.0023852705061082 -0.005664537521815, -0.0026781637249217 -0.0063716443030016, -0.0033852705061082 -0.006664537521815, -0.0040923772872948 -0.0063716443030016, -0.0043852705061082 -0.005664537521815, -0.0040923772872947 -0.0049574307406285, -0.0033852705061082 -0.004664537521815, -0.0026781637249217 -0.0049574307406285, -0.0023852705061082 -0.005664537521815)))",
            "111", "Bar Forest");
        FeatureTypeInfo ft = cb.buildFeatureType(fs);
        cat.add(ft);
       
        fs = (FeatureStore) store.getFeatureSource("Lakes");
        fs.addFeatures(fs2.getFeatures());
        addFeature(fs, "POLYGON ((0.0049784771992108 -0.0035817570010558, 0.0046394552911414 -0.0030781256232061, 0.0046513167019495 -0.0024837722339832, 0.0051238379318686 -0.0011179833712748, 0.0057730295670053 -0.0006191988155468, 0.0065631962428717 -0.0022312008226987, 0.0065546368796182 -0.0027977724434409, 0.0060815583363558 -0.0033764140395305, 0.0049784771992108 -0.0035817570010558))",
            "102", "Red Lake");
        addFeature(fs, "POLYGON ((0.0057191452206184 -0.0077928768384869, 0.0051345315543621 -0.0076850644756826, 0.0046394552911414 -0.0070781256232061, 0.0046513167019495 -0.0064837722339832, 0.0051238379318686 -0.0051179833712748, 0.0054994549090862 -0.0047342895334108, 0.0070636636030018 -0.0041582580884052, 0.0078667798947931 -0.0042156264760765, 0.0082944271909999 -0.0046527864045, 0.0089944271909999 -0.0060527864045, 0.0090938616646936 -0.0066106299753791, 0.0089805097233498 -0.0069740280868118, 0.0084059445811345 -0.007452049322921, 0.0057191452206184 -0.0077928768384869))",
            "103", "Green Lake");
        addFeature(fs, "POLYGON ((0.0007938800267961 -0.0056175636045986, 0.0011573084862925 -0.0051229419555271, 0.0017412204815544 -0.0049337922722299, 0.0023617041415903 -0.0050976945961703, 0.0029728059060882 -0.0055503031602247, 0.0034289873678372 -0.0063805324543033, 0.0035801692478343 -0.0074485059825999, 0.0034823709081135 -0.008013559804892, 0.0032473247836666 -0.008318888359415, 0.0029142821960289 -0.0085126790755088, 0.0023413406005588 -0.0085369332611115, 0.0011766812981572 -0.0078593563537122, 0.0006397573417165 -0.0067622385244755, 0.0007938800267961 -0.0056175636045986))",
            "110", "Black Lake");
        ft = cb.buildFeatureType(fs);
        cat.add(ft);
       
        fs = (FeatureStore) store.getFeatureSource("PrimitiveGeoFeature");
        fs.addFeatures(fs3.getFeatures());
        ft = cb.buildFeatureType(fs);
        cat.add(ft);
       
        tb = new SimpleFeatureTypeBuilder();
        tb.setName("TimeFeature");
        tb.add("name", String.class);
        tb.add("dateTime", Date.class);
       
        SimpleFeatureType timeFeatureType = tb.buildFeatureType();
        store.createSchema(timeFeatureType);
       
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        DefaultFeatureCollection features = new DefaultFeatureCollection(null, null);
        SimpleFeatureBuilder fb = new SimpleFeatureBuilder(timeFeatureType);
        fb.add("one");
        fb.add(dateFormat.parseObject("2006-04-04 22:00:00"));
        features.add(fb.buildFeature(null));
       
        fb.add("two");
        fb.add(dateFormat.parseObject("2006-05-05 20:00:00"));
        features.add(fb.buildFeature(null));
       
        fb.add("three");
        fb.add(dateFormat.parseObject("2006-06-28 18:00:00"));
        features.add(fb.buildFeature(null));
       
        fs = (FeatureStore) store.getFeatureSource("TimeFeature");
        fs.addFeatures(features);
        ft = cb.buildFeatureType(fs);
        cat.add(ft);
    }
View Full Code Here

                        "The catalog is empty, could not find a default workspace");
            }
        }

      //create a builder to help build catalog objects
        CatalogBuilder cb = new CatalogBuilder(catalog);
        cb.setWorkspace( ws );

        // ok, find the target store
        StoreInfo storeInfo = null;
        boolean add = false;
        if (store != null) {
          if (features != null)
          {
            storeInfo = catalog.getDataStoreByName(ws.getName(), store);
          }
          else if (coverage != null)
          {
            storeInfo = catalog.getCoverageStoreByName(ws.getName(), store);
          }
            if (storeInfo == null) {
                throw new ProcessException("Could not find store " + store + " in workspace "
                        + workspace);
                // TODO: support store creation
            }
        } else if (features != null) {
            storeInfo = catalog.getDefaultDataStore(ws);
            if (storeInfo == null) {
                throw new ProcessException("Could not find a default store in workspace "
                        + ws.getName());
            }
        } else if (coverage != null) {
          //create a new coverage store
            LOGGER.info("Auto-configuring coverage store: " + (name != null ? name : coverage.getName().toString()));
           
            storeInfo = cb.buildCoverageStore((name != null ? name : coverage.getName().toString()));
            add = true;
            store = (name != null ? name : coverage.getName().toString());
           
            if (storeInfo == null) {
                throw new ProcessException("Could not find a default store in workspace " + ws.getName());
            }
        }

        // check the target style if any
        StyleInfo targetStyle = null;
        if (styleName != null) {
            targetStyle = catalog.getStyleByName(styleName);
            if (targetStyle == null) {
                throw new ProcessException("Could not find style " + styleName);
            }
        }

        if (features != null)
        {
          // check if the target layer and the target feature type are not
          // already there (this is a half-assed attempt as we don't have
          // an API telling us how the feature type name will be changed
          // by DataStore.createSchema(...), but better than fully importing
          // the data into the target store to find out we cannot create the layer...)
          String tentativeTargetName = null;
          if (name != null) {
            tentativeTargetName = ws.getName() + ":" + name;
          } else {
            tentativeTargetName = ws.getName() + ":" + features.getSchema().getTypeName();
          }
          if (catalog.getLayer(tentativeTargetName) != null) {
            throw new ProcessException("Target layer " + tentativeTargetName + " already exists");
          }

          // check the target crs
          String targetSRSCode = null;
          if (srs != null) {
            try {
              Integer code = CRS.lookupEpsgCode(srs, true);
              if (code == null) {
                throw new WPSException("Could not find a EPSG code for " + srs);
              }
              targetSRSCode = "EPSG:" + code;
            } catch (Exception e) {
              throw new ProcessException("Could not lookup the EPSG code for the provided srs", e);
            }
          } else {
            // check we can extract a code from the original data
            GeometryDescriptor gd = features.getSchema().getGeometryDescriptor();
            if (gd == null) {
              // data is geometryless, we need a fake SRS
              targetSRSCode = "EPSG:4326";
              srsHandling = ProjectionPolicy.FORCE_DECLARED;
            } else {
              CoordinateReferenceSystem nativeCrs = gd.getCoordinateReferenceSystem();
              if (nativeCrs == null) {
                throw new ProcessException("The original data has no native CRS, "
                    + "you need to specify the srs parameter");
              } else {
                try {
                  Integer code = CRS.lookupEpsgCode(nativeCrs, true);
                  if (code == null) {
                    throw new ProcessException("Could not find an EPSG code for data "
                        + "native spatial reference system: " + nativeCrs);
                  } else {
                    targetSRSCode = "EPSG:" + code;
                  }
                } catch (Exception e) {
                  throw new ProcessException("Failed to loookup an official EPSG code for "
                      + "the source data native " + "spatial reference system", e);
                }
              }
            }
          }

          // import the data into the target store
          SimpleFeatureType targetType;
          try {
            targetType = importDataIntoStore(features, name, (DataStoreInfo) storeInfo);
          } catch (IOException e) {
            throw new ProcessException("Failed to import data into the target store", e);
          }

          // now import the newly created layer into GeoServer
          try {
            cb.setStore(storeInfo);

            // build the typeInfo and set CRS if necessary
            FeatureTypeInfo typeInfo = cb.buildFeatureType(targetType.getName());
            if (targetSRSCode != null) {
              typeInfo.setSRS(targetSRSCode);
            }
            if (srsHandling != null) {
              typeInfo.setProjectionPolicy(srsHandling);
            }
            // compute the bounds
            cb.setupBounds(typeInfo);

            // build the layer and set a style
            LayerInfo layerInfo = cb.buildLayer(typeInfo);
            if (targetStyle != null) {
              layerInfo.setDefaultStyle(targetStyle);
            }

            catalog.add(typeInfo);
            catalog.add(layerInfo);

            return layerInfo.prefixedName();
          } catch (Exception e) {
            throw new ProcessException(
                "Failed to complete the import inside the GeoServer catalog", e);
          }
        }
        else if (coverage != null)
        {
          try {
            final File directory = catalog.getResourceLoader().findOrCreateDirectory("data", workspace, store);
            final File file = File.createTempFile(store, ".tif", directory);
                ((CoverageStoreInfo)storeInfo).setURL( file.toURL().toExternalForm() );
                ((CoverageStoreInfo)storeInfo).setType("GeoTIFF");
               
              // check the target crs
                CoordinateReferenceSystem cvCrs = coverage.getCoordinateReferenceSystem();
                String targetSRSCode = null;
              if (srs != null) {
                try {
                  Integer code = CRS.lookupEpsgCode(srs, true);
                  if (code == null) {
                    throw new WPSException("Could not find a EPSG code for " + srs);
                  }
                  targetSRSCode = "EPSG:" + code;
                } catch (Exception e) {
                  throw new ProcessException("Could not lookup the EPSG code for the provided srs", e);
                }
              } else {
                // check we can extract a code from the original data
                if (cvCrs == null) {
                  // data is geometryless, we need a fake SRS
                  targetSRSCode = "EPSG:4326";
                  srsHandling = ProjectionPolicy.FORCE_DECLARED;
                  srs = DefaultGeographicCRS.WGS84;
                } else {
                  CoordinateReferenceSystem nativeCrs = cvCrs;
                  if (nativeCrs == null) {
                    throw new ProcessException("The original data has no native CRS, "
                        + "you need to specify the srs parameter");
                  } else {
                    try {
                      Integer code = CRS.lookupEpsgCode(nativeCrs, true);
                      if (code == null) {
                        throw new ProcessException("Could not find an EPSG code for data "
                            + "native spatial reference system: " + nativeCrs);
                      } else {
                        targetSRSCode = "EPSG:" + code;
                        srs = CRS.decode(targetSRSCode, true);
                      }
                    } catch (Exception e) {
                      throw new ProcessException("Failed to loookup an official EPSG code for "
                          + "the source data native " + "spatial reference system", e);
                    }
                  }
                }
              }
             
              MathTransform tx = CRS.findMathTransform(cvCrs, srs);
             
              if (!tx.isIdentity() || !CRS.equalsIgnoreMetadata(cvCrs, srs))
              {
                coverage = WCSUtils.resample(coverage, cvCrs, srs, null, Interpolation.getInstance(Interpolation.INTERP_NEAREST));
              }
             
              GeoTiffWriter writer = new GeoTiffWriter(file);

                // setting the write parameters for this geotiff
                final ParameterValueGroup params = new GeoTiffFormat().getWriteParameters();
                params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(
                        DEFAULT_WRITE_PARAMS);
                final GeneralParameterValue[] wps = (GeneralParameterValue[]) params.values().toArray(
                        new GeneralParameterValue[1]);
               
                try {
                    writer.write(coverage, wps);
                } finally {
                    try {
                        writer.dispose();
                    } catch (Exception e) {
                        // we tried, no need to fuss around this one
                    }
                }
               
                //add or update the datastore info
                if ( add ) {
                    catalog.add( (CoverageStoreInfo)storeInfo );
                }
                else {
                    catalog.save( (CoverageStoreInfo)storeInfo );
                }
               
                cb.setStore( (CoverageStoreInfo)storeInfo );
               
                GridCoverage2DReader reader = new GeoTiffReader(file);
                if ( reader == null ) {
                    throw new ProcessException( "Could not aquire reader for coverage." );
                }
               
                // coverage read params
                final Map customParameters = new HashMap();
                /*String useJAIImageReadParam = "USE_JAI_IMAGEREAD";
                if (useJAIImageReadParam != null) {
                  customParameters.put(AbstractGridFormat.USE_JAI_IMAGEREAD.getName().toString(), Boolean.valueOf(useJAIImageReadParam));
                }*/
               
                CoverageInfo cinfo = cb.buildCoverage( reader, customParameters );
               
                //check if the name of the coverage was specified
                if ( name != null ) {
                    cinfo.setName( name );
                }
               
                if ( !add ) {
                    //update the existing
                    CoverageInfo existing = catalog.getCoverageByCoverageStore((CoverageStoreInfo) storeInfo, name != null ? name : coverage.getName().toString() );
                    if ( existing == null ) {
                        //grab the first if there is only one
                        List<CoverageInfo> coverages = catalog.getCoveragesByCoverageStore( (CoverageStoreInfo) storeInfo );
                        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 ProcessException( "Unable to determine coverage to configure.");
                        }
                    }
                   
                    if ( existing != null ) {
                        cb.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 = cb.buildLayer( cinfo );
                    if ( styleName != null && targetStyle != null ) {
                      layerInfo.setDefaultStyle( targetStyle );
                    }
                    //JD: commenting this out, these sorts of edits should be handled
                    // with a second PUT request on the created coverage
View Full Code Here

                    throw new RestletException( "Can't change the workspace of a style, instead " +
                        "DELETE from existing workspace and POST to new workspace", Status.CLIENT_ERROR_FORBIDDEN );
                }
            }
           
            new CatalogBuilder( catalog ).updateStyle( original, s );
            catalog.save( original );
        }
        else if (object instanceof Style || object instanceof InputStream) {
            /*
             * Force the .sld file to be overriden and it's Style object cleared from the
View Full Code Here

       
        sourceDataStoreFormat = sourceDataStoreFormat.toLowerCase();
        targetDataStoreFormat = targetDataStoreFormat.toLowerCase();
       
        //create a builder to help build catalog objects
        CatalogBuilder builder = new CatalogBuilder(catalog);
        builder.setWorkspace( catalog.getWorkspaceByName( workspace ) );
       
        //does the target datastore already exist?
        DataStoreInfo info = catalog.getDataStoreByName( workspace, datastore );

        // set the namespace uri
        NamespaceInfo namespace = catalog.getNamespaceByPrefix( workspace );

        boolean add = false;
        boolean save = false;
        boolean canRemoveFiles = false;
       
        String charset = form.getFirstValue("charset");
       
        if (info == null) {
            LOGGER.info("Auto-configuring datastore: " + datastore);
           
            info = builder.buildDataStore( datastore );
            add = true;
           
            //TODO: should check if the store actually supports charset
            if (charset != null && charset.length() > 0) {
                info.getConnectionParameters().put("charset", charset);
            }
            DataStoreFactorySpi targetFactory = factory;
            if (!targetDataStoreFormat.equals(sourceDataStoreFormat)) {
                //target is different, we need to create it
                targetFactory = lookupDataStoreFactory(targetDataStoreFormat);
                if (targetFactory == null) {
                    throw new RestletException( "Unable to create data store of type "
                        + targetDataStoreFormat, Status.CLIENT_ERROR_BAD_REQUEST );
                }
               
                autoCreateParameters(info, namespace, targetFactory);
                canRemoveFiles = true;
            }
            else {
                updateParameters(info, namespace, targetFactory, uploadedFile);
            }
           
            info.setType(targetFactory.getDisplayName());
        }
        else {
            LOGGER.info("Using existing datastore: " + datastore);
           
            // look up the target data store factory
            targetDataStoreFormat = lookupDataStoreFactoryFormat(info.getType());
            if (targetDataStoreFormat == null) {
                throw new RuntimeException("Unable to locate data store factory of type " + info.getType());
            }
           
            if (targetDataStoreFormat.equals(sourceDataStoreFormat)) {
                save = true;
                updateParameters(info, namespace, factory, uploadedFile);
            }
            else {
                canRemoveFiles = true;
            }
        }
        builder.setStore(info);
       
        //add or update the datastore info
        if ( add ) {
            catalog.validate(info, true).throwIfInvalid();
            catalog.add( info );
        }
        else {
            if (save) {
                catalog.validate(info, false).throwIfInvalid();
                catalog.save( info );
            }
        }
       
        //create an instanceof the source datastore
        HashMap params = new HashMap();
        if (charset != null && charset.length() > 0) {
            params.put("charset",charset)
        }
        updateParameters(params, factory, uploadedFile);
        DataStore source;
        try {
            source = factory.createDataStore(params);
        } catch (IOException e) {
            throw new RuntimeException("Unable to create source data store", e);
        }
       
        try {
            DataStore ds = (DataStore) info.getDataStore(null);
            //synchronized(ds) {
            //if it is the case that the source does not match the target we need to
            // copy the data into the target
            if (!targetDataStoreFormat.equals(sourceDataStoreFormat)) {
                //copy over the feature types
                for (String featureTypeName : source.getTypeNames()) {
                    SimpleFeatureType featureType = null;
                   
                    //does the feature type already exist in the target?
                    try {
                        featureType = ds.getSchema(featureTypeName);
                    }
                    catch(Exception e) {
                        LOGGER.info(featureTypeName + " does not exist in data store " + datastore +
                            ". Attempting to create it");
                       
                        //schema does not exist, create it by first creating an instance of
                        // the source datastore and copying over its schema
                        ds.createSchema(source.getSchema(featureTypeName));
                        featureType = source.getSchema(featureTypeName);
                    }
   
                    FeatureSource featureSource = ds.getFeatureSource(featureTypeName);
                    if (!(featureSource instanceof FeatureStore)) {
                        LOGGER.warning(featureTypeName + " is not writable, skipping");
                        continue;
                    }
                   
                    Transaction tx = new DefaultTransaction();
                    FeatureStore featureStore = (FeatureStore) featureSource;
                    featureStore.setTransaction(tx);
                   
                    try {
                        //figure out update mode, whether we should kill existing data or append
                        String update = form.getFirstValue("update");
                        if ("overwrite".equalsIgnoreCase(update)) {
                            LOGGER.fine("Removing existing features from " + featureTypeName);
                            //kill all features
                            featureStore.removeFeatures(Filter.INCLUDE);
                        }
                       
                        LOGGER.fine("Adding features to " + featureTypeName);
                        FeatureCollection features = source.getFeatureSource(featureTypeName).getFeatures();
                        featureStore.addFeatures(features);
                       
                        tx.commit();
                    }
                    catch(Exception e) {
                        tx.rollback();
                    }
                    finally {
                        tx.close();
                    }
                }
            }

            //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 target datastore
            //DataStore ds = (DataStore) info.getDataStore(null);
            Map<String, FeatureTypeInfo> featureTypesByNativeName =
                new HashMap<String, FeatureTypeInfo>();
            for (FeatureTypeInfo ftInfo : catalog.getFeatureTypesByDataStore(info)) {
                featureTypesByNativeName.put(ftInfo.getNativeName(), ftInfo);
            }
           
            String[] featureTypeNames = source.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 = featureTypesByNativeName.get(featureTypeNames[i]);
               
                if ( ftinfo == null) {
                    //auto configure the feature type as well
                    ftinfo = builder.buildFeatureType(fs);
                    builder.lookupSRS(ftinfo, true);
                    builder.setupBounds(ftinfo);
                }
               
                //update the bounds
                ReferencedEnvelope bounds = fs.getBounds();
                ftinfo.setNativeBoundingBox( bounds );
               
                //TODO: set lat lon bounding box
               
                if ( ftinfo.getId() == null ) {
                   
                    //do a check for a type already named this name in the catalog, if it is already
                    // there try to rename it
                    if (catalog.getFeatureTypeByName(namespace, ftinfo.getName()) != null) {
                        LOGGER.warning(String.format("Feature type %s already exists in namespace %s, " +
                            "attempting to rename", ftinfo.getName(), namespace.getPrefix()));
                        int x = 1;
                        String originalName = ftinfo.getName();
                        do {
                            ftinfo.setName(originalName + i);
                            i++;
                        }
                        while(i < 10 && catalog.getFeatureTypeByName(namespace, ftinfo.getName()) != null);
                    }
                    catalog.validate(ftinfo, true).throwIfInvalid();
                    catalog.add( ftinfo );
                   
                    //add a layer for the feature type as well
                    LayerInfo layer = builder.buildLayer(ftinfo);

                    boolean valid = true;
                    try {
                        if (!catalog.validate(layer, true).isValid()) {
                            valid = false;
View Full Code Here

            ns = catalog.getNamespaceByPrefix( workspace );
            wml.setNamespace( ns );
        }
       
        // fill in missing information
        CatalogBuilder cb = new CatalogBuilder(catalog);
        cb.setStore(wms);
        cb.initWMSLayer( wml );
       
        wml.setEnabled(true);
        catalog.validate(wml, true).throwIfInvalid();
        catalog.add( wml );
       
        // create a layer for the feature type
        catalog.add(new CatalogBuilder(catalog).buildLayer(wml));
       
        LOGGER.info( "POST wms layer " + wmsstore + "," + wml.getName() );
        return wml.getName();
    }
View Full Code Here

        String wmsstore = getAttribute("wmsstore");
        String wmslayer = getAttribute("wmslayer");
       
        WMSStoreInfo wms = catalog.getStoreByName(workspace, wmsstore, WMSStoreInfo.class);
        WMSLayerInfo original = catalog.getResourceByStore( wms,  wmslayer, WMSLayerInfo.class );
        new CatalogBuilder(catalog).updateWMSLayer(original,wml);
        catalog.validate(original, false).throwIfInvalid();
        catalog.save( original );
       
        LOGGER.info( "PUT wms layer " + wmsstore + "," + wmslayer );
    }
View Full Code Here

            CoverageStoreInfo ds = catalog.getCoverageStoreByName( workspace, coveragestore );
            coverage.setStore( ds );
        }
        final boolean isNew = isNewCoverage(coverage);
        String name = coverage.getName();
        CatalogBuilder builder = new CatalogBuilder(catalog);
        CoverageStoreInfo store = coverage.getStore();
        builder.setStore(store);

        // We handle 2 different cases here
        if (!isNew) {
            // Configuring a partially defined coverage
            builder.initCoverage(coverage, name);
        } else {
            // Configuring a brand new coverage (only name has been specified)
            coverage = builder.buildCoverage(name);
        }

        NamespaceInfo ns = coverage.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 );
            coverage.setNamespace( ns );
        }
       
        coverage.setEnabled(true);
        catalog.validate(coverage, true).throwIfInvalid();
        catalog.add( coverage );
       
        //create a layer for the coverage
        catalog.add(builder.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);
        calculateOptionalFields(c, original);
        catalog.validate(original, false).throwIfInvalid();
        catalog.save( original );
       
        clear(original);
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.