Search in sources :

Example 46 with Filters

use of org.neo4j.ogm.cypher.Filters in project framework by dynamiatools.

the class Neo4jCrudService method buildFilters.

private Filters buildFilters(QueryParameters params) {
    Filters filters = new Filters();
    params.forEach((k, v) -> {
        if (v instanceof QueryCondition) {
            Filter filter = new Filter(k, Neo4jQueryCondition.getOperator((QueryCondition) v), ((QueryCondition) v).getValue());
            filter.setBooleanOperator(BooleanOperator.AND);
            filters.add(filter);
        } else {
            Filter filter = new Filter(k, ComparisonOperator.EQUALS, v);
            filter.setBooleanOperator(BooleanOperator.AND);
            filters.add(filter);
        }
    });
    return filters;
}
Also used : Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter)

Example 47 with Filters

use of org.neo4j.ogm.cypher.Filters in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method loadFilmByUserAndRatingUserPlays.

@Test
public void loadFilmByUserAndRatingUserPlays() {
    Filter userFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
    userFilter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class));
    Filter playsFilter = new Filter("level", ComparisonOperator.EQUALS, "ok");
    playsFilter.setOwnerEntityType(Movie.class);
    playsFilter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("plays", Plays.class));
    Filters filters = userFilter.and(playsFilter);
    Collection<Movie> films = session.loadAll(Movie.class, filters);
    assertThat(films).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Filters(org.neo4j.ogm.cypher.Filters) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Plays(org.neo4j.ogm.domain.cineasts.annotated.Plays) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 48 with Filters

use of org.neo4j.ogm.cypher.Filters 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)

Example 49 with Filters

use of org.neo4j.ogm.cypher.Filters in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldFilterByIsNullOrNotNull.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByIsNullOrNotNull() {
    Restaurant kuroda = new Restaurant("Kuroda", "Mainly Ramen");
    session.save(kuroda);
    Restaurant cyma = new Restaurant();
    cyma.setName("Cyma");
    session.save(cyma);
    session.clear();
    Filter descriptionIsNull = new Filter("description", ComparisonOperator.IS_NULL, null);
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(descriptionIsNull));
    assertThat(results).hasSize(1);
    Restaurant restaurant = results.iterator().next();
    assertThat(restaurant.getName()).isEqualTo("Cyma");
    Filter descriptionIsNotNull = new Filter("description", ComparisonOperator.IS_NULL, null);
    descriptionIsNotNull.setNegated(true);
    results = session.loadAll(Restaurant.class, new Filters().add(descriptionIsNotNull));
    assertThat(results).hasSize(1);
    restaurant = results.iterator().next();
    assertThat(restaurant.getName()).isEqualTo("Kuroda");
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 50 with Filters

use of org.neo4j.ogm.cypher.Filters in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldFilterByPropertyIsTrue.

/**
 * @see DATAGRAPH-904
 */
@Test
public void shouldFilterByPropertyIsTrue() {
    Restaurant kazan = new Restaurant("Kazan", 77.0);
    kazan.setHalal(true);
    session.save(kazan);
    Restaurant kuroda = new Restaurant("Kuroda", 72.4);
    kuroda.setHalal(false);
    session.save(kuroda);
    Filter isHalal = new Filter("halal", ComparisonOperator.IS_TRUE);
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filters().add(isHalal));
    assertThat(results).isNotNull();
    assertThat(results).hasSize(1);
    assertThat(results.iterator().next().getName()).isEqualTo("Kazan");
    Filter notHalal = new Filter("halal", ComparisonOperator.IS_TRUE);
    notHalal.setNegated(true);
    results = session.loadAll(Restaurant.class, new Filters().add(notHalal));
    assertThat(results).isNotNull();
    assertThat(results).hasSize(1);
    assertThat(results.iterator().next().getName()).isEqualTo("Kuroda");
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Aggregations

Filters (org.neo4j.ogm.cypher.Filters)82 Filter (org.neo4j.ogm.cypher.Filter)78 Test (org.junit.Test)77 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)10 Date (java.util.Date)6 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)6 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)4 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)3 User (org.neo4j.ogm.domain.cineasts.annotated.User)3 Before (org.junit.Before)2 Pagination (org.neo4j.ogm.cypher.query.Pagination)2 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)2 Pet (org.neo4j.ogm.domain.cineasts.annotated.Pet)2 Flight (org.neo4j.ogm.domain.gh851.Flight)2 Map (java.util.Map)1 UnaryOperator (java.util.function.UnaryOperator)1 PropertyValueTransformer (org.neo4j.ogm.cypher.PropertyValueTransformer)1 ContainsAnyComparison (org.neo4j.ogm.cypher.function.ContainsAnyComparison)1 DistanceComparison (org.neo4j.ogm.cypher.function.DistanceComparison)1 DistanceFromPoint (org.neo4j.ogm.cypher.function.DistanceFromPoint)1