Skip to content

Commit

Permalink
fix(filters): fix sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Sep 17, 2024
1 parent c037a9b commit 57292a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/ogc/features/domain/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func encodeCursor(fid int64, filtersChecksum []byte) EncodedCursor {
return EncodedCursor(base64.RawURLEncoding.EncodeToString(fidAsBytes) + string(separator) + base64.RawURLEncoding.EncodeToString(filtersChecksum))
}

// Decode turns encoded cursor into DecodedCursor and verifies the
// that the checksum of query params that act as filters hasn't changed
// Decode turns encoded cursor into DecodedCursor and verifies that
// the checksum of query params that act as filters hasn't changed
func (c EncodedCursor) Decode(filtersChecksum []byte) DecodedCursor {
value, err := neturl.QueryUnescape(string(c))
if err != nil || value == "" {
Expand Down
17 changes: 8 additions & 9 deletions internal/ogc/features/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,23 +279,22 @@ func configurePropertyFiltersWithAllowedValues(datasources map[DatasourceKey]ds.
collections map[string]config.GeoSpatialCollection) map[string]ds.PropertyFiltersWithAllowedValues {

result := make(map[string]ds.PropertyFiltersWithAllowedValues)
nrOfFilters := 0
for k, datasource := range datasources {
filters := datasource.GetPropertyFiltersWithAllowedValues(k.collectionID)
result[k.collectionID] = filters
nrOfFilters += len(filters)
result[k.collectionID] = datasource.GetPropertyFiltersWithAllowedValues(k.collectionID)
}

// sanity check to make sure datasources return all configured property filters.
nrOfExpectedFilters := 0
for _, collection := range collections {
actual := len(result[collection.ID])
if collection.Features != nil && collection.Features.Filters.Properties != nil {
nrOfExpectedFilters += len(collection.Features.Filters.Properties)
expected := len(collection.Features.Filters.Properties)
if expected != actual {
log.Fatalf("number of property filters received from datasource for collection '%s' does not "+
"match the number of configured property filters. Expected filters: %d, got from datasource: %d",
collection.ID, expected, actual)
}
}
}
if nrOfExpectedFilters != nrOfFilters {
log.Fatal("number of property filters received from datasource does not match the number of configured property filters")
}
return result
}

Expand Down

0 comments on commit 57292a1

Please sign in to comment.