From 8edd50feb4f6699a3ed51fec1d88c195571e467e Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sun, 3 Sep 2023 17:31:38 +0200 Subject: [PATCH] Show form references using tree sub command --- src/model/data_catalogue.rs | 4 +-- src/model/data_form.rs | 49 ++++++++++++++++++++++++++++++++++-- src/model/onkostar_editor.rs | 26 +++++++++++++++++++ src/model/requirements.rs | 14 +++++++++++ src/model/unterformular.rs | 49 ++++++++++++++++++++++++++++++++++-- 5 files changed, 136 insertions(+), 6 deletions(-) diff --git a/src/model/data_catalogue.rs b/src/model/data_catalogue.rs index e46b0cd..750ee47 100644 --- a/src/model/data_catalogue.rs +++ b/src/model/data_catalogue.rs @@ -127,10 +127,10 @@ impl Requires for DataCatalogue { .iter() .map(|entry| match entry { Requirement::PropertyCatalogue(_) => { - Some(format!(" + {}\n", entry.to_string())) + Some(format!(" - {}\n", entry.to_string())) } Requirement::ExternalPropertyCatalogue(_) => { - Some(format!(" + {}\n", entry.to_string())) + Some(format!(" - {}\n", entry.to_string())) } _ => None, }) diff --git a/src/model/data_form.rs b/src/model/data_form.rs index f01cdf0..33a7a23 100644 --- a/src/model/data_form.rs +++ b/src/model/data_form.rs @@ -256,7 +256,8 @@ impl Comparable for DataForm { impl Requires for DataForm { fn get_required_entries<'a>(&'a self, all: &'a OnkostarEditor) -> Vec { - self.data_catalogues + let mut data_catalogues = self + .data_catalogues .data_catalogue .iter() .collect::>() @@ -265,7 +266,45 @@ impl Requires for DataForm { Some(contained) => Requirement::DataCatalogue(contained), None => Requirement::ExternalDataCatalogue(entry.to_string()), }) - .collect::>() + .collect::>(); + + let data_forms = &mut self + .entries + .entry + .iter() + .filter(|&entry| entry.get_type() == "formReference") + .filter_map(|entry| match &entry.referenced_data_form { + Some(name) => Some(name), + None => None, + }) + .collect::>() + .into_iter() + .map(|entry| match all.find_data_form(entry.as_str()) { + Some(contained) => Requirement::DataFormReference(contained), + None => Requirement::ExternalDataFormReference(entry.to_string()), + }) + .collect::>(); + data_catalogues.append(data_forms); + + let unterformulare = &mut self + .entries + .entry + .iter() + .filter(|&entry| entry.get_type() == "formReference") + .filter_map(|entry| match &entry.referenced_data_form { + Some(name) => Some(name), + None => None, + }) + .collect::>() + .into_iter() + .map(|entry| match all.find_unterformular(entry.as_str()) { + Some(contained) => Requirement::UnterformularReference(contained), + None => Requirement::ExternalUnterformularReference(entry.to_string()), + }) + .collect::>(); + data_catalogues.append(unterformulare); + + data_catalogues } fn to_requirement_string<'a>(&'a self, all: &'a OnkostarEditor) -> String { @@ -301,6 +340,12 @@ impl Requires for DataForm { Requirement::ExternalDataCatalogue(_) => { Some(format!(" + {}\n", entry.to_string())) } + Requirement::UnterformularReference(_) => { + Some(format!(" > {}\n", entry.to_string())) + } + Requirement::ExternalUnterformularReference(_) => { + Some(format!(" > {}\n", entry.to_string())) + } _ => None, }) .filter(Option::is_some) diff --git a/src/model/onkostar_editor.rs b/src/model/onkostar_editor.rs index 7a35ebb..9ee3d9f 100644 --- a/src/model/onkostar_editor.rs +++ b/src/model/onkostar_editor.rs @@ -74,6 +74,32 @@ impl OnkostarEditor { } } + pub fn find_data_form<'a>(&'a self, name: &str) -> Option<&'a DataForm> { + match self + .editor + .data_form + .iter() + .filter(|&item| item.get_name().eq_ignore_ascii_case(name)) + .nth(0) + { + Some(x) => Some(x), + _ => None, + } + } + + pub fn find_unterformular<'a>(&'a self, name: &str) -> Option<&'a Unterformular> { + match self + .editor + .unterformular + .iter() + .filter(|&item| item.get_name().eq_ignore_ascii_case(name)) + .nth(0) + { + Some(x) => Some(x), + _ => None, + } + } + pub fn apply_profile(&mut self, profile: &Profile) { self.editor .data_form diff --git a/src/model/requirements.rs b/src/model/requirements.rs index 04e4592..f55a871 100644 --- a/src/model/requirements.rs +++ b/src/model/requirements.rs @@ -23,8 +23,10 @@ */ use crate::model::data_catalogue::DataCatalogue; +use crate::model::data_form::DataForm; use crate::model::onkostar_editor::OnkostarEditor; use crate::model::property_catalogue::PropertyCatalogue; +use crate::model::unterformular::Unterformular; use crate::model::Listable; #[allow(clippy::enum_variant_names)] @@ -33,6 +35,10 @@ pub enum Requirement<'a> { DataCatalogue(&'a DataCatalogue), ExternalPropertyCatalogue(String), ExternalDataCatalogue(String), + DataFormReference(&'a DataForm), + UnterformularReference(&'a Unterformular), + ExternalDataFormReference(String), + ExternalUnterformularReference(String), } impl ToString for Requirement<'_> { @@ -46,6 +52,14 @@ impl ToString for Requirement<'_> { Requirement::ExternalDataCatalogue(name) => { format!("Datenkatalog (-) '{}' - hier nicht enthalten", name) } + Requirement::DataFormReference(item) => item.to_listed_string(), + Requirement::UnterformularReference(item) => item.to_listed_string(), + Requirement::ExternalDataFormReference(name) => { + format!("Formular (-) '{}' - hier nicht enthalten", name) + } + Requirement::ExternalUnterformularReference(name) => { + format!("Unterformular (-) '{}' - hier nicht enthalten", name) + } } } } diff --git a/src/model/unterformular.rs b/src/model/unterformular.rs index 0d8fd1c..75fc1e5 100644 --- a/src/model/unterformular.rs +++ b/src/model/unterformular.rs @@ -260,7 +260,8 @@ impl Comparable for Unterformular { impl Requires for Unterformular { fn get_required_entries<'a>(&'a self, all: &'a OnkostarEditor) -> Vec { - self.data_catalogues + let mut data_catalogues = self + .data_catalogues .data_catalogue .iter() .collect::>() @@ -269,7 +270,45 @@ impl Requires for Unterformular { Some(contained) => Requirement::DataCatalogue(contained), None => Requirement::ExternalDataCatalogue(entry.to_string()), }) - .collect::>() + .collect::>(); + + let data_forms = &mut self + .entries + .entry + .iter() + .filter(|&entry| entry.get_type() == "formReference") + .filter_map(|entry| match &entry.referenced_data_form { + Some(name) => Some(name), + None => None, + }) + .collect::>() + .into_iter() + .map(|entry| match all.find_data_form(entry.as_str()) { + Some(contained) => Requirement::DataFormReference(contained), + None => Requirement::ExternalDataFormReference(entry.to_string()), + }) + .collect::>(); + data_catalogues.append(data_forms); + + let unterformulare = &mut self + .entries + .entry + .iter() + .filter(|&entry| entry.get_type() == "formReference") + .filter_map(|entry| match &entry.referenced_data_form { + Some(name) => Some(name), + None => None, + }) + .collect::>() + .into_iter() + .map(|entry| match all.find_unterformular(entry.as_str()) { + Some(contained) => Requirement::UnterformularReference(contained), + None => Requirement::ExternalUnterformularReference(entry.to_string()), + }) + .collect::>(); + data_catalogues.append(unterformulare); + + data_catalogues } fn to_requirement_string<'a>(&'a self, all: &'a OnkostarEditor) -> String { @@ -304,6 +343,12 @@ impl Requires for Unterformular { Requirement::ExternalDataCatalogue(_) => { Some(format!(" + {}\n", entry.to_string())) } + Requirement::UnterformularReference(_) => { + Some(format!(" > {}\n", entry.to_string())) + } + Requirement::ExternalUnterformularReference(_) => { + Some(format!(" > {}\n", entry.to_string())) + } _ => None, }) .filter(Option::is_some)