diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..4bbce435 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,713 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84ed82781cea27b43c9b106a979fe450a13a31aab0500595fb3fc06616de08e6" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.33", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "dsp_meta" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "hcl-rs", + "log", + "serde", + "serde_json", + "tracing", + "tracing-subscriber", + "tracing-test", + "url", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" + +[[package]] +name = "hcl-edit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b0742688008be2ba42fdff59d9957c854aa9b991a2db78144261203fe40fe27" +dependencies = [ + "fnv", + "hcl-primitives", + "vecmap-rs", + "winnow", +] + +[[package]] +name = "hcl-primitives" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395f49a98135905a09d33fb54899b057168ca0846729affe019f169c2a030f41" +dependencies = [ + "itoa", + "kstring", + "ryu", + "serde", + "unicode-ident", +] + +[[package]] +name = "hcl-rs" +version = "0.16.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93bfe5579dccda73d287c5b2113cc708c9a435e3e1966c817a20eaf47abd6312" +dependencies = [ + "hcl-edit", + "hcl-primitives", + "indexmap", + "itoa", + "serde", + "vecmap-rs", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "kstring" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3066350882a1cd6d950d055997f379ac37fd39f81cd4d8ed186032eb3c5747" +dependencies = [ + "serde", + "static_assertions", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "memchr" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "percent-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "proc-macro2" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.3.8", + "regex-syntax 0.7.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.5", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "serde" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] + +[[package]] +name = "serde_json" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "tracing-test" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a2c0ff408fe918a94c428a3f2ad04e4afd5c95bbc08fcf868eff750c15728a4" +dependencies = [ + "lazy_static", + "tracing-core", + "tracing-subscriber", + "tracing-test-macro", +] + +[[package]] +name = "tracing-test-macro" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" +dependencies = [ + "lazy_static", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "vecmap-rs" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fce387fb84d6d84a3609903c3466a642894264c9bebca7fe216bf0a29155e0e" +dependencies = [ + "serde", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +dependencies = [ + "memchr", +] diff --git a/src/dsp_meta/domain/convert/project.rs b/src/dsp_meta/domain/convert/project.rs index 041a1c09..d08e6c16 100644 --- a/src/dsp_meta/domain/convert/project.rs +++ b/src/dsp_meta/domain/convert/project.rs @@ -3,6 +3,7 @@ use tracing::warn; use crate::domain::value::discipline::Discipline; use crate::domain::value::iso_code::IsoCode; +use crate::domain::value::spatial_coverage::SpacialCoverage; use crate::domain::value::{ AlternativeName, ContactPoint, CreatedAt, CreatedBy, Description, EndDate, HowToCite, Keyword, LangString, Name, Publication, Shortcode, StartDate, TeaserText, URL, @@ -135,6 +136,7 @@ pub struct ExtractedProjectBlocks { pub url: Option, pub keywords: Vec, pub disciplines: Vec, + pub spacial_coverages: Vec, pub publications: Vec, } @@ -147,6 +149,7 @@ impl TryFrom> for ExtractedProjectBlocks { let mut url: Option = None; let mut keywords: Vec = vec![]; let mut disciplines: Vec = vec![]; + let mut spacial_coverages: Vec = vec![]; let mut publications: Vec = vec![]; for block in blocks { @@ -178,6 +181,9 @@ impl TryFrom> for ExtractedProjectBlocks { "discipline" => { disciplines.push(Discipline::try_from(block)?); } + "spacial_coverage" => { + spacial_coverages.push(SpacialCoverage::try_from(block)?); + } "publication" => { publications = vec![]; } @@ -193,6 +199,7 @@ impl TryFrom> for ExtractedProjectBlocks { url, keywords, disciplines, + spacial_coverages, publications, }) } @@ -500,6 +507,20 @@ mod tests { assert_eq!(result.disciplines.len(), 1); } + #[test] + fn extract_spacial_coverages() { + let input1 = block!( + spacial_coverage geonames { + ref_id = "1234" + description = "A description" + url = "https://geonames.org/1234" + } + ); + let blocks = vec![&input1]; + let result = ExtractedProjectBlocks::try_from(blocks).unwrap(); + assert_eq!(result.spacial_coverages.len(), 1); + } + #[test] fn extract_publications() { let blocks = vec![]; diff --git a/src/dsp_meta/domain/value/discipline.rs b/src/dsp_meta/domain/value/discipline.rs index 051687c6..9d54bb88 100644 --- a/src/dsp_meta/domain/value/discipline.rs +++ b/src/dsp_meta/domain/value/discipline.rs @@ -1,8 +1,5 @@ -use std::collections::HashMap; - -use tracing::warn; - -use crate::domain::value::iso_code::IsoCode; +use crate::domain::value::lang_text_data::LangTextData; +use crate::domain::value::ref_data::RefData; use crate::errors::DspMetaError; /// The discipline of a project can be defined in two ways: @@ -21,7 +18,7 @@ use crate::errors::DspMetaError; pub enum Discipline { Skos(RefData), Snf(RefData), - Text(TextData), + Text(LangTextData), } impl TryFrom<&hcl::Block> for Discipline { @@ -58,7 +55,7 @@ impl TryFrom<&hcl::Block> for Discipline { Ok(Discipline::Snf(ref_data)) } "text" => { - let text_data = TextData::try_from(attributes)?; + let text_data = LangTextData::try_from(attributes)?; Ok(Discipline::Text(text_data)) } _ => { @@ -68,130 +65,13 @@ impl TryFrom<&hcl::Block> for Discipline { } } -#[derive(Debug, PartialEq)] -pub struct RefData { - ref_id: String, - description: String, - url: url::Url, -} - -/// Reference to a discipline defined in an external reference system (e.g. SNF or SKOS) -/// FIXME: Move to the API layer where the service adapter is implemented -impl TryFrom> for RefData { - type Error = DspMetaError; - - fn try_from(attributes: Vec<&hcl::Attribute>) -> Result { - let mut ref_id: Option = None; - let mut description: Option = None; - let mut url: Option = None; - - for attribute in attributes { - match attribute.key() { - "ref_id" => { - if ref_id.is_some() { - return Err(DspMetaError::CreateValueObject( - "The passed discipline block contains multiple ref_id attributes." - .to_string(), - )); - } - ref_id = match attribute.expr() { - hcl::Expression::String(value) => Ok(Some(value.to_owned())), - _ => Err(DspMetaError::CreateValueObject( - "The passed discipline block ref_id attribute is not of String type." - .to_string(), - )), - }?; - } - "description" => { - if description.is_some() { - return Err(DspMetaError::CreateValueObject( - "The passed discipline block contains multiple description attributes." - .to_string(), - )); - } - description = match attribute.expr() { - hcl::Expression::String(value) => Ok(Some(value.to_owned())), - _ => Err(DspMetaError::CreateValueObject( - "The passed discipline block description attribute is not of String type.".to_string(), - )), - }?; - } - "url" => { - if url.is_some() { - return Err(DspMetaError::CreateValueObject( - "The passed discipline block contains multiple url attributes." - .to_string(), - )); - } - url = match attribute.expr() { - hcl::Expression::String(value) => { - Ok(Some(url::Url::parse(value).map_err(|_| { - DspMetaError::CreateValueObject( - "The passed discipline block url attribute is not a valid url." - .to_string(), - ) - })?)) - } - _ => Err(DspMetaError::CreateValueObject( - "The passed discipline block url attribute is not of String type." - .to_string(), - )), - }?; - } - _ => { - warn!("Parse error: unknown attribute '{}'.", attribute.key()); - } - } - } - - Ok(RefData { - ref_id: ref_id.ok_or(DspMetaError::CreateValueObject( - "The passed discipline block does not contain a ref_id attribute.".to_string(), - ))?, - description: description.ok_or(DspMetaError::CreateValueObject( - "The passed discipline block does not contain a description attribute.".to_string(), - ))?, - url: url.ok_or(DspMetaError::CreateValueObject( - "The passed discipline block does not contain a url attribute.".to_string(), - ))?, - }) - } -} - -#[derive(Debug, PartialEq)] -pub struct TextData(HashMap); - -/// Try to create the text description of the discipline -/// FIXME: Move to the API layer where the service adapter is implemented -impl TryFrom> for TextData { - type Error = DspMetaError; - - fn try_from(attributes: Vec<&hcl::Attribute>) -> Result { - let mut text_data: HashMap = HashMap::new(); - - for attribute in attributes { - let iso_code = IsoCode::try_from(attribute.key())?; - let text = match attribute.expr() { - hcl::Expression::String(value) => Ok(value.to_owned()), - _ => Err(DspMetaError::CreateValueObject( - "The passed discipline block description attribute is not of String type." - .to_string(), - )), - }?; - - text_data.insert(iso_code, text); - } - - Ok(TextData(text_data)) - } -} - #[cfg(test)] mod tests { use tracing_test::traced_test; use super::*; + use crate::domain::value::iso_code::IsoCode; #[test] #[traced_test] @@ -226,7 +106,7 @@ mod tests { ); let input = Discipline::try_from(&block).unwrap(); - let expected = Discipline::Text(TextData( + let expected = Discipline::Text(LangTextData( vec![ (IsoCode::DE, "Lokalgeschichte".to_string()), (IsoCode::EN, "Local history".to_string()), diff --git a/src/dsp_meta/domain/value/lang_text_data.rs b/src/dsp_meta/domain/value/lang_text_data.rs new file mode 100644 index 00000000..5f4aad97 --- /dev/null +++ b/src/dsp_meta/domain/value/lang_text_data.rs @@ -0,0 +1,32 @@ +use std::collections::HashMap; + +use crate::domain::value::iso_code::IsoCode; +use crate::errors::DspMetaError; + +#[derive(Debug, PartialEq)] +pub struct LangTextData(pub HashMap); + +/// Try to create the text description of the discipline +/// FIXME: Move to the API layer where the service adapter is implemented +impl TryFrom> for LangTextData { + type Error = DspMetaError; + + fn try_from(attributes: Vec<&hcl::Attribute>) -> Result { + let mut text_data: HashMap = HashMap::new(); + + for attribute in attributes { + let iso_code = IsoCode::try_from(attribute.key())?; + let text = match attribute.expr() { + hcl::Expression::String(value) => Ok(value.to_owned()), + _ => Err(DspMetaError::CreateValueObject( + "The passed discipline block description attribute is not of String type." + .to_string(), + )), + }?; + + text_data.insert(iso_code, text); + } + + Ok(LangTextData(text_data)) + } +} diff --git a/src/dsp_meta/domain/value/mod.rs b/src/dsp_meta/domain/value/mod.rs index c7124d03..20938bf0 100644 --- a/src/dsp_meta/domain/value/mod.rs +++ b/src/dsp_meta/domain/value/mod.rs @@ -6,6 +6,9 @@ use crate::errors::DspMetaError; pub(crate) mod discipline; pub(crate) mod iso_code; +mod lang_text_data; +mod ref_data; +pub(crate) mod spatial_coverage; pub(crate) mod version; #[derive(Debug, Default, Clone, PartialEq)] diff --git a/src/dsp_meta/domain/value/ref_data.rs b/src/dsp_meta/domain/value/ref_data.rs new file mode 100644 index 00000000..c65578c7 --- /dev/null +++ b/src/dsp_meta/domain/value/ref_data.rs @@ -0,0 +1,93 @@ +use tracing::warn; + +use crate::errors::DspMetaError; + +#[derive(Debug, PartialEq)] +pub struct RefData { + pub(crate) ref_id: String, + pub(crate) description: String, + pub(crate) url: url::Url, +} + +/// Reference to a discipline defined in an external reference system (e.g. SNF or SKOS) +/// FIXME: Move to the API layer where the service adapter is implemented +impl TryFrom> for RefData { + type Error = DspMetaError; + + fn try_from(attributes: Vec<&hcl::Attribute>) -> Result { + let mut ref_id: Option = None; + let mut description: Option = None; + let mut url: Option = None; + + for attribute in attributes { + match attribute.key() { + "ref_id" => { + if ref_id.is_some() { + return Err(DspMetaError::CreateValueObject( + "The passed discipline block contains multiple ref_id attributes." + .to_string(), + )); + } + ref_id = match attribute.expr() { + hcl::Expression::String(value) => Ok(Some(value.to_owned())), + _ => Err(DspMetaError::CreateValueObject( + "The passed discipline block ref_id attribute is not of String type." + .to_string(), + )), + }?; + } + "description" => { + if description.is_some() { + return Err(DspMetaError::CreateValueObject( + "The passed discipline block contains multiple description attributes." + .to_string(), + )); + } + description = match attribute.expr() { + hcl::Expression::String(value) => Ok(Some(value.to_owned())), + _ => Err(DspMetaError::CreateValueObject( + "The passed discipline block description attribute is not of String type.".to_string(), + )), + }?; + } + "url" => { + if url.is_some() { + return Err(DspMetaError::CreateValueObject( + "The passed discipline block contains multiple url attributes." + .to_string(), + )); + } + url = match attribute.expr() { + hcl::Expression::String(value) => { + Ok(Some(url::Url::parse(value).map_err(|_| { + DspMetaError::CreateValueObject( + "The passed discipline block url attribute is not a valid url." + .to_string(), + ) + })?)) + } + _ => Err(DspMetaError::CreateValueObject( + "The passed discipline block url attribute is not of String type." + .to_string(), + )), + }?; + } + _ => { + warn!("Parse error: unknown attribute '{}'.", attribute.key()); + } + } + } + + Ok(RefData { + ref_id: ref_id.ok_or(DspMetaError::CreateValueObject( + "The passed discipline block does not contain a ref_id attribute.".to_string(), + ))?, + description: description.ok_or(DspMetaError::CreateValueObject( + "The passed discipline block does not contain a description attribute.".to_string(), + ))?, + url: url.ok_or(DspMetaError::CreateValueObject( + "The passed discipline block does not contain a url attribute.".to_string(), + ))?, + }) + } +} diff --git a/src/dsp_meta/domain/value/spatial_coverage.rs b/src/dsp_meta/domain/value/spatial_coverage.rs new file mode 100644 index 00000000..1647b3ca --- /dev/null +++ b/src/dsp_meta/domain/value/spatial_coverage.rs @@ -0,0 +1,70 @@ +use crate::domain::value::ref_data::RefData; +use crate::errors::DspMetaError; + +#[derive(Debug, PartialEq)] +pub enum SpacialCoverage { + Geonames(RefData), +} + +impl TryFrom<&hcl::Block> for SpacialCoverage { + type Error = DspMetaError; + + fn try_from(block: &hcl::Block) -> Result { + if block.identifier.as_str() != "spacial_coverage" { + let msg = format!( + "The passed block is not named correctly. Expected 'spacial_coverage', however got '{}' instead.", + block.identifier.as_str() + ); + return Err(DspMetaError::CreateValueObject(msg)); + } + + if block.labels.len() != 1 { + return Err(DspMetaError::CreateValueObject("The passed number of block labels is not correct. Expected '1', namely 'reference data type' (e.g., 'geonames').".to_string())); + } + + let reference_data_type = block.labels.first().ok_or_else(|| { + DspMetaError::CreateValueObject( + "The passed spacial_coverage block is missing the reference data type label." + .to_string(), + ) + })?; + + let attributes: Vec<&hcl::Attribute> = block.body.attributes().collect(); + + match reference_data_type.as_str() { + "geonames" => { + let ref_data = RefData::try_from(attributes)?; + Ok(SpacialCoverage::Geonames(ref_data)) + } + _ => { + Err(DspMetaError::CreateValueObject("The passed spacial_coverage block is missing the correct reference data type label: 'geonames'.".to_string())) + } + } + } +} + +#[cfg(test)] +mod tests { + use crate::domain::value::ref_data::RefData; + use crate::domain::value::spatial_coverage::SpacialCoverage; + + #[test] + fn test_try_from_block_with_geonames() { + let block = hcl::block!( + spacial_coverage geonames { + ref_id = "1234" + description = "A description" + url = "https://geonames.org/1234" + } + ); + + let input = SpacialCoverage::try_from(&block).unwrap(); + let expected = SpacialCoverage::Geonames(RefData { + ref_id: "1234".to_string(), + description: "A description".to_string(), + url: "https://geonames.org/1234".parse().unwrap(), + }); + + assert_eq!(input, expected); + } +}