use of org.vertexium.VertexiumException in project vertexium by visallo.
the class ConfigurationUtils method createProvider.
@SuppressWarnings("unchecked")
public static <T> T createProvider(String className, Graph graph, GraphConfiguration config) throws VertexiumException {
checkNotNull(className, "className is required");
className = className.trim();
LOGGER.debug("creating provider '%s'", className);
Class<Graph> graphClass = Graph.class;
Class<GraphConfiguration> graphConfigurationClass = GraphConfiguration.class;
try {
Class<?> clazz = Class.forName(className);
try {
Constructor constructor;
try {
constructor = clazz.getConstructor(graphClass);
return (T) constructor.newInstance(graph);
} catch (NoSuchMethodException ignore1) {
try {
constructor = clazz.getConstructor(graphClass, graphConfigurationClass);
return (T) constructor.newInstance(graph, config);
} catch (NoSuchMethodException ignore2) {
try {
constructor = clazz.getConstructor(graphConfigurationClass);
return (T) constructor.newInstance(config);
} catch (NoSuchMethodException ignore3) {
try {
constructor = clazz.getConstructor(Map.class);
return (T) constructor.newInstance(config.getConfig());
} catch (NoSuchMethodException ignoreInner) {
constructor = clazz.getConstructor();
return (T) constructor.newInstance();
}
}
}
}
} catch (IllegalArgumentException e) {
StringBuilder possibleMatches = new StringBuilder();
for (Constructor<?> s : clazz.getConstructors()) {
possibleMatches.append(s.toGenericString());
possibleMatches.append(", ");
}
throw new VertexiumException("Invalid constructor for " + className + ". Expected <init>(" + graphConfigurationClass.getName() + "). Found: " + possibleMatches, e);
}
} catch (NoSuchMethodException e) {
throw new VertexiumException("Provider must have a single argument constructor taking a " + graphConfigurationClass.getName(), e);
} catch (ClassNotFoundException e) {
throw new VertexiumException("No provider found with class name " + className, e);
} catch (Exception e) {
throw new VertexiumException(e);
}
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class GeoPoint method parse.
public static GeoPoint parse(String str) {
String description;
Matcher m = WITH_DESCRIPTION_PATTERN.matcher(str);
if (m.matches()) {
description = m.group(1).trim();
str = m.group(2).trim();
} else {
description = null;
}
String[] parts = str.split(",");
if (parts.length < 2) {
throw new VertexiumException("Too few parts to GeoPoint string. Expected at least 2 found " + parts.length + " for string: " + str);
}
if (parts.length >= 4) {
throw new VertexiumException("Too many parts to GeoPoint string. Expected less than or equal to 3 found " + parts.length + " for string: " + str);
}
double latitude = parsePart(parts[0]);
double longitude = parsePart(parts[1]);
Double altitude = null;
if (parts.length >= 3) {
altitude = Double.parseDouble(parts[2]);
}
return new GeoPoint(latitude, longitude, altitude, description);
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reduceRangeResults.
private static RangeResult reduceRangeResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof Range) {
Range r = (Range) agg;
for (Range.Bucket b : r.getBuckets()) {
List<MultiBucketsAggregation.Bucket> l = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
l.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a range: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<RangeResult, RangeBucket>() {
@Override
protected RangeBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
return new RangeBucket(key, count, nestedResults);
}
@Override
protected RangeResult bucketsToResults(List<RangeBucket> buckets) {
return new RangeResult(buckets);
}
}.reduce(query, bucketsByKey);
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reduceTermsResults.
private static TermsResult reduceTermsResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof Terms) {
Terms h = (Terms) agg;
for (Terms.Bucket b : h.getBuckets()) {
TopHits exactMatchTopHits = b.getAggregations().get(ElasticsearchSearchQueryBase.TOP_HITS_AGGREGATION_NAME);
String mapKey = bucketKeyToString(b.getKey(), exactMatchTopHits);
List<MultiBucketsAggregation.Bucket> existingBucketByName = bucketsByKey.computeIfAbsent(mapKey, k -> new ArrayList<>());
existingBucketByName.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a terms: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<TermsResult, TermsBucket>() {
@Override
protected TermsBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
return new TermsBucket(key, count, nestedResults);
}
@Override
protected TermsResult bucketsToResults(List<TermsBucket> buckets) {
return new TermsResult(buckets);
}
}.reduce(query, bucketsByKey);
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reducePercentilesResults.
private static PercentilesResult reducePercentilesResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
List<Percentile> results = new ArrayList<>();
if (aggs.size() != 1) {
throw new VertexiumException("Unexpected number of aggregations. Expected 1 but found: " + aggs.size());
}
Aggregation agg = aggs.get(0);
if (agg instanceof Percentiles) {
Percentiles percentiles = (Percentiles) agg;
StreamUtils.stream(percentiles).filter(percentile -> !Double.isNaN(percentile.getValue())).forEach(percentile -> results.add(new Percentile(percentile.getPercent(), percentile.getValue())));
} else {
throw new VertexiumException("Aggregation is not a percentile: " + agg.getClass().getName());
}
return new PercentilesResult(results);
}
Aggregations