use of org.locationtech.geowave.core.store.statistics.binning.FieldValueBinningStrategy in project geowave by locationtech.
the class GeoWaveVisibilityIT method testMixedVisibilityStatistics.
public static void testMixedVisibilityStatistics(final DataStorePluginOptions dataStoreOptions, final VisibilityHandler visibilityHandler, final int totalFeatures) {
final SimpleFeatureBuilder bldr = new SimpleFeatureBuilder(getType());
final FeatureDataAdapter adapter = new FeatureDataAdapter(getType());
final DataStore store = dataStoreOptions.createDataStore();
// Add some statistics
final CountStatistic geomCount = new CountStatistic();
geomCount.setTag("testGeom");
geomCount.setTypeName(adapter.getTypeName());
geomCount.setBinningStrategy(new FieldValueBinningStrategy("geometry"));
final CountStatistic visCountC = new CountStatistic();
visCountC.setTag("testC");
visCountC.setTypeName(adapter.getTypeName());
visCountC.setBinningStrategy(new FieldValueBinningStrategy("c"));
final CountStatistic visCountAB = new CountStatistic();
visCountAB.setTag("testAB");
visCountAB.setTypeName(adapter.getTypeName());
visCountAB.setBinningStrategy(new FieldValueBinningStrategy("a", "b"));
// Specify visibility at the type level
store.addType(adapter, visibilityHandler, Lists.newArrayList(geomCount, visCountC, visCountAB), TestUtils.DEFAULT_SPATIAL_INDEX);
try (Writer<SimpleFeature> writer = store.createWriter(adapter.getTypeName())) {
for (int i = 0; i < totalFeatures; i++) {
bldr.set("a", A_FIELD_VALUES[i % 3]);
bldr.set("b", B_FIELD_VALUES[i % 3]);
bldr.set("c", C_FIELD_VALUES[i % 3]);
bldr.set("geometry", new GeometryFactory().createPoint(new Coordinate(0, 0)));
writer.write(bldr.buildFeature(Integer.toString(i)));
}
}
// Since each field is only visible if you provide that field ID as an authorization, each
// statistic should only reveal those counts if the appropriate authorization is set. Because
// these statistics are using a field value binning strategy, the actual bins of the statistic
// may reveal information that is not authorized to the user and should be hidden.
final CountValue countCNoAuth = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(adapter.getTypeName()).tag("testC").build());
assertEquals(0, countCNoAuth.getValue().longValue());
// When providing the "c" auth, all values should be present
final CountValue countCAuth = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(adapter.getTypeName()).tag("testC").addAuthorization("c").build());
assertEquals(totalFeatures, countCAuth.getValue().longValue());
// For the AB count statistic, the values should only be present if both "a" and "b"
// authorizations are provided
final CountValue countABNoAuth = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(adapter.getTypeName()).tag("testAB").build());
assertEquals(0, countABNoAuth.getValue().longValue());
final CountValue countABOnlyAAuth = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(adapter.getTypeName()).tag("testAB").addAuthorization("a").build());
assertEquals(0, countABOnlyAAuth.getValue().longValue());
final CountValue countABOnlyBAuth = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(adapter.getTypeName()).tag("testAB").addAuthorization("b").build());
assertEquals(0, countABOnlyBAuth.getValue().longValue());
final CountValue countABAuth = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(adapter.getTypeName()).tag("testAB").addAuthorization("a").addAuthorization("b").build());
assertEquals(totalFeatures, countABAuth.getValue().longValue());
// It should also work if additional authorizations are provided
final CountValue countABCAuth = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(adapter.getTypeName()).tag("testAB").addAuthorization("a").addAuthorization("b").addAuthorization("c").build());
assertEquals(totalFeatures, countABCAuth.getValue().longValue());
// Since the geometry field has no visibility, no authorizations should be required
final CountValue countGeomNoAuth = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(adapter.getTypeName()).tag("testGeom").build());
assertEquals(totalFeatures, countGeomNoAuth.getValue().longValue());
}
Aggregations