use of uk.gov.gchq.koryphe.impl.predicate.Or in project Gaffer by gchq.
the class FederatedAddGraphHandlerTest method shouldAddGraphWithCustomReadAccessPredicate.
@Test
public void shouldAddGraphWithCustomReadAccessPredicate() throws Exception {
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
final Schema expectedSchema = new Schema.Builder().build();
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
final AccessPredicate allowBlankUserAndTestUserReadAccess = new AccessPredicate(new AdaptedPredicate(new CallMethod("getUserId"), new Or<>(new IsEqual(testUser.getUserId()), new IsEqual(blankUser.getUserId()))));
new FederatedAddGraphHandler().doOperation(new AddGraph.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).readAccessPredicate(allowBlankUserAndTestUserReadAccess).build(), new Context(testUser), store);
assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
assertEquals(1, store.getGraphs(testUser, null, ignore).size());
}
use of uk.gov.gchq.koryphe.impl.predicate.Or in project gaffer-doc by gchq.
the class OrExample method isLessThan2EqualTo5OrIsMoreThan10.
public void isLessThan2EqualTo5OrIsMoreThan10() {
// ---------------------------------------------------------
final Or function = new Or<>(new IsLessThan(2), new IsEqual(5), new IsMoreThan(10));
// ---------------------------------------------------------
runExample(function, "When using an Or predicate with a single selected value you can just use the constructor new Or(predicates))'", 1, 2, 3, 5, 15, 1L, 3L, 5L);
}
use of uk.gov.gchq.koryphe.impl.predicate.Or in project gaffer-doc by gchq.
the class OrExample method firstItemIsLessThan2OrSecondItemIsMoreThan10.
public void firstItemIsLessThan2OrSecondItemIsMoreThan10() {
// ---------------------------------------------------------
final Or function = new Or.Builder().select(0).execute(new IsLessThan(2)).select(1).execute(new IsMoreThan(10)).build();
// ---------------------------------------------------------
runExample(function, "When using an Or predicate with multiple selected values, you need to use the Or.Builder to build your Or predicate, using .select() then .execute(). " + "When selecting values in the Or.Builder you need to refer to the position in the input array. I.e to use the first value use position 0 - select(0)." + "You can select multiple values to give to a predicate like isXLessThanY, this is achieved by passing 2 positions to the select method - select(0, 1)", new Tuple2<>(1, 15), new Tuple2<>(1, 1), new Tuple2<>(15, 15), new Tuple2<>(15, 1), new Tuple2<>(1L, 15L), new Tuple1<>(1));
}
use of uk.gov.gchq.koryphe.impl.predicate.Or in project Gaffer by gchq.
the class JavaPredicateToParquetPredicate method getParquetPredicate.
public FilterPredicate getParquetPredicate() throws SerialisationException {
FilterPredicate filterResult;
if (javaPredicate instanceof AgeOff) {
filterResult = getAgeOffPredicate((AgeOff) javaPredicate, selection, group, schemaUtils);
} else if (javaPredicate instanceof And) {
final And and = (And) javaPredicate;
filterResult = getAndFilter((List<Predicate>) and.getComponents(), selection, group, schemaUtils);
} else if (javaPredicate instanceof Or) {
final Or or = (Or) javaPredicate;
filterResult = getOrFilter((List<Predicate>) or.getComponents(), selection, group, schemaUtils);
} else if (javaPredicate instanceof Not) {
final Not not = (Not) javaPredicate;
final JavaPredicateToParquetPredicate predicateConverter = new JavaPredicateToParquetPredicate(schemaUtils, not.getPredicate(), selection, group);
final FilterPredicate parquetPredicate = predicateConverter.getParquetPredicate();
if (!predicateConverter.fullyApplied) {
fullyApplied = false;
}
filterResult = FilterPredicateUtils.not(parquetPredicate);
} else {
filterResult = getPrimitiveFilter(javaPredicate, selection[0], group, schemaUtils);
}
return filterResult;
}
use of uk.gov.gchq.koryphe.impl.predicate.Or in project Gaffer by gchq.
the class FederatedAddGraphWithHooksHandlerTest method shouldAddGraphWithCustomReadAccessPredicate.
@Test
public void shouldAddGraphWithCustomReadAccessPredicate() throws Exception {
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
final Schema expectedSchema = new Schema.Builder().build();
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
final AccessPredicate allowBlankUserAndTestUserReadAccess = new AccessPredicate(new AdaptedPredicate(new CallMethod("getUserId"), new Or<>(new IsEqual(testUser.getUserId()), new IsEqual(blankUser.getUserId()))));
new FederatedAddGraphWithHooksHandler().doOperation(new AddGraphWithHooks.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).readAccessPredicate(allowBlankUserAndTestUserReadAccess).build(), new Context(testUser), store);
assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
assertEquals(1, store.getGraphs(testUser, null, ignore).size());
}
Aggregations