Made a specific id for names.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
@@ -5,9 +5,9 @@ use crate::{
|
||||
definition::{DocDef, DocFuncType},
|
||||
field::Field,
|
||||
},
|
||||
message::wrapper::Message,
|
||||
message::{wrapper::Message, MessageAction},
|
||||
mtterror::{ErrorID, MTTError},
|
||||
name::NameType,
|
||||
name::{NameID, NameType},
|
||||
queue::{
|
||||
data_director::{Include, Path, RegMsg, Register, RouteID},
|
||||
router::Queue,
|
||||
@@ -171,11 +171,11 @@ impl Index {
|
||||
}
|
||||
|
||||
struct Indexes {
|
||||
data: HashMap<Uuid, Index>,
|
||||
data: HashMap<NameID, Index>,
|
||||
}
|
||||
|
||||
impl Indexes {
|
||||
fn new(settings: &HashMap<Uuid, IndexType>) -> Self {
|
||||
fn new(settings: &HashMap<NameID, IndexType>) -> Self {
|
||||
let mut output = HashMap::new();
|
||||
for (key, value) in settings.iter() {
|
||||
output.insert(key.clone(), value.create_index());
|
||||
@@ -183,15 +183,20 @@ impl Indexes {
|
||||
Self { data: output }
|
||||
}
|
||||
|
||||
fn index_ids(&self) -> HashSet<&Uuid> {
|
||||
self.data.keys().collect::<HashSet<&Uuid>>()
|
||||
fn index_ids(&self) -> HashSet<&NameID> {
|
||||
self.data.keys().collect::<HashSet<&NameID>>()
|
||||
}
|
||||
|
||||
fn pull(&self, field_id: &Uuid, calc: &Calculation) -> Result<HashSet<Oid>, MTTError> {
|
||||
fn pull(&self, field_id: &NameID, calc: &Calculation) -> Result<HashSet<Oid>, MTTError> {
|
||||
self.data.get(field_id).unwrap().pull(calc)
|
||||
}
|
||||
|
||||
fn add_to_index(&mut self, field_name: &Uuid, field: Field, oid: Oid) -> Result<(), MTTError> {
|
||||
fn add_to_index(
|
||||
&mut self,
|
||||
field_name: &NameID,
|
||||
field: Field,
|
||||
oid: Oid,
|
||||
) -> Result<(), MTTError> {
|
||||
let index = match self.data.get_mut(field_name) {
|
||||
Some(data) => data,
|
||||
None => return Ok(()),
|
||||
@@ -199,7 +204,7 @@ impl Indexes {
|
||||
index.add(field, oid)
|
||||
}
|
||||
|
||||
fn validate(&self, field_name: &Uuid, value: &Field) -> Result<(), MTTError> {
|
||||
fn validate(&self, field_name: &NameID, value: &Field) -> Result<(), MTTError> {
|
||||
match self.data.get(field_name) {
|
||||
Some(index) => match index.validate(value) {
|
||||
Ok(_) => {}
|
||||
@@ -210,7 +215,7 @@ impl Indexes {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn iter_mut(&mut self) -> impl Iterator<Item = (&Uuid, &mut Index)> {
|
||||
fn iter_mut(&mut self) -> impl Iterator<Item = (&NameID, &mut Index)> {
|
||||
self.data.iter_mut()
|
||||
}
|
||||
}
|
||||
@@ -361,7 +366,7 @@ struct DocumentFile {
|
||||
docdef: DocDef,
|
||||
docs: InternalRecords,
|
||||
indexes: Indexes,
|
||||
name_id: Uuid,
|
||||
name_id: NameID,
|
||||
queue: Queue,
|
||||
routes: HashMap<RouteID, DocFuncType>,
|
||||
rx: Receiver<Message>,
|
||||
@@ -373,7 +378,7 @@ impl DocumentFile {
|
||||
rx: Receiver<Message>,
|
||||
docdef: DocDef,
|
||||
routes: HashMap<RouteID, DocFuncType>,
|
||||
name_id: Uuid,
|
||||
name_id: NameID,
|
||||
) -> Self {
|
||||
let indexes = Indexes::new(docdef.get_indexes());
|
||||
Self {
|
||||
@@ -472,11 +477,12 @@ impl DocumentFile {
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
let field_id = match self.docdef.get_field_id(field_name) {
|
||||
let id_holder = field_name.into();
|
||||
let field_id = match self.docdef.get_field_id(id_holder.clone()) {
|
||||
Ok(data) => data,
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
let output = match self.docdef.validate(field_id.clone(), value) {
|
||||
let output = match self.docdef.validate(id_holder.clone(), value) {
|
||||
Ok(data) => data,
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
@@ -493,10 +499,17 @@ impl DocumentFile {
|
||||
_ => return,
|
||||
};
|
||||
let mut holder = InternalRecord::new();
|
||||
|
||||
let mut field_ids = self.docdef.get_field_ids();
|
||||
println!("{:?}", field_ids);
|
||||
for (name_id, value) in addition.iter() {}
|
||||
|
||||
for (name_id, value) in addition.iter() {
|
||||
let field_id = match self.docdef.get_field_id(name_id) {
|
||||
Ok(id) => id,
|
||||
Err(err) => {
|
||||
Err(mut err) => {
|
||||
err.add_parent(ErrorID::Field(name_id.clone()));
|
||||
err.add_parent(ErrorID::Document(msg.doc_name().clone()));
|
||||
let reply = msg.response(err);
|
||||
self.queue.send(reply);
|
||||
return;
|
||||
@@ -504,14 +517,16 @@ impl DocumentFile {
|
||||
};
|
||||
holder.insert(field_id.clone(), value.get(&Field::None));
|
||||
}
|
||||
for field_id in self.docdef.field_ids().iter() {
|
||||
for field_id in self.docdef.get_field_ids().iter() {
|
||||
let value = match holder.get(field_id) {
|
||||
Some(data) => data,
|
||||
None => &Field::None,
|
||||
};
|
||||
let corrected = match self.validate(field_id, value) {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
Err(mut err) => {
|
||||
err.add_parent(ErrorID::Field(field_id.clone().into()));
|
||||
err.add_parent(ErrorID::Document(msg.doc_name().clone()));
|
||||
let reply = msg.response(err);
|
||||
self.queue.send(reply);
|
||||
return;
|
||||
@@ -570,8 +585,8 @@ impl DocumentFile {
|
||||
|
||||
fn run_query(&self, query: &Query) -> Result<InternalRecords, MTTError> {
|
||||
let indexed_ids = self.indexes.index_ids();
|
||||
let mut indexed: HashMap<Uuid, Calculation> = HashMap::new();
|
||||
let mut unindexed: HashMap<Uuid, Calculation> = HashMap::new();
|
||||
let mut indexed: HashMap<NameID, Calculation> = HashMap::new();
|
||||
let mut unindexed: HashMap<NameID, Calculation> = HashMap::new();
|
||||
for (field, data) in query.iter() {
|
||||
let id = match self.docdef.get_field_id(field) {
|
||||
Ok(fid) => fid,
|
||||
@@ -647,7 +662,7 @@ impl DocumentFile {
|
||||
update: &Update,
|
||||
msg: &Message,
|
||||
) -> Result<Records, MTTError> {
|
||||
let mut changes: HashMap<Uuid, &CalcValue> = HashMap::new();
|
||||
let mut changes: HashMap<NameID, &CalcValue> = HashMap::new();
|
||||
for (key, value) in update.get_values().iter() {
|
||||
let field_id = match self.docdef.get_field_id(key) {
|
||||
Ok(data) => data,
|
||||
@@ -1125,7 +1140,6 @@ mod document_files {
|
||||
}
|
||||
assert!(entries.is_empty(), "did not use {:?}", entries);
|
||||
}
|
||||
*/
|
||||
|
||||
#[test]
|
||||
fn errors_on_wrong_field_name() {
|
||||
@@ -1145,8 +1159,10 @@ mod document_files {
|
||||
_ => unreachable!("got {:?}: should have been an error", result.get_action()),
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[test]
|
||||
#[ignore = "move to lib"]
|
||||
fn errors_on_wrong_field_type() {
|
||||
let mut test_doc = TestDocument::new([FieldType::Uuid].to_vec());
|
||||
test_doc.start(standard_paths());
|
||||
@@ -1769,6 +1785,7 @@ mod document_files {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "move to lib"]
|
||||
fn update_errors_on_bad_field_type() {
|
||||
let mut doc = TestDocument::new([FieldType::Uuid, FieldType::StaticString].to_vec());
|
||||
doc.start(standard_paths());
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{
|
||||
document::create::IndexType,
|
||||
message::MessageAction,
|
||||
mtterror::{ErrorID, MTTError},
|
||||
name::{Name, NameType, Names},
|
||||
name::{Name, NameID, NameType, Names},
|
||||
queue::data_director::{Include, Path},
|
||||
};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -62,7 +62,7 @@ impl FieldSetting {
|
||||
_ => {
|
||||
let vft: FieldType = value.into();
|
||||
if vft != self.fieldtype {
|
||||
let err = MTTError::new(ErrorID::FieldInvalidType);
|
||||
let err = MTTError::new(ErrorID::FieldTypeExpected(self.fieldtype.clone()));
|
||||
return Err(err);
|
||||
}
|
||||
Ok(value.clone())
|
||||
@@ -90,12 +90,13 @@ mod fieldsettings {
|
||||
|
||||
#[test]
|
||||
fn validates_for_bad_field_type() {
|
||||
let fset = FieldSetting::new(FieldType::Uuid);
|
||||
let test_type = FieldType::Uuid;
|
||||
let fset = FieldSetting::new(test_type.clone());
|
||||
let value: Field = "text".into();
|
||||
match fset.validate(&value) {
|
||||
Ok(data) => unreachable!("got {:?}: should have gotten an error", data),
|
||||
Err(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::FieldInvalidType => {}
|
||||
ErrorID::FieldTypeExpected(data) => assert_eq!(data, &test_type),
|
||||
_ => unreachable!("got {:?}: should have gotten a value", err),
|
||||
},
|
||||
}
|
||||
@@ -201,8 +202,8 @@ impl PathAction {
|
||||
pub struct DocDef {
|
||||
doc_names: Vec<Name>,
|
||||
field_names: Names,
|
||||
fields: HashMap<Uuid, FieldSetting>,
|
||||
indexes: HashMap<Uuid, IndexType>,
|
||||
fields: HashMap<NameID, FieldSetting>,
|
||||
indexes: HashMap<NameID, IndexType>,
|
||||
routes: Vec<PathAction>,
|
||||
}
|
||||
|
||||
@@ -272,7 +273,10 @@ impl DocDef {
|
||||
&self.field_names
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_field_ids(&self) -> HashSet<NameID> {
|
||||
self.field_names.get_ids()
|
||||
}
|
||||
|
||||
fn get_field_names_mut(&mut self) -> &mut Names {
|
||||
&mut self.field_names
|
||||
}
|
||||
@@ -282,7 +286,7 @@ impl DocDef {
|
||||
self.fields.insert(id, FieldSetting::new(ftype));
|
||||
}
|
||||
|
||||
pub fn get_field_id<NT>(&self, field_name: NT) -> Result<Uuid, MTTError>
|
||||
pub fn get_field_id<NT>(&self, field_name: NT) -> Result<NameID, MTTError>
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
@@ -292,7 +296,6 @@ impl DocDef {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get_field<NT>(&self, field_name: NT) -> Result<&FieldSetting, MTTError>
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
@@ -304,7 +307,6 @@ impl DocDef {
|
||||
Ok(self.fields.get(&id).unwrap())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get_field_mut<NT>(&mut self, field_name: NT) -> Result<&mut FieldSetting, MTTError>
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
@@ -316,7 +318,7 @@ impl DocDef {
|
||||
Ok(self.fields.get_mut(&id).unwrap())
|
||||
}
|
||||
|
||||
pub fn field_ids(&self) -> HashSet<Uuid> {
|
||||
pub fn field_ids(&self) -> HashSet<NameID> {
|
||||
self.fields.keys().cloned().collect()
|
||||
}
|
||||
|
||||
@@ -354,12 +356,11 @@ impl DocDef {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_indexes(&self) -> &HashMap<Uuid, IndexType> {
|
||||
pub fn get_indexes(&self) -> &HashMap<NameID, IndexType> {
|
||||
&self.indexes
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn iter(&self) -> impl Iterator<Item = (&Uuid, &FieldSetting)> {
|
||||
fn iter(&self) -> impl Iterator<Item = (&NameID, &FieldSetting)> {
|
||||
self.fields.iter()
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
action::Field,
|
||||
message::MessageAction,
|
||||
mtterror::{ErrorID, MTTError},
|
||||
name::{Name, NameType, Names},
|
||||
name::{Name, NameID, NameType, Names},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
@@ -38,7 +38,7 @@ mod oids {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct InternalRecord {
|
||||
data: HashMap<Uuid, Field>,
|
||||
data: HashMap<NameID, Field>,
|
||||
}
|
||||
|
||||
impl InternalRecord {
|
||||
@@ -48,7 +48,7 @@ impl InternalRecord {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert<F>(&mut self, id: Uuid, data: F) -> Field
|
||||
pub fn insert<F>(&mut self, id: NameID, data: F) -> Field
|
||||
where
|
||||
F: Into<Field>,
|
||||
{
|
||||
@@ -58,7 +58,7 @@ impl InternalRecord {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, id: &Uuid) -> Option<&Field> {
|
||||
pub fn get(&self, id: &NameID) -> Option<&Field> {
|
||||
self.data.get(id)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user