update magic draw parser to handle more edge cases
This commit is contained in:
parent
70408b0602
commit
bf92f783e4
@ -61,7 +61,7 @@ fn parse_class<R: Read>(
|
||||
})?;
|
||||
|
||||
Ok(DDLClass {
|
||||
class_id: class_id.context("Missing class id")?,
|
||||
class_id: class_id.context("Missing dll class id")?,
|
||||
property_ids,
|
||||
})
|
||||
}
|
||||
|
@ -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<R: Read + Seek>(project_file: R) -> Result<Vec<SQLTableColl
|
||||
for ddl_script in ddl_project.scripts {
|
||||
let mut tables = vec![];
|
||||
|
||||
let model_properties = ddl_script
|
||||
.classess
|
||||
.iter()
|
||||
.flat_map(|class| {
|
||||
class
|
||||
.property_ids
|
||||
.iter()
|
||||
.map(|prop| (&class.class_id, prop))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
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<R: Read + Seek>(project_file: R) -> Result<Vec<SQLTableColl
|
||||
let type_href = unwrap_opt_continue!(&property.type_href);
|
||||
let type_name = sql_type_names
|
||||
.get(type_href)
|
||||
.context("Proerty type name conversion not found")?;
|
||||
.context("Property type name conversion not found")?;
|
||||
|
||||
let check_constraint = get_sql_check_constraint(&models, &prop_name);
|
||||
let foreign_key = get_foreign_key(&modifiers, &model_classess, property_id)?;
|
||||
|
@ -13,7 +13,7 @@ use super::utils::{check_attribute, check_name, get_attribute, parse_element, My
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UsedPackage {
|
||||
share_point_id: String,
|
||||
share_point_ids: Vec<String>,
|
||||
name: String,
|
||||
needed_types: Vec<String>,
|
||||
}
|
||||
@ -23,6 +23,8 @@ pub enum SQLTypeName {
|
||||
Int,
|
||||
Decimal,
|
||||
Date,
|
||||
Datetime,
|
||||
Time,
|
||||
Float,
|
||||
Bool,
|
||||
Char,
|
||||
@ -39,22 +41,26 @@ fn parse_used_package<R: Read>(
|
||||
attrs: &[OwnedAttribute],
|
||||
needed_types: &[&str],
|
||||
) -> Result<UsedPackage> {
|
||||
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<SQLTypeName> {
|
||||
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<R: Read>(
|
||||
} => {
|
||||
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()
|
||||
|
@ -147,7 +147,7 @@ fn parse_constraint<R: Read>(
|
||||
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<R: Read>(
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user