From f2c01fd316cea56b3b2d1aa1cb05527c068a4d75 Mon Sep 17 00:00:00 2001 From: "p.zahnen" Date: Tue, 12 May 2026 15:28:17 +0200 Subject: [PATCH 01/31] add configurable collection/tileset extents --- .../features/domain/CollectionExtent.java | 21 ++++++++++ .../domain/FeatureProviderDataV2.java | 16 ++++++++ .../domain/FeatureTypeConfiguration.java | 8 ++++ .../tiles/app/TileProviderFeatures.java | 40 ++++++++++++------- .../tiles/app/TileProviderHttp.java | 8 ++++ .../tiles/app/TileProviderMbTiles.java | 23 +++++++++-- .../tiles/domain/TilesetCommon.java | 9 +++++ .../tiles/domain/TilesetFeaturesDefaults.java | 22 ++++++++++ .../tiles/domain/TilesetHttpDefaults.java | 22 ++++++++++ .../tiles/domain/TilesetMbTilesDefaults.java | 21 ++++++++++ 10 files changed, 173 insertions(+), 17 deletions(-) create mode 100644 xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java new file mode 100644 index 000000000..47974c9f0 --- /dev/null +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java @@ -0,0 +1,21 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain; + +import de.ii.xtraplatform.cql.domain.Interval; +import de.ii.xtraplatform.crs.domain.BoundingBox; +import java.util.Optional; +import org.immutables.value.Value; + +/** Extent object for spatial and temporal extents. */ +@Value.Immutable +public interface CollectionExtent { + Optional getSpatial(); + + Optional getTemporal(); +} diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java index cee2fd2a1..78d1e29ec 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java @@ -261,6 +261,14 @@ default List getCql2Functions() { @Override Optional getAuto(); + /** + * @langEn Optional spatial and temporal extent for all types in this provider. If set, disables + * automatic calculation. + * @langDe Optionaler räumlicher und zeitlicher Extent für alle Types dieses Providers. Wenn + * gesetzt, wird keine automatische Berechnung durchgeführt. + */ + Optional getExtent(); + // custom builder to automatically use keys of types as name of FeatureTypeV2 abstract class Builder> implements EntityDataBuilder { @@ -310,5 +318,13 @@ public T putFragments2(String key, ImmutableFeatureSchema.Builder builder) { @JsonProperty("extensions") public abstract T addAllExtensions(Iterable elements); + + /** + * @langEn Optional spatial and temporal extent for all types in this provider. If set, disables + * automatic calculation. + * @langDe Optionaler räumlicher und zeitlicher Extent für alle Types dieses Providers. Wenn + * gesetzt, wird keine automatische Berechnung durchgeführt. + */ + public abstract T extent(CollectionExtent extent); } } diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java index 968af0820..0ea035140 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java @@ -35,4 +35,12 @@ public interface FeatureTypeConfiguration { * @default "" */ Optional getDescription(); + + /** + * @langEn Optional spatial and temporal extent for this type. If set, disables automatic + * calculation for this type. + * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Type. Wenn gesetzt, wird keine + * automatische Berechnung für diesen Type durchgeführt. + */ + Optional getExtent(); } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java index 74ffa36e5..25cdf1d9c 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java @@ -1042,20 +1042,32 @@ private TilesetMetadata loadMetadata(TilesetFeatures tileset) { getLayers(tileset).stream() .map(id -> tileGenerator.getVectorSchema(id, FeatureEncoderMVT.FORMAT)) .collect(Collectors.toList()); - Optional bounds = - getLayers(tileset).stream() - .map(tileGenerator::getBounds) - .reduce( - Optional.empty(), - (a, b) -> { - if (b.isEmpty()) { - return a; - } - if (a.isPresent()) { - return Optional.of(BoundingBox.merge(b.get(), a.get())); - } - return b; - }); + + boolean forceCompute = getData().getTilesetDefaults().getSpatialExtentComputed().orElse(false); + Optional configuredExtent = + forceCompute + ? Optional.empty() + : tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent()); + + Optional bounds; + if (configuredExtent.isPresent()) { + bounds = configuredExtent; + } else { + bounds = + getLayers(tileset).stream() + .map(tileGenerator::getBounds) + .reduce( + Optional.empty(), + (a, b) -> { + if (b.isEmpty()) { + return a; + } + if (a.isPresent()) { + return Optional.of(BoundingBox.merge(b.get(), a.get())); + } + return b; + }); + } return ImmutableTilesetMetadata.builder() .addEncodings(TilesFormat.MVT) diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java index 2a378487d..c0f592b09 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java @@ -11,6 +11,7 @@ import dagger.assisted.Assisted; import dagger.assisted.AssistedInject; import de.ii.xtraplatform.base.domain.resiliency.VolatileRegistry; +import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; import de.ii.xtraplatform.features.domain.ProviderData; @@ -114,6 +115,12 @@ private void loadMetadata() { } private TilesetMetadata loadMetadata(TilesetHttp tileset) { + boolean forceCompute = getData().getTilesetDefaults().getSpatialExtentComputed().orElse(false); + Optional bounds = + forceCompute + ? Optional.empty() + : tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent()); + return ImmutableTilesetMetadata.builder() .encodings( tileset.getEncodings().isEmpty() @@ -124,6 +131,7 @@ private TilesetMetadata loadMetadata(TilesetHttp tileset) { ? getData().getTilesetDefaults().getLevels() : tileset.getLevels()) .center(tileset.getCenter().or(() -> getData().getTilesetDefaults().getCenter())) + .bounds(bounds) .build(); } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java index bc7f3fc30..700116be9 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java @@ -175,12 +175,26 @@ private void loadMetadata(Map tilesetSources) { (key, path) -> { Tuple tilesetKey = toTuple(key); - metadata.put(tilesetKey.first(), loadMetadata(tilesetKey.second(), path)); + TilesetMbTiles tileset = + getData() + .getTilesets() + .get(tilesetKey.first()) + .mergeDefaults(getData().getTilesetDefaults()); + boolean forceCompute = + getData().getTilesetDefaults().getSpatialExtentComputed().orElse(false); + Optional configuredExtent = + forceCompute + ? Optional.empty() + : tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent()); + + metadata.put( + tilesetKey.first(), loadMetadata(tilesetKey.second(), path, configuredExtent)); tmsRanges.put(tilesetKey.first(), metadata.get(tilesetKey.first()).getTmsRanges()); }); } - private TilesetMetadata loadMetadata(String tms, Path path) { + private TilesetMetadata loadMetadata( + String tms, Path path, Optional configuredExtent) { try { MbtilesMetadata metadata = new MbtilesTileset(path, false).getMetadata(); TileMatrixSet tileMatrixSet = @@ -208,11 +222,14 @@ private TilesetMetadata loadMetadata(String tms, Path path) { tms, new ImmutableMinMax.Builder().min(minzoom).max(maxzoom).getDefault(defzoom).build()); List bbox = metadata.getBounds(); - Optional bounds = + Optional boundsFromMetadata = bbox.size() == 4 ? Optional.of( BoundingBox.of(bbox.get(0), bbox.get(1), bbox.get(2), bbox.get(3), OgcCrs.CRS84)) : Optional.empty(); + // Configured extent takes priority; fall back to bounds from MBTiles metadata + Optional bounds = + configuredExtent.isPresent() ? configuredExtent : boundsFromMetadata; TilesFormat format = metadata.getFormat(); List vectorSchemas = metadata.getVectorLayers().stream() diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java index 870bdeecb..107ab7104 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java @@ -7,6 +7,7 @@ */ package de.ii.xtraplatform.tiles.domain; +import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; import de.ii.xtraplatform.tiles.domain.ImmutableMinMax.Builder; import java.util.Optional; @@ -24,4 +25,12 @@ public interface TilesetCommon extends TilesetCommonDefaults { @Override Optional getCenter(); + + /** + * @langEn Optional fixed spatial extent for this tileset. If set, this value is used as the clip + * bounding box. + * @langDe Optionaler fester räumlicher Extent für dieses Tileset. Wenn gesetzt, wird dieser Wert + * als Clip-BoundingBox verwendet. + */ + Optional getExtent(); } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java index f650d3f42..67e574ac4 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java @@ -8,9 +8,11 @@ package de.ii.xtraplatform.tiles.domain; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import java.util.Optional; import org.immutables.value.Value; /** @@ -35,4 +37,24 @@ default ImmutableTilesetFeaturesDefaults.Builder getBuilder() { } abstract class Builder implements BuildableBuilder {} + + /** + * @langEn Optional fixed spatial extent for this tileset. If set, this value is used as the clip + * bounding box instead of computing it. + * @langDe Optionaler fester räumlicher Extent für dieses Tileset. Wenn gesetzt, wird dieser Wert + * als Clip-BoundingBox verwendet, statt ihn zu berechnen. + */ + Optional getExtent(); + + /** + * @langEn If true, the spatial extent will always be computed from data, even if a fixed value is + * set globally. If false, a fixed value is always used. If not set, the global or provider + * logic applies. + * @langDe Wenn true, wird der räumliche Extent immer aus den Daten berechnet, auch wenn global + * ein fester Wert gesetzt ist. Wenn false, wird immer ein fixer Wert verwendet. Wenn nicht + * gesetzt, gilt die globale oder Provider-Logik. + */ + default Optional getSpatialExtentComputed() { + return Optional.empty(); + } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java index acd094cd5..93da07a24 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java @@ -8,9 +8,11 @@ package de.ii.xtraplatform.tiles.domain; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import java.util.Optional; import org.immutables.value.Value; /** @@ -31,5 +33,25 @@ default ImmutableTilesetHttpDefaults.Builder getBuilder() { return new ImmutableTilesetHttpDefaults.Builder().from(this); } + /** + * @langEn Optional fixed spatial extent for this tileset. If set, this value is used as the clip + * bounding box instead of falling back to TileMatrixSet bounds. + * @langDe Optionaler fester räumlicher Extent für dieses Tileset. Wenn gesetzt, wird dieser Wert + * als Clip-BoundingBox verwendet, statt auf TileMatrixSet-Bounds zurückzufallen. + */ + Optional getExtent(); + + /** + * @langEn If true, the spatial extent will always be computed from data, even if a fixed value is + * set globally. If false, a fixed value is always used. If not set, the global or provider + * logic applies. + * @langDe Wenn true, wird der räumliche Extent immer aus den Daten berechnet, auch wenn global + * ein fester Wert gesetzt ist. Wenn false, wird immer ein fixer Wert verwendet. Wenn nicht + * gesetzt, gilt die globale oder Provider-Logik. + */ + default Optional getSpatialExtentComputed() { + return Optional.empty(); + } + abstract class Builder implements BuildableBuilder {} } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java index ab183c13f..8f51b6fa6 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java @@ -8,6 +8,7 @@ package de.ii.xtraplatform.tiles.domain; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.docs.DocIgnore; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; import de.ii.xtraplatform.tiles.domain.ImmutableMinMax.Builder; @@ -36,4 +37,24 @@ public interface TilesetMbTilesDefaults extends TilesetCommonDefaults { default String getTileMatrixSet() { return "WebMercatorQuad"; } + + /** + * @langEn Optional fixed spatial extent for this tileset. If set, this value is used as the clip + * bounding box instead of falling back to MBTiles metadata. + * @langDe Optionaler fester räumlicher Extent für dieses Tileset. Wenn gesetzt, wird dieser Wert + * als Clip-BoundingBox verwendet, statt auf MBTiles-Metadaten zurückzufallen. + */ + Optional getExtent(); + + /** + * @langEn If true, the spatial extent will always be computed from data, even if a fixed value is + * set globally. If false, a fixed value is always used. If not set, the global or provider + * logic applies. + * @langDe Wenn true, wird der räumliche Extent immer aus den Daten berechnet, auch wenn global + * ein fester Wert gesetzt ist. Wenn false, wird immer ein fixer Wert verwendet. Wenn nicht + * gesetzt, gilt die globale oder Provider-Logik. + */ + default Optional getSpatialExtentComputed() { + return Optional.empty(); + } } From 89df02b067adc80d7756ddf552ee448588a20d49 Mon Sep 17 00:00:00 2001 From: "p.zahnen" Date: Fri, 15 May 2026 13:01:47 +0200 Subject: [PATCH 02/31] add TemporalExtent and include extent in FeatureSchema --- .../features/domain/CollectionExtent.java | 5 ++-- .../features/domain/FeatureSchema.java | 8 ++++++ .../features/domain/TemporalExtent.java | 28 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java index 47974c9f0..cc0d7d7e6 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java @@ -7,15 +7,16 @@ */ package de.ii.xtraplatform.features.domain; -import de.ii.xtraplatform.cql.domain.Interval; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import de.ii.xtraplatform.crs.domain.BoundingBox; import java.util.Optional; import org.immutables.value.Value; /** Extent object for spatial and temporal extents. */ @Value.Immutable +@JsonDeserialize(builder = ImmutableCollectionExtent.Builder.class) public interface CollectionExtent { Optional getSpatial(); - Optional getTemporal(); + Optional getTemporal(); } diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java index 309957177..05f977d57 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java @@ -401,6 +401,14 @@ default Type getType() { */ Optional getDescription(); + /** + * @langEn Optional spatial and temporal extent for this feature type. If set, automatic + * calculation for this type can be skipped by consuming applications. + * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Feature-Type. Wenn gesetzt, kann + * die automatische Berechnung für diesen Type in konsumierenden Anwendungen entfallen. + */ + Optional getExtent(); + /** * @langEn The unit of measurement of the value, only relevant for numeric properties. * @langDe Die Maßeinheit des Wertes, nur relevant bei numerischen Eigenschaften. diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java new file mode 100644 index 000000000..87b237ccb --- /dev/null +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java @@ -0,0 +1,28 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import javax.annotation.Nullable; +import org.immutables.value.Value; + +/** Temporal extent with start and end as Unix timestamp in milliseconds. */ +@Value.Immutable +@JsonDeserialize(builder = ImmutableTemporalExtent.Builder.class) +public interface TemporalExtent { + + /** + * Start of the temporal extent as Unix timestamp in milliseconds, or {@code null} for open start. + */ + @Nullable + Long getStart(); + + /** End of the temporal extent as Unix timestamp in milliseconds, or {@code null} for open end. */ + @Nullable + Long getEnd(); +} From df7a23fa418d26c5351e9fc0d6ec3440a1058e2d Mon Sep 17 00:00:00 2001 From: "p.zahnen" Date: Wed, 20 May 2026 19:12:10 +0200 Subject: [PATCH 03/31] add spatial/temporal extent types and usage --- .../features/gml/app/FeatureProviderWfs.java | 86 +++++++++++++++++- .../graphql/app/FeatureProviderGraphQl.java | 87 ++++++++++++++++++- .../sql/domain/FeatureProviderSql.java | 86 ++++++++++++++++++ .../domain/FeatureProviderDataV2.java | 10 +-- .../features/domain/FeatureSchema.java | 8 +- .../domain/FeatureTypeConfiguration.java | 2 +- ...tionExtent.java => FeatureTypeExtent.java} | 7 +- .../features/domain/SpatialExtent.java | 66 ++++++++++++++ .../features/domain/TemporalExtent.java | 55 ++++++++++-- .../tiles/app/TileProviderFeatures.java | 46 +++++++++- .../tiles/app/TileProviderHttp.java | 34 +++++++- .../tiles/app/TileProviderMbTiles.java | 35 ++++++-- .../tiles/domain/TilesetCommon.java | 10 +-- .../tiles/domain/TilesetFeaturesDefaults.java | 22 +---- .../tiles/domain/TilesetHttpDefaults.java | 22 +---- .../tiles/domain/TilesetMbTilesDefaults.java | 22 +---- 16 files changed, 494 insertions(+), 104 deletions(-) rename xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/{CollectionExtent.java => FeatureTypeExtent.java} (74%) create mode 100644 xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java diff --git a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java index a4e3f57e9..69e24f9df 100644 --- a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java +++ b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java @@ -45,11 +45,14 @@ import de.ii.xtraplatform.features.domain.FeatureStream; import de.ii.xtraplatform.features.domain.FeatureStreamImpl; import de.ii.xtraplatform.features.domain.FeatureTokenDecoder; +import de.ii.xtraplatform.features.domain.FeatureTypeExtent; import de.ii.xtraplatform.features.domain.Metadata; import de.ii.xtraplatform.features.domain.ProviderData; import de.ii.xtraplatform.features.domain.ProviderExtensionRegistry; import de.ii.xtraplatform.features.domain.Query; import de.ii.xtraplatform.features.domain.SchemaMapping; +import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.TemporalExtent; import de.ii.xtraplatform.features.domain.transform.OnlyQueryables; import de.ii.xtraplatform.features.domain.transform.OnlySortables; import de.ii.xtraplatform.features.gml.domain.FeatureProviderWfsData; @@ -60,6 +63,7 @@ import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; import jakarta.ws.rs.core.MediaType; +import java.time.OffsetDateTime; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.List; import java.util.Map; @@ -299,10 +303,15 @@ public FeatureSchema getSortablesSchema( @Override public Optional getSpatialExtent(String typeName) { - if (getData().getTypes().containsKey(typeName)) { + if (!getData().getTypes().containsKey(typeName)) { return Optional.empty(); } + Optional configured = getConfiguredSpatialExtent(typeName); + if (configured.isPresent()) { + return configured; + } + try { Stream> extentGraph = aggregateStatsReader.getSpatialExtent( @@ -340,7 +349,80 @@ public Optional getSpatialExtent(String typeName, EpsgCrs crs) { @Override public Optional getTemporalExtent(String typeName) { - return Optional.empty(); + if (!getData().getTypes().containsKey(typeName)) { + return Optional.empty(); + } + + return getConfiguredTemporalExtent(typeName); + } + + private Optional getConfiguredSpatialExtent(String typeName) { + Optional fromType = + Optional.ofNullable(getData().getTypes().get(typeName)) + .flatMap(FeatureSchema::getExtent) + .flatMap(FeatureTypeExtent::getSpatial); + Optional fromProvider = + getData().getExtent().flatMap(FeatureTypeExtent::getSpatial); + + return fromType + .or(() -> fromProvider) + .filter(extent -> extent.getComputed() == null) + .flatMap( + extent -> { + if (extent.getXmin() == null + || extent.getYmin() == null + || extent.getXmax() == null + || extent.getYmax() == null) { + return Optional.empty(); + } + EpsgCrs nativeCrs = getData().getNativeCrs().orElse(OgcCrs.CRS84); + if (extent.getZmin() != null && extent.getZmax() != null) { + return Optional.of( + BoundingBox.of( + extent.getXmin(), + extent.getYmin(), + extent.getZmin(), + extent.getXmax(), + extent.getYmax(), + extent.getZmax(), + nativeCrs)); + } + return Optional.of( + BoundingBox.of( + extent.getXmin(), + extent.getYmin(), + extent.getXmax(), + extent.getYmax(), + nativeCrs)); + }); + } + + private Optional getConfiguredTemporalExtent(String typeName) { + Optional fromType = + Optional.ofNullable(getData().getTypes().get(typeName)) + .flatMap(FeatureSchema::getExtent) + .flatMap(FeatureTypeExtent::getTemporal); + Optional fromProvider = + getData().getExtent().flatMap(FeatureTypeExtent::getTemporal); + + return fromType + .or(() -> fromProvider) + .filter(extent -> extent.getComputed() == null) + .flatMap( + extent -> { + if (extent.getStart() == null && extent.getEnd() == null) { + return Optional.empty(); + } + OffsetDateTime start = + extent.getStart() != null + ? OffsetDateTime.parse(extent.getStart()) + : OffsetDateTime.parse("0001-01-01T00:00:00Z"); + OffsetDateTime end = + extent.getEnd() != null + ? OffsetDateTime.parse(extent.getEnd()) + : OffsetDateTime.parse("9999-12-31T23:59:59Z"); + return Optional.of(Interval.of(start.toInstant(), end.toInstant())); + }); } @Override diff --git a/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java b/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java index 1b3ed8b32..c16ddaf5e 100644 --- a/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java +++ b/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java @@ -41,11 +41,14 @@ import de.ii.xtraplatform.features.domain.FeatureQueryEncoder; import de.ii.xtraplatform.features.domain.FeatureSchema; import de.ii.xtraplatform.features.domain.FeatureTokenDecoder; +import de.ii.xtraplatform.features.domain.FeatureTypeExtent; import de.ii.xtraplatform.features.domain.Metadata; import de.ii.xtraplatform.features.domain.ProviderData; import de.ii.xtraplatform.features.domain.ProviderExtensionRegistry; import de.ii.xtraplatform.features.domain.Query; import de.ii.xtraplatform.features.domain.SchemaMapping; +import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.TemporalExtent; import de.ii.xtraplatform.features.domain.transform.OnlyQueryables; import de.ii.xtraplatform.features.domain.transform.OnlySortables; import de.ii.xtraplatform.features.graphql.domain.FeatureProviderGraphQlData; @@ -54,6 +57,7 @@ import de.ii.xtraplatform.streams.domain.Reactive; import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; +import java.time.OffsetDateTime; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.List; import java.util.Map; @@ -312,7 +316,7 @@ public boolean is3dSupported() { @Override @SuppressWarnings("PMD.AvoidCatchingGenericException") public long getFeatureCount(String typeName) { - if (getData().getTypes().containsKey(typeName)) { + if (!getData().getTypes().containsKey(typeName)) { return -1; } @@ -358,10 +362,15 @@ public FeatureSchema getSortablesSchema( @Override @SuppressWarnings("PMD.AvoidCatchingGenericException") public Optional getSpatialExtent(String typeName) { - if (getData().getTypes().containsKey(typeName)) { + if (!getData().getTypes().containsKey(typeName)) { return Optional.empty(); } + Optional configured = getConfiguredSpatialExtent(typeName); + if (configured.isPresent()) { + return configured; + } + try { Stream> extentGraph = aggregateStatsReader.getSpatialExtent( @@ -399,7 +408,79 @@ public Optional getSpatialExtent(String typeName, EpsgCrs crs) { @Override public Optional getTemporalExtent(String typeName) { - return Optional.empty(); + if (!getData().getTypes().containsKey(typeName)) { + return Optional.empty(); + } + return getConfiguredTemporalExtent(typeName); + } + + private Optional getConfiguredSpatialExtent(String typeName) { + Optional fromType = + Optional.ofNullable(getData().getTypes().get(typeName)) + .flatMap(FeatureSchema::getExtent) + .flatMap(FeatureTypeExtent::getSpatial); + Optional fromProvider = + getData().getExtent().flatMap(FeatureTypeExtent::getSpatial); + + return fromType + .or(() -> fromProvider) + .filter(extent -> extent.getComputed() == null) + .flatMap( + extent -> { + if (extent.getXmin() == null + || extent.getYmin() == null + || extent.getXmax() == null + || extent.getYmax() == null) { + return Optional.empty(); + } + EpsgCrs nativeCrs = getData().getNativeCrs().orElse(OgcCrs.CRS84); + if (extent.getZmin() != null && extent.getZmax() != null) { + return Optional.of( + BoundingBox.of( + extent.getXmin(), + extent.getYmin(), + extent.getZmin(), + extent.getXmax(), + extent.getYmax(), + extent.getZmax(), + nativeCrs)); + } + return Optional.of( + BoundingBox.of( + extent.getXmin(), + extent.getYmin(), + extent.getXmax(), + extent.getYmax(), + nativeCrs)); + }); + } + + private Optional getConfiguredTemporalExtent(String typeName) { + Optional fromType = + Optional.ofNullable(getData().getTypes().get(typeName)) + .flatMap(FeatureSchema::getExtent) + .flatMap(FeatureTypeExtent::getTemporal); + Optional fromProvider = + getData().getExtent().flatMap(FeatureTypeExtent::getTemporal); + + return fromType + .or(() -> fromProvider) + .filter(extent -> extent.getComputed() == null) + .flatMap( + extent -> { + if (extent.getStart() == null && extent.getEnd() == null) { + return Optional.empty(); + } + OffsetDateTime start = + extent.getStart() != null + ? OffsetDateTime.parse(extent.getStart()) + : OffsetDateTime.parse("0001-01-01T00:00:00Z"); + OffsetDateTime end = + extent.getEnd() != null + ? OffsetDateTime.parse(extent.getEnd()) + : OffsetDateTime.parse("9999-12-31T23:59:59Z"); + return Optional.of(Interval.of(start.toInstant(), end.toInstant())); + }); } @Override diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index 45dc7e82e..d919876fe 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -76,6 +76,8 @@ import de.ii.xtraplatform.features.domain.SchemaMapping; import de.ii.xtraplatform.features.domain.SortKey; import de.ii.xtraplatform.features.domain.SourceSchemaValidator; +import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.TemporalExtent; import de.ii.xtraplatform.features.domain.transform.OnlyQueryables; import de.ii.xtraplatform.features.domain.transform.OnlySortables; import de.ii.xtraplatform.features.domain.transform.PropertyTransformations; @@ -105,6 +107,7 @@ import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; import java.sql.SQLException; +import java.time.OffsetDateTime; import java.time.ZoneId; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; @@ -1072,6 +1075,11 @@ public Optional getSpatialExtent(String typeName) { return Optional.empty(); } + Optional configured = getConfiguredSpatialExtent(typeName); + if (configured.isPresent()) { + return configured; + } + String[] cacheKey = {typeName, CACHE_KEY_STATS, "spatial"}; String cacheValidator = getData().getStableHash(); @@ -1149,6 +1157,11 @@ public Optional getTemporalExtent(String typeName) { return Optional.empty(); } + Optional configured = getConfiguredTemporalExtent(typeName); + if (configured.isPresent()) { + return configured; + } + String[] cacheKey = {typeName, CACHE_KEY_STATS, "temporal"}; String cacheValidator = getData().getStableHash(); @@ -1224,6 +1237,79 @@ public Optional getTemporalExtent(String typeName) { return Optional.empty(); } + private Optional getConfiguredSpatialExtent(String typeName) { + Optional fromType = + Optional.ofNullable(getData().getTypes().get(typeName)) + .flatMap(FeatureSchema::getExtent) + .flatMap(de.ii.xtraplatform.features.domain.FeatureTypeExtent::getSpatial); + Optional fromProvider = + getData() + .getExtent() + .flatMap(de.ii.xtraplatform.features.domain.FeatureTypeExtent::getSpatial); + + return fromType + .or(() -> fromProvider) + .filter(extent -> extent.getComputed() == null) + .flatMap( + extent -> { + if (extent.getXmin() == null + || extent.getYmin() == null + || extent.getXmax() == null + || extent.getYmax() == null) { + return Optional.empty(); + } + EpsgCrs nativeCrs = getData().getNativeCrs().orElse(OgcCrs.CRS84); + if (extent.getZmin() != null && extent.getZmax() != null) { + return Optional.of( + BoundingBox.of( + extent.getXmin(), + extent.getYmin(), + extent.getZmin(), + extent.getXmax(), + extent.getYmax(), + extent.getZmax(), + nativeCrs)); + } + return Optional.of( + BoundingBox.of( + extent.getXmin(), + extent.getYmin(), + extent.getXmax(), + extent.getYmax(), + nativeCrs)); + }); + } + + private Optional getConfiguredTemporalExtent(String typeName) { + Optional fromType = + Optional.ofNullable(getData().getTypes().get(typeName)) + .flatMap(FeatureSchema::getExtent) + .flatMap(de.ii.xtraplatform.features.domain.FeatureTypeExtent::getTemporal); + Optional fromProvider = + getData() + .getExtent() + .flatMap(de.ii.xtraplatform.features.domain.FeatureTypeExtent::getTemporal); + + return fromType + .or(() -> fromProvider) + .filter(extent -> extent.getComputed() == null) + .flatMap( + extent -> { + if (extent.getStart() == null && extent.getEnd() == null) { + return Optional.empty(); + } + OffsetDateTime start = + extent.getStart() != null + ? OffsetDateTime.parse(extent.getStart()) + : OffsetDateTime.parse("0001-01-01T00:00:00Z"); + OffsetDateTime end = + extent.getEnd() != null + ? OffsetDateTime.parse(extent.getEnd()) + : OffsetDateTime.parse("9999-12-31T23:59:59Z"); + return Optional.of(Interval.of(start.toInstant(), end.toInstant())); + }); + } + // NOPMD - TODO: cache deser does not work, because the the feature schemas have no name // (and there are no map keys to get them from) // so to implement this we need the split between cfg and internal schemas diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java index 78d1e29ec..6394fe7c9 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java @@ -267,7 +267,7 @@ default List getCql2Functions() { * @langDe Optionaler räumlicher und zeitlicher Extent für alle Types dieses Providers. Wenn * gesetzt, wird keine automatische Berechnung durchgeführt. */ - Optional getExtent(); + Optional getExtent(); // custom builder to automatically use keys of types as name of FeatureTypeV2 abstract class Builder> implements EntityDataBuilder { @@ -318,13 +318,5 @@ public T putFragments2(String key, ImmutableFeatureSchema.Builder builder) { @JsonProperty("extensions") public abstract T addAllExtensions(Iterable elements); - - /** - * @langEn Optional spatial and temporal extent for all types in this provider. If set, disables - * automatic calculation. - * @langDe Optionaler räumlicher und zeitlicher Extent für alle Types dieses Providers. Wenn - * gesetzt, wird keine automatische Berechnung durchgeführt. - */ - public abstract T extent(CollectionExtent extent); } } diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java index 05f977d57..525021bc2 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java @@ -402,12 +402,10 @@ default Type getType() { Optional getDescription(); /** - * @langEn Optional spatial and temporal extent for this feature type. If set, automatic - * calculation for this type can be skipped by consuming applications. - * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Feature-Type. Wenn gesetzt, kann - * die automatische Berechnung für diesen Type in konsumierenden Anwendungen entfallen. + * @langEn Optional spatial and temporal extent for this feature type. + * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Feature-Type. */ - Optional getExtent(); + Optional getExtent(); /** * @langEn The unit of measurement of the value, only relevant for numeric properties. diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java index 0ea035140..6d0c2f816 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java @@ -42,5 +42,5 @@ public interface FeatureTypeConfiguration { * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Type. Wenn gesetzt, wird keine * automatische Berechnung für diesen Type durchgeführt. */ - Optional getExtent(); + Optional getExtent(); } diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java similarity index 74% rename from xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java rename to xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java index cc0d7d7e6..bfe1a1110 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/CollectionExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java @@ -8,15 +8,14 @@ package de.ii.xtraplatform.features.domain; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import de.ii.xtraplatform.crs.domain.BoundingBox; import java.util.Optional; import org.immutables.value.Value; /** Extent object for spatial and temporal extents. */ @Value.Immutable -@JsonDeserialize(builder = ImmutableCollectionExtent.Builder.class) -public interface CollectionExtent { - Optional getSpatial(); +@JsonDeserialize(builder = ImmutableFeatureTypeExtent.Builder.class) +public interface FeatureTypeExtent { + Optional getSpatial(); Optional getTemporal(); } diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java new file mode 100644 index 000000000..2623b8081 --- /dev/null +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java @@ -0,0 +1,66 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.common.base.Preconditions; +import javax.annotation.Nullable; +import org.immutables.value.Value; + +/** Spatial extent in native CRS. */ +@Value.Immutable +@JsonDeserialize(builder = ImmutableSpatialExtent.Builder.class) +public interface SpatialExtent { + + @Nullable + Double getXmin(); + + @Nullable + Double getYmin(); + + @Nullable + Double getZmin(); + + @Nullable + Double getXmax(); + + @Nullable + Double getYmax(); + + @Nullable + Double getZmax(); + + @Nullable + Boolean getComputed(); + + @Value.Check + default void checkExclusiveComputed() { + boolean hasCoordinates = + getXmin() != null + || getYmin() != null + || getZmin() != null + || getXmax() != null + || getYmax() != null + || getZmax() != null; + boolean hasComputed = getComputed() != null; + + Preconditions.checkState( + !(hasCoordinates && hasComputed), + "SpatialExtent: 'computed' and explicit coordinates must not be set at the same time."); + + if (hasCoordinates) { + Preconditions.checkState( + getXmin() != null && getYmin() != null && getXmax() != null && getYmax() != null, + "SpatialExtent: xmin, ymin, xmax, ymax are required when coordinates are used."); + + Preconditions.checkState( + (getZmin() == null && getZmax() == null) || (getZmin() != null && getZmax() != null), + "SpatialExtent: zmin and zmax must both be set or both be absent."); + } + } +} diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java index 87b237ccb..b595487f3 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java @@ -8,21 +8,62 @@ package de.ii.xtraplatform.features.domain; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.common.base.Preconditions; +import java.time.LocalDate; +import java.time.format.DateTimeParseException; import javax.annotation.Nullable; import org.immutables.value.Value; -/** Temporal extent with start and end as Unix timestamp in milliseconds. */ +/** Temporal extent with ISO-8601 dates (yyyy-MM-dd). */ @Value.Immutable @JsonDeserialize(builder = ImmutableTemporalExtent.Builder.class) public interface TemporalExtent { - /** - * Start of the temporal extent as Unix timestamp in milliseconds, or {@code null} for open start. - */ + /** Start of the temporal extent as ISO-8601 date (yyyy-MM-dd), or {@code null} for open start. */ @Nullable - Long getStart(); + String getStart(); - /** End of the temporal extent as Unix timestamp in milliseconds, or {@code null} for open end. */ + /** End of the temporal extent as ISO-8601 date (yyyy-MM-dd), or {@code null} for open end. */ @Nullable - Long getEnd(); + String getEnd(); + + @Nullable + Boolean getComputed(); + + @Value.Check + default void checkExclusiveComputed() { + boolean hasBounds = getStart() != null || getEnd() != null; + boolean hasComputed = getComputed() != null; + + Preconditions.checkState( + !(hasBounds && hasComputed), + "TemporalExtent: 'computed' and explicit start/end must not be set at the same time."); + + if (getStart() != null) { + validateIsoDate(getStart(), "start"); + } + if (getEnd() != null) { + validateIsoDate(getEnd(), "end"); + } + } + + private static void validateIsoDate(String value, String field) { + Preconditions.checkState( + !value.matches("^-?\\d+$"), + "TemporalExtent: '%s' must be an ISO date string (yyyy-MM-dd), not a numeric timestamp.", + field); + Preconditions.checkState( + !value.contains("T"), + "TemporalExtent: '%s' must be an ISO date string (yyyy-MM-dd), timestamps are not allowed.", + field); + try { + LocalDate.parse(value); + } catch (DateTimeParseException e) { + Preconditions.checkState( + false, + "TemporalExtent: '%s' is not a valid ISO-8601 date (yyyy-MM-dd): %s", + field, + value); + } + } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java index 25cdf1d9c..146b435da 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java @@ -26,6 +26,8 @@ import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.crs.domain.CrsInfo; import de.ii.xtraplatform.crs.domain.CrsTransformerFactory; +import de.ii.xtraplatform.crs.domain.EpsgCrs; +import de.ii.xtraplatform.crs.domain.OgcCrs; import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; import de.ii.xtraplatform.entities.domain.EntityRegistry; @@ -37,6 +39,8 @@ import de.ii.xtraplatform.features.domain.FeatureProvider.FeatureVolatileCapability; import de.ii.xtraplatform.features.domain.FeatureSchema; import de.ii.xtraplatform.features.domain.ProviderData; +import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.jobs.domain.JobQueue; import de.ii.xtraplatform.tiles.domain.Cache; import de.ii.xtraplatform.tiles.domain.Cache.Storage; import de.ii.xtraplatform.tiles.domain.Cache.Type; @@ -1043,11 +1047,9 @@ private TilesetMetadata loadMetadata(TilesetFeatures tileset) { .map(id -> tileGenerator.getVectorSchema(id, FeatureEncoderMVT.FORMAT)) .collect(Collectors.toList()); - boolean forceCompute = getData().getTilesetDefaults().getSpatialExtentComputed().orElse(false); Optional configuredExtent = - forceCompute - ? Optional.empty() - : tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent()); + toBoundingBox( + tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent()), tileset); Optional bounds; if (configuredExtent.isPresent()) { @@ -1179,4 +1181,40 @@ private List getFeatureProviders() { private String getFeatureProviderId(TilesetFeatures tileset) { return tileset.getFeatureProvider().orElse(clean(getData().getId())); } + + private Optional toBoundingBox( + Optional extent, TilesetFeatures tileset) { + EpsgCrs nativeCrs = resolveNativeCrs(tileset); + return extent + .filter(e -> e.getComputed() == null) + .flatMap( + e -> { + if (e.getXmin() == null + || e.getYmin() == null + || e.getXmax() == null + || e.getYmax() == null) { + return Optional.empty(); + } + if (e.getZmin() != null && e.getZmax() != null) { + return Optional.of( + BoundingBox.of( + e.getXmin(), + e.getYmin(), + e.getZmin(), + e.getXmax(), + e.getYmax(), + e.getZmax(), + nativeCrs)); + } + return Optional.of( + BoundingBox.of(e.getXmin(), e.getYmin(), e.getXmax(), e.getYmax(), nativeCrs)); + }); + } + + private EpsgCrs resolveNativeCrs(TilesetFeatures tileset) { + return tileGenerator + .getFeatureProvider(getFeatureProviderId(tileset)) + .map(provider -> provider.crs().get().getNativeCrs()) + .orElse(OgcCrs.CRS84); + } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java index c0f592b09..faed2c4a7 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java @@ -12,9 +12,11 @@ import dagger.assisted.AssistedInject; import de.ii.xtraplatform.base.domain.resiliency.VolatileRegistry; import de.ii.xtraplatform.crs.domain.BoundingBox; +import de.ii.xtraplatform.crs.domain.OgcCrs; import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; import de.ii.xtraplatform.features.domain.ProviderData; +import de.ii.xtraplatform.features.domain.SpatialExtent; import de.ii.xtraplatform.tiles.domain.ChainedTileProvider; import de.ii.xtraplatform.tiles.domain.ImmutableTilesetMetadata; import de.ii.xtraplatform.tiles.domain.TileProviderData; @@ -115,11 +117,8 @@ private void loadMetadata() { } private TilesetMetadata loadMetadata(TilesetHttp tileset) { - boolean forceCompute = getData().getTilesetDefaults().getSpatialExtentComputed().orElse(false); Optional bounds = - forceCompute - ? Optional.empty() - : tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent()); + toBoundingBox(tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent())); return ImmutableTilesetMetadata.builder() .encodings( @@ -134,4 +133,31 @@ private TilesetMetadata loadMetadata(TilesetHttp tileset) { .bounds(bounds) .build(); } + + private Optional toBoundingBox(Optional extent) { + return extent + .filter(e -> e.getComputed() == null) + .flatMap( + e -> { + if (e.getXmin() == null + || e.getYmin() == null + || e.getXmax() == null + || e.getYmax() == null) { + return Optional.empty(); + } + if (e.getZmin() != null && e.getZmax() != null) { + return Optional.of( + BoundingBox.of( + e.getXmin(), + e.getYmin(), + e.getZmin(), + e.getXmax(), + e.getYmax(), + e.getZmax(), + OgcCrs.CRS84)); + } + return Optional.of( + BoundingBox.of(e.getXmin(), e.getYmin(), e.getXmax(), e.getYmax(), OgcCrs.CRS84)); + }); + } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java index 700116be9..52f30db59 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java @@ -20,6 +20,7 @@ import de.ii.xtraplatform.entities.domain.Entity.SubType; import de.ii.xtraplatform.features.domain.FeatureSchema; import de.ii.xtraplatform.features.domain.ProviderData; +import de.ii.xtraplatform.features.domain.SpatialExtent; import de.ii.xtraplatform.tiles.domain.ChainedTileProvider; import de.ii.xtraplatform.tiles.domain.ImmutableMinMax; import de.ii.xtraplatform.tiles.domain.ImmutableTilesetMetadata; @@ -180,12 +181,9 @@ private void loadMetadata(Map tilesetSources) { .getTilesets() .get(tilesetKey.first()) .mergeDefaults(getData().getTilesetDefaults()); - boolean forceCompute = - getData().getTilesetDefaults().getSpatialExtentComputed().orElse(false); Optional configuredExtent = - forceCompute - ? Optional.empty() - : tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent()); + toBoundingBox( + tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent())); metadata.put( tilesetKey.first(), loadMetadata(tilesetKey.second(), path, configuredExtent)); @@ -257,4 +255,31 @@ private Tuple toTuple(String tilesetKey) { String[] split = tilesetKey.split("/"); return Tuple.of(split[0], split[1]); } + + private Optional toBoundingBox(Optional extent) { + return extent + .filter(e -> e.getComputed() == null) + .flatMap( + e -> { + if (e.getXmin() == null + || e.getYmin() == null + || e.getXmax() == null + || e.getYmax() == null) { + return Optional.empty(); + } + if (e.getZmin() != null && e.getZmax() != null) { + return Optional.of( + BoundingBox.of( + e.getXmin(), + e.getYmin(), + e.getZmin(), + e.getXmax(), + e.getYmax(), + e.getZmax(), + OgcCrs.CRS84)); + } + return Optional.of( + BoundingBox.of(e.getXmin(), e.getYmin(), e.getXmax(), e.getYmax(), OgcCrs.CRS84)); + }); + } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java index 107ab7104..49ca3bb45 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java @@ -7,8 +7,8 @@ */ package de.ii.xtraplatform.tiles.domain; -import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import de.ii.xtraplatform.features.domain.SpatialExtent; import de.ii.xtraplatform.tiles.domain.ImmutableMinMax.Builder; import java.util.Optional; @@ -27,10 +27,8 @@ public interface TilesetCommon extends TilesetCommonDefaults { Optional getCenter(); /** - * @langEn Optional fixed spatial extent for this tileset. If set, this value is used as the clip - * bounding box. - * @langDe Optionaler fester räumlicher Extent für dieses Tileset. Wenn gesetzt, wird dieser Wert - * als Clip-BoundingBox verwendet. + * @langEn Optional fixed spatial extent for this tileset in native CRS. + * @langDe Optionaler fester räumlicher Extent für dieses Tileset im nativen CRS. */ - Optional getExtent(); + Optional getExtent(); } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java index 67e574ac4..2941a408f 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java @@ -8,10 +8,10 @@ package de.ii.xtraplatform.tiles.domain; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import de.ii.xtraplatform.features.domain.SpatialExtent; import java.util.Optional; import org.immutables.value.Value; @@ -39,22 +39,8 @@ default ImmutableTilesetFeaturesDefaults.Builder getBuilder() { abstract class Builder implements BuildableBuilder {} /** - * @langEn Optional fixed spatial extent for this tileset. If set, this value is used as the clip - * bounding box instead of computing it. - * @langDe Optionaler fester räumlicher Extent für dieses Tileset. Wenn gesetzt, wird dieser Wert - * als Clip-BoundingBox verwendet, statt ihn zu berechnen. + * @langEn Optional fixed spatial extent for this tileset in native CRS. + * @langDe Optionaler fester räumlicher Extent für dieses Tileset im nativen CRS. */ - Optional getExtent(); - - /** - * @langEn If true, the spatial extent will always be computed from data, even if a fixed value is - * set globally. If false, a fixed value is always used. If not set, the global or provider - * logic applies. - * @langDe Wenn true, wird der räumliche Extent immer aus den Daten berechnet, auch wenn global - * ein fester Wert gesetzt ist. Wenn false, wird immer ein fixer Wert verwendet. Wenn nicht - * gesetzt, gilt die globale oder Provider-Logik. - */ - default Optional getSpatialExtentComputed() { - return Optional.empty(); - } + Optional getExtent(); } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java index 93da07a24..9c9250e94 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java @@ -8,10 +8,10 @@ package de.ii.xtraplatform.tiles.domain; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import de.ii.xtraplatform.features.domain.SpatialExtent; import java.util.Optional; import org.immutables.value.Value; @@ -34,24 +34,10 @@ default ImmutableTilesetHttpDefaults.Builder getBuilder() { } /** - * @langEn Optional fixed spatial extent for this tileset. If set, this value is used as the clip - * bounding box instead of falling back to TileMatrixSet bounds. - * @langDe Optionaler fester räumlicher Extent für dieses Tileset. Wenn gesetzt, wird dieser Wert - * als Clip-BoundingBox verwendet, statt auf TileMatrixSet-Bounds zurückzufallen. + * @langEn Optional fixed spatial extent for this tileset in native CRS. + * @langDe Optionaler fester räumlicher Extent für dieses Tileset im nativen CRS. */ - Optional getExtent(); - - /** - * @langEn If true, the spatial extent will always be computed from data, even if a fixed value is - * set globally. If false, a fixed value is always used. If not set, the global or provider - * logic applies. - * @langDe Wenn true, wird der räumliche Extent immer aus den Daten berechnet, auch wenn global - * ein fester Wert gesetzt ist. Wenn false, wird immer ein fixer Wert verwendet. Wenn nicht - * gesetzt, gilt die globale oder Provider-Logik. - */ - default Optional getSpatialExtentComputed() { - return Optional.empty(); - } + Optional getExtent(); abstract class Builder implements BuildableBuilder {} } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java index 8f51b6fa6..1ccdcff11 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java @@ -8,9 +8,9 @@ package de.ii.xtraplatform.tiles.domain; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.docs.DocIgnore; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import de.ii.xtraplatform.features.domain.SpatialExtent; import de.ii.xtraplatform.tiles.domain.ImmutableMinMax.Builder; import java.util.Optional; import org.immutables.value.Value; @@ -39,22 +39,8 @@ default String getTileMatrixSet() { } /** - * @langEn Optional fixed spatial extent for this tileset. If set, this value is used as the clip - * bounding box instead of falling back to MBTiles metadata. - * @langDe Optionaler fester räumlicher Extent für dieses Tileset. Wenn gesetzt, wird dieser Wert - * als Clip-BoundingBox verwendet, statt auf MBTiles-Metadaten zurückzufallen. + * @langEn Optional fixed spatial extent for this tileset in native CRS. + * @langDe Optionaler fester räumlicher Extent für dieses Tileset im nativen CRS. */ - Optional getExtent(); - - /** - * @langEn If true, the spatial extent will always be computed from data, even if a fixed value is - * set globally. If false, a fixed value is always used. If not set, the global or provider - * logic applies. - * @langDe Wenn true, wird der räumliche Extent immer aus den Daten berechnet, auch wenn global - * ein fester Wert gesetzt ist. Wenn false, wird immer ein fixer Wert verwendet. Wenn nicht - * gesetzt, gilt die globale oder Provider-Logik. - */ - default Optional getSpatialExtentComputed() { - return Optional.empty(); - } + Optional getExtent(); } From a3256c16323679314b72b2b0d8bf5be24b47fc99 Mon Sep 17 00:00:00 2001 From: "p.zahnen" Date: Thu, 21 May 2026 18:31:53 +0200 Subject: [PATCH 04/31] treat computed=true only; handle date-only bounds --- .../features/gml/app/FeatureProviderWfs.java | 20 +++++++++++++++---- .../graphql/app/FeatureProviderGraphQl.java | 20 +++++++++++++++---- .../sql/domain/FeatureProviderSql.java | 20 +++++++++++++++---- .../features/domain/SpatialExtent.java | 4 ++-- .../features/domain/TemporalExtent.java | 4 ++-- 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java index 69e24f9df..51c78f3aa 100644 --- a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java +++ b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java @@ -63,7 +63,9 @@ import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; import jakarta.ws.rs.core.MediaType; +import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.List; import java.util.Map; @@ -366,7 +368,7 @@ private Optional getConfiguredSpatialExtent(String typeName) { return fromType .or(() -> fromProvider) - .filter(extent -> extent.getComputed() == null) + .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) .flatMap( extent -> { if (extent.getXmin() == null @@ -407,7 +409,7 @@ private Optional getConfiguredTemporalExtent(String typeName) { return fromType .or(() -> fromProvider) - .filter(extent -> extent.getComputed() == null) + .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) .flatMap( extent -> { if (extent.getStart() == null && extent.getEnd() == null) { @@ -415,16 +417,26 @@ private Optional getConfiguredTemporalExtent(String typeName) { } OffsetDateTime start = extent.getStart() != null - ? OffsetDateTime.parse(extent.getStart()) + ? parseConfiguredTemporalBound(extent.getStart(), false) : OffsetDateTime.parse("0001-01-01T00:00:00Z"); OffsetDateTime end = extent.getEnd() != null - ? OffsetDateTime.parse(extent.getEnd()) + ? parseConfiguredTemporalBound(extent.getEnd(), true) : OffsetDateTime.parse("9999-12-31T23:59:59Z"); return Optional.of(Interval.of(start.toInstant(), end.toInstant())); }); } + private static OffsetDateTime parseConfiguredTemporalBound(String value, boolean endOfDay) { + if (value.contains("T")) { + return OffsetDateTime.parse(value); + } + + return endOfDay + ? LocalDate.parse(value).atTime(23, 59, 59).atOffset(ZoneOffset.UTC) + : LocalDate.parse(value).atStartOfDay().atOffset(ZoneOffset.UTC); + } + @Override public Optional getMetadata() { return getConnector().getMetadata(); diff --git a/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java b/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java index c16ddaf5e..f25f55b81 100644 --- a/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java +++ b/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java @@ -57,7 +57,9 @@ import de.ii.xtraplatform.streams.domain.Reactive; import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; +import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.List; import java.util.Map; @@ -424,7 +426,7 @@ private Optional getConfiguredSpatialExtent(String typeName) { return fromType .or(() -> fromProvider) - .filter(extent -> extent.getComputed() == null) + .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) .flatMap( extent -> { if (extent.getXmin() == null @@ -465,7 +467,7 @@ private Optional getConfiguredTemporalExtent(String typeName) { return fromType .or(() -> fromProvider) - .filter(extent -> extent.getComputed() == null) + .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) .flatMap( extent -> { if (extent.getStart() == null && extent.getEnd() == null) { @@ -473,16 +475,26 @@ private Optional getConfiguredTemporalExtent(String typeName) { } OffsetDateTime start = extent.getStart() != null - ? OffsetDateTime.parse(extent.getStart()) + ? parseConfiguredTemporalBound(extent.getStart(), false) : OffsetDateTime.parse("0001-01-01T00:00:00Z"); OffsetDateTime end = extent.getEnd() != null - ? OffsetDateTime.parse(extent.getEnd()) + ? parseConfiguredTemporalBound(extent.getEnd(), true) : OffsetDateTime.parse("9999-12-31T23:59:59Z"); return Optional.of(Interval.of(start.toInstant(), end.toInstant())); }); } + private static OffsetDateTime parseConfiguredTemporalBound(String value, boolean endOfDay) { + if (value.contains("T")) { + return OffsetDateTime.parse(value); + } + + return endOfDay + ? LocalDate.parse(value).atTime(23, 59, 59).atOffset(ZoneOffset.UTC) + : LocalDate.parse(value).atStartOfDay().atOffset(ZoneOffset.UTC); + } + @Override public Optional getMetadata() { return Optional.empty(); diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index d919876fe..f3d39c2f6 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -107,8 +107,10 @@ import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; import java.sql.SQLException; +import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.ZoneId; +import java.time.ZoneOffset; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; import java.util.Collection; @@ -1249,7 +1251,7 @@ private Optional getConfiguredSpatialExtent(String typeName) { return fromType .or(() -> fromProvider) - .filter(extent -> extent.getComputed() == null) + .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) .flatMap( extent -> { if (extent.getXmin() == null @@ -1292,7 +1294,7 @@ private Optional getConfiguredTemporalExtent(String typeName) { return fromType .or(() -> fromProvider) - .filter(extent -> extent.getComputed() == null) + .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) .flatMap( extent -> { if (extent.getStart() == null && extent.getEnd() == null) { @@ -1300,16 +1302,26 @@ private Optional getConfiguredTemporalExtent(String typeName) { } OffsetDateTime start = extent.getStart() != null - ? OffsetDateTime.parse(extent.getStart()) + ? parseConfiguredTemporalBound(extent.getStart(), false) : OffsetDateTime.parse("0001-01-01T00:00:00Z"); OffsetDateTime end = extent.getEnd() != null - ? OffsetDateTime.parse(extent.getEnd()) + ? parseConfiguredTemporalBound(extent.getEnd(), true) : OffsetDateTime.parse("9999-12-31T23:59:59Z"); return Optional.of(Interval.of(start.toInstant(), end.toInstant())); }); } + private static OffsetDateTime parseConfiguredTemporalBound(String value, boolean endOfDay) { + if (value.contains("T")) { + return OffsetDateTime.parse(value); + } + + return endOfDay + ? LocalDate.parse(value).atTime(23, 59, 59).atOffset(ZoneOffset.UTC) + : LocalDate.parse(value).atStartOfDay().atOffset(ZoneOffset.UTC); + } + // NOPMD - TODO: cache deser does not work, because the the feature schemas have no name // (and there are no map keys to get them from) // so to implement this we need the split between cfg and internal schemas diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java index 2623b8081..c771d3318 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java @@ -47,10 +47,10 @@ default void checkExclusiveComputed() { || getXmax() != null || getYmax() != null || getZmax() != null; - boolean hasComputed = getComputed() != null; + boolean autoCompute = Boolean.TRUE.equals(getComputed()); Preconditions.checkState( - !(hasCoordinates && hasComputed), + !(hasCoordinates && autoCompute), "SpatialExtent: 'computed' and explicit coordinates must not be set at the same time."); if (hasCoordinates) { diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java index b595487f3..048d018e1 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java @@ -33,10 +33,10 @@ public interface TemporalExtent { @Value.Check default void checkExclusiveComputed() { boolean hasBounds = getStart() != null || getEnd() != null; - boolean hasComputed = getComputed() != null; + boolean autoCompute = Boolean.TRUE.equals(getComputed()); Preconditions.checkState( - !(hasBounds && hasComputed), + !(hasBounds && autoCompute), "TemporalExtent: 'computed' and explicit start/end must not be set at the same time."); if (getStart() != null) { From 7ede9233b85e37de646ce44155d75cad70b76b67 Mon Sep 17 00:00:00 2001 From: "p.zahnen" Date: Fri, 22 May 2026 12:23:48 +0200 Subject: [PATCH 05/31] adjustments temporalExtent --- .../features/domain/TemporalExtent.java | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java index 048d018e1..7fa599d5e 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java @@ -7,29 +7,51 @@ */ package de.ii.xtraplatform.features.domain; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.common.base.Preconditions; -import java.time.LocalDate; +import java.time.Instant; +import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import javax.annotation.Nullable; import org.immutables.value.Value; -/** Temporal extent with ISO-8601 dates (yyyy-MM-dd). */ +/** Temporal extent with UTC ISO-8601 instants (yyyy-MM-ddTHH:mm:ss.SSSZ). */ @Value.Immutable @JsonDeserialize(builder = ImmutableTemporalExtent.Builder.class) public interface TemporalExtent { - /** Start of the temporal extent as ISO-8601 date (yyyy-MM-dd), or {@code null} for open start. */ + /** + * Start of the temporal extent as UTC ISO-8601 instant (yyyy-MM-ddTHH:mm:ss[.SSS]Z), or {@code + * null} for open start. + */ @Nullable String getStart(); - /** End of the temporal extent as ISO-8601 date (yyyy-MM-dd), or {@code null} for open end. */ + /** + * End of the temporal extent as UTC ISO-8601 instant (yyyy-MM-ddTHH:mm:ss[.SSS]Z), or {@code + * null} for open end. + */ @Nullable String getEnd(); @Nullable Boolean getComputed(); + @Value.Derived + @JsonIgnore + default Instant getStartInstant() { + return getStart() == null + ? null + : Instant.from(DateTimeFormatter.ISO_INSTANT.parse(getStart())); + } + + @Value.Derived + @JsonIgnore + default Instant getEndInstant() { + return getEnd() == null ? null : Instant.from(DateTimeFormatter.ISO_INSTANT.parse(getEnd())); + } + @Value.Check default void checkExclusiveComputed() { boolean hasBounds = getStart() != null || getEnd() != null; @@ -40,28 +62,24 @@ default void checkExclusiveComputed() { "TemporalExtent: 'computed' and explicit start/end must not be set at the same time."); if (getStart() != null) { - validateIsoDate(getStart(), "start"); + validateIsoInstant(getStart(), "start"); } if (getEnd() != null) { - validateIsoDate(getEnd(), "end"); + validateIsoInstant(getEnd(), "end"); } } - private static void validateIsoDate(String value, String field) { + private static void validateIsoInstant(String value, String field) { Preconditions.checkState( !value.matches("^-?\\d+$"), - "TemporalExtent: '%s' must be an ISO date string (yyyy-MM-dd), not a numeric timestamp.", - field); - Preconditions.checkState( - !value.contains("T"), - "TemporalExtent: '%s' must be an ISO date string (yyyy-MM-dd), timestamps are not allowed.", + "TemporalExtent: '%s' must be a UTC ISO-8601 instant string, not a numeric timestamp.", field); try { - LocalDate.parse(value); + DateTimeFormatter.ISO_INSTANT.parse(value); } catch (DateTimeParseException e) { Preconditions.checkState( false, - "TemporalExtent: '%s' is not a valid ISO-8601 date (yyyy-MM-dd): %s", + "TemporalExtent: '%s' is not a valid UTC ISO-8601 instant (yyyy-MM-ddTHH:mm:ss.SSSZ): %s", field, value); } From dc1ed9b5c4e2852190d5bb58953dde3940b141ce Mon Sep 17 00:00:00 2001 From: "p.zahnen" Date: Fri, 22 May 2026 13:20:34 +0200 Subject: [PATCH 06/31] Update SpatialExtent.java --- .../features/domain/SpatialExtent.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java index c771d3318..23ae71f1e 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java @@ -9,6 +9,9 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.common.base.Preconditions; +import de.ii.xtraplatform.crs.domain.BoundingBox; +import de.ii.xtraplatform.crs.domain.EpsgCrs; +import java.util.Optional; import javax.annotation.Nullable; import org.immutables.value.Value; @@ -63,4 +66,18 @@ default void checkExclusiveComputed() { "SpatialExtent: zmin and zmax must both be set or both be absent."); } } + + default Optional toBoundingBox(EpsgCrs nativeCrs) { + if (getXmin() == null || getYmin() == null || getXmax() == null || getYmax() == null) { + return Optional.empty(); + } + + if (getZmin() != null && getZmax() != null) { + return Optional.of( + BoundingBox.of( + getXmin(), getYmin(), getZmin(), getXmax(), getYmax(), getZmax(), nativeCrs)); + } + + return Optional.of(BoundingBox.of(getXmin(), getYmin(), getXmax(), getYmax(), nativeCrs)); + } } From 5f9f844df4e0ac6456a8091586b086bae2060902 Mon Sep 17 00:00:00 2001 From: "p.zahnen" Date: Fri, 22 May 2026 14:19:42 +0200 Subject: [PATCH 07/31] refactoring --- .../features/gml/app/FeatureProviderWfs.java | 99 +------------------ .../graphql/app/FeatureProviderGraphQl.java | 99 +------------------ .../sql/domain/FeatureProviderSql.java | 99 +------------------ .../domain/AbstractFeatureProvider.java | 71 +++++++++++++ 4 files changed, 74 insertions(+), 294 deletions(-) diff --git a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java index 51c78f3aa..e1c2136be 100644 --- a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java +++ b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java @@ -16,7 +16,6 @@ import de.ii.xtraplatform.cql.domain.Cql; import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.crs.domain.CrsInfo; -import de.ii.xtraplatform.crs.domain.CrsTransformationException; import de.ii.xtraplatform.crs.domain.CrsTransformerFactory; import de.ii.xtraplatform.crs.domain.EpsgCrs; import de.ii.xtraplatform.crs.domain.OgcCrs; @@ -45,14 +44,11 @@ import de.ii.xtraplatform.features.domain.FeatureStream; import de.ii.xtraplatform.features.domain.FeatureStreamImpl; import de.ii.xtraplatform.features.domain.FeatureTokenDecoder; -import de.ii.xtraplatform.features.domain.FeatureTypeExtent; import de.ii.xtraplatform.features.domain.Metadata; import de.ii.xtraplatform.features.domain.ProviderData; import de.ii.xtraplatform.features.domain.ProviderExtensionRegistry; import de.ii.xtraplatform.features.domain.Query; import de.ii.xtraplatform.features.domain.SchemaMapping; -import de.ii.xtraplatform.features.domain.SpatialExtent; -import de.ii.xtraplatform.features.domain.TemporalExtent; import de.ii.xtraplatform.features.domain.transform.OnlyQueryables; import de.ii.xtraplatform.features.domain.transform.OnlySortables; import de.ii.xtraplatform.features.gml.domain.FeatureProviderWfsData; @@ -63,9 +59,6 @@ import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; import jakarta.ws.rs.core.MediaType; -import java.time.LocalDate; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.List; import java.util.Map; @@ -335,18 +328,7 @@ public Optional getSpatialExtent(String typeName) { @Override public Optional getSpatialExtent(String typeName, EpsgCrs crs) { return getSpatialExtent(typeName) - .flatMap( - boundingBox -> - crsTransformerFactory - .getTransformer(getNativeCrs(), crs, false) - .flatMap( - crsTransformer -> { - try { - return Optional.of(crsTransformer.transformBoundingBox(boundingBox)); - } catch (CrsTransformationException e) { - return Optional.empty(); - } - })); + .flatMap(boundingBox -> transformSpatialExtent(boundingBox, crs)); } @Override @@ -358,85 +340,6 @@ public Optional getTemporalExtent(String typeName) { return getConfiguredTemporalExtent(typeName); } - private Optional getConfiguredSpatialExtent(String typeName) { - Optional fromType = - Optional.ofNullable(getData().getTypes().get(typeName)) - .flatMap(FeatureSchema::getExtent) - .flatMap(FeatureTypeExtent::getSpatial); - Optional fromProvider = - getData().getExtent().flatMap(FeatureTypeExtent::getSpatial); - - return fromType - .or(() -> fromProvider) - .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) - .flatMap( - extent -> { - if (extent.getXmin() == null - || extent.getYmin() == null - || extent.getXmax() == null - || extent.getYmax() == null) { - return Optional.empty(); - } - EpsgCrs nativeCrs = getData().getNativeCrs().orElse(OgcCrs.CRS84); - if (extent.getZmin() != null && extent.getZmax() != null) { - return Optional.of( - BoundingBox.of( - extent.getXmin(), - extent.getYmin(), - extent.getZmin(), - extent.getXmax(), - extent.getYmax(), - extent.getZmax(), - nativeCrs)); - } - return Optional.of( - BoundingBox.of( - extent.getXmin(), - extent.getYmin(), - extent.getXmax(), - extent.getYmax(), - nativeCrs)); - }); - } - - private Optional getConfiguredTemporalExtent(String typeName) { - Optional fromType = - Optional.ofNullable(getData().getTypes().get(typeName)) - .flatMap(FeatureSchema::getExtent) - .flatMap(FeatureTypeExtent::getTemporal); - Optional fromProvider = - getData().getExtent().flatMap(FeatureTypeExtent::getTemporal); - - return fromType - .or(() -> fromProvider) - .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) - .flatMap( - extent -> { - if (extent.getStart() == null && extent.getEnd() == null) { - return Optional.empty(); - } - OffsetDateTime start = - extent.getStart() != null - ? parseConfiguredTemporalBound(extent.getStart(), false) - : OffsetDateTime.parse("0001-01-01T00:00:00Z"); - OffsetDateTime end = - extent.getEnd() != null - ? parseConfiguredTemporalBound(extent.getEnd(), true) - : OffsetDateTime.parse("9999-12-31T23:59:59Z"); - return Optional.of(Interval.of(start.toInstant(), end.toInstant())); - }); - } - - private static OffsetDateTime parseConfiguredTemporalBound(String value, boolean endOfDay) { - if (value.contains("T")) { - return OffsetDateTime.parse(value); - } - - return endOfDay - ? LocalDate.parse(value).atTime(23, 59, 59).atOffset(ZoneOffset.UTC) - : LocalDate.parse(value).atStartOfDay().atOffset(ZoneOffset.UTC); - } - @Override public Optional getMetadata() { return getConnector().getMetadata(); diff --git a/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java b/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java index f25f55b81..4f365dde3 100644 --- a/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java +++ b/xtraplatform-features-graphql/src/main/java/de/ii/xtraplatform/features/graphql/app/FeatureProviderGraphQl.java @@ -15,7 +15,6 @@ import de.ii.xtraplatform.cql.domain.Cql; import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.crs.domain.CrsInfo; -import de.ii.xtraplatform.crs.domain.CrsTransformationException; import de.ii.xtraplatform.crs.domain.CrsTransformerFactory; import de.ii.xtraplatform.crs.domain.EpsgCrs; import de.ii.xtraplatform.crs.domain.OgcCrs; @@ -41,14 +40,11 @@ import de.ii.xtraplatform.features.domain.FeatureQueryEncoder; import de.ii.xtraplatform.features.domain.FeatureSchema; import de.ii.xtraplatform.features.domain.FeatureTokenDecoder; -import de.ii.xtraplatform.features.domain.FeatureTypeExtent; import de.ii.xtraplatform.features.domain.Metadata; import de.ii.xtraplatform.features.domain.ProviderData; import de.ii.xtraplatform.features.domain.ProviderExtensionRegistry; import de.ii.xtraplatform.features.domain.Query; import de.ii.xtraplatform.features.domain.SchemaMapping; -import de.ii.xtraplatform.features.domain.SpatialExtent; -import de.ii.xtraplatform.features.domain.TemporalExtent; import de.ii.xtraplatform.features.domain.transform.OnlyQueryables; import de.ii.xtraplatform.features.domain.transform.OnlySortables; import de.ii.xtraplatform.features.graphql.domain.FeatureProviderGraphQlData; @@ -57,9 +53,6 @@ import de.ii.xtraplatform.streams.domain.Reactive; import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; -import java.time.LocalDate; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.List; import java.util.Map; @@ -394,18 +387,7 @@ public Optional getSpatialExtent(String typeName) { @Override public Optional getSpatialExtent(String typeName, EpsgCrs crs) { return getSpatialExtent(typeName) - .flatMap( - boundingBox -> - crsTransformerFactory - .getTransformer(getNativeCrs(), crs, false) - .flatMap( - crsTransformer -> { - try { - return Optional.of(crsTransformer.transformBoundingBox(boundingBox)); - } catch (CrsTransformationException e) { - return Optional.empty(); - } - })); + .flatMap(boundingBox -> transformSpatialExtent(boundingBox, crs)); } @Override @@ -416,85 +398,6 @@ public Optional getTemporalExtent(String typeName) { return getConfiguredTemporalExtent(typeName); } - private Optional getConfiguredSpatialExtent(String typeName) { - Optional fromType = - Optional.ofNullable(getData().getTypes().get(typeName)) - .flatMap(FeatureSchema::getExtent) - .flatMap(FeatureTypeExtent::getSpatial); - Optional fromProvider = - getData().getExtent().flatMap(FeatureTypeExtent::getSpatial); - - return fromType - .or(() -> fromProvider) - .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) - .flatMap( - extent -> { - if (extent.getXmin() == null - || extent.getYmin() == null - || extent.getXmax() == null - || extent.getYmax() == null) { - return Optional.empty(); - } - EpsgCrs nativeCrs = getData().getNativeCrs().orElse(OgcCrs.CRS84); - if (extent.getZmin() != null && extent.getZmax() != null) { - return Optional.of( - BoundingBox.of( - extent.getXmin(), - extent.getYmin(), - extent.getZmin(), - extent.getXmax(), - extent.getYmax(), - extent.getZmax(), - nativeCrs)); - } - return Optional.of( - BoundingBox.of( - extent.getXmin(), - extent.getYmin(), - extent.getXmax(), - extent.getYmax(), - nativeCrs)); - }); - } - - private Optional getConfiguredTemporalExtent(String typeName) { - Optional fromType = - Optional.ofNullable(getData().getTypes().get(typeName)) - .flatMap(FeatureSchema::getExtent) - .flatMap(FeatureTypeExtent::getTemporal); - Optional fromProvider = - getData().getExtent().flatMap(FeatureTypeExtent::getTemporal); - - return fromType - .or(() -> fromProvider) - .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) - .flatMap( - extent -> { - if (extent.getStart() == null && extent.getEnd() == null) { - return Optional.empty(); - } - OffsetDateTime start = - extent.getStart() != null - ? parseConfiguredTemporalBound(extent.getStart(), false) - : OffsetDateTime.parse("0001-01-01T00:00:00Z"); - OffsetDateTime end = - extent.getEnd() != null - ? parseConfiguredTemporalBound(extent.getEnd(), true) - : OffsetDateTime.parse("9999-12-31T23:59:59Z"); - return Optional.of(Interval.of(start.toInstant(), end.toInstant())); - }); - } - - private static OffsetDateTime parseConfiguredTemporalBound(String value, boolean endOfDay) { - if (value.contains("T")) { - return OffsetDateTime.parse(value); - } - - return endOfDay - ? LocalDate.parse(value).atTime(23, 59, 59).atOffset(ZoneOffset.UTC) - : LocalDate.parse(value).atStartOfDay().atOffset(ZoneOffset.UTC); - } - @Override public Optional getMetadata() { return Optional.empty(); diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index f3d39c2f6..59590a9c3 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -76,8 +76,6 @@ import de.ii.xtraplatform.features.domain.SchemaMapping; import de.ii.xtraplatform.features.domain.SortKey; import de.ii.xtraplatform.features.domain.SourceSchemaValidator; -import de.ii.xtraplatform.features.domain.SpatialExtent; -import de.ii.xtraplatform.features.domain.TemporalExtent; import de.ii.xtraplatform.features.domain.transform.OnlyQueryables; import de.ii.xtraplatform.features.domain.transform.OnlySortables; import de.ii.xtraplatform.features.domain.transform.PropertyTransformations; @@ -110,7 +108,6 @@ import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.ZoneId; -import java.time.ZoneOffset; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; import java.util.Collection; @@ -1134,18 +1131,7 @@ public Optional getSpatialExtent(String typeName) { @SuppressWarnings("PMD.AvoidCatchingGenericException") public Optional getSpatialExtent(String typeName, EpsgCrs crs) { return getSpatialExtent(typeName) - .flatMap( - boundingBox -> - crsTransformerFactory - .getTransformer(getNativeCrs(), crs, false) - .flatMap( - crsTransformer -> { - try { - return Optional.of(crsTransformer.transformBoundingBox(boundingBox)); - } catch (Exception e) { - return Optional.empty(); - } - })); + .flatMap(boundingBox -> transformSpatialExtent(boundingBox, crs)); } @Override @@ -1239,89 +1225,6 @@ public Optional getTemporalExtent(String typeName) { return Optional.empty(); } - private Optional getConfiguredSpatialExtent(String typeName) { - Optional fromType = - Optional.ofNullable(getData().getTypes().get(typeName)) - .flatMap(FeatureSchema::getExtent) - .flatMap(de.ii.xtraplatform.features.domain.FeatureTypeExtent::getSpatial); - Optional fromProvider = - getData() - .getExtent() - .flatMap(de.ii.xtraplatform.features.domain.FeatureTypeExtent::getSpatial); - - return fromType - .or(() -> fromProvider) - .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) - .flatMap( - extent -> { - if (extent.getXmin() == null - || extent.getYmin() == null - || extent.getXmax() == null - || extent.getYmax() == null) { - return Optional.empty(); - } - EpsgCrs nativeCrs = getData().getNativeCrs().orElse(OgcCrs.CRS84); - if (extent.getZmin() != null && extent.getZmax() != null) { - return Optional.of( - BoundingBox.of( - extent.getXmin(), - extent.getYmin(), - extent.getZmin(), - extent.getXmax(), - extent.getYmax(), - extent.getZmax(), - nativeCrs)); - } - return Optional.of( - BoundingBox.of( - extent.getXmin(), - extent.getYmin(), - extent.getXmax(), - extent.getYmax(), - nativeCrs)); - }); - } - - private Optional getConfiguredTemporalExtent(String typeName) { - Optional fromType = - Optional.ofNullable(getData().getTypes().get(typeName)) - .flatMap(FeatureSchema::getExtent) - .flatMap(de.ii.xtraplatform.features.domain.FeatureTypeExtent::getTemporal); - Optional fromProvider = - getData() - .getExtent() - .flatMap(de.ii.xtraplatform.features.domain.FeatureTypeExtent::getTemporal); - - return fromType - .or(() -> fromProvider) - .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) - .flatMap( - extent -> { - if (extent.getStart() == null && extent.getEnd() == null) { - return Optional.empty(); - } - OffsetDateTime start = - extent.getStart() != null - ? parseConfiguredTemporalBound(extent.getStart(), false) - : OffsetDateTime.parse("0001-01-01T00:00:00Z"); - OffsetDateTime end = - extent.getEnd() != null - ? parseConfiguredTemporalBound(extent.getEnd(), true) - : OffsetDateTime.parse("9999-12-31T23:59:59Z"); - return Optional.of(Interval.of(start.toInstant(), end.toInstant())); - }); - } - - private static OffsetDateTime parseConfiguredTemporalBound(String value, boolean endOfDay) { - if (value.contains("T")) { - return OffsetDateTime.parse(value); - } - - return endOfDay - ? LocalDate.parse(value).atTime(23, 59, 59).atOffset(ZoneOffset.UTC) - : LocalDate.parse(value).atStartOfDay().atOffset(ZoneOffset.UTC); - } - // NOPMD - TODO: cache deser does not work, because the the feature schemas have no name // (and there are no map keys to get them from) // so to implement this we need the split between cfg and internal schemas diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java index cd91f12fb..a0017684a 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java @@ -19,6 +19,7 @@ import de.ii.xtraplatform.codelists.domain.Codelist; import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.crs.domain.CrsInfo; +import de.ii.xtraplatform.crs.domain.CrsTransformationException; import de.ii.xtraplatform.crs.domain.CrsTransformerFactory; import de.ii.xtraplatform.crs.domain.EpsgCrs; import de.ii.xtraplatform.crs.domain.OgcCrs; @@ -45,6 +46,9 @@ import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.Values; import java.io.IOException; +import java.time.LocalDate; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedHashMap; @@ -64,6 +68,7 @@ import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.threeten.extra.Interval; @SuppressWarnings({ "PMD.CouplingBetweenObjects", @@ -642,6 +647,72 @@ protected Query preprocessQuery(Query query) { return query; } + protected Optional getConfiguredSpatialExtent(String typeName) { + Optional fromType = + Optional.ofNullable(getData().getTypes().get(typeName)) + .flatMap(FeatureSchema::getExtent) + .flatMap(FeatureTypeExtent::getSpatial); + Optional fromProvider = + getData().getExtent().flatMap(FeatureTypeExtent::getSpatial); + + return fromType + .or(() -> fromProvider) + .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) + .flatMap(extent -> extent.toBoundingBox(getData().getNativeCrs().orElse(OgcCrs.CRS84))); + } + + protected Optional getConfiguredTemporalExtent(String typeName) { + Optional fromType = + Optional.ofNullable(getData().getTypes().get(typeName)) + .flatMap(FeatureSchema::getExtent) + .flatMap(FeatureTypeExtent::getTemporal); + Optional fromProvider = + getData().getExtent().flatMap(FeatureTypeExtent::getTemporal); + + return fromType + .or(() -> fromProvider) + .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) + .flatMap( + extent -> { + if (extent.getStart() == null && extent.getEnd() == null) { + return Optional.empty(); + } + OffsetDateTime start = + extent.getStart() != null + ? parseConfiguredTemporalBound(extent.getStart(), false) + : OffsetDateTime.parse("0001-01-01T00:00:00Z"); + OffsetDateTime end = + extent.getEnd() != null + ? parseConfiguredTemporalBound(extent.getEnd(), true) + : OffsetDateTime.parse("9999-12-31T23:59:59Z"); + return Optional.of(Interval.of(start.toInstant(), end.toInstant())); + }); + } + + protected Optional transformSpatialExtent( + BoundingBox boundingBox, EpsgCrs targetCrs) { + return crsTransformerFactory + .getTransformer(getData().getNativeCrs().orElse(OgcCrs.CRS84), targetCrs, false) + .flatMap( + crsTransformer -> { + try { + return Optional.of(crsTransformer.transformBoundingBox(boundingBox)); + } catch (CrsTransformationException e) { + return Optional.empty(); + } + }); + } + + private static OffsetDateTime parseConfiguredTemporalBound(String value, boolean endOfDay) { + if (value.contains("T")) { + return OffsetDateTime.parse(value); + } + + return endOfDay + ? LocalDate.parse(value).atTime(23, 59, 59).atOffset(ZoneOffset.UTC) + : LocalDate.parse(value).atStartOfDay().atOffset(ZoneOffset.UTC); + } + @Override public FeatureChanges changes() { return changeHandler; From 2131c959e57ce56b6e5d288a17fef71ee83a02cc Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 13:51:39 +0100 Subject: [PATCH 08/31] tiles: extent of http and mbtiles tilesets is in CRS84 --- .../de/ii/xtraplatform/tiles/domain/TilesetCommon.java | 7 ------- .../de/ii/xtraplatform/tiles/domain/TilesetFeatures.java | 9 +++++++++ .../tiles/domain/TilesetFeaturesDefaults.java | 6 ++++-- .../de/ii/xtraplatform/tiles/domain/TilesetHttp.java | 7 +++++++ .../xtraplatform/tiles/domain/TilesetHttpDefaults.java | 4 ++-- .../de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java | 9 +++++++++ .../tiles/domain/TilesetMbTilesDefaults.java | 6 ++++-- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java index 49ca3bb45..870bdeecb 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetCommon.java @@ -8,7 +8,6 @@ package de.ii.xtraplatform.tiles.domain; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; -import de.ii.xtraplatform.features.domain.SpatialExtent; import de.ii.xtraplatform.tiles.domain.ImmutableMinMax.Builder; import java.util.Optional; @@ -25,10 +24,4 @@ public interface TilesetCommon extends TilesetCommonDefaults { @Override Optional getCenter(); - - /** - * @langEn Optional fixed spatial extent for this tileset in native CRS. - * @langDe Optionaler fester räumlicher Extent für dieses Tileset im nativen CRS. - */ - Optional getExtent(); } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java index 71a9c73dd..50ecafa44 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java @@ -13,6 +13,7 @@ import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import de.ii.xtraplatform.features.domain.SpatialExtent; import java.util.List; import java.util.Map; import java.util.Objects; @@ -49,6 +50,14 @@ public interface TilesetFeatures @Override Optional getFeatureProvider(); + /** + * @langEn Fixed spatial extent of the tileset in the native CRS of the feature provider. If set, + * the extent is not derived from the feature provider. + * @langDe Fester räumlicher Extent des Tilesets im nativen CRS des Feature-Providers. Wenn + * gesetzt, wird der Extent nicht vom Feature-Provider übernommen. + */ + Optional getExtent(); + @DocIgnore @Nullable @Override diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java index 2941a408f..e7a6e80ad 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java @@ -39,8 +39,10 @@ default ImmutableTilesetFeaturesDefaults.Builder getBuilder() { abstract class Builder implements BuildableBuilder {} /** - * @langEn Optional fixed spatial extent for this tileset in native CRS. - * @langDe Optionaler fester räumlicher Extent für dieses Tileset im nativen CRS. + * @langEn Fixed spatial extent of the tileset in the native CRS of the feature provider. If set, + * the extent is not derived from the feature provider. + * @langDe Fester räumlicher Extent des Tilesets im nativen CRS des Feature-Providers. Wenn + * gesetzt, wird der Extent nicht vom Feature-Provider übernommen. */ Optional getExtent(); } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java index 22f2071bf..4d21f92dd 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java @@ -12,6 +12,7 @@ import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import de.ii.xtraplatform.features.domain.SpatialExtent; import java.util.Map; import java.util.Optional; import org.immutables.value.Value; @@ -40,6 +41,12 @@ public interface TilesetHttp extends TilesetCommon, WithEncodings, Buildable getEncodings(); + /** + * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). + * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). + */ + Optional getExtent(); + /** * @langEn URL template for accessing tiles. Parameters to use are `{{tileMatrix}}`, * `{{tileRow}}`, `{{tileCol}}` and `{{fileExtension}}`. Single curly braces are also allowed. diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java index 9c9250e94..b6d9b8365 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java @@ -34,8 +34,8 @@ default ImmutableTilesetHttpDefaults.Builder getBuilder() { } /** - * @langEn Optional fixed spatial extent for this tileset in native CRS. - * @langDe Optionaler fester räumlicher Extent für dieses Tileset im nativen CRS. + * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). + * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). */ Optional getExtent(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java index 37d14ec20..a1843209b 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java @@ -13,6 +13,7 @@ import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; +import de.ii.xtraplatform.features.domain.SpatialExtent; import java.util.Objects; import java.util.Optional; import javax.annotation.Nullable; @@ -38,6 +39,14 @@ public interface TilesetMbTiles extends TilesetCommon, Buildable */ String getSource(); + /** + * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If set, `bounds` + * from the MBTiles metadata is ignored. + * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird + * `bounds` aus den MBTiles-Metadaten ignoriert. + */ + Optional getExtent(); + /** * @langEn Tile Matrix Set of the tiles in the MBTiles file. * @langDe Kachelschema der Kacheln in der MBTiles-Datei. diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java index 1ccdcff11..4589d1a9b 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java @@ -39,8 +39,10 @@ default String getTileMatrixSet() { } /** - * @langEn Optional fixed spatial extent for this tileset in native CRS. - * @langDe Optionaler fester räumlicher Extent für dieses Tileset im nativen CRS. + * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If set, `bounds` + * from the MBTiles metadata is ignored. + * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird + * `bounds` aus den MBTiles-Metadaten ignoriert. */ Optional getExtent(); } From 647bed5dd441ebd27d911259a9f8294474d17aad Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 13:52:33 +0100 Subject: [PATCH 09/31] reuse SpatialExtent.toBoundingBox, drop unused imports --- .../sql/domain/FeatureProviderSql.java | 2 - .../tiles/app/TileProviderFeatures.java | 37 ++---------------- .../tiles/app/TileProviderHttp.java | 33 ++-------------- .../tiles/app/TileProviderMbTiles.java | 38 +++---------------- 4 files changed, 13 insertions(+), 97 deletions(-) diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index 59590a9c3..7b9e17ee7 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -105,8 +105,6 @@ import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.ValueStore; import java.sql.SQLException; -import java.time.LocalDate; -import java.time.OffsetDateTime; import java.time.ZoneId; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java index 146b435da..7f9cbe6af 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java @@ -39,8 +39,6 @@ import de.ii.xtraplatform.features.domain.FeatureProvider.FeatureVolatileCapability; import de.ii.xtraplatform.features.domain.FeatureSchema; import de.ii.xtraplatform.features.domain.ProviderData; -import de.ii.xtraplatform.features.domain.SpatialExtent; -import de.ii.xtraplatform.jobs.domain.JobQueue; import de.ii.xtraplatform.tiles.domain.Cache; import de.ii.xtraplatform.tiles.domain.Cache.Storage; import de.ii.xtraplatform.tiles.domain.Cache.Type; @@ -1048,8 +1046,10 @@ private TilesetMetadata loadMetadata(TilesetFeatures tileset) { .collect(Collectors.toList()); Optional configuredExtent = - toBoundingBox( - tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent()), tileset); + tileset + .getExtent() + .or(() -> getData().getTilesetDefaults().getExtent()) + .flatMap(extent -> extent.toBoundingBox(resolveNativeCrs(tileset))); Optional bounds; if (configuredExtent.isPresent()) { @@ -1182,35 +1182,6 @@ private String getFeatureProviderId(TilesetFeatures tileset) { return tileset.getFeatureProvider().orElse(clean(getData().getId())); } - private Optional toBoundingBox( - Optional extent, TilesetFeatures tileset) { - EpsgCrs nativeCrs = resolveNativeCrs(tileset); - return extent - .filter(e -> e.getComputed() == null) - .flatMap( - e -> { - if (e.getXmin() == null - || e.getYmin() == null - || e.getXmax() == null - || e.getYmax() == null) { - return Optional.empty(); - } - if (e.getZmin() != null && e.getZmax() != null) { - return Optional.of( - BoundingBox.of( - e.getXmin(), - e.getYmin(), - e.getZmin(), - e.getXmax(), - e.getYmax(), - e.getZmax(), - nativeCrs)); - } - return Optional.of( - BoundingBox.of(e.getXmin(), e.getYmin(), e.getXmax(), e.getYmax(), nativeCrs)); - }); - } - private EpsgCrs resolveNativeCrs(TilesetFeatures tileset) { return tileGenerator .getFeatureProvider(getFeatureProviderId(tileset)) diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java index faed2c4a7..6851b16fc 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java @@ -16,7 +16,6 @@ import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; import de.ii.xtraplatform.features.domain.ProviderData; -import de.ii.xtraplatform.features.domain.SpatialExtent; import de.ii.xtraplatform.tiles.domain.ChainedTileProvider; import de.ii.xtraplatform.tiles.domain.ImmutableTilesetMetadata; import de.ii.xtraplatform.tiles.domain.TileProviderData; @@ -118,7 +117,10 @@ private void loadMetadata() { private TilesetMetadata loadMetadata(TilesetHttp tileset) { Optional bounds = - toBoundingBox(tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent())); + tileset + .getExtent() + .or(() -> getData().getTilesetDefaults().getExtent()) + .flatMap(extent -> extent.toBoundingBox(OgcCrs.CRS84)); return ImmutableTilesetMetadata.builder() .encodings( @@ -133,31 +135,4 @@ private TilesetMetadata loadMetadata(TilesetHttp tileset) { .bounds(bounds) .build(); } - - private Optional toBoundingBox(Optional extent) { - return extent - .filter(e -> e.getComputed() == null) - .flatMap( - e -> { - if (e.getXmin() == null - || e.getYmin() == null - || e.getXmax() == null - || e.getYmax() == null) { - return Optional.empty(); - } - if (e.getZmin() != null && e.getZmax() != null) { - return Optional.of( - BoundingBox.of( - e.getXmin(), - e.getYmin(), - e.getZmin(), - e.getXmax(), - e.getYmax(), - e.getZmax(), - OgcCrs.CRS84)); - } - return Optional.of( - BoundingBox.of(e.getXmin(), e.getYmin(), e.getXmax(), e.getYmax(), OgcCrs.CRS84)); - }); - } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java index 52f30db59..cef11d98a 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java @@ -20,7 +20,6 @@ import de.ii.xtraplatform.entities.domain.Entity.SubType; import de.ii.xtraplatform.features.domain.FeatureSchema; import de.ii.xtraplatform.features.domain.ProviderData; -import de.ii.xtraplatform.features.domain.SpatialExtent; import de.ii.xtraplatform.tiles.domain.ChainedTileProvider; import de.ii.xtraplatform.tiles.domain.ImmutableMinMax; import de.ii.xtraplatform.tiles.domain.ImmutableTilesetMetadata; @@ -182,8 +181,10 @@ private void loadMetadata(Map tilesetSources) { .get(tilesetKey.first()) .mergeDefaults(getData().getTilesetDefaults()); Optional configuredExtent = - toBoundingBox( - tileset.getExtent().or(() -> getData().getTilesetDefaults().getExtent())); + tileset + .getExtent() + .or(() -> getData().getTilesetDefaults().getExtent()) + .flatMap(extent -> extent.toBoundingBox(OgcCrs.CRS84)); metadata.put( tilesetKey.first(), loadMetadata(tilesetKey.second(), path, configuredExtent)); @@ -225,9 +226,7 @@ private TilesetMetadata loadMetadata( ? Optional.of( BoundingBox.of(bbox.get(0), bbox.get(1), bbox.get(2), bbox.get(3), OgcCrs.CRS84)) : Optional.empty(); - // Configured extent takes priority; fall back to bounds from MBTiles metadata - Optional bounds = - configuredExtent.isPresent() ? configuredExtent : boundsFromMetadata; + Optional bounds = configuredExtent.or(() -> boundsFromMetadata); TilesFormat format = metadata.getFormat(); List vectorSchemas = metadata.getVectorLayers().stream() @@ -255,31 +254,4 @@ private Tuple toTuple(String tilesetKey) { String[] split = tilesetKey.split("/"); return Tuple.of(split[0], split[1]); } - - private Optional toBoundingBox(Optional extent) { - return extent - .filter(e -> e.getComputed() == null) - .flatMap( - e -> { - if (e.getXmin() == null - || e.getYmin() == null - || e.getXmax() == null - || e.getYmax() == null) { - return Optional.empty(); - } - if (e.getZmin() != null && e.getZmax() != null) { - return Optional.of( - BoundingBox.of( - e.getXmin(), - e.getYmin(), - e.getZmin(), - e.getXmax(), - e.getYmax(), - e.getZmax(), - OgcCrs.CRS84)); - } - return Optional.of( - BoundingBox.of(e.getXmin(), e.getYmin(), e.getXmax(), e.getYmax(), OgcCrs.CRS84)); - }); - } } From c165d5b0262f9cd9d5063c195a2b9f0eca7dce3e Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 13:52:41 +0100 Subject: [PATCH 10/31] temporal extent: accept dates, keep open ends open --- .../domain/AbstractFeatureProvider.java | 33 +------ .../features/domain/TemporalExtent.java | 87 ++++++++++--------- .../features/domain/TemporalExtentSpec.groovy | 61 +++++++++++++ 3 files changed, 107 insertions(+), 74 deletions(-) create mode 100644 xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java index a0017684a..6988464d2 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java @@ -46,9 +46,6 @@ import de.ii.xtraplatform.streams.domain.Reactive.Stream; import de.ii.xtraplatform.values.domain.Values; import java.io.IOException; -import java.time.LocalDate; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedHashMap; @@ -657,7 +654,6 @@ protected Optional getConfiguredSpatialExtent(String typeName) { return fromType .or(() -> fromProvider) - .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) .flatMap(extent -> extent.toBoundingBox(getData().getNativeCrs().orElse(OgcCrs.CRS84))); } @@ -669,24 +665,7 @@ protected Optional getConfiguredTemporalExtent(String typeName) { Optional fromProvider = getData().getExtent().flatMap(FeatureTypeExtent::getTemporal); - return fromType - .or(() -> fromProvider) - .filter(extent -> !Boolean.TRUE.equals(extent.getComputed())) - .flatMap( - extent -> { - if (extent.getStart() == null && extent.getEnd() == null) { - return Optional.empty(); - } - OffsetDateTime start = - extent.getStart() != null - ? parseConfiguredTemporalBound(extent.getStart(), false) - : OffsetDateTime.parse("0001-01-01T00:00:00Z"); - OffsetDateTime end = - extent.getEnd() != null - ? parseConfiguredTemporalBound(extent.getEnd(), true) - : OffsetDateTime.parse("9999-12-31T23:59:59Z"); - return Optional.of(Interval.of(start.toInstant(), end.toInstant())); - }); + return fromType.or(() -> fromProvider).flatMap(TemporalExtent::toInterval); } protected Optional transformSpatialExtent( @@ -703,16 +682,6 @@ protected Optional transformSpatialExtent( }); } - private static OffsetDateTime parseConfiguredTemporalBound(String value, boolean endOfDay) { - if (value.contains("T")) { - return OffsetDateTime.parse(value); - } - - return endOfDay - ? LocalDate.parse(value).atTime(23, 59, 59).atOffset(ZoneOffset.UTC) - : LocalDate.parse(value).atStartOfDay().atOffset(ZoneOffset.UTC); - } - @Override public FeatureChanges changes() { return changeHandler; diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java index 7fa599d5e..e554b3d93 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java @@ -10,78 +10,81 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.common.base.Preconditions; +import java.time.DateTimeException; import java.time.Instant; -import java.time.format.DateTimeFormatter; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; import java.time.format.DateTimeParseException; +import java.util.Optional; import javax.annotation.Nullable; import org.immutables.value.Value; +import org.threeten.extra.Interval; -/** Temporal extent with UTC ISO-8601 instants (yyyy-MM-ddTHH:mm:ss.SSSZ). */ +/** + * Temporal extent. Bounds are either dates (yyyy-MM-dd, interpreted in UTC) or date-times with + * offset (yyyy-MM-ddTHH:mm:ss[.SSS]Z or ±HH:mm). A missing bound is open. + */ @Value.Immutable @JsonDeserialize(builder = ImmutableTemporalExtent.Builder.class) public interface TemporalExtent { - /** - * Start of the temporal extent as UTC ISO-8601 instant (yyyy-MM-ddTHH:mm:ss[.SSS]Z), or {@code - * null} for open start. - */ @Nullable String getStart(); - /** - * End of the temporal extent as UTC ISO-8601 instant (yyyy-MM-ddTHH:mm:ss[.SSS]Z), or {@code - * null} for open end. - */ @Nullable String getEnd(); @Nullable Boolean getComputed(); - @Value.Derived @JsonIgnore - default Instant getStartInstant() { - return getStart() == null - ? null - : Instant.from(DateTimeFormatter.ISO_INSTANT.parse(getStart())); - } + default Optional toInterval() { + if (getStart() == null && getEnd() == null) { + return Optional.empty(); + } - @Value.Derived - @JsonIgnore - default Instant getEndInstant() { - return getEnd() == null ? null : Instant.from(DateTimeFormatter.ISO_INSTANT.parse(getEnd())); + Instant start = getStart() == null ? Instant.MIN : parseStart(getStart()); + Instant end = getEnd() == null ? Instant.MAX : parseEnd(getEnd()); + + return Optional.of(Interval.of(start, end)); } @Value.Check - default void checkExclusiveComputed() { + default void check() { boolean hasBounds = getStart() != null || getEnd() != null; - boolean autoCompute = Boolean.TRUE.equals(getComputed()); Preconditions.checkState( - !(hasBounds && autoCompute), + !(hasBounds && Boolean.TRUE.equals(getComputed())), "TemporalExtent: 'computed' and explicit start/end must not be set at the same time."); - if (getStart() != null) { - validateIsoInstant(getStart(), "start"); - } - if (getEnd() != null) { - validateIsoInstant(getEnd(), "end"); - } - } - - private static void validateIsoInstant(String value, String field) { - Preconditions.checkState( - !value.matches("^-?\\d+$"), - "TemporalExtent: '%s' must be a UTC ISO-8601 instant string, not a numeric timestamp.", - field); try { - DateTimeFormatter.ISO_INSTANT.parse(value); + toInterval(); } catch (DateTimeParseException e) { - Preconditions.checkState( - false, - "TemporalExtent: '%s' is not a valid UTC ISO-8601 instant (yyyy-MM-ddTHH:mm:ss.SSSZ): %s", - field, - value); + throw new IllegalStateException( + String.format( + "TemporalExtent: '%s' is neither a date (yyyy-MM-dd) nor a date-time with offset.", + e.getParsedString()), + e); + } catch (DateTimeException e) { + throw new IllegalStateException("TemporalExtent: start must not be after end.", e); } } + + private static Instant parseStart(String value) { + return isDate(value) + ? LocalDate.parse(value).atStartOfDay().toInstant(ZoneOffset.UTC) + : OffsetDateTime.parse(value).toInstant(); + } + + private static Instant parseEnd(String value) { + return isDate(value) + ? LocalDate.parse(value).atTime(LocalTime.of(23, 59, 59)).toInstant(ZoneOffset.UTC) + : OffsetDateTime.parse(value).toInstant(); + } + + private static boolean isDate(String value) { + return !value.contains("T"); + } } diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy new file mode 100644 index 000000000..03d615a1a --- /dev/null +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy @@ -0,0 +1,61 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain + +import org.threeten.extra.Interval +import spock.lang.Specification + +import java.time.Instant + +class TemporalExtentSpec extends Specification { + + static TemporalExtent extent(String start, String end) { + new ImmutableTemporalExtent.Builder().start(start).end(end).build() + } + + def "bounds are parsed as #description"() { + expect: + extent(start, end).toInterval() == Optional.of(Interval.of(Instant.parse(expectedStart), Instant.parse(expectedEnd))) + + where: + description | start | end || expectedStart | expectedEnd + "dates" | "2020-01-01" | "2020-12-31" || "2020-01-01T00:00:00Z" | "2020-12-31T23:59:59Z" + "UTC date-times" | "2020-01-01T10:00:00Z" | "2020-01-02T10:00:00.5Z" || "2020-01-01T10:00:00Z" | "2020-01-02T10:00:00.5Z" + "offset date-times" | "2020-01-01T10:00:00+01:00" | "2020-01-01T12:00:00+01:00" || "2020-01-01T09:00:00Z" | "2020-01-01T11:00:00Z" + } + + def "missing bounds are open"() { + expect: + extent(null, "2020-12-31").toInterval().get().isUnboundedStart() + extent("2020-01-01", null).toInterval().get().isUnboundedEnd() + extent(null, null).toInterval().isEmpty() + } + + def "invalid extent '#start' / '#end' is rejected"() { + when: + extent(start, end) + + then: + thrown(IllegalStateException) + + where: + start | end + "1577836800" | null + "2020-01-01T10:00:00" | null + "2020-13-01" | null + "2021-01-01" | "2020-01-01" + } + + def "computed must not be combined with bounds"() { + when: + new ImmutableTemporalExtent.Builder().start("2020-01-01").computed(true).build() + + then: + thrown(IllegalStateException) + } +} From 6443f792dd225516fe173af4e151940feeb9f239 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:03:18 +0100 Subject: [PATCH 11/31] tiles: extent of features tilesets is in CRS84 --- .../xtraplatform/tiles/app/TileProviderFeatures.java | 10 +--------- .../ii/xtraplatform/tiles/domain/TilesetFeatures.java | 8 ++++---- .../tiles/domain/TilesetFeaturesDefaults.java | 8 ++++---- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java index 7f9cbe6af..66786aace 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java @@ -26,7 +26,6 @@ import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.crs.domain.CrsInfo; import de.ii.xtraplatform.crs.domain.CrsTransformerFactory; -import de.ii.xtraplatform.crs.domain.EpsgCrs; import de.ii.xtraplatform.crs.domain.OgcCrs; import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; @@ -1049,7 +1048,7 @@ private TilesetMetadata loadMetadata(TilesetFeatures tileset) { tileset .getExtent() .or(() -> getData().getTilesetDefaults().getExtent()) - .flatMap(extent -> extent.toBoundingBox(resolveNativeCrs(tileset))); + .flatMap(extent -> extent.toBoundingBox(OgcCrs.CRS84)); Optional bounds; if (configuredExtent.isPresent()) { @@ -1181,11 +1180,4 @@ private List getFeatureProviders() { private String getFeatureProviderId(TilesetFeatures tileset) { return tileset.getFeatureProvider().orElse(clean(getData().getId())); } - - private EpsgCrs resolveNativeCrs(TilesetFeatures tileset) { - return tileGenerator - .getFeatureProvider(getFeatureProviderId(tileset)) - .map(provider -> provider.crs().get().getNativeCrs()) - .orElse(OgcCrs.CRS84); - } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java index 50ecafa44..7bcc9b831 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java @@ -51,10 +51,10 @@ public interface TilesetFeatures Optional getFeatureProvider(); /** - * @langEn Fixed spatial extent of the tileset in the native CRS of the feature provider. If set, - * the extent is not derived from the feature provider. - * @langDe Fester räumlicher Extent des Tilesets im nativen CRS des Feature-Providers. Wenn - * gesetzt, wird der Extent nicht vom Feature-Provider übernommen. + * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If set, the extent + * is not derived from the feature provider. + * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird der + * Extent nicht vom Feature-Provider übernommen. */ Optional getExtent(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java index e7a6e80ad..59b253bea 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java @@ -39,10 +39,10 @@ default ImmutableTilesetFeaturesDefaults.Builder getBuilder() { abstract class Builder implements BuildableBuilder {} /** - * @langEn Fixed spatial extent of the tileset in the native CRS of the feature provider. If set, - * the extent is not derived from the feature provider. - * @langDe Fester räumlicher Extent des Tilesets im nativen CRS des Feature-Providers. Wenn - * gesetzt, wird der Extent nicht vom Feature-Provider übernommen. + * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If set, the extent + * is not derived from the feature provider. + * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird der + * Extent nicht vom Feature-Provider übernommen. */ Optional getExtent(); } From 37d6e145755f66f2eff861bd0805f5ff21b4c3df Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:17:29 +0100 Subject: [PATCH 12/31] extent: only allow computed: true, document options --- .../features/domain/SpatialExtent.java | 40 ++++++++++++++++++- .../features/domain/TemporalExtent.java | 24 +++++++++++ .../features/domain/SpatialExtentSpec.groovy | 35 ++++++++++++++++ .../features/domain/TemporalExtentSpec.groovy | 11 +++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java index 23ae71f1e..d71fa81b4 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java @@ -15,29 +15,64 @@ import javax.annotation.Nullable; import org.immutables.value.Value; -/** Spatial extent in native CRS. */ +/** + * Spatial extent. The coordinates are in the native CRS of the feature provider for providers and + * types, and in CRS84 (longitude/latitude) for tilesets. + */ @Value.Immutable @JsonDeserialize(builder = ImmutableSpatialExtent.Builder.class) public interface SpatialExtent { + /** + * @langEn Minimum x coordinate. + * @langDe Minimale x-Koordinate. + */ @Nullable Double getXmin(); + /** + * @langEn Minimum y coordinate. + * @langDe Minimale y-Koordinate. + */ @Nullable Double getYmin(); + /** + * @langEn Minimum z coordinate, optional. + * @langDe Minimale z-Koordinate, optional. + */ @Nullable Double getZmin(); + /** + * @langEn Maximum x coordinate. + * @langDe Maximale x-Koordinate. + */ @Nullable Double getXmax(); + /** + * @langEn Maximum y coordinate. + * @langDe Maximale y-Koordinate. + */ @Nullable Double getYmax(); + /** + * @langEn Maximum z coordinate, optional. + * @langDe Maximale z-Koordinate, optional. + */ @Nullable Double getZmax(); + /** + * @langEn Set to `true` to compute the extent from the data instead of inheriting a fixed extent + * from the parent level (provider for types, tileset defaults for tilesets). Must not be + * combined with coordinates; `false` is not allowed. + * @langDe Auf `true` setzen, um den Extent aus den Daten zu berechnen, statt einen festen Extent + * der übergeordneten Ebene (Provider für Types, Tileset-Defaults für Tilesets) zu erben. Darf + * nicht mit Koordinaten kombiniert werden; `false` ist nicht erlaubt. + */ @Nullable Boolean getComputed(); @@ -52,6 +87,9 @@ default void checkExclusiveComputed() { || getZmax() != null; boolean autoCompute = Boolean.TRUE.equals(getComputed()); + Preconditions.checkState( + !Boolean.FALSE.equals(getComputed()), + "SpatialExtent: 'computed' may only be true, omit it for a fixed extent."); Preconditions.checkState( !(hasCoordinates && autoCompute), "SpatialExtent: 'computed' and explicit coordinates must not be set at the same time."); diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java index e554b3d93..eb81c03d8 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java @@ -30,12 +30,32 @@ @JsonDeserialize(builder = ImmutableTemporalExtent.Builder.class) public interface TemporalExtent { + /** + * @langEn Start of the extent, either a date (`yyyy-MM-dd`, UTC) or a date-time with offset. Open + * if not set. + * @langDe Beginn des Extents, entweder ein Datum (`yyyy-MM-dd`, UTC) oder ein Zeitpunkt mit + * Offset. Offen, wenn nicht gesetzt. + */ @Nullable String getStart(); + /** + * @langEn End of the extent, either a date (`yyyy-MM-dd`, inclusive, UTC) or a date-time with + * offset. Open if not set. + * @langDe Ende des Extents, entweder ein Datum (`yyyy-MM-dd`, inklusive, UTC) oder ein Zeitpunkt + * mit Offset. Offen, wenn nicht gesetzt. + */ @Nullable String getEnd(); + /** + * @langEn Set to `true` to compute the extent from the data instead of inheriting a fixed extent + * from the parent level (provider for types). Must not be combined with `start` or `end`; + * `false` is not allowed. + * @langDe Auf `true` setzen, um den Extent aus den Daten zu berechnen, statt einen festen Extent + * der übergeordneten Ebene (Provider für Types) zu erben. Darf nicht mit `start` oder `end` + * kombiniert werden; `false` ist nicht erlaubt. + */ @Nullable Boolean getComputed(); @@ -55,6 +75,10 @@ default Optional toInterval() { default void check() { boolean hasBounds = getStart() != null || getEnd() != null; + Preconditions.checkState( + !Boolean.FALSE.equals(getComputed()), + "TemporalExtent: 'computed' may only be true, omit it for a fixed extent."); + Preconditions.checkState( !(hasBounds && Boolean.TRUE.equals(getComputed())), "TemporalExtent: 'computed' and explicit start/end must not be set at the same time."); diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy new file mode 100644 index 000000000..d9a09aa6a --- /dev/null +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy @@ -0,0 +1,35 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain + +import de.ii.xtraplatform.crs.domain.OgcCrs +import spock.lang.Specification + +class SpatialExtentSpec extends Specification { + + def "computed extent has no bounding box"() { + expect: + new ImmutableSpatialExtent.Builder().computed(true).build().toBoundingBox(OgcCrs.CRS84).isEmpty() + } + + def "computed may only be true"() { + when: + new ImmutableSpatialExtent.Builder().computed(false).build() + + then: + thrown(IllegalStateException) + } + + def "computed must not be combined with coordinates"() { + when: + new ImmutableSpatialExtent.Builder().xmin(0).ymin(0).xmax(1).ymax(1).computed(true).build() + + then: + thrown(IllegalStateException) + } +} diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy index 03d615a1a..6e8155971 100644 --- a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy @@ -58,4 +58,15 @@ class TemporalExtentSpec extends Specification { then: thrown(IllegalStateException) } + + def "computed may only be true"() { + expect: + new ImmutableTemporalExtent.Builder().computed(true).build().toInterval().isEmpty() + + when: + new ImmutableTemporalExtent.Builder().computed(false).build() + + then: + thrown(IllegalStateException) + } } From b466b100be54ccb165a3ffafeeb9a0a0d8dfdd90 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:19:00 +0100 Subject: [PATCH 13/31] extent: add @since v4.9 --- .../features/domain/FeatureProviderDataV2.java | 1 + .../de/ii/xtraplatform/features/domain/FeatureSchema.java | 1 + .../features/domain/FeatureTypeConfiguration.java | 1 + .../de/ii/xtraplatform/features/domain/SpatialExtent.java | 7 +++++++ .../de/ii/xtraplatform/features/domain/TemporalExtent.java | 3 +++ .../de/ii/xtraplatform/tiles/domain/TilesetFeatures.java | 1 + .../xtraplatform/tiles/domain/TilesetFeaturesDefaults.java | 1 + .../java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java | 1 + .../ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java | 1 + .../de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java | 1 + .../xtraplatform/tiles/domain/TilesetMbTilesDefaults.java | 1 + 11 files changed, 19 insertions(+) diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java index 6394fe7c9..1d92743e3 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java @@ -266,6 +266,7 @@ default List getCql2Functions() { * automatic calculation. * @langDe Optionaler räumlicher und zeitlicher Extent für alle Types dieses Providers. Wenn * gesetzt, wird keine automatische Berechnung durchgeführt. + * @since v4.9 */ Optional getExtent(); diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java index 525021bc2..7a739d932 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java @@ -404,6 +404,7 @@ default Type getType() { /** * @langEn Optional spatial and temporal extent for this feature type. * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Feature-Type. + * @since v4.9 */ Optional getExtent(); diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java index 6d0c2f816..301ca5d44 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java @@ -41,6 +41,7 @@ public interface FeatureTypeConfiguration { * calculation for this type. * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Type. Wenn gesetzt, wird keine * automatische Berechnung für diesen Type durchgeführt. + * @since v4.9 */ Optional getExtent(); } diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java index d71fa81b4..e0f388e09 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java @@ -26,6 +26,7 @@ public interface SpatialExtent { /** * @langEn Minimum x coordinate. * @langDe Minimale x-Koordinate. + * @since v4.9 */ @Nullable Double getXmin(); @@ -33,6 +34,7 @@ public interface SpatialExtent { /** * @langEn Minimum y coordinate. * @langDe Minimale y-Koordinate. + * @since v4.9 */ @Nullable Double getYmin(); @@ -40,6 +42,7 @@ public interface SpatialExtent { /** * @langEn Minimum z coordinate, optional. * @langDe Minimale z-Koordinate, optional. + * @since v4.9 */ @Nullable Double getZmin(); @@ -47,6 +50,7 @@ public interface SpatialExtent { /** * @langEn Maximum x coordinate. * @langDe Maximale x-Koordinate. + * @since v4.9 */ @Nullable Double getXmax(); @@ -54,6 +58,7 @@ public interface SpatialExtent { /** * @langEn Maximum y coordinate. * @langDe Maximale y-Koordinate. + * @since v4.9 */ @Nullable Double getYmax(); @@ -61,6 +66,7 @@ public interface SpatialExtent { /** * @langEn Maximum z coordinate, optional. * @langDe Maximale z-Koordinate, optional. + * @since v4.9 */ @Nullable Double getZmax(); @@ -72,6 +78,7 @@ public interface SpatialExtent { * @langDe Auf `true` setzen, um den Extent aus den Daten zu berechnen, statt einen festen Extent * der übergeordneten Ebene (Provider für Types, Tileset-Defaults für Tilesets) zu erben. Darf * nicht mit Koordinaten kombiniert werden; `false` ist nicht erlaubt. + * @since v4.9 */ @Nullable Boolean getComputed(); diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java index eb81c03d8..887ec7af3 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java @@ -35,6 +35,7 @@ public interface TemporalExtent { * if not set. * @langDe Beginn des Extents, entweder ein Datum (`yyyy-MM-dd`, UTC) oder ein Zeitpunkt mit * Offset. Offen, wenn nicht gesetzt. + * @since v4.9 */ @Nullable String getStart(); @@ -44,6 +45,7 @@ public interface TemporalExtent { * offset. Open if not set. * @langDe Ende des Extents, entweder ein Datum (`yyyy-MM-dd`, inklusive, UTC) oder ein Zeitpunkt * mit Offset. Offen, wenn nicht gesetzt. + * @since v4.9 */ @Nullable String getEnd(); @@ -55,6 +57,7 @@ public interface TemporalExtent { * @langDe Auf `true` setzen, um den Extent aus den Daten zu berechnen, statt einen festen Extent * der übergeordneten Ebene (Provider für Types) zu erben. Darf nicht mit `start` oder `end` * kombiniert werden; `false` ist nicht erlaubt. + * @since v4.9 */ @Nullable Boolean getComputed(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java index 7bcc9b831..93da3caec 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java @@ -55,6 +55,7 @@ public interface TilesetFeatures * is not derived from the feature provider. * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird der * Extent nicht vom Feature-Provider übernommen. + * @since v4.9 */ Optional getExtent(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java index 59b253bea..8a7a01e34 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java @@ -43,6 +43,7 @@ abstract class Builder implements BuildableBuilder {} * is not derived from the feature provider. * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird der * Extent nicht vom Feature-Provider übernommen. + * @since v4.9 */ Optional getExtent(); } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java index 4d21f92dd..39f2d939b 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java @@ -44,6 +44,7 @@ public interface TilesetHttp extends TilesetCommon, WithEncodings, Buildable getExtent(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java index b6d9b8365..4cac4c6ec 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java @@ -36,6 +36,7 @@ default ImmutableTilesetHttpDefaults.Builder getBuilder() { /** * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). + * @since v4.9 */ Optional getExtent(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java index a1843209b..ec5ca2488 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java @@ -44,6 +44,7 @@ public interface TilesetMbTiles extends TilesetCommon, Buildable * from the MBTiles metadata is ignored. * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird * `bounds` aus den MBTiles-Metadaten ignoriert. + * @since v4.9 */ Optional getExtent(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java index 4589d1a9b..6220fdddf 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java @@ -43,6 +43,7 @@ default String getTileMatrixSet() { * from the MBTiles metadata is ignored. * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird * `bounds` aus den MBTiles-Metadaten ignoriert. + * @since v4.9 */ Optional getExtent(); } From 3e58f0500e7587f85b0d59da69480bfdf50a68c6 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:28:42 +0100 Subject: [PATCH 14/31] sql: restrict queries to fixed extents --- .../sql/domain/FeatureProviderSql.java | 50 +++++++++++- .../sql/domain/FeatureProviderSqlData.java | 16 ++++ .../features/domain/ExtentFilters.java | 76 +++++++++++++++++++ .../features/domain/ExtentFiltersSpec.groovy | 72 ++++++++++++++++++ 4 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/ExtentFilters.java create mode 100644 xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentFiltersSpec.groovy diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index 7b9e17ee7..b8e07ef01 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -42,6 +42,7 @@ import de.ii.xtraplatform.features.domain.DatasetChangeListener; import de.ii.xtraplatform.features.domain.DecoderFactories; import de.ii.xtraplatform.features.domain.DecoderFactory; +import de.ii.xtraplatform.features.domain.ExtentFilters; import de.ii.xtraplatform.features.domain.FeatureChangeListener; import de.ii.xtraplatform.features.domain.FeatureCrs; import de.ii.xtraplatform.features.domain.FeatureEventHandler.ModifiableContext; @@ -1421,7 +1422,9 @@ protected Query preprocessQuery(Query query) { } @SuppressWarnings("PMD.CognitiveComplexity") - protected Query preprocessQuery(Query query, List resultSetTables) { + protected Query preprocessQuery(Query originalQuery, List resultSetTables) { + Query query = restrictToExtent(originalQuery); + if (query instanceof FeatureQuery && (((FeatureQuery) query).getFields().size() > 1 || !"*".equals(((FeatureQuery) query).getFields().get(0)))) { @@ -1494,6 +1497,51 @@ protected Query preprocessQuery(Query query, List resultSetTables) { return query; } + private Query restrictToExtent(Query query) { + boolean restrictToExtent = + Optional.ofNullable(getData().getQueryGeneration()) + .map(QueryGeneratorSettings::getRestrictToExtent) + .orElse(true); + if (!restrictToExtent) { + return query; + } + if (query instanceof FeatureQuery featureQuery) { + return featureQuery.returnsSingleFeature() + ? query + : ImmutableFeatureQuery.builder() + .from(featureQuery) + .addAllFilters(extentFilters(featureQuery.getType())) + .build(); + } + if (query instanceof MultiFeatureQuery multiQuery) { + return ImmutableMultiFeatureQuery.builder() + .from(multiQuery) + .queries( + multiQuery.getQueries().stream() + .map( + subQuery -> + (SubQuery) + ImmutableSubQuery.builder() + .from(subQuery) + .addAllFilters(extentFilters(subQuery.getType())) + .build()) + .toList()) + .build(); + } + return query; + } + + private List extentFilters(String typeName) { + return Optional.ofNullable(getData().getTypes().get(typeName)) + .map( + type -> + ExtentFilters.of( + type, + getConfiguredSpatialExtent(typeName), + getConfiguredTemporalExtent(typeName))) + .orElse(List.of()); + } + @Override public FeatureStream getFeatureStream(MultiFeatureQuery query) { validateQuery(query); diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSqlData.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSqlData.java index 3613ba116..cd63730e7 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSqlData.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSqlData.java @@ -228,6 +228,22 @@ default boolean getNativeDatetimeComparison() { return false; } + /** + * @langEn Restrict all queries for multiple features to the extent of the type, if a fixed + * extent is configured. Features are selected if they intersect the extent, so they may + * reach beyond it. Queries for a single feature by id are not affected. + * @langDe Schränkt alle Abfragen mehrerer Features auf den Extent des Types ein, wenn ein + * fester Extent konfiguriert ist. Selektiert werden Features, die den Extent schneiden, sie + * können also über ihn hinausreichen. Abfragen eines einzelnen Features per Id sind nicht + * betroffen. + * @default true + * @since v4.9 + */ + @Value.Default + default boolean getRestrictToExtent() { + return true; + } + @DocIgnore @Value.Default default Optional getAccentiCollation() { diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/ExtentFilters.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/ExtentFilters.java new file mode 100644 index 000000000..358a4a3bd --- /dev/null +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/ExtentFilters.java @@ -0,0 +1,76 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain; + +import de.ii.xtraplatform.cql.domain.Bbox; +import de.ii.xtraplatform.cql.domain.Cql2Expression; +import de.ii.xtraplatform.cql.domain.Interval; +import de.ii.xtraplatform.cql.domain.Operand; +import de.ii.xtraplatform.cql.domain.Property; +import de.ii.xtraplatform.cql.domain.SIntersects; +import de.ii.xtraplatform.cql.domain.SpatialLiteral; +import de.ii.xtraplatform.cql.domain.TIntersects; +import de.ii.xtraplatform.cql.domain.Temporal; +import de.ii.xtraplatform.cql.domain.TemporalLiteral; +import de.ii.xtraplatform.crs.domain.BoundingBox; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * Filters that restrict a query to a fixed extent. Intersects is used instead of contains so that + * features and tiles select the same features, even if some of them reach beyond the extent. + */ +public final class ExtentFilters { + + private ExtentFilters() {} + + public static List of( + FeatureSchema type, + Optional spatialExtent, + Optional temporalExtent) { + List filters = new ArrayList<>(); + + spatialExtent + .flatMap(extent -> type.getFilterGeometry().map(geometry -> spatial(geometry, extent))) + .ifPresent(filters::add); + + temporalExtent + .flatMap(extent -> primaryTemporal(type).map(temporal -> temporal(temporal, extent))) + .ifPresent(filters::add); + + return filters; + } + + private static Cql2Expression spatial(FeatureSchema geometry, BoundingBox extent) { + return SIntersects.of( + Property.of(geometry.getFullPathAsString()), SpatialLiteral.of(Bbox.of(extent))); + } + + private static Cql2Expression temporal(Temporal property, org.threeten.extra.Interval extent) { + return TIntersects.of(property, new TemporalLiteral.Builder(extent).build()); + } + + private static Optional primaryTemporal(FeatureSchema type) { + return type.getPrimaryInstant() + .map(instant -> Property.of(instant.getFullPathAsString())) + .or( + () -> + type.getPrimaryInterval() + .map( + interval -> + Interval.of( + List.of(boundOf(interval.first()), boundOf(interval.second()))))); + } + + private static Operand boundOf(FeatureSchema property) { + return property == null + ? TemporalLiteral.of("..") + : Property.of(property.getFullPathAsString()); + } +} diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentFiltersSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentFiltersSpec.groovy new file mode 100644 index 000000000..6f4ca539d --- /dev/null +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentFiltersSpec.groovy @@ -0,0 +1,72 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain + +import de.ii.xtraplatform.cql.domain.Bbox +import de.ii.xtraplatform.cql.domain.Interval +import de.ii.xtraplatform.cql.domain.Property +import de.ii.xtraplatform.cql.domain.SIntersects +import de.ii.xtraplatform.cql.domain.SpatialLiteral +import de.ii.xtraplatform.cql.domain.TIntersects +import de.ii.xtraplatform.cql.domain.TemporalLiteral +import de.ii.xtraplatform.crs.domain.BoundingBox +import de.ii.xtraplatform.crs.domain.EpsgCrs +import spock.lang.Specification + +import java.time.Instant + +class ExtentFiltersSpec extends Specification { + + static BoundingBox BBOX = BoundingBox.of(300000, 5600000, 400000, 5700000, EpsgCrs.of(25832)) + static org.threeten.extra.Interval INTERVAL = + org.threeten.extra.Interval.of(Instant.parse("2020-01-01T00:00:00Z"), Instant.MAX) + + static FeatureSchema type(Map temporalRoles) { + def builder = new ImmutableFeatureSchema.Builder() + .name("t").sourcePath("/t").type(SchemaBase.Type.OBJECT) + .putProperties2("geom", new ImmutableFeatureSchema.Builder() + .sourcePath("geom").type(SchemaBase.Type.GEOMETRY) + .role(SchemaBase.Role.PRIMARY_GEOMETRY)) + temporalRoles.each { name, role -> + builder.putProperties2(name, new ImmutableFeatureSchema.Builder() + .sourcePath(name).type(SchemaBase.Type.DATETIME).role(role)) + } + builder.build() + } + + def "spatial and instant extents become intersects filters"() { + when: + def filters = ExtentFilters.of(type(["date": SchemaBase.Role.PRIMARY_INSTANT]), Optional.of(BBOX), Optional.of(INTERVAL)) + + then: + filters == [ + SIntersects.of(Property.of("geom"), SpatialLiteral.of(Bbox.of(BBOX))), + TIntersects.of(Property.of("date"), new TemporalLiteral.Builder(INTERVAL).build()) + ] + } + + def "an interval extent uses both interval properties"() { + when: + def filters = ExtentFilters.of( + type(["begin": SchemaBase.Role.PRIMARY_INTERVAL_START, "end": SchemaBase.Role.PRIMARY_INTERVAL_END]), + Optional.empty(), Optional.of(INTERVAL)) + + then: + filters == [ + TIntersects.of( + Interval.of([Property.of("begin"), Property.of("end")]), + new TemporalLiteral.Builder(INTERVAL).build()) + ] + } + + def "no extent or no matching property means no filter"() { + expect: + ExtentFilters.of(type([:]), Optional.empty(), Optional.empty()).isEmpty() + ExtentFilters.of(type([:]), Optional.empty(), Optional.of(INTERVAL)).isEmpty() + } +} From 3dd24961f14264136ab9ce266b7cce92fda893ef Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:28:44 +0100 Subject: [PATCH 15/31] tiles: http tilesets fall back to tile matrix set extent --- .../tiles/app/TileProviderHttp.java | 49 ++++++++++++++++--- .../tiles/domain/TilesetHttp.java | 6 ++- .../tiles/domain/TilesetHttpDefaults.java | 6 ++- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java index 6851b16fc..9c77c270c 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java @@ -12,12 +12,17 @@ import dagger.assisted.AssistedInject; import de.ii.xtraplatform.base.domain.resiliency.VolatileRegistry; import de.ii.xtraplatform.crs.domain.BoundingBox; +import de.ii.xtraplatform.crs.domain.CrsTransformationException; +import de.ii.xtraplatform.crs.domain.CrsTransformerFactory; import de.ii.xtraplatform.crs.domain.OgcCrs; import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; import de.ii.xtraplatform.features.domain.ProviderData; import de.ii.xtraplatform.tiles.domain.ChainedTileProvider; import de.ii.xtraplatform.tiles.domain.ImmutableTilesetMetadata; +import de.ii.xtraplatform.tiles.domain.MinMax; +import de.ii.xtraplatform.tiles.domain.TileMatrixSet; +import de.ii.xtraplatform.tiles.domain.TileMatrixSetRepository; import de.ii.xtraplatform.tiles.domain.TileProviderData; import de.ii.xtraplatform.tiles.domain.TileProviderHttpData; import de.ii.xtraplatform.tiles.domain.TileQuery; @@ -31,6 +36,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,11 +55,19 @@ public class TileProviderHttp extends AbstractTileProvider private static final Logger LOGGER = LoggerFactory.getLogger(TileProviderHttp.class); private final ChainedTileProvider providerChain; private final Map metadata; + private final TileMatrixSetRepository tileMatrixSetRepository; + private final CrsTransformerFactory crsTransformerFactory; @AssistedInject - public TileProviderHttp(VolatileRegistry volatileRegistry, @Assisted TileProviderHttpData data) { + public TileProviderHttp( + TileMatrixSetRepository tileMatrixSetRepository, + CrsTransformerFactory crsTransformerFactory, + VolatileRegistry volatileRegistry, + @Assisted TileProviderHttpData data) { super(volatileRegistry, data, "access"); this.metadata = new LinkedHashMap<>(); + this.tileMatrixSetRepository = tileMatrixSetRepository; + this.crsTransformerFactory = crsTransformerFactory; Map tilesetSources = data.getTilesets().entrySet().stream() @@ -116,23 +130,46 @@ private void loadMetadata() { } private TilesetMetadata loadMetadata(TilesetHttp tileset) { + Map levels = + tileset.getLevels().isEmpty() + ? getData().getTilesetDefaults().getLevels() + : tileset.getLevels(); Optional bounds = tileset .getExtent() .or(() -> getData().getTilesetDefaults().getExtent()) - .flatMap(extent -> extent.toBoundingBox(OgcCrs.CRS84)); + .flatMap(extent -> extent.toBoundingBox(OgcCrs.CRS84)) + .or(() -> getTileMatrixSetsExtent(levels.keySet())); return ImmutableTilesetMetadata.builder() .encodings( tileset.getEncodings().isEmpty() ? getData().getTilesetDefaults().getEncodings().keySet() : tileset.getEncodings().keySet()) - .levels( - tileset.getLevels().isEmpty() - ? getData().getTilesetDefaults().getLevels() - : tileset.getLevels()) + .levels(levels) .center(tileset.getCenter().or(() -> getData().getTilesetDefaults().getCenter())) .bounds(bounds) .build(); } + + private Optional getTileMatrixSetsExtent(Set tileMatrixSetIds) { + return tileMatrixSetIds.stream() + .map(tileMatrixSetRepository::get) + .flatMap(Optional::stream) + .map(this::toCrs84) + .flatMap(Optional::stream) + .reduce(BoundingBox::merge); + } + + private Optional toCrs84(TileMatrixSet tileMatrixSet) { + try { + return Optional.of(tileMatrixSet.getBoundingBoxCrs84(crsTransformerFactory)); + } catch (CrsTransformationException e) { + LOGGER.debug( + "Could not transform the extent of tile matrix set '{}' to CRS84: {}", + tileMatrixSet.getId(), + e.getMessage()); + return Optional.empty(); + } + } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java index 39f2d939b..c4a229507 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java @@ -42,8 +42,10 @@ public interface TilesetHttp extends TilesetCommon, WithEncodings, Buildable getEncodings(); /** - * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). - * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). + * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If not set, the + * extent of the tile matrix sets is used. + * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn nicht gesetzt, wird + * der Extent der Kachelschemas verwendet. * @since v4.9 */ Optional getExtent(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java index 4cac4c6ec..c953da6ca 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java @@ -34,8 +34,10 @@ default ImmutableTilesetHttpDefaults.Builder getBuilder() { } /** - * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). - * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). + * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If not set, the + * extent of the tile matrix sets is used. + * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn nicht gesetzt, wird + * der Extent der Kachelschemas verwendet. * @since v4.9 */ Optional getExtent(); From 5d8d068658e097ff19083b620d59bf289d5ba8c4 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:42:25 +0100 Subject: [PATCH 16/31] extract extent inheritance and query restriction for testing --- .../sql/domain/FeatureProviderSql.java | 28 +--------------- .../domain/AbstractFeatureProvider.java | 26 +++++---------- .../features/domain/ExtentFilters.java | 33 +++++++++++++++++++ .../features/domain/FeatureTypeExtent.java | 18 ++++++++++ 4 files changed, 61 insertions(+), 44 deletions(-) diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index b8e07ef01..633045ed4 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -1502,33 +1502,7 @@ private Query restrictToExtent(Query query) { Optional.ofNullable(getData().getQueryGeneration()) .map(QueryGeneratorSettings::getRestrictToExtent) .orElse(true); - if (!restrictToExtent) { - return query; - } - if (query instanceof FeatureQuery featureQuery) { - return featureQuery.returnsSingleFeature() - ? query - : ImmutableFeatureQuery.builder() - .from(featureQuery) - .addAllFilters(extentFilters(featureQuery.getType())) - .build(); - } - if (query instanceof MultiFeatureQuery multiQuery) { - return ImmutableMultiFeatureQuery.builder() - .from(multiQuery) - .queries( - multiQuery.getQueries().stream() - .map( - subQuery -> - (SubQuery) - ImmutableSubQuery.builder() - .from(subQuery) - .addAllFilters(extentFilters(subQuery.getType())) - .build()) - .toList()) - .build(); - } - return query; + return restrictToExtent ? ExtentFilters.restrict(query, this::extentFilters) : query; } private List extentFilters(String typeName) { diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java index 6988464d2..c2131c984 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java @@ -645,27 +645,19 @@ protected Query preprocessQuery(Query query) { } protected Optional getConfiguredSpatialExtent(String typeName) { - Optional fromType = - Optional.ofNullable(getData().getTypes().get(typeName)) - .flatMap(FeatureSchema::getExtent) - .flatMap(FeatureTypeExtent::getSpatial); - Optional fromProvider = - getData().getExtent().flatMap(FeatureTypeExtent::getSpatial); - - return fromType - .or(() -> fromProvider) + return getConfiguredExtent(typeName) + .getSpatial() .flatMap(extent -> extent.toBoundingBox(getData().getNativeCrs().orElse(OgcCrs.CRS84))); } protected Optional getConfiguredTemporalExtent(String typeName) { - Optional fromType = - Optional.ofNullable(getData().getTypes().get(typeName)) - .flatMap(FeatureSchema::getExtent) - .flatMap(FeatureTypeExtent::getTemporal); - Optional fromProvider = - getData().getExtent().flatMap(FeatureTypeExtent::getTemporal); - - return fromType.or(() -> fromProvider).flatMap(TemporalExtent::toInterval); + return getConfiguredExtent(typeName).getTemporal().flatMap(TemporalExtent::toInterval); + } + + private FeatureTypeExtent getConfiguredExtent(String typeName) { + return FeatureTypeExtent.inherit( + Optional.ofNullable(getData().getTypes().get(typeName)).flatMap(FeatureSchema::getExtent), + getData().getExtent()); } protected Optional transformSpatialExtent( diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/ExtentFilters.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/ExtentFilters.java index 358a4a3bd..090b899db 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/ExtentFilters.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/ExtentFilters.java @@ -18,9 +18,11 @@ import de.ii.xtraplatform.cql.domain.Temporal; import de.ii.xtraplatform.cql.domain.TemporalLiteral; import de.ii.xtraplatform.crs.domain.BoundingBox; +import de.ii.xtraplatform.features.domain.MultiFeatureQuery.SubQuery; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.function.Function; /** * Filters that restrict a query to a fixed extent. Intersects is used instead of contains so that @@ -47,6 +49,37 @@ public static List of( return filters; } + /** + * Adds the extent filters of each queried type to a query. Queries for a single feature are not + * restricted, so every feature stays reachable by its id. + */ + public static Query restrict(Query query, Function> filtersForType) { + if (query instanceof FeatureQuery featureQuery && !featureQuery.returnsSingleFeature()) { + return ImmutableFeatureQuery.builder() + .from(featureQuery) + .addAllFilters(filtersForType.apply(featureQuery.getType())) + .build(); + } + if (query instanceof MultiFeatureQuery multiQuery) { + return ImmutableMultiFeatureQuery.builder() + .from(multiQuery) + .queries( + multiQuery.getQueries().stream() + .map(subQuery -> restrictSubQuery(subQuery, filtersForType)) + .toList()) + .build(); + } + return query; + } + + private static SubQuery restrictSubQuery( + SubQuery subQuery, Function> filtersForType) { + return ImmutableSubQuery.builder() + .from(subQuery) + .addAllFilters(filtersForType.apply(subQuery.getType())) + .build(); + } + private static Cql2Expression spatial(FeatureSchema geometry, BoundingBox extent) { return SIntersects.of( Property.of(geometry.getFullPathAsString()), SpatialLiteral.of(Bbox.of(extent))); diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java index bfe1a1110..713806f08 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java @@ -18,4 +18,22 @@ public interface FeatureTypeExtent { Optional getSpatial(); Optional getTemporal(); + + /** + * Each part of the type extent replaces the same part of the provider extent; a part with {@code + * computed: true} therefore discards an inherited fixed extent. + */ + static FeatureTypeExtent inherit( + Optional typeExtent, Optional providerExtent) { + return ImmutableFeatureTypeExtent.builder() + .spatial( + typeExtent + .flatMap(FeatureTypeExtent::getSpatial) + .or(() -> providerExtent.flatMap(FeatureTypeExtent::getSpatial))) + .temporal( + typeExtent + .flatMap(FeatureTypeExtent::getTemporal) + .or(() -> providerExtent.flatMap(FeatureTypeExtent::getTemporal))) + .build(); + } } From d8a27631d976eaccbdeee5ad6b0903b685a4984f Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:43:23 +0100 Subject: [PATCH 17/31] add extent tests --- .../features/domain/ExtentFiltersSpec.groovy | 49 ++++++++ .../domain/FeatureTypeExtentSpec.groovy | 60 ++++++++++ .../features/domain/SpatialExtentSpec.groovy | 27 +++++ .../app/TileProviderHttpExtentSpec.groovy | 109 ++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/FeatureTypeExtentSpec.groovy create mode 100644 xtraplatform-tiles/src/test/groovy/de/ii/xtraplatform/tiles/app/TileProviderHttpExtentSpec.groovy diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentFiltersSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentFiltersSpec.groovy index 6f4ca539d..d9851db74 100644 --- a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentFiltersSpec.groovy +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentFiltersSpec.groovy @@ -8,6 +8,7 @@ package de.ii.xtraplatform.features.domain import de.ii.xtraplatform.cql.domain.Bbox +import de.ii.xtraplatform.cql.domain.Cql2Expression import de.ii.xtraplatform.cql.domain.Interval import de.ii.xtraplatform.cql.domain.Property import de.ii.xtraplatform.cql.domain.SIntersects @@ -69,4 +70,52 @@ class ExtentFiltersSpec extends Specification { ExtentFilters.of(type([:]), Optional.empty(), Optional.empty()).isEmpty() ExtentFilters.of(type([:]), Optional.empty(), Optional.of(INTERVAL)).isEmpty() } + + static Cql2Expression FILTER = SIntersects.of(Property.of("geom"), SpatialLiteral.of(Bbox.of(BBOX))) + + def "queries for multiple features are restricted"() { + given: + def query = ImmutableFeatureQuery.builder().type("t").build() + + when: + def restricted = ExtentFilters.restrict(query, { type -> type == "t" ? [FILTER] : [] }) as FeatureQuery + + then: + restricted.filters == [FILTER] + } + + def "existing filters are kept"() { + given: + def existing = SIntersects.of(Property.of("other"), SpatialLiteral.of(Bbox.of(0, 0, 1, 1))) + def query = ImmutableFeatureQuery.builder().type("t").addFilters(existing).build() + + when: + def restricted = ExtentFilters.restrict(query, { [FILTER] }) as FeatureQuery + + then: + restricted.filters == [existing, FILTER] + } + + def "queries for a single feature are not restricted"() { + given: + def query = ImmutableFeatureQuery.builder().type("t").returnsSingleFeature(true).build() + + expect: + ExtentFilters.restrict(query, { [FILTER] }).is(query) + } + + def "each sub query of a multi query gets the filters of its type"() { + given: + def other = TIntersects.of(Property.of("date"), new TemporalLiteral.Builder(INTERVAL).build()) + def query = ImmutableMultiFeatureQuery.builder() + .addQueries(ImmutableSubQuery.builder().type("a").collectionId("a").build()) + .addQueries(ImmutableSubQuery.builder().type("b").collectionId("b").build()) + .build() + + when: + def restricted = ExtentFilters.restrict(query, { type -> type == "a" ? [FILTER] : [other] }) as MultiFeatureQuery + + then: + restricted.queries*.filters == [[FILTER], [other]] + } } diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/FeatureTypeExtentSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/FeatureTypeExtentSpec.groovy new file mode 100644 index 000000000..c7a7695e2 --- /dev/null +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/FeatureTypeExtentSpec.groovy @@ -0,0 +1,60 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain + +import spock.lang.Specification + +class FeatureTypeExtentSpec extends Specification { + + static SpatialExtent FIXED_SPATIAL = new ImmutableSpatialExtent.Builder().xmin(0).ymin(0).xmax(1).ymax(1).build() + static SpatialExtent OTHER_SPATIAL = new ImmutableSpatialExtent.Builder().xmin(5).ymin(5).xmax(6).ymax(6).build() + static SpatialExtent COMPUTED_SPATIAL = new ImmutableSpatialExtent.Builder().computed(true).build() + static TemporalExtent FIXED_TEMPORAL = new ImmutableTemporalExtent.Builder().start("2020-01-01").build() + + static Optional extent(SpatialExtent spatial, TemporalExtent temporal) { + Optional.of(ImmutableFeatureTypeExtent.builder() + .spatial(Optional.ofNullable(spatial)) + .temporal(Optional.ofNullable(temporal)) + .build()) + } + + def "a type without extent inherits the provider extent"() { + when: + def resolved = FeatureTypeExtent.inherit(Optional.empty(), extent(FIXED_SPATIAL, FIXED_TEMPORAL)) + + then: + resolved.spatial == Optional.of(FIXED_SPATIAL) + resolved.temporal == Optional.of(FIXED_TEMPORAL) + } + + def "the type extent replaces the provider extent per part"() { + when: + def resolved = FeatureTypeExtent.inherit(extent(OTHER_SPATIAL, null), extent(FIXED_SPATIAL, FIXED_TEMPORAL)) + + then: + resolved.spatial == Optional.of(OTHER_SPATIAL) + resolved.temporal == Optional.of(FIXED_TEMPORAL) + } + + def "computed on the type discards the inherited fixed extent"() { + when: + def resolved = FeatureTypeExtent.inherit(extent(COMPUTED_SPATIAL, null), extent(FIXED_SPATIAL, null)) + + then: + resolved.spatial.flatMap { it.toBoundingBox(de.ii.xtraplatform.crs.domain.OgcCrs.CRS84) }.isEmpty() + } + + def "nothing configured means nothing fixed"() { + when: + def resolved = FeatureTypeExtent.inherit(Optional.empty(), Optional.empty()) + + then: + resolved.spatial.isEmpty() + resolved.temporal.isEmpty() + } +} diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy index d9a09aa6a..45f1c787e 100644 --- a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy @@ -7,6 +7,8 @@ */ package de.ii.xtraplatform.features.domain +import de.ii.xtraplatform.crs.domain.BoundingBox +import de.ii.xtraplatform.crs.domain.EpsgCrs import de.ii.xtraplatform.crs.domain.OgcCrs import spock.lang.Specification @@ -32,4 +34,29 @@ class SpatialExtentSpec extends Specification { then: thrown(IllegalStateException) } + + def "coordinates become a bounding box in the given CRS"() { + given: + def crs = EpsgCrs.of(25832) + + expect: + new ImmutableSpatialExtent.Builder().xmin(1).ymin(2).xmax(3).ymax(4).build().toBoundingBox(crs) == + Optional.of(BoundingBox.of(1, 2, 3, 4, crs)) + new ImmutableSpatialExtent.Builder().xmin(1).ymin(2).zmin(0).xmax(3).ymax(4).zmax(10).build().toBoundingBox(crs) == + Optional.of(BoundingBox.of(1, 2, 0, 3, 4, 10, crs)) + } + + def "incomplete coordinates are rejected"() { + when: + new ImmutableSpatialExtent.Builder().xmin(1).ymin(2).xmax(3).build() + + then: + thrown(IllegalStateException) + + when: + new ImmutableSpatialExtent.Builder().xmin(1).ymin(2).xmax(3).ymax(4).zmin(0).build() + + then: + thrown(IllegalStateException) + } } diff --git a/xtraplatform-tiles/src/test/groovy/de/ii/xtraplatform/tiles/app/TileProviderHttpExtentSpec.groovy b/xtraplatform-tiles/src/test/groovy/de/ii/xtraplatform/tiles/app/TileProviderHttpExtentSpec.groovy new file mode 100644 index 000000000..6050bcf8b --- /dev/null +++ b/xtraplatform-tiles/src/test/groovy/de/ii/xtraplatform/tiles/app/TileProviderHttpExtentSpec.groovy @@ -0,0 +1,109 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.tiles.app + +import de.ii.xtraplatform.base.domain.resiliency.VolatileRegistry +import de.ii.xtraplatform.crs.domain.BoundingBox +import de.ii.xtraplatform.crs.domain.CrsTransformationException +import de.ii.xtraplatform.crs.domain.CrsTransformerFactory +import de.ii.xtraplatform.crs.domain.OgcCrs +import de.ii.xtraplatform.features.domain.ImmutableSpatialExtent +import de.ii.xtraplatform.features.domain.SpatialExtent +import de.ii.xtraplatform.tiles.domain.ImmutableMinMax +import de.ii.xtraplatform.tiles.domain.ImmutableTileProviderHttpData +import de.ii.xtraplatform.tiles.domain.ImmutableTilesetHttp +import de.ii.xtraplatform.tiles.domain.ImmutableTilesetHttpDefaults +import de.ii.xtraplatform.tiles.domain.TileMatrixSet +import de.ii.xtraplatform.tiles.domain.TileMatrixSetRepository +import de.ii.xtraplatform.tiles.domain.TilesFormat +import de.ii.xtraplatform.tiles.domain.TilesetHttp +import spock.lang.Specification + +class TileProviderHttpExtentSpec extends Specification { + + static SpatialExtent TILESET_EXTENT = new ImmutableSpatialExtent.Builder().xmin(7).ymin(50).xmax(8).ymax(51).build() + static SpatialExtent DEFAULTS_EXTENT = new ImmutableSpatialExtent.Builder().xmin(5).ymin(47).xmax(15).ymax(55).build() + static SpatialExtent COMPUTED = new ImmutableSpatialExtent.Builder().computed(true).build() + + TileMatrixSetRepository tileMatrixSets = Stub() + CrsTransformerFactory crsTransformerFactory = Stub() + + TileMatrixSet tileMatrixSet(String id, BoundingBox crs84) { + TileMatrixSet tms = Stub() + tms.getId() >> id + tms.getBoundingBoxCrs84(_) >> crs84 + tileMatrixSets.get(id) >> Optional.of(tms) + tms + } + + TileProviderHttp provider(SpatialExtent defaultsExtent) { + def defaults = new ImmutableTilesetHttpDefaults.Builder() + .putLevels("Unknown", new ImmutableMinMax.Builder().min(0).max(10)) + .putEncodings(TilesFormat.MVT, "pbf") + if (defaultsExtent != null) { + defaults.extent(defaultsExtent) + } + def data = new ImmutableTileProviderHttpData.Builder() + .id("tiles") + .providerType("TILE") + .providerSubType("HTTP") + .tilesetDefaults(defaults.build()) + .build() + new TileProviderHttp(tileMatrixSets, crsTransformerFactory, Stub(VolatileRegistry), data) + } + + static TilesetHttp tileset(SpatialExtent extent, List tileMatrixSetIds = []) { + def builder = new ImmutableTilesetHttp.Builder().id("ts").urlTemplate("https://example.com/{z}/{y}/{x}") + tileMatrixSetIds.each { builder.putLevels(it, new ImmutableMinMax.Builder().min(0).max(10)) } + if (extent != null) { + builder.extent(extent) + } + builder.build() + } + + static BoundingBox crs84(double xmin, double ymin, double xmax, double ymax) { + BoundingBox.of(xmin, ymin, xmax, ymax, OgcCrs.CRS84) + } + + def "the tileset extent wins over the defaults"() { + expect: + provider(DEFAULTS_EXTENT).loadMetadata(tileset(TILESET_EXTENT)).bounds == Optional.of(crs84(7, 50, 8, 51)) + } + + def "the defaults extent is used if the tileset has none"() { + expect: + provider(DEFAULTS_EXTENT).loadMetadata(tileset(null)).bounds == Optional.of(crs84(5, 47, 15, 55)) + } + + def "without a fixed extent the union of the tile matrix set extents is used"() { + given: + tileMatrixSet("A", crs84(0, 0, 10, 10)) + tileMatrixSet("B", crs84(-5, 5, 5, 20)) + + expect: + provider(null).loadMetadata(tileset(null, ["A", "B"])).bounds == Optional.of(crs84(-5, 0, 10, 20)) + } + + def "computed on the tileset discards the defaults extent"() { + given: + tileMatrixSet("A", crs84(0, 0, 10, 10)) + + expect: + provider(DEFAULTS_EXTENT).loadMetadata(tileset(COMPUTED, ["A"])).bounds == Optional.of(crs84(0, 0, 10, 10)) + } + + def "tile matrix sets that cannot be transformed are skipped"() { + given: + TileMatrixSet broken = Stub() + broken.getBoundingBoxCrs84(_) >> { throw new CrsTransformationException("no") } + tileMatrixSets.get("broken") >> Optional.of(broken) + + expect: + provider(null).loadMetadata(tileset(null, ["broken"])).bounds.isEmpty() + } +} From 543383dfb795d816017a291186b178764f7c2e25 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:50:40 +0100 Subject: [PATCH 18/31] sql: test encoding of extent filters --- .../sql/app/FilterEncoderSqlSpec.groovy | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/FilterEncoderSqlSpec.groovy b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/FilterEncoderSqlSpec.groovy index 4c1478a27..af6ab8b43 100644 --- a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/FilterEncoderSqlSpec.groovy +++ b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/FilterEncoderSqlSpec.groovy @@ -28,7 +28,12 @@ import de.ii.xtraplatform.cql.domain.AEquals import de.ii.xtraplatform.cql.domain.AOverlaps import de.ii.xtraplatform.cql.domain.ArrayLiteral import de.ii.xtraplatform.crs.domain.CrsTransformerFactory +import de.ii.xtraplatform.crs.domain.BoundingBox import de.ii.xtraplatform.crs.domain.OgcCrs +import de.ii.xtraplatform.features.domain.ExtentFilters +import de.ii.xtraplatform.features.domain.FeatureSchema +import de.ii.xtraplatform.features.domain.ImmutableFeatureSchema +import de.ii.xtraplatform.features.domain.SchemaBase import de.ii.xtraplatform.crs.infra.CrsTransformerFactoryProj import de.ii.xtraplatform.features.sql.domain.SqlDialectGpkg import de.ii.xtraplatform.features.sql.domain.SqlDialectPgis @@ -37,6 +42,7 @@ import spock.lang.Shared import spock.lang.Specification import java.nio.file.Path +import java.time.Instant import java.util.concurrent.CompletableFuture class FilterEncoderSqlSpec extends Specification { @@ -368,6 +374,64 @@ class FilterEncoderSqlSpec extends Specification { actual == expected } + static FeatureSchema typeWithExtentProperties(Map properties) { + def builder = new ImmutableFeatureSchema.Builder().name("building").sourcePath("/building").type(SchemaBase.Type.OBJECT) + properties.each { name, role -> + builder.putProperties2(name, new ImmutableFeatureSchema.Builder() + .sourcePath(name) + .type(role == SchemaBase.Role.PRIMARY_GEOMETRY ? SchemaBase.Type.GEOMETRY : SchemaBase.Type.DATETIME) + .role(role)) + } + builder.build() + } + + def 'extent restriction, spatial'() { + + given: + def type = typeWithExtentProperties(["location": SchemaBase.Role.PRIMARY_GEOMETRY]) + def extent = BoundingBox.of(-118.0, 33.8, -117.9, 34.0, OgcCrs.CRS84) + + when: + def filters = ExtentFilters.of(type, Optional.of(extent), Optional.empty()) + String actual = filterEncoder.encode(filters[0], QuerySchemaFixtures.SIMPLE_GEOMETRY) + + then: 'intersects, not within, so features reaching beyond the extent are kept' + filters.size() == 1 + actual == "ST_Intersects(A.location, ST_GeomFromText('POLYGON((-118.0 33.8,-117.9 33.8,-117.9 34.0,-118.0 34.0,-118.0 33.8))',4326))" + } + + def 'extent restriction, temporal with open end'() { + + given: + def type = typeWithExtentProperties(["updated": SchemaBase.Role.PRIMARY_INSTANT]) + def extent = org.threeten.extra.Interval.of(Instant.parse("2017-06-10T00:00:00Z"), Instant.MAX) + + when: + def filters = ExtentFilters.of(type, Optional.empty(), Optional.of(extent)) + String actual = filterEncoder.encode(filters[0], QuerySchemaFixtures.SIMPLE_INTERVAL) + + then: 'the open end of the extent becomes infinity' + filters.size() == 1 + actual == "(A.updated::timestamp(0),A.updated::timestamp(0)) OVERLAPS (TIMESTAMP '2017-06-10T00:00:00Z',TIMESTAMP 'infinity')" + } + + def 'extent restriction, temporal on an interval'() { + + given: + def type = typeWithExtentProperties([ + "start": SchemaBase.Role.PRIMARY_INTERVAL_START, + "end" : SchemaBase.Role.PRIMARY_INTERVAL_END]) + def extent = org.threeten.extra.Interval.of(Instant.parse("2017-06-10T00:00:00Z"), Instant.parse("2017-06-12T00:00:00Z")) + + when: + def filters = ExtentFilters.of(type, Optional.empty(), Optional.of(extent)) + String actual = filterEncoder.encode(filters[0], QuerySchemaFixtures.SIMPLE_INTERVAL) + + then: + filters.size() == 1 + actual == "(COALESCE(A.start,TIMESTAMP '-infinity'), COALESCE(A.end,TIMESTAMP 'infinity')) OVERLAPS (TIMESTAMP '2017-06-10T00:00:00Z',TIMESTAMP '2017-06-12T00:00:00Z')" + } + def 'temporal operation, timestamp'() { given: From 52b138b94710ab946efade15223d11abe45b8b18 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 14:55:17 +0100 Subject: [PATCH 19/31] sql: separate options for spatial and temporal extent restriction --- .../sql/domain/FeatureProviderSql.java | 15 +++++---- .../sql/domain/FeatureProviderSqlData.java | 32 ++++++++++++++----- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index 633045ed4..b6646bdad 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -1498,21 +1498,22 @@ protected Query preprocessQuery(Query originalQuery, List resultSetTable } private Query restrictToExtent(Query query) { - boolean restrictToExtent = - Optional.ofNullable(getData().getQueryGeneration()) - .map(QueryGeneratorSettings::getRestrictToExtent) - .orElse(true); - return restrictToExtent ? ExtentFilters.restrict(query, this::extentFilters) : query; + return ExtentFilters.restrict(query, this::extentFilters); } private List extentFilters(String typeName) { + Optional settings = Optional.ofNullable(getData().getQueryGeneration()); + boolean spatial = settings.map(QueryGeneratorSettings::getRestrictToSpatialExtent).orElse(true); + boolean temporal = + settings.map(QueryGeneratorSettings::getRestrictToTemporalExtent).orElse(true); + return Optional.ofNullable(getData().getTypes().get(typeName)) .map( type -> ExtentFilters.of( type, - getConfiguredSpatialExtent(typeName), - getConfiguredTemporalExtent(typeName))) + spatial ? getConfiguredSpatialExtent(typeName) : Optional.empty(), + temporal ? getConfiguredTemporalExtent(typeName) : Optional.empty())) .orElse(List.of()); } diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSqlData.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSqlData.java index cd63730e7..c72118361 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSqlData.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSqlData.java @@ -229,18 +229,34 @@ default boolean getNativeDatetimeComparison() { } /** - * @langEn Restrict all queries for multiple features to the extent of the type, if a fixed - * extent is configured. Features are selected if they intersect the extent, so they may - * reach beyond it. Queries for a single feature by id are not affected. - * @langDe Schränkt alle Abfragen mehrerer Features auf den Extent des Types ein, wenn ein - * fester Extent konfiguriert ist. Selektiert werden Features, die den Extent schneiden, sie - * können also über ihn hinausreichen. Abfragen eines einzelnen Features per Id sind nicht - * betroffen. + * @langEn Restrict all queries for multiple features to the spatial extent of the type, if a + * fixed spatial extent is configured. Features are selected if they intersect the extent, + * so they may reach beyond it. Queries for a single feature by id are not affected. + * @langDe Schränkt alle Abfragen mehrerer Features auf den räumlichen Extent des Types ein, + * wenn ein fester räumlicher Extent konfiguriert ist. Selektiert werden Features, die den + * Extent schneiden, sie können also über ihn hinausreichen. Abfragen eines einzelnen + * Features per Id sind nicht betroffen. * @default true * @since v4.9 */ @Value.Default - default boolean getRestrictToExtent() { + default boolean getRestrictToSpatialExtent() { + return true; + } + + /** + * @langEn Restrict all queries for multiple features to the temporal extent of the type, if a + * fixed temporal extent is configured. Features are selected if they intersect the extent, + * so they may reach beyond it. Queries for a single feature by id are not affected. + * @langDe Schränkt alle Abfragen mehrerer Features auf den zeitlichen Extent des Types ein, + * wenn ein fester zeitlicher Extent konfiguriert ist. Selektiert werden Features, die den + * Extent schneiden, sie können also über ihn hinausreichen. Abfragen eines einzelnen + * Features per Id sind nicht betroffen. + * @default true + * @since v4.9 + */ + @Value.Default + default boolean getRestrictToTemporalExtent() { return true; } From 8cc17e625ad16c1ae9388886583096f9f48e5e66 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Sat, 31 Oct 2026 20:18:08 +0100 Subject: [PATCH 20/31] fix PMD violations in extent handling --- .../sql/domain/FeatureProviderSql.java | 1 - .../features/domain/SpatialExtent.java | 35 +++++++++++-------- .../tiles/app/TileProviderHttp.java | 10 +++--- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index b6646bdad..4354d7755 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -1127,7 +1127,6 @@ public Optional getSpatialExtent(String typeName) { } @Override - @SuppressWarnings("PMD.AvoidCatchingGenericException") public Optional getSpatialExtent(String typeName, EpsgCrs crs) { return getSpatialExtent(typeName) .flatMap(boundingBox -> transformSpatialExtent(boundingBox, crs)); diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java index e0f388e09..0d4feb5ed 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java @@ -85,13 +85,7 @@ public interface SpatialExtent { @Value.Check default void checkExclusiveComputed() { - boolean hasCoordinates = - getXmin() != null - || getYmin() != null - || getZmin() != null - || getXmax() != null - || getYmax() != null - || getZmax() != null; + boolean hasCoordinates = hasCoordinates(); boolean autoCompute = Boolean.TRUE.equals(getComputed()); Preconditions.checkState( @@ -102,16 +96,29 @@ default void checkExclusiveComputed() { "SpatialExtent: 'computed' and explicit coordinates must not be set at the same time."); if (hasCoordinates) { - Preconditions.checkState( - getXmin() != null && getYmin() != null && getXmax() != null && getYmax() != null, - "SpatialExtent: xmin, ymin, xmax, ymax are required when coordinates are used."); - - Preconditions.checkState( - (getZmin() == null && getZmax() == null) || (getZmin() != null && getZmax() != null), - "SpatialExtent: zmin and zmax must both be set or both be absent."); + checkCoordinatesComplete(); } } + private boolean hasCoordinates() { + return getXmin() != null + || getYmin() != null + || getZmin() != null + || getXmax() != null + || getYmax() != null + || getZmax() != null; + } + + private void checkCoordinatesComplete() { + Preconditions.checkState( + getXmin() != null && getYmin() != null && getXmax() != null && getYmax() != null, + "SpatialExtent: xmin, ymin, xmax, ymax are required when coordinates are used."); + + Preconditions.checkState( + (getZmin() == null && getZmax() == null) || (getZmin() != null && getZmax() != null), + "SpatialExtent: zmin and zmax must both be set or both be absent."); + } + default Optional toBoundingBox(EpsgCrs nativeCrs) { if (getXmin() == null || getYmin() == null || getXmax() == null || getYmax() == null) { return Optional.empty(); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java index 9c77c270c..089756ff0 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java @@ -165,10 +165,12 @@ private Optional toCrs84(TileMatrixSet tileMatrixSet) { try { return Optional.of(tileMatrixSet.getBoundingBoxCrs84(crsTransformerFactory)); } catch (CrsTransformationException e) { - LOGGER.debug( - "Could not transform the extent of tile matrix set '{}' to CRS84: {}", - tileMatrixSet.getId(), - e.getMessage()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "Could not transform the extent of tile matrix set '{}' to CRS84: {}", + tileMatrixSet.getId(), + e.getMessage()); + } return Optional.empty(); } } From 776cd1cbcc694aa8756f7e9fa4dd5885e572e54b Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Mon, 9 Nov 2026 18:44:59 +0100 Subject: [PATCH 21/31] fix extents of API collections being read as provider extents FeatureTypeConfiguration is implemented by the collection configuration of OGC APIs, so the type extent added to it replaced the type of the existing collection option `extent`. Collection extents of earlier versions were then read as provider extents: the CRS was ignored and temporal values in milliseconds failed to load. The type extent stays in FeatureSchema, where the provider types declare it. --- .../features/domain/FeatureTypeConfiguration.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java index 301ca5d44..968af0820 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeConfiguration.java @@ -35,13 +35,4 @@ public interface FeatureTypeConfiguration { * @default "" */ Optional getDescription(); - - /** - * @langEn Optional spatial and temporal extent for this type. If set, disables automatic - * calculation for this type. - * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Type. Wenn gesetzt, wird keine - * automatische Berechnung für diesen Type durchgeführt. - * @since v4.9 - */ - Optional getExtent(); } From 894fd09975893c261d3ced8e60610153e12674ac Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Mon, 9 Nov 2026 18:46:24 +0100 Subject: [PATCH 22/31] fix feature count ignoring the restriction to a fixed extent Queries for multiple features are restricted to a fixed extent of the type, but the feature count was computed for all features. The count query now applies the same extent filters, so the number of features of a collection matches numberMatched. --- .../sql/app/AggregateStatsQueryGenerator.java | 22 ++++- .../sql/app/AggregateStatsReaderSql.java | 9 +- .../sql/domain/FeatureProviderSql.java | 7 +- .../AggregateStatsQueryGeneratorSpec.groovy | 92 +++++++++++++++++++ 4 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java index c510cbe4f..ce17d3021 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java @@ -7,11 +7,14 @@ */ package de.ii.xtraplatform.features.sql.app; +import de.ii.xtraplatform.cql.domain.And; +import de.ii.xtraplatform.cql.domain.Cql2Expression; import de.ii.xtraplatform.features.sql.domain.SqlDialect; import de.ii.xtraplatform.features.sql.domain.SqlQueryColumn; import de.ii.xtraplatform.features.sql.domain.SqlQueryColumn.Operation; import de.ii.xtraplatform.features.sql.domain.SqlQueryMapping; import de.ii.xtraplatform.features.sql.domain.SqlQuerySchema; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -31,13 +34,30 @@ public AggregateStatsQueryGenerator(SqlDialect sqlDialect, FilterEncoderSql filt } public String getCountQuery(SqlQueryMapping mapping) { + return getCountQuery(mapping, List.of()); + } + + /** + * Counts the features that match the filter of the main table and the additional filters, e.g. + * the restriction of all queries to a fixed extent. + */ + public String getCountQuery(SqlQueryMapping mapping, List additionalFilters) { SqlQuerySchema sourceSchema = mapping.getMainTable(); List aliases = AliasGenerator.getAliases(sourceSchema); String mainTable = String.format(FORMAT_TABLE_ALIAS, sourceSchema.getName(), aliases.get(0)); - Optional filter = getFilter(mapping, sourceSchema); + List filters = new ArrayList<>(); + sourceSchema.getFilter().ifPresent(filters::add); + filters.addAll(additionalFilters); + + Optional filter = + filters.isEmpty() + ? Optional.empty() + : Optional.of( + filterEncoder.encode( + filters.size() == 1 ? filters.get(0) : And.of(filters), mapping)); String where = filter.isPresent() ? String.format(FORMAT_WHERE, filter.get()) : ""; return String.format("SELECT COUNT(*) FROM %s%s", mainTable, where); diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsReaderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsReaderSql.java index bda3de787..0e5a88161 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsReaderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsReaderSql.java @@ -8,6 +8,7 @@ package de.ii.xtraplatform.features.sql.app; import de.ii.xtraplatform.base.domain.util.Tuple; +import de.ii.xtraplatform.cql.domain.Cql2Expression; import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.crs.domain.EpsgCrs; import de.ii.xtraplatform.features.domain.AggregateStatsReader; @@ -50,6 +51,11 @@ public AggregateStatsReaderSql( @Override public Stream getCount(List sourceSchemas) { + return getCount(sourceSchemas, List.of()); + } + + /** Like {@link #getCount(List)}, restricted to the features that match the filters. */ + public Stream getCount(List sourceSchemas, List filters) { return Reactive.Source.iterable(sourceSchemas) .via( Reactive.Transformer.flatMap( @@ -57,7 +63,8 @@ public Stream getCount(List sourceSchemas) { sqlClient .get() .getSourceStream( - queryGenerator.getCountQuery(schemaSql), SqlQueryOptions.single()))) + queryGenerator.getCountQuery(schemaSql, filters), + SqlQueryOptions.single()))) .via(Reactive.Transformer.map(sqlRow -> Long.parseLong((String) sqlRow.getValues().get(0)))) .to(Reactive.Sink.reduce(0L, Long::sum)); } diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java index 4354d7755..2afe4bf2c 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java @@ -36,7 +36,6 @@ import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; import de.ii.xtraplatform.features.domain.AbstractFeatureProvider; -import de.ii.xtraplatform.features.domain.AggregateStatsReader; import de.ii.xtraplatform.features.domain.ConnectionInfo; import de.ii.xtraplatform.features.domain.ConnectorFactory; import de.ii.xtraplatform.features.domain.DatasetChangeListener; @@ -467,7 +466,7 @@ public class FeatureProviderSql private final Scheduler scheduler; private FeatureQueryEncoderSql queryTransformer; - private AggregateStatsReader aggregateStatsReader; + private AggregateStatsReaderSql aggregateStatsReader; private FeatureMutationsSql featureMutationsSql; private PathParserSql pathParser2; private SqlPathParser pathParser3; @@ -1042,7 +1041,9 @@ public long getFeatureCount(String typeName) { } try { - Stream countGraph = aggregateStatsReader.getCount(queryMappings.get(typeName)); + // count what queries for multiple features return, i.e. within a fixed extent if restricted + Stream countGraph = + aggregateStatsReader.getCount(queryMappings.get(typeName), extentFilters(typeName)); Long count = countGraph diff --git a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy new file mode 100644 index 000000000..ebb2970b6 --- /dev/null +++ b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy @@ -0,0 +1,92 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.sql.app + +import de.ii.xtraplatform.cql.app.CqlImpl +import de.ii.xtraplatform.cql.domain.Bbox +import de.ii.xtraplatform.cql.domain.Property +import de.ii.xtraplatform.cql.domain.SIntersects +import de.ii.xtraplatform.cql.domain.SpatialLiteral +import de.ii.xtraplatform.cql.domain.TIntersects +import de.ii.xtraplatform.cql.domain.TemporalLiteral +import de.ii.xtraplatform.crs.domain.OgcCrs +import de.ii.xtraplatform.features.domain.FeatureSchemaFixtures +import de.ii.xtraplatform.features.domain.MappingOperationResolver +import de.ii.xtraplatform.features.domain.MappingRuleFixtures +import de.ii.xtraplatform.features.json.app.DecoderFactoryJson +import de.ii.xtraplatform.features.sql.domain.ImmutableQueryGeneratorSettings +import de.ii.xtraplatform.features.sql.domain.ImmutableSqlPathDefaults +import de.ii.xtraplatform.features.sql.domain.SqlDialectPgis +import de.ii.xtraplatform.features.sql.domain.SqlPathParser +import de.ii.xtraplatform.features.sql.domain.SqlQueryMapping +import spock.lang.Shared +import spock.lang.Specification + +import java.time.Instant +import java.util.function.Function + +class AggregateStatsQueryGeneratorSpec extends Specification { + + static final String INTERSECTS = "ST_Intersects(A.geom, ST_GeomFromText('POLYGON((7.0 50.0,7.1 50.0,7.1 50.1,7.0 50.1,7.0 50.0))',4326))" + + @Shared + SqlQueryMapping unfaelleMapping + + @Shared + AggregateStatsQueryGenerator generator + + def setupSpec() { + def cql = new CqlImpl() + def pathParser = new SqlPathParser(new ImmutableSqlPathDefaults.Builder().build(), cql, + Map.of("JSON", new DecoderFactoryJson(), "EXPRESSION", new DecoderFactorySqlExpression())) + def mappingDeriver = new SqlMappingDeriver(pathParser, new ImmutableQueryGeneratorSettings.Builder().build()) + def schema = FeatureSchemaFixtures.fromYaml("strassen_unfaelle2") + def resolved = schema.accept(new MappingOperationResolver(), List.of()) + unfaelleMapping = mappingDeriver.derive(MappingRuleFixtures.fromYaml("strassen_unfaelle2"), resolved).get(0) + + def filterEncoder = new FilterEncoderSql(OgcCrs.CRS84, new SqlDialectPgis(), null, null, new CqlImpl(), List.of(), null, + { type -> Optional.empty() } as Function, Map.of()) + generator = new AggregateStatsQueryGenerator(new SqlDialectPgis(), filterEncoder) + } + + def 'without additional filters the count is unrestricted'() { + + when: + String actual = generator.getCountQuery(unfaelleMapping) + + then: + actual == "SELECT COUNT(*) FROM unfaelle_point A" + } + + def 'a restriction to a fixed spatial extent becomes the where clause of the count'() { + + given: 'the filter that restricts queries for multiple features to the extent' + def filter = SIntersects.of(Property.of("geometry"), SpatialLiteral.of(Bbox.of(7.0, 50.0, 7.1, 50.1, OgcCrs.CRS84))) + + when: + String actual = generator.getCountQuery(unfaelleMapping, List.of(filter)) + + then: 'the count matches what queries for multiple features return' + actual == "SELECT COUNT(*) FROM unfaelle_point A WHERE ${INTERSECTS}" + } + + def 'spatial and temporal restrictions are combined'() { + + given: + def spatial = SIntersects.of(Property.of("geometry"), SpatialLiteral.of(Bbox.of(7.0, 50.0, 7.1, 50.1, OgcCrs.CRS84))) + def temporal = TIntersects.of(Property.of("unfzeit"), + new TemporalLiteral.Builder(org.threeten.extra.Interval.of(Instant.parse("2019-01-01T00:00:00Z"), Instant.parse("2019-12-31T23:59:59Z"))).build()) + + when: + String actual = generator.getCountQuery(unfaelleMapping, List.of(spatial, temporal)) + + then: 'both predicates are part of a single conjunction' + actual.startsWith("SELECT COUNT(*) FROM unfaelle_point A WHERE (${INTERSECTS} AND ") + actual.contains("OVERLAPS (TIMESTAMP '2019-01-01T00:00:00Z',TIMESTAMP '2019-12-31T23:59:59Z')") + } +} From bcc9cb243c5fb2a54d90cc2b3e542ceac5b7181d Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Mon, 9 Nov 2026 19:09:29 +0100 Subject: [PATCH 23/31] tiles: configure tileset extents with extent.spatial as for feature providers Tileset extents in tilesetDefaults and tilesets of the FEATURES, HTTP and MBTILES tile providers now have the same form as the extent of feature providers and their types: `extent.spatial`, in CRS84. A temporal extent is rejected for tiles. Before, a flat `extent` was expected and `extent.spatial` was ignored without an error. The extent type is renamed from FeatureTypeExtent to Extent, since it is used for providers, types and tilesets alike. --- .../domain/AbstractFeatureProvider.java | 4 +- .../xtraplatform/features/domain/Extent.java | 43 +++++++++++++++++++ .../domain/FeatureProviderDataV2.java | 2 +- .../features/domain/FeatureSchema.java | 2 +- .../features/domain/FeatureTypeExtent.java | 39 ----------------- .../features/domain/SpatialExtent.java | 2 +- ...ypeExtentSpec.groovy => ExtentSpec.groovy} | 14 +++--- .../tiles/app/TileProviderFeatures.java | 6 +-- .../tiles/app/TileProviderHttp.java | 6 +-- .../tiles/app/TileProviderMbTiles.java | 6 +-- .../tiles/domain/TilesetFeatures.java | 17 +++++--- .../tiles/domain/TilesetFeaturesDefaults.java | 17 +++++--- .../tiles/domain/TilesetHttp.java | 17 +++++--- .../tiles/domain/TilesetHttpDefaults.java | 17 +++++--- .../tiles/domain/TilesetMbTiles.java | 15 ++++--- .../tiles/domain/TilesetMbTilesDefaults.java | 15 ++++--- .../app/TileProviderHttpExtentSpec.groovy | 21 ++++++++- 17 files changed, 147 insertions(+), 96 deletions(-) create mode 100644 xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/Extent.java delete mode 100644 xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java rename xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/{FeatureTypeExtentSpec.groovy => ExtentSpec.groovy} (75%) diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java index c2131c984..a0f1a8834 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/AbstractFeatureProvider.java @@ -654,8 +654,8 @@ protected Optional getConfiguredTemporalExtent(String typeName) { return getConfiguredExtent(typeName).getTemporal().flatMap(TemporalExtent::toInterval); } - private FeatureTypeExtent getConfiguredExtent(String typeName) { - return FeatureTypeExtent.inherit( + private Extent getConfiguredExtent(String typeName) { + return Extent.inherit( Optional.ofNullable(getData().getTypes().get(typeName)).flatMap(FeatureSchema::getExtent), getData().getExtent()); } diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/Extent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/Extent.java new file mode 100644 index 000000000..8255acec8 --- /dev/null +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/Extent.java @@ -0,0 +1,43 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.domain; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.common.base.Preconditions; +import java.util.Optional; +import org.immutables.value.Value; + +/** Extent object for spatial and temporal extents. */ +@Value.Immutable +@JsonDeserialize(builder = ImmutableExtent.Builder.class) +public interface Extent { + Optional getSpatial(); + + Optional getTemporal(); + + /** + * Each part of the extent replaces the same part of the extent of the parent level (provider for + * types, API for collections, tileset defaults for tilesets); a part with {@code computed: true} + * therefore discards an inherited fixed extent. + */ + static Extent inherit(Optional extent, Optional parentExtent) { + return ImmutableExtent.builder() + .spatial( + extent.flatMap(Extent::getSpatial).or(() -> parentExtent.flatMap(Extent::getSpatial))) + .temporal( + extent.flatMap(Extent::getTemporal).or(() -> parentExtent.flatMap(Extent::getTemporal))) + .build(); + } + + /** Tiles have only a spatial extent, a temporal extent is rejected. */ + static void checkSpatialOnly(Optional extent) { + Preconditions.checkState( + extent.flatMap(Extent::getTemporal).isEmpty(), + "Extent: 'temporal' is not supported for tiles, only 'spatial'."); + } +} diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java index 1d92743e3..3dc979c76 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java @@ -268,7 +268,7 @@ default List getCql2Functions() { * gesetzt, wird keine automatische Berechnung durchgeführt. * @since v4.9 */ - Optional getExtent(); + Optional getExtent(); // custom builder to automatically use keys of types as name of FeatureTypeV2 abstract class Builder> implements EntityDataBuilder { diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java index 7a739d932..1e5943f10 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java @@ -406,7 +406,7 @@ default Type getType() { * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Feature-Type. * @since v4.9 */ - Optional getExtent(); + Optional getExtent(); /** * @langEn The unit of measurement of the value, only relevant for numeric properties. diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java deleted file mode 100644 index 713806f08..000000000 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureTypeExtent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2026 interactive instruments GmbH - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package de.ii.xtraplatform.features.domain; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.Optional; -import org.immutables.value.Value; - -/** Extent object for spatial and temporal extents. */ -@Value.Immutable -@JsonDeserialize(builder = ImmutableFeatureTypeExtent.Builder.class) -public interface FeatureTypeExtent { - Optional getSpatial(); - - Optional getTemporal(); - - /** - * Each part of the type extent replaces the same part of the provider extent; a part with {@code - * computed: true} therefore discards an inherited fixed extent. - */ - static FeatureTypeExtent inherit( - Optional typeExtent, Optional providerExtent) { - return ImmutableFeatureTypeExtent.builder() - .spatial( - typeExtent - .flatMap(FeatureTypeExtent::getSpatial) - .or(() -> providerExtent.flatMap(FeatureTypeExtent::getSpatial))) - .temporal( - typeExtent - .flatMap(FeatureTypeExtent::getTemporal) - .or(() -> providerExtent.flatMap(FeatureTypeExtent::getTemporal))) - .build(); - } -} diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java index 0d4feb5ed..4ba9e1f62 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java @@ -17,7 +17,7 @@ /** * Spatial extent. The coordinates are in the native CRS of the feature provider for providers and - * types, and in CRS84 (longitude/latitude) for tilesets. + * types, and in CRS84 (longitude/latitude) for tilesets and APIs. */ @Value.Immutable @JsonDeserialize(builder = ImmutableSpatialExtent.Builder.class) diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/FeatureTypeExtentSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentSpec.groovy similarity index 75% rename from xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/FeatureTypeExtentSpec.groovy rename to xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentSpec.groovy index c7a7695e2..9de12bc10 100644 --- a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/FeatureTypeExtentSpec.groovy +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/ExtentSpec.groovy @@ -9,15 +9,15 @@ package de.ii.xtraplatform.features.domain import spock.lang.Specification -class FeatureTypeExtentSpec extends Specification { +class ExtentSpec extends Specification { static SpatialExtent FIXED_SPATIAL = new ImmutableSpatialExtent.Builder().xmin(0).ymin(0).xmax(1).ymax(1).build() static SpatialExtent OTHER_SPATIAL = new ImmutableSpatialExtent.Builder().xmin(5).ymin(5).xmax(6).ymax(6).build() static SpatialExtent COMPUTED_SPATIAL = new ImmutableSpatialExtent.Builder().computed(true).build() static TemporalExtent FIXED_TEMPORAL = new ImmutableTemporalExtent.Builder().start("2020-01-01").build() - static Optional extent(SpatialExtent spatial, TemporalExtent temporal) { - Optional.of(ImmutableFeatureTypeExtent.builder() + static Optional extent(SpatialExtent spatial, TemporalExtent temporal) { + Optional.of(ImmutableExtent.builder() .spatial(Optional.ofNullable(spatial)) .temporal(Optional.ofNullable(temporal)) .build()) @@ -25,7 +25,7 @@ class FeatureTypeExtentSpec extends Specification { def "a type without extent inherits the provider extent"() { when: - def resolved = FeatureTypeExtent.inherit(Optional.empty(), extent(FIXED_SPATIAL, FIXED_TEMPORAL)) + def resolved = Extent.inherit(Optional.empty(), extent(FIXED_SPATIAL, FIXED_TEMPORAL)) then: resolved.spatial == Optional.of(FIXED_SPATIAL) @@ -34,7 +34,7 @@ class FeatureTypeExtentSpec extends Specification { def "the type extent replaces the provider extent per part"() { when: - def resolved = FeatureTypeExtent.inherit(extent(OTHER_SPATIAL, null), extent(FIXED_SPATIAL, FIXED_TEMPORAL)) + def resolved = Extent.inherit(extent(OTHER_SPATIAL, null), extent(FIXED_SPATIAL, FIXED_TEMPORAL)) then: resolved.spatial == Optional.of(OTHER_SPATIAL) @@ -43,7 +43,7 @@ class FeatureTypeExtentSpec extends Specification { def "computed on the type discards the inherited fixed extent"() { when: - def resolved = FeatureTypeExtent.inherit(extent(COMPUTED_SPATIAL, null), extent(FIXED_SPATIAL, null)) + def resolved = Extent.inherit(extent(COMPUTED_SPATIAL, null), extent(FIXED_SPATIAL, null)) then: resolved.spatial.flatMap { it.toBoundingBox(de.ii.xtraplatform.crs.domain.OgcCrs.CRS84) }.isEmpty() @@ -51,7 +51,7 @@ class FeatureTypeExtentSpec extends Specification { def "nothing configured means nothing fixed"() { when: - def resolved = FeatureTypeExtent.inherit(Optional.empty(), Optional.empty()) + def resolved = Extent.inherit(Optional.empty(), Optional.empty()) then: resolved.spatial.isEmpty() diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java index 66786aace..de7249481 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderFeatures.java @@ -32,6 +32,7 @@ import de.ii.xtraplatform.entities.domain.EntityRegistry; import de.ii.xtraplatform.features.domain.DatasetChange; import de.ii.xtraplatform.features.domain.DatasetChangeListener; +import de.ii.xtraplatform.features.domain.Extent; import de.ii.xtraplatform.features.domain.FeatureChange; import de.ii.xtraplatform.features.domain.FeatureChangeListener; import de.ii.xtraplatform.features.domain.FeatureProvider; @@ -1045,9 +1046,8 @@ private TilesetMetadata loadMetadata(TilesetFeatures tileset) { .collect(Collectors.toList()); Optional configuredExtent = - tileset - .getExtent() - .or(() -> getData().getTilesetDefaults().getExtent()) + Extent.inherit(tileset.getExtent(), getData().getTilesetDefaults().getExtent()) + .getSpatial() .flatMap(extent -> extent.toBoundingBox(OgcCrs.CRS84)); Optional bounds; diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java index 089756ff0..fbcb9917f 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderHttp.java @@ -17,6 +17,7 @@ import de.ii.xtraplatform.crs.domain.OgcCrs; import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; +import de.ii.xtraplatform.features.domain.Extent; import de.ii.xtraplatform.features.domain.ProviderData; import de.ii.xtraplatform.tiles.domain.ChainedTileProvider; import de.ii.xtraplatform.tiles.domain.ImmutableTilesetMetadata; @@ -135,9 +136,8 @@ private TilesetMetadata loadMetadata(TilesetHttp tileset) { ? getData().getTilesetDefaults().getLevels() : tileset.getLevels(); Optional bounds = - tileset - .getExtent() - .or(() -> getData().getTilesetDefaults().getExtent()) + Extent.inherit(tileset.getExtent(), getData().getTilesetDefaults().getExtent()) + .getSpatial() .flatMap(extent -> extent.toBoundingBox(OgcCrs.CRS84)) .or(() -> getTileMatrixSetsExtent(levels.keySet())); diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java index cef11d98a..34da2cbc3 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/app/TileProviderMbTiles.java @@ -18,6 +18,7 @@ import de.ii.xtraplatform.crs.domain.OgcCrs; import de.ii.xtraplatform.entities.domain.Entity; import de.ii.xtraplatform.entities.domain.Entity.SubType; +import de.ii.xtraplatform.features.domain.Extent; import de.ii.xtraplatform.features.domain.FeatureSchema; import de.ii.xtraplatform.features.domain.ProviderData; import de.ii.xtraplatform.tiles.domain.ChainedTileProvider; @@ -181,9 +182,8 @@ private void loadMetadata(Map tilesetSources) { .get(tilesetKey.first()) .mergeDefaults(getData().getTilesetDefaults()); Optional configuredExtent = - tileset - .getExtent() - .or(() -> getData().getTilesetDefaults().getExtent()) + Extent.inherit(tileset.getExtent(), getData().getTilesetDefaults().getExtent()) + .getSpatial() .flatMap(extent -> extent.toBoundingBox(OgcCrs.CRS84)); metadata.put( diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java index 93da3caec..2d1d7ff7d 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeatures.java @@ -13,7 +13,7 @@ import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; -import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.Extent; import java.util.List; import java.util.Map; import java.util.Objects; @@ -51,13 +51,18 @@ public interface TilesetFeatures Optional getFeatureProvider(); /** - * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If set, the extent - * is not derived from the feature provider. - * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird der - * Extent nicht vom Feature-Provider übernommen. + * @langEn Fixed extent of the tileset, only `spatial` in CRS84 (longitude/latitude). If set, the + * extent is not derived from the feature provider. + * @langDe Fester Extent des Tilesets, nur `spatial` in CRS84 (Länge/Breite). Wenn gesetzt, wird + * der Extent nicht vom Feature-Provider übernommen. * @since v4.9 */ - Optional getExtent(); + Optional getExtent(); + + @Value.Check + default void checkExtentIsSpatial() { + Extent.checkSpatialOnly(getExtent()); + } @DocIgnore @Nullable diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java index 8a7a01e34..d0fcddd82 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetFeaturesDefaults.java @@ -11,7 +11,7 @@ import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; -import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.Extent; import java.util.Optional; import org.immutables.value.Value; @@ -39,11 +39,16 @@ default ImmutableTilesetFeaturesDefaults.Builder getBuilder() { abstract class Builder implements BuildableBuilder {} /** - * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If set, the extent - * is not derived from the feature provider. - * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird der - * Extent nicht vom Feature-Provider übernommen. + * @langEn Fixed extent of the tileset, only `spatial` in CRS84 (longitude/latitude). If set, the + * extent is not derived from the feature provider. + * @langDe Fester Extent des Tilesets, nur `spatial` in CRS84 (Länge/Breite). Wenn gesetzt, wird + * der Extent nicht vom Feature-Provider übernommen. * @since v4.9 */ - Optional getExtent(); + Optional getExtent(); + + @Value.Check + default void checkExtentIsSpatial() { + Extent.checkSpatialOnly(getExtent()); + } } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java index c4a229507..7ef2d294c 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttp.java @@ -12,7 +12,7 @@ import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; -import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.Extent; import java.util.Map; import java.util.Optional; import org.immutables.value.Value; @@ -42,13 +42,18 @@ public interface TilesetHttp extends TilesetCommon, WithEncodings, Buildable getEncodings(); /** - * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If not set, the - * extent of the tile matrix sets is used. - * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn nicht gesetzt, wird - * der Extent der Kachelschemas verwendet. + * @langEn Fixed extent of the tileset, only `spatial` in CRS84 (longitude/latitude). If not set, + * the extent of the tile matrix sets is used. + * @langDe Fester Extent des Tilesets, nur `spatial` in CRS84 (Länge/Breite). Wenn nicht gesetzt, + * wird der Extent der Kachelschemas verwendet. * @since v4.9 */ - Optional getExtent(); + Optional getExtent(); + + @Value.Check + default void checkExtentIsSpatial() { + Extent.checkSpatialOnly(getExtent()); + } /** * @langEn URL template for accessing tiles. Parameters to use are `{{tileMatrix}}`, diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java index c953da6ca..5245ff576 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetHttpDefaults.java @@ -11,7 +11,7 @@ import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; -import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.Extent; import java.util.Optional; import org.immutables.value.Value; @@ -34,13 +34,18 @@ default ImmutableTilesetHttpDefaults.Builder getBuilder() { } /** - * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If not set, the - * extent of the tile matrix sets is used. - * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn nicht gesetzt, wird - * der Extent der Kachelschemas verwendet. + * @langEn Fixed extent of the tileset, only `spatial` in CRS84 (longitude/latitude). If not set, + * the extent of the tile matrix sets is used. + * @langDe Fester Extent des Tilesets, nur `spatial` in CRS84 (Länge/Breite). Wenn nicht gesetzt, + * wird der Extent der Kachelschemas verwendet. * @since v4.9 */ - Optional getExtent(); + Optional getExtent(); + + @Value.Check + default void checkExtentIsSpatial() { + Extent.checkSpatialOnly(getExtent()); + } abstract class Builder implements BuildableBuilder {} } diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java index ec5ca2488..00f9d1b08 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTiles.java @@ -13,7 +13,7 @@ import de.ii.xtraplatform.entities.domain.maptobuilder.Buildable; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableBuilder; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; -import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.Extent; import java.util.Objects; import java.util.Optional; import javax.annotation.Nullable; @@ -40,13 +40,18 @@ public interface TilesetMbTiles extends TilesetCommon, Buildable String getSource(); /** - * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If set, `bounds` - * from the MBTiles metadata is ignored. - * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird + * @langEn Fixed extent of the tileset, only `spatial` in CRS84 (longitude/latitude). If set, + * `bounds` from the MBTiles metadata is ignored. + * @langDe Fester Extent des Tilesets, nur `spatial` in CRS84 (Länge/Breite). Wenn gesetzt, wird * `bounds` aus den MBTiles-Metadaten ignoriert. * @since v4.9 */ - Optional getExtent(); + Optional getExtent(); + + @Value.Check + default void checkExtentIsSpatial() { + Extent.checkSpatialOnly(getExtent()); + } /** * @langEn Tile Matrix Set of the tiles in the MBTiles file. diff --git a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java index 6220fdddf..760be6657 100644 --- a/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java +++ b/xtraplatform-tiles/src/main/java/de/ii/xtraplatform/tiles/domain/TilesetMbTilesDefaults.java @@ -10,7 +10,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import de.ii.xtraplatform.docs.DocIgnore; import de.ii.xtraplatform.entities.domain.maptobuilder.BuildableMap; -import de.ii.xtraplatform.features.domain.SpatialExtent; +import de.ii.xtraplatform.features.domain.Extent; import de.ii.xtraplatform.tiles.domain.ImmutableMinMax.Builder; import java.util.Optional; import org.immutables.value.Value; @@ -39,11 +39,16 @@ default String getTileMatrixSet() { } /** - * @langEn Fixed spatial extent of the tileset in CRS84 (longitude/latitude). If set, `bounds` - * from the MBTiles metadata is ignored. - * @langDe Fester räumlicher Extent des Tilesets in CRS84 (Länge/Breite). Wenn gesetzt, wird + * @langEn Fixed extent of the tileset, only `spatial` in CRS84 (longitude/latitude). If set, + * `bounds` from the MBTiles metadata is ignored. + * @langDe Fester Extent des Tilesets, nur `spatial` in CRS84 (Länge/Breite). Wenn gesetzt, wird * `bounds` aus den MBTiles-Metadaten ignoriert. * @since v4.9 */ - Optional getExtent(); + Optional getExtent(); + + @Value.Check + default void checkExtentIsSpatial() { + Extent.checkSpatialOnly(getExtent()); + } } diff --git a/xtraplatform-tiles/src/test/groovy/de/ii/xtraplatform/tiles/app/TileProviderHttpExtentSpec.groovy b/xtraplatform-tiles/src/test/groovy/de/ii/xtraplatform/tiles/app/TileProviderHttpExtentSpec.groovy index 6050bcf8b..b3780836f 100644 --- a/xtraplatform-tiles/src/test/groovy/de/ii/xtraplatform/tiles/app/TileProviderHttpExtentSpec.groovy +++ b/xtraplatform-tiles/src/test/groovy/de/ii/xtraplatform/tiles/app/TileProviderHttpExtentSpec.groovy @@ -12,7 +12,9 @@ import de.ii.xtraplatform.crs.domain.BoundingBox import de.ii.xtraplatform.crs.domain.CrsTransformationException import de.ii.xtraplatform.crs.domain.CrsTransformerFactory import de.ii.xtraplatform.crs.domain.OgcCrs +import de.ii.xtraplatform.features.domain.ImmutableExtent import de.ii.xtraplatform.features.domain.ImmutableSpatialExtent +import de.ii.xtraplatform.features.domain.ImmutableTemporalExtent import de.ii.xtraplatform.features.domain.SpatialExtent import de.ii.xtraplatform.tiles.domain.ImmutableMinMax import de.ii.xtraplatform.tiles.domain.ImmutableTileProviderHttpData @@ -46,7 +48,7 @@ class TileProviderHttpExtentSpec extends Specification { .putLevels("Unknown", new ImmutableMinMax.Builder().min(0).max(10)) .putEncodings(TilesFormat.MVT, "pbf") if (defaultsExtent != null) { - defaults.extent(defaultsExtent) + defaults.extent(ImmutableExtent.builder().spatial(defaultsExtent).build()) } def data = new ImmutableTileProviderHttpData.Builder() .id("tiles") @@ -61,7 +63,7 @@ class TileProviderHttpExtentSpec extends Specification { def builder = new ImmutableTilesetHttp.Builder().id("ts").urlTemplate("https://example.com/{z}/{y}/{x}") tileMatrixSetIds.each { builder.putLevels(it, new ImmutableMinMax.Builder().min(0).max(10)) } if (extent != null) { - builder.extent(extent) + builder.extent(ImmutableExtent.builder().spatial(extent).build()) } builder.build() } @@ -106,4 +108,19 @@ class TileProviderHttpExtentSpec extends Specification { expect: provider(null).loadMetadata(tileset(null, ["broken"])).bounds.isEmpty() } + + def "a temporal extent is rejected for a tileset"() { + + when: + new ImmutableTilesetHttp.Builder().id("ts").urlTemplate("https://example.com/{z}/{y}/{x}") + .extent(ImmutableExtent.builder() + .spatial(TILESET_EXTENT) + .temporal(new ImmutableTemporalExtent.Builder().start("2020-01-01").build()) + .build()) + .build() + + then: + def e = thrown(IllegalStateException) + e.message == "Extent: 'temporal' is not supported for tiles, only 'spatial'." + } } From 9159100d9732fd699eca38101b999f9db46c1995 Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Mon, 9 Nov 2026 19:47:34 +0100 Subject: [PATCH 24/31] fix missing spatial extents of WFS feature types The bounding boxes from the capabilities are stored under the ids derived from the prefixed feature type name (prefix_localname, localname), but were looked up with the prefixed name, so no type got an extent. With a native CRS84, the bounding box was also dropped for lack of a transformer. The bounding box is now returned in CRS84 as given in the capabilities; it was transformed to the native CRS and back before, which enlarged it. --- .../gml/app/AggregateStatsReaderWfs.java | 49 +++++++++++-------- .../features/gml/app/FeatureProviderWfs.java | 22 +++++++-- .../app/AggregateStatsReaderWfsSpec.groovy | 41 ++++++++++++++++ 3 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 xtraplatform-features-gml/src/test/groovy/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfsSpec.groovy diff --git a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfs.java b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfs.java index 5fbcf366b..8b3a3c26c 100644 --- a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfs.java +++ b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfs.java @@ -7,34 +7,26 @@ */ package de.ii.xtraplatform.features.gml.app; -import static de.ii.xtraplatform.base.domain.util.LambdaWithException.mayThrow; - import de.ii.xtraplatform.crs.domain.BoundingBox; -import de.ii.xtraplatform.crs.domain.CrsTransformer; -import de.ii.xtraplatform.crs.domain.CrsTransformerFactory; -import de.ii.xtraplatform.crs.domain.EpsgCrs; -import de.ii.xtraplatform.crs.domain.OgcCrs; import de.ii.xtraplatform.features.domain.AggregateStatsReader; import de.ii.xtraplatform.features.domain.FeatureMetadata; import de.ii.xtraplatform.features.domain.FeatureSchema; import de.ii.xtraplatform.features.domain.Metadata; import de.ii.xtraplatform.streams.domain.Reactive; import de.ii.xtraplatform.streams.domain.Reactive.Stream; +import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.Objects; import java.util.Optional; import org.threeten.extra.Interval; public class AggregateStatsReaderWfs implements AggregateStatsReader { private final FeatureMetadata featureMetadata; - private final Optional crsTransformer; - public AggregateStatsReaderWfs( - FeatureMetadata featureMetadata, - CrsTransformerFactory crsTransformerFactory, - EpsgCrs nativeCrs) { + public AggregateStatsReaderWfs(FeatureMetadata featureMetadata) { this.featureMetadata = featureMetadata; - this.crsTransformer = crsTransformerFactory.getTransformer(OgcCrs.CRS84, nativeCrs, true); } @Override @@ -42,6 +34,7 @@ public Stream getCount(List sourceSchemas) { return Reactive.Source.single(-1L).to(Reactive.Sink.head()); } + /** The bounding box from the capabilities, in CRS84. */ @Override public Stream> getSpatialExtent( List sourceSchemas, boolean is3d) { @@ -52,14 +45,10 @@ public Stream> getSpatialExtent( .map(Metadata::getFeatureTypesBoundingBox) .flatMap( boundingBoxes -> - Optional.ofNullable( - boundingBoxes.get(sourceSchemas.get(0).getSourcePath().get().substring(1)))) - .flatMap( - boundingBox1 -> - crsTransformer.map( - mayThrow( - crsTransformer1 -> - crsTransformer1.transformBoundingBox(boundingBox1)))); + getTypeIds(sourceSchemas.get(0)).stream() + .map(boundingBoxes::get) + .filter(Objects::nonNull) + .findFirst()); return Reactive.Source.single(boundingBox).to(Reactive.Sink.head()); } @@ -68,4 +57,24 @@ public Stream> getSpatialExtent( public Stream> getTemporalExtent(List sourceSchemas) { return Reactive.Source.single(Optional.empty()).to(Reactive.Sink.head()); } + + /** + * The ids under which the capabilities analyzer stores the bounding box of a feature type: the + * prefixed name becomes {@code prefix_localname}, and if unique also {@code localname}, both in + * lower case. + */ + static List getTypeIds(FeatureSchema schema) { + String prefixedName = + schema.getSourcePath().map(path -> path.substring(1)).orElse(schema.getName()); + int separator = prefixedName.indexOf(':'); + String localName = prefixedName.substring(separator + 1).toLowerCase(Locale.ROOT); + + List ids = new ArrayList<>(); + ids.add(schema.getName()); + if (separator > 0) { + ids.add(prefixedName.substring(0, separator).toLowerCase(Locale.ROOT) + "_" + localName); + } + ids.add(localName); + return ids; + } } diff --git a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java index e1c2136be..eaf1e9019 100644 --- a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java +++ b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/FeatureProviderWfs.java @@ -16,6 +16,7 @@ import de.ii.xtraplatform.cql.domain.Cql; import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.crs.domain.CrsInfo; +import de.ii.xtraplatform.crs.domain.CrsTransformationException; import de.ii.xtraplatform.crs.domain.CrsTransformerFactory; import de.ii.xtraplatform.crs.domain.EpsgCrs; import de.ii.xtraplatform.crs.domain.OgcCrs; @@ -169,9 +170,7 @@ protected boolean onStartup() throws InterruptedException { getData().getNativeCrs().orElse(OgcCrs.CRS84), crsTransformerFactory, cql); - this.aggregateStatsReader = - new AggregateStatsReaderWfs( - this, crsTransformerFactory, getData().getNativeCrs().orElse(OgcCrs.CRS84)); + this.aggregateStatsReader = new AggregateStatsReaderWfs(this); return true; } @@ -327,8 +326,23 @@ public Optional getSpatialExtent(String typeName) { @Override public Optional getSpatialExtent(String typeName, EpsgCrs crs) { + // a configured extent is in the native CRS, one from the capabilities in CRS84 return getSpatialExtent(typeName) - .flatMap(boundingBox -> transformSpatialExtent(boundingBox, crs)); + .flatMap( + boundingBox -> + Objects.equals(boundingBox.getEpsgCrs(), crs) + ? Optional.of(boundingBox) + : crsTransformerFactory + .getTransformer(boundingBox.getEpsgCrs(), crs, false) + .flatMap( + crsTransformer -> { + try { + return Optional.of( + crsTransformer.transformBoundingBox(boundingBox)); + } catch (CrsTransformationException e) { + return Optional.empty(); + } + })); } @Override diff --git a/xtraplatform-features-gml/src/test/groovy/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfsSpec.groovy b/xtraplatform-features-gml/src/test/groovy/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfsSpec.groovy new file mode 100644 index 000000000..b0eae4db2 --- /dev/null +++ b/xtraplatform-features-gml/src/test/groovy/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfsSpec.groovy @@ -0,0 +1,41 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.gml.app + +import de.ii.xtraplatform.features.domain.ImmutableFeatureSchema +import de.ii.xtraplatform.features.domain.SchemaBase +import spock.lang.Specification + +class AggregateStatsReaderWfsSpec extends Specification { + + def "the bounding box of a prefixed feature type is found under the ids of the capabilities analyzer"() { + + given: 'a type whose source path is the prefixed name of the WFS feature type' + def schema = new ImmutableFeatureSchema.Builder() + .name("rbz") + .sourcePath("/dvg:nw_DVG1_rbz") + .type(SchemaBase.Type.OBJECT) + .build() + + expect: 'the type id, then prefix_localname and localname in lower case, not the prefixed name' + AggregateStatsReaderWfs.getTypeIds(schema) == ["rbz", "dvg_nw_dvg1_rbz", "nw_dvg1_rbz"] + } + + def "a feature type without a prefix"() { + + given: + def schema = new ImmutableFeatureSchema.Builder() + .name("flurstueck") + .sourcePath("/Flurstueck") + .type(SchemaBase.Type.OBJECT) + .build() + + expect: + AggregateStatsReaderWfs.getTypeIds(schema) == ["flurstueck", "flurstueck"] + } +} From 0b89744ad2a8f9b52cd29afda1d1eae5161cf0df Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Mon, 9 Nov 2026 19:48:33 +0100 Subject: [PATCH 25/31] features: document that only SQL providers restrict queries to a fixed extent --- .../features/domain/FeatureProviderDataV2.java | 12 ++++++++---- .../xtraplatform/features/domain/FeatureSchema.java | 9 +++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java index 3dc979c76..0734ac391 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureProviderDataV2.java @@ -262,10 +262,14 @@ default List getCql2Functions() { Optional getAuto(); /** - * @langEn Optional spatial and temporal extent for all types in this provider. If set, disables - * automatic calculation. - * @langDe Optionaler räumlicher und zeitlicher Extent für alle Types dieses Providers. Wenn - * gesetzt, wird keine automatische Berechnung durchgeführt. + * @langEn Optional spatial (in the native CRS) and temporal extent for all types in this + * provider. If set, the extent is not computed from the data. SQL providers also restrict + * queries for multiple features to the extent, see `queryGeneration`; other providers do not + * restrict queries. + * @langDe Optionaler räumlicher (im nativen Koordinatenreferenzsystem) und zeitlicher Extent für + * alle Types dieses Providers. Wenn gesetzt, wird der Extent nicht aus den Daten berechnet. + * SQL-Provider schränken zudem Abfragen mehrerer Features auf den Extent ein, siehe + * `queryGeneration`; andere Provider schränken Abfragen nicht ein. * @since v4.9 */ Optional getExtent(); diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java index 1e5943f10..d2fd6f679 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/FeatureSchema.java @@ -402,8 +402,13 @@ default Type getType() { Optional getDescription(); /** - * @langEn Optional spatial and temporal extent for this feature type. - * @langDe Optionaler räumlicher und zeitlicher Extent für diesen Feature-Type. + * @langEn Optional spatial (in the native CRS) and temporal extent for this feature type. Each + * part replaces the same part of the extent of the provider. SQL providers also restrict + * queries for multiple features to the extent, see `queryGeneration`. + * @langDe Optionaler räumlicher (im nativen Koordinatenreferenzsystem) und zeitlicher Extent für + * diesen Feature-Type. Jeder Teil ersetzt denselben Teil des Extents des Providers. + * SQL-Provider schränken zudem Abfragen mehrerer Features auf den Extent ein, siehe + * `queryGeneration`. * @since v4.9 */ Optional getExtent(); From 8d4987a270d3c357dd69b41647e531f77dcb261e Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Tue, 10 Nov 2026 05:12:23 +0100 Subject: [PATCH 26/31] fix computed temporal extents that ignore open starts and ends For data with a start and an end, the computed temporal extent used the earliest start and the latest end that are set, so a collection with features that have no end, e.g. current versions, got the end of the latest closed interval. A missing start or end now makes that side of the extent unbounded. An empty table still has no temporal extent. Temporal extents cached by an earlier version are used until the features of the type or the provider configuration change; clear the cache to recompute them. --- .../geoparquet/app/SqlDialectDuckdb.java | 12 +---- .../features/oracle/app/SqlDialectOras.java | 10 +---- .../sql/app/AggregateStatsQueryGenerator.java | 45 ++++++++++++++++--- .../features/sql/domain/SqlDialect.java | 6 +++ .../features/sql/domain/SqlDialectGpkg.java | 10 +---- .../features/sql/domain/SqlDialectPgis.java | 11 +---- .../AggregateStatsQueryGeneratorSpec.groovy | 38 ++++++++++++++++ .../sql/domain/SqlDialectPostGisSpec.groovy | 6 ++- 8 files changed, 95 insertions(+), 43 deletions(-) diff --git a/xtraplatform-features-geoparquet/src/main/java/de/ii/xtraplatform/features/geoparquet/app/SqlDialectDuckdb.java b/xtraplatform-features-geoparquet/src/main/java/de/ii/xtraplatform/features/geoparquet/app/SqlDialectDuckdb.java index dc6ee9b1d..d6cf69f90 100644 --- a/xtraplatform-features-geoparquet/src/main/java/de/ii/xtraplatform/features/geoparquet/app/SqlDialectDuckdb.java +++ b/xtraplatform-features-geoparquet/src/main/java/de/ii/xtraplatform/features/geoparquet/app/SqlDialectDuckdb.java @@ -99,10 +99,6 @@ public Optional parseExtent(String extent, EpsgCrs crs) { @Override public Optional parseTemporalExtent(String start, String end, ZoneId timeZone) { - if (Objects.isNull(start)) { - return Optional.empty(); - } - DateTimeFormatter parser; if (Objects.isNull(timeZone)) { parser = @@ -118,18 +114,14 @@ public Optional parseTemporalExtent(String start, String end, ZoneId t // Note: Strictly, INFINITY/-INFINITY and INSTANT.MAX/INSTANT.MIN are not the same! May result // in undesired behavior. Instant parsedStart; - switch (start.toUpperCase(Locale.ROOT)) { + switch (Objects.requireNonNullElse(start, "-INFINITY").toUpperCase(Locale.ROOT)) { case "-INFINITY" -> parsedStart = Instant.MIN; case "INFINITY" -> parsedStart = Instant.MAX; default -> parsedStart = parser.parse(start, Instant::from); } - if (Objects.isNull(end)) { - return Optional.of(Interval.of(parsedStart, Instant.MAX)); - } - Instant parsedEnd; - switch (end.toUpperCase(Locale.ROOT)) { + switch (Objects.requireNonNullElse(end, "INFINITY").toUpperCase(Locale.ROOT)) { case "INFINITY" -> parsedEnd = Instant.MAX; case "-INFINITY" -> parsedEnd = Instant.MIN; default -> parsedEnd = parser.parse(end, Instant::from); diff --git a/xtraplatform-features-oracle/src/main/java/de/ii/xtraplatform/features/oracle/app/SqlDialectOras.java b/xtraplatform-features-oracle/src/main/java/de/ii/xtraplatform/features/oracle/app/SqlDialectOras.java index 614429f0c..d797ac4df 100644 --- a/xtraplatform-features-oracle/src/main/java/de/ii/xtraplatform/features/oracle/app/SqlDialectOras.java +++ b/xtraplatform-features-oracle/src/main/java/de/ii/xtraplatform/features/oracle/app/SqlDialectOras.java @@ -124,17 +124,11 @@ public Optional parseExtent(String extent, EpsgCrs crs) { @Override public Optional parseTemporalExtent(String start, String end, ZoneId timeZone) { - if (Objects.isNull(start)) { - return Optional.empty(); - } DateTimeFormatter parser = DateTimeFormatter.ofPattern("yyyy-MM-dd[['T'][' ']HH:mm:ss][.SSS][X]") .withZone(ZoneOffset.UTC); - Instant parsedStart = parser.parse(start, Instant::from); - if (Objects.isNull(end)) { - return Optional.of(Interval.of(parsedStart, Instant.MAX)); - } - Instant parsedEnd = parser.parse(end, Instant::from); + Instant parsedStart = Objects.isNull(start) ? Instant.MIN : parser.parse(start, Instant::from); + Instant parsedEnd = Objects.isNull(end) ? Instant.MAX : parser.parse(end, Instant::from); return Optional.of(Interval.of(parsedStart, parsedEnd)); } diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java index ce17d3021..a2e1c2671 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java @@ -25,6 +25,13 @@ public class AggregateStatsQueryGenerator { private static final String FORMAT_TABLE_ALIAS = "%s %s"; private static final String FORMAT_WHERE = " WHERE %s"; + /** + * The temporal extent queries return no row if there is nothing to aggregate, so that NULL in the + * result always stands for an unbounded start or end. + */ + private static final String FORMAT_TEMPORAL_EXTENT = + "SELECT T.extent_start, T.extent_end FROM (%s) T WHERE T.row_count > 0"; + private final SqlDialect sqlDialect; private final FilterEncoderSql filterEncoder; @@ -111,8 +118,10 @@ public String getTemporalExtentQuery( String where = filter.isPresent() ? String.format(FORMAT_WHERE, filter.get()) : ""; return String.format( - "SELECT MIN(%s), MAX(%s) FROM %s%s%s%s", - column, column, mainTable, join.isEmpty() ? "" : " ", join, where); + FORMAT_TEMPORAL_EXTENT, + String.format( + "SELECT MIN(%s) AS extent_start, MAX(%s) AS extent_end, COUNT(%s) AS row_count FROM %s%s%s%s", + column, column, column, mainTable, join.isEmpty() ? "" : " ", join, where)); } public String getTemporalExtentQuery( @@ -148,8 +157,15 @@ public String getTemporalExtentQuery( String where = filter.isPresent() ? String.format(FORMAT_WHERE, filter.get()) : ""; return String.format( - "SELECT MIN(%s), MAX(%s) FROM %s%s%s%s", - columnStart, columnEnd, mainTable, join.isEmpty() ? "" : " ", join, where); + FORMAT_TEMPORAL_EXTENT, + String.format( + "SELECT %s AS extent_start, %s AS extent_end, COUNT(*) AS row_count FROM %s%s%s%s", + minOrUnbounded(columnStart), + maxOrUnbounded(columnEnd), + mainTable, + join.isEmpty() ? "" : " ", + join, + where)); } else { List startAliases = AliasGenerator.getAliases(intervalStart); @@ -179,11 +195,28 @@ public String getTemporalExtentQuery( String where = filter.isPresent() ? String.format(FORMAT_WHERE, filter.get()) : ""; return String.format( - "SELECT * FROM (SELECT MIN(%s) FROM %s%s) AS A, (SELECT MAX(%s) from %s%s) AS B;", - columnStart, startTableWithJoins, where, columnEnd, endTableWithJoins, where); + "SELECT S.extent_start, E.extent_end FROM (SELECT %s AS extent_start, COUNT(*) AS" + + " row_count FROM %s%s) S, (SELECT %s AS extent_end FROM %s%s) E WHERE S.row_count >" + + " 0", + minOrUnbounded(columnStart), + startTableWithJoins, + where, + maxOrUnbounded(columnEnd), + endTableWithJoins, + where); } } + /** The earliest start, or NULL (unbounded) if any start is NULL. */ + private static String minOrUnbounded(String column) { + return String.format("CASE WHEN COUNT(*) > COUNT(%1$s) THEN NULL ELSE MIN(%1$s) END", column); + } + + /** The latest end, or NULL (unbounded) if any end is NULL. */ + private static String maxOrUnbounded(String column) { + return String.format("CASE WHEN COUNT(*) > COUNT(%1$s) THEN NULL ELSE MAX(%1$s) END", column); + } + private Optional getFilter(SqlQueryMapping mapping, SqlQuerySchema schemaSql) { return schemaSql.getFilter().map(cql -> filterEncoder.encode(cql, mapping)); } diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialect.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialect.java index 3835ee993..77174ff11 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialect.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialect.java @@ -177,6 +177,12 @@ default String dropResultSetTable(String name) { Optional parseExtent(String extent, EpsgCrs crs); + /** + * @param start the earliest start, or null if the start is unbounded + * @param end the latest end, or null if the end is unbounded + * @param timeZone the time zone of values without an offset + * @return the temporal extent + */ Optional parseTemporalExtent(String start, String end, ZoneId timeZone); String escapeString(String value); diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialectGpkg.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialectGpkg.java index 708a50da1..10600f3b7 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialectGpkg.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialectGpkg.java @@ -83,17 +83,11 @@ public Optional parseExtent(String extent, EpsgCrs crs) { @Override public Optional parseTemporalExtent(String start, String end, ZoneId timeZone) { - if (Objects.isNull(start)) { - return Optional.empty(); - } DateTimeFormatter parser = DateTimeFormatter.ofPattern("yyyy-MM-dd[['T'][' ']HH:mm:ss][.SSS][X]") .withZone(ZoneOffset.UTC); - Instant parsedStart = parser.parse(start, Instant::from); - if (Objects.isNull(end)) { - return Optional.of(Interval.of(parsedStart, Instant.MAX)); - } - Instant parsedEnd = parser.parse(end, Instant::from); + Instant parsedStart = Objects.isNull(start) ? Instant.MIN : parser.parse(start, Instant::from); + Instant parsedEnd = Objects.isNull(end) ? Instant.MAX : parser.parse(end, Instant::from); return Optional.of(Interval.of(parsedStart, parsedEnd)); } diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialectPgis.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialectPgis.java index 19717fdbe..b42b47571 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialectPgis.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlDialectPgis.java @@ -175,15 +175,8 @@ public Optional parseExtent(String extent, EpsgCrs crs) { @Override public Optional parseTemporalExtent(String start, String end, ZoneId timeZone) { - if (Objects.isNull(start)) { - return Optional.empty(); - } - - Instant parsedStart = parseInstant(start, timeZone); - if (Objects.isNull(end)) { - return Optional.of(Interval.of(parsedStart, Instant.MAX)); - } - Instant parsedEnd = parseInstant(end, timeZone); + Instant parsedStart = Objects.isNull(start) ? Instant.MIN : parseInstant(start, timeZone); + Instant parsedEnd = Objects.isNull(end) ? Instant.MAX : parseInstant(end, timeZone); return Optional.of(Interval.of(parsedStart, parsedEnd)); } diff --git a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy index ebb2970b6..6dacae9a8 100644 --- a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy +++ b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy @@ -21,6 +21,7 @@ import de.ii.xtraplatform.features.domain.MappingRuleFixtures import de.ii.xtraplatform.features.json.app.DecoderFactoryJson import de.ii.xtraplatform.features.sql.domain.ImmutableQueryGeneratorSettings import de.ii.xtraplatform.features.sql.domain.ImmutableSqlPathDefaults +import de.ii.xtraplatform.features.sql.domain.ImmutableSqlQuerySchema import de.ii.xtraplatform.features.sql.domain.SqlDialectPgis import de.ii.xtraplatform.features.sql.domain.SqlPathParser import de.ii.xtraplatform.features.sql.domain.SqlQueryMapping @@ -89,4 +90,41 @@ class AggregateStatsQueryGeneratorSpec extends Specification { actual.startsWith("SELECT COUNT(*) FROM unfaelle_point A WHERE (${INTERSECTS} AND ") actual.contains("OVERLAPS (TIMESTAMP '2019-01-01T00:00:00Z',TIMESTAMP '2019-12-31T23:59:59Z')") } + + def 'the temporal extent of an instant is empty if there is no value'() { + + given: + def instant = unfaelleMapping.getColumnForPrimaryInstant().get() + + when: + String actual = generator.getTemporalExtentQuery(unfaelleMapping, instant.first(), instant.second()) + + then: 'no row without a value, so that a NULL can only stand for an unbounded start or end' + actual == "SELECT T.extent_start, T.extent_end FROM (SELECT MIN(A.unfzeit::timestamp(0)) AS extent_start, MAX(A.unfzeit::timestamp(0)) AS extent_end, COUNT(A.unfzeit::timestamp(0)) AS row_count FROM unfaelle_point A) T WHERE T.row_count > 0" + } + + def 'the temporal extent of an interval is unbounded at the start or end if any start or end is open'() { + + given: 'start and end in the same table' + def column = unfaelleMapping.getColumnForPrimaryInstant().get() + + when: + String actual = generator.getTemporalExtentQuery(unfaelleMapping, column.first(), column.second(), column.first(), column.second()) + + then: 'a NULL start or end is not ignored by MIN or MAX but makes that side unbounded' + actual == "SELECT T.extent_start, T.extent_end FROM (SELECT CASE WHEN COUNT(*) > COUNT(A.unfzeit::timestamp(0)) THEN NULL ELSE MIN(A.unfzeit::timestamp(0)) END AS extent_start, CASE WHEN COUNT(*) > COUNT(A.unfzeit::timestamp(0)) THEN NULL ELSE MAX(A.unfzeit::timestamp(0)) END AS extent_end, COUNT(*) AS row_count FROM unfaelle_point A) T WHERE T.row_count > 0" + } + + def 'the temporal extent of an interval with start and end in different tables'() { + + given: + def column = unfaelleMapping.getColumnForPrimaryInstant().get() + def endTable = new ImmutableSqlQuerySchema.Builder().from(column.first()).name("unfaelle_end").build() + + when: + String actual = generator.getTemporalExtentQuery(unfaelleMapping, column.first(), column.second(), endTable, column.second()) + + then: + actual == "SELECT S.extent_start, E.extent_end FROM (SELECT CASE WHEN COUNT(*) > COUNT(A.unfzeit::timestamp(0)) THEN NULL ELSE MIN(A.unfzeit::timestamp(0)) END AS extent_start, COUNT(*) AS row_count FROM unfaelle_point A) S, (SELECT CASE WHEN COUNT(*) > COUNT(A.unfzeit::timestamp(0)) THEN NULL ELSE MAX(A.unfzeit::timestamp(0)) END AS extent_end FROM unfaelle_point A) E WHERE S.row_count > 0" + } } diff --git a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/SqlDialectPostGisSpec.groovy b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/SqlDialectPostGisSpec.groovy index fba35b54c..639d8afdf 100644 --- a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/SqlDialectPostGisSpec.groovy +++ b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/SqlDialectPostGisSpec.groovy @@ -41,7 +41,8 @@ class SqlDialectPostGisSpec extends Specification { when: Optional interval = sqlDialectPostGis.parseTemporalExtent(null, end, ZoneId.of("UTC")) then: - interval.isEmpty() + interval.get().isUnboundedStart() + interval.get().getEnd().toString() == "2015-12-21T22:17:56Z" } def 'Temporal extent end is null'() { @@ -57,7 +58,8 @@ class SqlDialectPostGisSpec extends Specification { when: Optional interval = sqlDialectPostGis.parseTemporalExtent(null, null, ZoneId.of("UTC")) then: - interval.isEmpty() + interval.get().isUnboundedStart() + interval.get().isUnboundedEnd() } def 'Temporal extent start > end'() { From ea9f0f2a737b3c515eded96549e242cd923d04e3 Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Tue, 10 Nov 2026 05:40:22 +0100 Subject: [PATCH 27/31] fix missing temporal extent of types with only a start or only an end A type with only PRIMARY_INTERVAL_START or only PRIMARY_INTERVAL_END had no computed temporal extent, so its collection always showed an open interval. The extent is now computed from the bound that is there, with the other side unbounded. --- .../sql/app/AggregateStatsQueryGenerator.java | 40 +++++++++++++++++++ .../sql/app/AggregateStatsReaderSql.java | 15 +++++++ .../AggregateStatsQueryGeneratorSpec.groovy | 14 +++++++ 3 files changed, 69 insertions(+) diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java index a2e1c2671..562c98b92 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGenerator.java @@ -207,6 +207,46 @@ public String getTemporalExtentQuery( } } + /** + * The temporal extent of an interval with only a start or only an end; the other side is + * unbounded. + * + * @param mapping the type + * @param bound the table of the start or end + * @param boundColumn the column of the start or end + * @param isStart whether the column is the start + * @return the query + */ + public String getTemporalExtentQuery( + SqlQueryMapping mapping, SqlQuerySchema bound, SqlQueryColumn boundColumn, boolean isStart) { + SqlQuerySchema mainSchema = mapping.getMainTable(); + + List aliases = AliasGenerator.getAliases(bound); + String boundAlias = aliases.get(aliases.size() - 1); + + String mainTable = String.format(FORMAT_TABLE_ALIAS, mainSchema.getName(), aliases.get(0)); + + String column = + SqlQueryColumnOperations.getQualifiedColumnResolved( + boundAlias, SqlQueryColumnOperations.dateToDatetime(boundColumn), sqlDialect); + + String join = JoinGenerator.getJoins(bound, aliases, filterEncoder); + + Optional filter = getFilter(mapping, mainSchema); + String where = filter.isPresent() ? String.format(FORMAT_WHERE, filter.get()) : ""; + + return String.format( + FORMAT_TEMPORAL_EXTENT, + String.format( + "SELECT %s AS extent_start, %s AS extent_end, COUNT(*) AS row_count FROM %s%s%s%s", + isStart ? minOrUnbounded(column) : "NULL", + isStart ? "NULL" : maxOrUnbounded(column), + mainTable, + join.isEmpty() ? "" : " ", + join, + where)); + } + /** The earliest start, or NULL (unbounded) if any start is NULL. */ private static String minOrUnbounded(String column) { return String.format("CASE WHEN COUNT(*) > COUNT(%1$s) THEN NULL ELSE MIN(%1$s) END", column); diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsReaderSql.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsReaderSql.java index 0e5a88161..a0d1c9496 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsReaderSql.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/AggregateStatsReaderSql.java @@ -143,6 +143,21 @@ public Stream> getTemporalExtent(List source SqlQueryOptions.tuple()); } + // only a start or only an end, the other side is unbounded + Optional> bound = + intervalStart.or(() -> intervalEnd); + if (bound.isPresent()) { + return sqlClient + .get() + .getSourceStream( + queryGenerator.getTemporalExtentQuery( + mapping, + bound.get().first(), + bound.get().second(), + intervalStart.isPresent()), + SqlQueryOptions.tuple()); + } + return Source.empty(); })) .via( diff --git a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy index 6dacae9a8..4d5daf944 100644 --- a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy +++ b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/app/AggregateStatsQueryGeneratorSpec.groovy @@ -127,4 +127,18 @@ class AggregateStatsQueryGeneratorSpec extends Specification { then: actual == "SELECT S.extent_start, E.extent_end FROM (SELECT CASE WHEN COUNT(*) > COUNT(A.unfzeit::timestamp(0)) THEN NULL ELSE MIN(A.unfzeit::timestamp(0)) END AS extent_start, COUNT(*) AS row_count FROM unfaelle_point A) S, (SELECT CASE WHEN COUNT(*) > COUNT(A.unfzeit::timestamp(0)) THEN NULL ELSE MAX(A.unfzeit::timestamp(0)) END AS extent_end FROM unfaelle_point A) E WHERE S.row_count > 0" } + + def 'the temporal extent of an interval with only a start or only an end is unbounded on the other side'() { + + given: + def column = unfaelleMapping.getColumnForPrimaryInstant().get() + + when: + String startOnly = generator.getTemporalExtentQuery(unfaelleMapping, column.first(), column.second(), true) + String endOnly = generator.getTemporalExtentQuery(unfaelleMapping, column.first(), column.second(), false) + + then: + startOnly == "SELECT T.extent_start, T.extent_end FROM (SELECT CASE WHEN COUNT(*) > COUNT(A.unfzeit::timestamp(0)) THEN NULL ELSE MIN(A.unfzeit::timestamp(0)) END AS extent_start, NULL AS extent_end, COUNT(*) AS row_count FROM unfaelle_point A) T WHERE T.row_count > 0" + endOnly == "SELECT T.extent_start, T.extent_end FROM (SELECT NULL AS extent_start, CASE WHEN COUNT(*) > COUNT(A.unfzeit::timestamp(0)) THEN NULL ELSE MAX(A.unfzeit::timestamp(0)) END AS extent_end, COUNT(*) AS row_count FROM unfaelle_point A) T WHERE T.row_count > 0" + } } From 73e9da482a41f3eb2c607d1be61d1828fd989766 Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Tue, 10 Nov 2026 05:41:16 +0100 Subject: [PATCH 28/31] fix extent updates after writes that ignore features or open intervals When several features were written in one call (e.g. a wfs:Insert with many features), the spatial and temporal extent of the result only covered the last one. The extents now cover all written features. For data with a start and an end, a feature without a start or end now makes that side of the extent unbounded, also next to features that have one. Values that the write sets itself, such as the start and the open end of a new version, are taken into account. A partial update that does not change the start or the end leaves that side as it is. --- .../features/sql/app/SqlMutationSession.java | 18 +- .../domain/FeatureTokenStatsCollector.java | 244 ++++++++++++++---- .../FeatureTokenStatsCollectorSpec.groovy | 159 ++++++++++++ 3 files changed, 362 insertions(+), 59 deletions(-) create mode 100644 xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollectorSpec.groovy diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/SqlMutationSession.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/SqlMutationSession.java index f356b1161..cff3e7414 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/SqlMutationSession.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/app/SqlMutationSession.java @@ -156,9 +156,10 @@ public FeatureTransactions.MutationResult createFeatures( .hasFeatures(false); List collected = new ArrayList<>(); + FeatureTokenStatsCollector.Stats stats = new FeatureTokenStatsCollector.Stats(crs); try { for (FeatureTokenSource src : featureTokenSources) { - drainSource(src, mapping, crs, builder, collected, false); + drainSource(src, mapping, crs, stats, collected, false); } } catch (RuntimeException e) { return builder.error(translateEncoderError(e)).build(); @@ -172,7 +173,9 @@ public FeatureTransactions.MutationResult createFeatures( for (FeatureDataSql feature : collected) { applyRoleOverrides(feature, roleOverrides); } + stats.applyRoleOverrides(roleOverrides); } + stats.writeTo(builder); RowCursor rowCursor = new RowCursor(mapping.getMainTable().getFullPath()); @@ -1721,11 +1724,13 @@ private FeatureTransactions.MutationResult writeFeatures( ImmutableMutationResult.builder().type(type).hasFeatures(false); List collected = new ArrayList<>(); + FeatureTokenStatsCollector.Stats stats = new FeatureTokenStatsCollector.Stats(crs); try { - drainSource(featureTokenSource, mapping, crs, builder, collected, partial); + drainSource(featureTokenSource, mapping, crs, stats, collected, partial); } catch (RuntimeException e) { return builder.error(translateEncoderError(e)).build(); } + stats.writeTo(builder); RowCursor rowCursor = new RowCursor(mapping.getMainTable().getFullPath()); boolean deleteFirst = @@ -1743,17 +1748,16 @@ private FeatureTransactions.MutationResult writeFeatures( // Assembles the token-source → FeatureEncoderSql pipeline and drains it into `collected`. A // fresh FeatureTokenStatsCollector is instantiated per source so internal transformer state - // doesn't leak across runs; the result builder is shared, so accumulated stats (bbox, temporal - // extent) overwrite per source — matching the existing single-source-multi-feature semantics - // where the last feature's stats win. + // doesn't leak across runs; the stats are shared, so the extents (bbox, temporal extent) cover + // the features of all sources. private void drainSource( FeatureTokenSource featureTokenSource, SqlQueryMapping mapping, EpsgCrs crs, - ImmutableMutationResult.Builder builder, + FeatureTokenStatsCollector.Stats stats, List collected, boolean partial) { - FeatureTokenStatsCollector statsCollector = new FeatureTokenStatsCollector(builder, crs); + FeatureTokenStatsCollector statsCollector = new FeatureTokenStatsCollector(stats, partial); Source featureSqlSource = featureTokenSource diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollector.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollector.java index 318d45417..af55f252d 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollector.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollector.java @@ -9,6 +9,7 @@ import de.ii.xtraplatform.crs.domain.BoundingBox; import de.ii.xtraplatform.crs.domain.EpsgCrs; +import de.ii.xtraplatform.features.domain.FeatureTransactions; import de.ii.xtraplatform.features.domain.ImmutableMutationResult.Builder; import de.ii.xtraplatform.features.domain.SchemaBase.Role; import de.ii.xtraplatform.features.domain.Tuple; @@ -18,24 +19,32 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; +import java.util.Map; import java.util.Objects; +/** + * Collects the spatial and temporal extent of the features of one token source into {@link Stats}, + * which can be shared by all sources of a mutation. + */ public class FeatureTokenStatsCollector extends FeatureTokenTransformerSql { - private final Builder builder; - private final EpsgCrs crs; + private final Stats stats; + private final boolean partial; private int dim = 2; - private Double xmin; - private Double ymin; - private Double xmax; - private Double ymax; - private String start = ""; - private String end = ""; - - public FeatureTokenStatsCollector(Builder builder, EpsgCrs crs) { + // the values of the current feature; null if not given, PATCH_NULL_VALUE if cleared + private String featureInstant; + private String featureStart; + private String featureEnd; + + /** + * @param stats the extents of the mutation + * @param partial whether the features only carry the properties that change, so that a missing + * start or end leaves the extent as it is instead of making it unbounded + */ + public FeatureTokenStatsCollector(Stats stats, boolean partial) { super(); - this.builder = builder; - this.crs = crs; + this.stats = stats; + this.partial = partial; } @Override @@ -47,62 +56,77 @@ public void onStart(ModifiableContext context) } @Override - public void onEnd(ModifiableContext context) { - if (xmin != null && ymin != null && xmax != null && ymax != null) { - builder.spatialExtent(BoundingBox.of(xmin, ymin, xmax, ymax, crs)); - } + // null stands for a value that the next feature does not give + @SuppressWarnings("PMD.NullAssignment") + public void onFeatureStart(ModifiableContext context) { + this.featureInstant = null; + this.featureStart = null; + this.featureEnd = null; + + super.onFeatureStart(context); + } + + @Override + public void onFeatureEnd(ModifiableContext context) { + SqlQueryMapping mapping = context.mapping(); - if (!start.isEmpty() || !end.isEmpty()) { - builder.temporalExtent(Tuple.of(parseTemporal(start), parseTemporal(end))); + if (mapping.getSchemaForRole(Role.PRIMARY_INSTANT).isPresent()) { + if (Objects.nonNull(featureInstant) && !isCleared(featureInstant)) { + stats.addInstant(featureInstant); + } + } else if (mapping.getSchemaForRole(Role.PRIMARY_INTERVAL_START).isPresent() + || mapping.getSchemaForRole(Role.PRIMARY_INTERVAL_END).isPresent()) { + addInterval(mapping); } - super.onEnd(context); + super.onFeatureEnd(context); } - private Long parseTemporal(String temporal) { - if (temporal.isEmpty()) { - return null; + private void addInterval(SqlQueryMapping mapping) { + // a type with only one of the two roles is unbounded on the other side + if (mapping.getSchemaForRole(Role.PRIMARY_INTERVAL_START).isEmpty()) { + stats.addIntervalStart(null); + } else if (isDetermined(featureStart)) { + stats.addIntervalStart(boundOrUnbounded(featureStart)); } - try { - if (temporal.length() > 10) { - return ZonedDateTime.parse(temporal).toInstant().toEpochMilli(); - } - return LocalDate.parse(temporal).atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli(); - } catch (DateTimeParseException e) { - return null; + if (mapping.getSchemaForRole(Role.PRIMARY_INTERVAL_END).isEmpty()) { + stats.addIntervalEnd(null); + } else if (isDetermined(featureEnd)) { + stats.addIntervalEnd(boundOrUnbounded(featureEnd)); } } + // a missing value leaves a partial update as it is, but is unbounded for a complete feature + private boolean isDetermined(String value) { + return !partial || Objects.nonNull(value); + } + + private static String boundOrUnbounded(String value) { + return Objects.isNull(value) || isCleared(value) ? null : value; + } + + private static boolean isCleared(String value) { + return Objects.equals(value, FeatureTransactions.PATCH_NULL_VALUE); + } + @Override - @SuppressWarnings("PMD.CyclomaticComplexity") public void onValue(ModifiableContext context) { String value = context.value(); - if (Objects.isNull(value)) { - super.onValue(context); - return; - } - - if (hasRole(context, Role.PRIMARY_INSTANT)) { - if (start.isEmpty() || value.compareTo(start) < 0) { - this.start = value; - } - if (end.isEmpty() || value.compareTo(end) > 0) { - this.end = value; + if (Objects.nonNull(value)) { + if (hasRole(context, Role.PRIMARY_INSTANT)) { + this.featureInstant = value; + } else if (hasRole(context, Role.PRIMARY_INTERVAL_START)) { + this.featureStart = value; + } else if (hasRole(context, Role.PRIMARY_INTERVAL_END)) { + this.featureEnd = value; } - } else if (hasRole(context, Role.PRIMARY_INTERVAL_START) - && (start.isEmpty() || value.compareTo(start) < 0)) { - this.start = value; - } else if (hasRole(context, Role.PRIMARY_INTERVAL_END) - && (end.isEmpty() || value.compareTo(end) > 0)) { - this.end = value; } super.onValue(context); } @Override - @SuppressWarnings({"PMD.CognitiveComplexity", "PMD.CyclomaticComplexity"}) public void onGeometry(ModifiableContext context) { // Only the primary geometry feeds the spatial extent: secondary geometry properties may // store positions in a different CRS (position variants), which must not be interpreted in @@ -113,10 +137,7 @@ public void onGeometry(ModifiableContext contex double[][] minMax = value.accept(new MinMaxDeriver()); if (minMax.length > 1 && minMax[0].length >= dim && minMax[1].length >= dim) { - this.xmin = xmin == null ? minMax[0][0] : Math.min(xmin, minMax[0][0]); - this.xmax = xmax == null ? minMax[1][0] : Math.max(xmax, minMax[1][0]); - this.ymin = ymin == null ? minMax[0][1] : Math.min(ymin, minMax[0][1]); - this.ymax = ymax == null ? minMax[1][1] : Math.max(ymax, minMax[1][1]); + stats.addBoundingBox(minMax[0][0], minMax[0][1], minMax[1][0], minMax[1][1]); } } @@ -130,4 +151,123 @@ private boolean hasRole(ModifiableContext conte .filter(schema -> Objects.equals(schema.getFullPathAsString(), context.pathAsString())) .isPresent(); } + + /** + * The extents of the features written by one mutation. In the temporal extent, null stands for an + * unbounded start or end, as soon as one feature has no start or no end. + */ + public static final class Stats { + + private final EpsgCrs crs; + private Double xmin; + private Double ymin; + private Double xmax; + private Double ymax; + // earliest start and latest end that are set + private String start; + private String end; + private boolean startUnbounded; + private boolean endUnbounded; + // whether a written feature determines the start or the end; not the case for a partial + // update that leaves them as they are + private boolean startKnown; + private boolean endKnown; + + public Stats(EpsgCrs crs) { + this.crs = crs; + } + + void addBoundingBox(double minX, double minY, double maxX, double maxY) { + this.xmin = xmin == null ? minX : Math.min(xmin, minX); + this.ymin = ymin == null ? minY : Math.min(ymin, minY); + this.xmax = xmax == null ? maxX : Math.max(xmax, maxX); + this.ymax = ymax == null ? maxY : Math.max(ymax, maxY); + } + + void addInstant(String value) { + addIntervalStart(value); + addIntervalEnd(value); + } + + void addIntervalStart(String value) { + this.startKnown = true; + if (Objects.isNull(value)) { + this.startUnbounded = true; + } else if (Objects.isNull(start) || value.compareTo(start) < 0) { + this.start = value; + } + } + + void addIntervalEnd(String value) { + this.endKnown = true; + if (Objects.isNull(value)) { + this.endUnbounded = true; + } else if (Objects.isNull(end) || value.compareTo(end) > 0) { + this.end = value; + } + } + + /** + * Applies values that the mutation sets for all of its features, e.g. the start and the open + * end of new versions. A null value is an unbounded start or end. + * + * @param overrides the values per role + */ + public void applyRoleOverrides(Map overrides) { + if (overrides.containsKey(Role.PRIMARY_INTERVAL_START)) { + this.start = Objects.toString(overrides.get(Role.PRIMARY_INTERVAL_START), null); + this.startUnbounded = Objects.isNull(start); + this.startKnown = true; + } + if (overrides.containsKey(Role.PRIMARY_INTERVAL_END)) { + this.end = Objects.toString(overrides.get(Role.PRIMARY_INTERVAL_END), null); + this.endUnbounded = Objects.isNull(end); + this.endKnown = true; + } + } + + /** + * Sets the extents of the mutation result. A side that no written feature determines takes a + * value of the other side: extents only grow, and the start of a feature is never after its + * end, so that value does not change the extent on the unknown side. Without such a value, the + * result has no temporal extent. + * + * @param builder the result of the mutation + */ + public void writeTo(Builder builder) { + if (xmin != null && ymin != null && xmax != null && ymax != null) { + builder.spatialExtent(BoundingBox.of(xmin, ymin, xmax, ymax, crs)); + } + + writeTemporal(builder); + } + + // the count comes from the conditional expressions of the two sides, splitting them up would + // not make the method easier to follow + @SuppressWarnings("PMD.NPathComplexity") + private void writeTemporal(Builder builder) { + String startValue = startKnown ? start : end; + String endValue = endKnown ? end : start; + boolean startOpen = startKnown && startUnbounded; + boolean endOpen = endKnown && endUnbounded; + + if ((startOpen || Objects.nonNull(startValue)) && (endOpen || Objects.nonNull(endValue))) { + builder.temporalExtent( + Tuple.of( + startOpen ? null : parseTemporal(startValue), + endOpen ? null : parseTemporal(endValue))); + } + } + + private static Long parseTemporal(String temporal) { + try { + if (temporal.length() > 10) { + return ZonedDateTime.parse(temporal).toInstant().toEpochMilli(); + } + return LocalDate.parse(temporal).atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli(); + } catch (DateTimeParseException e) { + return null; + } + } + } } diff --git a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollectorSpec.groovy b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollectorSpec.groovy new file mode 100644 index 000000000..c06b49c3b --- /dev/null +++ b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollectorSpec.groovy @@ -0,0 +1,159 @@ +/* + * Copyright 2026 interactive instruments GmbH + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package de.ii.xtraplatform.features.sql.domain + +import de.ii.xtraplatform.crs.domain.OgcCrs +import de.ii.xtraplatform.features.domain.FeatureSchema +import de.ii.xtraplatform.features.domain.FeatureTransactions +import de.ii.xtraplatform.features.domain.ImmutableMutationResult +import de.ii.xtraplatform.features.domain.SchemaBase.Role +import de.ii.xtraplatform.features.domain.Tuple +import spock.lang.Specification + +import java.time.Instant + +class FeatureTokenStatsCollectorSpec extends Specification { + + static final String JAN = "2024-01-01T00:00:00Z" + static final String MAR = "2024-03-01T00:00:00Z" + static final String APR = "2024-04-01T00:00:00Z" + + def "a feature without an end makes the end unbounded, whatever the other features have"() { + + given: 'two features written in one mutation, from separate sources' + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, false, JAN, null) + interval(stats, false, MAR, APR) + + expect: + temporal(stats) == Tuple.of(millis(JAN), null) + } + + def "a feature without a start makes the start unbounded"() { + + given: + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, false, MAR, APR) + interval(stats, false, null, MAR) + + expect: + temporal(stats) == Tuple.of(null, millis(APR)) + } + + def "features without instants are ignored"() { + + given: + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + stats.addInstant(MAR) + stats.addInstant(JAN) + + expect: + temporal(stats) == Tuple.of(millis(JAN), millis(MAR)) + } + + def "no temporal extent without temporal values"() { + + given: + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + + expect: + temporal(stats) == null + } + + def "a type with only a start is unbounded at the end"() { + + given: + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, false, JAN, null, true, false) + + expect: + temporal(stats) == Tuple.of(millis(JAN), null) + } + + def "a type with only an end is unbounded at the start"() { + + given: + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, false, null, APR, false, true) + + expect: + temporal(stats) == Tuple.of(null, millis(APR)) + } + + def "the values set by the mutation replace those of the features"() { + + given: 'a new version: the mutation sets the start and leaves the end open' + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, false, null, null) + def overrides = new HashMap() + overrides.put(Role.PRIMARY_INTERVAL_START, MAR) + overrides.put(Role.PRIMARY_INTERVAL_END, null) + stats.applyRoleOverrides(overrides) + + expect: + temporal(stats) == Tuple.of(millis(MAR), null) + } + + def "a partial update without start or end leaves the extent as it is"() { + + given: + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, true, null, null) + + expect: + temporal(stats) == null + } + + def "a partial update with an end only uses it for both sides"() { + + given: 'the start is unchanged and not after the end' + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, true, null, APR) + + expect: + temporal(stats) == Tuple.of(millis(APR), millis(APR)) + } + + def "a partial update that clears the end makes it unbounded"() { + + given: + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, true, MAR, FeatureTransactions.PATCH_NULL_VALUE) + + expect: + temporal(stats) == Tuple.of(millis(MAR), null) + } + + // one feature as the collector passes it on at the end of the feature + static void interval(FeatureTokenStatsCollector.Stats stats, boolean partial, String start, String end, + boolean hasStart = true, boolean hasEnd = true) { + def collector = new FeatureTokenStatsCollector(stats, partial) + collector.featureStart = start + collector.featureEnd = end + collector.addInterval(mapping(hasStart, hasEnd)) + } + + static SqlQueryMapping mapping(boolean hasStart, boolean hasEnd) { + def schema = new de.ii.xtraplatform.features.domain.ImmutableFeatureSchema.Builder() + .name("t").type(de.ii.xtraplatform.features.domain.SchemaBase.Type.DATETIME).build() + return [getSchemaForRole: { Role role -> + (role == Role.PRIMARY_INTERVAL_START && hasStart) || (role == Role.PRIMARY_INTERVAL_END && hasEnd) + ? Optional.of(schema) : Optional.empty() + }] as SqlQueryMapping + } + + static Tuple temporal(FeatureTokenStatsCollector.Stats stats) { + def builder = ImmutableMutationResult.builder().type(FeatureTransactions.MutationResult.Type.CREATE).hasFeatures(false) + stats.writeTo(builder) + builder.build().getTemporalExtent().orElse(null) + } + + static Long millis(String instant) { + Instant.parse(instant).toEpochMilli() + } +} From 49f6115378fe98e4d5d1d7ba17a4c61ae2bc3c1a Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Tue, 10 Nov 2026 05:54:19 +0100 Subject: [PATCH 29/31] features: reject extents that set neither values nor computed An empty `spatial` or `temporal` object stopped the inheritance of a fixed extent from the parent level, exactly like `computed: true`, but read as if nothing was set. It is now rejected; to compute the extent instead of inheriting a fixed one, set `computed: true`. --- .../features/domain/SpatialExtent.java | 12 ++++++++---- .../features/domain/TemporalExtent.java | 14 ++++++++++---- .../features/domain/SpatialExtentSpec.groovy | 9 +++++++++ .../features/domain/TemporalExtentSpec.groovy | 10 +++++++++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java index 4ba9e1f62..085339c53 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/SpatialExtent.java @@ -73,11 +73,13 @@ public interface SpatialExtent { /** * @langEn Set to `true` to compute the extent from the data instead of inheriting a fixed extent - * from the parent level (provider for types, tileset defaults for tilesets). Must not be - * combined with coordinates; `false` is not allowed. + * from the parent level (provider for types, tileset defaults for tilesets). Without a fixed + * extent on the parent level, this is the same as omitting the extent. Either the coordinates + * or `computed: true` must be set; `false` is not allowed. * @langDe Auf `true` setzen, um den Extent aus den Daten zu berechnen, statt einen festen Extent - * der übergeordneten Ebene (Provider für Types, Tileset-Defaults für Tilesets) zu erben. Darf - * nicht mit Koordinaten kombiniert werden; `false` ist nicht erlaubt. + * der übergeordneten Ebene (Provider für Types, Tileset-Defaults für Tilesets) zu erben. Ohne + * festen Extent auf der übergeordneten Ebene ist das dasselbe, wie den Extent wegzulassen. + * Anzugeben sind entweder die Koordinaten oder `computed: true`; `false` ist nicht erlaubt. * @since v4.9 */ @Nullable @@ -94,6 +96,8 @@ default void checkExclusiveComputed() { Preconditions.checkState( !(hasCoordinates && autoCompute), "SpatialExtent: 'computed' and explicit coordinates must not be set at the same time."); + Preconditions.checkState( + hasCoordinates || autoCompute, "SpatialExtent: set the coordinates or 'computed: true'."); if (hasCoordinates) { checkCoordinatesComplete(); diff --git a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java index 887ec7af3..a25a6c810 100644 --- a/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java +++ b/xtraplatform-features/src/main/java/de/ii/xtraplatform/features/domain/TemporalExtent.java @@ -52,11 +52,13 @@ public interface TemporalExtent { /** * @langEn Set to `true` to compute the extent from the data instead of inheriting a fixed extent - * from the parent level (provider for types). Must not be combined with `start` or `end`; - * `false` is not allowed. + * from the parent level (provider for types). Without a fixed extent on the parent level, + * this is the same as omitting the extent. Either `start`, `end` or both, or `computed: true` + * must be set; `false` is not allowed. * @langDe Auf `true` setzen, um den Extent aus den Daten zu berechnen, statt einen festen Extent - * der übergeordneten Ebene (Provider für Types) zu erben. Darf nicht mit `start` oder `end` - * kombiniert werden; `false` ist nicht erlaubt. + * der übergeordneten Ebene (Provider für Types) zu erben. Ohne festen Extent auf der + * übergeordneten Ebene ist das dasselbe, wie den Extent wegzulassen. Anzugeben sind entweder + * `start`, `end` oder beide oder `computed: true`; `false` ist nicht erlaubt. * @since v4.9 */ @Nullable @@ -86,6 +88,10 @@ default void check() { !(hasBounds && Boolean.TRUE.equals(getComputed())), "TemporalExtent: 'computed' and explicit start/end must not be set at the same time."); + Preconditions.checkState( + hasBounds || Boolean.TRUE.equals(getComputed()), + "TemporalExtent: set 'start', 'end' or 'computed: true'."); + try { toInterval(); } catch (DateTimeParseException e) { diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy index 45f1c787e..3f18decd5 100644 --- a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/SpatialExtentSpec.groovy @@ -27,6 +27,15 @@ class SpatialExtentSpec extends Specification { thrown(IllegalStateException) } + def "an extent without coordinates and computed is rejected"() { + when: 'an empty object, which would otherwise silently stop the inheritance' + new ImmutableSpatialExtent.Builder().build() + + then: + def e = thrown(IllegalStateException) + e.message == "SpatialExtent: set the coordinates or 'computed: true'." + } + def "computed must not be combined with coordinates"() { when: new ImmutableSpatialExtent.Builder().xmin(0).ymin(0).xmax(1).ymax(1).computed(true).build() diff --git a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy index 6e8155971..7fc2c1b67 100644 --- a/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy +++ b/xtraplatform-features/src/test/groovy/de/ii/xtraplatform/features/domain/TemporalExtentSpec.groovy @@ -33,7 +33,15 @@ class TemporalExtentSpec extends Specification { expect: extent(null, "2020-12-31").toInterval().get().isUnboundedStart() extent("2020-01-01", null).toInterval().get().isUnboundedEnd() - extent(null, null).toInterval().isEmpty() + } + + def "an extent without start, end and computed is rejected"() { + when: 'an empty object, which would otherwise silently stop the inheritance' + extent(null, null) + + then: + def e = thrown(IllegalStateException) + e.message == "TemporalExtent: set 'start', 'end' or 'computed: true'." } def "invalid extent '#start' / '#end' is rejected"() { From f70ef8b90a5610f0b2320c68e6f9646fe88a3d78 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Tue, 17 Nov 2026 17:26:46 +0100 Subject: [PATCH 30/31] fix extent updates after partial updates that only clear the start or end A partial update that cleared the end without touching the start, or the start without touching the end, gave no temporal extent, so the extent did not become unbounded on that side. The unknown side now gets a value that never widens an extent. An unparsable value no longer makes a side unbounded either. --- .../domain/FeatureTokenStatsCollector.java | 37 +++++++++++++------ .../FeatureTokenStatsCollectorSpec.groovy | 20 ++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollector.java b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollector.java index af55f252d..7c5777f7f 100644 --- a/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollector.java +++ b/xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollector.java @@ -158,6 +158,12 @@ private boolean hasRole(ModifiableContext conte */ public static final class Stats { + // A side without a value, e.g. the start of a partial update that only clears the end, must + // not change the extent; since extents only grow, the latest start and the earliest end are + // the values that never do. Null would stand for an unbounded side. + private static final long NO_START = Long.MAX_VALUE; + private static final long NO_END = Long.MIN_VALUE; + private final EpsgCrs crs; private Double xmin; private Double ymin; @@ -229,8 +235,9 @@ public void applyRoleOverrides(Map overrides) { /** * Sets the extents of the mutation result. A side that no written feature determines takes a * value of the other side: extents only grow, and the start of a feature is never after its - * end, so that value does not change the extent on the unknown side. Without such a value, the - * result has no temporal extent. + * end, so that value does not change the extent on the unknown side. If the other side is + * unbounded and has no value, the unknown side gets a value that never changes an extent. + * Without any temporal value, the result has no temporal extent. * * @param builder the result of the mutation */ @@ -242,31 +249,37 @@ public void writeTo(Builder builder) { writeTemporal(builder); } - // the count comes from the conditional expressions of the two sides, splitting them up would - // not make the method easier to follow - @SuppressWarnings("PMD.NPathComplexity") private void writeTemporal(Builder builder) { String startValue = startKnown ? start : end; String endValue = endKnown ? end : start; boolean startOpen = startKnown && startUnbounded; boolean endOpen = endKnown && endUnbounded; - if ((startOpen || Objects.nonNull(startValue)) && (endOpen || Objects.nonNull(endValue))) { - builder.temporalExtent( - Tuple.of( - startOpen ? null : parseTemporal(startValue), - endOpen ? null : parseTemporal(endValue))); + boolean nothingWritten = + !startOpen && !endOpen && (Objects.isNull(startValue) || Objects.isNull(endValue)); + if (nothingWritten) { + return; } + + builder.temporalExtent( + Tuple.of(bound(startOpen, startValue, NO_START), bound(endOpen, endValue, NO_END))); } - private static Long parseTemporal(String temporal) { + private static Long bound(boolean unbounded, String value, long noValue) { + return unbounded ? null : parseTemporal(value, noValue); + } + + private static Long parseTemporal(String temporal, long noValue) { + if (Objects.isNull(temporal)) { + return noValue; + } try { if (temporal.length() > 10) { return ZonedDateTime.parse(temporal).toInstant().toEpochMilli(); } return LocalDate.parse(temporal).atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli(); } catch (DateTimeParseException e) { - return null; + return noValue; } } } diff --git a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollectorSpec.groovy b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollectorSpec.groovy index c06b49c3b..423653951 100644 --- a/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollectorSpec.groovy +++ b/xtraplatform-features-sql/src/test/groovy/de/ii/xtraplatform/features/sql/domain/FeatureTokenStatsCollectorSpec.groovy @@ -129,6 +129,26 @@ class FeatureTokenStatsCollectorSpec extends Specification { temporal(stats) == Tuple.of(millis(MAR), null) } + def "a partial update that only clears the end makes it unbounded without changing the start"() { + + given: 'the start is unchanged and unknown' + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, true, null, FeatureTransactions.PATCH_NULL_VALUE) + + expect: 'the latest possible start, which never widens an extent' + temporal(stats) == Tuple.of(Long.MAX_VALUE, null) + } + + def "a partial update that only clears the start makes it unbounded without changing the end"() { + + given: + def stats = new FeatureTokenStatsCollector.Stats(OgcCrs.CRS84) + interval(stats, true, FeatureTransactions.PATCH_NULL_VALUE, null) + + expect: + temporal(stats) == Tuple.of(null, Long.MIN_VALUE) + } + // one feature as the collector passes it on at the end of the feature static void interval(FeatureTokenStatsCollector.Stats stats, boolean partial, String start, String end, boolean hasStart = true, boolean hasEnd = true) { From cf73ff9180d0e324adc155eebfd04599e7fa59a6 Mon Sep 17 00:00:00 2001 From: Andreas Zahnen Date: Tue, 17 Nov 2026 17:28:35 +0100 Subject: [PATCH 31/31] fix WFS feature types getting the bounding box of another type The id of a type was tried first and may be the local name of another WFS feature type. It is now tried after prefix_localname and localname. --- .../features/gml/app/AggregateStatsReaderWfs.java | 5 +++-- .../features/gml/app/AggregateStatsReaderWfsSpec.groovy | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfs.java b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfs.java index 8b3a3c26c..d9b46ec14 100644 --- a/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfs.java +++ b/xtraplatform-features-gml/src/main/java/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfs.java @@ -61,7 +61,7 @@ public Stream> getTemporalExtent(List sourceSc /** * The ids under which the capabilities analyzer stores the bounding box of a feature type: the * prefixed name becomes {@code prefix_localname}, and if unique also {@code localname}, both in - * lower case. + * lower case. The id of the type is the last resort. */ static List getTypeIds(FeatureSchema schema) { String prefixedName = @@ -69,12 +69,13 @@ static List getTypeIds(FeatureSchema schema) { int separator = prefixedName.indexOf(':'); String localName = prefixedName.substring(separator + 1).toLowerCase(Locale.ROOT); + // the type id comes last, it may be the local name of another feature type List ids = new ArrayList<>(); - ids.add(schema.getName()); if (separator > 0) { ids.add(prefixedName.substring(0, separator).toLowerCase(Locale.ROOT) + "_" + localName); } ids.add(localName); + ids.add(schema.getName()); return ids; } } diff --git a/xtraplatform-features-gml/src/test/groovy/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfsSpec.groovy b/xtraplatform-features-gml/src/test/groovy/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfsSpec.groovy index b0eae4db2..0d9881f99 100644 --- a/xtraplatform-features-gml/src/test/groovy/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfsSpec.groovy +++ b/xtraplatform-features-gml/src/test/groovy/de/ii/xtraplatform/features/gml/app/AggregateStatsReaderWfsSpec.groovy @@ -22,8 +22,8 @@ class AggregateStatsReaderWfsSpec extends Specification { .type(SchemaBase.Type.OBJECT) .build() - expect: 'the type id, then prefix_localname and localname in lower case, not the prefixed name' - AggregateStatsReaderWfs.getTypeIds(schema) == ["rbz", "dvg_nw_dvg1_rbz", "nw_dvg1_rbz"] + expect: 'prefix_localname and localname in lower case, not the prefixed name, and the type id last' + AggregateStatsReaderWfs.getTypeIds(schema) == ["dvg_nw_dvg1_rbz", "nw_dvg1_rbz", "rbz"] } def "a feature type without a prefix"() {