mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-20 20:26:50 +00:00
feat: change form types to fix some OSC issues
This will: * convert "Unterformular" to "DataForm" if flag `Hat_Unterformulare` is set to true * convert "DataForm" to "Unterformular" if required entry for procedure date is not set * sort forms by required form references
This commit is contained in:
parent
8be859d274
commit
95ba080875
@ -207,7 +207,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fix {
|
if fix {
|
||||||
// No operation as of now
|
data = data.fix();
|
||||||
}
|
}
|
||||||
|
|
||||||
if sorted {
|
if sorted {
|
||||||
|
@ -17,14 +17,6 @@
|
|||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
use console::style;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::any::TypeId;
|
|
||||||
use std::cmp::Ordering;
|
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::fmt::Debug;
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
use crate::checks::CheckNotice::ErrorWithCode;
|
use crate::checks::CheckNotice::ErrorWithCode;
|
||||||
use crate::checks::{CheckNotice, Checkable};
|
use crate::checks::{CheckNotice, Checkable};
|
||||||
use crate::model::onkostar_editor::OnkostarEditor;
|
use crate::model::onkostar_editor::OnkostarEditor;
|
||||||
@ -37,6 +29,15 @@ use crate::model::{
|
|||||||
};
|
};
|
||||||
use crate::model::{Haeufigkeiten, Ordner};
|
use crate::model::{Haeufigkeiten, Ordner};
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
|
use console::style;
|
||||||
|
use quick_xml::de::from_str;
|
||||||
|
use quick_xml::se::Serializer;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::any::TypeId;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DataFormType;
|
pub struct DataFormType;
|
||||||
@ -201,6 +202,24 @@ pub struct Form<Type> {
|
|||||||
ansichten: Option<Ansichten>,
|
ansichten: Option<Ansichten>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Form<DataFormType> {
|
||||||
|
pub(crate) fn to_unterformular(&self) -> Form<UnterformularType> {
|
||||||
|
let mut buf = String::new();
|
||||||
|
let serializer = Serializer::new(&mut buf);
|
||||||
|
self.serialize(serializer).expect("Generated XML");
|
||||||
|
from_str::<Form<UnterformularType>>(&buf).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Form<UnterformularType> {
|
||||||
|
pub(crate) fn to_dataform(&self) -> Form<DataFormType> {
|
||||||
|
let mut buf = String::new();
|
||||||
|
let serializer = Serializer::new(&mut buf);
|
||||||
|
self.serialize(serializer).expect("Generated XML");
|
||||||
|
from_str::<Form<DataFormType>>(&buf).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<Type: 'static> FormEntryContainer for Form<Type> {
|
impl<Type: 'static> FormEntryContainer for Form<Type> {
|
||||||
fn apply_profile(&mut self, profile: &Profile) {
|
fn apply_profile(&mut self, profile: &Profile) {
|
||||||
profile.forms.iter().for_each(|profile_form| {
|
profile.forms.iter().for_each(|profile_form| {
|
||||||
|
@ -211,6 +211,63 @@ impl OnkostarEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fix(mut self) -> Self {
|
||||||
|
fn has_error1(form: &Form<UnterformularType>, error_code: &str) -> bool {
|
||||||
|
form.check()
|
||||||
|
.iter()
|
||||||
|
.filter(|&check_notice| match check_notice {
|
||||||
|
CheckNotice::ErrorWithCode { code, .. } => code == error_code,
|
||||||
|
_ => false,
|
||||||
|
})
|
||||||
|
.count()
|
||||||
|
> 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_error2(form: &Form<DataFormType>, error_code: &str) -> bool {
|
||||||
|
form.check()
|
||||||
|
.iter()
|
||||||
|
.filter(|&check_notice| match check_notice {
|
||||||
|
CheckNotice::ErrorWithCode { code, .. } => code == error_code,
|
||||||
|
_ => false,
|
||||||
|
})
|
||||||
|
.count()
|
||||||
|
> 0
|
||||||
|
}
|
||||||
|
|
||||||
|
self.editor
|
||||||
|
.data_form
|
||||||
|
.iter_mut()
|
||||||
|
.filter(|form| has_error2(form, "2023-0002"))
|
||||||
|
.map(|form| form.to_unterformular())
|
||||||
|
.for_each(|form| self.editor.unterformular.push(form));
|
||||||
|
|
||||||
|
self.editor
|
||||||
|
.unterformular
|
||||||
|
.iter_mut()
|
||||||
|
.filter(|form| has_error1(form, "2023-0001"))
|
||||||
|
.map(|form| form.to_dataform())
|
||||||
|
.for_each(|form| self.editor.data_form.push(form));
|
||||||
|
|
||||||
|
self.editor
|
||||||
|
.data_form
|
||||||
|
.retain(|form| !has_error2(form, "2023-0002"));
|
||||||
|
|
||||||
|
self.editor
|
||||||
|
.unterformular
|
||||||
|
.retain(|form| !has_error1(form, "2023-0001"));
|
||||||
|
|
||||||
|
// Sort forms by requirements
|
||||||
|
self.editor
|
||||||
|
.data_form
|
||||||
|
.sort_unstable_by(Form::compare_by_requirement);
|
||||||
|
|
||||||
|
self.editor
|
||||||
|
.unterformular
|
||||||
|
.sort_unstable_by(Form::compare_by_requirement);
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn sorted(&mut self) {
|
pub fn sorted(&mut self) {
|
||||||
self.editor
|
self.editor
|
||||||
.property_catalogue
|
.property_catalogue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user