Skip to content

Commit

Permalink
Merge pull request #56 from EdwinBetanc0urt/bugfix/uuid-null-panicked…
Browse files Browse the repository at this point in the history
…-runtime

fix: When `UUID` is null stop thread process.
  • Loading branch information
yamelsenih authored Sep 30, 2024
2 parents f5ddcca + 623daf6 commit 9a15583
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 45 deletions.
21 changes: 14 additions & 7 deletions src/models/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ impl Browser {
browser.id = _id;
browser
}

pub fn to_string(&self) -> String {
format!("Browser: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value)
}
}

impl IndexDocument for Browser {
Expand All @@ -204,9 +208,12 @@ impl IndexDocument for Browser {
json!(self)
}

fn id(self: &Self) -> String {
self.id.to_owned().unwrap()
}
fn id(self: &Self) -> String {
self.id.to_owned().unwrap_or_else(|| {
log::error!("{}", self.to_string());
"".to_string()
})
}

fn index_name(self: &Self) -> String {
match &self.index_value {
Expand Down Expand Up @@ -281,9 +288,9 @@ pub async fn browser_from_id(_id: Option<String>, _language: Option<&String>, _d
Error::new(ErrorKind::InvalidData.into(), "Browser Identifier is Mandatory").to_string()
);
}
let mut _document = Browser::from_id(_id);
let mut _document: Browser = Browser::from_id(_id);

let _index_name = match get_index_name("browser".to_string(),_language, _dictionary_code).await {
let _index_name: String = match get_index_name("browser".to_string(),_language, _dictionary_code).await {
Ok(index_name) => index_name,
Err(error) => {
log::error!("Index name error: {:?}", error.to_string());
Expand Down Expand Up @@ -322,7 +329,7 @@ pub async fn browsers(_language: Option<&String>, _search_value: Option<&String>
};

// Find index
let _index_name = match get_index_name("browser".to_string(), _language, _dictionary_code).await {
let _index_name: String = match get_index_name("browser".to_string(), _language, _dictionary_code).await {
Ok(index_name) => index_name,
Err(error) => {
log::error!("Index name error: {:?}", error.to_string());
Expand All @@ -331,7 +338,7 @@ pub async fn browsers(_language: Option<&String>, _search_value: Option<&String>
};
log::info!("Index to search {:}", _index_name);

let mut _document = Browser::default();
let mut _document: Browser = Browser::default();
_document.index_value = Some(_index_name);
let _browser_document: &dyn IndexDocument = &_document;
match find(_browser_document, _search_value, 0, 10).await {
Expand Down
19 changes: 13 additions & 6 deletions src/models/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl Form {
form.id = _id;
form
}

pub fn to_string(&self) -> String {
format!("Form: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value)
}
}

impl IndexDocument for Form {
Expand All @@ -98,7 +102,10 @@ impl IndexDocument for Form {
}

fn id(self: &Self) -> String {
self.id.to_owned().unwrap()
self.id.to_owned().unwrap_or_else(|| {
log::error!("{}", self.to_string());
"".to_string()
})
}

fn index_name(self: &Self) -> String {
Expand Down Expand Up @@ -129,9 +136,9 @@ pub async fn form_from_id(_id: Option<String>, _language: Option<&String>, _dict
Error::new(ErrorKind::InvalidData.into(), "Form Identifier is Mandatory").to_string()
);
}
let mut _document = Form::from_id(_id);
let mut _document: Form = Form::from_id(_id);

let _index_name = match get_index_name("form".to_string(), _language, _dictionary_code).await {
let _index_name: String = match get_index_name("form".to_string(), _language, _dictionary_code).await {
Ok(index_name) => index_name,
Err(error) => {
log::error!("Index name error: {:?}", error.to_string());
Expand All @@ -145,7 +152,7 @@ pub async fn form_from_id(_id: Option<String>, _language: Option<&String>, _dict
match get_by_id(_form_document).await {
Ok(value) => {
let form: Form = serde_json::from_value(value).unwrap();
log::info!("Finded Value: {:?}", form.id);
log::info!("Finded Form Value: {:?}", form.id);
// Ok(FormResponse {
// form: Some(form)
// })
Expand All @@ -167,7 +174,7 @@ pub async fn forms(_language: Option<&String>, _search_value: Option<&String>, _
};

// Find index
let _index_name = match get_index_name("form".to_string(),_language, _dictionary_code).await {
let _index_name: String = match get_index_name("form".to_string(),_language, _dictionary_code).await {
Ok(index_name) => index_name,
Err(error) => {
log::error!("Index name error: {:?}", error.to_string());
Expand All @@ -176,7 +183,7 @@ pub async fn forms(_language: Option<&String>, _search_value: Option<&String>, _
};
log::info!("Index to search {:}", _index_name);

let mut _document = Form::default();
let mut _document: Form = Form::default();
_document.index_value = Some(_index_name);
let _forms_document: &dyn IndexDocument = &_document;
match find(_forms_document, _search_value, 0, 10).await {
Expand Down
13 changes: 10 additions & 3 deletions src/models/menu_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ impl MenuItem {
}
})
}

pub fn to_string(&self) -> String {
format!("Menu Item: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value)
}
}

impl IndexDocument for MenuItem {
Expand All @@ -267,9 +271,12 @@ impl IndexDocument for MenuItem {
json!(self)
}

fn id(self: &Self) -> String {
self.id.to_owned().unwrap()
}
fn id(self: &Self) -> String {
self.id.to_owned().unwrap_or_else(|| {
log::error!("{}", self.to_string());
"".to_string()
})
}

fn index_name(self: &Self) -> String {
match &self.index_value {
Expand Down
19 changes: 13 additions & 6 deletions src/models/menu_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl MenuTree {
menu.id = _id;
menu
}

pub fn to_string(&self) -> String {
format!("Menu Tree: UUID {:?}, ID {:?}, Index: {:?}", self.uuid, self.internal_id, self.index_value)
}
}

impl IndexDocument for MenuTree {
Expand All @@ -95,9 +99,12 @@ impl IndexDocument for MenuTree {
json!(self)
}

fn id(self: &Self) -> String {
self.id.to_owned().unwrap()
}
fn id(self: &Self) -> String {
self.id.to_owned().unwrap_or_else(|| {
log::error!("{}", self.to_string());
"".to_string()
})
}

fn index_name(self: &Self) -> String {
match &self.index_value {
Expand Down Expand Up @@ -127,9 +134,9 @@ pub async fn menu_tree_from_id(_id: Option<String>, _dictionary_code: Option<&St
Error::new(ErrorKind::InvalidData.into(), "MenuTree Identifier is Mandatory")
);
}
let mut _document = MenuTree::from_id(_id);
let mut _document: MenuTree = MenuTree::from_id(_id);

let mut _index_name = "menu_tree".to_string();
let mut _index_name: String = "menu_tree".to_string();
if let Some(code) = _dictionary_code {
if !code.trim().is_empty() {
_index_name.push_str("_");
Expand All @@ -143,7 +150,7 @@ pub async fn menu_tree_from_id(_id: Option<String>, _dictionary_code: Option<&St
match get_by_id(_menu_document).await {
Ok(value) => {
let mut menu: MenuTree = serde_json::from_value(value).unwrap();
log::info!("Finded Value: {:?}", menu.id);
log::info!("Finded Menu Tree Value: {:?}", menu.id);
// sort menu children nodes by sequence
if let Some(ref mut children) = menu.children {
children.sort_by_key(|child| child.sequence.clone().unwrap_or(0));
Expand Down
23 changes: 15 additions & 8 deletions src/models/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ impl Process {
process.id = _id;
process
}

pub fn to_string(&self) -> String {
format!("Process/Report: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value)
}
}

impl IndexDocument for Process {
Expand All @@ -200,9 +204,12 @@ impl IndexDocument for Process {
json!(self)
}

fn id(self: &Self) -> String {
self.id.to_owned().unwrap()
}
fn id(self: &Self) -> String {
self.id.to_owned().unwrap_or_else(|| {
log::error!("{}", self.to_string());
"".to_string()
})
}

fn index_name(self: &Self) -> String {
match &self.index_value {
Expand Down Expand Up @@ -262,9 +269,9 @@ pub async fn process_from_id(_id: Option<String>, _language: Option<&String>, _d
Error::new(ErrorKind::InvalidData.into(), "Process/Report Identifier is Mandatory").to_string()
);
}
let mut _document = Process::from_id(_id);
let mut _document: Process = Process::from_id(_id);

let _index_name = match get_index_name("process".to_string(), _language, _dictionary_code).await {
let _index_name: String = match get_index_name("process".to_string(), _language, _dictionary_code).await {
Ok(index_name) => index_name,
Err(error) => {
log::error!("Index name error: {:?}", error.to_string());
Expand All @@ -278,7 +285,7 @@ pub async fn process_from_id(_id: Option<String>, _language: Option<&String>, _d
match get_by_id(_process_document).await {
Ok(value) => {
let mut process: Process = serde_json::from_value(value).unwrap();
log::info!("Finded Value: {:?}", process.id);
log::info!("Finded Process Value: {:?}", process.id);

// sort process parameter by sequence
if let Some(ref mut parameters) = process.parameters {
Expand All @@ -303,7 +310,7 @@ pub async fn processes(_language: Option<&String>, _search_value: Option<&String
};

// Find index
let _index_name = match get_index_name("process".to_string(), _language, _dictionary_code).await {
let _index_name: String = match get_index_name("process".to_string(), _language, _dictionary_code).await {
Ok(index_name) => index_name,
Err(error) => {
log::error!("Index name error: {:?}", error.to_string());
Expand All @@ -312,7 +319,7 @@ pub async fn processes(_language: Option<&String>, _search_value: Option<&String
};
log::info!("Index to search {:}", _index_name);

let mut _document = Process::default();
let mut _document: Process = Process::default();
_document.index_value = Some(_index_name);
let _process_document: &dyn IndexDocument = &_document;
match find(_process_document, _search_value, 0, 10).await {
Expand Down
28 changes: 21 additions & 7 deletions src/models/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ impl Role {
menu.uuid = _id.cloned();
menu
}

pub fn to_string(&self) -> String {
format!("Form: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value)
}
}

impl IndexDocument for Role {
Expand All @@ -110,9 +114,12 @@ impl IndexDocument for Role {
json!(self)
}

fn id(self: &Self) -> String {
self.uuid.to_owned().unwrap()
}
fn id(self: &Self) -> String {
self.id.to_owned().unwrap_or_else(|| {
log::error!("{}", self.to_string());
"".to_string()
})
}

fn index_name(self: &Self) -> String {
match &self.index_value {
Expand Down Expand Up @@ -157,10 +164,17 @@ pub async fn role_from_id(_uuid: Option<&String>, _client_uuid: Option<&String>,
let _role_document: &dyn IndexDocument = &_document;
match get_by_id(_role_document).await {
Ok(value) => {
let role: Role = serde_json::from_value(value).unwrap();
log::info!("Finded Value: {:?}", role.id);
Ok(role)
},
match serde_json::from_value::<Role>(value) {
Ok(role) => {
log::info!("Finded Role Value: {:?}", role.id);
Ok(role)
},
Err(error) => {
log::error!("{}", error);
Err(error.to_string())
},
}
},
Err(error) => {
log::error!("{}", error);
Err(error)
Expand Down
23 changes: 15 additions & 8 deletions src/models/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ impl Window {
window.id = _id;
window
}

pub fn to_string(&self) -> String {
format!("Window: UUID {:?}, ID {:?}, Name {:?}, Index: {:?}", self.uuid, self.internal_id, self.name, self.index_value)
}
}

impl IndexDocument for Window {
Expand All @@ -218,9 +222,12 @@ impl IndexDocument for Window {
json!(self)
}

fn id(self: &Self) -> String {
self.id.to_owned().unwrap()
}
fn id(self: &Self) -> String {
self.id.to_owned().unwrap_or_else(|| {
log::error!("{}", self.to_string());
"".to_string()
})
}

fn index_name(self: &Self) -> String {
match &self.index_value {
Expand Down Expand Up @@ -291,9 +298,9 @@ pub async fn window_from_id(_id: Option<String>, _language: Option<&String>, _di
Error::new(ErrorKind::InvalidData.into(), "Window Identifier is Mandatory").to_string()
);
}
let mut _document = Window::from_id(_id.to_owned());
let mut _document: Window = Window::from_id(_id.to_owned());

let _index_name = match get_index_name("window".to_string(), _language,_dictionary_code).await {
let _index_name: String = match get_index_name("window".to_string(), _language,_dictionary_code).await {
Ok(index_name) => index_name,
Err(error) => {
log::error!("Index name error to {:?}: {:?}", _id.to_owned(), error.to_string());
Expand All @@ -307,7 +314,7 @@ pub async fn window_from_id(_id: Option<String>, _language: Option<&String>, _di
match get_by_id(_window_document).await {
Ok(value) => {
let mut window: Window = serde_json::from_value(value).unwrap();
log::info!("Finded Value: {:?}", window.id);
log::info!("Finded Window Value: {:?}", window.id);

// sort tabs by sequence
if let Some(ref mut tabs) = window.tabs {
Expand Down Expand Up @@ -336,7 +343,7 @@ pub async fn windows(_language: Option<&String>, _search_value: Option<&String>,
};

// Find index
let _index_name = match get_index_name("window".to_string(), _language, _dictionary_code).await {
let _index_name: String = match get_index_name("window".to_string(), _language, _dictionary_code).await {
Ok(index_name) => index_name,
Err(error) => {
log::error!("Index name error: {:?}", error.to_string());
Expand All @@ -345,7 +352,7 @@ pub async fn windows(_language: Option<&String>, _search_value: Option<&String>,
};
log::info!("Index to search {:}", _index_name);

let mut _document = Window::default();
let mut _document: Window = Window::default();
_document.index_value = Some(_index_name);
let _window_document: &dyn IndexDocument = &_document;
match find(_window_document, _search_value, 0, 10).await {
Expand Down

0 comments on commit 9a15583

Please sign in to comment.