Package org.geoserver.wfs.request

Examples of org.geoserver.wfs.request.Replace


    public Class getElementClass() {
        return Replace.class;
    }

    public QName[] getTypeNames(TransactionElement element) throws WFSTransactionException {
        Replace replace = (Replace) element;

        List<QName> typeNames = new ArrayList();
       
        List features = replace.getFeatures();
        if (!features.isEmpty()) {
            for (Iterator f = features.iterator(); f.hasNext();) {
                SimpleFeature feature = (SimpleFeature) f.next();

                String name = feature.getFeatureType().getTypeName();
View Full Code Here


    }

    public void execute(TransactionElement element, TransactionRequest request, Map featureStores,
        TransactionResponse response, TransactionListener listener) throws WFSTransactionException {

        Replace replace = (Replace) element;
       
        List<SimpleFeature> newFeatures = replace.getFeatures();
        SimpleFeatureStore featureStore =
                DataUtilities.simple((FeatureStore) featureStores.values().iterator().next());
        if (featureStore == null) {
            throw new WFSException(element, "Could not obtain feature store");
        }

        //check the supplied filter matches the number of supplied features
        String featureTypeName = featureStore.getSchema().getTypeName();
       
        //ids of replaced featres
        Collection<FeatureId> replaced = new ArrayList();

        try {
            Query query = new Query(featureTypeName, replace.getFilter());
           
            SimpleFeatureCollection features = featureStore.getFeatures(replace.getFilter());
            if (newFeatures.size() != features.size()) {
                throw new WFSException(element, String.format("Specified filter matched %d features but " +
                    "%d were supplied", features.size(), newFeatures.size()));
            }
   
            //replace the features in order...
            //JD, TODO: a better mechanism for replace... this is sort of a hack based on a combo of
            // feature ids and orders
            // may want to check if the store is making feature id's writable and attempt
            // to actually update the ID's
   
            //load all the existing features into memory
            Map<String,SimpleFeature> oldFeatures = new LinkedHashMap<String, SimpleFeature>();
           
           
            SimpleFeatureIterator it = features.features();
            try {
                while(it.hasNext()) {
                    SimpleFeature f = it.next();
                    oldFeatures.put(f.getID(), f);
                }
            }
            finally {
                it.close();
            }

            //first pass update all the features that match by id
            List<SimpleFeature> leftovers = new ArrayList();
           
           
            for (SimpleFeature newFeature : newFeatures) {
                SimpleFeature oldFeature = oldFeatures.get(newFeature.getID());
                if (oldFeature == null) {
                    leftovers.add(newFeature);
                    continue;
                }

                //matching feature found, update it
                replace(oldFeature, newFeature, featureStore, oldFeatures, replaced);

            }

            //do left overs
            for (SimpleFeature newFeature : leftovers) {
                //grab the "next" old feature
                SimpleFeature oldFeature = oldFeatures.values().iterator().next();
                replace(oldFeature, newFeature, featureStore, oldFeatures, replaced);
            }
        }
        catch(IOException e) {
            throw new WFSException(element, "Transaction REPLACE failed", e);
        }

        response.setTotalReplaced(BigInteger.valueOf(replaced.size()));
        response.addReplacedFeatures(replace.getHandle(), replaced);
     }
View Full Code Here

TOP

Related Classes of org.geoserver.wfs.request.Replace

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.