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();
}
}
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());
}
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);
}
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());
}
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);
}
}
Aggregations