Search in sources :

Example 1 with IndexingException

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

the class BaseEntityIndexer method deleteStatement.

@Override
public void deleteStatement(final RyaStatement statement) throws IOException {
    requireNonNull(statement);
    final EntityStorage entities = this.entities.get();
    final TypeStorage types = this.types.get();
    checkState(entities != null, "Must set this indexers configuration before storing statements.");
    checkState(types != null, "Must set this indexers configuration before storing statements.");
    try {
        new EntityUpdater(entities).update(statement.getSubject(), old -> {
            // If there is no Entity for the subject of the statement, then do nothing.
            if (!old.isPresent()) {
                return Optional.empty();
            }
            final Entity oldEntity = old.get();
            // Increment the version of the Entity.
            final Entity.Builder updated = Entity.builder(oldEntity);
            updated.setVersion(oldEntity.getVersion() + 1);
            if (TYPE_URI.equals(statement.getPredicate())) {
                // If the Type ID already isn't in the list of explicit types, then do nothing.
                final RyaURI typeId = new RyaURI(statement.getObject().getData());
                if (!oldEntity.getExplicitTypeIds().contains(typeId)) {
                    return Optional.empty();
                }
                // Otherwise remove it from the list.
                updated.unsetExplicitType(typeId);
            } else {
                // If the deleted property appears within the old entity's properties, then remove it.
                final RyaURI deletedPropertyName = statement.getPredicate();
                boolean propertyWasPresent = false;
                for (final RyaURI typeId : oldEntity.getProperties().keySet()) {
                    for (final RyaURI propertyName : oldEntity.getProperties().get(typeId).keySet()) {
                        if (deletedPropertyName.equals(propertyName)) {
                            propertyWasPresent = true;
                            updated.unsetProperty(typeId, deletedPropertyName);
                        }
                    }
                }
                // If no properties were removed, then do nothing.
                if (!propertyWasPresent) {
                    return Optional.empty();
                }
            }
            return Optional.of(updated.build());
        });
    } catch (final IndexingException e) {
        throw new IOException("Failed to update the Entity index.", e);
    }
}
Also used : TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) Entity(org.apache.rya.indexing.entity.model.Entity) RyaURI(org.apache.rya.api.domain.RyaURI) IndexingException(org.apache.rya.indexing.mongodb.IndexingException) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) IOException(java.io.IOException)

Example 2 with IndexingException

use of org.apache.rya.indexing.mongodb.IndexingException 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)

Example 3 with IndexingException

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

the class BaseEntityIndexer method storeStatements.

@Override
public void storeStatements(final Collection<RyaStatement> statements) throws IOException {
    requireNonNull(statements);
    final Map<RyaURI, List<RyaStatement>> groupedBySubject = statements.stream().collect(groupingBy(RyaStatement::getSubject));
    for (final Entry<RyaURI, List<RyaStatement>> entry : groupedBySubject.entrySet()) {
        try {
            updateEntity(entry.getKey(), entry.getValue());
        } catch (final IndexingException e) {
            throw new IOException("Failed to update the Entity index.", e);
        }
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) IndexingException(org.apache.rya.indexing.mongodb.IndexingException) List(java.util.List) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)3 RyaURI (org.apache.rya.api.domain.RyaURI)3 IndexingException (org.apache.rya.indexing.mongodb.IndexingException)3 ParseException (com.vividsolutions.jts.io.ParseException)1 List (java.util.List)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 Entity (org.apache.rya.indexing.entity.model.Entity)1 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)1 TypeStorage (org.apache.rya.indexing.entity.storage.TypeStorage)1 Event (org.apache.rya.indexing.geotemporal.model.Event)1 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)1 GmlParser (org.apache.rya.indexing.mongodb.geo.GmlParser)1 URI (org.openrdf.model.URI)1