Search in sources :

Example 1 with Event

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

the class MongoGeoTemporalIndexIT method ensureInEventStore_Test.

@Test
public void ensureInEventStore_Test() throws Exception {
    final Sail sail = GeoRyaSailFactory.getInstance(conf);
    final SailRepository repo = new SailRepository(sail);
    try (final MongoGeoTemporalIndexer indexer = new MongoGeoTemporalIndexer()) {
        indexer.setConf(conf);
        indexer.init();
        addStatements(repo.getConnection());
        final EventStorage events = indexer.getEventStorage();
        final RyaURI subject = new RyaURI("urn:event1");
        final Optional<Event> event = events.get(subject);
        assertTrue(event.isPresent());
    } finally {
        sail.shutDown();
    }
}
Also used : MongoGeoTemporalIndexer(org.apache.rya.indexing.geotemporal.mongo.MongoGeoTemporalIndexer) RyaURI(org.apache.rya.api.domain.RyaURI) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) Event(org.apache.rya.indexing.geotemporal.model.Event) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 2 with Event

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

the class MongoGeoTemporalIndexerIT method ensureEvent.

@Test
public void ensureEvent() throws Exception {
    final RyaStatement geoStmnt = statement(point(0, 0));
    final RyaStatement timeStmnt = statement(makeInstant(0));
    final EventStorage store = indexer.getEventStorage();
    indexer.storeStatement(geoStmnt);
    Optional<Event> evnt = store.get(geoStmnt.getSubject());
    assertTrue(evnt.isPresent());
    Event expected = Event.builder().setSubject(geoStmnt.getSubject()).setGeometry(point(0, 0)).build();
    assertEquals(expected, evnt.get());
    indexer.storeStatement(timeStmnt);
    evnt = store.get(timeStmnt.getSubject());
    assertTrue(evnt.isPresent());
    expected = Event.builder().setSubject(geoStmnt.getSubject()).setGeometry(point(0, 0)).setTemporalInstant(makeInstant(0)).build();
    assertEquals(expected, evnt.get());
    indexer.deleteStatement(geoStmnt);
    evnt = store.get(timeStmnt.getSubject());
    assertTrue(evnt.isPresent());
    expected = Event.builder().setSubject(timeStmnt.getSubject()).setTemporalInstant(makeInstant(0)).build();
    assertEquals(expected, evnt.get());
    indexer.deleteStatement(timeStmnt);
    evnt = store.get(timeStmnt.getSubject());
    assertTrue(evnt.isPresent());
    expected = Event.builder().setSubject(timeStmnt.getSubject()).build();
    assertEquals(expected, evnt.get());
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Event(org.apache.rya.indexing.geotemporal.model.Event) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 3 with Event

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

the class EventDocumentConverterTest method to_and_from_document.

@Test
public void to_and_from_document() throws DocumentConverterException {
    final Geometry geo = GF.createPoint(new Coordinate(10, 10));
    final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
    // An Event that will be stored.
    final Event event = Event.builder().setSubject(new RyaURI("urn:event/001")).setGeometry(geo).setTemporalInstant(instant).build();
    final Document document = new EventDocumentConverter().toDocument(event);
    // Convert the Document back into an Event.
    final Event converted = new EventDocumentConverter().fromDocument(document);
    // Ensure the original matches the round trip converted Event.
    assertEquals(event, converted);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Event(org.apache.rya.indexing.geotemporal.model.Event) EventDocumentConverter(org.apache.rya.indexing.geotemporal.mongo.EventDocumentConverter) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Document(org.bson.Document) Test(org.junit.Test)

Example 4 with Event

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

the class MongoEventStorageIT method create_and_get.

@Test
public void create_and_get() throws Exception {
    final Geometry geo = GF.createPoint(new Coordinate(10, 10));
    final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
    // An Event that will be stored.
    final Event event = Event.builder().setSubject(new RyaURI("urn:event/001")).setGeometry(geo).setTemporalInstant(instant).build();
    // Create it.
    final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.create(event);
    // Get it.
    final Optional<Event> storedEvent = storage.get(new RyaURI("urn:event/001"));
    // Verify the correct value was returned.
    assertEquals(event, storedEvent.get());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Event(org.apache.rya.indexing.geotemporal.model.Event) TemporalInstant(org.apache.rya.indexing.TemporalInstant) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 5 with Event

use of org.apache.rya.indexing.geotemporal.model.Event 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

Event (org.apache.rya.indexing.geotemporal.model.Event)12 RyaURI (org.apache.rya.api.domain.RyaURI)10 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)9 Test (org.junit.Test)9 TemporalInstant (org.apache.rya.indexing.TemporalInstant)8 TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)8 Coordinate (com.vividsolutions.jts.geom.Coordinate)7 Geometry (com.vividsolutions.jts.geom.Geometry)7 Document (org.bson.Document)3 TemporalInterval (org.apache.rya.indexing.TemporalInterval)2 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 DBObject (com.mongodb.DBObject)1 MongoException (com.mongodb.MongoException)1 CoordinateList (com.vividsolutions.jts.geom.CoordinateList)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 LinearRing (com.vividsolutions.jts.geom.LinearRing)1 ParseException (com.vividsolutions.jts.io.ParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1