Search in sources :

Example 1 with SmartUriException

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

the class MongoDbSmartUri method queryEntity.

@Override
public ConvertingCursor<TypedEntity> queryEntity(final Type type, final Map<URI, Value> map) throws SmartUriException {
    checkInit();
    // Query it.
    try {
        final Set<Property> properties = SmartUriAdapter.mapToProperties(map);
        final ConvertingCursor<TypedEntity> cursor = entityStorage.search(Optional.empty(), type, properties);
        return cursor;
    } catch (final EntityStorageException e) {
        throw new SmartUriException("Failed to query entity storage", e);
    }
}
Also used : SmartUriException(org.apache.rya.indexing.smarturi.SmartUriException) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) Property(org.apache.rya.indexing.entity.model.Property) EntityStorageException(org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException)

Example 2 with SmartUriException

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

the class DuplicateDataDetector method compareEntities.

/**
 * Compares two entities to determine if they have nearly identical data.
 * @param entity1 the first {@link Entity}. (not {@code null})
 * @param entity2 the second {@link Entity}. (not {@code null})
 * @return {@code true} if the two entities have nearly identical data.
 * {@code false} otherwise.
 * @throws SmartUriException
 */
public boolean compareEntities(final Entity entity1, final Entity entity2) throws SmartUriException {
    requireNonNull(entity1);
    requireNonNull(entity2);
    boolean allValuesNearlyEqual = true;
    final List<RyaURI> types1 = entity1.getExplicitTypeIds();
    final List<RyaURI> types2 = entity2.getExplicitTypeIds();
    final boolean doBothHaveSameTypes = types1.containsAll(types2);
    if (!doBothHaveSameTypes) {
        return false;
    }
    for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> entry : entity1.getProperties().entrySet()) {
        final RyaURI typeIdUri = entry.getKey();
        for (final Entry<RyaURI, Property> typeProperty : entry.getValue().entrySet()) {
            final RyaURI propertyNameUri = typeProperty.getKey();
            final Property property1 = typeProperty.getValue();
            final Optional<Property> p2 = entity2.lookupTypeProperty(typeIdUri, propertyNameUri);
            if (p2.isPresent()) {
                final Property property2 = p2.get();
                final RyaType value1 = property1.getValue();
                final RyaType value2 = property2.getValue();
                final String data1 = value1.getData();
                final String data2 = value2.getData();
                final URI xmlSchemaUri1 = value1.getDataType();
                final ApproxEqualsDetector<?> approxEqualsDetector = uriMap.get(xmlSchemaUri1);
                if (approxEqualsDetector == null) {
                    throw new SmartUriException("No appropriate detector found for the type: " + xmlSchemaUri1);
                }
                final boolean approxEquals = approxEqualsDetector.areApproxEquals(data1, data2);
                if (!approxEquals) {
                    allValuesNearlyEqual = false;
                    break;
                }
            } else {
                allValuesNearlyEqual = false;
                break;
            }
        }
        if (!allValuesNearlyEqual) {
            break;
        }
    }
    return allValuesNearlyEqual;
}
Also used : SmartUriException(org.apache.rya.indexing.smarturi.SmartUriException) RyaType(org.apache.rya.api.domain.RyaType) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) ImmutableMap(com.google.common.collect.ImmutableMap) RyaURI(org.apache.rya.api.domain.RyaURI) Property(org.apache.rya.indexing.entity.model.Property)

Example 3 with SmartUriException

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

the class MongoDbSmartUri method storeEntity.

@Override
public void storeEntity(final RyaURI subject, final Map<URI, Value> map) throws SmartUriException {
    checkInit();
    final URI uri = SmartUriAdapter.serializeUri(subject, map);
    final Entity entity = SmartUriAdapter.deserializeUriEntity(uri);
    // Create it.
    try {
        entityStorage.create(entity);
    } catch (final ObjectStorageException e) {
        throw new SmartUriException("Failed to create entity storage", e);
    }
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) SmartUriException(org.apache.rya.indexing.smarturi.SmartUriException) ObjectStorageException(org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException) RyaURI(org.apache.rya.api.domain.RyaURI) URI(org.openrdf.model.URI)

Aggregations

SmartUriException (org.apache.rya.indexing.smarturi.SmartUriException)3 RyaURI (org.apache.rya.api.domain.RyaURI)2 Property (org.apache.rya.indexing.entity.model.Property)2 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)2 URI (org.openrdf.model.URI)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 RyaType (org.apache.rya.api.domain.RyaType)1 Entity (org.apache.rya.indexing.entity.model.Entity)1 EntityStorageException (org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException)1 ObjectStorageException (org.apache.rya.indexing.mongodb.update.RyaObjectStorage.ObjectStorageException)1