Search in sources :

Example 1 with ObjectStorageException

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);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) Var(org.openrdf.query.algebra.Var) ArrayList(java.util.ArrayList) ObjectStorageException(org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException) TemporalInstant(org.apache.rya.indexing.TemporalInstant) DateTime(org.joda.time.DateTime) Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) CollectionIteration(org.openrdf.query.algebra.evaluation.iterator.CollectionIteration) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Value(org.openrdf.model.Value) MapBindingSet(org.openrdf.query.impl.MapBindingSet)

Example 2 with ObjectStorageException

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);
    }
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) SmartUriException(org.apache.rya.indexing.smarturi.SmartUriException) ObjectStorageException(org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException) RyaURI(org.apache.rya.api.domain.RyaURI) URI(org.openrdf.model.URI)

Aggregations

RyaURI (org.apache.rya.api.domain.RyaURI)2 ObjectStorageException (org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 ArrayList (java.util.ArrayList)1 TemporalInstant (org.apache.rya.indexing.TemporalInstant)1 Entity (org.apache.rya.indexing.entity.model.Entity)1 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)1 SmartUriException (org.apache.rya.indexing.smarturi.SmartUriException)1 DateTime (org.joda.time.DateTime)1 URI (org.openrdf.model.URI)1 Value (org.openrdf.model.Value)1 BindingSet (org.openrdf.query.BindingSet)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 Var (org.openrdf.query.algebra.Var)1 CollectionIteration (org.openrdf.query.algebra.evaluation.iterator.CollectionIteration)1 MapBindingSet (org.openrdf.query.impl.MapBindingSet)1