use of org.vertexium.VertexiumException in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reduceGeohashResults.
private static GeohashResult reduceGeohashResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof GeoHashGrid) {
GeoHashGrid h = (GeoHashGrid) agg;
for (GeoHashGrid.Bucket b : h.getBuckets()) {
List<MultiBucketsAggregation.Bucket> existingBucket = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
existingBucket.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a geohash: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<GeohashResult, GeohashBucket>() {
@Override
protected GeohashBucket createBucket(final Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
GeoPoint geoPoint = getAverageGeoPointFromBuckets(buckets);
return new GeohashBucket(key.toString(), count, geoPoint, nestedResults) {
@Override
public GeoRect getGeoCell() {
org.elasticsearch.common.geo.GeoPoint northWest = new org.elasticsearch.common.geo.GeoPoint();
org.elasticsearch.common.geo.GeoPoint southEast = new org.elasticsearch.common.geo.GeoPoint();
GeohashUtils.decodeCell(key.toString(), northWest, southEast);
return new GeoRect(new GeoPoint(northWest.getLat(), northWest.getLon()), new GeoPoint(southEast.getLat(), southEast.getLon()));
}
};
}
@Override
protected GeohashResult bucketsToResults(List<GeohashBucket> buckets) {
return new GeohashResult(buckets);
}
}.reduce(query, bucketsByKey);
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class ElasticsearchGraphQueryIterable method reduceHistogramResults.
private static HistogramResult reduceHistogramResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof Histogram) {
Histogram h = (Histogram) agg;
org.vertexium.query.Aggregation queryAgg = query.getAggregationByName(query.getAggregationName(h.getName()));
boolean isCalendarFieldQuery = queryAgg != null && queryAgg instanceof CalendarFieldAggregation;
for (Histogram.Bucket b : h.getBuckets()) {
if (isCalendarFieldQuery && b.getKey().toString().equals("-1.0")) {
continue;
}
List<MultiBucketsAggregation.Bucket> l = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
l.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a histogram: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<HistogramResult, HistogramBucket>() {
@Override
protected HistogramBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
return new HistogramBucket(key, count, nestedResults);
}
@Override
protected HistogramResult bucketsToResults(List<HistogramBucket> buckets) {
return new HistogramResult(buckets);
}
}.reduce(query, bucketsByKey);
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class GeohashUtils method decodeCell.
public static void decodeCell(String key, org.elasticsearch.common.geo.GeoPoint northWest, org.elasticsearch.common.geo.GeoPoint southEast) {
try {
double[] interval = decodeCell(key);
northWest.reset(interval[1], interval[2]);
southEast.reset(interval[0], interval[3]);
} catch (Exception e) {
throw new VertexiumException("Could not decode cell", e);
}
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class ElasticsearchResource method expandVertexiumPlugin.
private void expandVertexiumPlugin(File vertexiumPluginDir) {
InputStream zipIn = getClass().getResourceAsStream("/vertexium-elasticsearch5-plugin.zip");
File pluginZip = new File(vertexiumPluginDir.getParentFile(), "vertexium-elasticsearch5-plugin.zip");
try (OutputStream zipOut = new FileOutputStream(pluginZip)) {
IOUtils.copy(zipIn, zipOut);
} catch (Exception ex) {
throw new VertexiumException("Could not write plugin zip file", ex);
}
try {
ZipFile zipFile = new ZipFile(pluginZip);
zipFile.extractFile("elasticsearch/plugin-descriptor.properties", vertexiumPluginDir.getAbsolutePath(), null, "plugin-descriptor.properties");
} catch (Exception ex) {
throw new VertexiumException("Could not extract plugin", ex);
}
pluginZip.delete();
}
use of org.vertexium.VertexiumException in project vertexium by visallo.
the class InMemoryAuthorizations method canRead.
@Override
public boolean canRead(Visibility visibility) {
Preconditions.checkNotNull(visibility, "visibility is required");
// this is just a shortcut so that we don't need to construct evaluators and visibility objects to check for an empty string.
if (visibility.getVisibilityString().length() == 0) {
return true;
}
VisibilityEvaluator visibilityEvaluator = new VisibilityEvaluator(new Authorizations(this.getAuthorizations()));
ColumnVisibility columnVisibility = new ColumnVisibility(visibility.getVisibilityString());
try {
return visibilityEvaluator.evaluate(columnVisibility);
} catch (VisibilityParseException e) {
throw new VertexiumException("could not evaluate visibility " + visibility.getVisibilityString(), e);
}
}
Aggregations