polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [02/50] [abbrv] zest-qi4j git commit: ..
Date Fri, 17 Apr 2015 16:45:49 GMT
..


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/c93be181
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/c93be181
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/c93be181

Branch: refs/heads/ramtej-fb/spatial.queries
Commit: c93be181549ac93665bd648103dff653a8890751
Parents: d4076d1
Author: jj <juergen.jetmar@gmail.com>
Authored: Tue Jan 6 17:11:27 2015 +0100
Committer: jj <juergen.jetmar@gmail.com>
Committed: Tue Jan 6 17:11:27 2015 +0100

----------------------------------------------------------------------
 .../SpatialExceptionConfiguration.java          |   7 +
 .../configuration/SpatialSupportMatrix.java     | 123 ++++++++++++++++++
 .../ElasticSearchSpatialExtensionFinder.java    | 129 +++++++++++++++++++
 .../domain/openstreetmap/model/state/OSM.java   |   7 +
 .../domain/openstreetmap/model/MapEntity.java   |   7 +
 .../domain/openstreetmap/model/TagEntity.java   |   7 +
 .../OpenStreetMapDomainModelAssembler.java      |   7 +
 .../openstreetmap/model/state/Features.java     |   7 +
 .../openstreetmap/model/state/Identifiable.java |   7 +
 .../openstreetmap/model/state/Properties.java   |   7 +
 .../model/test/TestOpenStreetMapModel.java      |  26 ++++
 11 files changed, 334 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialExceptionConfiguration.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialExceptionConfiguration.java
b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialExceptionConfiguration.java
new file mode 100644
index 0000000..40012c7
--- /dev/null
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialExceptionConfiguration.java
@@ -0,0 +1,7 @@
+package org.qi4j.index.elasticsearch.extensions.spatial.configuration;
+
+/**
+ * Created by jj on 25.12.14.
+ */
+public interface SpatialExceptionConfiguration {
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialSupportMatrix.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialSupportMatrix.java
b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialSupportMatrix.java
new file mode 100644
index 0000000..e805410
--- /dev/null
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialSupportMatrix.java
@@ -0,0 +1,123 @@
+package org.qi4j.index.elasticsearch.extensions.spatial.configuration;
+
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
+import org.qi4j.api.geometry.TPoint;
+import org.qi4j.api.geometry.TPolygon;
+import org.qi4j.api.geometry.internal.TGeometry;
+import org.qi4j.api.query.grammar.ExpressionSpecification;
+import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.ST_Disjoint;
+import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.ST_Intersects;
+import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.ST_WithinV2;
+import org.qi4j.index.elasticsearch.extensions.spatial.mappings.cache.MappingsCache;
+
+import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Created by jj on 22.12.14.
+ */
+public class SpatialSupportMatrix
+{
+
+    private Boolean OrderBy = true;
+    private Class<? extends TGeometry> AnyGeometry = TGeometry.class;
+    public static enum INDEX_MAPPING_POINT_METHOD {AS_GEO_POINT, AS_GEO_SHAPE}
+
+    private static final Table<Class, INDEX_MAPPING_POINT_METHOD, ConfigurationEntry>
SPATIAL_SUPPORT_MATRIX = HashBasedTable.create();
+
+
+
+    {
+        // ST_Within
+        supports(ST_WithinV2.class, propertyOf(AnyGeometry), filterOf(TPoint.class, TPolygon.class),
OrderBy, INDEX_MAPPING_POINT_METHOD.AS_GEO_POINT);
+        supports(ST_WithinV2.class, propertyOf(AnyGeometry), filterOf(TPoint.class, TPolygon.class),
not(OrderBy), INDEX_MAPPING_POINT_METHOD.AS_GEO_SHAPE);
+
+        // ST_Disjoint
+        supports(not(ST_Disjoint.class), AnyGeometry, AnyGeometry, OrderBy, INDEX_MAPPING_POINT_METHOD.AS_GEO_POINT);
+        supports(ST_Disjoint.class, TGeometry.class, TGeometry.class, not(OrderBy), INDEX_MAPPING_POINT_METHOD.AS_GEO_SHAPE);
+
+        // ST_Intersects
+        supports(not(ST_Intersects.class), AnyGeometry, AnyGeometry, OrderBy, INDEX_MAPPING_POINT_METHOD.AS_GEO_POINT);
+        supports(not(ST_Intersects.class), TGeometry.class, TGeometry.class, not(OrderBy),
INDEX_MAPPING_POINT_METHOD.AS_GEO_SHAPE);
+    }
+
+
+
+
+    {
+        supports(ST_WithinV2.class, TPoint.class, not(TPoint.class), OrderBy, INDEX_MAPPING_POINT_METHOD.AS_GEO_SHAPE);
+    }
+
+    private class ConfigurationEntry
+    {
+        private INDEX_MAPPING_POINT_METHOD method;
+        private Boolean orderBy;
+        private List<Class<? extends  TGeometry>> supportedPropertyGeometries
= new LinkedList<>();
+        private List<Class<? extends  TGeometry>> supportedFilterGeometries =
new LinkedList<>();
+
+        public ConfigurationEntry(Class<? extends  TGeometry>[] geometriesOfProperty,
Class<? extends  TGeometry>[] geometriesOfFilter, Boolean orderBy, INDEX_MAPPING_POINT_METHOD
method)
+        {
+            this.supportedPropertyGeometries = Arrays.asList(geometriesOfProperty);
+            this.supportedFilterGeometries   = Arrays.asList(geometriesOfFilter);
+            this.orderBy = orderBy;
+            this.method  = method;
+        }
+
+        public boolean isSupported( Class<? extends  TGeometry> geometryOfProperty,
Class<? extends  TGeometry> geometryOfFilter, Boolean orderBy)
+        {
+            return false;
+        }
+    }
+
+
+    public boolean isSupported(Class expression, Class<? extends  TGeometry> geometryOfProperty,Class<?
extends  TGeometry> geometryOfFilter, Boolean orderBy, INDEX_MAPPING_POINT_METHOD method
)
+    {
+        if (SPATIAL_SUPPORT_MATRIX.contains(expression, method))
+            return SPATIAL_SUPPORT_MATRIX.get(expression, method).isSupported(geometryOfProperty,
geometryOfFilter, orderBy);
+        else
+            return false;
+    }
+
+    private void supports (Class expression, Class<? extends  TGeometry> geometryOfProperty,Class<?
extends  TGeometry> geometryOfFilter, Boolean orderBy, INDEX_MAPPING_POINT_METHOD method)
+    {
+        supports
+                (
+                 expression,
+                 (Class < ?extends TGeometry >[])Array.newInstance(geometryOfProperty,
1),
+                 (Class<? extends TGeometry>[]) Array.newInstance(geometryOfFilter,
1),
+                 orderBy, method
+                );
+    }
+
+    private void supports (Class expression, Class<? extends  TGeometry>[] geometriesOfProperty,Class<?
extends  TGeometry>[] geometriesOfFilter, Boolean orderBy, INDEX_MAPPING_POINT_METHOD method)
+    {
+        SPATIAL_SUPPORT_MATRIX.put(expression, method, new ConfigurationEntry(geometriesOfProperty,
geometriesOfFilter,orderBy, method));
+    }
+
+
+
+    private Class not(Class clazz)
+    {
+        return Object.class;
+    }
+
+    private Boolean not(Boolean bool)
+    {
+        return false;
+    }
+
+
+    private Class<? extends  TGeometry>[] filterOf(Class<? extends  TGeometry>...
geometryOfFilters)
+    {
+        return geometryOfFilters;
+    }
+
+    private Class<? extends  TGeometry>[] propertyOf(Class<? extends  TGeometry>...
geometryOfProperty)
+    {
+        return geometryOfProperty;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/index/ElasticSearchSpatialExtensionFinder.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/index/ElasticSearchSpatialExtensionFinder.java
b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/index/ElasticSearchSpatialExtensionFinder.java
new file mode 100644
index 0000000..c1ec059
--- /dev/null
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/index/ElasticSearchSpatialExtensionFinder.java
@@ -0,0 +1,129 @@
+package org.qi4j.index.elasticsearch.extensions.spatial.index;
+
+/*
+ * Copyright 2014 Jiri Jetmar.
+ *
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.elasticsearch.index.query.*;
+import org.qi4j.api.query.grammar.ComparisonSpecification;
+import org.qi4j.api.query.grammar.ContainsAllSpecification;
+import org.qi4j.api.query.grammar.ContainsSpecification;
+import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification;
+import org.qi4j.api.query.grammar.extensions.spatial.predicate.SpatialPredicatesSpecification;
+import org.qi4j.api.structure.Module;
+import org.qi4j.functional.Specification;
+import org.qi4j.index.elasticsearch.ElasticSearchSupport;
+import org.qi4j.index.elasticsearch.extensions.spatial.functions.convert.ElasticSearchSpatialConvertFinderSupport;
+import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.ElasticSearchSpatialPredicateFinderSupport;
+import org.qi4j.spi.query.EntityFinderException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.elasticsearch.index.query.FilterBuilders.geoShapeFilter;
+
+import org.qi4j.index.elasticsearch.ElasticSearchFinderSupport;
+
+public final class ElasticSearchSpatialExtensionFinder
+{
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchSpatialExtensionFinder.class);
+
+    private static final Map<Class<?>, SpatialQuerySpecSupport> SPATIAL_QUERY_EXPRESSIONS_CATALOG
= new HashMap<>( 2 );
+
+    static
+    {
+        SPATIAL_QUERY_EXPRESSIONS_CATALOG.put(SpatialPredicatesSpecification.class, new ElasticSearchSpatialPredicateFinderSupport());
+        SPATIAL_QUERY_EXPRESSIONS_CATALOG.put(SpatialConvertSpecification.class, new ElasticSearchSpatialConvertFinderSupport());
+    }
+
+
+
+    public interface ModuleHelper {
+        void setModule(Module module, ElasticSearchSupport support);
+    }
+
+    public static interface SpatialQuerySpecSupport extends ModuleHelper
+    {
+        void processSpecification(FilterBuilder filterBuilder, Specification<?> spec,
Map<String, Object> variables)  throws EntityFinderException;
+    }
+
+
+
+    public static class SpatialSpecSupport
+                implements  SpatialQuerySpecSupport {
+
+        Module module;
+        ElasticSearchSupport support;
+
+        public void setModule(Module module, ElasticSearchSupport support)
+        {
+            this.module  = module;
+            this.support = support;
+        }
+
+
+        public void processSpecification(FilterBuilder filterBuilder,
+                                              Specification<?> spec,
+                                              Map<String, Object> variables) {
+
+            SpatialQuerySpecSupport spatialQuerySpecSupport = SPATIAL_QUERY_EXPRESSIONS_CATALOG.get(spec.getClass().getSuperclass());
+            spatialQuerySpecSupport.setModule(module, support);
+
+            try {
+                spatialQuerySpecSupport.processSpecification(filterBuilder, spec, variables);
+
+            } catch (Exception _ex) {
+                _ex.printStackTrace();
+            }
+
+
+        }
+
+    }
+
+
+    public static class SpatialTypeSupport
+            implements ElasticSearchFinderSupport.ComplexTypeSupport
+    {
+
+        public FilterBuilder comparison( ComparisonSpecification<?> spec, Map<String,
Object> variables )
+        {
+            return null;
+        }
+
+        public FilterBuilder contains( ContainsSpecification<?> spec, Map<String,
Object> variables )
+        {
+            return null;
+        }
+
+        public FilterBuilder containsAll( ContainsAllSpecification<?> spec, Map<String,
Object> variables )
+        {
+            return null;
+        }
+    }
+
+
+
+
+        private ElasticSearchSpatialExtensionFinder()
+    {
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/samples/openstreetmap/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/OSM.java
----------------------------------------------------------------------
diff --git a/samples/openstreetmap/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/OSM.java
b/samples/openstreetmap/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/OSM.java
new file mode 100644
index 0000000..c249034
--- /dev/null
+++ b/samples/openstreetmap/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/OSM.java
@@ -0,0 +1,7 @@
+package org.qi4j.sample.spatial.domain.openstreetmap.model.state;
+
+/**
+ * Created by jj on 01.12.14.
+ */
+public interface OSM {
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/MapEntity.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/MapEntity.java
b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/MapEntity.java
new file mode 100644
index 0000000..fe7ddfa
--- /dev/null
+++ b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/MapEntity.java
@@ -0,0 +1,7 @@
+package org.qi4j.sample.spatial.domain.openstreetmap.model;
+
+/**
+ * Created by jj on 28.11.14.
+ */
+public interface MapEntity {
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/TagEntity.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/TagEntity.java
b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/TagEntity.java
new file mode 100644
index 0000000..1175663
--- /dev/null
+++ b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/TagEntity.java
@@ -0,0 +1,7 @@
+package org.qi4j.sample.spatial.domain.openstreetmap.model;
+
+/**
+ * Created by jj on 28.11.14.
+ */
+public class TagEntity {
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/assembly/OpenStreetMapDomainModelAssembler.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/assembly/OpenStreetMapDomainModelAssembler.java
b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/assembly/OpenStreetMapDomainModelAssembler.java
new file mode 100644
index 0000000..0c5661f
--- /dev/null
+++ b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/assembly/OpenStreetMapDomainModelAssembler.java
@@ -0,0 +1,7 @@
+package org.qi4j.sample.spatial.domain.openstreetmap.model.assembly;
+
+/**
+ * Created by jj on 28.11.14.
+ */
+public class OpenStreetMapDomainModelAssembler {
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Features.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Features.java
b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Features.java
new file mode 100644
index 0000000..b6c5908
--- /dev/null
+++ b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Features.java
@@ -0,0 +1,7 @@
+package org.qi4j.sample.spatial.domain.openstreetmap.model.state;
+
+/**
+ * Created by jj on 28.11.14.
+ */
+public interface Features {
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Identifiable.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Identifiable.java
b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Identifiable.java
new file mode 100644
index 0000000..763cc9d
--- /dev/null
+++ b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Identifiable.java
@@ -0,0 +1,7 @@
+package org.qi4j.sample.spatial.domain.openstreetmap.model.state;
+
+/**
+ * Created by jj on 28.11.14.
+ */
+public interface Identifiable {
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Properties.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Properties.java
b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Properties.java
new file mode 100644
index 0000000..9dca43d
--- /dev/null
+++ b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Properties.java
@@ -0,0 +1,7 @@
+package org.qi4j.sample.spatial.domain.openstreetmap.model.state;
+
+/**
+ * Created by jj on 28.11.14.
+ */
+public interface Properties {
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/c93be181/samples/spatial/src/test/java/org/qi4j/sample/spatial/domain/openstreetmap/model/test/TestOpenStreetMapModel.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/test/java/org/qi4j/sample/spatial/domain/openstreetmap/model/test/TestOpenStreetMapModel.java
b/samples/spatial/src/test/java/org/qi4j/sample/spatial/domain/openstreetmap/model/test/TestOpenStreetMapModel.java
new file mode 100644
index 0000000..c220823
--- /dev/null
+++ b/samples/spatial/src/test/java/org/qi4j/sample/spatial/domain/openstreetmap/model/test/TestOpenStreetMapModel.java
@@ -0,0 +1,26 @@
+package org.qi4j.sample.spatial.domain.openstreetmap.model.test;
+
+import org.junit.Test;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.sample.spatial.domain.openstreetmap.model.assembly.OpenStreetMapDomainModelAssembler;
+import org.qi4j.test.AbstractQi4jTest;
+
+/**
+ * Created by jj on 28.11.14.
+ */
+public class TestOpenStreetMapModel extends AbstractQi4jTest {
+
+    @Override
+    public void assemble( ModuleAssembly module )
+            throws AssemblyException
+    {
+        new OpenStreetMapDomainModelAssembler().assemble(module);
+    }
+
+    @Test
+    public void foo()
+    {
+        System.out.println("foo");
+    }
+}


Mime
View raw message