Search in sources :

Example 26 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 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);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Event(org.apache.rya.indexing.geotemporal.model.Event) TemporalInstant(org.apache.rya.indexing.TemporalInstant) EventAlreadyExistsException(org.apache.rya.indexing.geotemporal.storage.EventStorage.EventAlreadyExistsException) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 27 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 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());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Event(org.apache.rya.indexing.geotemporal.model.Event) TemporalInstant(org.apache.rya.indexing.TemporalInstant) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 28 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.

the class EventDocumentConverter method fromDocument.

@Override
public Event fromDocument(final Document document) throws DocumentConverterException {
    requireNonNull(document);
    final boolean isInstant;
    // Preconditions.
    if (!document.containsKey(SUBJECT)) {
        throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + SUBJECT + "' field is missing.");
    }
    if (document.containsKey(INSTANT)) {
        isInstant = true;
    } else {
        isInstant = false;
    }
    final String subject = document.getString(SUBJECT);
    final Event.Builder builder = new Event.Builder().setSubject(new RyaURI(subject));
    if (document.containsKey(GEO_KEY)) {
        final Document geoObj = (Document) document.get(GEO_KEY);
        final GeometryFactory geoFact = new GeometryFactory();
        final String typeString = (String) geoObj.get("type");
        final CoordinateList coords = new CoordinateList();
        final Geometry geo;
        if (typeString.equals("Point")) {
            final List<Double> point = (List<Double>) geoObj.get("coordinates");
            final Coordinate coord = new Coordinate(point.get(0), point.get(1));
            geo = geoFact.createPoint(coord);
        } else if (typeString.equals("LineString")) {
            final List<List<Double>> pointsList = (List<List<Double>>) geoObj.get("coordinates");
            for (final List<Double> point : pointsList) {
                coords.add(new Coordinate(point.get(0), point.get(1)));
            }
            geo = geoFact.createLineString(coords.toCoordinateArray());
        } else {
            final List<List<List<Double>>> pointsList = (List<List<List<Double>>>) geoObj.get("coordinates");
            if (pointsList.size() == 1) {
                final List<List<Double>> poly = pointsList.get(0);
                for (final List<Double> point : poly) {
                    coords.add(new Coordinate(point.get(0), point.get(1)));
                }
                geo = geoFact.createPolygon(coords.toCoordinateArray());
            } else {
                final List<List<Double>> first = pointsList.get(0);
                final CoordinateList shellCoords = new CoordinateList();
                for (final List<Double> point : pointsList.get(0)) {
                    shellCoords.add(new Coordinate(point.get(0), point.get(1)));
                }
                final LinearRing shell = geoFact.createLinearRing(shellCoords.toCoordinateArray());
                final List<List<List<Double>>> holesPoints = pointsList.subList(1, pointsList.size() - 1);
                final LinearRing[] holes = new LinearRing[holesPoints.size()];
                for (int ii = 0; ii < holes.length; ii++) {
                    final List<List<Double>> holePoints = holesPoints.get(ii);
                    final CoordinateList shells = new CoordinateList();
                    for (final List<Double> point : pointsList.get(0)) {
                        shells.add(new Coordinate(point.get(0), point.get(1)));
                    }
                    holes[ii] = geoFact.createLinearRing(shells.toCoordinateArray());
                }
                geo = geoFact.createPolygon(shell, holes);
            }
        }
        builder.setGeometry(geo);
    }
    if (isInstant) {
        // we already know the key exists
        final Date date = (Date) document.get(INSTANT);
        final DateTime dt = new DateTime(date.getTime());
        final TemporalInstant instant = new TemporalInstantRfc3339(dt);
        builder.setTemporalInstant(instant);
    } else if (document.containsKey(INTERVAL_START)) {
        Date date = (Date) document.get(INTERVAL_START);
        DateTime dt = new DateTime(date.getTime());
        final TemporalInstant begining = new TemporalInstantRfc3339(dt);
        date = (Date) document.get(INTERVAL_END);
        dt = new DateTime(date.getTime());
        final TemporalInstant end = new TemporalInstantRfc3339(dt);
        final TemporalInterval interval = new TemporalInterval(begining, end);
        builder.setTemporalInterval(interval);
    }
    return builder.build();
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) CoordinateList(com.vividsolutions.jts.geom.CoordinateList) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Document(org.bson.Document) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Date(java.util.Date) DateTime(org.joda.time.DateTime) Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) Event(org.apache.rya.indexing.geotemporal.model.Event) CoordinateList(com.vividsolutions.jts.geom.CoordinateList) List(java.util.List) LinearRing(com.vividsolutions.jts.geom.LinearRing) TemporalInterval(org.apache.rya.indexing.TemporalInterval)

Example 29 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 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);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Coordinate(com.vividsolutions.jts.geom.Coordinate) MapBindingSet(org.openrdf.query.impl.MapBindingSet) MongoEventStorage(org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage) MongoEventStorage(org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 30 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 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));
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) ArrayList(java.util.ArrayList) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Coordinate(com.vividsolutions.jts.geom.Coordinate) MapBindingSet(org.openrdf.query.impl.MapBindingSet) MongoEventStorage(org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage) MongoEventStorage(org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Aggregations

TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)34 Test (org.junit.Test)26 TemporalInstant (org.apache.rya.indexing.TemporalInstant)21 RyaURI (org.apache.rya.api.domain.RyaURI)15 Geometry (com.vividsolutions.jts.geom.Geometry)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 TemporalInterval (org.apache.rya.indexing.TemporalInterval)12 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)11 URI (org.openrdf.model.URI)11 Event (org.apache.rya.indexing.geotemporal.model.Event)9 Value (org.openrdf.model.Value)9 ValueFactory (org.openrdf.model.ValueFactory)9 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)9 EventQueryNode (org.apache.rya.indexing.geotemporal.model.EventQueryNode)7 DateTime (org.joda.time.DateTime)5 MongoEventStorage (org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage)4 BindingSet (org.openrdf.query.BindingSet)4 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)4 MapBindingSet (org.openrdf.query.impl.MapBindingSet)4 IOException (java.io.IOException)3