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;
}
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);
}
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.");
}
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");
}
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");
}
Aggregations