use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class AccumuloTemporalIndexer method storeStatement.
/**
* Store a statement in the index if it meets the criterion: Object should be
* a literal and one of the validPredicates from the configuration.
* If it does not meet the criteria, it is silently ignored.
* logs a warning if the object is not parse-able.
* Attempts to parse with calendarValue = literalValue.calendarValue()
* if that fails, tries: org.joda.time.DateTime.parse() .
* T O D O parse an interval using multiple predicates for same subject -- ontology dependent.
*/
private void storeStatement(final Statement statement) throws IOException, IllegalArgumentException {
Objects.requireNonNull(temporalIndexBatchWriter, "This is not initialized for writing. Must call setMultiTableBatchWriter() and init().");
// if the predicate list is empty, accept all predicates.
// Otherwise, make sure the predicate is on the "valid" list
final boolean isValidPredicate = validPredicates == null || validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
if (!isValidPredicate || !(statement.getObject() instanceof Literal)) {
return;
}
// 0 begin, 1 end of interval
final DateTime[] indexDateTimes = new DateTime[2];
extractDateTime(statement, indexDateTimes);
if (indexDateTimes[0] == null) {
return;
}
if (!this.isInit)
throw new RuntimeException("Method .init() was not called (or failed) before attempting to store statements.");
// Add this as an instant, or interval.
try {
if (indexDateTimes[1] != null) {
final TemporalInterval interval = new TemporalInterval(new TemporalInstantRfc3339(indexDateTimes[0]), new TemporalInstantRfc3339(indexDateTimes[1]));
addInterval(temporalIndexBatchWriter, interval, statement);
} else {
final TemporalInstant instant = new TemporalInstantRfc3339(indexDateTimes[0]);
addInstant(temporalIndexBatchWriter, instant, statement);
}
} catch (final MutationsRejectedException e) {
throw new IOException("While adding interval/instant for statement =" + statement, e);
}
}
use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class MongoEventStorageIT method delete.
@Test
public void delete() 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/002")).setGeometry(geo).setTemporalInstant(instant).build();
// Create it.
final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
storage.create(event);
// Delete it.
final boolean deleted = storage.delete(new RyaURI("urn:event/002"));
// Verify a document was deleted.
assertTrue(deleted);
}
use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class MongoEventStorageIT method update_differentSubjects.
@Test(expected = EventStorageException.class)
public void update_differentSubjects() throws Exception {
final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
final Geometry geo = GF.createPoint(new Coordinate(10, 10));
final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
// Two objects that do not have the same Subjects.
final Event old = Event.builder().setSubject(new RyaURI("urn:event/001")).setGeometry(geo).setTemporalInstant(instant).build();
final Event updated = Event.builder().setSubject(new RyaURI("urn:event/002")).setGeometry(geo).setTemporalInstant(instant).build();
// The update will fail.
storage.update(old, updated);
}
use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.
the class MongoEventStorageIT method can_not_create_with_same_subject.
@Test
public void can_not_create_with_same_subject() 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);
// Try to create it again. This will fail.
boolean failed = false;
try {
storage.create(event);
} catch (final EventAlreadyExistsException e) {
failed = true;
}
assertTrue(failed);
}
use of org.apache.rya.indexing.TemporalInstant 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());
}
Aggregations