use of org.apache.rya.indexing.geotemporal.storage.EventStorage in project incubator-rya by apache.
the class MongoEventStorageIT method delete_nonExisting.
@Test
public void delete_nonExisting() throws Exception {
// Delete an Event that has not been created.
final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
final boolean deleted = storage.delete(new RyaURI("urn:event/003"));
// Verify no document was deleted.
assertFalse(deleted);
}
use of org.apache.rya.indexing.geotemporal.storage.EventStorage in project incubator-rya by apache.
the class MongoEventStorageIT method update.
@Test
public void update() throws Exception {
final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
final Geometry geo = GF.createPoint(new Coordinate(10, 10));
TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
// An Event that will be stored.
final Event event = Event.builder().setSubject(new RyaURI("urn:event/004")).setGeometry(geo).setTemporalInstant(instant).build();
storage.create(event);
// Show Alice was stored.
Optional<Event> latest = storage.get(new RyaURI("urn:event/004"));
assertEquals(event, latest.get());
instant = new TemporalInstantRfc3339(DateTime.now());
// Change Alice's eye color to brown.
final Event updated = Event.builder(event).setTemporalInstant(instant).build();
storage.update(event, updated);
// Fetch the Alice object and ensure it has the new value.
latest = storage.get(new RyaURI("urn:event/004"));
assertEquals(updated, latest.get());
}
use of org.apache.rya.indexing.geotemporal.storage.EventStorage in project incubator-rya by apache.
the class EventQueryNode2IT method evaluate_constantSubject.
@Test
public void evaluate_constantSubject() throws Exception {
final EventStorage storage = new MongoEventStorage(super.getMongoClient(), "testDB");
RyaURI subject = new RyaURI("urn:event-1111");
final Geometry geo = GF.createPoint(new Coordinate(1, 1));
final TemporalInstant temp = new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0);
final Event event = Event.builder().setSubject(subject).setGeometry(geo).setTemporalInstant(temp).build();
subject = new RyaURI("urn:event-2222");
final Event otherEvent = Event.builder().setSubject(subject).setGeometry(geo).setTemporalInstant(temp).build();
storage.create(event);
storage.create(otherEvent);
final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?event ?time ?point ?wkt " + "WHERE { " + " <urn:event-1111> time:atTime ?time . " + " <urn:event-1111> geo:asWKT ?wkt . " + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + " FILTER(tempo:equals(?time, \"" + temp.toString() + "\")) " + "}";
final EventQueryNode node = buildNode(storage, query);
final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(new MapBindingSet());
final MapBindingSet expected = new MapBindingSet();
expected.addBinding("wkt", VF.createLiteral("POINT (1 1)"));
expected.addBinding("time", VF.createLiteral(temp.toString()));
int count = 0;
assertTrue(rez.hasNext());
while (rez.hasNext()) {
assertEquals(expected, rez.next());
count++;
}
assertEquals(1, count);
}
use of org.apache.rya.indexing.geotemporal.storage.EventStorage in project incubator-rya by apache.
the class EventQueryNode2IT method evaluate_variableSubject_existingBindingset.
@Test
public void evaluate_variableSubject_existingBindingset() throws Exception {
final EventStorage storage = new MongoEventStorage(super.getMongoClient(), "testDB");
RyaURI subject = new RyaURI("urn:event-1111");
Geometry geo = GF.createPoint(new Coordinate(1, 1));
final TemporalInstant temp = new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0);
final Event event = Event.builder().setSubject(subject).setGeometry(geo).setTemporalInstant(temp).build();
subject = new RyaURI("urn:event-2222");
geo = GF.createPoint(new Coordinate(-1, -1));
final Event otherEvent = Event.builder().setSubject(subject).setGeometry(geo).setTemporalInstant(temp).build();
storage.create(event);
storage.create(otherEvent);
final String query = "PREFIX time: <http://www.w3.org/2006/time#> \n" + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n" + "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>" + "SELECT ?event ?time ?point ?wkt " + "WHERE { " + " ?event time:atTime ?time . " + " ?event geo:asWKT ?wkt . " + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + " FILTER(tempo:equals(?time, \"2015-12-30T12:00:00Z\")) " + "}";
final EventQueryNode node = buildNode(storage, query);
final MapBindingSet existingBindings = new MapBindingSet();
existingBindings.addBinding("event", VF.createURI("urn:event-2222"));
final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(existingBindings);
final MapBindingSet expected = new MapBindingSet();
expected.addBinding("wkt", VF.createLiteral("POINT (-1 -1)"));
expected.addBinding("time", VF.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString()));
final List<BindingSet> actual = new ArrayList<>();
while (rez.hasNext()) {
actual.add(rez.next());
}
assertEquals(1, actual.size());
assertEquals(expected, actual.get(0));
}
use of org.apache.rya.indexing.geotemporal.storage.EventStorage in project incubator-rya by apache.
the class MongoGeoTemporalIndexer method deleteStatement.
@Override
public void deleteStatement(final RyaStatement statement) throws IOException {
requireNonNull(statement);
final RyaURI subject = statement.getSubject();
try {
final EventStorage eventStore = events.get();
checkState(events != null, "Must set this indexers configuration before storing statements.");
new EventUpdater(eventStore).update(subject, old -> {
final Event.Builder updated;
if (!old.isPresent()) {
return Optional.empty();
} else {
updated = Event.builder(old.get());
}
final Event currentEvent = updated.build();
final URI pred = statement.getObject().getDataType();
if ((pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) && currentEvent.getGeometry().isPresent()) {
// is geo and needs to be removed.
try {
if (currentEvent.getGeometry().get().equals(GeoParseUtils.getGeometry(RyaToRdfConversions.convertStatement(statement), new GmlParser()))) {
updated.setGeometry(null);
}
} catch (final Exception e) {
LOG.debug("Unable to parse the stored geometry.");
}
} else {
// is time
final String dateTime = statement.getObject().getData();
final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
if (matcher.find()) {
final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
if (currentEvent.getInterval().get().equals(interval)) {
updated.setTemporalInterval(null);
}
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
if (currentEvent.getInstant().get().equals(instant)) {
updated.setTemporalInstant(null);
}
}
}
return Optional.of(updated.build());
});
} catch (final IndexingException e) {
throw new IOException("Failed to update the Entity index.", e);
}
}
Aggregations