1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-19 19:56:50 +00:00

Show form references using tree sub command

This commit is contained in:
Paul-Christian Volkmer 2023-09-03 17:31:38 +02:00
parent 31eda3efc9
commit 8edd50feb4
5 changed files with 136 additions and 6 deletions

View File

@ -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,
})

View File

@ -256,7 +256,8 @@ impl Comparable for DataForm {
impl Requires for DataForm {
fn get_required_entries<'a>(&'a self, all: &'a OnkostarEditor) -> Vec<Requirement> {
self.data_catalogues
let mut data_catalogues = self
.data_catalogues
.data_catalogue
.iter()
.collect::<HashSet<_>>()
@ -265,7 +266,45 @@ impl Requires for DataForm {
Some(contained) => Requirement::DataCatalogue(contained),
None => Requirement::ExternalDataCatalogue(entry.to_string()),
})
.collect::<Vec<_>>()
.collect::<Vec<_>>();
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::<HashSet<_>>()
.into_iter()
.map(|entry| match all.find_data_form(entry.as_str()) {
Some(contained) => Requirement::DataFormReference(contained),
None => Requirement::ExternalDataFormReference(entry.to_string()),
})
.collect::<Vec<_>>();
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::<HashSet<_>>()
.into_iter()
.map(|entry| match all.find_unterformular(entry.as_str()) {
Some(contained) => Requirement::UnterformularReference(contained),
None => Requirement::ExternalUnterformularReference(entry.to_string()),
})
.collect::<Vec<_>>();
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)

View File

@ -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

View File

@ -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)
}
}
}
}

View File

@ -260,7 +260,8 @@ impl Comparable for Unterformular {
impl Requires for Unterformular {
fn get_required_entries<'a>(&'a self, all: &'a OnkostarEditor) -> Vec<Requirement> {
self.data_catalogues
let mut data_catalogues = self
.data_catalogues
.data_catalogue
.iter()
.collect::<HashSet<_>>()
@ -269,7 +270,45 @@ impl Requires for Unterformular {
Some(contained) => Requirement::DataCatalogue(contained),
None => Requirement::ExternalDataCatalogue(entry.to_string()),
})
.collect::<Vec<_>>()
.collect::<Vec<_>>();
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::<HashSet<_>>()
.into_iter()
.map(|entry| match all.find_data_form(entry.as_str()) {
Some(contained) => Requirement::DataFormReference(contained),
None => Requirement::ExternalDataFormReference(entry.to_string()),
})
.collect::<Vec<_>>();
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::<HashSet<_>>()
.into_iter()
.map(|entry| match all.find_unterformular(entry.as_str()) {
Some(contained) => Requirement::UnterformularReference(contained),
None => Requirement::ExternalUnterformularReference(entry.to_string()),
})
.collect::<Vec<_>>();
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)