use of org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginException in project geowave by locationtech.
the class GeoWaveGrpcVectorService method vectorQuery.
@Override
public void vectorQuery(final VectorQueryParametersProtos request, final StreamObserver<FeatureProtos> responseObserver) {
final String storeName = request.getStoreName();
final StoreLoader storeLoader = new StoreLoader(storeName);
// first check to make sure the data store exists
if (!storeLoader.loadFromConfig(GeoWaveGrpcServiceOptions.geowaveConfigFile)) {
throw new ParameterException("Cannot find store name: " + storeLoader.getStoreName());
}
GeoWaveGTDataStore gtStore = null;
try {
gtStore = new GeoWaveGTDataStore(new GeoWavePluginConfig(storeLoader.getDataStorePlugin()));
} catch (final IOException | GeoWavePluginException e) {
LOGGER.error("Exception encountered instantiating GeoWaveGTDataStore", e);
responseObserver.onError(e);
}
Filter filter = null;
try {
filter = ECQL.toFilter(request.getQuery());
} catch (final CQLException e) {
LOGGER.error("Exception encountered creating filter from CQL", e);
responseObserver.onError(e);
}
ContentFeatureCollection featureCollection = null;
try {
final String typeName = request.getTypeName();
featureCollection = gtStore.getFeatureSource(typeName).getFeatures(filter);
} catch (final IOException | NullPointerException e) {
LOGGER.error("Exception encountered getting feature collection", e);
responseObserver.onError(e);
}
try (final SimpleFeatureIterator iterator = featureCollection.features()) {
while (iterator.hasNext()) {
final SimpleFeature simpleFeature = iterator.next();
final SimpleFeatureType type = simpleFeature.getType();
final FeatureProtos.Builder b = FeatureProtos.newBuilder();
final FeatureAttributeProtos.Builder attBuilder = FeatureAttributeProtos.newBuilder();
for (int i = 0; i < type.getAttributeDescriptors().size(); i++) {
setAttributeBuilderValue(simpleFeature.getAttribute(i), attBuilder);
b.putAttributes(type.getAttributeDescriptors().get(i).getLocalName(), attBuilder.build());
/*
* b.putAttributes( type.getAttributeDescriptors().get( i).getLocalName(),
* simpleFeature.getAttribute(i) == null ? "" : simpleFeature.getAttribute(
* i).toString());
*/
}
final FeatureProtos f = b.build();
responseObserver.onNext(f);
}
responseObserver.onCompleted();
} catch (final NullPointerException e) {
LOGGER.error("Exception encountered", e);
responseObserver.onError(e);
}
}
Aggregations