1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use crate::validation::common::{ValidationError, ValidationErrors};
use crate::structure::gxmodel::GxModel;
use uuid::Uuid;
use std::collections::HashSet;
#[derive(Debug)]
pub struct Validation {}
impl Validation {
pub fn validate(model: &GxModel) -> ValidationErrors {
let mut errors = Vec::<ValidationError>::new();
/*
errors.extend(Validation::all_locales_have_translation_docs(&model));
errors.extend(Validation::all_translation_docs_have_locales(&model));
errors.extend(
Validation::all_page_xflow_references_point_to_existing_entities(&model),
);
errors.extend(Validation::all_doc_collections_have_correct_unique_keys(
&model,
));
*/
errors
}
/*
pub fn all_locales_have_translation_docs(model: &GxModel) -> ValidationErrors {
debug!("all_locales_have_translation_docs");
let mut errors = Vec::<ValidationError>::new();
for locale in &model.config.body.locales {
if !model.has_translation(&locale) {
errors.push(ValidationError {
code: 1,
message: format!("Model: locale '{:?}' has no translation document", &locale),
paths: vec!["/config/locales".to_owned()],
});
}
}
errors
}
pub fn all_translation_docs_have_locales(model: &GxModel) -> Vec<ValidationError> {
debug!("all_translation_docs_have_locales");
let mut errors = Vec::<ValidationError>::new();
for t in &model.translations {
if !model.has_locale(&t.body.locale) {
errors.push(ValidationError {
code: 1,
message: format!("Model: translation doc exists with locale '{:?}' but it is not listed as a supported locale",
&t.body.locale),
paths: vec!["/config/translations".to_owned()],
});
}
}
errors
}
pub fn all_page_xflow_references_point_to_existing_entities(
model: &GxModel,
) -> Vec<ValidationError> {
debug!("all_page_xflow_references_point_to_existing_entities");
let mut errors = Vec::<ValidationError>::new();
let xflow_ids = model.all_xflow_ids();
for page in &model.pages {
for xflow_reference in &page.all_xflow_references() {
if !xflow_ids.contains(xflow_reference) {
let message = format!(
"Page: Contains a reference to xflow id '{}', which does not exist in this model",
xflow_reference
);
errors.push(ValidationError {
code: 1,
message: message,
paths: vec![format!("/pages/{id}", id = page.id)],
});
}
}
}
errors
}
pub fn all_doc_collections_have_correct_unique_keys(
model: &GxModel,
) -> Vec<ValidationError> {
debug!("all_doc_collections_have_correct_unique_keys");
let mut errors = Vec::<ValidationError>::new();
let mut xflow_ids = HashSet::<&Uuid>::new();
for doc in &model.xflows {
if xflow_ids.contains(&doc.id) {
let message = format!("xflow: Duplicate ID found in XFlow document '{}'", doc.id);
errors.push(ValidationError {
code: 1,
message: message,
paths: vec![format!("/xflow/{id}", id = doc.id)],
});
} else {
xflow_ids.insert(&doc.id);
}
}
let mut page_ids = HashSet::<&Uuid>::new();
for doc in &model.pages {
if page_ids.contains(&doc.id) {
let message = format!("page: Duplicate ID found in page document '{}'", doc.id);
errors.push(ValidationError {
code: 1,
message: message,
paths: vec![format!("/page/{id}", id = doc.id)],
});
} else {
page_ids.insert(&doc.id);
}
}
let mut translation_ids = HashSet::<&Uuid>::new();
for doc in &model.translations {
if translation_ids.contains(&doc.id) {
let message = format!(
"translation: Duplicate ID found in translation document '{}'",
doc.id
);
errors.push(ValidationError {
code: 1,
message: message,
paths: vec![format!("/translation/{id}", id = doc.id)],
});
} else {
translation_ids.insert(&doc.id);
}
}
errors
}
*/
}