use of org.locationtech.geogig.api.data.ForwardingFeatureSource in project GeoGig by boundlessgeo.
the class ImportOp method getFeatureSource.
@SuppressWarnings({ "rawtypes", "unchecked" })
private FeatureSource getFeatureSource(String typeName) {
FeatureSource featureSource;
try {
featureSource = dataStore.getFeatureSource(typeName);
} catch (Exception e) {
throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_FEATURES);
}
return new ForwardingFeatureSource(featureSource) {
@Override
public FeatureCollection getFeatures(Query query) throws IOException {
final FeatureCollection features = super.getFeatures(query);
return new ForwardingFeatureCollection(features) {
@Override
public FeatureIterator features() {
final FeatureType featureType = getSchema();
final String fidPrefix = featureType.getName().getLocalPart() + ".";
FeatureIterator iterator = delegate.features();
return new FidAndFtReplacerIterator(iterator, fidAttribute, fidPrefix, (SimpleFeatureType) featureType);
}
};
}
};
}
use of org.locationtech.geogig.api.data.ForwardingFeatureSource in project GeoGig by boundlessgeo.
the class WorkingTreeTest method testInsertPagingFeatureSource.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInsertPagingFeatureSource() throws Exception {
assertEquals(2, super.getGeogig().getPlatform().availableProcessors());
final List<SimpleFeature> features = ImmutableList.of((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3);
MemoryDataStore store = new MemoryDataStore();
store.addFeatures(features);
final QueryCapabilities caps = mock(QueryCapabilities.class);
when(caps.isOffsetSupported()).thenReturn(true);
FeatureSource source = new ForwardingFeatureSource(store.getFeatureSource(pointsName)) {
@Override
public QueryCapabilities getQueryCapabilities() {
return caps;
}
@Override
public FeatureCollection getFeatures(Query query) throws IOException {
Integer startIndex = query.getStartIndex();
if (startIndex == null) {
return super.getFeatures();
}
int toIndex = (int) Math.min((long) startIndex + query.getMaxFeatures(), features.size());
List<SimpleFeature> result = features.subList(startIndex, toIndex);
return DataUtilities.collection(result);
}
};
assertTrue(source.getQueryCapabilities().isOffsetSupported());
String treePath = "target_typename";
workTree.insert(treePath, source, Query.ALL, LISTENER);
assertEquals(3, workTree.countUnstaged(treePath).featureCount());
}
Aggregations