use of org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException in project incubator-rya by apache.
the class EventQueryNode method evaluate.
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException {
final List<BindingSet> list = new ArrayList<>();
try {
final Collection<Event> searchEvents;
final String subj;
// if the provided binding set has the subject already, set it to the constant subject.
if (!subjectConstant.isPresent() && bindings.hasBinding(subjectVar.get())) {
subjectConstant = Optional.of(bindings.getValue(subjectVar.get()).stringValue());
} else if (bindings.size() != 0) {
list.add(bindings);
}
// If the subject needs to be filled in, check if the subject variable is in the binding set.
if (subjectConstant.isPresent()) {
// if it is, fetch that value and then fetch the entity for the subject.
subj = subjectConstant.get();
searchEvents = eventStore.search(Optional.of(new RyaURI(subj)), Optional.of(geoFilters), Optional.of(temporalFilters));
} else {
searchEvents = eventStore.search(Optional.empty(), Optional.of(geoFilters), Optional.of(temporalFilters));
}
for (final Event event : searchEvents) {
final MapBindingSet resultSet = new MapBindingSet();
if (event.getGeometry().isPresent()) {
final Geometry geo = event.getGeometry().get();
final Value geoValue = ValueFactoryImpl.getInstance().createLiteral(geo.toText());
final Var geoObj = geoPattern.getObjectVar();
resultSet.addBinding(geoObj.getName(), geoValue);
}
final Value temporalValue;
if (event.isInstant() && event.getInstant().isPresent()) {
final Optional<TemporalInstant> opt = event.getInstant();
DateTime dt = opt.get().getAsDateTime();
dt = dt.toDateTime(DateTimeZone.UTC);
final String str = dt.toString(TemporalInstantRfc3339.FORMATTER);
temporalValue = ValueFactoryImpl.getInstance().createLiteral(str);
} else if (event.getInterval().isPresent()) {
temporalValue = ValueFactoryImpl.getInstance().createLiteral(event.getInterval().get().getAsPair());
} else {
temporalValue = null;
}
if (temporalValue != null) {
final Var temporalObj = temporalPattern.getObjectVar();
resultSet.addBinding(temporalObj.getName(), temporalValue);
}
list.add(resultSet);
}
} catch (final ObjectStorageException e) {
throw new QueryEvaluationException("Failed to evaluate the binding set", e);
}
return new CollectionIteration<>(list);
}
use of org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException in project incubator-rya by apache.
the class MongoDbSmartUri method storeEntity.
@Override
public void storeEntity(final RyaURI subject, final Map<URI, Value> map) throws SmartUriException {
checkInit();
final URI uri = SmartUriAdapter.serializeUri(subject, map);
final Entity entity = SmartUriAdapter.deserializeUriEntity(uri);
// Create it.
try {
entityStorage.create(entity);
} catch (final ObjectStorageException e) {
throw new SmartUriException("Failed to create entity storage", e);
}
}
Aggregations