Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/geosync/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@
(concat
[(rest/create-data-store geoserver-workspace store-name file-url :geopackage)
(rest/create-feature-type-via-put geoserver-workspace store-name file-url :geopackage)]
(when (not= native-name layer-name)
(when (not= native-name store-name)
[(rest/create-feature-type-alias geoserver-workspace
store-name
native-name
layer-name)
store-name)
(rest/delete-layer geoserver-workspace native-name)
(rest/delete-feature-type geoserver-workspace store-name native-name)])
(when matching-style
[(rest/update-layer-style geoserver-workspace layer-name matching-style :vector)]))))
[(rest/update-layer-style geoserver-workspace store-name matching-style :vector)]))))

:imagemosaic (do (update-properties-file! (str file-url "/datastore.properties") "schema" geoserver-workspace)
(update-properties-file! (str file-url "/indexer.properties") "Name" store-name)
Expand Down
56 changes: 54 additions & 2 deletions test/geosync/core_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns geosync.core-test
(:require [clojure.test :refer [deftest is testing]]
[geosync.core :as core]))
(:require [clojure.string :as s]
[clojure.test :refer [deftest is testing]]
[geosync.core :as core]))

(defn geosync-conf
([]
Expand Down Expand Up @@ -61,3 +62,54 @@
(testing "returns one spec if styles already exists and overwrite-styles is false"
(is (= (count (core/file-paths->style-specs (geosync-conf {:overwrite-styles true}) #{"my-workspace:test-style"} ["test/data/test-style.css"]))
1))))

(defn- gpkg-file-spec
[store-name layer-name native-name]
{:store-type :geopackage
:store-name store-name
:layer-name layer-name
:native-name native-name
:file-url (str "file:///srv/gis/" store-name ".gpkg")
:style nil
:indexed? false})

(defn- published-feature-type-names
"The feature type names a spec list POSTs to the featuretypes endpoint."
[specs]
(->> specs
(filter (fn [[method uri]]
(and (= "POST" method) (s/ends-with? uri "/featuretypes"))))
;; the first <name> belongs to the nested <store>; the feature type's own follows it
(map (fn [[_ _ body]] (second (re-find #"</store><name>([^<]+)</name>" body))))))

(defn- deleted-feature-type-names
[specs]
(->> specs
(filter (fn [[method uri]]
(and (= "DELETE" method) (s/includes? uri "/featuretypes/"))))
(map (fn [[_ uri]] (last (s/split uri #"/"))))))

(deftest geopackage-layer-specs-test
(testing "a nested GeoPackage publishes under the path-joined store name, not the bare filename"
(let [store-name "elmfire_landfire_fire-area_20260909_130000"
specs (core/file-spec->layer-specs (geosync-conf)
#{}
[]
(gpkg-file-spec store-name
"fire-area_20260909_130000"
"fire_area"))]
(is (= [store-name] (published-feature-type-names specs)))
(is (= ["fire_area"] (deleted-feature-type-names specs)))))
(testing "a flat GeoPackage keeps the name it publishes under today"
(let [specs (core/file-spec->layer-specs (geosync-conf)
#{}
[]
(gpkg-file-spec "state-boundaries" "state-boundaries" "states"))]
(is (= ["state-boundaries"] (published-feature-type-names specs)))))
(testing "no alias is created when the internal table already matches the store name"
(let [specs (core/file-spec->layer-specs (geosync-conf)
#{}
[]
(gpkg-file-spec "viirs-timestamped" "viirs-timestamped" "viirs-timestamped"))]
(is (empty? (published-feature-type-names specs)))
(is (= 2 (count specs))))))