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