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