use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class GetAllElementsHandlerTest method testGetAllElementsWithViewRestrictedByGroupAndAPostAggregationFilter.
@Test
public void testGetAllElementsWithViewRestrictedByGroupAndAPostAggregationFilter() throws OperationException {
// Given
final Graph graph = getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetAllElements getAllElements = new GetAllElements.Builder().view(new View.Builder().edge(BASIC_EDGE1, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(COUNT).execute(new IsMoreThan(5)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e.getGroup().equals(BASIC_EDGE1) && ((int) e.getProperty(COUNT)) > 5).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class ElementFilterTest method shouldExecuteOrPredicates.
@Test
public void shouldExecuteOrPredicates() {
final ElementFilter filter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new Or.Builder<>().select(0).execute(new IsMoreThan(2)).select(1).execute(new IsEqual("some value")).build()).build();
final Entity element1 = makeEntity(3, "some value");
final Entity element2 = makeEntity(1, "some value");
final Entity element3 = makeEntity(3, "some invalid value");
final Entity element4 = makeEntity(1, "some invalid value");
// When
final boolean result1 = filter.test(element1);
final boolean result2 = filter.test(element2);
final boolean result3 = filter.test(element3);
final boolean result4 = filter.test(element4);
// Then
assertTrue(result1);
assertTrue(result2);
assertTrue(result3);
assertFalse(result4);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class ElementFilterTest method shouldExecuteNotPredicates.
@Test
public void shouldExecuteNotPredicates() {
final ElementFilter filter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new Not<>(new Or.Builder<>().select(0).execute(new IsMoreThan(2)).select(1).execute(new IsEqual("some value")).build())).build();
final Entity element1 = makeEntity(3, "some value");
final Entity element2 = makeEntity(1, "some value");
final Entity element3 = makeEntity(3, "some invalid value");
final Entity element4 = makeEntity(1, "some invalid value");
// When
final boolean result1 = filter.test(element1);
final boolean result2 = filter.test(element2);
final boolean result3 = filter.test(element3);
final boolean result4 = filter.test(element4);
// Then
assertFalse(result1);
assertFalse(result2);
assertFalse(result3);
assertTrue(result4);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class Queries method runFullExample.
private void runFullExample(final Graph graph, final User user) throws OperationException {
final OperationChain<Iterable<? extends String>> opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("South West")).view(new View.Builder().edge("RegionContainsLocation").build()).build()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("LocationContainsRoad").build()).build()).then(new ToSet<>()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("RoadHasJunction").build()).build()).then(new GetElements.Builder().view(new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).entity("JunctionUse", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate", "endDate").execute(new InDateRangeDual.Builder().start("2000/01/01").end("2001/01/01").build()).build()).postAggregationFilter(new ElementFilter.Builder().select("countByVehicleType").execute(new PredicateMap<>("BUS", new IsMoreThan(1000L))).build()).transientProperty("busCount", Long.class).transformer(new ElementTransformer.Builder().select("countByVehicleType").execute(new FreqMapExtractor("BUS")).project("busCount").build()).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).then(new Sort.Builder().comparators(new ElementPropertyComparator.Builder().groups("JunctionUse").property("busCount").reverse(true).build()).resultLimit(2).deduplicate(true).build()).then(new ToCsv.Builder().generator(new CsvGenerator.Builder().vertex("Junction").property("busCount", "Bus Count").build()).build()).build();
final Iterable<? extends String> results = graph.execute(opChain, user);
System.out.println("Full example results:");
for (final String result : results) {
System.out.println(result);
}
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnFalseForOrFilterWithIncompatibleProperties.
@Test
public void shouldValidateAndReturnFalseForOrFilterWithIncompatibleProperties() {
// Given
final ViewValidator validator = new ViewValidator();
final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new Or.Builder().select(0).execute(new IsMoreThan(2)).select(1).execute(new IsEqual("some other value")).build()).build()).build()).build();
final Schema schema = new Schema.Builder().type("obj", Object.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").property(TestPropertyNames.PROP_2, "string").build()).build();
// When
final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
// Then
assertFalse(result.isValid());
}
Aggregations