diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..95a321b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,154 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arcanite-addml" +version = "0.1.0" +dependencies = [ + "quick-xml", + "serde", + "serde-xml-rs", + "serde_path_to_error", + "vec1", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.201" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-xml-rs" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb3aa78ecda1ebc9ec9847d5d3aba7d618823446a049ba2491940506da6e2782" +dependencies = [ + "log", + "serde", + "thiserror", + "xml-rs", +] + +[[package]] +name = "serde_derive" +version = "1.0.201" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "vec1" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb60dcfffc189bfd4e2a81333c268619fee9db53da71bce2bcbd8e129c56936" +dependencies = [ + "serde", +] + +[[package]] +name = "xml-rs" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8fc1bfd --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +members = [ + "arcanite-addml", +] diff --git a/arcanite-addml/Cargo.lock b/arcanite-addml/Cargo.lock new file mode 100644 index 0000000..95a321b --- /dev/null +++ b/arcanite-addml/Cargo.lock @@ -0,0 +1,154 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arcanite-addml" +version = "0.1.0" +dependencies = [ + "quick-xml", + "serde", + "serde-xml-rs", + "serde_path_to_error", + "vec1", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "proc-macro2" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.201" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-xml-rs" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb3aa78ecda1ebc9ec9847d5d3aba7d618823446a049ba2491940506da6e2782" +dependencies = [ + "log", + "serde", + "thiserror", + "xml-rs", +] + +[[package]] +name = "serde_derive" +version = "1.0.201" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "vec1" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb60dcfffc189bfd4e2a81333c268619fee9db53da71bce2bcbd8e129c56936" +dependencies = [ + "serde", +] + +[[package]] +name = "xml-rs" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" diff --git a/arcanite-addml/Cargo.toml b/arcanite-addml/Cargo.toml new file mode 100644 index 0000000..01f85a7 --- /dev/null +++ b/arcanite-addml/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "arcanite-addml" +version = "0.1.0" +edition = "2021" + +[dependencies] +# TODO: Choose between quick-xml and serde-xml-rs +quick-xml = { version = "0.31.0", features = ["serde", "serialize"] } +serde = { version = "1.0.201", features = ["derive"] } +serde-xml-rs = "0.6.0" +serde_path_to_error = "0.1.16" +vec1 = { version = "1.12.0", features = ["serde"] } diff --git a/arcanite-addml/README.md b/arcanite-addml/README.md new file mode 100644 index 0000000..2f7a81e --- /dev/null +++ b/arcanite-addml/README.md @@ -0,0 +1,7 @@ +# arcanite-addml + +## Links + +- https://www.arkivverket.no/forvaltning-og-utvikling/regelverk-og-standarder/andre-arkivstandarder/addml-archival-data-description-markup-language +- https://www.arkivverket.no/forvaltning-og-utvikling/regelverk-og-standarder/andre-arkivstandarder/addml-archival-data-description-markup-language/_/attachment/download/e3e195d0-aa21-4df3-99a8-31096f3e4525:c0a09d695060c1cae7e5b820feb3bca97c50d049/ADDML%208-3%20Generelt.pdf +- https://www.arkivverket.no/forvaltning-og-utvikling/regelverk-og-standarder/andre-arkivstandarder/addml-archival-data-description-markup-language/_/attachment/download/94c6a79e-d1af-40ae-b1ef-3e754f762d95:f0fadebbc99ef785cca2c674726846f2c5603ae5/ADDML%208-3%20Profil%20Arkivverket.pdf \ No newline at end of file diff --git a/arcanite-addml/src/lib.rs b/arcanite-addml/src/lib.rs new file mode 100644 index 0000000..516c87f --- /dev/null +++ b/arcanite-addml/src/lib.rs @@ -0,0 +1,4 @@ +mod raw_types; +pub mod types; + +pub use raw_types::RawAddmlDocument; diff --git a/arcanite-addml/src/raw_types.rs b/arcanite-addml/src/raw_types.rs new file mode 100644 index 0000000..cef0d33 --- /dev/null +++ b/arcanite-addml/src/raw_types.rs @@ -0,0 +1,557 @@ +use serde::{Deserialize, Serialize}; +use vec1::Vec1; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawAdditionalElement { + pub name: String, + pub data_type: Option, + pub format: Option, + pub value: Option, + pub properties: Option, + pub additional_elements: Option, + pub processes: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawAdditionalElements { + pub description: Option, + pub additional_element: Option>, + pub processes: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawAddmlDocument { + pub dataset: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawAlignment(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawAlternateKey; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawCharDefinition { + pub from_char: String, + pub to_char: String, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawCharDefinitions { + pub char_definition: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawCharset(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawCode { + pub code_value: String, + pub explan: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawCodes { + pub code: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawContent { + pub content: String, + pub description: Option, + pub additional_elements: Option, + pub processes: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawContext { + pub description: Option, + pub additional_elements: Option, + pub processes: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawDataObject { + pub name: String, + pub description: Option, + pub properties: Option, + pub data_objects: Option, + pub processes: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawDataObjects { + pub description: Option, + pub data_object: Vec1, + pub processes: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawDataset { + pub name: String, + pub description: Option, + pub reference: Option, + pub flat_files: Option, + pub data_objects: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawDataType(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawDelimFileFormat { + pub record_separator: RawRecordSeparator, + pub field_separating_char: RawFieldSeparatingChar, + pub quoting_char: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawDescription(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawEndPos(pub usize); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawExternal; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldDefinition { + pub name: String, + pub type_reference: String, + pub description: Option, + pub properties: Option, + pub start_pos: Option, + pub end_pos: Option, + pub fixed_length: Option, + pub min_length: Option, + pub max_length: Option, + pub unique: Option, + pub not_null: Option, + pub field_parts: Option, + pub codes: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldDefinitionReference { + pub name: String, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldDefinitionReferences { + pub field_definition_reference: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldDefinitions { + pub field_definition: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldFormat(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldParts { + pub name: String, + pub field_definition: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldProcesses { + pub definition_reference: String, + pub processes: RawProcesses, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldSeparatingChar(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldType { + pub name: String, + pub description: Option, + pub data_type: RawDataType, + pub field_format: Option, + pub alignment: Option, + pub pad_char: Option, + pub pack_type: Option, + pub null_values: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFieldTypes { + pub field_type: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFixedFileFormat { + pub record_separator: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFixedLength(pub usize); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFixedOccurrences(pub usize); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFlatFile { + pub name: String, + pub definition_reference: String, + pub properties: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFlatFileDefinition { + pub name: String, + pub type_reference: Option, + pub description: Option, + pub properties: Option>, + pub external: Option, + pub record_definition_field_identifier: Option, + pub record_definitions: RawRecordDefinitions, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFlatFileDefinitionReference { + pub name: String, + pub record_definition_references: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFlatFileDefinitions { + pub flat_file_definition: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFlatFileProcess { + pub flat_file_reference: String, + pub processes: Option, + pub record_processes: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFlatFiles { + pub flat_file: Vec, + pub flat_file_definitions: RawFlatFileDefinitions, + pub structure_types: RawStructureTypes, + pub queries: Option, + pub processes: Option, + pub flat_file_processes: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFlatFileType { + pub name: String, + pub description: Option, + pub charset: RawCharset, + pub char_definitions: Option, + // TODO: ensure at least one of the following is present + pub fixed_file_format: Option, + pub delim_file_format: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawFlatFileTypes { + pub flat_file_type: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawForeignKey { + pub flat_file_definition_reference: RawFlatFileDefinitionReference, + pub relation_type: RawRelationType, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawHeaderLevel { + // TODO: there seems to be a format for this, but it's left unspecified? +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawIncomplete; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawKey { + pub name: String, + pub primary_key: Option, + pub alternate_key: Option, + pub foreign_key: Option, + + pub field_definition_references: RawFieldDefinitionReferences, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawKeys { + pub key: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawMaxLength(pub usize); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawMinLength(pub usize); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawNotNull; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawNullValue(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawNullValues { + pub null_value: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawPackType(pub Option); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawPadChar(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawParameter { + pub name: String, + pub value: String, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawParameters { + pub parameter: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawPrimaryKey; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawProcess { + pub name: String, + pub parameters: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawProcesses { + pub process: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawProperties { + pub property: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawProperty { + pub name: String, + pub data_type: Option, + pub format: Option, + pub value: Option, + pub properties: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawQueries { + pub query: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawQuery { + pub name: String, + pub description: Option, + pub statement: RawStatement, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawQuotingChar(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordDefinition { + pub name: String, + pub type_reference: Option, + pub description: Option, + pub properties: Option, + pub record_definition_field_value: Option, + pub incomplete: Option, + pub fixed_length: Option, + pub repeating_groups: Option, + pub keys: Option, + pub field_definitions: RawFieldDefinitions, + pub header_level: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordDefinitionFieldIdentifier(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordDefinitionFieldValue(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordDefinitionReference { + pub name: String, + pub field_definition_references: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordDefinitionReferences { + pub record_definition_reference: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordDefinitions { + pub record_definition: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordProcesses { + // TODO: report this as a bug in the spec + // pub name: String, + pub definition_reference: String, + pub processes: Option, + pub field_processes: Option>, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordSeparator(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordType { + pub name: String, + pub description: Option, + pub trimmed: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRecordTypes { + pub record_type: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawReference { + pub name: Option, + pub context: Option, + pub content: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRelationType(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRepeatingGroup { + pub name: String, + // TODO: one of repeating_group_occurrence_field or fixed_occurrences must be present, maybe create enum? + pub repeating_group_occurrence_field: Option, + pub fixed_occurrences: Option, + pub field_definition_references: RawFieldDefinitionReferences, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRepeatingGroupOccurrenceField { + pub definition_reference: String, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawRepeatingGroups { + pub repeating_group: Vec1, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawStartPos(pub usize); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawStatement(pub String); + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawStructureTypes { + pub flat_file_types: RawFlatFileTypes, + pub record_types: Option, + pub field_types: RawFieldTypes, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawTrimmed; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawUnique; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RawValue(pub String); diff --git a/arcanite-addml/src/types.rs b/arcanite-addml/src/types.rs new file mode 100644 index 0000000..a60ef43 --- /dev/null +++ b/arcanite-addml/src/types.rs @@ -0,0 +1,77 @@ +use vec1::Vec1; + +use crate::raw_types::*; + +mod additional_element; +mod additional_elements; +mod addml_document; +mod char_definition; +mod code; +mod content; +mod context; +mod data_object; +mod data_objects; +mod dataset; +mod delim_file_format; +mod field_definition; +mod field_parts; +mod field_processes; +mod field_type; +mod fixed_file_format; +mod flat_file; +mod flat_file_definition; +mod flat_file_definition_reference; +mod flat_file_process; +mod flat_file_type; +mod flat_files; +mod header_level; +mod key; +mod parameter; +mod process; +mod property; +mod query; +mod record_definition; +mod record_definition_reference; +mod record_processes; +mod record_type; +mod reference; +mod repeating_group; +mod repeating_group_occurrence_field; +mod structure_types; + +pub use additional_element::*; +pub use additional_elements::*; +pub use addml_document::*; +pub use char_definition::*; +pub use code::*; +pub use content::*; +pub use context::*; +pub use data_object::*; +pub use data_objects::*; +pub use dataset::*; +pub use delim_file_format::*; +pub use field_definition::*; +pub use field_parts::*; +pub use field_processes::*; +pub use field_type::*; +pub use fixed_file_format::*; +pub use flat_file::*; +pub use flat_file_definition::*; +pub use flat_file_definition_reference::*; +pub use flat_file_process::*; +pub use flat_file_type::*; +pub use flat_files::*; +pub use header_level::*; +pub use key::*; +pub use parameter::*; +pub use process::*; +pub use property::*; +pub use query::*; +pub use record_definition::*; +pub use record_definition_reference::*; +pub use record_processes::*; +pub use record_type::*; +pub use reference::*; +pub use repeating_group::*; +pub use repeating_group_occurrence_field::*; +pub use structure_types::*; diff --git a/arcanite-addml/src/types/additional_element.rs b/arcanite-addml/src/types/additional_element.rs new file mode 100644 index 0000000..1c471b1 --- /dev/null +++ b/arcanite-addml/src/types/additional_element.rs @@ -0,0 +1,56 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct AdditionalElement { + pub name: String, + pub data_type: Option, + pub format: Option, + pub value: Option, + pub properties: Vec, + pub additional_elements: Option, + pub processes: Vec, +} + +impl From for AdditionalElement { + fn from(raw: RawAdditionalElement) -> Self { + AdditionalElement { + name: raw.name, + data_type: raw.data_type, + format: raw.format, + value: raw.value.map(|RawValue(v)| v), + properties: raw + .properties + .map(|RawProperties { property: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + additional_elements: raw.additional_elements.map(|ae| ae.into()), + processes: raw + .processes + .map(|RawProcesses { process: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawAdditionalElement { + fn from(val: AdditionalElement) -> Self { + RawAdditionalElement { + name: val.name, + data_type: val.data_type, + format: val.format, + value: val.value.map(RawValue), + properties: match Vec1::try_from_vec(val.properties) { + Ok(properties) => Some(RawProperties { + property: properties.mapped(|p| p.into()), + }), + Err(_) => None, + }, + additional_elements: val.additional_elements.map(|ae| ae.into()), + processes: match Vec1::try_from_vec(val.processes) { + Ok(processes) => Some(RawProcesses { + process: processes.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/additional_elements.rs b/arcanite-addml/src/types/additional_elements.rs new file mode 100644 index 0000000..ea910bd --- /dev/null +++ b/arcanite-addml/src/types/additional_elements.rs @@ -0,0 +1,40 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct AdditionalElements { + pub description: Option, + pub additional_element: Option>, + pub processes: Vec, +} + +impl From for AdditionalElements { + fn from(raw: RawAdditionalElements) -> Self { + AdditionalElements { + description: raw.description.map(|RawDescription(d)| d), + additional_element: raw + .additional_element + .map(|ae| ae.into_iter().map(|ae| ae.into()).collect()), + processes: raw + .processes + .map(|RawProcesses { process: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawAdditionalElements { + fn from(val: AdditionalElements) -> Self { + RawAdditionalElements { + description: val.description.map(RawDescription), + additional_element: val + .additional_element + .map(|ae| ae.into_iter().map(|ae| ae.into()).collect()), + processes: match Vec1::try_from_vec(val.processes) { + Ok(processes) => Some(RawProcesses { + process: processes.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/addml_document.rs b/arcanite-addml/src/types/addml_document.rs new file mode 100644 index 0000000..6a0e297 --- /dev/null +++ b/arcanite-addml/src/types/addml_document.rs @@ -0,0 +1,22 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct AddmlDocument { + dataset: Vec1, +} + +impl From for AddmlDocument { + fn from(raw: RawAddmlDocument) -> Self { + AddmlDocument { + dataset: raw.dataset.mapped(|ds| ds.into()), + } + } +} + +impl From for RawAddmlDocument { + fn from(val: AddmlDocument) -> Self { + RawAddmlDocument { + dataset: val.dataset.mapped(|ds| ds.into()), + } + } +} diff --git a/arcanite-addml/src/types/char_definition.rs b/arcanite-addml/src/types/char_definition.rs new file mode 100644 index 0000000..d380423 --- /dev/null +++ b/arcanite-addml/src/types/char_definition.rs @@ -0,0 +1,25 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct CharDefinition { + pub from_char: String, + pub to_char: String, +} + +impl From for CharDefinition { + fn from(raw: RawCharDefinition) -> Self { + CharDefinition { + from_char: raw.from_char, + to_char: raw.to_char, + } + } +} + +impl From for RawCharDefinition { + fn from(val: CharDefinition) -> Self { + RawCharDefinition { + from_char: val.from_char, + to_char: val.to_char, + } + } +} diff --git a/arcanite-addml/src/types/code.rs b/arcanite-addml/src/types/code.rs new file mode 100644 index 0000000..a1bc5cd --- /dev/null +++ b/arcanite-addml/src/types/code.rs @@ -0,0 +1,25 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Code { + code_value: String, + explan: Option, +} + +impl From for Code { + fn from(raw: RawCode) -> Self { + Code { + code_value: raw.code_value, + explan: raw.explan, + } + } +} + +impl From for RawCode { + fn from(val: Code) -> Self { + RawCode { + code_value: val.code_value, + explan: val.explan, + } + } +} diff --git a/arcanite-addml/src/types/content.rs b/arcanite-addml/src/types/content.rs new file mode 100644 index 0000000..e6ef646 --- /dev/null +++ b/arcanite-addml/src/types/content.rs @@ -0,0 +1,39 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Content { + pub content: String, + pub description: Option, + pub additional_elements: Option, + pub processes: Vec, +} + +impl From for Content { + fn from(raw: RawContent) -> Self { + Content { + content: raw.content, + description: raw.description.map(|RawDescription(d)| d), + additional_elements: raw.additional_elements.map(|ae| ae.into()), + processes: raw + .processes + .map(|RawProcesses { process: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawContent { + fn from(val: Content) -> Self { + RawContent { + content: val.content, + description: val.description.map(RawDescription), + additional_elements: val.additional_elements.map(|ae| ae.into()), + processes: match Vec1::try_from_vec(val.processes) { + Ok(processes) => Some(RawProcesses { + process: processes.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/context.rs b/arcanite-addml/src/types/context.rs new file mode 100644 index 0000000..b451f4b --- /dev/null +++ b/arcanite-addml/src/types/context.rs @@ -0,0 +1,36 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Context { + pub description: Option, + pub additional_elements: Option, + pub processes: Vec, +} + +impl From for Context { + fn from(raw: RawContext) -> Self { + Context { + description: raw.description.map(|RawDescription(d)| d), + additional_elements: raw.additional_elements.map(|ae| ae.into()), + processes: raw + .processes + .map(|RawProcesses { process: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawContext { + fn from(val: Context) -> Self { + RawContext { + description: val.description.map(RawDescription), + additional_elements: val.additional_elements.map(|ae| ae.into()), + processes: match Vec1::try_from_vec(val.processes) { + Ok(processes) => Some(RawProcesses { + process: processes.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/data_object.rs b/arcanite-addml/src/types/data_object.rs new file mode 100644 index 0000000..84241f6 --- /dev/null +++ b/arcanite-addml/src/types/data_object.rs @@ -0,0 +1,50 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct DataObject { + pub name: String, + pub description: Option, + pub properties: Vec, + pub data_objects: Option, + pub processes: Vec, +} + +impl From for DataObject { + fn from(raw: RawDataObject) -> Self { + DataObject { + name: raw.name, + description: raw.description.map(|RawDescription(d)| d), + properties: raw + .properties + .map(|RawProperties { property: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + data_objects: raw.data_objects.map(|do_| do_.into()), + processes: raw + .processes + .map(|RawProcesses { process: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawDataObject { + fn from(val: DataObject) -> Self { + RawDataObject { + name: val.name, + description: val.description.map(RawDescription), + properties: match Vec1::try_from_vec(val.properties) { + Ok(properties) => Some(RawProperties { + property: properties.mapped(|p| p.into()), + }), + Err(_) => None, + }, + data_objects: val.data_objects.map(|do_| do_.into()), + processes: match Vec1::try_from_vec(val.processes) { + Ok(processes) => Some(RawProcesses { + process: processes.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/data_objects.rs b/arcanite-addml/src/types/data_objects.rs new file mode 100644 index 0000000..4c17fa7 --- /dev/null +++ b/arcanite-addml/src/types/data_objects.rs @@ -0,0 +1,36 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct DataObjects { + pub description: Option, + pub data_object: Vec1, + pub processes: Vec, +} + +impl From for DataObjects { + fn from(raw: RawDataObjects) -> Self { + DataObjects { + description: raw.description.map(|RawDescription(d)| d), + data_object: raw.data_object.mapped(|do_| do_.into()), + processes: raw + .processes + .map(|RawProcesses { process: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawDataObjects { + fn from(val: DataObjects) -> Self { + RawDataObjects { + description: val.description.map(RawDescription), + data_object: val.data_object.mapped(|do_| do_.into()), + processes: match Vec1::try_from_vec(val.processes) { + Ok(processes) => Some(RawProcesses { + process: processes.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/dataset.rs b/arcanite-addml/src/types/dataset.rs new file mode 100644 index 0000000..c7f048a --- /dev/null +++ b/arcanite-addml/src/types/dataset.rs @@ -0,0 +1,34 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Dataset { + pub name: String, + pub description: Option, + pub reference: Option, + pub flat_files: Option, + pub data_objects: Option, +} + +impl From for Dataset { + fn from(raw: RawDataset) -> Self { + Dataset { + name: raw.name, + description: raw.description.map(|RawDescription(d)| d), + reference: raw.reference.map(|r| r.into()), + flat_files: raw.flat_files.map(|ff| ff.into()), + data_objects: raw.data_objects.map(|do_| do_.into()), + } + } +} + +impl From for RawDataset { + fn from(val: Dataset) -> Self { + RawDataset { + name: val.name, + description: val.description.map(RawDescription), + reference: val.reference.map(|r| r.into()), + flat_files: val.flat_files.map(|ff| ff.into()), + data_objects: val.data_objects.map(|do_| do_.into()), + } + } +} diff --git a/arcanite-addml/src/types/delim_file_format.rs b/arcanite-addml/src/types/delim_file_format.rs new file mode 100644 index 0000000..0964ef3 --- /dev/null +++ b/arcanite-addml/src/types/delim_file_format.rs @@ -0,0 +1,28 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct DelimFileFormat { + pub record_separator: String, + pub field_separating_char: String, + pub quoting_char: Option, +} + +impl From for DelimFileFormat { + fn from(raw: RawDelimFileFormat) -> Self { + DelimFileFormat { + record_separator: raw.record_separator.0, + field_separating_char: raw.field_separating_char.0, + quoting_char: raw.quoting_char.map(|RawQuotingChar(qc)| qc), + } + } +} + +impl From for RawDelimFileFormat { + fn from(val: DelimFileFormat) -> Self { + RawDelimFileFormat { + record_separator: RawRecordSeparator(val.record_separator), + field_separating_char: RawFieldSeparatingChar(val.field_separating_char), + quoting_char: val.quoting_char.map(RawQuotingChar), + } + } +} diff --git a/arcanite-addml/src/types/field_definition.rs b/arcanite-addml/src/types/field_definition.rs new file mode 100644 index 0000000..48705af --- /dev/null +++ b/arcanite-addml/src/types/field_definition.rs @@ -0,0 +1,74 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FieldDefinition { + pub name: String, + pub type_reference: String, + pub description: Option, + pub properties: Vec, + pub start_pos: Option, + pub end_pos: Option, + pub fixed_length: Option, + pub min_length: Option, + pub max_length: Option, + pub unique: bool, + pub not_null: bool, + pub field_parts: Option, + pub codes: Vec, +} + +impl From for FieldDefinition { + fn from(raw: RawFieldDefinition) -> Self { + FieldDefinition { + name: raw.name, + type_reference: raw.type_reference, + description: raw.description.map(|RawDescription(d)| d), + properties: raw + .properties + .map(|RawProperties { property: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + start_pos: raw.start_pos.map(|RawStartPos(sp)| sp), + end_pos: raw.end_pos.map(|RawEndPos(ep)| ep), + fixed_length: raw.fixed_length.map(|RawFixedLength(fl)| fl), + min_length: raw.min_length.map(|RawMinLength(ml)| ml), + max_length: raw.max_length.map(|RawMaxLength(ml)| ml), + unique: raw.unique.is_some(), + not_null: raw.not_null.is_some(), + field_parts: raw.field_parts.map(|fp| fp.into()), + codes: raw + .codes + .map(|RawCodes { code: c }| c.mapped(|c| c.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawFieldDefinition { + fn from(val: FieldDefinition) -> Self { + RawFieldDefinition { + name: val.name, + type_reference: val.type_reference, + description: val.description.map(RawDescription), + properties: match Vec1::try_from_vec(val.properties) { + Ok(properties) => Some(RawProperties { + property: properties.mapped(|p| p.into()), + }), + Err(_) => None, + }, + start_pos: val.start_pos.map(RawStartPos), + end_pos: val.end_pos.map(RawEndPos), + fixed_length: val.fixed_length.map(RawFixedLength), + min_length: val.min_length.map(RawMinLength), + max_length: val.max_length.map(RawMaxLength), + unique: if val.unique { Some(RawUnique) } else { None }, + not_null: if val.not_null { Some(RawNotNull) } else { None }, + field_parts: val.field_parts.map(|fp| fp.into()), + codes: match Vec1::try_from_vec(val.codes) { + Ok(codes) => Some(RawCodes { + code: codes.mapped(|c| c.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/field_parts.rs b/arcanite-addml/src/types/field_parts.rs new file mode 100644 index 0000000..1b62ddc --- /dev/null +++ b/arcanite-addml/src/types/field_parts.rs @@ -0,0 +1,25 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FieldParts { + pub name: String, + pub field_definition: Vec1, +} + +impl From for FieldParts { + fn from(raw: RawFieldParts) -> Self { + FieldParts { + name: raw.name, + field_definition: raw.field_definition.mapped(|fd| fd.into()), + } + } +} + +impl From for RawFieldParts { + fn from(val: FieldParts) -> Self { + RawFieldParts { + name: val.name, + field_definition: val.field_definition.mapped(|fd| fd.into()), + } + } +} diff --git a/arcanite-addml/src/types/field_processes.rs b/arcanite-addml/src/types/field_processes.rs new file mode 100644 index 0000000..7739af6 --- /dev/null +++ b/arcanite-addml/src/types/field_processes.rs @@ -0,0 +1,27 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FieldProcesses { + pub definition_reference: String, + pub processes: Vec1, +} + +impl From for FieldProcesses { + fn from(raw: RawFieldProcesses) -> Self { + FieldProcesses { + definition_reference: raw.definition_reference, + processes: raw.processes.process.mapped(|p| p.into()), + } + } +} + +impl From for RawFieldProcesses { + fn from(val: FieldProcesses) -> Self { + RawFieldProcesses { + definition_reference: val.definition_reference, + processes: RawProcesses { + process: val.processes.mapped(|p| p.into()), + }, + } + } +} diff --git a/arcanite-addml/src/types/field_type.rs b/arcanite-addml/src/types/field_type.rs new file mode 100644 index 0000000..f3ce424 --- /dev/null +++ b/arcanite-addml/src/types/field_type.rs @@ -0,0 +1,55 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FieldType { + pub name: String, + pub description: Option, + pub data_type: String, + pub field_format: Option, + pub alignment: Option, + pub pad_char: Option, + // TODO: Make a more explanatory type for this + // If the outer Option is Some, the field is packed, + // but the algorithm is not specified. The inner value + // can also be "packed", which would be the same as Some(None). + pub pack_type: Option>, + pub null_values: Vec, +} + +impl From for FieldType { + fn from(raw: RawFieldType) -> Self { + FieldType { + name: raw.name, + description: raw.description.map(|RawDescription(d)| d), + data_type: raw.data_type.0, + field_format: raw.field_format.map(|RawFieldFormat(ff)| ff), + alignment: raw.alignment.map(|RawAlignment(a)| a), + pad_char: raw.pad_char.map(|RawPadChar(pc)| pc), + pack_type: raw.pack_type.map(|RawPackType(pt)| pt), + null_values: raw + .null_values + .map(|RawNullValues { null_value: nv }| nv.mapped(|RawNullValue(nv)| nv).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawFieldType { + fn from(val: FieldType) -> Self { + RawFieldType { + name: val.name, + description: val.description.map(RawDescription), + data_type: RawDataType(val.data_type), + field_format: val.field_format.map(RawFieldFormat), + alignment: val.alignment.map(RawAlignment), + pad_char: val.pad_char.map(RawPadChar), + pack_type: val.pack_type.map(|pt| RawPackType(pt)), + null_values: match Vec1::try_from_vec(val.null_values) { + Ok(null_values) => Some(RawNullValues { + null_value: null_values.mapped(|nv| RawNullValue(nv)), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/fixed_file_format.rs b/arcanite-addml/src/types/fixed_file_format.rs new file mode 100644 index 0000000..dfe915b --- /dev/null +++ b/arcanite-addml/src/types/fixed_file_format.rs @@ -0,0 +1,22 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FixedFileFormat { + pub record_separator: Option, +} + +impl From for FixedFileFormat { + fn from(raw: RawFixedFileFormat) -> Self { + FixedFileFormat { + record_separator: raw.record_separator.map(|RawRecordSeparator(rs)| rs), + } + } +} + +impl From for RawFixedFileFormat { + fn from(val: FixedFileFormat) -> Self { + RawFixedFileFormat { + record_separator: val.record_separator.map(RawRecordSeparator), + } + } +} diff --git a/arcanite-addml/src/types/flat_file.rs b/arcanite-addml/src/types/flat_file.rs new file mode 100644 index 0000000..1ee09b3 --- /dev/null +++ b/arcanite-addml/src/types/flat_file.rs @@ -0,0 +1,36 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FlatFile { + pub name: String, + pub definition_reference: String, + pub properties: Vec, +} + +impl From for FlatFile { + fn from(raw: RawFlatFile) -> Self { + FlatFile { + name: raw.name, + definition_reference: raw.definition_reference, + properties: raw + .properties + .map(|RawProperties { property: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawFlatFile { + fn from(val: FlatFile) -> Self { + RawFlatFile { + name: val.name, + definition_reference: val.definition_reference, + properties: match Vec1::try_from_vec(val.properties) { + Ok(properties) => Some(RawProperties { + property: properties.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/flat_file_definition.rs b/arcanite-addml/src/types/flat_file_definition.rs new file mode 100644 index 0000000..8234c87 --- /dev/null +++ b/arcanite-addml/src/types/flat_file_definition.rs @@ -0,0 +1,70 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FlatFileDefinition { + pub name: String, + pub type_reference: Option, + pub description: Option, + pub properties: Vec>, + pub external: bool, + pub record_definition_field_identifier: Option, + pub record_definitions: Vec1, +} + +impl From for FlatFileDefinition { + fn from(raw: RawFlatFileDefinition) -> Self { + FlatFileDefinition { + name: raw.name, + type_reference: raw.type_reference, + description: raw.description.map(|RawDescription(d)| d), + properties: match raw.properties { + Some(raw_properties) => raw_properties + .into_iter() + .map(|RawProperties { property: p }| p.mapped(|p| p.into()).into()) + .collect(), + None => vec![], + }, + external: match raw.external { + Some(RawExternal) => true, + None => false, + }, + record_definition_field_identifier: raw + .record_definition_field_identifier + .map(|RawRecordDefinitionFieldIdentifier(rdfi)| rdfi), + record_definitions: raw + .record_definitions + .record_definition + .mapped(|rd| rd.into()), + } + } +} + +impl From for RawFlatFileDefinition { + fn from(val: FlatFileDefinition) -> Self { + RawFlatFileDefinition { + name: val.name, + type_reference: val.type_reference, + description: val.description.map(RawDescription), + properties: Vec1::try_from_vec(val.properties) + .map(|properties| { + properties + .mapped(|p| RawProperties { + property: Vec1::try_from_vec(p).unwrap().mapped(|p| p.into()), + }) + .into() + }) + .ok(), + external: if val.external { + Some(RawExternal) + } else { + None + }, + record_definition_field_identifier: val + .record_definition_field_identifier + .map(RawRecordDefinitionFieldIdentifier), + record_definitions: RawRecordDefinitions { + record_definition: val.record_definitions.mapped(|rd| rd.into()), + }, + } + } +} diff --git a/arcanite-addml/src/types/flat_file_definition_reference.rs b/arcanite-addml/src/types/flat_file_definition_reference.rs new file mode 100644 index 0000000..455fcc4 --- /dev/null +++ b/arcanite-addml/src/types/flat_file_definition_reference.rs @@ -0,0 +1,41 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FlatFileDefinitionReference { + pub name: String, + pub record_definition_references: Vec, +} + +impl From for FlatFileDefinitionReference { + fn from(raw: RawFlatFileDefinitionReference) -> Self { + FlatFileDefinitionReference { + name: raw.name, + record_definition_references: raw + .record_definition_references + .map( + |RawRecordDefinitionReferences { + record_definition_reference, + }| { + record_definition_reference.mapped(|rdr| rdr.into()).into() + }, + ) + .unwrap_or_default(), + } + } +} + +impl From for RawFlatFileDefinitionReference { + fn from(val: FlatFileDefinitionReference) -> Self { + RawFlatFileDefinitionReference { + name: val.name, + record_definition_references: match Vec1::try_from_vec(val.record_definition_references) + { + Ok(record_definition_references) => Some(RawRecordDefinitionReferences { + record_definition_reference: record_definition_references + .mapped(|rdr| rdr.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/flat_file_process.rs b/arcanite-addml/src/types/flat_file_process.rs new file mode 100644 index 0000000..f12c6fa --- /dev/null +++ b/arcanite-addml/src/types/flat_file_process.rs @@ -0,0 +1,43 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FlatFileProcess { + pub flat_file_reference: String, + pub processes: Vec, + pub record_processes: Vec, +} + +impl From for FlatFileProcess { + fn from(raw: RawFlatFileProcess) -> Self { + FlatFileProcess { + flat_file_reference: raw.flat_file_reference, + processes: raw + .processes + .map(|RawProcesses { process }| process.mapped(|p| p.into()).into()) + .unwrap_or_default(), + record_processes: raw + .record_processes + .into_iter() + .map(|rrp| rrp.into()) + .collect(), + } + } +} + +impl From for RawFlatFileProcess { + fn from(val: FlatFileProcess) -> Self { + RawFlatFileProcess { + flat_file_reference: val.flat_file_reference, + processes: Vec1::try_from_vec(val.processes) + .map(|processes| RawProcesses { + process: processes.mapped(|p| p.into()), + }) + .ok(), + record_processes: val + .record_processes + .into_iter() + .map(|rp| rp.into()) + .collect(), + } + } +} diff --git a/arcanite-addml/src/types/flat_file_type.rs b/arcanite-addml/src/types/flat_file_type.rs new file mode 100644 index 0000000..b329d04 --- /dev/null +++ b/arcanite-addml/src/types/flat_file_type.rs @@ -0,0 +1,48 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FlatFileType { + pub name: String, + pub description: Option, + pub charset: String, + pub char_definitions: Vec, + // TODO: ensure at least one of the following is present + pub fixed_file_format: Option, + pub delim_file_format: Option, +} + +impl From for FlatFileType { + fn from(raw: RawFlatFileType) -> Self { + FlatFileType { + name: raw.name, + description: raw.description.map(|RawDescription(d)| d), + charset: raw.charset.0, + char_definitions: raw + .char_definitions + .map(|RawCharDefinitions { char_definition }| { + char_definition.mapped(|cd| cd.into()).into() + }) + .unwrap_or_default(), + fixed_file_format: raw.fixed_file_format.map(|fff| fff.into()), + delim_file_format: raw.delim_file_format.map(|dff| dff.into()), + } + } +} + +impl From for RawFlatFileType { + fn from(val: FlatFileType) -> Self { + RawFlatFileType { + name: val.name, + description: val.description.map(|d| RawDescription(d)), + charset: RawCharset(val.charset), + char_definitions: match Vec1::try_from_vec(val.char_definitions) { + Ok(char_definitions) => Some(RawCharDefinitions { + char_definition: char_definitions.mapped(|cd| cd.into()), + }), + Err(_) => None, + }, + fixed_file_format: val.fixed_file_format.map(|fff| fff.into()), + delim_file_format: val.delim_file_format.map(|dff| dff.into()), + } + } +} diff --git a/arcanite-addml/src/types/flat_files.rs b/arcanite-addml/src/types/flat_files.rs new file mode 100644 index 0000000..7035ae6 --- /dev/null +++ b/arcanite-addml/src/types/flat_files.rs @@ -0,0 +1,64 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct FlatFiles { + pub flat_file: Vec, + pub flat_file_definitions: Vec1, + pub structure_types: StructureTypes, + pub queries: Vec, + pub processes: Vec, + pub flat_file_processes: Vec, +} + +impl From for FlatFiles { + fn from(raw: RawFlatFiles) -> Self { + FlatFiles { + flat_file: raw.flat_file.into_iter().map(|ff| ff.into()).collect(), + flat_file_definitions: raw + .flat_file_definitions + .flat_file_definition + .mapped(|ffd| ffd.into()), + structure_types: raw.structure_types.into(), + queries: raw + .queries + .map(|RawQueries { query }| query.mapped(|q| q.into()).into()) + .unwrap_or_default(), + processes: raw + .processes + .map(|RawProcesses { process }| process.mapped(|p| p.into()).into()) + .unwrap_or_default(), + flat_file_processes: raw + .flat_file_processes + .into_iter() + .map(|rffp| rffp.into()) + .collect(), + } + } +} + +impl From for RawFlatFiles { + fn from(val: FlatFiles) -> Self { + RawFlatFiles { + flat_file: val.flat_file.into_iter().map(|ff| ff.into()).collect(), + flat_file_definitions: RawFlatFileDefinitions { + flat_file_definition: val.flat_file_definitions.mapped(|ffd| ffd.into()), + }, + structure_types: val.structure_types.into(), + queries: Vec1::try_from_vec(val.queries) + .map(|queries| RawQueries { + query: queries.mapped(|q| q.into()), + }) + .ok(), + processes: Vec1::try_from_vec(val.processes) + .map(|processes| RawProcesses { + process: processes.mapped(|p| p.into()), + }) + .ok(), + flat_file_processes: val + .flat_file_processes + .into_iter() + .map(|rffp| rffp.into()) + .collect(), + } + } +} diff --git a/arcanite-addml/src/types/header_level.rs b/arcanite-addml/src/types/header_level.rs new file mode 100644 index 0000000..81d0ddb --- /dev/null +++ b/arcanite-addml/src/types/header_level.rs @@ -0,0 +1,18 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct HeaderLevel { + // TODO: there seems to be a format for this, but it's left unspecified? +} + +impl From for HeaderLevel { + fn from(_: RawHeaderLevel) -> Self { + HeaderLevel {} + } +} + +impl From for RawHeaderLevel { + fn from(_: HeaderLevel) -> Self { + RawHeaderLevel {} + } +} diff --git a/arcanite-addml/src/types/key.rs b/arcanite-addml/src/types/key.rs new file mode 100644 index 0000000..cdd54f7 --- /dev/null +++ b/arcanite-addml/src/types/key.rs @@ -0,0 +1,78 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub enum KeyType { + PrimaryKey, + AlternateKey, + ForeignKey { + flat_file_definition_reference: FlatFileDefinitionReference, + relation_type: String, + }, +} + +#[derive(Debug, Clone, PartialEq)] +pub struct Key { + pub name: String, + pub key_type: KeyType, + + pub field_definition_references: Vec1, +} + +impl From for Key { + fn from(raw: RawKey) -> Self { + Key { + name: raw.name, + // TODO: this state should be validated properly. + // Falling back to PrimaryKey is a bad idea. + key_type: if raw.primary_key.is_some() { + KeyType::PrimaryKey + } else if raw.alternate_key.is_some() { + KeyType::AlternateKey + } else if raw.foreign_key.is_some() { + let fk = raw.foreign_key.unwrap(); + KeyType::ForeignKey { + flat_file_definition_reference: fk.flat_file_definition_reference.into(), + relation_type: fk.relation_type.0, + } + } else { + KeyType::PrimaryKey + }, + field_definition_references: raw + .field_definition_references + .field_definition_reference + .mapped(|fdr| fdr.name), + } + } +} + +impl From for RawKey { + fn from(val: Key) -> Self { + let (primary_key, alternate_key, foreign_key) = match val.key_type { + KeyType::PrimaryKey => (Some(RawPrimaryKey), None, None), + KeyType::AlternateKey => (None, Some(RawAlternateKey), None), + KeyType::ForeignKey { + flat_file_definition_reference, + relation_type, + } => ( + None, + None, + Some(RawForeignKey { + flat_file_definition_reference: flat_file_definition_reference.into(), + relation_type: RawRelationType(relation_type), + }), + ), + }; + + RawKey { + name: val.name, + primary_key, + alternate_key, + foreign_key, + field_definition_references: RawFieldDefinitionReferences { + field_definition_reference: val + .field_definition_references + .mapped(|name| RawFieldDefinitionReference { name }), + }, + } + } +} diff --git a/arcanite-addml/src/types/parameter.rs b/arcanite-addml/src/types/parameter.rs new file mode 100644 index 0000000..809ccfe --- /dev/null +++ b/arcanite-addml/src/types/parameter.rs @@ -0,0 +1,25 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Parameter { + pub name: String, + pub value: String, +} + +impl From for Parameter { + fn from(raw: RawParameter) -> Self { + Parameter { + name: raw.name, + value: raw.value, + } + } +} + +impl From for RawParameter { + fn from(val: Parameter) -> Self { + RawParameter { + name: val.name, + value: val.value, + } + } +} diff --git a/arcanite-addml/src/types/process.rs b/arcanite-addml/src/types/process.rs new file mode 100644 index 0000000..ac4bbfb --- /dev/null +++ b/arcanite-addml/src/types/process.rs @@ -0,0 +1,33 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Process { + pub name: String, + pub parameters: Vec, +} + +impl From for Process { + fn from(raw: RawProcess) -> Self { + Process { + name: raw.name, + parameters: raw + .parameters + .map(|RawParameters { parameter: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawProcess { + fn from(val: Process) -> Self { + RawProcess { + name: val.name, + parameters: match Vec1::try_from_vec(val.parameters) { + Ok(parameters) => Some(RawParameters { + parameter: parameters.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/property.rs b/arcanite-addml/src/types/property.rs new file mode 100644 index 0000000..7e307f3 --- /dev/null +++ b/arcanite-addml/src/types/property.rs @@ -0,0 +1,42 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Property { + pub name: String, + pub data_type: Option, + pub format: Option, + pub value: Option, + pub properties: Vec, +} + +impl From for Property { + fn from(raw: RawProperty) -> Self { + Property { + name: raw.name, + data_type: raw.data_type, + format: raw.format, + value: raw.value.map(|RawValue(v)| v), + properties: raw + .properties + .map(|RawProperties { property: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + } + } +} + +impl From for RawProperty { + fn from(val: Property) -> Self { + RawProperty { + name: val.name, + data_type: val.data_type, + format: val.format, + value: val.value.map(RawValue), + properties: match Vec1::try_from_vec(val.properties) { + Ok(properties) => Some(RawProperties { + property: properties.mapped(|p| p.into()), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/query.rs b/arcanite-addml/src/types/query.rs new file mode 100644 index 0000000..c2a0ce7 --- /dev/null +++ b/arcanite-addml/src/types/query.rs @@ -0,0 +1,28 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Query { + pub name: String, + pub description: Option, + pub statement: String, +} + +impl From for Query { + fn from(raw: RawQuery) -> Self { + Query { + name: raw.name, + description: raw.description.map(|RawDescription(d)| d), + statement: raw.statement.0, + } + } +} + +impl From for RawQuery { + fn from(val: Query) -> Self { + RawQuery { + name: val.name, + description: val.description.map(RawDescription), + statement: RawStatement(val.statement), + } + } +} diff --git a/arcanite-addml/src/types/record_definition.rs b/arcanite-addml/src/types/record_definition.rs new file mode 100644 index 0000000..8de6b83 --- /dev/null +++ b/arcanite-addml/src/types/record_definition.rs @@ -0,0 +1,94 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct RecordDefinition { + pub name: String, + pub type_reference: Option, + pub description: Option, + pub properties: Vec, + pub record_definition_field_value: Option, + pub incomplete: bool, + pub fixed_length: Option, + pub repeating_groups: Vec, + pub keys: Vec, + pub field_definitions: Vec1, + pub header_level: Option, +} + +impl From for RecordDefinition { + fn from(raw: RawRecordDefinition) -> Self { + RecordDefinition { + name: raw.name, + type_reference: raw.type_reference, + description: raw.description.map(|RawDescription(d)| d), + properties: raw + .properties + .map(|RawProperties { property: p }| p.mapped(|p| p.into()).into()) + .unwrap_or_default(), + record_definition_field_value: raw + .record_definition_field_value + .map(|RawRecordDefinitionFieldValue(rdfv)| rdfv), + incomplete: match raw.incomplete { + Some(RawIncomplete) => true, + None => false, + }, + fixed_length: raw.fixed_length.map(|RawFixedLength(l)| l), + repeating_groups: raw + .repeating_groups + .map(|RawRepeatingGroups { repeating_group }| { + repeating_group.mapped(|rg| rg.into()).into() + }) + .unwrap_or_default(), + keys: raw + .keys + .map(|RawKeys { key }| key.mapped(|k| k.into()).into()) + .unwrap_or_default(), + field_definitions: raw + .field_definitions + .field_definition + .mapped(|fd| fd.into()), + header_level: raw.header_level.map(|hl| hl.into()), + } + } +} + +impl From for RawRecordDefinition { + fn from(val: RecordDefinition) -> Self { + RawRecordDefinition { + name: val.name, + type_reference: val.type_reference, + description: val.description.map(RawDescription), + properties: match Vec1::try_from_vec(val.properties) { + Ok(properties) => Some(RawProperties { + property: properties.mapped(|p| p.into()), + }), + Err(_) => None, + }, + record_definition_field_value: val + .record_definition_field_value + .map(RawRecordDefinitionFieldValue), + incomplete: if val.incomplete { + Some(RawIncomplete) + } else { + None + }, + fixed_length: val.fixed_length.map(RawFixedLength), + repeating_groups: match Vec1::try_from_vec(val.repeating_groups) { + Ok(repeating_groups) => Some(RawRepeatingGroups { + repeating_group: repeating_groups.mapped(|rg| rg.into()), + }), + Err(_) => None, + }, + keys: match Vec1::try_from_vec(val.keys) { + Ok(keys) => Some(RawKeys { + key: keys.mapped(|k| k.into()), + }), + Err(_) => None, + }, + field_definitions: RawFieldDefinitions { + field_definition: val.field_definitions.mapped(|fd| fd.into()), + }, + header_level: val.header_level.map(|hl| hl.into()), + } + } +} diff --git a/arcanite-addml/src/types/record_definition_reference.rs b/arcanite-addml/src/types/record_definition_reference.rs new file mode 100644 index 0000000..24035c0 --- /dev/null +++ b/arcanite-addml/src/types/record_definition_reference.rs @@ -0,0 +1,40 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct RecordDefinitionReference { + pub name: String, + pub field_definition_references: Vec, +} + +impl From for RecordDefinitionReference { + fn from(raw: RawRecordDefinitionReference) -> Self { + RecordDefinitionReference { + name: raw.name, + field_definition_references: raw + .field_definition_references + .map( + |RawFieldDefinitionReferences { + field_definition_reference, + }| { + field_definition_reference.mapped(|fdr| fdr.name).into() + }, + ) + .unwrap_or_default(), + } + } +} + +impl From for RawRecordDefinitionReference { + fn from(val: RecordDefinitionReference) -> Self { + RawRecordDefinitionReference { + name: val.name, + field_definition_references: match Vec1::try_from_vec(val.field_definition_references) { + Ok(field_definition_references) => Some(RawFieldDefinitionReferences { + field_definition_reference: field_definition_references + .mapped(|name| RawFieldDefinitionReference { name }), + }), + Err(_) => None, + }, + } + } +} diff --git a/arcanite-addml/src/types/record_processes.rs b/arcanite-addml/src/types/record_processes.rs new file mode 100644 index 0000000..65f7cf0 --- /dev/null +++ b/arcanite-addml/src/types/record_processes.rs @@ -0,0 +1,42 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct RecordProcesses { + // TODO: report this as a bug in the spec + // pub name: String, + pub definition_reference: String, + pub processes: Vec, + pub field_processes: Option>, +} + +impl From for RecordProcesses { + fn from(raw: RawRecordProcesses) -> Self { + RecordProcesses { + definition_reference: raw.definition_reference, + processes: raw + .processes + .map(|RawProcesses { process }| process.mapped(|p| p.into()).into()) + .unwrap_or_default(), + field_processes: raw + .field_processes + .map(|rfps| rfps.into_iter().map(|rfp| rfp.into()).collect()), + } + } +} + +impl From for RawRecordProcesses { + fn from(val: RecordProcesses) -> Self { + RawRecordProcesses { + // name: val.name, + definition_reference: val.definition_reference, + processes: Vec1::try_from_vec(val.processes) + .map(|processes| RawProcesses { + process: processes.mapped(|p| p.into()), + }) + .ok(), + field_processes: val + .field_processes + .map(|rfps| rfps.into_iter().map(|rfp| rfp.into()).collect()), + } + } +} diff --git a/arcanite-addml/src/types/record_type.rs b/arcanite-addml/src/types/record_type.rs new file mode 100644 index 0000000..f31eac6 --- /dev/null +++ b/arcanite-addml/src/types/record_type.rs @@ -0,0 +1,31 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct RecordType { + pub name: String, + pub description: Option, + pub trimmed: bool, +} + +impl From for RecordType { + fn from(raw: RawRecordType) -> Self { + RecordType { + name: raw.name, + description: raw.description.map(|RawDescription(d)| d), + trimmed: match raw.trimmed { + Some(RawTrimmed) => true, + None => false, + }, + } + } +} + +impl From for RawRecordType { + fn from(val: RecordType) -> Self { + RawRecordType { + name: val.name, + description: val.description.map(RawDescription), + trimmed: if val.trimmed { Some(RawTrimmed) } else { None }, + } + } +} diff --git a/arcanite-addml/src/types/reference.rs b/arcanite-addml/src/types/reference.rs new file mode 100644 index 0000000..88f0871 --- /dev/null +++ b/arcanite-addml/src/types/reference.rs @@ -0,0 +1,28 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct Reference { + pub name: Option, + pub context: Option, + pub content: Option, +} + +impl From for Reference { + fn from(raw: RawReference) -> Self { + Reference { + name: raw.name, + context: raw.context.map(|c| c.into()), + content: raw.content.map(|c| c.into()), + } + } +} + +impl From for RawReference { + fn from(val: Reference) -> Self { + RawReference { + name: val.name, + context: val.context.map(|c| c.into()), + content: val.content.map(|c| c.into()), + } + } +} diff --git a/arcanite-addml/src/types/repeating_group.rs b/arcanite-addml/src/types/repeating_group.rs new file mode 100644 index 0000000..52e792f --- /dev/null +++ b/arcanite-addml/src/types/repeating_group.rs @@ -0,0 +1,43 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct RepeatingGroup { + pub name: String, + // TODO: one of repeating_group_occurrence_field or fixed_occurrences must be present, maybe create enum? + pub repeating_group_occurrence_field: Option, + pub fixed_occurrences: Option, + pub field_definition_references: Vec1, +} + +impl From for RepeatingGroup { + fn from(raw: RawRepeatingGroup) -> Self { + RepeatingGroup { + name: raw.name, + repeating_group_occurrence_field: raw + .repeating_group_occurrence_field + .map(|rgof| rgof.into()), + fixed_occurrences: raw.fixed_occurrences.map(|RawFixedOccurrences(u)| u), + field_definition_references: raw + .field_definition_references + .field_definition_reference + .mapped(|fdr| fdr.name), + } + } +} + +impl From for RawRepeatingGroup { + fn from(val: RepeatingGroup) -> Self { + RawRepeatingGroup { + name: val.name, + repeating_group_occurrence_field: val + .repeating_group_occurrence_field + .map(|rgof| rgof.into()), + fixed_occurrences: val.fixed_occurrences.map(RawFixedOccurrences), + field_definition_references: RawFieldDefinitionReferences { + field_definition_reference: val + .field_definition_references + .mapped(|name| RawFieldDefinitionReference { name }), + }, + } + } +} diff --git a/arcanite-addml/src/types/repeating_group_occurrence_field.rs b/arcanite-addml/src/types/repeating_group_occurrence_field.rs new file mode 100644 index 0000000..2885d4d --- /dev/null +++ b/arcanite-addml/src/types/repeating_group_occurrence_field.rs @@ -0,0 +1,22 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct RepeatingGroupOccurrenceField { + definition_reference: String, +} + +impl From for RepeatingGroupOccurrenceField { + fn from(raw: RawRepeatingGroupOccurrenceField) -> Self { + RepeatingGroupOccurrenceField { + definition_reference: raw.definition_reference, + } + } +} + +impl From for RawRepeatingGroupOccurrenceField { + fn from(val: RepeatingGroupOccurrenceField) -> Self { + RawRepeatingGroupOccurrenceField { + definition_reference: val.definition_reference, + } + } +} diff --git a/arcanite-addml/src/types/structure_types.rs b/arcanite-addml/src/types/structure_types.rs new file mode 100644 index 0000000..425d14d --- /dev/null +++ b/arcanite-addml/src/types/structure_types.rs @@ -0,0 +1,39 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct StructureTypes { + pub flat_file_types: Vec1, + pub record_types: Vec, + pub field_types: Vec1, +} + +impl From for StructureTypes { + fn from(raw: RawStructureTypes) -> Self { + StructureTypes { + flat_file_types: raw.flat_file_types.flat_file_type.mapped(|fft| fft.into()), + record_types: raw + .record_types + .map(|RawRecordTypes { record_type }| record_type.mapped(|rt| rt.into()).into()) + .unwrap_or_default(), + field_types: raw.field_types.field_type.mapped(|ft| ft.into()), + } + } +} + +impl From for RawStructureTypes { + fn from(val: StructureTypes) -> Self { + RawStructureTypes { + flat_file_types: RawFlatFileTypes { + flat_file_type: val.flat_file_types.mapped(|fft| fft.into()), + }, + record_types: Vec1::try_from_vec(val.record_types) + .map(|record_types| RawRecordTypes { + record_type: record_types.mapped(|rt| rt.into()), + }) + .ok(), + field_types: RawFieldTypes { + field_type: val.field_types.mapped(|ft| ft.into()), + }, + } + } +}