Commit 84009c63 authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-7195] WFS SHAPE-ZIP output does not always honor field lenght restrictions

parent c0ef2c2a
......@@ -6,6 +6,7 @@
package org.geoserver.wfs.response;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.geotools.data.simple.SimpleFeatureCollection;
......@@ -17,6 +18,7 @@ import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.GeometryDescriptor;
import org.opengis.filter.Filter;
/**
* FeatureCollection that remaps attribute names using a given map.
*
......@@ -62,8 +64,13 @@ public class RemappingFeatureCollection extends DecoratingSimpleFeatureCollectio
if(attDesc instanceof GeometryDescriptor) {
GeometryDescriptor geoDesc=(GeometryDescriptor)attDesc;
builder.add(attributesMapping.get(attDesc.getLocalName()),attDesc.getType().getBinding(),geoDesc.getCoordinateReferenceSystem());
} else
} else {
List<Filter> filters = attDesc.getType().getRestrictions();
if (filters != null && !filters.isEmpty()) {
builder.restrictions(filters);
}
builder.add(attributesMapping.get(attDesc.getLocalName()),attDesc.getType().getBinding());
}
}
return builder.buildFeatureType();
}
......
/* (c) 2015 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.wfs.response;
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import org.geotools.data.collection.ListFeatureCollection;
import org.geotools.feature.AttributeTypeBuilder;
import org.geotools.feature.FeatureTypes;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.junit.Test;
import org.opengis.feature.simple.SimpleFeatureType;
import com.vividsolutions.jts.geom.Point;
public class RemappingFeatureCollectionTest {
@Test
public void testPreserveRestrictions() throws Exception {
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
AttributeTypeBuilder ab = new AttributeTypeBuilder();
tb.add("geom", Point.class);
ab.setName("name");
ab.setBinding(String.class);
ab.setLength(20);
tb.add(ab.buildDescriptor("name"));
tb.setName("testType");
SimpleFeatureType original = tb.buildFeatureType();
int length = FeatureTypes.getFieldLength(original.getDescriptor("name"));
assertEquals(20, length);
ListFeatureCollection fc = new ListFeatureCollection(original);
RemappingFeatureCollection remapped = new RemappingFeatureCollection(fc,
Collections.singletonMap("name", "xyz"));
int remappedLength = FeatureTypes.getFieldLength(remapped.getSchema().getDescriptor("xyz"));
assertEquals(20, remappedLength);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment