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);
}
}
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);
}
}
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);
}
}
}
Aggregations