From 22cf2376ad19c6a921415eca65aaacc4b785640b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Tue, 3 Sep 2024 09:36:38 +0200 Subject: [PATCH] Remove unused dsp-domain crate --- Cargo.lock | 29 +- Cargo.toml | 2 +- data/add_status.py | 79 ----- data/dokubib.hcl | 170 ----------- data/hdm.hcl | 173 ----------- data/incunabula.hcl | 256 ---------------- dsp-domain/src/error.rs | 16 - dsp-domain/src/lib.rs | 3 - dsp-domain/src/metadata/entity/dataset.rs | 32 -- dsp-domain/src/metadata/entity/grant.rs | 18 -- dsp-domain/src/metadata/entity/mod.rs | 6 - .../src/metadata/entity/organization.rs | 8 - dsp-domain/src/metadata/entity/person.rs | 8 - dsp-domain/src/metadata/entity/project.rs | 35 --- .../src/metadata/entity/project_metadata.rs | 19 -- dsp-domain/src/metadata/mod.rs | 2 - dsp-domain/src/metadata/value/abstract.rs | 26 -- dsp-domain/src/metadata/value/access.rs | 27 -- .../src/metadata/value/alternative_name.rs | 25 -- dsp-domain/src/metadata/value/attribution.rs | 28 -- dsp-domain/src/metadata/value/data_type.rs | 29 -- dsp-domain/src/metadata/value/description.rs | 26 -- dsp-domain/src/metadata/value/discipline.rs | 23 -- dsp-domain/src/metadata/value/funder.rs | 2 - dsp-domain/src/metadata/value/identifier.rs | 19 -- dsp-domain/src/metadata/value/iso_code.rs | 71 ----- dsp-domain/src/metadata/value/keyword.rs | 15 - .../src/metadata/value/lang_text_data.rs | 9 - dsp-domain/src/metadata/value/language.rs | 26 -- dsp-domain/src/metadata/value/license.rs | 58 ---- dsp-domain/src/metadata/value/mod.rs | 72 ----- dsp-domain/src/metadata/value/publication.rs | 8 - dsp-domain/src/metadata/value/ref_data.rs | 8 - .../src/metadata/value/simple_text_data.rs | 12 - .../src/metadata/value/spatial_coverage.rs | 6 - dsp-domain/src/metadata/value/status.rs | 25 -- .../src/metadata/value/temporal_coverage.rs | 9 - dsp-domain/src/metadata/value/url.rs | 39 --- dsp-domain/src/metadata/value/version.rs | 4 - dsp-domain/src/ontology/mod.rs | 236 --------------- dsp-meta/Cargo.toml | 5 - .../src/api/convert/hcl/dsp_meta_error.rs | 7 - .../dataset/extracted_dataset_attributes.rs | 253 ---------------- .../dataset/extracted_dataset_blocks.rs | 101 ------- .../src/api/convert/hcl/entity/dataset/mod.rs | 210 ------------- .../hcl/entity/grant/extracted_grant.rs | 228 -------------- .../src/api/convert/hcl/entity/grant/mod.rs | 113 ------- dsp-meta/src/api/convert/hcl/entity/mod.rs | 3 - .../project/extracted_project_attributes.rs | 211 ------------- .../project/extracted_project_blocks.rs | 271 ----------------- .../src/api/convert/hcl/entity/project/mod.rs | 281 ------------------ dsp-meta/src/api/convert/hcl/hcl_attribute.rs | 2 - dsp-meta/src/api/convert/hcl/hcl_block.rs | 1 - dsp-meta/src/api/convert/hcl/hcl_body.rs | 1 - dsp-meta/src/api/convert/hcl/mod.rs | 7 - .../src/api/convert/hcl/project_metadata.rs | 121 -------- .../src/api/convert/hcl/value/abstract.rs | 77 ----- .../api/convert/hcl/value/alternative_name.rs | 74 ----- .../src/api/convert/hcl/value/attribution.rs | 130 -------- .../src/api/convert/hcl/value/description.rs | 77 ----- .../src/api/convert/hcl/value/discipline.rs | 107 ------- dsp-meta/src/api/convert/hcl/value/keyword.rs | 76 ----- .../api/convert/hcl/value/lang_text_data.rs | 29 -- .../src/api/convert/hcl/value/language.rs | 78 ----- dsp-meta/src/api/convert/hcl/value/license.rs | 170 ----------- dsp-meta/src/api/convert/hcl/value/mod.rs | 16 - .../src/api/convert/hcl/value/publication.rs | 66 ---- .../src/api/convert/hcl/value/ref_data.rs | 88 ------ .../api/convert/hcl/value/simple_text_data.rs | 85 ------ .../api/convert/hcl/value/spatial_coverage.rs | 71 ----- .../convert/hcl/value/temporal_coverage.rs | 86 ------ dsp-meta/src/api/convert/hcl/value/url.rs | 121 -------- dsp-meta/src/api/convert/hcl/value/version.rs | 45 --- dsp-meta/src/api/convert/mod.rs | 2 - dsp-meta/src/api/convert/rdf/constance.rs | 7 - dsp-meta/src/api/convert/rdf/error.rs | 7 - dsp-meta/src/api/convert/rdf/mod.rs | 6 - dsp-meta/src/api/convert/rdf/project.rs | 39 --- .../src/api/convert/rdf/project_metadata.rs | 147 --------- dsp-meta/src/api/convert/rdf/triple.rs | 6 - dsp-meta/src/api/convert/rdf/value/mod.rs | 1 - .../src/api/convert/rdf/value/shortcode.rs | 26 -- dsp-meta/src/error.rs | 10 - dsp-meta/tests/common/mod.rs | 12 - dsp-meta/tests/integration_test.rs | 41 --- 85 files changed, 29 insertions(+), 5145 deletions(-) delete mode 100644 data/add_status.py delete mode 100644 data/dokubib.hcl delete mode 100644 data/hdm.hcl delete mode 100644 data/incunabula.hcl delete mode 100644 dsp-domain/src/error.rs delete mode 100644 dsp-domain/src/lib.rs delete mode 100644 dsp-domain/src/metadata/entity/dataset.rs delete mode 100644 dsp-domain/src/metadata/entity/grant.rs delete mode 100644 dsp-domain/src/metadata/entity/mod.rs delete mode 100644 dsp-domain/src/metadata/entity/organization.rs delete mode 100644 dsp-domain/src/metadata/entity/person.rs delete mode 100644 dsp-domain/src/metadata/entity/project.rs delete mode 100644 dsp-domain/src/metadata/entity/project_metadata.rs delete mode 100644 dsp-domain/src/metadata/mod.rs delete mode 100644 dsp-domain/src/metadata/value/abstract.rs delete mode 100644 dsp-domain/src/metadata/value/access.rs delete mode 100644 dsp-domain/src/metadata/value/alternative_name.rs delete mode 100644 dsp-domain/src/metadata/value/attribution.rs delete mode 100644 dsp-domain/src/metadata/value/data_type.rs delete mode 100644 dsp-domain/src/metadata/value/description.rs delete mode 100644 dsp-domain/src/metadata/value/discipline.rs delete mode 100644 dsp-domain/src/metadata/value/funder.rs delete mode 100644 dsp-domain/src/metadata/value/identifier.rs delete mode 100644 dsp-domain/src/metadata/value/iso_code.rs delete mode 100644 dsp-domain/src/metadata/value/keyword.rs delete mode 100644 dsp-domain/src/metadata/value/lang_text_data.rs delete mode 100644 dsp-domain/src/metadata/value/language.rs delete mode 100644 dsp-domain/src/metadata/value/license.rs delete mode 100644 dsp-domain/src/metadata/value/mod.rs delete mode 100644 dsp-domain/src/metadata/value/publication.rs delete mode 100644 dsp-domain/src/metadata/value/ref_data.rs delete mode 100644 dsp-domain/src/metadata/value/simple_text_data.rs delete mode 100644 dsp-domain/src/metadata/value/spatial_coverage.rs delete mode 100644 dsp-domain/src/metadata/value/status.rs delete mode 100644 dsp-domain/src/metadata/value/temporal_coverage.rs delete mode 100644 dsp-domain/src/metadata/value/url.rs delete mode 100644 dsp-domain/src/metadata/value/version.rs delete mode 100644 dsp-domain/src/ontology/mod.rs delete mode 100644 dsp-meta/src/api/convert/hcl/dsp_meta_error.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/dataset/extracted_dataset_attributes.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/dataset/extracted_dataset_blocks.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/dataset/mod.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/grant/extracted_grant.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/grant/mod.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/mod.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/project/extracted_project_attributes.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/project/extracted_project_blocks.rs delete mode 100644 dsp-meta/src/api/convert/hcl/entity/project/mod.rs delete mode 100644 dsp-meta/src/api/convert/hcl/hcl_attribute.rs delete mode 100644 dsp-meta/src/api/convert/hcl/hcl_block.rs delete mode 100644 dsp-meta/src/api/convert/hcl/hcl_body.rs delete mode 100644 dsp-meta/src/api/convert/hcl/mod.rs delete mode 100644 dsp-meta/src/api/convert/hcl/project_metadata.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/abstract.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/alternative_name.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/attribution.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/description.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/discipline.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/keyword.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/lang_text_data.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/language.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/license.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/mod.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/publication.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/ref_data.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/simple_text_data.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/spatial_coverage.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/temporal_coverage.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/url.rs delete mode 100644 dsp-meta/src/api/convert/hcl/value/version.rs delete mode 100644 dsp-meta/src/api/convert/rdf/constance.rs delete mode 100644 dsp-meta/src/api/convert/rdf/error.rs delete mode 100644 dsp-meta/src/api/convert/rdf/mod.rs delete mode 100644 dsp-meta/src/api/convert/rdf/project.rs delete mode 100644 dsp-meta/src/api/convert/rdf/project_metadata.rs delete mode 100644 dsp-meta/src/api/convert/rdf/triple.rs delete mode 100644 dsp-meta/src/api/convert/rdf/value/mod.rs delete mode 100644 dsp-meta/src/api/convert/rdf/value/shortcode.rs delete mode 100644 dsp-meta/tests/common/mod.rs delete mode 100644 dsp-meta/tests/integration_test.rs diff --git a/Cargo.lock b/Cargo.lock index 08a3f5f7..abeaaffe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -562,6 +562,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] +<<<<<<< HEAD name = "dsp-domain" version = "2.2.0" dependencies = [ @@ -586,6 +587,33 @@ dependencies = [ ] [[package]] +||||||| parent of d2944c9 (Remove unused dsp-domain crate) +name = "dsp-domain" +version = "2.1.0" +dependencies = [ + "anyhow", + "assert_cmd", + "axum", + "axum-macros", + "clap", + "hcl-rs", + "hyper", + "log", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower", + "tower-http", + "tracing", + "tracing-subscriber", + "tracing-test", + "url", +] + +[[package]] +======= +>>>>>>> d2944c9 (Remove unused dsp-domain crate) name = "dsp-meta" version = "2.2.0" dependencies = [ @@ -597,7 +625,6 @@ dependencies = [ "chrono", "clap", "config", - "dsp-domain", "fake", "hcl-rs", "http-body-util", diff --git a/Cargo.toml b/Cargo.toml index cbe1275f..513853dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["dsp-domain", "dsp-meta", "dsp-meta-cmd", "serde-rdf"] +members = ["dsp-meta", "dsp-meta-cmd", "serde-rdf"] resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/data/add_status.py b/data/add_status.py deleted file mode 100644 index 78f690c6..00000000 --- a/data/add_status.py +++ /dev/null @@ -1,79 +0,0 @@ -import os -import json - -# List of ongoing shortcodes -ongoing_shortcodes = [ - "0102", - "0103", - "0105", - "0106", - "0107", - "0112", - "0114", - "0116", - "0118", - "0119", - "0121", - "0801", - "0804", - "0805", - "0806", - "0807", - "080C", - "080E", - "0810", - "0812", - "0813", - "0816", - "081B", - "0820", - "0827", - "082B", - "082C", - "0836", - "0838", - "083A", - "083B", - "083C", - "083E", - "0843", - "0844", - "0849", - "084A", - "084E" -] - -def update_json_files(folder_path): - print(ongoing_shortcodes) - # Iterate through all files in the given folder - for filename in os.listdir(folder_path): - # Check if the file is a JSON file - if filename.endswith(".json"): - file_path = os.path.join(folder_path, filename) - - # Read the JSON file - with open(file_path, 'r', encoding='utf-8') as file: - data = json.load(file) - - # Check if the "project" and "shortcode" keys exist - if "project" in data and "shortcode" in data["project"]: - shortcode = data["project"]["shortcode"] - - # Determine the status based on the shortcode - print (shortcode) - print (shortcode in ongoing_shortcodes) - if shortcode in ongoing_shortcodes: - status = "ongoing" - else: - status = "finished" - - # Add or update the "status" property - data["project"]["status"] = status - - # Write the updated JSON back to the file - with open(file_path, 'w', encoding='utf-8') as file: - json.dump(data, file, indent=4, ensure_ascii=False) - else: - print(f"File {filename} does not contain the expected structure.") - -update_json_files('./json/') \ No newline at end of file diff --git a/data/dokubib.hcl b/data/dokubib.hcl deleted file mode 100644 index 72a5adb7..00000000 --- a/data/dokubib.hcl +++ /dev/null @@ -1,170 +0,0 @@ -version = 1 - -project { - id = "http://ns.dasch.swiss/repository#dsp-0804-project" - created_at = 1630601300976368000 - created_by = "dsp-metadata-gui" - shortcode = "0804" - name = "Bilddatenbank Bibliothek St. Moritz" - - teaser_text = "Bibliothek St. Moritz Dokumentation is the local history archive of the community of St. Moritz, Switzerland." - - description { - en = "Bibliothek St. Moritz Dokumentation is the local history archive of the community of St. Moritz, Switzerland. It’s collection contains publications, manuscripts and audiovisual documents of the touristic development of St. Moritz" - } - - url { - href = "https://data.dasch.swiss/dokubib/" - label = "Project Website" - } - - how_to_cite = "Dokumentationsbibliothek St. Moritz" - start_date = "2021-01-01" - end_date = "2021-12-31" - - status = "Ongoing" - - keyword { - en = "local history" - de = "Lokalgeschichte" - } - keyword { - en = "regional history" - de = "Regionalgeschichte" - } - keyword { - en = "tourism" - de = "Tourismus" - } - keyword { - en = "St. Moritz" - de = "St. Moritz" - } - keyword { - en = "Switzerland" - de = "Schweiz" - } - - discipline skos { - ref_id = "https://skos.um.es/unesco6/5501" - description = "Local history" - url = "https://skos.um.es/unesco6/5501" - } - - spatial_coverage geonames { - ref_id = "https://www.geonames.org/2658822" - description = "St. Moritz" - url = "https://www.geonames.org/2658822" - } - temporal_coverage chronontology { - ref_id = "https://chronontology.dainst.org/period/INtagfT8h7Fs" - description = "20th and 21st Centuries" - url = "https://chronontology.dainst.org/period/INtagfT8h7Fs" - } - temporal_coverage chronontology { - ref_id = "https://chronontology.dainst.org/period/kqORhO4TGm4n" - description = "20th Century (1900 - 1999)" - url = "https://chronontology.dainst.org/period/kqORhO4TGm4n" - } - - publication { - text = "Bibliothek St. Moritz Dokumentation" - } - - // reference to person or organization (0-1) - contact_point = "gemeinde_st_moritz" - - // reference to datasets (1-n) - datasets = ["http://ns.dasch.swiss/repository#dsp-0804-dataset-000"] - - // reference to grants (0-n) - grants = ["http://ns.dasch.swiss/repository#dsp-0804-grant-000"] -} - -dataset { - id = "http://ns.dasch.swiss/repository#dsp-0804-dataset-000" - created_at = 1630601300976368000 - created_by = "dsp-metadata-gui" - title = "Dokumentationsbibliothek St. Moritz Bilddatenbank" - how_to_cite = "Dokumentationsbibliothek St. Moritz" - status = "Ongoing" - access_conditions = "Restricted" - date_published = 1630601300976368000 - type_of_data = ["Image", "Text"] - - abstract { - en = "Bilddatenbank makes accessible the collection of historic photographs and other graphical representation of St. Moritz Dokumentationsbibliothek" - } - - license { - type = "creative_commons" - href = "https://creativecommons.org/licenses/by-nc/4.0" - date = "2021-09-02" - label = "CC BY-NC 4.0" - } - - language { - de = "Deutsch" - } - language { - en = "German" - } - language { - fr = "Allemand" - } - - attribution { - agent = "http://ns.dasch.swiss/repository#dsp-0804-organization-001" - roles = [ - "Creator", - "Publisher" - ] - } -} - -dmp { - available = false -} - -grant { - id = "http://ns.dasch.swiss/repository#dsp-0804-grant-000" - created_at = 1630601300976368000 - created_by = "dsp-metadata-gui" - type = "Funding" - name = "Ordinary Budget" - funders = ["http://ns.dasch.swiss/repository#dsp-0804-organization-000"] // reference to person or organization -} - -organization { - id = "http://ns.dasch.swiss/repository#dsp-0804-organization-000" - created_at = "1630601301506212000" - created_by = "dsp-metadata-gui" - name = "Gemeinde St. Moritz" - - address { - street = "" - postal_code = "7500" - locality = "St. Moritz" - country = "Switzerland" - } -} - -organization "biblio_stmoritz" { - id = "http://ns.dasch.swiss/repository#dsp-0804-organization-001" - created_at = "1630601301561696000" - created_by = "dsp-metadata-gui" - email = "doku@biblio-stmoritz.ch" - name = "Dokumentationsbibliothek St. Moritz" - - url { - href = "https://www.biblio-stmoritz.ch" - label = "www.biblio-stmoritz.ch" - } - - address { - street = "Plazza da Scoula 14" - postal_code = "7500" - locality = "St. Moritz" - country = "Switzerland" - } -} diff --git a/data/hdm.hcl b/data/hdm.hcl deleted file mode 100644 index d4f103bb..00000000 --- a/data/hdm.hcl +++ /dev/null @@ -1,173 +0,0 @@ -version = 1 - -project { - id = "http://ns.dasch.swiss/repository#dsp-081C-project" - created_at = 1630601274523025000 - created_by = "dsp-metadata-gui" - shortcode = "081C" - name = "Hôtel de Musique Bern" - - teaser_text = "The database documents the different kinds of spectacles such as theatre plays, operas, ballets, or concerts that took place in the Hôtel de Musique in Bern between 1766 and 1905." - - description { - en = "The database documents the events that took place in the Hôtel de Musique in Bern between 1766 and 1905. The repertoire was constituted by different kinds of spectacles like theatre plays, operas, ballets, concerts, dance parties, acrobatic performances, conferences or magicians. The list reconstructs the lifely and colourful theatre culture of Bern in the 19th Century." - } - - url { - href = "https://admin.dasch.swiss/project/081C" - label = "Discover Project Data" - } - - how_to_cite = "HdM-Bern" - start_date = "2009-04-01" - end_date = "2015-04-01" - - status = "Finished" - - keyword { - en = "19 Century" - } - keyword { - de = "Bern" - } - keyword { - en = "Concert" - } - keyword { - en = "Music" - } - keyword { - en = "Musicology" - } - keyword { - en = "Opera" - } - keyword { - en = "Spectales" - } - keyword { - en = "Switzerland" - } - keyword { - en = "Theater history" - } - keyword { - en = "Theatre" - } - - discipline snf { - ref_id = "10302" - description = "Schweizer Geschichte" - url = "https://www.snf.ch/SiteCollectionDocuments/allg_disziplinenliste.pdf" - } - discipline snf { - ref_id = "10405" - description = "Musikologie" - url = "https://www.snf.ch/SiteCollectionDocuments/allg_disziplinenliste.pdf" - } - discipline snf { - ref_id = "10406" - description = "Theater-und Filmwissenschaften" - url = "https://www.snf.ch/SiteCollectionDocuments/allg_disziplinenliste.pdf" - } - discipline snf { - ref_id = "10604" - description = "Musik und Theater" - url = "https://www.snf.ch/SiteCollectionDocuments/allg_disziplinenliste.pdf" - } - - spatial_coverage geonames { - ref_id = "https://www.geonames.org/2661552" - description = "Bern" - url = "https://www.geonames.org/2661552" - } - - temporal_coverage periodo { - ref_id = "https://n2t.net/ark:/99152/p06c6g3pvr5" - description = "Under Mediation act, 1803-1814" - url = "https://n2t.net/ark:/99152/p06c6g3pvr5" - } - temporal_coverage periodo { - ref_id = "https://n2t.net/ark:/99152/p06c6g3p4cf" - description = "Sonderbund, 1845-1847" - url = "https://n2t.net/ark:/99152/p06c6g3p4cf" - } - temporal_coverage periodo { - ref_id = "https://n2t.net/ark:/99152/p06c6g364np" - description = "Helvetic Republic, 1798-1803" - url = "https://n2t.net/ark:/99152/p06c6g364np" - } - temporal_coverage text { - de = "1766-1905" - en = "1766-1905" - fr = "1766-1905" - } - datasets = ["http://ns.dasch.swiss/repository#dsp-081C-dataset-000"] - - // reference to grants (0-n) - grants = ["http://ns.dasch.swiss/repository#dsp-081C-grant-000"] -} - -dataset { - id = "http://ns.dasch.swiss/repository#dsp-081C-dataset-000" - created_at = 1630601285266958000 - created_by = "dsp-metadata-gui" - title = "Hôtel de Musique Bern" - how_to_cite = "HdM-Bern" - status = "Finished" - access_conditions = "Open" - date_published = 1630601285266958000 - type_of_data = ["Text"] - - abstract { - en = "The database documents the events that took place in the Hôtel de Musique in Bern between 1766 and 1905. The repertoire was constituted by different kinds of spectacles like theatre plays, operas, ballets, concerts, dance parties, acrobatic performances, conferences or magicians. The list reconstructs the lifely and colourful theatre culture of Bern in the 19th Century." - } - - license { - type = "creative_commons" - href = "https://creativecommons.org/licenses/by-nc/4.0" - date = "2021-09-02" - label = "CC BY-NC 4.0" - } - - language { - de = "Deutsch" - en = "German" - fr = "Allemand" - } - - // reference to person or organization - attribution { - agent = "http://ns.dasch.swiss/repository#dsp-081C-organization-000" // reference to person or organization - roles = ["Author"] - } -} - -grant { - id = "http://ns.dasch.swiss/repository#dsp-081C-grant-000" - created_at = 1630601285796580000 - created_by = "dsp-metadata-gui" - type = "funding" - name = "Hôtel de Musique Bern" - funders = ["http://ns.dasch.swiss/repository#dsp-081C-organization-000"] -} - -organization { - id = "http://ns.dasch.swiss/repository#dsp-081C-organization-000" - created_at = 1630601285796580000 - created_by = "dsp-metadata-gui" - name = "Institut für Musikwissenschaft der Universität Bern" - email = "urchueguia@musik.unibe.ch" - - url { - href = "https://www.musik.unibe.ch" - label = "https://www.musik.unibe.ch" - } - - address { - street = "Mittelstr. 43" - postal_code = "3011" - locality = "Bern" - country = "Switzerland" - } -} diff --git a/data/incunabula.hcl b/data/incunabula.hcl deleted file mode 100644 index 549d8710..00000000 --- a/data/incunabula.hcl +++ /dev/null @@ -1,256 +0,0 @@ -version = 1 - -project { - id = "http://ns.dasch.swiss/repository#dsp-0803-project" - created_at = 1637624150548721000 - created_by = "dsp-metadata-gui" - shortcode = "0803" - name = "Die Bilderfolgen der Basler Frühdrucke: Spätmittelalterliche Didaxe als Bild-Text-Lektüre" - - alternative_name { - en = "Incunabula" - } - - teaser_text = "An art-scientific monograph of the richly illustrated early prints in Basel - the most important center of early letterpress printing in the territory of present-day Switzerland." - - description { - de = "Eine kunstwissenschaftliche Monographie der reich bebilderten Frühdrucke in Basel - dem wichtigsten Zentrum des frühen Buchdrucks auf dem Gebiet der heutigen Schweiz - wird im vorliegenden Projekt erstmals seit über einem Jahrhundert ins Auge gefasst. Im Zentrum stehen 18 Werke aus vier verschiedenen Offizinen, welche insgesamt über 1000 Holzschnitte enthalten, die bedeutendsten überlieferten Basler Bilderfolgen des Spätmittelalters nach den massiven Zerstörungen im Zuge der Reformation. Bei den Texten handelt es sich fast ausschliesslich um deutsche und lateinische Kompilationen religiösen, didaktischen Inhalts, darunter viele zeitgenössische und in Basel entstandene, neben Übersetzungen des 15. Jahrhunderts und vollständig überarbeiteten Ausgaben bereits verbreiteter Werke. Äusserst erfolgreiche Bücher wie das Narrenschiff oder der Heilsspiegel stehen neben kaum bekannten wie den seelsorgerischen Schriften des Kartäusers Ludwig Moser und des Franziskaners Johannes Meder. Die Analyse eines umfassenden Corpus bebilderter Frühdrucke fehlt in der neueren Forschung, welche sich bezüglich der Basler Produktion vorwiegend der Untersuchung der Produzentenkreise gewidmet, die Bilder dagegen - mit Ausnahme des Narrenschiffs - wenig beachtet hat. Sehr heterogen ist auch die Erforschung der Texte, von denen ein grosser Teil unediert geblieben ist, von anderen wiederum existieren ausführlich kommentierte Faksimileausgaben. Die bisherige Bild-Text-Forschung hat sich auf das Narrenschiff fokussiert.Neben der Quellenanalyse der Bilder und Texte strebt das Projekt eine umfassende Untersuchung der Bild-Text-Bezüge unter Berücksichtigung rezeptionsästethischer Fragestellungen an. Gefragt wird nach der Funktion der Bilder für die spätmittelalterlichen visuellen und auditiven Rezipienten. Dabei wird davon ausgegangen, dass es sich bei unseren Frühdrucken ausnahmslos um kalkulierte Bild-Text-Kompilationen handelt, welche einen reflektierten und kreativen Umgang ihrer Produzenten mit den drucktechnischen Möglichkeiten des neuen Mediums voraussetzen, wie z.B. mit der Möglichkeit der vielfältigen Kontextualisierung von Bildern. Die Analyse der Bild- und Textquellen liefert eine umfassende Fallstudie zum Medienwechsel zwischen Handschrift und Frühdruck, diejenige der Bild-Text-Bezüge im Spannungsfeld zwischen mündlicher Tradierung und schriftlicher Fixierung religiöser Didaxe eine Fallstudie zur spätmittelalterlichen Rezeptionsforschung.Methodisch knüpft das Projekt an rezeptionsästhetische Konzepte und Studien der jüngeren literaturwissenschaftlichen Forschung an, welche mit ikonographischen Analysen kombiniert werden. Durch diese Erweiterung textzentrierter methodischer Ansätze treten die Texte in Bezug auf die Bilder nicht mehr als übergeordnete, unabhängige Einheiten in den Blick, sondern die Konstruktion des Werksinnes erscheint im Wechselspiel der Medien. Der traditionelle Begriff der Buchillustration wird dadurch grundlegend revidiert.Neben mehreren Aufsätzen und einer Tagung sind eine Monographie in Buchform geplant, welche sich an die Fachwelt sowie an eine interessierte Öffentlichkeit wendet, ausserdem eine Internet-Publikation der Bild- und Textquellen im Rahmen der Zusammenarbeit mit der Basler Univeristätsbibliothek." - } - - url { - href = "https://admin.dasch.swiss/project/3ABR_2i8QYGSIDvmP9mlEw" - label = "Discover Project Data" - } - - how_to_cite = "Incunabula" - start_date = "2008-06-01" - end_date = "2012-08-31" - - status = "Finished" - - keyword { - de = "Basel" - } - keyword { - en = "Contextualisation of images" - } - keyword { - en = "Late Middle Ages" - } - keyword { - en = "Letterpress Printing" - } - - discipline snf { - ref_id = "10404" - description = "Visual arts and Art history" - url = "https://www.snf.ch/SiteCollectionDocuments/allg_disziplinenliste.pdf" - } - - publication { - text = "Graf Kathrin (2011), Klerikersatiren in Bild und Text. Zur Kompilationstechnik im Narrenschiff, in Krause Karin u. Schellewald Barbara (ed.), 205-227." - } - publication { - text = "Krause Karin u. Schellewald Barbara (ed.) (2011), Bild und Text im Mittelalter." - } - publication { - text = "Rosenthaler Lukas u. Ryf Patrick (2009), Incunabula Basilea: A Web 2.0 Application as Research Tool to Early Prints, in Archiving, 6, 175-177." - } - publication { - text = "Rosenthaler Lukas u. Schweizer Tobias (2012), SALSAH - eine webbasierte Forschungsplattform für die Geisteswissenschaften, in SAGW Bulletin, 32-33." - } - publication { - text = "Rosenthaler Lukas, Virtual Research Environments. A New Approach for Dealing with Digitized Sources in Research in Arts and Humanities, in Clivaz Claire (ed.), ebook auf der Plattform http://www.ppur.info/lire-demain.html, Lausanne, 661-670." - } - publication { - text = "Rosenthaler Lukas, Virtual Research Environments. A New Approach for Dealing with Digitized Sources in Research in Arts and Humanities, in Clivaz Claire (ed.), ebook auf der Plattform http://www.ppur.info/lire-demain.html, Lausanne, 661-670." - } - publication { - text = "Ryf Patrick u. Rosenthaler Lukas (2010), SALSAH: System for Annotation and Linkage of Sources in Arts and Humanities. Eine Web 2.0 Applikation zur wissenschaftlichen Betrachtung und Bearbeitung von historischem Bild- und Textmaterial, in Bienert Andreas u.a. (ed.), GFaI, Berlin, 123-126." - } - publication { - text = "Schmitt Lothar (2009), Sebastian Brant, Albrecht Dürer und das Narrenschiff, in Wolfenbütteler Abhandlungen zur Renaissanceforschung, 26, 347-412." - } - publication { - text = "Schmitt Lothar (2010), Mehr als Dürer. Die Ilustrationen in Friedrich Riederers \"Spiegel der wahren Rhetorik\", in Knape Joachim u. Luppold Stefanie (ed.), 191-216." - } - publication { - text = "Schweizer Tobias u. Rosenthaler Lukas (2011), SALSAH - eine virtuelle Forschungsumgebung für die Geisteswissenschaften, in Bienert Andreas u.a. (ed.), GFaI, Berlin, 147-153." - } - publication { - text = "Schweizer Tobias, Development of a Topographical Transcription Method, in Clivaz Claire u. a. (ed.), ebook, auf der Plattform http://www.ppur.info/lire-demain.html, Lausanne, 671-680." - } - datasets = ["http://ns.dasch.swiss/repository#dsp-0803-dataset-000"] - - grants = ["http://ns.dasch.swiss/repository#dsp-0803-grant-000"] -} - -dataset { - id = "http://ns.dasch.swiss/repository#dsp-0803-dataset-000" - created_at = 1637624150907146000 - created_by = "dsp-metadata-gui" - title = "Die Bilderfolgen der Basler Frühdrucke: Spätmittelalterliche Didaxe als Bild-Text-Lektüre" - how_to_cite = "dokubib" - status = "Finished" - access_conditions = "Open" - date_published = 1630601285266958000 - type_of_data = ["Text", "Image"] - - abstract { - en = "The interdisciplinary research project \"The image sequences of Basel's early prints: Late Medieval didactic didactics as an image-text reading\" combines a comprehensive art scholarly analysis of the links between images and texts in the illustrated incunabula in Basel with the digitization of the holdings of the University Library and the development of an electronic edition in the form of a new kind of Web-0.2 application. The project is carried out by Kunsthistorische Seminar of the University of Basel (Prof. Dr. B. Schellewald) and Digital Humanities Lab of the University of Basel (Prof. Dr. L. Rosenthaler). The core of the digital edition consists of around twenty richly illustrated early prints from four different Basel officers. Many of them appeared in several editions before 1500, some of them in German and Latin at almost the same time. It is an extraordinarily varied production; in addition to the Mirror of Salvation, there is a novel, the Melusine, the travelogues of Jean de Mandeville, some prayer and edification books, theological writings, Lent sermons, the lives of Saints Fridolin and Meinrad, the famous ship of fools and the knight of Thurn. The Internet publication makes the digitized corpus of these early prints usable for the scientific edition as well as for the exploration of images and texts through the possibilities of non-linear linking and commenting on the images and texts. Existing and emerging online editions can also be linked to it, which optimises the use of databases from other institutions with regard to our corpus." - } - - license { - type = "creative_commons" - href = "https://creativecommons.org/licenses/by-nc/4.0" - date = "2021-09-02" - label = "CC BY-NC 4.0" - } - - language { - de = "Deutsch" - en = "German" - fr = "Allemand" - } - - // reference to person or organization - attribution { - agent = "katrin_graf_lamei" - roles = ["Employee"] - } - // reference to person or organization - attribution { - agent = "barbara_schellewald" - roles = ["Applicant"] - } - // reference to person or organization - attribution { - agent = "lothar_schmidt" - roles = ["Employee"] - } - // reference to person or organization - attribution { - agent = "hannes_hug" - roles = ["Co-Applicant"] - } - // reference to person or organization - attribution { - agent = "lukas_rosenthaler" - roles = ["Co-Applicant"] - } -} - -grant { - id = "http://ns.dasch.swiss/repository#dsp-0803-grant-000" - created_at = "1637624150958979000" - created_by = "dsp-metadata-gui" - type = "Project funding" - name = "Project funding" - number = "120378" - funders = ["http://ns.dasch.swiss/repository#dsp-0803-organization-003"] // reference to person or organization (1-n) - - url { - href = "https://data.snf.ch/grants/grant/120378" - label = "https://data.snf.ch/grants/grant/120378" - } -} - -person "barbara_schellewald" { - id = "http://ns.dasch.swiss/repository#dsp-0803-person-000" - created_at = "1637624150958979000" - created_by = "dsp-metadata-gui" - - family_name { - text = "Schellewald" - } - given_name { - text = "Barbara" - } - // reference to organization (1-n) - affiliation = ["kunst_seminar_unibas"] -} - -person "hannes_hug" { - id = "http://ns.dasch.swiss/repository#dsp-0803-person-001" - created_at = "1637624150959055000" - created_by = "dsp-metadata-gui" - - family_name { - text = "Hug" - } - given_name { - text = "Hannes" - } - // reference to organization (1-n) - affiliation = ["ub_unibas"] -} - -person "lukas_rosenthaler" { - id = "http://ns.dasch.swiss/repository#dsp-0803-person-002" - created_at = "1637624150959124000" - created_by = "dsp-metadata-gui" - - family_name { - text = "Rosenthaler" - } - given_name { - text = "Lukas" - } - // reference to organization (1-n) - affiliation = ["dhlab_basel"] -} - -person "lothar_schmitt" { - id = "http://ns.dasch.swiss/repository#dsp-0803-person-003" - created_at = "1637624150959191000" - created_by = "dsp-metadata-gui" - - family_name { - text = "Schmitt" - } - given_name { - text = "Lothar" - } - - // reference to organization (1-n) - affiliation = ["dhlab_basel"] -} - -person "katrin_graf_lamei" { - id = "http://ns.dasch.swiss/repository#dsp-0803-person-004" - created_at = "1637624150959244000" - created_by = "dsp-metadata-gui" - - family_name { - text = "Graf" - } - family_name { - text = "Lamei" - } - given_name { - text = "Katrin" - } - - // reference to organization (1-n) - affiliation = ["dhlab_basel"] -} - -organization "kunst_seminar_unibas" { - id = "http://ns.dasch.swiss/repository#dsp-0803-organization-000" - name = "Kunsthistorisches Seminar Universität Basel" -} - -organization "ub_unibas" { - id = "http://ns.dasch.swiss/repository#dsp-0803-organization-001" - name = "Universität Basel Universitätsbibliothek Sekretariat" -} - -organization "dhlab_basel" { - id = "http://ns.dasch.swiss/repository#dsp-0803-organization-002" - name = "Digital Humanities Lab Philosophisch-Historische Fakultät Universität Basel" -} - -organization { - id = "http://ns.dasch.swiss/repository#dsp-0803-organization-003" - name = "Swiss National Science Foundation (SNSF)" -} diff --git a/dsp-domain/src/error.rs b/dsp-domain/src/error.rs deleted file mode 100644 index 9fe8891d..00000000 --- a/dsp-domain/src/error.rs +++ /dev/null @@ -1,16 +0,0 @@ -use thiserror::Error; - -/// Type alias for `Result` with default error `DspDomainError`. -/// -/// Can be used like `std::result::Result` as well. -pub type Result = std::result::Result; - -/// This error is raised when a domain entity or value fails creation -/// at runtime. -#[derive(Debug, Error)] -pub enum DspDomainError { - #[error("Error creating value object: `{0}`")] - CreateValueObject(String), - #[error("Error creating domain object.")] - CreateDomainObject(String), -} diff --git a/dsp-domain/src/lib.rs b/dsp-domain/src/lib.rs deleted file mode 100644 index d19c750d..00000000 --- a/dsp-domain/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod error; -pub mod metadata; -mod ontology; diff --git a/dsp-domain/src/metadata/entity/dataset.rs b/dsp-domain/src/metadata/entity/dataset.rs deleted file mode 100644 index 19eed3cd..00000000 --- a/dsp-domain/src/metadata/entity/dataset.rs +++ /dev/null @@ -1,32 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::access::Access; -use crate::metadata::value::attribution::Attribution; -use crate::metadata::value::data_type::DataType; -use crate::metadata::value::identifier::DatasetId; -use crate::metadata::value::language::Language; -use crate::metadata::value::license::License; -use crate::metadata::value::r#abstract::Abstract; -use crate::metadata::value::status::Status; -use crate::metadata::value::url::Url; -use crate::metadata::value::{CreatedAt, CreatedBy, DatePublished, HowToCite, Title}; - -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct Dataset { - pub id: DatasetId, // (1) - pub created_at: CreatedAt, // (1) - pub created_by: CreatedBy, // (1) - pub title: Title, // (1) - pub status: Status, // (1) - pub access_conditions: Access, // (1) - pub how_to_cite: HowToCite, // (1) - pub date_published: Option, // (0-1) - pub type_of_data: Vec, // (1-n) - pub alternative_titles: Vec, // (0-n) - pub abstracts: Vec<Abstract>, // (1-n) - pub licenses: Vec<License>, // (1-n) - pub languages: Vec<Language>, // (1-n) - pub attributions: Vec<Attribution>, // (1-n) - - pub urls: Vec<Url>, // (0-n) -} diff --git a/dsp-domain/src/metadata/entity/grant.rs b/dsp-domain/src/metadata/entity/grant.rs deleted file mode 100644 index d1ce3e2b..00000000 --- a/dsp-domain/src/metadata/entity/grant.rs +++ /dev/null @@ -1,18 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::funder::Funder; -use crate::metadata::value::identifier::GrantId; -use crate::metadata::value::url::Url; -use crate::metadata::value::{CreatedAt, CreatedBy, GrantNumber, GrantType, Name}; - -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct Grant { - pub id: GrantId, // (1) - pub created_at: CreatedAt, // (1) - pub created_by: CreatedBy, // (1) - pub type_of_grant: GrantType, // (1) - pub name: Option<Name>, // (0-1) - pub number: Option<GrantNumber>, // (0-1) - pub url: Option<Url>, // (0-1) - pub funders: Vec<Funder>, // (1-n) -} diff --git a/dsp-domain/src/metadata/entity/mod.rs b/dsp-domain/src/metadata/entity/mod.rs deleted file mode 100644 index ec828f8d..00000000 --- a/dsp-domain/src/metadata/entity/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod dataset; -pub mod grant; -mod organization; -mod person; -pub mod project; -pub mod project_metadata; diff --git a/dsp-domain/src/metadata/entity/organization.rs b/dsp-domain/src/metadata/entity/organization.rs deleted file mode 100644 index b4df1037..00000000 --- a/dsp-domain/src/metadata/entity/organization.rs +++ /dev/null @@ -1,8 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::identifier::OrganizationId; - -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct Organization { - pub id: OrganizationId, -} diff --git a/dsp-domain/src/metadata/entity/person.rs b/dsp-domain/src/metadata/entity/person.rs deleted file mode 100644 index 7f693ace..00000000 --- a/dsp-domain/src/metadata/entity/person.rs +++ /dev/null @@ -1,8 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::identifier::PersonId; - -#[derive(Debug, Clone, Default, PartialEq, Serialize)] -pub struct Person { - pub id: PersonId, -} diff --git a/dsp-domain/src/metadata/entity/project.rs b/dsp-domain/src/metadata/entity/project.rs deleted file mode 100644 index ecd8fdc7..00000000 --- a/dsp-domain/src/metadata/entity/project.rs +++ /dev/null @@ -1,35 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::alternative_name::AlternativeName; -use crate::metadata::value::description::Description; -use crate::metadata::value::discipline::Discipline; -use crate::metadata::value::identifier::{DatasetId, ProjectId}; -use crate::metadata::value::keyword::Keyword; -use crate::metadata::value::publication::Publication; -use crate::metadata::value::status::Status; -use crate::metadata::value::url::Url; -use crate::metadata::value::{ - ContactPoint, CreatedAt, CreatedBy, EndDate, HowToCite, Name, Shortcode, StartDate, TeaserText, -}; - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct Project { - pub id: ProjectId, - pub created_at: CreatedAt, - pub created_by: CreatedBy, - pub shortcode: Shortcode, - pub name: Name, - pub alternative_names: Vec<AlternativeName>, - pub teaser_text: TeaserText, - pub description: Description, - pub url: Url, - pub how_to_cite: HowToCite, - pub start_date: StartDate, - pub end_date: Option<EndDate>, - pub status: Status, - pub contact_point: Option<ContactPoint>, - pub keywords: Vec<Keyword>, - pub disciplines: Vec<Discipline>, - pub publications: Vec<Publication>, - pub datasets: Vec<DatasetId>, -} diff --git a/dsp-domain/src/metadata/entity/project_metadata.rs b/dsp-domain/src/metadata/entity/project_metadata.rs deleted file mode 100644 index 315dc729..00000000 --- a/dsp-domain/src/metadata/entity/project_metadata.rs +++ /dev/null @@ -1,19 +0,0 @@ -use serde::Serialize; - -use crate::metadata::entity::dataset::Dataset; -use crate::metadata::entity::grant::Grant; -use crate::metadata::entity::organization::Organization; -use crate::metadata::entity::person::Person; -use crate::metadata::entity::project::Project; -use crate::metadata::value::version::Version; - -/// The Metadata struct represents the metadata of a DSP project. -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct ProjectMetadata { - pub version: Version, - pub project: Project, - pub datasets: Vec<Dataset>, - pub grants: Vec<Grant>, - pub organizations: Vec<Organization>, - pub persons: Vec<Person>, -} diff --git a/dsp-domain/src/metadata/mod.rs b/dsp-domain/src/metadata/mod.rs deleted file mode 100644 index 8b5893d0..00000000 --- a/dsp-domain/src/metadata/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod entity; -pub mod value; diff --git a/dsp-domain/src/metadata/value/abstract.rs b/dsp-domain/src/metadata/value/abstract.rs deleted file mode 100644 index fbc57458..00000000 --- a/dsp-domain/src/metadata/value/abstract.rs +++ /dev/null @@ -1,26 +0,0 @@ -use std::collections::HashMap; - -use serde::Serialize; - -use crate::metadata::value::iso_code::IsoCode; -use crate::metadata::value::lang_text_data::LangTextData; - -/// A set of abstracts in different languages. -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct Abstract(pub HashMap<IsoCode, String>); - -impl Default for Abstract { - fn default() -> Self { - let mut map: HashMap<IsoCode, String> = HashMap::new(); - map.insert(IsoCode::DE, String::from("Die Default-Auszug.")); - map.insert(IsoCode::EN, String::from("The default abstract.")); - map.insert(IsoCode::FR, String::from("Le standard abstract.")); - Self(map) - } -} - -impl From<LangTextData> for Abstract { - fn from(value: LangTextData) -> Self { - Abstract(value.0) - } -} diff --git a/dsp-domain/src/metadata/value/access.rs b/dsp-domain/src/metadata/value/access.rs deleted file mode 100644 index 7158bcd4..00000000 --- a/dsp-domain/src/metadata/value/access.rs +++ /dev/null @@ -1,27 +0,0 @@ -use serde::Serialize; - -use crate::error::DspDomainError; - -#[derive(Clone, Debug, Default, PartialEq, Serialize)] -pub enum Access { - #[default] - Open, - Restricted, - Closed, -} - -impl TryFrom<String> for Access { - type Error = DspDomainError; - - fn try_from(value: String) -> Result<Self, Self::Error> { - match value.as_str() { - "Open" => Ok(Access::Open), - "Restricted" => Ok(Access::Restricted), - "Closed" => Ok(Access::Closed), - _ => Err(DspDomainError::CreateValueObject(format!( - "Creating Access failed because provided value '{}' is not allowed.", - value - ))), - } - } -} diff --git a/dsp-domain/src/metadata/value/alternative_name.rs b/dsp-domain/src/metadata/value/alternative_name.rs deleted file mode 100644 index f058935e..00000000 --- a/dsp-domain/src/metadata/value/alternative_name.rs +++ /dev/null @@ -1,25 +0,0 @@ -use std::collections::HashMap; - -use serde::Serialize; - -use crate::metadata::value::iso_code::IsoCode; -use crate::metadata::value::lang_text_data::LangTextData; - -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct AlternativeName(pub HashMap<IsoCode, String>); - -impl Default for AlternativeName { - fn default() -> Self { - let mut map: HashMap<IsoCode, String> = HashMap::new(); - map.insert(IsoCode::DE, String::from("Der Default AlternativeName.")); - map.insert(IsoCode::EN, String::from("The default AlternativeName.")); - map.insert(IsoCode::FR, String::from("Le default AlternativeName.")); - Self(map) - } -} - -impl From<LangTextData> for AlternativeName { - fn from(value: LangTextData) -> Self { - AlternativeName(value.0) - } -} diff --git a/dsp-domain/src/metadata/value/attribution.rs b/dsp-domain/src/metadata/value/attribution.rs deleted file mode 100644 index af7ffe1d..00000000 --- a/dsp-domain/src/metadata/value/attribution.rs +++ /dev/null @@ -1,28 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::identifier::AgentId; - -/// Represents an HCL block which consists of attribute keys and a value expressions. -/// -/// In HCL syntax this is represented as: -/// -/// ```hcl -/// attribution { -/// agent = "identifier of the agent" -/// roles = ["role1", "role2"] -/// } -/// ``` -#[derive(Clone, Debug, PartialEq, Eq, Serialize)] -pub struct Attribution { - pub agent: AgentId, - pub roles: Vec<String>, -} - -impl Default for Attribution { - fn default() -> Self { - Attribution { - agent: AgentId("Default agent ID".to_string()), - roles: vec!["role1".to_string(), "role2".to_string()], - } - } -} diff --git a/dsp-domain/src/metadata/value/data_type.rs b/dsp-domain/src/metadata/value/data_type.rs deleted file mode 100644 index 5533ab44..00000000 --- a/dsp-domain/src/metadata/value/data_type.rs +++ /dev/null @@ -1,29 +0,0 @@ -use serde::Serialize; - -use crate::error::DspDomainError; - -#[derive(Clone, Debug, Default, PartialEq, Serialize)] -pub enum DataType { - #[default] - Text, - Image, - Audio, - Video, -} - -impl TryFrom<String> for DataType { - type Error = DspDomainError; - - fn try_from(value: String) -> Result<Self, Self::Error> { - match value.as_str() { - "Text" => Ok(DataType::Text), - "Image" => Ok(DataType::Image), - "Audio" => Ok(DataType::Audio), - "Video" => Ok(DataType::Video), - _ => Err(DspDomainError::CreateValueObject(format!( - "Creating Status failed because provided value '{}' is not allowed.", - value - ))), - } - } -} diff --git a/dsp-domain/src/metadata/value/description.rs b/dsp-domain/src/metadata/value/description.rs deleted file mode 100644 index 48fed13b..00000000 --- a/dsp-domain/src/metadata/value/description.rs +++ /dev/null @@ -1,26 +0,0 @@ -use std::collections::HashMap; - -use serde::Serialize; - -use crate::metadata::value::iso_code::IsoCode; -use crate::metadata::value::lang_text_data::LangTextData; - -/// A set of descriptions in different languages. -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct Description(pub HashMap<IsoCode, String>); - -impl Default for Description { - fn default() -> Self { - Description(HashMap::from_iter([ - (IsoCode::DE, String::from("Die Default-Beschreibung.")), - (IsoCode::EN, String::from("The default description.")), - (IsoCode::FR, String::from("Le standard description.")), - ])) - } -} - -impl From<LangTextData> for Description { - fn from(value: LangTextData) -> Self { - Description(value.0) - } -} diff --git a/dsp-domain/src/metadata/value/discipline.rs b/dsp-domain/src/metadata/value/discipline.rs deleted file mode 100644 index f14e37ec..00000000 --- a/dsp-domain/src/metadata/value/discipline.rs +++ /dev/null @@ -1,23 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::lang_text_data::LangTextData; -use crate::metadata::value::ref_data::RefData; - -/// The discipline of a project can be defined in two ways: -/// 1. A reference to a discipline defined in an external reference system (e.g. SNF or SKOS) -/// 2. A text description of the discipline -/// -/// Example: -/// ```hcl -/// discipline skos { -/// ref_id = "https://skos.um.es/unesco6/5501" -/// description = "Local history" -/// url = "https://skos.um.es/unesco6/5501" -/// } -/// ``` -#[derive(Debug, Clone, PartialEq, Serialize)] -pub enum Discipline { - Skos(RefData), - Snf(RefData), - Text(LangTextData), -} diff --git a/dsp-domain/src/metadata/value/funder.rs b/dsp-domain/src/metadata/value/funder.rs deleted file mode 100644 index b76c2e54..00000000 --- a/dsp-domain/src/metadata/value/funder.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize)] -pub struct Funder(pub String); diff --git a/dsp-domain/src/metadata/value/identifier.rs b/dsp-domain/src/metadata/value/identifier.rs deleted file mode 100644 index f5ca5070..00000000 --- a/dsp-domain/src/metadata/value/identifier.rs +++ /dev/null @@ -1,19 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize)] -pub struct ProjectId(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize)] -pub struct DatasetId(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize)] -pub struct GrantId(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize)] -pub struct OrganizationId(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize)] -pub struct PersonId(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize)] -pub struct AgentId(pub String); diff --git a/dsp-domain/src/metadata/value/iso_code.rs b/dsp-domain/src/metadata/value/iso_code.rs deleted file mode 100644 index 216812d4..00000000 --- a/dsp-domain/src/metadata/value/iso_code.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::fmt::{Display, Formatter}; - -use serde::Serialize; - -use crate::error::DspDomainError; - -/// Language codes according to ISO 639-1 -/// Not an exhaustive list. -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize)] -#[serde(rename_all(serialize = "lowercase"))] -pub enum IsoCode { - #[default] - DE, // German - EN, // English - FR, // French - IT, // Italian - ES, // Spanish - PT, // Portuguese - NL, // Dutch - PL, // Polish - RU, // Russian - JA, // Japanese - ZH, // Chinese - AR, // Arabic - FA, // Persian -} - -impl Display for IsoCode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - IsoCode::DE => write!(f, "de"), - IsoCode::EN => write!(f, "en"), - IsoCode::FR => write!(f, "fr"), - IsoCode::IT => write!(f, "it"), - IsoCode::ES => write!(f, "es"), - IsoCode::PT => write!(f, "pt"), - IsoCode::NL => write!(f, "nl"), - IsoCode::PL => write!(f, "pl"), - IsoCode::RU => write!(f, "ru"), - IsoCode::JA => write!(f, "ja"), - IsoCode::ZH => write!(f, "zh"), - IsoCode::AR => write!(f, "ar"), - IsoCode::FA => write!(f, "fa"), - } - } -} - -impl TryFrom<&str> for IsoCode { - type Error = DspDomainError; - - fn try_from(value: &str) -> Result<Self, Self::Error> { - match value { - "de" => Ok(IsoCode::DE), - "en" => Ok(IsoCode::EN), - "fr" => Ok(IsoCode::FR), - "it" => Ok(IsoCode::IT), - "es" => Ok(IsoCode::ES), - "pt" => Ok(IsoCode::PT), - "nl" => Ok(IsoCode::NL), - "pl" => Ok(IsoCode::PL), - "ru" => Ok(IsoCode::RU), - "ja" => Ok(IsoCode::JA), - "zh" => Ok(IsoCode::ZH), - "ar" => Ok(IsoCode::AR), - "fa" => Ok(IsoCode::FA), - _ => Err(DspDomainError::CreateValueObject( - "Creating an IsoCode failed because provided value is not allowed.".to_string(), - )), - } - } -} diff --git a/dsp-domain/src/metadata/value/keyword.rs b/dsp-domain/src/metadata/value/keyword.rs deleted file mode 100644 index d63a4bb3..00000000 --- a/dsp-domain/src/metadata/value/keyword.rs +++ /dev/null @@ -1,15 +0,0 @@ -use std::collections::HashMap; - -use serde::Serialize; - -use crate::metadata::value::iso_code::IsoCode; -use crate::metadata::value::lang_text_data::LangTextData; - -#[derive(Clone, Debug, Default, PartialEq, Serialize)] -pub struct Keyword(pub HashMap<IsoCode, String>); - -impl From<LangTextData> for Keyword { - fn from(value: LangTextData) -> Self { - Keyword(value.0) - } -} diff --git a/dsp-domain/src/metadata/value/lang_text_data.rs b/dsp-domain/src/metadata/value/lang_text_data.rs deleted file mode 100644 index 8d83266b..00000000 --- a/dsp-domain/src/metadata/value/lang_text_data.rs +++ /dev/null @@ -1,9 +0,0 @@ -use std::collections::HashMap; - -use serde::Serialize; - -use crate::metadata::value::iso_code::IsoCode; - -/// Represents multiple strings in different languages. -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct LangTextData(pub HashMap<IsoCode, String>); diff --git a/dsp-domain/src/metadata/value/language.rs b/dsp-domain/src/metadata/value/language.rs deleted file mode 100644 index ea703fe6..00000000 --- a/dsp-domain/src/metadata/value/language.rs +++ /dev/null @@ -1,26 +0,0 @@ -use std::collections::HashMap; - -use serde::Serialize; - -use crate::metadata::value::iso_code::IsoCode; -use crate::metadata::value::lang_text_data::LangTextData; - -/// A set of abstracts in different languages. -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct Language(pub HashMap<IsoCode, String>); - -impl Default for Language { - fn default() -> Self { - let mut map: HashMap<IsoCode, String> = HashMap::new(); - map.insert(IsoCode::DE, String::from("Deutsch")); - map.insert(IsoCode::EN, String::from("German")); - map.insert(IsoCode::FR, String::from("Allemand")); - Self(map) - } -} - -impl From<LangTextData> for Language { - fn from(value: LangTextData) -> Self { - Language(value.0) - } -} diff --git a/dsp-domain/src/metadata/value/license.rs b/dsp-domain/src/metadata/value/license.rs deleted file mode 100644 index 19f0b4c5..00000000 --- a/dsp-domain/src/metadata/value/license.rs +++ /dev/null @@ -1,58 +0,0 @@ -use serde::Serialize; - -use crate::error::DspDomainError; -use crate::error::DspDomainError::CreateValueObject; - -/// Represents an HCL block which consists of attribute keys and a value expressions. -/// -/// In HCL syntax this is represented as: -/// -/// ```hcl -/// license { -/// type = "creative_commons" -/// href = "https://creativecommons.org/licenses/by-nc/4.0" -/// date = "2021-09-02" -/// label = "CC BY-NC 4.0" -/// } -/// ``` -#[derive(Clone, Debug, PartialEq, Eq, Serialize)] -pub struct License { - pub license_type: String, - pub href: url::Url, - pub date: String, - pub label: String, -} - -impl License { - pub fn new( - license_type: String, - url_string: String, - date: String, - label: String, - ) -> Result<Self, DspDomainError> { - let maybe_url = url::Url::try_from(url_string.as_str()); - match maybe_url { - Ok(href) => Ok(License { - license_type, - href, - date, - label, - }), - Err(_) => Err(CreateValueObject( - "Creating an UrlValue failed because provided value is not a valid URL." - .to_string(), - )), - } - } -} - -impl Default for License { - fn default() -> Self { - License { - license_type: "creative_commons".to_string(), - href: url::Url::try_from("https://default.xyz").unwrap(), - date: "2021-09-02".to_string(), - label: "Default license label".to_string(), - } - } -} diff --git a/dsp-domain/src/metadata/value/mod.rs b/dsp-domain/src/metadata/value/mod.rs deleted file mode 100644 index 6231d04e..00000000 --- a/dsp-domain/src/metadata/value/mod.rs +++ /dev/null @@ -1,72 +0,0 @@ -use serde::Serialize; - -pub mod r#abstract; -pub mod access; -pub mod alternative_name; -pub mod attribution; -pub mod data_type; -pub mod description; -pub mod discipline; -pub mod funder; -pub mod identifier; -pub mod iso_code; -pub mod keyword; -pub mod lang_text_data; -pub mod language; -pub mod license; -pub mod publication; -pub mod ref_data; -pub mod simple_text_data; -pub mod spatial_coverage; -pub mod status; -pub mod temporal_coverage; -pub mod url; -pub mod version; - -#[derive(Debug, Default, Clone, PartialEq)] -pub struct ID(String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct CreatedAt(pub u64); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct CreatedBy(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct Shortcode(pub String); - -impl Shortcode { - pub fn as_string(&self) -> String { - self.0.to_string() - } -} - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct Name(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct TeaserText(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct HowToCite(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct StartDate(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct EndDate(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct ContactPoint(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct Title(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct DatePublished(pub u64); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct GrantType(pub String); - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct GrantNumber(pub String); diff --git a/dsp-domain/src/metadata/value/publication.rs b/dsp-domain/src/metadata/value/publication.rs deleted file mode 100644 index 8f0d4cb2..00000000 --- a/dsp-domain/src/metadata/value/publication.rs +++ /dev/null @@ -1,8 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::simple_text_data::SimpleTextData; - -#[derive(Clone, Debug, PartialEq, Serialize)] -pub enum Publication { - SimpleText(SimpleTextData), -} diff --git a/dsp-domain/src/metadata/value/ref_data.rs b/dsp-domain/src/metadata/value/ref_data.rs deleted file mode 100644 index bb0e41c8..00000000 --- a/dsp-domain/src/metadata/value/ref_data.rs +++ /dev/null @@ -1,8 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Clone, PartialEq, Serialize)] -pub struct RefData { - pub ref_id: String, - pub description: String, - pub url: url::Url, -} diff --git a/dsp-domain/src/metadata/value/simple_text_data.rs b/dsp-domain/src/metadata/value/simple_text_data.rs deleted file mode 100644 index b0d27939..00000000 --- a/dsp-domain/src/metadata/value/simple_text_data.rs +++ /dev/null @@ -1,12 +0,0 @@ -use serde::Serialize; - -use crate::metadata::value::publication::Publication; - -#[derive(Clone, Debug, PartialEq, Serialize)] -pub struct SimpleTextData(pub String); - -impl SimpleTextData { - pub fn to_simple_text(&self) -> Publication { - Publication::SimpleText(self.to_owned()) - } -} diff --git a/dsp-domain/src/metadata/value/spatial_coverage.rs b/dsp-domain/src/metadata/value/spatial_coverage.rs deleted file mode 100644 index 62079cc5..00000000 --- a/dsp-domain/src/metadata/value/spatial_coverage.rs +++ /dev/null @@ -1,6 +0,0 @@ -use crate::metadata::value::ref_data::RefData; - -#[derive(Debug, PartialEq)] -pub enum SpatialCoverage { - Geonames(RefData), -} diff --git a/dsp-domain/src/metadata/value/status.rs b/dsp-domain/src/metadata/value/status.rs deleted file mode 100644 index a48873c5..00000000 --- a/dsp-domain/src/metadata/value/status.rs +++ /dev/null @@ -1,25 +0,0 @@ -use serde::Serialize; - -use crate::error::DspDomainError; - -#[derive(Clone, Debug, Default, PartialEq, Serialize)] -pub enum Status { - #[default] - Ongoing, - Finished, -} - -impl TryFrom<String> for Status { - type Error = DspDomainError; - - fn try_from(value: String) -> Result<Self, Self::Error> { - match value.as_str() { - "Ongoing" => Ok(Status::Ongoing), - "Finished" => Ok(Status::Finished), - _ => Err(DspDomainError::CreateValueObject(format!( - "Creating Status failed because provided value '{}' is not allowed.", - value - ))), - } - } -} diff --git a/dsp-domain/src/metadata/value/temporal_coverage.rs b/dsp-domain/src/metadata/value/temporal_coverage.rs deleted file mode 100644 index 436438ce..00000000 --- a/dsp-domain/src/metadata/value/temporal_coverage.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::metadata::value::lang_text_data::LangTextData; -use crate::metadata::value::ref_data::RefData; - -#[derive(Debug, PartialEq)] -pub enum TemporalCoverage { - Chronontology(RefData), - Periodo(RefData), - Text(LangTextData), -} diff --git a/dsp-domain/src/metadata/value/url.rs b/dsp-domain/src/metadata/value/url.rs deleted file mode 100644 index 8e05a0bd..00000000 --- a/dsp-domain/src/metadata/value/url.rs +++ /dev/null @@ -1,39 +0,0 @@ -use serde::Serialize; - -/// Represents an HCL block which consists of attribute keys and a value expressions. -/// -/// In HCL syntax this is represented as: -/// -/// ```hcl -/// url { -/// href = "https://www.google.com" -/// label = "text describing the link" -/// } -/// ``` -#[derive(Clone, Debug, PartialEq, Eq, Serialize)] -pub struct Url { - pub href: url::Url, - pub label: String, -} - -impl Url { - pub fn new(url_string: String, label: String) -> Result<Self, String> { - let maybe_url = url::Url::try_from(url_string.as_str()); - match maybe_url { - Ok(href) => Ok(Url { href, label }), - Err(_) => Err( - "Creating an UrlValue failed because provided value is not a valid URL." - .to_string(), - ), - } - } -} - -impl Default for Url { - fn default() -> Self { - Url { - href: url::Url::try_from("https://default.xyz").unwrap(), - label: "Default URL description".to_string(), - } - } -} diff --git a/dsp-domain/src/metadata/value/version.rs b/dsp-domain/src/metadata/value/version.rs deleted file mode 100644 index f08b832c..00000000 --- a/dsp-domain/src/metadata/value/version.rs +++ /dev/null @@ -1,4 +0,0 @@ -use serde::Serialize; - -#[derive(Debug, Default, Clone, PartialEq, Serialize)] -pub struct Version(pub u64); diff --git a/dsp-domain/src/ontology/mod.rs b/dsp-domain/src/ontology/mod.rs deleted file mode 100644 index 7a38e13e..00000000 --- a/dsp-domain/src/ontology/mod.rs +++ /dev/null @@ -1,236 +0,0 @@ -#![allow(dead_code)] - -// Functional domain for ontologies. -// - -use std::cell::RefCell; -use std::collections::{HashMap, HashSet}; - -use crate::error::DspDomainError; - -type Iri = String; - -#[derive(Debug, PartialEq)] -pub struct Identified(pub Iri); - -#[derive(Debug, PartialEq)] -struct UnIdentified; - -#[derive(Debug, PartialEq)] -struct WithOntologyInfo { - label: String, - project_iri: Iri, - comment: String, -} - -#[derive(Debug, PartialEq)] -struct NoOntologyInfo; - -/// Used to track defined classes inside the ontology -struct DefinedClasses(RefCell<HashSet<Iri>>); - -#[derive(Debug, Clone, PartialEq)] -struct OntologyClass { - id: Iri, // only one per ontology - label: String, - comment: String, -} - -#[derive(Debug, PartialEq)] -struct OntologyProperty { - name: Iri, // only one per ontology - label: String, - comment: String, - range: String, // what type is allowed in object position: subject / predicate / object -} - -#[derive(Debug, PartialEq)] -struct Cardinality { - ontology_class: OntologyClass, - ontology_property: OntologyProperty, - cardinality_type: CardinalityType, -} - -#[derive(Debug, PartialEq)] -enum CardinalityType { - MaxCardinalityOne, - MinCardinalityOne, - MinCardinalityZero, -} - -pub struct Ontology { - id: Iri, - label: String, - project_iri: Iri, - comment: String, -} - -#[derive(Debug, PartialEq)] -struct OntologyBuilder<ID, INFO> { - id: ID, - info: INFO, - classes: HashMap<Iri, OntologyClass>, -} - -/// gives us an empty ontology builder -impl OntologyBuilder<UnIdentified, NoOntologyInfo> { - fn default() -> Self { - Self { - id: UnIdentified, - info: NoOntologyInfo, - classes: HashMap::new(), - } - } -} - -/// we always allow setting the id and info -impl<T> OntologyBuilder<UnIdentified, T> { - fn id(self, iri: Iri) -> OntologyBuilder<Identified, T> { - OntologyBuilder { - id: Identified(iri), - info: self.info, - classes: self.classes, - } - } -} - -impl<T> OntologyBuilder<T, NoOntologyInfo> { - fn info( - self, - label: String, - project_iri: Iri, - comment: String, - ) -> OntologyBuilder<T, WithOntologyInfo> { - OntologyBuilder { - id: self.id, - info: WithOntologyInfo { - label, - project_iri, - comment, - }, - classes: self.classes, - } - } -} - -impl<T, S> OntologyBuilder<T, S> { - fn add_class(mut self, clazz: OntologyClass) -> Result<OntologyBuilder<T, S>, DspDomainError> { - if self.classes.contains_key(&clazz.id) { - return Err(DspDomainError::CreateDomainObject( - "The ontology already contains a class with the same id.".to_string(), - )); - } - let id = clazz.id.clone(); - self.classes.insert(id, clazz); - Ok(self) - } -} - -/// we can only construct the ontology once all needed information is set -impl OntologyBuilder<Identified, WithOntologyInfo> { - fn into_ontology(self) -> Ontology { - Ontology { - id: self.id.0, - label: self.info.label, - project_iri: self.info.project_iri, - comment: self.info.comment, - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn create_empty_ontology() { - let empty = OntologyBuilder::default(); - assert_eq!(empty.id, UnIdentified); - assert_eq!(empty.info, NoOntologyInfo); - } - - #[test] - fn ontology_with_id() { - let empty = OntologyBuilder::default(); - let with_id = empty.id("https:://example.com/example".to_owned()); - assert_eq!( - with_id.id, - Identified("https:://example.com/example".to_owned()) - ); - assert_eq!(with_id.info, NoOntologyInfo); - } - - #[test] - fn ontology_with_info() { - let empty = OntologyBuilder::default(); - - let with_id = empty.id("https:://example.com/example".to_owned()); - let with_info = with_id.info("label".to_owned(), "iri".to_owned(), "comment".to_owned()); - assert_eq!( - with_info.id, - Identified("https:://example.com/example".to_owned()) - ); - assert_eq!( - with_info.info, - WithOntologyInfo { - label: "label".to_owned(), - project_iri: "iri".to_owned(), - comment: "comment".to_owned(), - } - ) - } - - #[test] - fn ontology_with_info_1() { - let empty = OntologyBuilder::default(); - let with_info = empty.info("label".to_owned(), "iri".to_owned(), "comment".to_owned()); - let with_id = with_info.id("https:://example.com/example".to_owned()); - - assert_eq!( - with_id.id, - Identified("https:://example.com/example".to_owned()) - ); - assert_eq!( - with_id.info, - WithOntologyInfo { - label: "label".to_owned(), - project_iri: "iri".to_owned(), - comment: "comment".to_owned(), - } - ) - } - - #[test] - fn ontology_with_class() { - let empty = OntologyBuilder::default(); - let actual = empty - .info("label".to_owned(), "iri".to_owned(), "comment".to_owned()) - .id("https:://example.com/example".to_owned()) - .add_class(OntologyClass { - id: "something".to_string(), - label: "".to_string(), - comment: "".to_string(), - }); - - assert!(actual.unwrap().classes.contains_key("something")); - } - - #[test] - fn error_adding_duplicate_class() { - let empty = OntologyBuilder::default(); - let actual = empty - .add_class(OntologyClass { - id: "something".to_string(), - label: "".to_string(), - comment: "".to_string(), - }) - .unwrap() - .add_class(OntologyClass { - id: "something".to_string(), - label: "".to_string(), - comment: "".to_string(), - }); - - assert!(actual.is_err()); - } -} diff --git a/dsp-meta/Cargo.toml b/dsp-meta/Cargo.toml index e460a1f2..8b781e62 100644 --- a/dsp-meta/Cargo.toml +++ b/dsp-meta/Cargo.toml @@ -13,7 +13,6 @@ authors.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dsp-domain = { path = "../dsp-domain" } anyhow.workspace = true axum.workspace = true axum-macros.workspace = true @@ -46,7 +45,3 @@ chrono.workspace = true assert_cmd = "2.0.16" axum-test = "15.3.0" fake = "2.9.2" - -[[test]] -name = "integration_test" -test = true diff --git a/dsp-meta/src/api/convert/hcl/dsp_meta_error.rs b/dsp-meta/src/api/convert/hcl/dsp_meta_error.rs deleted file mode 100644 index 193124ab..00000000 --- a/dsp-meta/src/api/convert/hcl/dsp_meta_error.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate::error::DspMetaError; - -impl From<hcl::Error> for DspMetaError { - fn from(error: hcl::Error) -> Self { - DspMetaError::ParseHcl(error.to_string()) - } -} diff --git a/dsp-meta/src/api/convert/hcl/entity/dataset/extracted_dataset_attributes.rs b/dsp-meta/src/api/convert/hcl/entity/dataset/extracted_dataset_attributes.rs deleted file mode 100644 index 82156ad2..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/dataset/extracted_dataset_attributes.rs +++ /dev/null @@ -1,253 +0,0 @@ -use std::cell::OnceCell; - -use dsp_domain::metadata::value::access::Access; -use dsp_domain::metadata::value::data_type::DataType; -use dsp_domain::metadata::value::identifier::DatasetId; -use dsp_domain::metadata::value::status::Status; -use dsp_domain::metadata::value::{CreatedAt, CreatedBy, DatePublished, HowToCite, Title}; -use hcl::Expression; -use tracing::warn; - -use crate::error::DspMetaError; - -pub struct ExtractedDatasetAttributes { - pub id: OnceCell<DatasetId>, // (1) - pub created_at: OnceCell<CreatedAt>, // (1) - pub created_by: OnceCell<CreatedBy>, // (1) - pub title: OnceCell<Title>, // (1) - pub status: OnceCell<Status>, // (1) - pub access_conditions: OnceCell<Access>, // (1) - pub how_to_cite: OnceCell<HowToCite>, // (1) - pub date_published: OnceCell<DatePublished>, // (0-1) - pub type_of_data: Vec<DataType>, // (1-n) - pub alternative_titles: Vec<Title>, // (0-n) -} - -impl TryFrom<Vec<&hcl::Attribute>> for ExtractedDatasetAttributes { - type Error = DspMetaError; - - fn try_from(attributes: Vec<&hcl::Attribute>) -> Result<Self, Self::Error> { - let id: OnceCell<DatasetId> = OnceCell::new(); - let created_at: OnceCell<CreatedAt> = OnceCell::new(); - let created_by: OnceCell<CreatedBy> = OnceCell::new(); - let title: OnceCell<Title> = OnceCell::new(); - let status: OnceCell<Status> = OnceCell::new(); - let access_conditions: OnceCell<Access> = OnceCell::new(); - let how_to_cite: OnceCell<HowToCite> = OnceCell::new(); - let date_published: OnceCell<DatePublished> = OnceCell::new(); - let mut type_of_data: Vec<DataType> = vec![]; - let mut alternative_titles: Vec<Title> = vec![]; - - for attribute in attributes { - match attribute.key() { - "id" => { - let extracted_id = match attribute.expr() { - Expression::String(value) => Ok(DatasetId(value.to_owned())), - _ => Err(DspMetaError::ParseDataset( - "Parse error: id needs to be a string.".to_string(), - )), - }?; - id.set(extracted_id).map_err(|_| { - DspMetaError::ParseDataset( - "Parse error: id needs to be unique.".to_string(), - ) - })?; - } - "created_at" => { - let extracted_created_at = match attribute.expr() { - Expression::Number(value) => Ok(CreatedAt(value.as_u64().unwrap())), /* FIXME: get rid of unwrap */ - _ => Err(DspMetaError::ParseDataset( - "Parse error: created_at needs to be a number.".to_string(), - )), - }?; - created_at.set(extracted_created_at).map_err(|_| { - DspMetaError::ParseDataset( - "Parse error: created_at needs to be unique.".to_string(), - ) - })?; - } - "created_by" => { - let extracted_created_by = match attribute.expr() { - Expression::String(value) => Ok(CreatedBy(value.to_owned())), - _ => Err(DspMetaError::ParseDataset( - "Parse error: created_by needs to be a string.".to_string(), - )), - }?; - created_by.set(extracted_created_by).map_err(|_| { - DspMetaError::ParseDataset( - "Parse error: created_by needs to be unique.".to_string(), - ) - })?; - } - "title" => { - let extracted_title = match attribute.expr() { - Expression::String(value) => Ok(Title(value.to_owned())), - _ => Err(DspMetaError::ParseDataset( - "Parse error: title needs to be a string.".to_string(), - )), - }?; - title.set(extracted_title).map_err(|_| { - DspMetaError::ParseDataset( - "Parse error: title needs to be unique.".to_string(), - ) - })?; - } - "status" => { - let extracted_status = match attribute.expr() { - Expression::String(value) => Ok(Status::try_from(value.to_owned())?), - _ => Err(DspMetaError::ParseDataset( - "Parse error: status needs to be a string.".to_string(), - )), - }?; - status.set(extracted_status).map_err(|_| { - DspMetaError::ParseDataset( - "Parse error: status needs to be unique.".to_string(), - ) - })?; - } - "access_conditions" => { - let extracted_access_conditions = match attribute.expr() { - Expression::String(value) => Ok(Access::try_from(value.to_owned())?), - _ => Err(DspMetaError::ParseDataset( - "Parse error: access_conditions needs to be a string.".to_string(), - )), - }?; - access_conditions - .set(extracted_access_conditions) - .map_err(|_| { - DspMetaError::ParseDataset( - "Parse error: access_conditions needs to be unique.".to_string(), - ) - })?; - } - "how_to_cite" => { - let extracted_how_to_cite = match attribute.expr() { - Expression::String(value) => Ok(HowToCite(value.to_owned())), - _ => Err(DspMetaError::ParseDataset( - "Parse error: how_to_cite needs to be a string.".to_string(), - )), - }?; - how_to_cite.set(extracted_how_to_cite).map_err(|_| { - DspMetaError::ParseDataset( - "Parse error: how_to_cite needs to be unique.".to_string(), - ) - })?; - } - "date_published" => { - let extracted_date_published = match attribute.expr() { - Expression::Number(value) => Ok(DatePublished(value.as_u64().unwrap())), - _ => Err(DspMetaError::ParseDataset( - "Parse error: date_published needs to be a string.".to_string(), - )), - }?; - date_published.set(extracted_date_published).map_err(|_| { - DspMetaError::ParseDataset( - "Parse error: date_published needs to be unique.".to_string(), - ) - })?; - } - "type_of_data" => { - type_of_data = match attribute.expr() { - Expression::Array(values) => { - let mut data_types = vec![]; - for value in values { - match value { - Expression::String(value) => { - data_types.push(DataType::try_from(value.to_owned())?) - } - _ => { - return Err(DspMetaError::ParseDataset( - "Parse error: type_of_data value needs to be a string." - .to_string(), - )) - } - } - } - Ok(data_types) - } - _ => Err(DspMetaError::ParseDataset( - "Parse error: type_of_data needs to be a list of strings.".to_string(), - )), - }?; - } - "alternative_titles" => { - alternative_titles = match attribute.expr() { - Expression::Array(values) => { - let mut titles = vec![]; - for value in values { - match value { - Expression::String(value) => { - titles.push(Title(value.to_owned())) - } - _ => { - return Err(DspMetaError::ParseDataset( - "Parse error: alternative_titles value needs to be a string." - .to_string(), - )) - } - } - } - Ok(titles) - } - _ => Err(DspMetaError::ParseDataset( - "Parse error: alternative_titles needs to be a list of strings." - .to_string(), - )), - }?; - } - _ => { - warn!("Parse error: unknown attribute '{}'.", attribute.key()); - } - } - } - Ok(ExtractedDatasetAttributes { - id, - created_at, - created_by, - title, - status, - access_conditions, - how_to_cite, - date_published, - type_of_data, - alternative_titles, - }) - } -} - -#[cfg(test)] -mod tests { - use hcl::Number; - use tracing_test::traced_test; - - use super::*; - - #[test] - fn extract_created_at() { - let attribute = hcl::Attribute::new("created_at", Number::from(1u64)); - let attributes = vec![&attribute]; - let mut result = ExtractedDatasetAttributes::try_from(attributes).unwrap(); - assert_eq!(result.created_at.take().unwrap(), CreatedAt(1)); - } - - #[test] - fn extract_created_by() { - let attribute = hcl::Attribute::new("created_by", "someone"); - let attributes = vec![&attribute]; - let mut result = ExtractedDatasetAttributes::try_from(attributes).unwrap(); - assert_eq!( - result.created_by.take().unwrap(), - CreatedBy("someone".to_string()) - ); - } - - #[traced_test] - #[test] - fn warn_on_unknown_attribute() { - let attribute = hcl::Attribute::new("gugus", "something"); - let attributes = vec![&attribute]; - let _ = ExtractedDatasetAttributes::try_from(attributes); - - assert!(logs_contain("Parse error: unknown attribute 'gugus'")); - } -} diff --git a/dsp-meta/src/api/convert/hcl/entity/dataset/extracted_dataset_blocks.rs b/dsp-meta/src/api/convert/hcl/entity/dataset/extracted_dataset_blocks.rs deleted file mode 100644 index 94d8f2b8..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/dataset/extracted_dataset_blocks.rs +++ /dev/null @@ -1,101 +0,0 @@ -use dsp_domain::metadata::value::attribution::Attribution; -use dsp_domain::metadata::value::language::Language; -use dsp_domain::metadata::value::license::License; -use dsp_domain::metadata::value::r#abstract::Abstract; -use dsp_domain::metadata::value::url::Url; -use tracing::warn; - -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const ABSTRACT_BLOCK: &str = "abstract"; -const LICENSE_BLOCK: &str = "license"; -const LANGUAGE_BLOCK: &str = "language"; -const ATTRIBUTION_BLOCK: &str = "attribution"; -const URL_BLOCK: &str = "url"; - -#[derive(Debug, Default, PartialEq)] -pub struct ExtractedDatasetBlocks { - pub abstracts: Vec<Abstract>, - pub licenses: Vec<License>, - pub languages: Vec<Language>, - pub attributions: Vec<Attribution>, - pub urls: Vec<Url>, -} - -impl TryFrom<Vec<&hcl::Block>> for ExtractedDatasetBlocks { - type Error = DspMetaError; - - fn try_from(blocks: Vec<&hcl::Block>) -> Result<Self, Self::Error> { - let mut abstracts: Vec<Abstract> = vec![]; - let mut licenses: Vec<License> = vec![]; - let mut languages: Vec<Language> = vec![]; - let mut attributions: Vec<Attribution> = vec![]; - let mut urls: Vec<Url> = vec![]; - - for block in blocks { - match block.identifier.as_str() { - ABSTRACT_BLOCK => abstracts.push(HclBlock(block).try_into()?), - LICENSE_BLOCK => licenses.push(HclBlock(block).try_into()?), - LANGUAGE_BLOCK => languages.push(HclBlock(block).try_into()?), - ATTRIBUTION_BLOCK => attributions.push(HclBlock(block).try_into()?), - URL_BLOCK => urls.push(HclBlock(block).try_into()?), - _ => { - // catch all - warn!( - "Parse error: unknown or not implemented block '{}'.", - block.identifier - ); - } - } - } - Ok(ExtractedDatasetBlocks { - abstracts, - licenses, - languages, - attributions, - urls, - }) - } -} - -#[cfg(test)] -mod tests { - use hcl::{block, Identifier}; - use tracing_test::traced_test; - - use crate::api::convert::hcl::entity::dataset::extracted_dataset_blocks::ExtractedDatasetBlocks; - - #[test] - fn extract_abstracts() { - let input1 = block!( - abstract { - de = "abstract1_de" - en = "abstract1_en" - fr = "abstract1_fr" - } - ); - let input2 = block!( - abstract { - de = "abstract2_de" - en = "abstract2_en" - fr = "abstract2_fr" - } - ); - let blocks = vec![&input1, &input2]; - let result = ExtractedDatasetBlocks::try_from(blocks).unwrap(); - assert_eq!(result.abstracts.len(), 2); - } - - #[traced_test] - #[test] - fn warn_on_unknown_block() { - let block = hcl::Block::new(Identifier::new("gugus").unwrap()); - let blocks = vec![&block]; - let _ = ExtractedDatasetBlocks::try_from(blocks); - - assert!(logs_contain( - " Parse error: unknown or not implemented block 'gugus'" - )); - } -} diff --git a/dsp-meta/src/api/convert/hcl/entity/dataset/mod.rs b/dsp-meta/src/api/convert/hcl/entity/dataset/mod.rs deleted file mode 100644 index eafccba6..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/dataset/mod.rs +++ /dev/null @@ -1,210 +0,0 @@ -use dsp_domain::metadata::entity::dataset::Dataset; -use extracted_dataset_attributes::ExtractedDatasetAttributes; -use extracted_dataset_blocks::ExtractedDatasetBlocks; - -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -pub(crate) mod extracted_dataset_attributes; -pub(crate) mod extracted_dataset_blocks; - -impl<'a> TryInto<Dataset> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Dataset, Self::Error> { - if self.0.identifier.as_str() != "dataset" { - return Err(DspMetaError::ParseDataset( - format!( - "Parse error: dataset block needs to be named 'dataset', however got '{}' instead.", - self.0.identifier.as_str() - ) - .to_string(), - )); - } - - // extract the dataset attributes - // id (1), created_at (1), created_by (1), title (1), status (1), access_conditions (1), - // how_to_cite (1), date_published (0-1), type_of_data (1-n), alternative_titles (0-n), - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - - let mut extracted_attributes = ExtractedDatasetAttributes::try_from(attributes)?; - - let id = extracted_attributes.id.take().ok_or_else(|| { - DspMetaError::ParseDataset("Parse error: project needs to have an id.".to_string()) - })?; - - let created_at = extracted_attributes.created_at.take().ok_or_else(|| { - DspMetaError::ParseDataset( - "Parse error: project needs to have a created_at value.".to_string(), - ) - })?; - - let created_by = extracted_attributes.created_by.take().ok_or_else(|| { - DspMetaError::ParseDataset( - "Parse error: project needs to have a created_by value.".to_string(), - ) - })?; - - let title = extracted_attributes.title.take().ok_or_else(|| { - DspMetaError::ParseDataset("Parse error: dataset needs to have a title.".to_string()) - })?; - - let status = extracted_attributes.status.take().ok_or_else(|| { - DspMetaError::ParseDataset("Parse error: dataset needs to have a status".to_string()) - })?; - - let access_conditions = extracted_attributes - .access_conditions - .take() - .ok_or_else(|| { - DspMetaError::ParseDataset( - "Parse error: dataset needs to have a access_condition".to_string(), - ) - })?; - - let how_to_cite = extracted_attributes.how_to_cite.take().ok_or_else(|| { - DspMetaError::ParseDataset("Parse error: dataset needs to have how_to_cite".to_string()) - })?; - - let date_published = extracted_attributes.date_published.take(); - - let type_of_data = if !extracted_attributes.type_of_data.is_empty() { - Ok(extracted_attributes.type_of_data) - } else { - Err(DspMetaError::ParseDataset( - "Parse dataset: there needs to be at least one type_of_data.".to_string(), - )) - }?; - - let alternative_titles = extracted_attributes.alternative_titles; - - // extract the dataset blocks - // abstracts (1-n), licenses (1-n), languages (1-n), attributions (1-n), - // urls (0-n), - - let blocks: Vec<&hcl::Block> = self.0.body.blocks().collect(); - let extracted_blocks = ExtractedDatasetBlocks::try_from(blocks)?; - - let abstracts = if !extracted_blocks.abstracts.is_empty() { - Ok(extracted_blocks.abstracts) - } else { - Err(DspMetaError::ParseDataset( - "Parse dataset: there needs to be at least one abstract.".to_string(), - )) - }?; - - let licenses = if !extracted_blocks.licenses.is_empty() { - Ok(extracted_blocks.licenses) - } else { - Err(DspMetaError::ParseDataset( - "Parse dataset: there needs to be at least one license.".to_string(), - )) - }?; - - let languages = if !extracted_blocks.languages.is_empty() { - Ok(extracted_blocks.languages) - } else { - Err(DspMetaError::ParseDataset( - "Parse dataset: there needs to be at least one language.".to_string(), - )) - }?; - - let attributions = if !extracted_blocks.attributions.is_empty() { - Ok(extracted_blocks.attributions) - } else { - Err(DspMetaError::ParseDataset( - "Parse dataset: there needs to be at least one attribution.".to_string(), - )) - }?; - let urls = extracted_blocks.urls; - - Ok(Dataset { - id, - created_at, - created_by, - title, - status, - access_conditions, - how_to_cite, - date_published, - type_of_data, - alternative_titles, - abstracts, - licenses, - languages, - attributions, - urls, - }) - } -} - -#[cfg(test)] -mod tests { - use dsp_domain::metadata::value::access::Access; - use dsp_domain::metadata::value::data_type::DataType; - use dsp_domain::metadata::value::identifier::DatasetId; - use dsp_domain::metadata::value::status::Status; - use dsp_domain::metadata::value::{CreatedAt, CreatedBy, DatePublished, HowToCite, Title}; - use hcl::block; - use tracing_test::traced_test; - - use super::*; - - #[traced_test] - #[test] - fn test_convert_dataset_block() { - let input_dataset_block = block!( - dataset { - id = "d1" - created_at = 1630601274523025000u64 // FIXME: is there a more readable way to write an i64? - created_by = "dsp-metadata-gui" - title = "The German Family Panel (pairfam)" - how_to_cite = "pairfam" - status = "Ongoing" - access_conditions = "Open" - date_published = 1630601274523025000u64 - type_of_data = ["Image", "Text"] - abstract { - en = "The interdisciplinary research project \"The image sequences of Basel's early prints: Late Medieval didactic didactics as an image-text reading\" combines a comprehensive art scholarly analysis of the links between images and texts in the illustrated incunabula in Basel with the digitization of the holdings of the University Library and the development of an electronic edition in the form of a new kind of Web-0.2 application. The project is carried out by Kunsthistorische Seminar of the University of Basel (Prof. Dr. B. Schellewald) and Digital Humanities Lab of the University of Basel (Prof. Dr. L. Rosenthaler). The core of the digital edition consists of around twenty richly illustrated early prints from four different Basel officers. Many of them appeared in several editions before 1500, some of them in German and Latin at almost the same time. It is an extraordinarily varied production; in addition to the Mirror of Salvation, there is a novel, the Melusine, the travelogues of Jean de Mandeville, some prayer and edification books, theological writings, Lent sermons, the lives of Saints Fridolin and Meinrad, the famous ship of fools and the knight of Thurn. The Internet publication makes the digitized corpus of these early prints usable for the scientific edition as well as for the exploration of images and texts through the possibilities of non-linear linking and commenting on the images and texts. Existing and emerging online editions can also be linked to it, which optimises the use of databases from other institutions with regard to our corpus." - } - license { - type = "creative_commons" - href = "https://creativecommons.org/licenses/by-nc/4.0" - date = "2021-09-02" - label = "CC BY-NC 4.0" - } - language { - de = "Deutsch" - en = "German" - fr = "Allemand" - } - - // reference to person or organization - attribution { - agent = "http://ns.dasch.swiss/repository#dsp-081C-organization-000" // reference to person or organization - roles = ["Author"] - } - } - ); - let dataset: Dataset = HclBlock(&input_dataset_block).try_into().unwrap(); - assert_eq!(dataset.id, DatasetId(String::from("d1"))); - assert_eq!(dataset.created_at, CreatedAt(1630601274523025000)); - assert_eq!( - dataset.created_by, - CreatedBy(String::from("dsp-metadata-gui")) - ); - assert_eq!( - dataset.title, - Title(String::from("The German Family Panel (pairfam)")) - ); - assert_eq!(dataset.how_to_cite, HowToCite("pairfam".to_string())); - assert_eq!(dataset.status, Status::Ongoing); - assert_eq!(dataset.access_conditions, Access::Open); - assert_eq!( - dataset.date_published, - Some(DatePublished(1630601274523025000u64)) - ); - assert_eq!(dataset.type_of_data, vec![DataType::Image, DataType::Text]); - } -} diff --git a/dsp-meta/src/api/convert/hcl/entity/grant/extracted_grant.rs b/dsp-meta/src/api/convert/hcl/entity/grant/extracted_grant.rs deleted file mode 100644 index 2adba635..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/grant/extracted_grant.rs +++ /dev/null @@ -1,228 +0,0 @@ -use dsp_domain::metadata::value::funder::Funder; -use dsp_domain::metadata::value::identifier::GrantId; -use dsp_domain::metadata::value::url::Url; -use dsp_domain::metadata::value::{CreatedAt, CreatedBy, GrantNumber, GrantType, Name}; -use hcl::Expression; -use log::warn; - -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -pub struct ExtractedGrant { - pub id: Option<GrantId>, - pub created_at: Option<CreatedAt>, - pub created_by: Option<CreatedBy>, - pub type_of_grant: Option<GrantType>, - pub name: Option<Name>, - pub number: Option<GrantNumber>, - pub url: Option<Url>, - pub funders: Vec<Funder>, -} - -impl<'a> TryFrom<HclBlock<'a>> for ExtractedGrant { - type Error = DspMetaError; - - fn try_from(hcl_block: HclBlock<'a>) -> Result<Self, Self::Error> { - let mut id: Option<GrantId> = None; - let mut created_at: Option<CreatedAt> = None; - let mut created_by: Option<CreatedBy> = None; - let mut type_of_grant: Option<GrantType> = None; - let mut name: Option<Name> = None; - let mut number: Option<GrantNumber> = None; - let mut url: Option<Url> = None; - let mut funders: Vec<Funder> = Vec::new(); - - // check if the block is named grant - if hcl_block.0.identifier.as_str() != "grant" { - return Err(DspMetaError::ParseGrant( - format!( - "Parse error: grant block needs to be named 'grant', however got '{}' instead.", - hcl_block.0.identifier.as_str() - ) - .to_string(), - )); - } - - // extract the attributes - // id (1), created_at (1), created_by (1), type_of_grant (1), - // name (0-1), number (0-1), funders (1-n), - - let attributes: Vec<&hcl::Attribute> = hcl_block.0.body.attributes().collect(); - - for attribute in attributes { - match attribute.key() { - "id" => { - if id.is_some() { - return Err(DspMetaError::ParseGrant( - "Parse error: grant needs to have only one id.".to_string(), - )); - } - id = match attribute.expr() { - hcl::Expression::String(value) => Some(GrantId(value.to_string())), - _ => { - return Err(DspMetaError::ParseGrant( - "Parse error: grant id needs to be a string.".to_string(), - )) - } - }; - } - "created_at" => { - if created_at.is_some() { - return Err(DspMetaError::ParseGrant( - "Parse error: grant needs to have only one created_at value." - .to_string(), - )); - } - created_at = match attribute.expr() { - hcl::Expression::Number(value) => Some(CreatedAt(value.as_u64().unwrap())), - _ => { - return Err(DspMetaError::ParseGrant( - "Parse error: grant created_at needs to be a number.".to_string(), - )) - } - } - } - "created_by" => { - if created_by.is_some() { - return Err(DspMetaError::ParseGrant( - "Parse error: grant needs to have only one created_by value." - .to_string(), - )); - } - created_by = match attribute.expr() { - hcl::Expression::String(value) => Some(CreatedBy(value.to_string())), - _ => { - return Err(DspMetaError::ParseGrant( - "Parse error: grant created_by needs to be a string.".to_string(), - )) - } - } - } - "type_of_grant" => { - if type_of_grant.is_some() { - return Err(DspMetaError::ParseGrant( - "Parse error: grant needs to have only one type_of_grant value." - .to_string(), - )); - } - type_of_grant = match attribute.expr() { - hcl::Expression::String(value) => Some(GrantType(value.to_string())), - _ => { - return Err(DspMetaError::ParseGrant( - "Parse error: grant type_of_grant needs to be a string." - .to_string(), - )) - } - } - } - "name" => { - if name.is_some() { - return Err(DspMetaError::ParseGrant( - "Parse error: grant needs to have only one name value.".to_string(), - )); - } - name = match attribute.expr() { - hcl::Expression::String(value) => Some(Name(value.to_string())), - _ => { - return Err(DspMetaError::ParseGrant( - "Parse error: grant name needs to be a string.".to_string(), - )) - } - } - } - "number" => { - if number.is_some() { - return Err(DspMetaError::ParseGrant( - "Parse error: grant needs to have only one number value.".to_string(), - )); - } - number = match attribute.expr() { - hcl::Expression::String(value) => Some(GrantNumber(value.to_string())), - _ => { - return Err(DspMetaError::ParseGrant( - "Parse error: grant number needs to be a string.".to_string(), - )) - } - } - } - "funders" => { - match attribute.expr() { - Expression::Array(values) => { - for value in values { - match value { - Expression::String(value) => { - // pushing the value to the vector - funders.push(Funder(value.to_string())) - } - _ => { - return Err(DspMetaError::ParseGrant( - "Parse error: grant funder needs to be a string." - .to_string(), - )) - } - } - } - } - _ => { - return Err(DspMetaError::ParseGrant( - "Parse error: grant funder needs to be an array.".to_string(), - )) - } - } - } - _ => warn!("Parse error: unknown attribute '{}'.", attribute.key()), - } - } - - // extract the blocks - // url (0-1), - - let blocks: Vec<&hcl::Block> = hcl_block.0.body.blocks().collect(); - - for block in blocks { - match block.identifier.as_str() { - "url" => { - if url.is_some() { - return Err(DspMetaError::ParseGrant( - "Parse error: grant needs to have only one url.".to_string(), - )); - } - url = Some(HclBlock(block).try_into()?) - } - _ => warn!( - "Parse error: unknown or not implemented block '{}'.", - block.identifier - ), - } - } - - Ok(Self { - id, - created_at, - created_by, - type_of_grant, - name, - number, - url, - funders, - }) - } -} - -#[cfg(test)] -mod tests { - use hcl::block; - - use super::*; - - #[test] - fn extract_id() { - let hcl = block!( - grant { - id = "grant-1" - } - ); - let extracted = ExtractedGrant::try_from(HclBlock(&hcl)).unwrap(); - assert_eq!(extracted.id, Some(GrantId("grant-1".to_string()))); - } -} diff --git a/dsp-meta/src/api/convert/hcl/entity/grant/mod.rs b/dsp-meta/src/api/convert/hcl/entity/grant/mod.rs deleted file mode 100644 index d953fbd1..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/grant/mod.rs +++ /dev/null @@ -1,113 +0,0 @@ -use dsp_domain::metadata::entity::grant::Grant; - -use crate::api::convert::hcl::entity::grant::extracted_grant::ExtractedGrant; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -mod extracted_grant; - -impl<'a> TryInto<Grant> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Grant, Self::Error> { - let mut extracted = ExtractedGrant::try_from(self)?; - - // id (1), created_at (1), created_by (1), type_of_grant (1), - // name (0-1), number (0-1), url (0-1), funders (1-n), - - let id = extracted.id.take().ok_or_else(|| { - DspMetaError::ParseGrant("Parse error: Grant needs to have an id.".to_string()) - })?; - - let created_at = extracted.created_at.take().ok_or_else(|| { - DspMetaError::ParseGrant( - "Parse error: grant needs to have a created_at value.".to_string(), - ) - })?; - - let created_by = extracted.created_by.take().ok_or_else(|| { - DspMetaError::ParseGrant( - "Parse error: grant needs to have a created_by value.".to_string(), - ) - })?; - - let type_of_grant = extracted.type_of_grant.ok_or(DspMetaError::ParseGrant( - "Parse error: grant needs to have a type.".to_string(), - ))?; - - let name = extracted.name; - - let number = extracted.number; - - let url = extracted.url; - - let funders = if !extracted.funders.is_empty() { - Ok(extracted.funders) - } else { - Err(DspMetaError::ParseGrant( - "Parse grant: there needs to be at least one funder.".to_string(), - )) - }?; - - Ok(Grant { - id, - created_at, - created_by, - type_of_grant, - name, - number, - url, - funders, - }) - } -} - -#[cfg(test)] -mod tests { - use dsp_domain::metadata::value::identifier::GrantId; - use dsp_domain::metadata::value::url::Url; - use hcl::block; - use tracing_test::traced_test; - - use super::*; - - #[traced_test] - #[test] - fn test_convert_grant_block() { - let input_block = block!( - grant { - id = "g1" - created_at = 1630601300976368000u64 - created_by = "dsp-metadata-gui" - type_of_grant = "funding" - name = "The German Family Panel (pairfam)" - number = "01US1706A" - url { - href = "https://data.snf.ch/grants/grant/120378" - label = "https://data.snf.ch/grants/grant/120378" - } - funders = ["f1"] - } - ); - let grant: Grant = HclBlock(&input_block).try_into().unwrap(); - assert_eq!(grant.id, GrantId("g1".to_string())); - assert_eq!(grant.created_at.0, 1630601300976368000u64); - assert_eq!(grant.created_by.0, "dsp-metadata-gui".to_string()); - assert_eq!(grant.type_of_grant.0, "funding".to_string()); - assert_eq!( - grant.name.unwrap().0, - "The German Family Panel (pairfam)".to_string() - ); - assert_eq!(grant.number.unwrap().0, "01US1706A".to_string()); - assert_eq!( - grant.url, - Some( - Url::new( - "https://data.snf.ch/grants/grant/120378".to_string(), - "https://data.snf.ch/grants/grant/120378".to_string() - ) - .unwrap() - ) - ); - } -} diff --git a/dsp-meta/src/api/convert/hcl/entity/mod.rs b/dsp-meta/src/api/convert/hcl/entity/mod.rs deleted file mode 100644 index 53c9ffed..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub(crate) mod dataset; -pub(crate) mod grant; -pub(crate) mod project; diff --git a/dsp-meta/src/api/convert/hcl/entity/project/extracted_project_attributes.rs b/dsp-meta/src/api/convert/hcl/entity/project/extracted_project_attributes.rs deleted file mode 100644 index 8d74f6db..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/project/extracted_project_attributes.rs +++ /dev/null @@ -1,211 +0,0 @@ -use dsp_domain::metadata::value::identifier::{DatasetId, ProjectId}; -use dsp_domain::metadata::value::status::Status; -use dsp_domain::metadata::value::{ - ContactPoint, CreatedAt, CreatedBy, EndDate, HowToCite, Name, Shortcode, StartDate, TeaserText, -}; -use hcl::Expression; -use tracing::warn; - -use crate::error::DspMetaError; - -pub struct ExtractedProjectAttributes { - pub id: Option<ProjectId>, - pub created_at: Option<CreatedAt>, - pub created_by: Option<CreatedBy>, - pub shortcode: Option<Shortcode>, - pub name: Option<Name>, - pub teaser_text: Option<TeaserText>, - pub how_to_cite: Option<HowToCite>, - pub start_date: Option<StartDate>, - pub end_date: Option<EndDate>, - pub status: Option<Status>, - pub contact_point: Option<ContactPoint>, - pub datasets: Vec<DatasetId>, -} - -impl TryFrom<Vec<&hcl::Attribute>> for ExtractedProjectAttributes { - type Error = DspMetaError; - - fn try_from(attributes: Vec<&hcl::Attribute>) -> Result<Self, Self::Error> { - let mut id: Option<ProjectId> = None; - let mut created_at: Option<CreatedAt> = None; - let mut created_by: Option<CreatedBy> = None; - let mut shortcode: Option<Shortcode> = None; - let mut name: Option<Name> = None; - let mut teaser_text: Option<TeaserText> = None; - let mut how_to_cite: Option<HowToCite> = None; - let mut start_date: Option<StartDate> = None; - let mut end_date: Option<EndDate> = None; - let mut status: Option<Status> = None; - let mut contact_point: Option<ContactPoint> = None; - let mut datasets: Vec<DatasetId> = vec![]; - - // FIXME: throw error on duplicate attributes - for attribute in attributes { - match attribute.key() { - "id" => { - id = match attribute.expr() { - Expression::String(value) => Ok(Some(ProjectId(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: id needs to be a string.".to_string(), - )), - }?; - } - "created_at" => { - created_at = match attribute.expr() { - Expression::Number(value) => Ok(Some(CreatedAt(value.as_u64().unwrap()))), /* FIXME: get rid of unwrap */ - _ => Err(DspMetaError::ParseProject( - "Parse error: created_at needs to be a number.".to_string(), - )), - }? - } - "created_by" => { - created_by = match attribute.expr() { - Expression::String(value) => Ok(Some(CreatedBy(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: created_by needs to be a string.".to_string(), - )), - }? - } - "shortcode" => { - shortcode = match attribute.expr() { - Expression::String(value) => Ok(Some(Shortcode(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: shortcode needs to be a string.".to_string(), - )), - }?; - } - "name" => { - name = match attribute.expr() { - Expression::String(value) => Ok(Some(Name(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: name needs to be a string.".to_string(), - )), - }?; - } - "teaser_text" => { - teaser_text = match attribute.expr() { - Expression::String(value) => Ok(Some(TeaserText(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: teaser_text needs to be a string.".to_string(), - )), - }?; - } - "how_to_cite" => { - how_to_cite = match attribute.expr() { - Expression::String(value) => Ok(Some(HowToCite(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: how_to_cite needs to be a string.".to_string(), - )), - }?; - } - "start_date" => { - start_date = match attribute.expr() { - Expression::String(value) => Ok(Some(StartDate(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: start_date needs to be a string.".to_string(), - )), - }?; - } - "end_date" => { - end_date = match attribute.expr() { - Expression::String(value) => Ok(Some(EndDate(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: end_date needs to be a string.".to_string(), - )), - }?; - } - "status" => { - status = match attribute.expr() { - Expression::String(value) => Ok(Some(Status::try_from(value.to_owned())?)), - _ => Err(DspMetaError::ParseProject( - "Parse error: end_date needs to be a string.".to_string(), - )), - }?; - } - "contact_point" => { - contact_point = match attribute.expr() { - Expression::String(value) => Ok(Some(ContactPoint(value.to_owned()))), - _ => Err(DspMetaError::ParseProject( - "Parse error: contact_point needs to be a string.".to_string(), - )), - }?; - } - "datasets" => { - datasets = - match attribute.expr() { - Expression::Array(values) => { - let mut dataset_ids = vec![]; - for value in values { - match value { - Expression::String(value) => { - dataset_ids.push(DatasetId(value.to_owned())) - } - _ => return Err(DspMetaError::ParseProject( - "Parse error: datasets needs to be a list of strings." - .to_string(), - )), - } - } - Ok(dataset_ids) - } - _ => Err(DspMetaError::ParseProject( - "Parse error: datasets needs to be a list of strings.".to_string(), - )), - }?; - } - _ => { - warn!("Parse error: unknown attribute '{}'.", attribute.key()); - } - } - } - Ok(ExtractedProjectAttributes { - id, - created_at, - created_by, - shortcode, - name, - teaser_text, - how_to_cite, - start_date, - end_date, - status, - contact_point, - datasets, - }) - } -} - -#[cfg(test)] -mod tests { - use hcl::Number; - use tracing_test::traced_test; - - use super::*; - - #[test] - fn extract_created_at() { - let attribute = hcl::Attribute::new("created_at", Number::from(1u64)); - let attributes = vec![&attribute]; - let result = ExtractedProjectAttributes::try_from(attributes).unwrap(); - assert_eq!(result.created_at.unwrap(), CreatedAt(1)); - } - - #[test] - fn extract_created_by() { - let attribute = hcl::Attribute::new("created_by", "someone"); - let attributes = vec![&attribute]; - let result = ExtractedProjectAttributes::try_from(attributes).unwrap(); - assert_eq!(result.created_by.unwrap(), CreatedBy("someone".to_owned())); - } - - #[traced_test] - #[test] - fn warn_on_unknown_attribute() { - let attribute = hcl::Attribute::new("gugus", "something"); - let attributes = vec![&attribute]; - let _ = ExtractedProjectAttributes::try_from(attributes); - - assert!(logs_contain("Parse error: unknown attribute 'gugus'")); - } -} diff --git a/dsp-meta/src/api/convert/hcl/entity/project/extracted_project_blocks.rs b/dsp-meta/src/api/convert/hcl/entity/project/extracted_project_blocks.rs deleted file mode 100644 index a67a6ecb..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/project/extracted_project_blocks.rs +++ /dev/null @@ -1,271 +0,0 @@ -use dsp_domain::metadata::value::alternative_name::AlternativeName; -use dsp_domain::metadata::value::description::Description; -use dsp_domain::metadata::value::discipline::Discipline; -use dsp_domain::metadata::value::keyword::Keyword; -use dsp_domain::metadata::value::publication::Publication; -use dsp_domain::metadata::value::spatial_coverage::SpatialCoverage; -use dsp_domain::metadata::value::temporal_coverage::TemporalCoverage; -use dsp_domain::metadata::value::url::Url; -use tracing::warn; - -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const ALTERNATIVE_NAME_BLOCK: &str = "alternative_name"; -const DESCRIPTION_BLOCK: &str = "description"; -const URL_BLOCK: &str = "url"; -const KEYWORD_BLOCK: &str = "keyword"; -const DISCIPLINE_BLOCK: &str = "discipline"; -const SPATIAL_COVERAGE_BLOCK: &str = "spatial_coverage"; -const TEMPORAL_COVERAGE_BLOCK: &str = "temporal_coverage"; -const PUBLICATION_BLOCK: &str = "publication"; - -#[derive(Debug, Default, PartialEq)] -pub struct ExtractedProjectBlocks { - pub alternative_names: Vec<AlternativeName>, - pub description: Option<Description>, - pub url: Option<Url>, - pub keywords: Vec<Keyword>, - pub disciplines: Vec<Discipline>, - pub spatial_coverages: Vec<SpatialCoverage>, - pub temporal_coverages: Vec<TemporalCoverage>, - pub publications: Vec<Publication>, -} - -impl TryFrom<Vec<&hcl::Block>> for ExtractedProjectBlocks { - type Error = DspMetaError; - - fn try_from(blocks: Vec<&hcl::Block>) -> Result<Self, Self::Error> { - let mut alternative_names: Vec<AlternativeName> = vec![]; - let mut description: Option<Description> = None; - let mut url: Option<Url> = None; - let mut keywords: Vec<Keyword> = vec![]; - let mut disciplines: Vec<Discipline> = vec![]; - let mut spatial_coverages: Vec<SpatialCoverage> = vec![]; - let mut temporal_coverages: Vec<TemporalCoverage> = vec![]; - let mut publications: Vec<Publication> = vec![]; - - for block in blocks { - match block.identifier.as_str() { - ALTERNATIVE_NAME_BLOCK => alternative_names.push(HclBlock(block).try_into()?), - DESCRIPTION_BLOCK => { - if description.is_some() { - return Err(DspMetaError::ParseProject( - "Only one 'description' block allowed.".to_string(), - )); - } - description = Some(HclBlock(block).try_into()?) - } - URL_BLOCK => { - if url.is_some() { - return Err(DspMetaError::ParseProject( - "Only one 'url' block allowed.".to_string(), - )); - } - url = Some(HclBlock(block).try_into()?) - } - KEYWORD_BLOCK => keywords.push(HclBlock(block).try_into()?), - DISCIPLINE_BLOCK => disciplines.push(HclBlock(block).try_into()?), - SPATIAL_COVERAGE_BLOCK => spatial_coverages.push(HclBlock(block).try_into()?), - TEMPORAL_COVERAGE_BLOCK => temporal_coverages.push(HclBlock(block).try_into()?), - PUBLICATION_BLOCK => publications.push(HclBlock(block).try_into()?), - _ => { - // catch all - warn!("Parse error: unknown block '{}'.", block.identifier); - } - } - } - Ok(ExtractedProjectBlocks { - alternative_names, - description, - url, - keywords, - disciplines, - spatial_coverages, - temporal_coverages, - publications, - }) - } -} - -#[cfg(test)] -mod tests { - use hcl::{block, Identifier}; - use tracing_test::traced_test; - - use crate::api::convert::hcl::entity::project::extracted_project_blocks::ExtractedProjectBlocks; - - #[test] - fn extract_alternative_names() { - let input1 = block!( - alternative_name { - de = "name1_de" - en = "name1_en" - fr = "name1_fr" - } - ); - let input2 = block!( - alternative_name { - de = "name2_de" - en = "name2_en" - fr = "name2_fr" - } - ); - let blocks = vec![&input1, &input2]; - let result = ExtractedProjectBlocks::try_from(blocks).unwrap(); - assert_eq!(result.alternative_names.len(), 2); - } - - #[test] - fn extract_description() { - let input = block!( - description { - de = "descr_de" - en = "descr_en" - fr = "descr_fr" - } - ); - let blocks = vec![&input]; - let result = ExtractedProjectBlocks::try_from(blocks).unwrap(); - assert!(result.description.is_some()); - } - - #[test] - fn error_on_multiple_description_blocks() { - let input1 = block!( - description { - de = "descr_de" - en = "descr_en" - fr = "descr_fr" - } - ); - let input2 = block!( - description { - de = "descr_de" - en = "descr_en" - fr = "descr_fr" - } - ); - let blocks = vec![&input1, &input2]; - let result = ExtractedProjectBlocks::try_from(blocks); - assert!(result.is_err()); - } - - #[test] - fn extract_single_url() { - let input = block!( - url { - href = "https://data.dasch.swiss/dokubib/" - label = "Project Website" - } - ); - let blocks = vec![&input]; - let result = ExtractedProjectBlocks::try_from(blocks).unwrap(); - assert!(result.url.is_some()); - } - - #[test] - fn error_on_multiple_url_blocks() { - let input1 = block!( - url { - href = "https://data.dasch.swiss/dokubib/" - label = "Project Website" - } - ); - let input2 = block!( - url { - href = "https://data.dasch.swiss/dokubib/" - label = "Project Website" - } - ); - let blocks = vec![&input1, &input2]; - let result = ExtractedProjectBlocks::try_from(blocks); - assert!(result.is_err()); - } - - #[test] - fn extract_keywords() { - let input1 = block!( - keyword { - de = "keyword1_de" - en = "keyword1_en" - fr = "keyword1_fr" - } - - ); - let input2 = block!( - keyword { - de = "keyword2_de" - en = "keyword2_en" - fr = "keyword2_fr" - } - ); - let blocks = vec![&input1, &input2]; - let result = ExtractedProjectBlocks::try_from(blocks).unwrap(); - assert_eq!(result.keywords.len(), 2); - } - - #[test] - fn extract_disciplines() { - let input1 = block!( - discipline skos { - ref_id = "https://skos.um.es/unesco6/5501" - description = "Local history" - url = "https://skos.um.es/unesco6/5501" - } - ); - let blocks = vec![&input1]; - let result = ExtractedProjectBlocks::try_from(blocks).unwrap(); - assert_eq!(result.disciplines.len(), 1); - } - - #[test] - fn extract_spatial_coverages() { - let input1 = block!( - spatial_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.spatial_coverages.len(), 1); - } - - #[test] - fn extract_temporal_coverage() { - let input1 = block!( - temporal_coverage chronontology { - ref_id = "https://chronontology.dainst.org/period/INtagfT8h7Fs" - description = "20th and 21st Centuries" - url = "https://chronontology.dainst.org/period/INtagfT8h7Fs" - } - ); - let blocks = vec![&input1]; - let result = ExtractedProjectBlocks::try_from(blocks).unwrap(); - assert_eq!(result.temporal_coverages.len(), 1); - } - - #[test] - fn extract_publications() { - let input1 = block!( - publication { - text = "A publication" - } - ); - let blocks = vec![&input1]; - let result = ExtractedProjectBlocks::try_from(blocks).unwrap(); - assert_eq!(result.publications.len(), 1); - } - - #[traced_test] - #[test] - fn warn_on_unknown_block() { - let block = hcl::Block::new(Identifier::new("gugus").unwrap()); - let blocks = vec![&block]; - let _ = ExtractedProjectBlocks::try_from(blocks); - - assert!(logs_contain("Parse error: unknown block 'gugus'")); - } -} diff --git a/dsp-meta/src/api/convert/hcl/entity/project/mod.rs b/dsp-meta/src/api/convert/hcl/entity/project/mod.rs deleted file mode 100644 index 3c24bc6b..00000000 --- a/dsp-meta/src/api/convert/hcl/entity/project/mod.rs +++ /dev/null @@ -1,281 +0,0 @@ -use dsp_domain::metadata::entity::project::Project; -use extracted_project_attributes::ExtractedProjectAttributes; -use extracted_project_blocks::ExtractedProjectBlocks; - -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -pub(crate) mod extracted_project_attributes; -pub(crate) mod extracted_project_blocks; - -impl<'a> TryInto<Project> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Project, Self::Error> { - if self.0.identifier.as_str() != "project" { - return Err(DspMetaError::ParseProject( - format!( - "Parse error: project block needs to be named 'project', however got '{}' instead.", - self.0.identifier.as_str() - ) - .to_string(), - )); - } - - // extract the project attributes - // created_at, created_by, shortcode, name, teaser_text, how_to_cite, start_date, end_date, - // datasets (1-n), funders, grants - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - - let extracted_attributes = ExtractedProjectAttributes::try_from(attributes)?; - - let id = extracted_attributes.id.ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have an id.".to_string(), - ))?; - - let created_at = extracted_attributes - .created_at - .ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a created_at value.".to_string(), - ))?; - - let created_by = extracted_attributes - .created_by - .ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a created_by value.".to_string(), - ))?; - - let shortcode = extracted_attributes - .shortcode - .ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a shortcode.".to_string(), - ))?; - - let name = extracted_attributes.name.ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a name.".to_string(), - ))?; - - let teaser_text = extracted_attributes - .teaser_text - .ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a teaser_text.".to_string(), - ))?; - - let how_to_cite = extracted_attributes - .how_to_cite - .ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a how_to_cite.".to_string(), - ))?; - - let start_date = extracted_attributes - .start_date - .ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a start_date.".to_string(), - ))?; - - let end_date = extracted_attributes.end_date; - - let status = extracted_attributes - .status - .ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a status.".to_string(), - ))?; - - let contact_point = extracted_attributes.contact_point; - - let datasets = extracted_attributes.datasets; - - // extract the project blocks - // alternative_names (0-n), description (1), url (1), keywords (1-n), disciplines (1-n), - // publications (0-n) - - let blocks: Vec<&hcl::Block> = self.0.body.blocks().collect(); - let extracted_blocks = ExtractedProjectBlocks::try_from(blocks)?; - - let alternative_names = extracted_blocks.alternative_names; - let description = extracted_blocks - .description - .ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a description.".to_string(), - ))?; - let url = extracted_blocks.url.ok_or(DspMetaError::ParseProject( - "Parse error: project needs to have a url.".to_string(), - ))?; - let keywords = if !extracted_blocks.keywords.is_empty() { - Ok(extracted_blocks.keywords) - } else { - Err(DspMetaError::ParseProject( - "Parse error: project needs to have at least one keyword.".to_string(), - )) - }?; - let disciplines = if !extracted_blocks.disciplines.is_empty() { - Ok(extracted_blocks.disciplines) - } else { - Err(DspMetaError::ParseProject( - "Parse error: project needs to have at least one discipline.".to_string(), - )) - }?; - let publications = extracted_blocks.publications; - - let project = Project { - id, - created_at, - created_by, - shortcode, - name, - alternative_names, - teaser_text, - description, - url, - how_to_cite, - start_date, - end_date, - status, - contact_point, - keywords, - disciplines, - publications, - datasets, - }; - - Ok(project) - } -} - -#[cfg(test)] -mod tests { - use std::collections::HashMap; - - use dsp_domain::metadata::entity::project::Project; - use dsp_domain::metadata::value::description::Description; - use dsp_domain::metadata::value::discipline::Discipline; - use dsp_domain::metadata::value::identifier::{DatasetId, ProjectId}; - use dsp_domain::metadata::value::iso_code::IsoCode; - use dsp_domain::metadata::value::keyword::Keyword; - use dsp_domain::metadata::value::ref_data::RefData; - use dsp_domain::metadata::value::url::Url; - use dsp_domain::metadata::value::{ - ContactPoint, CreatedAt, CreatedBy, EndDate, HowToCite, Name, Shortcode, StartDate, - TeaserText, - }; - use hcl::block; - use tracing_test::traced_test; - - use crate::api::convert::hcl::hcl_block::HclBlock; - - #[traced_test] - #[test] - fn test_convert_project_block() { - let input_project_block = block!( - project { - id = "p1" - created_at = 1630601274523025000u64 // FIXME: is there a more readable way to write an i64? - created_by = "dsp-metadata-gui" - shortcode = "0803" - name = "The German Family Panel (pairfam)" - alternative_name "1" { - de = "Der deutsche Familienpanel (pairfam)" - en = "The German Family Panel (pairfam)" - } - teaser_text = "The German Family Panel (pairfam) is a multidisciplinary, longitudinal study." - description { - de = "Der deutsche Familienpanel (pairfam) ist eine multidisziplinäre, längsschnittliche Studie." - en = "The German Family Panel (pairfam) is a multidisciplinary, longitudinal study." - } - url { - href = "https://admin.dasch.swiss/project/081C" - label = "Discover Project Data" - } - how_to_cite = "Huinink, Johannes; Schröder, Carolin; Castiglioni, Laura; Feldhaus, Michael" - start_date = "2009-04-01" - end_date = "2012-03-31" - status = "Ongoing" - keyword { - en = "Bern" - } - discipline snf { - ref_id = "10302" - description = "Schweizer Geschichte" - url = "https://www.snf.ch/SiteCollectionDocuments/allg_disziplinenliste.pdf" - } - contact_point = "project_organization" - datasets = ["ds1", "ds2"] - } - ); - let project: Project = HclBlock(&input_project_block).try_into().unwrap(); - assert_eq!(project.id, ProjectId(String::from("p1"))); - assert_eq!(project.created_at, CreatedAt(1630601274523025000)); - assert_eq!( - project.created_by, - CreatedBy(String::from("dsp-metadata-gui")) - ); - assert_eq!(project.shortcode, Shortcode(String::from("0803"))); - assert_eq!( - project.name, - Name(String::from("The German Family Panel (pairfam)")) - ); - assert_eq!( - project.teaser_text, - TeaserText(String::from( - "The German Family Panel (pairfam) is a multidisciplinary, longitudinal study." - )) - ); - assert_eq!( - project.description, - Description( - HashMap::from_iter( - [ - (IsoCode::DE, "Der deutsche Familienpanel (pairfam) ist eine multidisziplinäre, längsschnittliche Studie.".to_string()), - (IsoCode::EN, "The German Family Panel (pairfam) is a multidisciplinary, longitudinal study.".to_string()) - ] - ) - ) - ); - assert_eq!( - project.url, - Url { - href: url::Url::parse("https://admin.dasch.swiss/project/081C").unwrap(), - label: "Discover Project Data".to_string() - } - ); - assert_eq!( - project.how_to_cite, - HowToCite(String::from( - "Huinink, Johannes; Schröder, Carolin; Castiglioni, Laura; Feldhaus, Michael" - )) - ); - assert_eq!(project.start_date, StartDate(String::from("2009-04-01"))); - assert_eq!(project.end_date, Some(EndDate(String::from("2012-03-31")))); - assert_eq!( - project.status, - dsp_domain::metadata::value::status::Status::Ongoing - ); - assert_eq!( - project.keywords, - vec![Keyword(HashMap::from_iter([( - IsoCode::EN, - "Bern".to_string() - )]))] - ); - assert_eq!( - project.disciplines, - vec![Discipline::Snf(RefData { - ref_id: "10302".to_string(), - description: "Schweizer Geschichte".to_string(), - url: url::Url::parse( - "https://www.snf.ch/SiteCollectionDocuments/allg_disziplinenliste.pdf" - ) - .unwrap() - })] - ); - assert_eq!( - project.contact_point, - Some(ContactPoint(String::from("project_organization"))) - ); - assert_eq!( - project.datasets, - vec![DatasetId("ds1".to_string()), DatasetId("ds2".to_string())] - ); - } -} diff --git a/dsp-meta/src/api/convert/hcl/hcl_attribute.rs b/dsp-meta/src/api/convert/hcl/hcl_attribute.rs deleted file mode 100644 index ec18163b..00000000 --- a/dsp-meta/src/api/convert/hcl/hcl_attribute.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub struct HclAttribute<'a>(pub &'a hcl::Attribute); -pub struct HclAttributes<'a>(pub Vec<&'a hcl::Attribute>); diff --git a/dsp-meta/src/api/convert/hcl/hcl_block.rs b/dsp-meta/src/api/convert/hcl/hcl_block.rs deleted file mode 100644 index d68a9fbb..00000000 --- a/dsp-meta/src/api/convert/hcl/hcl_block.rs +++ /dev/null @@ -1 +0,0 @@ -pub struct HclBlock<'a>(pub &'a hcl::Block); diff --git a/dsp-meta/src/api/convert/hcl/hcl_body.rs b/dsp-meta/src/api/convert/hcl/hcl_body.rs deleted file mode 100644 index 86062da7..00000000 --- a/dsp-meta/src/api/convert/hcl/hcl_body.rs +++ /dev/null @@ -1 +0,0 @@ -pub struct HclBody<'a>(pub &'a hcl::Body); diff --git a/dsp-meta/src/api/convert/hcl/mod.rs b/dsp-meta/src/api/convert/hcl/mod.rs deleted file mode 100644 index 6a837de2..00000000 --- a/dsp-meta/src/api/convert/hcl/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod dsp_meta_error; -mod entity; -pub mod hcl_attribute; -pub mod hcl_block; -pub mod hcl_body; -pub(crate) mod project_metadata; -mod value; diff --git a/dsp-meta/src/api/convert/hcl/project_metadata.rs b/dsp-meta/src/api/convert/hcl/project_metadata.rs deleted file mode 100644 index 5e51888c..00000000 --- a/dsp-meta/src/api/convert/hcl/project_metadata.rs +++ /dev/null @@ -1,121 +0,0 @@ -use dsp_domain::metadata::entity::dataset::Dataset; -use dsp_domain::metadata::entity::project::Project; -use dsp_domain::metadata::entity::project_metadata::ProjectMetadata; -use dsp_domain::metadata::value::version::Version; - -use crate::api::convert::hcl::hcl_attribute::HclAttribute; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::api::convert::hcl::hcl_body::HclBody; -use crate::error::DspMetaError; - -impl<'a> TryInto<ProjectMetadata> for HclBody<'a> { - type Error = DspMetaError; - - /// Converts an `hcl::Body` into `ProjectMetadata` by consuming the - /// input. This operation can fail. - fn try_into(self) -> Result<ProjectMetadata, Self::Error> { - let mut maybe_version: Option<Version> = None; - let mut maybe_project: Option<Project> = None; - let mut maybe_datasets: Vec<Dataset> = vec![]; - - let attributes: Vec<&hcl::Attribute> = self.0.attributes().collect(); - for attribute in attributes { - match attribute.key() { - "version" => maybe_version = Some(HclAttribute(attribute).try_into()?), - _ => { - continue; - } - } - } - - let blocks: Vec<&hcl::Block> = self.0.blocks().collect(); - for block in blocks { - match block.identifier() { - "project" => { - if maybe_project.is_some() { - return Err(DspMetaError::ParseProject( - "Only one project block allowed.".to_string(), - )); - } else { - maybe_project = Some(HclBlock(block).try_into()?) - } - } - "dataset" => maybe_datasets.push(HclBlock(block).try_into()?), - _ => { - continue; - } - } - } - - // Validate that the version is provided - let version = maybe_version.ok_or_else(|| { - DspMetaError::ParseVersion("Version attribute is not provided.".to_string()) - })?; - - // Validate that the project is provided - let project = maybe_project.ok_or_else(|| { - DspMetaError::ParseProject("Project block is not provided.".to_string()) - })?; - - // Validate that at least one dataset is provided - let datasets = if !maybe_datasets.is_empty() { - maybe_datasets - } else { - return Err(DspMetaError::ParseProject( - "At least one dataset block needs to be provided.".to_string(), - )); - }; - - // Validate that all referenced datasets exist - for dataset in &project.datasets { - if !datasets.iter().any(|d| d.id == *dataset) { - return Err(DspMetaError::ParseProject(format!( - "Dataset with id '{:?}' referenced in project block does not exist.", - dataset - ))); - } - } - - let metadata = ProjectMetadata { - version, - project, - datasets, - grants: Vec::new(), - organizations: Vec::new(), - persons: Vec::new(), - }; - Ok(metadata) - } -} - -#[cfg(test)] -mod tests { - use dsp_domain::metadata::entity::project_metadata::ProjectMetadata; - use hcl::body; - - use crate::api::convert::hcl::hcl_body::HclBody; - use crate::error::DspMetaError; - - #[test] - fn try_from_multiple_projects_error() { - let input = body!( - project { - shortcode = "0803" - } - project { - shortcode = "0804" - } - ); - - let project: Result<ProjectMetadata, DspMetaError> = HclBody(&input).try_into(); - assert!(project.is_err()); - } - - #[test] - fn try_from_no_project_error() { - let input = body!(); - - let project: Result<ProjectMetadata, DspMetaError> = HclBody(&input).try_into(); - assert!(project.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/abstract.rs b/dsp-meta/src/api/convert/hcl/value/abstract.rs deleted file mode 100644 index edaa4daa..00000000 --- a/dsp-meta/src/api/convert/hcl/value/abstract.rs +++ /dev/null @@ -1,77 +0,0 @@ -use dsp_domain::metadata::value::lang_text_data::LangTextData; -use dsp_domain::metadata::value::r#abstract::Abstract; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const ABSTRACT_BLOCK_IDENTIFIER: &str = "abstract"; - -impl<'a> TryInto<Abstract> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Abstract, Self::Error> { - if self.0.identifier.as_str() != ABSTRACT_BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected '{}', however got '{}' instead.", - ABSTRACT_BLOCK_IDENTIFIER, - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - - // FIXME: improve API - let lang_text_data: Result<LangTextData, DspMetaError> = - HclAttributes(attributes).try_into(); - lang_text_data.map(|l| l.into()) - } -} - -#[cfg(test)] -mod tests { - use std::collections::HashMap; - - use dsp_domain::metadata::value::iso_code::IsoCode; - use dsp_domain::metadata::value::r#abstract::Abstract; - - use crate::api::convert::hcl::hcl_block::HclBlock; - use crate::error::DspMetaError; - - #[test] - fn test_try_from_correct_block() { - let block = hcl::block!( - abstract { - de = "Die Zusammenfassung" - en = "The abstract" - fr = "Le résumé" - } - ); - - let result: Abstract = HclBlock(&block).try_into().unwrap(); - - let mut map = HashMap::new(); - map.insert(IsoCode::DE, String::from("Die Zusammenfassung")); - map.insert(IsoCode::EN, String::from("The abstract")); - map.insert(IsoCode::FR, String::from("Le résumé")); - let expected = Abstract(map); - - assert_eq!(result, expected); - } - - #[test] - fn test_try_from_incorrect_block() { - let block = hcl::block!( - other_block_name { - de = "Die Zusammenfassung" - en = "The abstract" - fr = "Le résumé" - } - ); - - let result: Result<Abstract, DspMetaError> = HclBlock(&block).try_into(); - - assert!(result.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/alternative_name.rs b/dsp-meta/src/api/convert/hcl/value/alternative_name.rs deleted file mode 100644 index effddfa0..00000000 --- a/dsp-meta/src/api/convert/hcl/value/alternative_name.rs +++ /dev/null @@ -1,74 +0,0 @@ -use dsp_domain::metadata::value::alternative_name::AlternativeName; -use dsp_domain::metadata::value::lang_text_data::LangTextData; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const ALTERNATIVE_NAME_BLOCK_IDENTIFIER: &str = "alternative_name"; - -impl<'a> TryInto<AlternativeName> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<AlternativeName, Self::Error> { - if self.0.identifier.as_str() != ALTERNATIVE_NAME_BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected '{}', however got '{}' instead.", - ALTERNATIVE_NAME_BLOCK_IDENTIFIER, - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - - // FIXME: improve API - let lang_text_data: Result<LangTextData, DspMetaError> = - HclAttributes(attributes).try_into(); - lang_text_data.map(|l| l.into()) - } -} - -#[cfg(test)] -mod tests { - use std::collections::HashMap; - - use dsp_domain::metadata::value::iso_code::IsoCode; - - use super::*; - - #[test] - fn test_try_into_from_correct_block() { - let block = hcl::block!( - alternative_name { - de = "Der alternative Name" - en = "The alternative name" - fr = "Le alternative name" - } - ); - - let alternative_name: AlternativeName = HclBlock(&block).try_into().unwrap(); - let mut map: HashMap<IsoCode, String> = HashMap::new(); - map.insert(IsoCode::DE, String::from("Der alternative Name")); - map.insert(IsoCode::EN, String::from("The alternative name")); - map.insert(IsoCode::FR, String::from("Le alternative name")); - let expected = AlternativeName(map); - - assert_eq!(alternative_name, expected); - } - - #[test] - fn test_try_into_from_incorrect_block() { - let block = hcl::block!( - alternative_name_other { - de = "Der alternative Name" - en = "The alternative name" - fr = "Le alternative name" - } - ); - - let alternative_name: Result<AlternativeName, DspMetaError> = HclBlock(&block).try_into(); - - assert!(alternative_name.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/attribution.rs b/dsp-meta/src/api/convert/hcl/value/attribution.rs deleted file mode 100644 index 321d2739..00000000 --- a/dsp-meta/src/api/convert/hcl/value/attribution.rs +++ /dev/null @@ -1,130 +0,0 @@ -use dsp_domain::metadata::value::attribution::Attribution; -use dsp_domain::metadata::value::identifier::AgentId; -use tracing::warn; - -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const BLOCK_IDENTIFIER: &str = "attribution"; -const AGENT_ATTRIBUTE_KEY: &str = "agent"; -const ROLES_ATTRIBUTE_KEY: &str = "roles"; - -impl<'a> TryInto<Attribution> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Attribution, Self::Error> { - if self.0.identifier.as_str() != BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected '{}', however got '{}' instead.", - BLOCK_IDENTIFIER, - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let mut maybe_agent: Option<AgentId> = None; - let mut maybe_roles: Vec<String> = vec![]; - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - for attribute in attributes { - match attribute.key() { - AGENT_ATTRIBUTE_KEY => { - if maybe_agent.is_some() { - return Err(DspMetaError::CreateValueObject( - format!("The passed {BLOCK_IDENTIFIER} block contains multiple {AGENT_ATTRIBUTE_KEY} attributes.") - .to_string(), - )); - } - maybe_agent = match attribute.expr() { - hcl::Expression::String(value) => Ok(Some(AgentId(value.to_owned()))), - _ => Err(DspMetaError::CreateValueObject( - format!("The passed {BLOCK_IDENTIFIER} block {AGENT_ATTRIBUTE_KEY} attribute is not of String type.").to_string(), - )), - }?; - }, - ROLES_ATTRIBUTE_KEY => { - match attribute.expr() { - hcl::Expression::Array(values) => { - for value in values { - match value { - hcl::Expression::String(value) => maybe_roles.push(value.to_owned()), - _ => { - return Err(DspMetaError::CreateValueObject( - format!("The passed {BLOCK_IDENTIFIER} block {ROLES_ATTRIBUTE_KEY} attribute is not of String type.").to_string(), - )) - } - } - } - } - _ => { - return Err(DspMetaError::CreateValueObject( - format!("The passed {BLOCK_IDENTIFIER} block {ROLES_ATTRIBUTE_KEY} attribute is not of List type.").to_string(), - )) - } - } - } - _ => { - warn!("Parse error: unknown attribute '{}'.", attribute.key()); - } - } - } - - let agent = maybe_agent.ok_or( - DspMetaError::CreateValueObject( - format!("The passed {BLOCK_IDENTIFIER} block does not contain a {AGENT_ATTRIBUTE_KEY} attribute.") - .to_string(), - ) - )?; - - let roles = if !maybe_roles.is_empty() { - Ok(maybe_roles) - } else { - Err(DspMetaError::CreateValueObject( - format!("The passed {BLOCK_IDENTIFIER} block does not contain a {ROLES_ATTRIBUTE_KEY} attribute.") - .to_string(), - )) - }?; - - Ok(Attribution { agent, roles }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_try_from_correct_block() { - let block = hcl::block!( - attribution { - agent = "http://ns.dasch.swiss/repository#dsp-081C-organization-000" // reference to person or organization - roles = ["Author"] - } - ); - - let result: Attribution = HclBlock(&block).try_into().unwrap(); - - let expected = Attribution { - agent: AgentId(String::from( - "http://ns.dasch.swiss/repository#dsp-081C-organization-000", - )), - roles: vec![String::from("Author")], - }; - - assert_eq!(result, expected); - } - - #[test] - fn test_try_from_incorrect_block() { - let block = hcl::block!( - other_block { - agent = "http://ns.dasch.swiss/repository#dsp-081C-organization-000" // reference to person or organization - roles = ["Author"] - } - ); - - let result: Result<Attribution, DspMetaError> = HclBlock(&block).try_into(); - - assert!(result.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/description.rs b/dsp-meta/src/api/convert/hcl/value/description.rs deleted file mode 100644 index 5af3fcc3..00000000 --- a/dsp-meta/src/api/convert/hcl/value/description.rs +++ /dev/null @@ -1,77 +0,0 @@ -use dsp_domain::metadata::value::description::Description; -use dsp_domain::metadata::value::lang_text_data::LangTextData; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const DESCRIPTION_BLOCK_IDENTIFIER: &str = "description"; - -impl<'a> TryInto<Description> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Description, Self::Error> { - if self.0.identifier.as_str() != DESCRIPTION_BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected '{}', however got '{}' instead.", - DESCRIPTION_BLOCK_IDENTIFIER, - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - - // FIXME: improve API - let lang_text_data: Result<LangTextData, DspMetaError> = - HclAttributes(attributes).try_into(); - lang_text_data.map(|l| l.into()) - } -} - -#[cfg(test)] -mod tests { - use std::collections::HashMap; - - use dsp_domain::metadata::value::description::*; - use dsp_domain::metadata::value::iso_code::IsoCode; - - use crate::api::convert::hcl::hcl_block::HclBlock; - use crate::error::DspMetaError; - - #[test] - fn test_try_from_correct_block() { - let block = hcl::block!( - description { - de = "Die Beschreibung" - en = "The description" - fr = "La description" - } - ); - - let description: Description = HclBlock(&block).try_into().unwrap(); - - let mut map = HashMap::new(); - map.insert(IsoCode::DE, String::from("Die Beschreibung")); - map.insert(IsoCode::EN, String::from("The description")); - map.insert(IsoCode::FR, String::from("La description")); - let expected = Description(map); - - assert_eq!(description, expected); - } - - #[test] - fn test_try_from_incorrect_block() { - let block = hcl::block!( - description_other { - de = "Die Beschreibung" - en = "The description" - fr = "La description" - } - ); - - let description: Result<Description, DspMetaError> = HclBlock(&block).try_into(); - - assert!(description.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/discipline.rs b/dsp-meta/src/api/convert/hcl/value/discipline.rs deleted file mode 100644 index ca00950b..00000000 --- a/dsp-meta/src/api/convert/hcl/value/discipline.rs +++ /dev/null @@ -1,107 +0,0 @@ -use dsp_domain::metadata::value::discipline::Discipline; -use dsp_domain::metadata::value::lang_text_data::LangTextData; -use dsp_domain::metadata::value::ref_data::RefData; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -impl<'a> TryInto<Discipline> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Discipline, Self::Error> { - if self.0.identifier.as_str() != "discipline" { - let msg = format!( - "The passed block is not named correctly. Expected 'discipline', however got '{}' instead.", - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - if self.0.labels.len() != 1 { - return Err(DspMetaError::CreateValueObject("The passed number of block labels is not correct. Expected '1', namely 'reference data type' (e.g., 'skos').".to_string())); - } - - let reference_data_type = self.0.labels.first().ok_or_else(|| { - DspMetaError::CreateValueObject( - "The passed discipline block is missing the reference data type label.".to_string(), - ) - })?; - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - - match reference_data_type.as_str() { - "skos" => { - let ref_data: RefData = HclAttributes(attributes).try_into()?; - Ok(Discipline::Skos(ref_data)) - } - "snf" => { - let ref_data: RefData = HclAttributes(attributes).try_into()?; - Ok(Discipline::Snf(ref_data)) - } - "text" => { - let text_data: LangTextData = HclAttributes(attributes).try_into()?; - Ok(Discipline::Text(text_data)) - } - _ => { - Err(DspMetaError::CreateValueObject("The passed discipline block is missing the correct reference data type label: 'skos', 'snf', or 'text'.".to_string())) - } - } - } -} - -#[cfg(test)] -mod tests { - - use dsp_domain::metadata::value::discipline::*; - use dsp_domain::metadata::value::iso_code::IsoCode; - use tracing_test::traced_test; - - use super::*; - - #[test] - #[traced_test] - fn test_try_from_block_with_skos() { - let block = hcl::block!( - discipline skos { - ref_id = "https://skos.um.es/unesco6/5501" - description = "Local history" - url = "https://skos.um.es/unesco6/5501" - } - ); - - let input: Discipline = HclBlock(&block).try_into().unwrap(); - let expected = Discipline::Skos(RefData { - ref_id: "https://skos.um.es/unesco6/5501".to_string(), - description: "Local history".to_string(), - url: url::Url::parse("https://skos.um.es/unesco6/5501").unwrap(), - }); - - assert_eq!(input, expected); - } - - #[test] - #[traced_test] - fn test_try_from_block_with_text() { - let block = hcl::block!( - discipline text { - de = "Lokalgeschichte" - en = "Local history" - fr = "Histoire locale" - } - ); - - let input: Discipline = HclBlock(&block).try_into().unwrap(); - let expected = Discipline::Text(LangTextData( - vec![ - (IsoCode::DE, "Lokalgeschichte".to_string()), - (IsoCode::EN, "Local history".to_string()), - (IsoCode::FR, "Histoire locale".to_string()), - ] - .into_iter() - .collect(), - )); - - assert_eq!(input, expected); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/keyword.rs b/dsp-meta/src/api/convert/hcl/value/keyword.rs deleted file mode 100644 index ebd1f2b5..00000000 --- a/dsp-meta/src/api/convert/hcl/value/keyword.rs +++ /dev/null @@ -1,76 +0,0 @@ -use dsp_domain::metadata::value::keyword::Keyword; -use dsp_domain::metadata::value::lang_text_data::LangTextData; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const KEYWORD_BLOCK_IDENTIFIER: &str = "keyword"; - -impl<'a> TryInto<Keyword> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Keyword, Self::Error> { - if self.0.identifier.as_str() != KEYWORD_BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected '{}', however got '{}' instead.", - KEYWORD_BLOCK_IDENTIFIER, - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - // FIXME: improve API - let lang_text_data: Result<LangTextData, DspMetaError> = - HclAttributes(attributes).try_into(); - lang_text_data.map(|l| l.into()) - } -} - -#[cfg(test)] -mod tests { - use std::collections::HashMap; - - use dsp_domain::metadata::value::iso_code::IsoCode; - use dsp_domain::metadata::value::keyword::*; - - use crate::api::convert::hcl::hcl_block::HclBlock; - use crate::error::DspMetaError; - - #[test] - fn test_try_from_correct_block() { - let block = hcl::block!( - keyword { - de = "Der keyword" - en = "The keyword" - fr = "Le keyword" - } - ); - - let keyword: Keyword = HclBlock(&block).try_into().unwrap(); - - let mut map: HashMap<IsoCode, String> = HashMap::new(); - map.insert(IsoCode::DE, String::from("Der keyword")); - map.insert(IsoCode::EN, String::from("The keyword")); - map.insert(IsoCode::FR, String::from("Le keyword")); - let expected = Keyword(map); - - assert_eq!(keyword, expected); - } - - #[test] - fn test_try_from_incorrect_block() { - let block = hcl::block!( - keyword_other { - de = "Der keyword" - en = "The keyword" - fr = "Le keyword" - } - ); - - let keyword: Result<Keyword, DspMetaError> = HclBlock(&block).try_into(); - - assert!(keyword.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/lang_text_data.rs b/dsp-meta/src/api/convert/hcl/value/lang_text_data.rs deleted file mode 100644 index 5b05d9dd..00000000 --- a/dsp-meta/src/api/convert/hcl/value/lang_text_data.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::collections::HashMap; - -use dsp_domain::metadata::value::iso_code::IsoCode; -use dsp_domain::metadata::value::lang_text_data::LangTextData; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::error::DspMetaError; - -impl<'a> TryInto<LangTextData> for HclAttributes<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<LangTextData, Self::Error> { - let mut text_data: HashMap<IsoCode, String> = HashMap::new(); - - for attribute in self.0 { - 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 attribute value is not of String type.".to_string(), - )), - }?; - - text_data.insert(iso_code, text); - } - - Ok(LangTextData(text_data)) - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/language.rs b/dsp-meta/src/api/convert/hcl/value/language.rs deleted file mode 100644 index edaed62a..00000000 --- a/dsp-meta/src/api/convert/hcl/value/language.rs +++ /dev/null @@ -1,78 +0,0 @@ -use dsp_domain::metadata::value::lang_text_data::LangTextData; -use dsp_domain::metadata::value::language::Language; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const BLOCK_IDENTIFIER: &str = "language"; - -impl<'a> TryInto<Language> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Language, Self::Error> { - if self.0.identifier.as_str() != BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected '{}', however got '{}' instead.", - BLOCK_IDENTIFIER, - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - - // FIXME: improve API - let lang_text_data: Result<LangTextData, DspMetaError> = - HclAttributes(attributes).try_into(); - lang_text_data.map(|l| l.into()) - } -} - -#[cfg(test)] -mod tests { - use std::collections::HashMap; - - use dsp_domain::metadata::value::description::*; - use dsp_domain::metadata::value::iso_code::IsoCode; - use dsp_domain::metadata::value::language::Language; - - use crate::api::convert::hcl::hcl_block::HclBlock; - use crate::error::DspMetaError; - - #[test] - fn test_try_from_correct_block() { - let block = hcl::block!( - language { - de = "Deutsch" - en = "German" - fr = "Allemand" - } - ); - - let result: Language = HclBlock(&block).try_into().unwrap(); - - let mut map = HashMap::new(); - map.insert(IsoCode::DE, String::from("Deutsch")); - map.insert(IsoCode::EN, String::from("German")); - map.insert(IsoCode::FR, String::from("Allemand")); - let expected = Language(map); - - assert_eq!(result, expected); - } - - #[test] - fn test_try_from_incorrect_block() { - let block = hcl::block!( - other_block { - de = "Deutsch" - en = "German" - fr = "Allemand" - } - ); - - let result: Result<Description, DspMetaError> = HclBlock(&block).try_into(); - - assert!(result.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/license.rs b/dsp-meta/src/api/convert/hcl/value/license.rs deleted file mode 100644 index 256a7841..00000000 --- a/dsp-meta/src/api/convert/hcl/value/license.rs +++ /dev/null @@ -1,170 +0,0 @@ -use dsp_domain::metadata::value::license::License; -use tracing::warn; - -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const LICENSE_BLOCK_IDENTIFIER: &str = "license"; -const TYPE_ATTRIBUTE_KEY: &str = "type"; -const HREF_ATTRIBUTE_KEY: &str = "href"; -const DATE_ATTRIBUTE_KEY: &str = "date"; -const LABEL_ATTRIBUTE_KEY: &str = "label"; - -impl<'a> TryInto<License> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<License, Self::Error> { - if self.0.identifier.as_str() != LICENSE_BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected '{}', however got '{}' instead.", - LICENSE_BLOCK_IDENTIFIER, - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let mut type_: Option<String> = None; - let mut href: Option<url::Url> = None; - let mut date: Option<String> = None; - let mut label: Option<String> = None; - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - for attribute in attributes { - match attribute.key() { - TYPE_ATTRIBUTE_KEY => { - if type_.is_some() { - return Err(DspMetaError::CreateValueObject( - format!("The passed {LICENSE_BLOCK_IDENTIFIER} block contains multiple {TYPE_ATTRIBUTE_KEY} attributes.") - .to_string(), - )); - } - type_ = match attribute.expr() { - hcl::Expression::String(value) => Ok(Some(value.to_owned())), - _ => Err(DspMetaError::CreateValueObject( - format!("The passed {LICENSE_BLOCK_IDENTIFIER} block {TYPE_ATTRIBUTE_KEY} attribute is not of String type.").to_string(), - )), - }?; - } - HREF_ATTRIBUTE_KEY => { - if href.is_some() { - return Err(DspMetaError::CreateValueObject( - format!("Multiple {TYPE_ATTRIBUTE_KEY} attributes not allowed.") - .to_string(), - )); - } - href = match attribute.expr() { - hcl::Expression::String(value) => { - Ok(Some(url::Url::parse(value).map_err(|_| { - DspMetaError::CreateValueObject( - format!("The passed {LICENSE_BLOCK_IDENTIFIER} block {TYPE_ATTRIBUTE_KEY} attribute is not a valid URL.") - .to_string(), - ) - })?)) - } - _ => Err(DspMetaError::CreateValueObject( - "The value for the href attribute is not of String type.".to_string(), - )), - }?; - } - DATE_ATTRIBUTE_KEY => { - if date.is_some() { - return Err(DspMetaError::CreateValueObject( - format!("Multiple {DATE_ATTRIBUTE_KEY} attributes not allowed.") - .to_string(), - )); - } - date = match attribute.expr() { - hcl::Expression::String(value) => Ok(Some(value.to_owned())), - _ => Err(DspMetaError::CreateValueObject( - format!("The passed {LICENSE_BLOCK_IDENTIFIER} block {DATE_ATTRIBUTE_KEY} attribute is not of String type.").to_string(), - )), - }?; - } - LABEL_ATTRIBUTE_KEY => { - if label.is_some() { - return Err(DspMetaError::CreateValueObject( - format!("The passed {LICENSE_BLOCK_IDENTIFIER} block contains multiple {LABEL_ATTRIBUTE_KEY} attributes.") - .to_string(), - )); - } - label = match attribute.expr() { - hcl::Expression::String(value) => Ok(Some(value.to_owned())), - _ => Err(DspMetaError::CreateValueObject( - format!("The passed {LICENSE_BLOCK_IDENTIFIER} block {LABEL_ATTRIBUTE_KEY} attribute is not of String type.").to_string(), - )), - }?; - } - _ => { - warn!("Parse error: unknown attribute '{}'.", attribute.key()); - } - } - } - - Ok(License { - license_type: type_.ok_or_else(|| { - DspMetaError::CreateDomainObject( - "The required href attribute is missing.".to_string(), - ) - })?, - href: href.ok_or_else(|| { - DspMetaError::CreateDomainObject( - "The required href attribute is missing.".to_string(), - ) - })?, - date: date.ok_or_else(|| { - DspMetaError::CreateDomainObject( - "The required date attribute is missing.".to_string(), - ) - })?, - label: label.ok_or_else(|| { - DspMetaError::CreateDomainObject( - "The required label attribute is missing.".to_string(), - ) - })?, - }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_try_from_correct_block() { - let block = hcl::block!( - license { - type = "creative_commons" - href = "https://www.google.com" - date = "2021-09-02" - label = "CC BY-NC 4.0" - } - ); - - let result: License = HclBlock(&block).try_into().unwrap(); - - let expected = License { - license_type: "creative_commons".to_string(), - href: url::Url::try_from("https://www.google.com").unwrap(), - date: "2021-09-02".to_string(), - label: "CC BY-NC 4.0".to_string(), - }; - - assert_eq!(result, expected); - } - - #[test] - fn test_try_from_incorrect_block() { - let block = hcl::block!( - other_block { - type = "creative_commons" - href = "https://www.google.com" - date = "2021-09-02" - label = "CC BY-NC 4.0" - } - ); - - let result: Result<License, DspMetaError> = HclBlock(&block).try_into(); - - assert!(result.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/mod.rs b/dsp-meta/src/api/convert/hcl/value/mod.rs deleted file mode 100644 index f04cdd97..00000000 --- a/dsp-meta/src/api/convert/hcl/value/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -mod r#abstract; -mod alternative_name; -mod attribution; -mod description; -mod discipline; -mod keyword; -mod lang_text_data; -mod language; -mod license; -mod publication; -mod ref_data; -mod simple_text_data; -mod spatial_coverage; -mod temporal_coverage; -mod url; -mod version; diff --git a/dsp-meta/src/api/convert/hcl/value/publication.rs b/dsp-meta/src/api/convert/hcl/value/publication.rs deleted file mode 100644 index 0c1caae5..00000000 --- a/dsp-meta/src/api/convert/hcl/value/publication.rs +++ /dev/null @@ -1,66 +0,0 @@ -use dsp_domain::metadata::value::publication::Publication; -use dsp_domain::metadata::value::simple_text_data::SimpleTextData; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const PUBLICATION_BLOCK_IDENTIFIER: &str = "publication"; - -impl<'a> TryInto<Publication> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Publication, Self::Error> { - if self.0.identifier.as_str() != PUBLICATION_BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected 'publication', however got '{}' instead.", - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - let simple_text_data: Result<SimpleTextData, DspMetaError> = - HclAttributes(attributes).try_into(); - simple_text_data.map(|s| s.to_simple_text()) - } -} - -#[cfg(test)] -mod tests { - use dsp_domain::metadata::value::publication::*; - use dsp_domain::metadata::value::simple_text_data::SimpleTextData; - - use crate::api::convert::hcl::hcl_block::HclBlock; - use crate::error::DspMetaError; - - #[test] - fn test_try_from_correct_block() { - let block = hcl::block!( - publication { - text = "A publication" - } - ); - - let publication: Publication = HclBlock(&block).try_into().unwrap(); - - match publication { - Publication::SimpleText(data) => { - assert_eq!(data, SimpleTextData("A publication".to_string())); - } - } - } - - #[test] - fn test_try_from_incorrect_block() { - let block = hcl::block!( - publication_other { - text = "A publication" - } - ); - - let publication: Result<Publication, DspMetaError> = HclBlock(&block).try_into(); - - assert!(publication.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/ref_data.rs b/dsp-meta/src/api/convert/hcl/value/ref_data.rs deleted file mode 100644 index f32b32a6..00000000 --- a/dsp-meta/src/api/convert/hcl/value/ref_data.rs +++ /dev/null @@ -1,88 +0,0 @@ -use dsp_domain::metadata::value::ref_data::RefData; -use tracing::warn; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::error::DspMetaError; - -/// 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<'a> TryInto<RefData> for HclAttributes<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<RefData, Self::Error> { - let mut ref_id: Option<String> = None; - let mut description: Option<String> = None; - let mut url: Option<url::Url> = None; - - for attribute in self.0 { - 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/dsp-meta/src/api/convert/hcl/value/simple_text_data.rs b/dsp-meta/src/api/convert/hcl/value/simple_text_data.rs deleted file mode 100644 index b3b1def1..00000000 --- a/dsp-meta/src/api/convert/hcl/value/simple_text_data.rs +++ /dev/null @@ -1,85 +0,0 @@ -use dsp_domain::metadata::value::simple_text_data::SimpleTextData; -use tracing::warn; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::error::DspMetaError; - -const TEXT_ATTRIBUTE_IDENTIFIER: &str = "text"; - -impl<'a> TryInto<SimpleTextData> for HclAttributes<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<SimpleTextData, Self::Error> { - let mut text_attribute_value: Option<String> = None; - - for attribute in self.0 { - match attribute.key() { - TEXT_ATTRIBUTE_IDENTIFIER => { - if text_attribute_value.is_some() { - return Err(DspMetaError::CreateValueObject( - "Multiple text attributes are not allowed.".to_string(), - )); - } - text_attribute_value = match attribute.expr() { - hcl::Expression::String(value) => Ok(Some(value.to_owned())), - _ => Err(DspMetaError::CreateValueObject( - "The attribute value is not of String type.".to_string(), - )), - }?; - } - _ => { - warn!("Parse error: unknown attribute '{}'.", attribute.key()); - } - } - } - Ok(SimpleTextData(text_attribute_value.ok_or_else(|| { - DspMetaError::CreateValueObject("Missing text attribute.".to_string()) - })?)) - } -} - -#[cfg(test)] -mod tests { - - use dsp_domain::metadata::value::simple_text_data::*; - use tracing_test::traced_test; - - use crate::api::convert::hcl::hcl_attribute::HclAttributes; - use crate::error::DspMetaError; - - #[test] - fn test_try_from_attributes() { - let attribute = hcl::Attribute::new("text", "some text"); - let text_data: SimpleTextData = HclAttributes(vec![&attribute]).try_into().unwrap(); - assert_eq!(text_data, SimpleTextData("some text".to_string())); - } - - #[traced_test] - #[test] - fn test_try_from_attributes_missing_text() { - let attribute = hcl::Attribute::new("some_other_attribute", "some text"); - let text_data: Result<SimpleTextData, DspMetaError> = - HclAttributes(vec![&attribute]).try_into(); - assert!(text_data.is_err()); - assert!(logs_contain( - "Parse error: unknown attribute 'some_other_attribute'" - )); - } - - #[test] - fn test_try_from_attributes_multiple_text() { - let attribute = hcl::Attribute::new("text", "some text"); - let attribute2 = hcl::Attribute::new("text", "some text"); - let text_data: Result<SimpleTextData, DspMetaError> = - HclAttributes(vec![&attribute, &attribute2]).try_into(); - assert!(text_data.is_err()); - } - - #[test] - fn test_try_from_attributes_wrong_type() { - let attribute = hcl::Attribute::new("text", 1); - let text_data: Result<SimpleTextData, DspMetaError> = - HclAttributes(vec![&attribute]).try_into(); - assert!(text_data.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/spatial_coverage.rs b/dsp-meta/src/api/convert/hcl/value/spatial_coverage.rs deleted file mode 100644 index bf833d2e..00000000 --- a/dsp-meta/src/api/convert/hcl/value/spatial_coverage.rs +++ /dev/null @@ -1,71 +0,0 @@ -use dsp_domain::metadata::value::ref_data::RefData; -use dsp_domain::metadata::value::spatial_coverage::SpatialCoverage; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const SPATIAL_COVERAGE: &str = "spatial_coverage"; -const GEONAMES: &str = "geonames"; - -impl<'a> TryInto<SpatialCoverage> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<SpatialCoverage, Self::Error> { - if self.0.identifier.as_str() != SPATIAL_COVERAGE { - let msg = format!( - "The passed block is not named correctly. Expected 'spatial_coverage', however got '{}' instead.", - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - if self.0.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 = self.0.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> = self.0.body.attributes().collect(); - - match reference_data_type.as_str() { - GEONAMES => { - let ref_data: RefData = HclAttributes(attributes).try_into()?; - Ok(SpatialCoverage::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 super::*; - - #[test] - fn test_try_from_block_with_geonames() { - let block = hcl::block!( - spatial_coverage geonames { - ref_id = "1234" - description = "A description" - url = "https://geonames.org/1234" - } - ); - - let input: SpatialCoverage = HclBlock(&block).try_into().unwrap(); - let expected = SpatialCoverage::Geonames(RefData { - ref_id: "1234".to_string(), - description: "A description".to_string(), - url: "https://geonames.org/1234".parse().unwrap(), - }); - - assert_eq!(input, expected); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/temporal_coverage.rs b/dsp-meta/src/api/convert/hcl/value/temporal_coverage.rs deleted file mode 100644 index 9522bd7e..00000000 --- a/dsp-meta/src/api/convert/hcl/value/temporal_coverage.rs +++ /dev/null @@ -1,86 +0,0 @@ -use dsp_domain::metadata::value::lang_text_data::LangTextData; -use dsp_domain::metadata::value::ref_data::RefData; -use dsp_domain::metadata::value::temporal_coverage::TemporalCoverage; - -use crate::api::convert::hcl::hcl_attribute::HclAttributes; -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const TEMPORAL_COVERAGE: &str = "temporal_coverage"; -const CHRONONTOLOGY: &str = "chronontology"; -const PERIODO: &str = "periodo"; - -const TEXT: &str = "text"; - -impl<'a> TryInto<TemporalCoverage> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<TemporalCoverage, Self::Error> { - if self.0.identifier.as_str() != TEMPORAL_COVERAGE { - let msg = format!( - "The passed block is not named correctly. Expected 'temporal_coverage', however got '{}' instead.", - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - if self.0.labels.len() != 1 { - return Err(DspMetaError::CreateValueObject("The passed number of block labels is not correct. Expected '1', namely 'reference data type' (e.g., 'chronontology, periodo').".to_string())); - } - - let reference_data_type = self.0.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> = self.0.body.attributes().collect(); - - match reference_data_type.as_str() { - CHRONONTOLOGY => { - let ref_data: RefData = HclAttributes(attributes).try_into()?; - Ok(TemporalCoverage::Chronontology(ref_data)) - } - PERIODO => { - let ref_data: RefData = HclAttributes(attributes).try_into()?; - Ok(TemporalCoverage::Periodo(ref_data)) - } - TEXT => { - let text_data: LangTextData = HclAttributes(attributes).try_into()?; - Ok(TemporalCoverage::Text(text_data)) - } - _ => { - let msg = format!("The passed temporal_coverage block is missing the correct reference data type label. Expected one of '{}', '{}' or '{}'. Got '{}'.", CHRONONTOLOGY, PERIODO, TEXT, reference_data_type.as_str()); - Err(DspMetaError::CreateValueObject(msg)) - } - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_try_from_block_with_chonontology() { - let block = hcl::block!( - temporal_coverage chronontology { - ref_id = "https://chronontology.dainst.org/period/INtagfT8h7Fs" - description = "20th and 21st Centuries" - url = "https://chronontology.dainst.org/period/INtagfT8h7Fs" - } - ); - - let input: TemporalCoverage = HclBlock(&block).try_into().unwrap(); - let expected = TemporalCoverage::Chronontology(RefData { - ref_id: "https://chronontology.dainst.org/period/INtagfT8h7Fs".to_string(), - description: "20th and 21st Centuries".to_string(), - url: "https://chronontology.dainst.org/period/INtagfT8h7Fs" - .parse() - .unwrap(), - }); - - assert_eq!(input, expected); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/url.rs b/dsp-meta/src/api/convert/hcl/value/url.rs deleted file mode 100644 index c48e2b40..00000000 --- a/dsp-meta/src/api/convert/hcl/value/url.rs +++ /dev/null @@ -1,121 +0,0 @@ -use dsp_domain::metadata::value::url::Url; -use tracing::warn; - -use crate::api::convert::hcl::hcl_block::HclBlock; -use crate::error::DspMetaError; - -const URL_BLOCK_IDENTIFIER: &str = "url"; -const HREF_ATTRIBUTE_KEY: &str = "href"; -const LABEL_ATTRIBUTE_KEY: &str = "label"; - -impl<'a> TryInto<Url> for HclBlock<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Url, Self::Error> { - if self.0.identifier.as_str() != URL_BLOCK_IDENTIFIER { - let msg = format!( - "The passed block is not named correctly. Expected '{}', however got '{}' instead.", - URL_BLOCK_IDENTIFIER, - self.0.identifier.as_str() - ); - return Err(DspMetaError::CreateValueObject(msg)); - } - - let mut href: Option<url::Url> = None; - let mut label: Option<String> = None; - - let attributes: Vec<&hcl::Attribute> = self.0.body.attributes().collect(); - for attribute in attributes { - match attribute.key() { - LABEL_ATTRIBUTE_KEY => { - if label.is_some() { - return Err(DspMetaError::CreateValueObject( - "The passed discipline block contains multiple description attributes." - .to_string(), - )); - } - label = 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(), - )), - }?; - } - HREF_ATTRIBUTE_KEY => { - if href.is_some() { - return Err(DspMetaError::CreateValueObject( - "Multiple href attributes not allowed.".to_string(), - )); - } - href = 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 value for the href attribute is not of String type.".to_string(), - )), - }?; - } - _ => { - warn!("Parse error: unknown attribute '{}'.", attribute.key()); - } - } - } - - Ok(Url { - href: href.ok_or(DspMetaError::CreateValueObject( - "The required href attribute is missing.".to_string(), - ))?, - label: label.ok_or(DspMetaError::CreateValueObject( - "The required label attribute is missing.".to_string(), - ))?, - }) - } -} - -#[cfg(test)] -mod tests { - - use dsp_domain::metadata::value::url::*; - - use crate::api::convert::hcl::hcl_block::HclBlock; - use crate::error::DspMetaError; - - #[test] - fn test_try_from_correct_block() { - let block = hcl::block!( - url { - href = "https://www.google.com" - label = "Google" - } - ); - - let url: Url = HclBlock(&block).try_into().unwrap(); - - let expected = Url { - href: url::Url::try_from("https://www.google.com").unwrap(), - label: "Google".to_string(), - }; - - assert_eq!(url, expected); - } - - #[test] - fn test_try_from_incorrect_block() { - let block = hcl::block!( - url_other { - href = "https://www.google.com" - label = "Google" - } - ); - - let url: Result<Url, DspMetaError> = HclBlock(&block).try_into(); - - assert!(url.is_err()); - } -} diff --git a/dsp-meta/src/api/convert/hcl/value/version.rs b/dsp-meta/src/api/convert/hcl/value/version.rs deleted file mode 100644 index a6316e1a..00000000 --- a/dsp-meta/src/api/convert/hcl/value/version.rs +++ /dev/null @@ -1,45 +0,0 @@ -use dsp_domain::metadata::value::version::Version; -use hcl::Expression; - -use crate::api::convert::hcl::hcl_attribute::HclAttribute; -use crate::error::DspMetaError; - -/// Given a list of attributes, try to extract the version. -impl<'a> TryInto<Version> for HclAttribute<'a> { - type Error = DspMetaError; - - fn try_into(self) -> Result<Version, Self::Error> { - type Error = crate::error::DspMetaError; - - let mut result: Result<Version, Self::Error> = Err(Error::ParseVersion( - "Version attribute is not provided.".to_string(), - )); - - if self.0.key() == "version" { - result = match self.0.expr() { - Expression::Number(value) => Ok(Version(value.as_u64().ok_or_else(|| { - Error::ParseVersion("Version needs to be a non-negative number.".to_string()) - })?)), - _ => Err(Error::ParseVersion( - "Version needs to be a non-negative number.".to_string(), - )), - } - } - - result - } -} - -#[cfg(test)] -mod tests { - use dsp_domain::metadata::value::version::*; - - use crate::api::convert::hcl::hcl_attribute::HclAttribute; - - #[test] - fn test_try_from_attributes() { - let attribute = hcl::Attribute::new("version", 1u64); - let version: Version = HclAttribute(&attribute).try_into().unwrap(); - assert_eq!(version, Version(1)); - } -} diff --git a/dsp-meta/src/api/convert/mod.rs b/dsp-meta/src/api/convert/mod.rs index 9c49a5a8..e2d4eff1 100644 --- a/dsp-meta/src/api/convert/mod.rs +++ b/dsp-meta/src/api/convert/mod.rs @@ -1,3 +1 @@ pub(crate) mod axum; -pub mod hcl; -pub(crate) mod rdf; diff --git a/dsp-meta/src/api/convert/rdf/constance.rs b/dsp-meta/src/api/convert/rdf/constance.rs deleted file mode 100644 index ddf62807..00000000 --- a/dsp-meta/src/api/convert/rdf/constance.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![allow(dead_code)] -pub const RDF_NAMESPACE_STRING: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; -pub const RDFS_NAMESPACE_STRING: &str = "http://www.w3.org/2000/01/rdf-schema#"; -pub const XSD_NAMESPACE_STRING: &str = "http://www.w3.org/2001/XMLSchema#"; -pub const DSP_NAMESPACE_STRING: &str = "http://ns.dasch.swiss/repository#"; -pub const PROV_NAMESPACE_STRING: &str = "http://www.w3.org/ns/prov#"; -pub const SCHEMA_NAMESPACE_STRING: &str = "https://schema.org/"; diff --git a/dsp-meta/src/api/convert/rdf/error.rs b/dsp-meta/src/api/convert/rdf/error.rs deleted file mode 100644 index bd014cc4..00000000 --- a/dsp-meta/src/api/convert/rdf/error.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate::error::DspMetaError; - -impl From<sophia::iri::InvalidIri> for DspMetaError { - fn from(error: sophia::iri::InvalidIri) -> Self { - DspMetaError::SerializeToRdf(error.0) - } -} diff --git a/dsp-meta/src/api/convert/rdf/mod.rs b/dsp-meta/src/api/convert/rdf/mod.rs deleted file mode 100644 index 01176117..00000000 --- a/dsp-meta/src/api/convert/rdf/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod constance; -mod error; -mod project; -pub(crate) mod project_metadata; -mod triple; -pub mod value; diff --git a/dsp-meta/src/api/convert/rdf/project.rs b/dsp-meta/src/api/convert/rdf/project.rs deleted file mode 100644 index 45481f90..00000000 --- a/dsp-meta/src/api/convert/rdf/project.rs +++ /dev/null @@ -1,39 +0,0 @@ -// placeholder for project - -use dsp_domain::metadata::entity::project::Project; -use sophia::api::graph::{Graph, MutableGraph}; -use sophia::api::ns::{rdf, Namespace}; -use sophia::inmem::graph::LightGraph; -use sophia::iri::Iri; - -use crate::api::convert::rdf::constance::DSP_NAMESPACE_STRING; -use crate::api::convert::rdf::value::shortcode::ShortcodeGraphDto; - -pub struct ProjectGraphDto(pub Project); -impl ProjectGraphDto { - pub(crate) fn to_graph(&self) -> LightGraph { - let mut graph = LightGraph::new(); - - // http://ns.dasch.swiss/repository#dsp-081C-project a http://ns.dasch.swiss/repository#Project - let ns = Namespace::new_unchecked(DSP_NAMESPACE_STRING); - - let project_iri = ns - .get(format!("{}dsp-{}-project", ns.as_str(), self.0.shortcode.0).as_str()) - .expect("project_iri creation failed.") - .to_string(); - let project_iri = Iri::new(project_iri).expect("project_iri creation failed."); - - let project_class = ns.get("Project").expect("project_class creation failed."); - - graph - .insert(&project_iri, rdf::type_, project_class) - .expect("insert of project triples into graph failed."); - - let shortcode_graph = ShortcodeGraphDto(&self.0.shortcode).to_graph(&project_iri); - graph - .insert_all(shortcode_graph.triples()) - .expect("insert of project triples into graph failed."); - - graph - } -} diff --git a/dsp-meta/src/api/convert/rdf/project_metadata.rs b/dsp-meta/src/api/convert/rdf/project_metadata.rs deleted file mode 100644 index f5dbfe4b..00000000 --- a/dsp-meta/src/api/convert/rdf/project_metadata.rs +++ /dev/null @@ -1,147 +0,0 @@ -use dsp_domain::metadata::entity::project_metadata::ProjectMetadata; -use sophia::api::ns::Namespace; -use sophia::api::prefix::{Prefix, PrefixMapPair}; -use sophia::api::prelude::Stringifier; -use sophia::api::serializer::TripleSerializer; -use sophia::inmem::graph::LightGraph; -use sophia::iri::Iri; -use sophia::turtle::serializer::turtle::{TurtleConfig, TurtleSerializer}; -use tracing::trace; - -use crate::api::convert::rdf::constance::{ - DSP_NAMESPACE_STRING, PROV_NAMESPACE_STRING, SCHEMA_NAMESPACE_STRING, XSD_NAMESPACE_STRING, -}; -use crate::api::convert::rdf::project::ProjectGraphDto; -pub struct ProjectMetadataGraph { - graph: LightGraph, -} - -impl ProjectMetadataGraph { - /// Serialize the graph to a turtle string. - /// - /// Example output: - /// ```turtle - /// @prefix dsp: <http://ns.dasch.swiss/repository#> . - /// @prefix prov: <http://www.w3.org/ns/prov#> . - /// @prefix sdo: <https://schema.org/> . - /// @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . - /// - /// dsp:dsp-081C-project a dsp:Project ; - /// dsp:hasDataset dsp:dsp-081C-dataset-000 ; - /// dsp:hasDescription "The database documents the events that took place in the Hôtel de Musique - /// in Bern between 1766 and 1905. The repertoire was constituted by different kinds of spectacles - /// like theatre plays, operas, ballets, concerts, dance parties, acrobatic performances, conferences - /// or magicians. The list reconstructs the lifely and colourful theatre culture of Bern in the 19th - /// Century."@en ; dsp:hasDiscipline "10302 Schweizer Geschichte"@de, - /// "10405 Musikologie"@de, - /// "10406 Theater-und Filmwissenschaften"@de, - /// "10604 Musik und Theater"@de ; - /// dsp:hasFunder dsp:dsp-081C-organization-000 ; - /// dsp:hasHowToCite "HdM-Bern"^^xsd:string ; - /// dsp:hasKeyword "Bern"@de, - /// "19 Century"@en, - /// "Concert"@en, - /// "Music"@en, - /// "Musicology"@en, - /// "Opera"@en, - /// "Spectales"@en, - /// "Switzerland"@en, - /// "Theater history"@en, - /// "Theatre"@en ; - /// dsp:hasName "Hôtel de Musique Bern"^^xsd:string ; - /// dsp:hasShortcode "081C"^^xsd:string ; - /// dsp:hasSpatialCoverage [ a sdo:URL ; - /// sdo:propertyID [ a sdo:PropertyValue ; - /// sdo:propertyID "Bern" ] ; - /// sdo:url "https://www.geonames.org/2661552" ] ; - /// dsp:hasStartDate "2009-04-01"^^xsd:date ; - /// dsp:hasTeaser "The database documents the different kinds of spectacles such as theatre - /// plays, operas, ballets, or concerts that took place in the Hôtel de Musique in Bern between 1766 - /// and 1905."^^xsd:string ; dsp:hasTemporalCoverage [ a sdo:URL ; - /// sdo:propertyID [ a sdo:PropertyValue ; - /// sdo:propertyID "Sonderbund, 1845-1847" ] ; - /// sdo:url "http://n2t.net/ark:/99152/p06c6g3p4cf" ], - /// [ a sdo:URL ; - /// sdo:propertyID [ a sdo:PropertyValue ; - /// sdo:propertyID "Under Mediation act, 1803-1814" ] ; - /// sdo:url "http://n2t.net/ark:/99152/p06c6g3pvr5" ], - /// [ a sdo:URL ; - /// sdo:propertyID [ a sdo:PropertyValue ; - /// sdo:propertyID "Helvetic Republic, 1798-1803" ] ; - /// sdo:url "http://n2t.net/ark:/99152/p06c6g364np" ], - /// "1766-1905"@de, - /// "1766-1905"@en, - /// "1766-1905"@fr ; - /// dsp:hasURL [ a sdo:URL ; - /// sdo:propertyID [ a sdo:PropertyValue ; - /// sdo:propertyID "Discover Project Data" ] ; - /// sdo:url "https://admin.dasch.swiss/project/081C" ] . - /// ``` - pub fn to_turtle_string(&self) -> String { - let prefix_map: Vec<PrefixMapPair> = vec![ - ( - Prefix::new_unchecked("dsp".into()), - Iri::new_unchecked("http://ns.dasch.swiss/repository#".into()), - ), - ( - Prefix::new_unchecked("prov".into()), - Iri::new_unchecked("http://www.w3.org/ns/prov#".into()), - ), - ( - Prefix::new_unchecked("sdo".into()), - Iri::new_unchecked("https://schema.org/".into()), - ), - ( - Prefix::new_unchecked("rdf".into()), - Iri::new_unchecked("http://www.w3.org/1999/02/22-rdf-syntax-ns#".into()), - ), - ( - Prefix::new_unchecked("rdfs".into()), - Iri::new_unchecked("http://www.w3.org/2000/01/rdf-schema#".into()), - ), - ( - Prefix::new_unchecked("xsd".into()), - Iri::new_unchecked("http://www.w3.org/2001/XMLSchema#".into()), - ), - ]; - - let config = TurtleConfig::new() - .with_pretty(true) - .with_own_prefix_map(prefix_map); - let mut serializer = TurtleSerializer::new_stringifier_with_config(config); - let out = serializer - .serialize_graph(&self.graph) - .expect("Error serializing graph to turtle.") - .to_string(); - out - } -} - -/// A wrapper around an optional ProjectMetadata. -pub struct ProjectMetadataGraphWrapper(pub ProjectMetadata); - -/// Convert a `ProjectMetadataGraphDto` into a `ProjectMetadataGraph`. -/// -/// The underlying graph implementation is a `LightGraph` (in contrast to FastGraph) which is a -/// simple in-memory graph graph implementation with a low memory footprint, without indexing, -/// thus fast to build but slow to query. Since we are only interested in building the graph and -/// immediately serializing it, this is the better choice (supported by benchmarking results). -impl From<ProjectMetadataGraphWrapper> for ProjectMetadataGraph { - fn from(value: ProjectMetadataGraphWrapper) -> ProjectMetadataGraph { - trace!("entered ProjectMetadataGraph::from()"); - let _dsp = Namespace::new_unchecked(DSP_NAMESPACE_STRING); - - let _prov = Namespace::new_unchecked(PROV_NAMESPACE_STRING); - - let _sdo = Namespace::new_unchecked(SCHEMA_NAMESPACE_STRING); - - let _xsd = Namespace::new_unchecked(XSD_NAMESPACE_STRING); - - let graph = ProjectGraphDto(value.0.project).to_graph(); - let result = ProjectMetadataGraph { graph }; - - trace!("The resulting graph\n{}", result.to_turtle_string()); - - result - } -} diff --git a/dsp-meta/src/api/convert/rdf/triple.rs b/dsp-meta/src/api/convert/rdf/triple.rs deleted file mode 100644 index 0b672c22..00000000 --- a/dsp-meta/src/api/convert/rdf/triple.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![allow(dead_code)] -struct Triple { - subject: String, - predicate: String, - object: String, -} diff --git a/dsp-meta/src/api/convert/rdf/value/mod.rs b/dsp-meta/src/api/convert/rdf/value/mod.rs deleted file mode 100644 index 708ab009..00000000 --- a/dsp-meta/src/api/convert/rdf/value/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod shortcode; diff --git a/dsp-meta/src/api/convert/rdf/value/shortcode.rs b/dsp-meta/src/api/convert/rdf/value/shortcode.rs deleted file mode 100644 index 6823004c..00000000 --- a/dsp-meta/src/api/convert/rdf/value/shortcode.rs +++ /dev/null @@ -1,26 +0,0 @@ -use dsp_domain::metadata::value::Shortcode; -use sophia::api::graph::MutableGraph; -use sophia::api::ns::Namespace; -use sophia::inmem::graph::LightGraph; -use sophia::iri::Iri; - -pub(crate) struct ShortcodeGraphDto<'a>(pub &'a Shortcode); - -impl<'a> ShortcodeGraphDto<'a> { - pub fn to_graph(&self, project_iri: &Iri<String>) -> LightGraph { - // http://ns.dasch.swiss/repository#dsp-081C-project http://ns.dasch.swiss/repository#hasShortcode "081C"^^http://www.w3.org/2001/XMLSchema#string - let dsp = Namespace::new_unchecked("http://ns.dasch.swiss/repository#"); - - let has_shortcode = dsp - .get("hasShortcode") - .expect("has_shortcode_property creation failed."); - - // mutating the graph - let mut graph: LightGraph = LightGraph::new(); - - graph - .insert(project_iri, has_shortcode, self.0.as_string().as_str()) - .expect("triple inserted"); - graph - } -} diff --git a/dsp-meta/src/error.rs b/dsp-meta/src/error.rs index af3b80a5..f6183a4f 100644 --- a/dsp-meta/src/error.rs +++ b/dsp-meta/src/error.rs @@ -1,6 +1,5 @@ use std::io; -use dsp_domain::error::DspDomainError; use serde::Serialize; use serde_json::Error; use thiserror::Error; @@ -45,15 +44,6 @@ impl From<io::Error> for DspMetaError { } } -impl From<DspDomainError> for DspMetaError { - fn from(value: DspDomainError) -> Self { - match value { - DspDomainError::CreateValueObject(err) => DspMetaError::CreateValueObject(err), - DspDomainError::CreateDomainObject(err) => DspMetaError::CreateDomainObject(err), - } - } -} - impl From<serde_json::Error> for DspMetaError { fn from(value: Error) -> Self { DspMetaError::JsonSerialization(value.to_string()) diff --git a/dsp-meta/tests/common/mod.rs b/dsp-meta/tests/common/mod.rs deleted file mode 100644 index 8fd6b940..00000000 --- a/dsp-meta/tests/common/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -use std::path::Path; - -use dsp_domain::metadata::entity::project_metadata::ProjectMetadata; -use dsp_meta::api::convert::hcl::hcl_body::HclBody; -use dsp_meta::error::DspMetaError; - -pub fn load<P: AsRef<Path>>(path: P) -> Result<ProjectMetadata, DspMetaError> { - let input = std::fs::read_to_string(path)?; - let body: hcl::Body = hcl::from_str(&input)?; - let entity: ProjectMetadata = HclBody(&body).try_into()?; - Ok(entity) -} diff --git a/dsp-meta/tests/integration_test.rs b/dsp-meta/tests/integration_test.rs deleted file mode 100644 index 1237a7ec..00000000 --- a/dsp-meta/tests/integration_test.rs +++ /dev/null @@ -1,41 +0,0 @@ -mod common; - -use std::env; - -use common::load; - -#[test] -fn load_dokubib_config() { - let file = env::current_dir() - .unwrap() - .parent() - .unwrap() - .join("data") - .join("dokubib.hcl"); - let metadata = load(file).unwrap(); - assert_eq!(metadata.version.0, 1); -} - -#[test] -fn load_hdm_config() { - let file = env::current_dir() - .unwrap() - .parent() - .unwrap() - .join("data") - .join("hdm.hcl"); - let metadata = load(file).unwrap(); - assert_eq!(metadata.version.0, 1); -} - -#[test] -fn load_incunabula_config() { - let file = env::current_dir() - .unwrap() - .parent() - .unwrap() - .join("data") - .join("incunabula.hcl"); - let metadata = load(file).unwrap(); - assert_eq!(metadata.version.0, 1); -}