Search in sources :

Example 1 with FeatureMapUpdate

use of org.geotoolkit.storage.FeatureMapUpdate in project geotoolkit by Geomatys.

the class WFSFeatureSet method replaceIf.

@Override
public void replaceIf(Predicate<? super Feature> filter, UnaryOperator<Feature> updater) throws DataStoreException {
    if (!(filter instanceof Filter)) {
        throw new DataStoreException("Predicate filter must be an instance of org.opengis.filter.Filter");
    }
    if (!(updater instanceof FeatureMapUpdate)) {
        throw new DataStoreException("Predicate filter must be an instance of org.opengis.filter.Filter");
    }
    final FeatureType featureType = getType();
    final FeatureMapUpdate map = (FeatureMapUpdate) updater;
    final TransactionRequest request = store.createTransaction();
    final Update update = store.createUpdateElement();
    update.setInputFormat("text/xml; subtype=\"gml/3.1.1\"");
    update.setFilter((Filter) filter);
    update.setTypeName(featureType.getName());
    for (Map.Entry<String, ? extends Object> entry : map.getValues().entrySet()) {
        update.updates().put(featureType.getProperty(entry.getKey()), entry.getValue());
    }
    request.elements().add(update);
    try {
        final InputStream response = request.getResponseStream();
        response.close();
    // TODO send event
    } catch (IOException ex) {
        throw new DataStoreException(ex);
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) Filter(org.opengis.filter.Filter) InputStream(java.io.InputStream) FeatureMapUpdate(org.geotoolkit.storage.FeatureMapUpdate) IOException(java.io.IOException) FeatureMapUpdate(org.geotoolkit.storage.FeatureMapUpdate) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 FeatureMapUpdate (org.geotoolkit.storage.FeatureMapUpdate)1 FeatureType (org.opengis.feature.FeatureType)1 Filter (org.opengis.filter.Filter)1