Search in sources :

Example 21 with Filter

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

the class CineastsIntegrationTest method loadParticularUserRatingsAndComments.

@Test
public void loadParticularUserRatingsAndComments() {
    Collection<User> filmCritics = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Michal"));
    assertThat(filmCritics).hasSize(1);
    User critic = filmCritics.iterator().next();
    assertThat(critic.getRatings()).hasSize(2);
    for (Rating rating : critic.getRatings()) {
        assertThat(rating.getComment()).as("The comment should've been mapped").isNotNull();
        assertThat(rating.getStars() > 0).as("The star rating should've been mapped").isTrue();
        assertThat(rating.getUser()).as("The user start node should've been mapped").isNotNull();
        assertThat(rating.getMovie()).as("The movie end node should've been mapped").isNotNull();
    }
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 22 with Filter

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

the class CineastsIntegrationTest method nestedFilteringMustThrowExceptionWithOrInThePipelineForRelationshipEntities.

@Test
public void nestedFilteringMustThrowExceptionWithOrInThePipelineForRelationshipEntities() {
    Filter userNameFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
    userNameFilter.setBooleanOperator(BooleanOperator.OR);
    Filter ratingFilter = new Filter("stars", ComparisonOperator.EQUALS, 5);
    userNameFilter.setNestedPath(new Filter.NestedPathSegment("user", User.class));
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> session.loadAll(Rating.class, userNameFilter.and(ratingFilter))).withMessage("Filters containing nested paths cannot be combined via the logical OR operator.");
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Test(org.junit.Test)

Example 23 with Filter

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

the class CineastsIntegrationTest method loadRatingsForSpecificFilm.

@Test
public void loadRatingsForSpecificFilm() {
    Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
    assertThat(films).hasSize(1);
    Movie film = films.iterator().next();
    assertThat(film.getRatings()).hasSize(2);
    for (Rating rating : film.getRatings()) {
        assertThat(rating.getStars() > 0).as("The star rating should've been mapped").isTrue();
        assertThat(rating.getUser()).as("The user start node should've been mapped").isNotNull();
        assertThat(rating.getMovie()).as("The wrong film was mapped to the rating").isSameAs(film);
    }
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 24 with Filter

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

the class CineastsIntegrationTest method loadFilmByRatingUserPlays.

@Test
public void loadFilmByRatingUserPlays() {
    Filter filter = new Filter("level", ComparisonOperator.EQUALS, "ok");
    filter.setOwnerEntityType(Movie.class);
    filter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("plays", Plays.class));
    Collection<Movie> films = session.loadAll(Movie.class, filter);
    assertThat(films).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) 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 25 with Filter

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

the class CineastsRelationshipEntityTest method shouldHydrateTheEndNodeOfAnRECorrectly.

// DATAGRAPH-552
@Test
public void shouldHydrateTheEndNodeOfAnRECorrectly() {
    Movie movie = new Movie("Pulp Fiction", 1994);
    Actor actor = new Actor("John Travolta");
    actor.playedIn(movie, "Vincent");
    session.save(movie);
    User michal = new User();
    michal.setName("Michal");
    michal.setLogin("bachmania");
    Rating awesome = new Rating();
    awesome.setMovie(movie);
    awesome.setUser(michal);
    awesome.setStars(5);
    michal.setRatings(Collections.singleton(awesome));
    session.save(michal);
    // Check that Pulp Fiction has one rating from Michal
    Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Pulp Fiction"));
    assertThat(films).hasSize(1);
    Movie film = films.iterator().next();
    assertThat(film).isNotNull();
    assertThat(film.getRatings()).hasSize(1);
    assertThat(film.getRatings().iterator().next().getUser().getName()).isEqualTo("Michal");
    assertThat(film.getRoles().iterator().next().getRole()).isEqualTo("Vincent");
    session.clear();
    Rating rating = session.load(Rating.class, awesome.getId(), 2);
    assertThat(rating).isNotNull();
    Movie loadedMovie = rating.getMovie();
    assertThat(loadedMovie).isNotNull();
    assertThat(loadedMovie.getTitle()).isEqualTo("Pulp Fiction");
    assertThat(loadedMovie.getRoles().iterator().next().getRole()).isEqualTo("Vincent");
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Aggregations

Filter (org.neo4j.ogm.cypher.Filter)155 Test (org.junit.Test)146 Filters (org.neo4j.ogm.cypher.Filters)78 User (org.neo4j.ogm.domain.cineasts.annotated.User)19 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)18 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)17 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)12 Date (java.util.Date)10 Session (org.neo4j.ogm.session.Session)10 DistanceFromNativePoint (org.neo4j.ogm.cypher.function.DistanceFromNativePoint)8 SomethingSpatial (org.neo4j.ogm.persistence.types.nativetypes.SomethingSpatial)8 HashSet (java.util.HashSet)7 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)7 GroupMember (org.neo4j.ogm.domain.gh824.GroupMember)7 ArrayList (java.util.ArrayList)4 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)4 User (org.neo4j.ogm.domain.gh824.User)4 UserGroup (org.neo4j.ogm.domain.gh824.UserGroup)4 Studio (org.neo4j.ogm.domain.music.Studio)4 Collections (java.util.Collections)2