Search in sources :

Example 1 with GeoWavePluginException

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);
    }
}
Also used : GeoWavePluginConfig(org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginConfig) ContentFeatureCollection(org.geotools.data.store.ContentFeatureCollection) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) GeoWavePluginException(org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginException) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) GeoWaveGTDataStore(org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore) FeatureProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureProtos) StoreLoader(org.locationtech.geowave.core.store.cli.store.StoreLoader) ParameterException(com.beust.jcommander.ParameterException) FeatureAttributeProtos(org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos) CQLException(org.geotools.filter.text.cql2.CQLException)

Aggregations

ParameterException (com.beust.jcommander.ParameterException)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 ContentFeatureCollection (org.geotools.data.store.ContentFeatureCollection)1 CQLException (org.geotools.filter.text.cql2.CQLException)1 GeoWaveGTDataStore (org.locationtech.geowave.adapter.vector.plugin.GeoWaveGTDataStore)1 GeoWavePluginConfig (org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginConfig)1 GeoWavePluginException (org.locationtech.geowave.adapter.vector.plugin.GeoWavePluginException)1 StoreLoader (org.locationtech.geowave.core.store.cli.store.StoreLoader)1 FeatureAttributeProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureAttributeProtos)1 FeatureProtos (org.locationtech.geowave.service.grpc.protobuf.FeatureProtos)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1 Filter (org.opengis.filter.Filter)1