Search in sources :

Example 1 with GmlParser

use of org.apache.rya.indexing.mongodb.geo.GmlParser in project incubator-rya by apache.

the class MongoGeoTemporalIndexer method updateEvent.

private void updateEvent(final RyaURI subject, final RyaStatement statement) throws IndexingException, ParseException {
    final EventStorage eventStore = events.get();
    checkState(events != null, "Must set this indexers configuration before storing statements.");
    new EventUpdater(eventStore).update(subject, old -> {
        final Event.Builder updated;
        if (!old.isPresent()) {
            updated = Event.builder().setSubject(subject);
        } else {
            updated = Event.builder(old.get());
        }
        final URI pred = statement.getObject().getDataType();
        if (pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) {
            // is geo
            try {
                final Statement geoStatement = RyaToRdfConversions.convertStatement(statement);
                final Geometry geometry = GeoParseUtils.getGeometry(geoStatement, new GmlParser());
                updated.setGeometry(geometry);
            } catch (final ParseException e) {
                LOG.error(e.getMessage(), e);
            }
        } else {
            // is time
            final String dateTime = statement.getObject().getData();
            final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
            if (matcher.find()) {
                final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
                updated.setTemporalInterval(interval);
            } else {
                final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
                updated.setTemporalInstant(instant);
            }
        }
        return Optional.of(updated.build());
    });
}
Also used : Matcher(java.util.regex.Matcher) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) GmlParser(org.apache.rya.indexing.mongodb.geo.GmlParser) TemporalInstant(org.apache.rya.indexing.TemporalInstant) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Geometry(com.vividsolutions.jts.geom.Geometry) Event(org.apache.rya.indexing.geotemporal.model.Event) ParseException(com.vividsolutions.jts.io.ParseException) TemporalInterval(org.apache.rya.indexing.TemporalInterval) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage)

Example 2 with GmlParser

use of org.apache.rya.indexing.mongodb.geo.GmlParser in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategy method serialize.

@Override
public DBObject serialize(final RyaStatement ryaStatement) {
    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("_id", ryaStatement.getSubject().hashCode());
    final URI obj = ryaStatement.getObject().getDataType();
    if (obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) {
        try {
            final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
            final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser());
            if (geo.getNumPoints() > 1) {
                builder.add(GEO_KEY, geoStrategy.getCorrespondingPoints(geo));
            } else {
                builder.add(GEO_KEY, geoStrategy.getDBPoint(geo));
            }
        } catch (final ParseException e) {
            LOG.error("Could not create geometry for statement " + ryaStatement, e);
            return null;
        }
    } else {
        builder.add(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData()));
    }
    return builder.get();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) GmlParser(org.apache.rya.indexing.mongodb.geo.GmlParser) ParseException(com.vividsolutions.jts.io.ParseException) URI(org.openrdf.model.URI)

Example 3 with GmlParser

use of org.apache.rya.indexing.mongodb.geo.GmlParser in project incubator-rya by apache.

the class MongoGeoTemporalIndexer method deleteStatement.

@Override
public void deleteStatement(final RyaStatement statement) throws IOException {
    requireNonNull(statement);
    final RyaURI subject = statement.getSubject();
    try {
        final EventStorage eventStore = events.get();
        checkState(events != null, "Must set this indexers configuration before storing statements.");
        new EventUpdater(eventStore).update(subject, old -> {
            final Event.Builder updated;
            if (!old.isPresent()) {
                return Optional.empty();
            } else {
                updated = Event.builder(old.get());
            }
            final Event currentEvent = updated.build();
            final URI pred = statement.getObject().getDataType();
            if ((pred.equals(GeoConstants.GEO_AS_WKT) || pred.equals(GeoConstants.GEO_AS_GML) || pred.equals(GeoConstants.XMLSCHEMA_OGC_WKT) || pred.equals(GeoConstants.XMLSCHEMA_OGC_GML)) && currentEvent.getGeometry().isPresent()) {
                // is geo and needs to be removed.
                try {
                    if (currentEvent.getGeometry().get().equals(GeoParseUtils.getGeometry(RyaToRdfConversions.convertStatement(statement), new GmlParser()))) {
                        updated.setGeometry(null);
                    }
                } catch (final Exception e) {
                    LOG.debug("Unable to parse the stored geometry.");
                }
            } else {
                // is time
                final String dateTime = statement.getObject().getData();
                final Matcher matcher = TemporalInstantRfc3339.PATTERN.matcher(dateTime);
                if (matcher.find()) {
                    final TemporalInterval interval = TemporalInstantRfc3339.parseInterval(dateTime);
                    if (currentEvent.getInterval().get().equals(interval)) {
                        updated.setTemporalInterval(null);
                    }
                } else {
                    final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(dateTime));
                    if (currentEvent.getInstant().get().equals(instant)) {
                        updated.setTemporalInstant(null);
                    }
                }
            }
            return Optional.of(updated.build());
        });
    } catch (final IndexingException e) {
        throw new IOException("Failed to update the Entity index.", e);
    }
}
Also used : Matcher(java.util.regex.Matcher) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) GmlParser(org.apache.rya.indexing.mongodb.geo.GmlParser) IOException(java.io.IOException) TemporalInstant(org.apache.rya.indexing.TemporalInstant) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) IndexingException(org.apache.rya.indexing.mongodb.IndexingException) ParseException(com.vividsolutions.jts.io.ParseException) IOException(java.io.IOException) RyaURI(org.apache.rya.api.domain.RyaURI) IndexingException(org.apache.rya.indexing.mongodb.IndexingException) Event(org.apache.rya.indexing.geotemporal.model.Event) TemporalInterval(org.apache.rya.indexing.TemporalInterval) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage)

Aggregations

ParseException (com.vividsolutions.jts.io.ParseException)3 GmlParser (org.apache.rya.indexing.mongodb.geo.GmlParser)3 URI (org.openrdf.model.URI)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 Matcher (java.util.regex.Matcher)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 RyaURI (org.apache.rya.api.domain.RyaURI)2 TemporalInstant (org.apache.rya.indexing.TemporalInstant)2 TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)2 TemporalInterval (org.apache.rya.indexing.TemporalInterval)2 Event (org.apache.rya.indexing.geotemporal.model.Event)2 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)2 Statement (org.openrdf.model.Statement)2 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 IOException (java.io.IOException)1 IndexingException (org.apache.rya.indexing.mongodb.IndexingException)1