diff --git a/src/magicdraw_parser/ddl_parser.rs b/src/magicdraw_parser/ddl_parser.rs index d4e6cd4..b7e9a6e 100644 --- a/src/magicdraw_parser/ddl_parser.rs +++ b/src/magicdraw_parser/ddl_parser.rs @@ -61,7 +61,7 @@ fn parse_class( })?; Ok(DDLClass { - class_id: class_id.context("Missing class id")?, + class_id: class_id.context("Missing dll class id")?, property_ids, }) } diff --git a/src/magicdraw_parser/mod.rs b/src/magicdraw_parser/mod.rs index cae4c5c..6763f07 100644 --- a/src/magicdraw_parser/mod.rs +++ b/src/magicdraw_parser/mod.rs @@ -216,6 +216,8 @@ fn get_sql_type( Ok(match type_name { SQLTypeName::Int => SQLType::Int, SQLTypeName::Date => SQLType::Date, + SQLTypeName::Datetime => SQLType::Datetime, + SQLTypeName::Time => SQLType::Time, SQLTypeName::Float => SQLType::Float, SQLTypeName::Bool => SQLType::Bool, SQLTypeName::Decimal => SQLType::Decimal, @@ -266,17 +268,6 @@ pub fn parse_project(project_file: R) -> Result>(); - let mut model_classess = vec![]; for ddl_class in &ddl_script.classess { let model_class = find_class_by_id(&models, &ddl_class.class_id) @@ -302,7 +293,7 @@ pub fn parse_project(project_file: R) -> Result, name: String, needed_types: Vec, } @@ -23,6 +23,8 @@ pub enum SQLTypeName { Int, Decimal, Date, + Datetime, + Time, Float, Bool, Char, @@ -39,22 +41,26 @@ fn parse_used_package( attrs: &[OwnedAttribute], needed_types: &[&str], ) -> Result { - let mut share_point_id = None; + let mut share_point_ids = vec![]; let project_uri = get_attribute(&attrs, None, "usedProjectURI")?; let name = project_uri.split("/").last().unwrap(); parse_element(parser, &mut |p, name, attrs| { - if share_point_id.is_none() && check_name(&name, None, "mountPoints") { - share_point_id = get_attribute(&attrs, None, "sharePointID") - .ok() - .map(str::to_string); + if check_name(&name, None, "mountPoints") { + if let Ok(mount_id) = get_attribute(&attrs, None, "sharePointID").map(str::to_string) { + share_point_ids.push(mount_id); + } } Ok(()) })?; + if share_point_ids.is_empty() { + bail!("Share point mount ids not found") + } + Ok(UsedPackage { name: name.to_string(), - share_point_id: share_point_id.context("Share point id not found")?, + share_point_ids, needed_types: needed_types.iter().map(|s| s.to_string()).collect(), }) } @@ -109,14 +115,16 @@ fn is_umodel_snapshot_file(filename: &str) -> bool { fn parse_type_name(str: &str) -> Result { use SQLTypeName::*; - Ok(match str { + Ok(match &str.to_lowercase()[..] { "decimal" | "dec" => Decimal, "char" => Char, - "varchar" => Varchar, - "float" => Float, - "Integer" | "integer" | "int" => Int, + "varchar" | "string" => Varchar, + "float" | "double precision" => Float, // TODO: Cheecky double precision -> float + "integer" | "int" => Int, "date" => Date, - "Boolean" => Bool, + "datetime" => Datetime, + "time" => Time, + "boolean" => Bool, _ => bail!("Unknown SQL type: '{}'", str), }) } @@ -161,8 +169,9 @@ fn parse_primitive_types( } => { if check_name(&name, Some("uml"), "Package") { if let Some(id) = get_attribute(&attributes, None, "ID").ok() { + let id = id.to_string(); if let Some(package) = - used_packages.iter().find(|p| p.share_point_id.eq(id)) + used_packages.iter().find(|p| p.share_point_ids.contains(&id)) { let package_types = parse_types_package(&mut parser)? .into_iter() diff --git a/src/magicdraw_parser/uml_model_parser.rs b/src/magicdraw_parser/uml_model_parser.rs index c559467..58695a1 100644 --- a/src/magicdraw_parser/uml_model_parser.rs +++ b/src/magicdraw_parser/uml_model_parser.rs @@ -147,7 +147,7 @@ fn parse_constraint( if let Some((prop_name, check_body)) = body.unwrap().split_once(" in ") { return Ok(Some(UMLConstraint { id, - class_id: Some(constrainted_element_id.context("Missing class id")?), + class_id: Some(constrainted_element_id.context("Missing constraint class id")?), body: Some(format!("in {}", check_body)), property_id: None, property_name: Some(prop_name.into()), @@ -155,9 +155,13 @@ fn parse_constraint( } } + if constrainted_element_id.is_none() { + return Ok(None); + } + return Ok(Some(UMLConstraint { id, - property_id: Some(constrainted_element_id.context("Missing property id")?), + property_id: Some(constrainted_element_id.unwrap()), body: None, class_id: None, property_name: None,