Search in sources :

Example 1 with TemporalPolicy

use of org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.TemporalPolicy in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategy method getTemporalObjs.

private DBObject[] getTemporalObjs(final Collection<IndexingExpr> temporalFilters) {
    final List<DBObject> objs = new ArrayList<>();
    temporalFilters.forEach(filter -> {
        final TemporalPolicy policy = TemporalPolicy.fromURI(filter.getFunction());
        final String timeStr = ((Value) filter.getArguments()[0]).stringValue();
        final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(timeStr);
        if (matcher.find()) {
            final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(timeStr);
            if (policy == TemporalPolicy.INSTANT_AFTER_INSTANT || policy == TemporalPolicy.INSTANT_BEFORE_INSTANT || policy == TemporalPolicy.INSTANT_EQUALS_INSTANT) {
                if (interval == null) {
                    LOG.error("Cannot perform temporal interval based queries on an instant.");
                }
            }
            objs.add(getTemporalObject(interval, policy));
        } else {
            final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(timeStr));
            if (policy != TemporalPolicy.INSTANT_AFTER_INSTANT && policy != TemporalPolicy.INSTANT_BEFORE_INSTANT && policy != TemporalPolicy.INSTANT_EQUALS_INSTANT) {
                LOG.error("Cannot perform temporal instant based queries on an interval.");
            }
            objs.add(getTemporalObject(instant, policy));
        }
    });
    return objs.toArray(new DBObject[] {});
}
Also used : TemporalPolicy(org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.TemporalPolicy) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Value(org.openrdf.model.Value) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInstant(org.apache.rya.indexing.TemporalInstant) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) TemporalInterval(org.apache.rya.indexing.TemporalInterval)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 TemporalInstant (org.apache.rya.indexing.TemporalInstant)1 TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)1 TemporalInterval (org.apache.rya.indexing.TemporalInterval)1 TemporalPolicy (org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.TemporalPolicy)1 Value (org.openrdf.model.Value)1