Package org.geoserver.catalog

Examples of org.geoserver.catalog.FeatureTypeInfo


        }

        @Override
        protected Object load() {
            try {
                FeatureTypeInfo fti = (FeatureTypeInfo) featureTypeInfo.getObject();
                List<String> result = new ArrayList<String>();
                for (PropertyDescriptor property :  fti.getFeatureType().getDescriptors()) {
                    result.add(property.getName().getLocalPart());
                }
                Collections.sort(result);
                return result;
            } catch(IOException e) {
View Full Code Here


            //ns set to null, if all given types are from the same namespace, us that one
            if ( !types.isEmpty() ) {
                Iterator<FeatureTypeInfo> i = types.iterator();
                NamespaceInfo namespace = i.next().getNamespace();
                while( i.hasNext() ) {
                    FeatureTypeInfo type = i.next();
                    if ( !namespace.equals( type.getNamespace() ) ) {
                        namespace = null;
                        break;
                    }
                }
               
View Full Code Here

               
                // may have multiple type names in each query, so add them all
                for (QName name : (List<QName>) queryType.getTypeName()) {
                    // get a feature type name from the query
                    Name featureTypeName = new NameImpl(name.getNamespaceURI(), name.getLocalPart());
                    FeatureTypeInfo meta = catalog.getFeatureTypeByName(featureTypeName);
                   
                    if (meta == null) {
                        throw new WFSException("Could not find feature type " + featureTypeName
                                + " in the GeoServer catalog");
                    }
                   
                    // add it to the map
                    Set<FeatureTypeInfo> metas = ns2metas.get(featureTypeName.getNamespaceURI());
                   
                    if (metas == null) {
                        metas = new HashSet<FeatureTypeInfo>();
                        ns2metas.put(featureTypeName.getNamespaceURI(), metas);
                    }
                    metas.add(meta);
                }
            } else {
                FeatureType featureType = ((FeatureCollection) featureCollections.get(fcIndex)).getSchema();

                //load the metadata for the feature type
                String namespaceURI = featureType.getName().getNamespaceURI();
                FeatureTypeInfo meta = catalog.getFeatureTypeByName(featureType.getName());
               
                if(meta == null)
                    throw new WFSException("Could not find feature type " + featureType.getName() + " in the GeoServer catalog");

                //add it to the map
                Set metas = (Set) ns2metas.get(namespaceURI);

                if (metas == null) {
                    metas = new HashSet();
                    ns2metas.put(namespaceURI, metas);
                }

                metas.add(meta);
            }
        }

        //set feature bounding parameter
        //JD: this is quite bad as its not at all thread-safe, once we remove the configuration
        // as being a singleton on trunk/2.0.x this should not be an issue
        if ( wfs.isFeatureBounding() ) {
            configuration.getProperties().remove( GMLConfiguration.NO_FEATURE_BOUNDS );
        }
        else {
            configuration.getProperties().add( GMLConfiguration.NO_FEATURE_BOUNDS);
        }
       
        Encoder encoder = new Encoder(configuration, configuration.schema());
        encoder.setEncoding(Charset.forName( global.getCharset() ));

        //declare wfs schema location
        BaseRequestType gft = (BaseRequestType)getFeature.getParameters()[0];
       
        if (wfs.isCanonicalSchemaLocation()) {
            encoder.setSchemaLocation(org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE,
                    WFS.CANONICAL_SCHEMA_LOCATION);
        } else {
            encoder.setSchemaLocation(org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE,
                    buildSchemaURL(gft.getBaseUrl(), "wfs/1.1.0/wfs.xsd"));
        }

        //declare application schema namespaces
        Map<String, String> params = params("service", "WFS", "version", "1.1.0", "request", "DescribeFeatureType");
        for (Iterator i = ns2metas.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();

            String namespaceURI = (String) entry.getKey();
            Set metas = (Set) entry.getValue();

            StringBuffer typeNames = new StringBuffer();

            String userSchemaLocation = null;
            for (Iterator m = metas.iterator(); m.hasNext();) {
                FeatureTypeInfo meta = (FeatureTypeInfo) m.next();
                if (userSchemaLocation == null) {
                    FeatureType featureType = meta.getFeatureType();
                    Object schemaUri = featureType.getUserData().get("schemaURI");
                    if (schemaUri != null) {
                        userSchemaLocation = schemaUri.toString();
                    }
                }
                typeNames.append(meta.getPrefixedName());
               
                if (m.hasNext()) {
                    typeNames.append(",");
                }
            }
View Full Code Here

        List results = new ArrayList();
        try {
            for (int i = 0; (i < request.getQuery().size()) && (count < maxFeatures); i++) {
                QueryType query = (QueryType) request.getQuery().get(i);

                FeatureTypeInfo meta = null;

                if (query.getTypeName().size() == 1) {
                    meta = featureTypeInfo((QName) query.getTypeName().get(0));
                } else {
                    //TODO: a join is taking place
                }

                FeatureSource<? extends FeatureType, ? extends Feature> source = meta.getFeatureSource(null,null);

                List<AttributeTypeInfo> atts = meta.attributes();
                List attNames = new ArrayList( atts.size() );
                for ( AttributeTypeInfo att : atts ) {
                    attNames.add( att.getName() );
                }

                //make sure property names are cool
                List propNames = query.getPropertyName();

                for (Iterator iter = propNames.iterator(); iter.hasNext();) {
                    String propName = (String) iter.next();

                    //HACK: strip off namespace
                    if (propName.indexOf(':') != -1) {
                        propName = propName.substring(propName.indexOf(':') + 1);
                    }

                    if (!attNames.contains(propName)) {
                        String mesg = "Requested property: " + propName + " is " + "not available "
                            + "for " + query.getTypeName() + ".  " + "The possible propertyName "
                            + "values are: " + attNames;

                        throw new WFSException(mesg);
                    }
                }

                //we must also include any properties that are mandatory ( even if not requested ),
                // ie. those with minOccurs > 0
                List extraGeometries = new ArrayList();
                List properties = new ArrayList();
                if (propNames.size() != 0) {
                    Iterator ii = atts.iterator();

                    while (ii.hasNext()) {
                        AttributeTypeInfo ati = (AttributeTypeInfo) ii.next();
                        LOGGER.finer("checking to see if " + propNames + " contains" + ati);

                        if (((ati.getMinOccurs() > 0) && (ati.getMaxOccurs() != 0))) {
                            //mandatory, add it
                            properties.add(ati.getName());

                            continue;
                        }

                        //check if it was requested
                        for (Iterator p = propNames.iterator(); p.hasNext();) {
                            String propName = (String) p.next();

                            if (propName.matches("(\\w+:)?" + ati.getName())) {
                                properties.add(ati.getName());
                                break;
                            }
                        }
                       
                        // if we need to force feature bounds computation, we have to load
                        // all of the geometries, but we'll have to remove them in the
                        // returned feature type
                        if(wfs.isFeatureBounding() && meta.getFeatureType().getDescriptor(ati.getName()) instanceof GeometryDescriptor
                                && !properties.contains(ati.getName())) {
                            properties.add(ati.getName());
                            extraGeometries.add(ati.getName());
                        }
                    }

                    //replace property names
                    query.getPropertyName().clear();
                    query.getPropertyName().addAll(properties);
                }

                //make sure filters are sane
                //
                // Validation of filters on non-simple feature types is not yet supported.
                // FIXME: Support validation of filters on non-simple feature types:
                // need to consider xpath properties and how to configure namespace prefixes in
                // GeoTools app-schema FeaturePropertyAccessorFactory.
                if (query.getFilter() != null && source.getSchema() instanceof SimpleFeatureType) {
                   
                    //1. ensure any property name refers to a property that
                    // actually exists
                    final FeatureType featureType = source.getSchema();
                    ExpressionVisitor visitor = new AbstractExpressionVisitor() {
                            public Object visit(PropertyName name, Object data) {
                                // case of multiple geometries being returned
                                if (name.evaluate(featureType) == null) {
                                    throw new WFSException("Illegal property name: "
                                        + name.getPropertyName(), "InvalidParameterValue");
                                }

                                return name;
                            }
                            ;
                        };
                    query.getFilter().accept(new AbstractFilterVisitor(visitor), null);
                   
                    //2. ensure any spatial predicate is made against a property
                    // that is actually special
                    AbstractFilterVisitor fvisitor = new AbstractFilterVisitor() {
                     
                        protected Object visit( BinarySpatialOperator filter, Object data ) {
                            PropertyName name = null;
                            if ( filter.getExpression1() instanceof PropertyName ) {
                                name = (PropertyName) filter.getExpression1();
                            }
                            else if ( filter.getExpression2() instanceof PropertyName ) {
                                name = (PropertyName) filter.getExpression2();
                            }
                           
                            if ( name != null ) {
                                //check against fetaure type to make sure its
                                // a geometric type
                                AttributeDescriptor att = (AttributeDescriptor) name.evaluate(featureType);
                                if ( !( att instanceof GeometryDescriptor ) ) {
                                    throw new WFSException("Property " + name + " is not geometric", "InvalidParameterValue");
                                }
                            }
                           
                            return filter;
                        }
                    };
                    query.getFilter().accept(fvisitor, null);
                   
                    //3. ensure that any bounds specified as part of the query
                    // are valid with respect to the srs defined on the query
                    if ( wfs.isCiteCompliant() ) {
                       
                        if ( query.getSrsName() != null ) {
                            final QueryType fquery = query;
                            fvisitor = new AbstractFilterVisitor() {
                                public Object visit(BBOX filter, Object data) {
                                    if ( filter.getSRS() != null &&
                                            !fquery.getSrsName().toString().equals( filter.getSRS() ) ) {
                                       
                                        //back project bounding box into geographic coordinates
                                        CoordinateReferenceSystem geo = DefaultGeographicCRS.WGS84;
                                       
                                        GeneralEnvelope e = new GeneralEnvelope(
                                            new double[] { filter.getMinX(), filter.getMinY()},
                                            new double[] { filter.getMaxX(), filter.getMaxY()}
                                        );
                                        CoordinateReferenceSystem crs = null;
                                        try {
                                            crs = CRS.decode( filter.getSRS() );
                                            e = CRS.transform(CRS.findMathTransform(crs, geo, true), e);
                                        }
                                        catch( Exception ex ) {
                                            throw new WFSException( ex );
                                        }
                                       
                                        //ensure within bounds defined by srs specified on
                                        // query
                                        try {
                                            crs = CRS.decode( fquery.getSrsName().toString() );
                                        }
                                        catch( Exception ex ) {
                                            throw new WFSException( ex );
                                        }
                                       
                                        GeographicBoundingBox valid =
                                            (GeographicBoundingBox) crs.getDomainOfValidity()
                                            .getGeographicElements().iterator().next();
                                       
                                        if ( e.getMinimum(0) < valid.getWestBoundLongitude() ||
                                            e.getMinimum(0) > valid.getEastBoundLongitude() ||
                                            e.getMaximum(0) < valid.getWestBoundLongitude() ||
                                            e.getMaximum(0) > valid.getEastBoundLongitude() ||
                                            e.getMinimum(1) < valid.getSouthBoundLatitude() ||
                                            e.getMinimum(1) > valid.getNorthBoundLatitude() ||
                                            e.getMaximum(1) < valid.getSouthBoundLatitude() ||
                                            e.getMaximum(1) > valid.getNorthBoundLatitude() ) {
                                               
                                            throw new WFSException( "bounding box out of valid range of crs", "InvalidParameterValue");
                                        }
                                    }
                                   
                                    return data;
                                }
                            };
                           
                            query.getFilter().accept(fvisitor, null);
                        }
                    }  
                }

                // handle local maximum
                int queryMaxFeatures = maxFeatures - count;
                if(meta.getMaxFeatures() > 0 && meta.getMaxFeatures() < queryMaxFeatures)
                    queryMaxFeatures = meta.getMaxFeatures();
                org.geotools.data.Query gtQuery = toDataQuery(query, queryMaxFeatures, source, request);
               
                LOGGER.fine("Query is " + query + "\n To gt2: " + gtQuery);

                FeatureCollection<? extends FeatureType, ? extends Feature> features = getFeatures(request, source, gtQuery);
View Full Code Here

       
        return traverseXlinkDepth;
    }
   
    FeatureTypeInfo featureTypeInfo(QName name) throws WFSException, IOException {
        FeatureTypeInfo meta = catalog.getFeatureTypeByName(name.getNamespaceURI(), name.getLocalPart());

        if (meta == null) {
            String msg = "Could not locate " + name + " in catalog.";
            throw new WFSException(msg);
        }
View Full Code Here

        //get the feature
        SimpleFeature feature = (SimpleFeature) value;
        SimpleFeatureType featureType = feature.getType();
       
        //grab the metadata
        FeatureTypeInfo meta = catalog.getFeatureTypeByName(featureType.getName());
       
        //create teh encoder
        Encoder encoder = new Encoder( configuration );
        encoder.setEncoding(Charset.forName( wfs.getGeoServer().getGlobal().getCharset() ) );
        encoder.encode( feature,
            new QName( meta.getNamespace().getURI(), meta.getName()), output );
    }
View Full Code Here

        props.put(MockData.KEY_SRS_NUMBER, 3004);
        dataDirectory.addWellKnownType(MockData.LINES, props);
    }
   
    public void testForce() throws Exception {
        FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.BASIC_POLYGONS.getLocalPart());
        assertEquals("EPSG:4269", fti.getSRS());
        assertEquals(ProjectionPolicy.FORCE_DECLARED, fti.getProjectionPolicy());
        FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
        assertEquals(CRS.decode("EPSG:4269"), fc.getSchema().getCoordinateReferenceSystem());
        FeatureIterator fi = fc.features();
        Feature f = fi.next();
        fi.close();
        assertEquals(CRS.decode("EPSG:4269"), f.getType().getCoordinateReferenceSystem());
View Full Code Here

        fi.close();
        assertEquals(CRS.decode("EPSG:4269"), f.getType().getCoordinateReferenceSystem());
    }
   
    public void testReproject() throws Exception {
        FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.LAKES.getLocalPart());
        assertEquals("EPSG:3003", fti.getSRS());
        assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy());
        FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
        assertEquals(CRS.decode("EPSG:3003"), fc.getSchema().getCoordinateReferenceSystem());
        FeatureIterator fi = fc.features();
        Feature f = fi.next();
        fi.close();
        assertEquals(CRS.decode("EPSG:3003"), f.getType().getCoordinateReferenceSystem());
View Full Code Here

        fi.close();
        assertEquals(CRS.decode("EPSG:3003"), f.getType().getCoordinateReferenceSystem());
    }
   
    public void testLeaveNative() throws Exception {
        FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.LINES.getLocalPart());
        assertEquals("EPSG:3004", fti.getSRS());
        assertEquals(ProjectionPolicy.NONE, fti.getProjectionPolicy());
        FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
        assertEquals(CRS.decode("EPSG:32615"), fc.getSchema().getCoordinateReferenceSystem());
        FeatureIterator fi = fc.features();
        Feature f = fi.next();
        fi.close();
        assertEquals(CRS.decode("EPSG:32615"), f.getType().getCoordinateReferenceSystem());
View Full Code Here

        assertEquals(0, provider.size());

        provider.setShowPublished(true);
        assertEquals(numberOfPublishedResources, provider.size());

        FeatureTypeInfo typeInfo = resources.get(0);
        typeInfo.setName("notTheNativeName");
        catalog.save(typeInfo);

        provider = new NewLayerPageProvider();
        provider.setStoreId(cite.getId());
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.