Skip to content

Commit

Permalink
Add dynamic mount path for OGC Features API; including dynamically mo…
Browse files Browse the repository at this point in the history
…difying hierarchy level of OGC Features endpoints based on where it is mounted.
  • Loading branch information
recalcitrantsupplant committed Oct 13, 2024
1 parent a2e633b commit 259ab49
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion prez/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def assemble_app(
app.mount("/static", StaticFiles(directory=Path(__file__).parent / "static"), name="static")
if _settings.enable_ogc_features:
app.mount(
"/catalogs/{catalogId}/collections/{recordsCollectionId}/features",
_settings.ogc_features_mount_path,
features_subapi,
)
app.include_router(base_prez_router)
Expand Down
1 change: 1 addition & 0 deletions prez/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Settings(BaseSettings):
]
enable_sparql_endpoint: bool = False
enable_ogc_features: bool = True
ogc_features_mount_path: str = "/catalogs/{catalogId}/collections/{recordsCollectionId}/features"
custom_endpoints: bool = False
configuration_mode: bool = False
temporal_predicate: Optional[URIRef] = SDO.temporal
Expand Down
4 changes: 2 additions & 2 deletions prez/reference_data/endpoints/features/features_metadata.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ ogcfeat:feature

ogcfeat:queryables-global
a ont:ListingEndpoint ;
ont:relevantShapes ex:FeatureCollections ;
ont:relevantShapes ex:QueryablesGlobal ;
.

ogcfeat:queryables-local
a ont:ListingEndpoint ;
ont:relevantShapes ex:Feature ;
ont:relevantShapes ex:QueryablesLocal ;
.
16 changes: 11 additions & 5 deletions prez/reference_data/endpoints/features/features_nodeshapes.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ex:FeatureCollections
sh:property [ sh:path void:inDataset ;
sh:class dcat:Dataset ; ] ;
sh:targetClass geo:FeatureCollection ;
ont:hierarchyLevel 3 .
ont:hierarchyLevel 1 .

ex:Feature
a sh:NodeShape ;
Expand All @@ -24,14 +24,20 @@ ex:Feature
sh:property [ sh:class dcat:Dataset ;
sh:path ( [ sh:inversePath rdfs:member ] void:inDataset ) ] ;
sh:targetClass geo:Feature ;
ont:hierarchyLevel 4 .
ont:hierarchyLevel 2 .

ex:Object
a sh:NodeShape ;
ont:hierarchyLevel 3 .
ont:hierarchyLevel 1 .

ex:Queryables
ex:QueryablesGlobal
a sh:NodeShape ;
sh:targetClass prez:Queryable ;
ont:hierarchyLevel 3 , 5
ont:hierarchyLevel 1 ;
.

ex:QueryablesLocal
a sh:NodeShape ;
sh:targetClass prez:Queryable ;
ont:hierarchyLevel 2 ;
.
19 changes: 15 additions & 4 deletions prez/services/app_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ async def generate_prefixes(repo: Repo):
async def _add_prefixes_from_graph(g):
i = 0
for i, (s, prefix) in enumerate(
g.subject_objects(
predicate=URIRef("http://purl.org/vocab/vann/preferredNamespacePrefix")
)
g.subject_objects(
predicate=URIRef("http://purl.org/vocab/vann/preferredNamespacePrefix")
)
):
namespace = g.value(
s, URIRef("http://purl.org/vocab/vann/preferredNamespaceUri")
Expand All @@ -174,8 +174,19 @@ async def create_endpoints_graph(app_state):
endpoints_root = Path(__file__).parent.parent / "reference_data/endpoints"
# OGC Features endpoints
if app_state.settings.enable_ogc_features:
features_g = Graph()
updated_hl_g = Graph()
for f in (endpoints_root / "features").glob("*.ttl"):
endpoints_graph_cache.parse(f)
features_g.parse(f)
segments = [seg for seg in app_state.settings.ogc_features_mount_path.strip('/').split('/') if seg.startswith("{")]
mount_delta = len(segments)
if mount_delta > 0:
for s, p, o in features_g.triples((None, ONT.hierarchyLevel, None)):
new_o = Literal(int(o) + mount_delta)
features_g.remove((s, p, o))
updated_hl_g.add((s, p, new_o))
endpoints_graph_cache.__iadd__(features_g)
endpoints_graph_cache.__iadd__(updated_hl_g)
# Custom data endpoints
if app_state.settings.custom_endpoints:
# first try remote, if endpoints are found, use these
Expand Down

0 comments on commit 259ab49

Please sign in to comment.