-
Notifications
You must be signed in to change notification settings - Fork 196
Refactor layer type registration using LayerTypePresets to centralize and streamline configuration management.
#457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
api/src/main/java/org/neo4j/spatial/api/layer/LayerTypePresets.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright (c) "Neo4j" | ||
| * Neo4j Sweden AB [http://neo4j.com] | ||
| * | ||
| * This file is part of Neo4j Spatial. | ||
| * | ||
| * Neo4j is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package org.neo4j.spatial.api.layer; | ||
|
|
||
| import java.util.List; | ||
| import org.geotools.referencing.crs.AbstractCRS; | ||
| import org.neo4j.spatial.api.encoder.GeometryEncoder; | ||
| import org.neo4j.spatial.api.index.LayerIndexReader; | ||
|
|
||
| /** | ||
| * Interface that provides a mechanism for managing a collection of predefined | ||
| * layer configurations, referred to as layer-type presets. These presets define | ||
| * mappings between layer types and their corresponding properties, components | ||
| * and behaviors. | ||
| * | ||
| * <p>Implementations are discovered via {@link java.util.ServiceLoader} and must | ||
| * be registered in META-INF/services/org.neo4j.spatial.api.layer.LayerTypePresets. | ||
| * All registered presets from all implementations are combined into a single registry. | ||
| * If multiple implementations define presets with the same type name (case-insensitive), | ||
| * the last one loaded will override earlier registrations.</p> | ||
| */ | ||
| public interface LayerTypePresets { | ||
|
|
||
| List<RegisteredLayerType> getLayerTypePresets(); | ||
|
|
||
| /** | ||
| * Support mapping a String (ex: 'SimplePoint') to the respective GeometryEncoder and Layer classes | ||
| * to allow for more streamlined method for creating Layers. | ||
| */ | ||
| record RegisteredLayerType( | ||
| String typeName, | ||
| Class<? extends GeometryEncoder> geometryEncoder, | ||
| Class<? extends Layer> layerClass, | ||
| AbstractCRS crs, | ||
| Class<? extends LayerIndexReader> layerIndexClass, | ||
| String defaultConfig | ||
| ) { | ||
|
|
||
| /** | ||
| * For external expression of the configuration of this geometry encoder | ||
| * | ||
| * @return descriptive signature of encoder, type and configuration | ||
| */ | ||
| public String getSignature() { | ||
| return "RegisteredLayerType(name='" + typeName + "', geometryEncoder=" + | ||
| geometryEncoder.getSimpleName() + ", layerClass=" + layerClass.getSimpleName() + | ||
| ", index=" + layerIndexClass.getSimpleName() + | ||
| ", crs='" + crs.getName(null) + "', defaultConfig='" + defaultConfig + "')"; | ||
| } | ||
| } | ||
|
|
||
| } | ||
39 changes: 39 additions & 0 deletions
39
server-plugin/src/main/java/org/neo4j/gis/spatial/OsmSpatialLayerTypePresets.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright (c) "Neo4j" | ||
| * Neo4j Sweden AB [http://neo4j.com] | ||
| * | ||
| * This file is part of Neo4j Spatial. | ||
| * | ||
| * Neo4j is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package org.neo4j.gis.spatial; | ||
|
|
||
| import java.util.List; | ||
| import org.geotools.referencing.crs.DefaultGeographicCRS; | ||
| import org.neo4j.gis.spatial.index.LayerRTreeIndex; | ||
| import org.neo4j.gis.spatial.osm.OSMGeometryEncoder; | ||
| import org.neo4j.gis.spatial.osm.OSMLayer; | ||
| import org.neo4j.spatial.api.layer.LayerTypePresets; | ||
|
|
||
| public class OsmSpatialLayerTypePresets implements LayerTypePresets { | ||
|
|
||
| @Override | ||
| public List<RegisteredLayerType> getLayerTypePresets() { | ||
| return List.of( | ||
| new RegisteredLayerType("OSM", OSMGeometryEncoder.class, OSMLayer.class, | ||
| DefaultGeographicCRS.WGS84, LayerRTreeIndex.class, "geometry") | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
server-plugin/src/main/java/org/neo4j/gis/spatial/SpatialLayerTypePresets.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) "Neo4j" | ||
| * Neo4j Sweden AB [http://neo4j.com] | ||
| * | ||
| * This file is part of Neo4j Spatial. | ||
| * | ||
| * Neo4j is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package org.neo4j.gis.spatial; | ||
|
|
||
| import java.util.List; | ||
| import org.geotools.referencing.crs.DefaultGeographicCRS; | ||
| import org.neo4j.gis.spatial.encoders.NativePointEncoder; | ||
| import org.neo4j.gis.spatial.encoders.NativePointsEncoder; | ||
| import org.neo4j.gis.spatial.encoders.SimplePointEncoder; | ||
| import org.neo4j.gis.spatial.index.LayerGeohashPointIndex; | ||
| import org.neo4j.gis.spatial.index.LayerHilbertPointIndex; | ||
| import org.neo4j.gis.spatial.index.LayerRTreeIndex; | ||
| import org.neo4j.gis.spatial.index.LayerZOrderPointIndex; | ||
| import org.neo4j.spatial.api.layer.LayerTypePresets; | ||
|
|
||
| public class SpatialLayerTypePresets implements LayerTypePresets { | ||
|
|
||
| @Override | ||
| public List<RegisteredLayerType> getLayerTypePresets() { | ||
| return List.of( | ||
| new RegisteredLayerType("SimplePoint", SimplePointEncoder.class, | ||
| SimplePointLayer.class, DefaultGeographicCRS.WGS84, LayerRTreeIndex.class, | ||
| "longitude:latitude"), | ||
| new RegisteredLayerType("Geohash", SimplePointEncoder.class, | ||
| SimplePointLayer.class, DefaultGeographicCRS.WGS84, LayerGeohashPointIndex.class, | ||
| "longitude:latitude"), | ||
| new RegisteredLayerType("ZOrder", SimplePointEncoder.class, | ||
| SimplePointLayer.class, DefaultGeographicCRS.WGS84, LayerZOrderPointIndex.class, | ||
| "longitude:latitude"), | ||
| new RegisteredLayerType("Hilbert", SimplePointEncoder.class, | ||
| SimplePointLayer.class, DefaultGeographicCRS.WGS84, LayerHilbertPointIndex.class, | ||
| "longitude:latitude"), | ||
| new RegisteredLayerType("NativePoint", NativePointEncoder.class, | ||
| SimplePointLayer.class, DefaultGeographicCRS.WGS84, LayerRTreeIndex.class, "location"), | ||
| new RegisteredLayerType("NativePoints", NativePointsEncoder.class, | ||
| EditableLayerImpl.class, DefaultGeographicCRS.WGS84, LayerRTreeIndex.class, "geometry"), | ||
| new RegisteredLayerType("NativeGeohash", NativePointEncoder.class, | ||
| SimplePointLayer.class, DefaultGeographicCRS.WGS84, LayerGeohashPointIndex.class, "location"), | ||
| new RegisteredLayerType("NativeZOrder", NativePointEncoder.class, | ||
| SimplePointLayer.class, DefaultGeographicCRS.WGS84, LayerZOrderPointIndex.class, "location"), | ||
| new RegisteredLayerType("NativeHilbert", NativePointEncoder.class, | ||
| SimplePointLayer.class, DefaultGeographicCRS.WGS84, LayerHilbertPointIndex.class, "location"), | ||
| new RegisteredLayerType("WKT", WKTGeometryEncoder.class, EditableLayerImpl.class, | ||
| DefaultGeographicCRS.WGS84, LayerRTreeIndex.class, "geometry"), | ||
| new RegisteredLayerType("WKB", WKBGeometryEncoder.class, EditableLayerImpl.class, | ||
| DefaultGeographicCRS.WGS84, LayerRTreeIndex.class, "geometry") | ||
| ); | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
...-plugin/src/main/resources/META-INF/services/org.neo4j.spatial.api.layer.LayerTypePresets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| org.neo4j.gis.spatial.SpatialLayerTypePresets | ||
| org.neo4j.gis.spatial.OsmSpatialLayerTypePresets |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.