use crate::model::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Kind {
Literal,
Association,
Enum,
}
pub fn attr_kind(a: &CimAttribute) -> Kind {
if a.is_enum_value {
Kind::Enum
} else if a.is_primitive || a.is_cim_datatype {
Kind::Literal
} else {
Kind::Association
}
}
pub fn attr_range(a: &CimAttribute) -> &str {
if a.rdf_range.is_empty() {
&a.cim_data_type
} else {
&a.rdf_range
}
}
pub fn xsd_type(a: &CimAttribute) -> &'static str {
if attr_kind(a) != Kind::Literal {
return "";
}
match a.data_type.as_str() {
DATA_TYPE_STRING => "string",
DATA_TYPE_INTEGER => "integer",
DATA_TYPE_BOOLEAN => "boolean",
DATA_TYPE_FLOAT => "double",
DATA_TYPE_DECIMAL => "decimal",
DATA_TYPE_DATE => "date",
DATA_TYPE_DATE_TIME => "dateTime",
DATA_TYPE_MONTH_DAY => "gMonthDay",
"URI" => "anyURI",
_ => "string",
}
}
pub fn value_namespace<'a>(spec: &'a CimSpecification, a: &CimAttribute) -> &'a str {
if attr_kind(a) != Kind::Enum {
return "";
}
spec.enums.get(&a.rdf_range).map_or("", |e| e.namespace.as_str())
}
pub fn profile_uris(spec: &CimSpecification) -> Vec<(&str, &str)> {
let mut v: Vec<(&str, &str)> = spec
.ontologies
.iter()
.filter(|(_, o)| !o.owl_version_iri.is_empty())
.map(|(k, o)| (k.as_str(), o.owl_version_iri.as_str()))
.collect();
v.sort_unstable();
v
}
pub fn namespaces(spec: &CimSpecification) -> Vec<(&str, &str)> {
let mut v: Vec<(&str, &str)> =
spec.profile_namespaces.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect();
v.sort_unstable();
v
}