Search in sources :

Example 1 with FilterFunction

use of org.neo4j.ogm.cypher.function.FilterFunction in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method nestedFilteringMustThrowExceptionWithOrInThePipeline.

@Test
public void nestedFilteringMustThrowExceptionWithOrInThePipeline() {
    // rated by the user who doesn't own Catty or by the user who owns Catty
    Filter filterA = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filterA.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    filterA.setNegated(true);
    Filter alwaysTrueFilter = new Filter(new FilterFunction() {

        private Filter theFilter;

        @Override
        public Object getValue() {
            return null;
        }

        @Override
        public Map<String, Object> parameters(UnaryOperator createUniqueParameterName, PropertyValueTransformer valueTransformer) {
            return Collections.emptyMap();
        }

        @Override
        public String expression(String nodeIdentifier, String filteredProperty, UnaryOperator createUniqueParameterName) {
            return "1 = 1 ";
        }
    });
    alwaysTrueFilter.setBooleanOperator(BooleanOperator.OR);
    Filter filterB = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filterB.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    filterB.setBooleanOperator(BooleanOperator.AND);
    Filters filters = new Filters(filterA, alwaysTrueFilter, filterB);
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> session.loadAll(Movie.class, filters)).withMessage("Filters containing nested paths cannot be combined via the logical OR operator.");
}
Also used : FilterFunction(org.neo4j.ogm.cypher.function.FilterFunction) PropertyValueTransformer(org.neo4j.ogm.cypher.PropertyValueTransformer) User(org.neo4j.ogm.domain.cineasts.annotated.User) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) UnaryOperator(java.util.function.UnaryOperator) Map(java.util.Map) Pet(org.neo4j.ogm.domain.cineasts.annotated.Pet) Test(org.junit.Test)

Aggregations

Map (java.util.Map)1 UnaryOperator (java.util.function.UnaryOperator)1 Test (org.junit.Test)1 Filter (org.neo4j.ogm.cypher.Filter)1 Filters (org.neo4j.ogm.cypher.Filters)1 PropertyValueTransformer (org.neo4j.ogm.cypher.PropertyValueTransformer)1 FilterFunction (org.neo4j.ogm.cypher.function.FilterFunction)1 Pet (org.neo4j.ogm.domain.cineasts.annotated.Pet)1 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)1 User (org.neo4j.ogm.domain.cineasts.annotated.User)1