Search in sources :

Example 1 with Location

use of org.neo4j.ogm.domain.restaurant.Location in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldQueryByDistance.

@Test
public void shouldQueryByDistance() {
    Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
    session.save(restaurant);
    HashMap<String, Object> parameters = new HashMap<>();
    parameters.put("distance", 1000);
    Restaurant found = session.queryForObject(Restaurant.class, "MATCH (r:Restaurant) " + "WHERE distance(point({latitude: r.latitude, longitude:r.longitude}),point({latitude:37.0, longitude:-118.0, crs: 'WGS-84'})) < $distance*1000 RETURN r;", parameters);
    assertThat(found).isNotNull();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) HashMap(java.util.HashMap) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 2 with Location

use of org.neo4j.ogm.domain.restaurant.Location in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldSaveRestaurantWithCompositeLocationConverter.

@Test
public void shouldSaveRestaurantWithCompositeLocationConverter() {
    Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
    session.save(restaurant);
    session.clear();
    assertThat(session.query("MATCH (n:`Restaurant` {name: 'San Francisco International Airport (SFO)', latitude: 37.61649, " + "longitude: -122.38681, zip: 94128, score: 0.0, halal: false, specialities:[]}) return n", emptyMap()).queryResults()).hasSize(1);
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 3 with Location

use of org.neo4j.ogm.domain.restaurant.Location in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method saveAndRetrieveRestaurantWithLocation.

@Test
public void saveAndRetrieveRestaurantWithLocation() {
    Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
    session.save(restaurant);
    session.clear();
    Collection<Restaurant> results = session.loadAll(Restaurant.class, new Filter("name", ComparisonOperator.EQUALS, "San Francisco International Airport (SFO)"));
    assertThat(results).hasSize(1);
    Restaurant result = results.iterator().next();
    assertThat(result.getLocation()).isNotNull();
    assertThat(result.getLocation().getLatitude()).isCloseTo(37.61649, within(0d));
    assertThat(result.getLocation().getLongitude()).isCloseTo(-122.38681, within(0d));
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Filter(org.neo4j.ogm.cypher.Filter) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 4 with Location

use of org.neo4j.ogm.domain.restaurant.Location in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldQueryByDistanceUsingFilter.

@Test
public void shouldQueryByDistanceUsingFilter() {
    Restaurant restaurant = new Restaurant("San Francisco International Airport (SFO)", new Location(37.61649, -122.38681), 94128);
    session.save(restaurant);
    session.clear();
    Filter filter = new Filter(new DistanceComparison(new DistanceFromPoint(37.61649, -122.38681, 1000 * 1000.0)), ComparisonOperator.LESS_THAN);
    Collection<Restaurant> found = session.loadAll(Restaurant.class, filter);
    assertThat(found).isNotNull();
    assertThat(found.size() >= 1).isTrue();
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) DistanceComparison(org.neo4j.ogm.cypher.function.DistanceComparison) DistanceFromPoint(org.neo4j.ogm.cypher.function.DistanceFromPoint) Filter(org.neo4j.ogm.cypher.Filter) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Example 5 with Location

use of org.neo4j.ogm.domain.restaurant.Location in project neo4j-ogm by neo4j.

the class RestaurantIntegrationTest method shouldUpdateLabelsCorrectly.

@Test
public void shouldUpdateLabelsCorrectly() throws Exception {
    Franchise franchise = new Franchise();
    Restaurant r1 = new Restaurant();
    r1.setName("La Strada Tooting");
    r1.labels = Arrays.asList("Delicious", "Foreign");
    Restaurant r2 = new Restaurant();
    r2.setName("La Strada Brno");
    r2.labels = Arrays.asList("Average", "Foreign");
    franchise.addBranch(new Branch(new Location(0.0, 0.0), franchise, r1));
    franchise.addBranch(new Branch(new Location(0.0, 0.0), franchise, r2));
    session.save(franchise);
    // remove labels, different label for each entity
    r1.labels = Arrays.asList("Foreign");
    r2.labels = Arrays.asList("Foreign");
    session.save(franchise);
    session.clear();
    Restaurant loadedR1 = session.load(Restaurant.class, r1.getId());
    assertThat(loadedR1.labels).containsOnly("Foreign");
    Restaurant loadedR2 = session.load(Restaurant.class, r2.getId());
    assertThat(loadedR2.labels).containsOnly("Foreign");
}
Also used : Restaurant(org.neo4j.ogm.domain.restaurant.Restaurant) Branch(org.neo4j.ogm.domain.restaurant.Branch) Franchise(org.neo4j.ogm.domain.restaurant.Franchise) Location(org.neo4j.ogm.domain.restaurant.Location) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 Location (org.neo4j.ogm.domain.restaurant.Location)7 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)7 Branch (org.neo4j.ogm.domain.restaurant.Branch)3 Franchise (org.neo4j.ogm.domain.restaurant.Franchise)3 Filter (org.neo4j.ogm.cypher.Filter)2 HashMap (java.util.HashMap)1 DistanceComparison (org.neo4j.ogm.cypher.function.DistanceComparison)1 DistanceFromPoint (org.neo4j.ogm.cypher.function.DistanceFromPoint)1