Search in sources :

Example 1 with GeoTemporalIndexException

use of org.apache.rya.indexing.geotemporal.GeoTemporalIndexException in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategy method getGeoObjs.

private DBObject[] getGeoObjs(final Collection<IndexingExpr> geoFilters) {
    final List<DBObject> objs = new ArrayList<>();
    geoFilters.forEach(filter -> {
        final GeoPolicy policy = GeoPolicy.fromURI(filter.getFunction());
        final WKTReader reader = new WKTReader();
        final String geoStr = ((Value) filter.getArguments()[0]).stringValue();
        try {
            // This method is what is used in the GeoIndexer.
            final Geometry geo = reader.read(geoStr);
            objs.add(getGeoObject(geo, policy));
        } catch (final GeoTemporalIndexException | UnsupportedOperationException | ParseException e) {
            LOG.error("Unable to parse '" + geoStr + "'.", e);
        }
    });
    return objs.toArray(new DBObject[] {});
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeoPolicy(org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.GeoPolicy) GeoTemporalIndexException(org.apache.rya.indexing.geotemporal.GeoTemporalIndexException) ArrayList(java.util.ArrayList) Value(org.openrdf.model.Value) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 2 with GeoTemporalIndexException

use of org.apache.rya.indexing.geotemporal.GeoTemporalIndexException in project incubator-rya by apache.

the class MongoEventStorage method search.

@Override
public Collection<Event> search(final Optional<RyaURI> subject, final Optional<Collection<IndexingExpr>> geoFilters, final Optional<Collection<IndexingExpr>> temporalFilters) throws EventStorageException {
    requireNonNull(subject);
    try {
        final Collection<IndexingExpr> geos = (geoFilters.isPresent() ? geoFilters.get() : new ArrayList<>());
        final Collection<IndexingExpr> tempos = (temporalFilters.isPresent() ? temporalFilters.get() : new ArrayList<>());
        final DBObject filterObj = queryAdapter.getFilterQuery(geos, tempos);
        final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(filterObj.toMap());
        if (subject.isPresent()) {
            builder.append(EventDocumentConverter.SUBJECT, subject.get().getData());
        }
        final MongoCursor<Document> results = mongo.getDatabase(ryaInstanceName).getCollection(COLLECTION_NAME).find(BsonDocument.parse(builder.get().toString())).iterator();
        final List<Event> events = new ArrayList<>();
        while (results.hasNext()) {
            events.add(EVENT_CONVERTER.fromDocument(results.next()));
        }
        return events;
    } catch (final MongoException | DocumentConverterException | GeoTemporalIndexException e) {
        throw new EventStorageException("Could not get the Event.", e);
    }
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) MongoException(com.mongodb.MongoException) ArrayList(java.util.ArrayList) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) DBObject(com.mongodb.DBObject) DocumentConverterException(org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException) GeoTemporalIndexException(org.apache.rya.indexing.geotemporal.GeoTemporalIndexException) Event(org.apache.rya.indexing.geotemporal.model.Event) IndexingExpr(org.apache.rya.indexing.IndexingExpr)

Aggregations

DBObject (com.mongodb.DBObject)2 ArrayList (java.util.ArrayList)2 GeoTemporalIndexException (org.apache.rya.indexing.geotemporal.GeoTemporalIndexException)2 BasicDBObject (com.mongodb.BasicDBObject)1 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 MongoException (com.mongodb.MongoException)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 ParseException (com.vividsolutions.jts.io.ParseException)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 IndexingExpr (org.apache.rya.indexing.IndexingExpr)1 DocumentConverterException (org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException)1 GeoPolicy (org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.GeoPolicy)1 Event (org.apache.rya.indexing.geotemporal.model.Event)1 BsonDocument (org.bson.BsonDocument)1 Document (org.bson.Document)1 Value (org.openrdf.model.Value)1