Search in sources :

Example 36 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoSphereCorrectly.

// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoSphereCorrectly() {
    ClassWithGeoSphere object = new ClassWithGeoSphere();
    Sphere sphere = new Sphere(new Point(1, 2), 3);
    Distance radius = sphere.getRadius();
    object.sphere = sphere;
    org.bson.Document document = new org.bson.Document();
    converter.write(object, document);
    assertThat(document).isNotNull();
    assertThat(document.get("sphere")).isInstanceOf(org.bson.Document.class);
    assertThat(document.get("sphere")).isEqualTo((Object) new org.bson.Document("center", new org.bson.Document("x", sphere.getCenter().getX()).append("y", sphere.getCenter().getY())).append("radius", radius.getNormalizedValue()).append("metric", radius.getMetric().toString()));
}
Also used : Sphere(org.springframework.data.mongodb.core.geo.Sphere) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 37 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoSphereWithMetricDistanceCorrectly.

// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoSphereWithMetricDistanceCorrectly() {
    ClassWithGeoSphere object = new ClassWithGeoSphere();
    Sphere sphere = new Sphere(new Point(1, 2), new Distance(3, Metrics.KILOMETERS));
    Distance radius = sphere.getRadius();
    object.sphere = sphere;
    org.bson.Document document = new org.bson.Document();
    converter.write(object, document);
    assertThat(document).isNotNull();
    assertThat(document.get("sphere")).isInstanceOf(org.bson.Document.class);
    assertThat(document.get("sphere")).isEqualTo((Object) new org.bson.Document("center", new org.bson.Document("x", sphere.getCenter().getX()).append("y", sphere.getCenter().getY())).append("radius", radius.getNormalizedValue()).append("metric", radius.getMetric().toString()));
}
Also used : Sphere(org.springframework.data.mongodb.core.geo.Sphere) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 38 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoShapeCorrectly.

// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoShapeCorrectly() {
    ClassWithGeoShape object = new ClassWithGeoShape();
    Sphere sphere = new Sphere(new Point(1, 2), 3);
    Distance radius = sphere.getRadius();
    object.shape = sphere;
    org.bson.Document document = new org.bson.Document();
    converter.write(object, document);
    assertThat(document).isNotNull();
    assertThat(document.get("shape")).isInstanceOf(org.bson.Document.class);
    assertThat(document.get("shape")).isEqualTo((Object) new org.bson.Document("center", new org.bson.Document("x", sphere.getCenter().getX()).append("y", sphere.getCenter().getY())).append("radius", radius.getNormalizedValue()).append("metric", radius.getMetric().toString()));
}
Also used : Sphere(org.springframework.data.mongodb.core.geo.Sphere) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 39 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoCircleCorrectly.

// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoCircleCorrectly() {
    ClassWithGeoCircle object = new ClassWithGeoCircle();
    Circle circle = new Circle(new Point(1, 2), 3);
    Distance radius = circle.getRadius();
    object.circle = circle;
    org.bson.Document document = new org.bson.Document();
    converter.write(object, document);
    assertThat(document).isNotNull();
    assertThat(document.get("circle")).isInstanceOf(org.bson.Document.class);
    assertThat(document.get("circle")).isEqualTo((Object) new org.bson.Document("center", new org.bson.Document("x", circle.getCenter().getX()).append("y", circle.getCenter().getY())).append("radius", radius.getNormalizedValue()).append("metric", radius.getMetric().toString()));
}
Also used : Circle(org.springframework.data.geo.Circle) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 40 with Distance

use of org.springframework.data.geo.Distance in project nixmash-blog by mintster.

the class ProductServiceImpl method getProductsByLocation.

@Override
public List<Product> getProductsByLocation(String LatLng) throws GeoLocationException {
    List<Product> found;
    try {
        Point point = GeoConverters.StringToPointConverter.INSTANCE.convert(LatLng);
        found = customProductRepository.findByLocationNear(new Point(point.getX(), point.getY()), new Distance(30));
    } catch (Exception e) {
        logger.debug("No location found with coordinates: {}", LatLng);
        throw new GeoLocationException("Error in mapping latLng: " + LatLng);
    }
    return found;
}
Also used : Product(com.nixmash.blog.solr.model.Product) Point(org.springframework.data.geo.Point) GeoLocationException(com.nixmash.blog.solr.exceptions.GeoLocationException) Distance(org.springframework.data.geo.Distance) GeoLocationException(com.nixmash.blog.solr.exceptions.GeoLocationException)

Aggregations

Distance (org.springframework.data.geo.Distance)44 Test (org.junit.jupiter.api.Test)34 Point (org.springframework.data.geo.Point)32 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)17 Query (org.springframework.data.mongodb.core.query.Query)9 Test (org.junit.Test)6 Product (com.nixmash.blog.solr.model.Product)5 Document (org.bson.Document)5 Circle (org.springframework.data.geo.Circle)5 Document (org.springframework.data.mongodb.core.mapping.Document)5 PartTree (org.springframework.data.repository.query.parser.PartTree)5 Sphere (org.springframework.data.mongodb.core.geo.Sphere)4 Arrays (java.util.Arrays)3 Sort (org.springframework.data.domain.Sort)3 Metrics (org.springframework.data.geo.Metrics)3 MongoClient (com.mongodb.reactivestreams.client.MongoClient)2 Method (java.lang.reflect.Method)2 Map (java.util.Map)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2