cimstructs/
IdentifiedObject.rs1#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct IdentifiedObject {
4 pub id: String,
5 pub description: String,
7 pub energy_ident_code_eic: String,
9 pub m_rid: String,
11 pub name: String,
13 pub short_name: String,
15}
16impl crate::base::CimElement for IdentifiedObject {
17 fn mrid(&self) -> &str { &self.id }
18 fn type_name(&self) -> &'static str { "IdentifiedObject" }
19 fn as_any(&self) -> &dyn std::any::Any { self }
20 fn to_json_value(&self) -> serde_json::Value {
21 serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
22 }
23 fn to_block(&self) -> crate::base::RdfBlock {
24 let mut block = crate::base::RdfBlock {
25 type_name: "IdentifiedObject".to_string(),
26 mrid: self.id.clone(),
27 fields: std::collections::HashMap::new(),
28 duplicate_fields: std::collections::HashSet::new(),
29 };
30 if !self.description.is_empty() {
31 block.fields.insert("IdentifiedObject.description".into(), crate::base::FieldValue::Text(self.description.clone()));
32 }
33 if !self.energy_ident_code_eic.is_empty() {
34 block.fields.insert("IdentifiedObject.energyIdentCodeEic".into(), crate::base::FieldValue::Text(self.energy_ident_code_eic.clone()));
35 }
36 if !self.m_rid.is_empty() {
37 block.fields.insert("IdentifiedObject.mRID".into(), crate::base::FieldValue::Text(self.m_rid.clone()));
38 }
39 if !self.name.is_empty() {
40 block.fields.insert("IdentifiedObject.name".into(), crate::base::FieldValue::Text(self.name.clone()));
41 }
42 if !self.short_name.is_empty() {
43 block.fields.insert("IdentifiedObject.shortName".into(), crate::base::FieldValue::Text(self.short_name.clone()));
44 }
45 block
46 }
47}
48
49impl IdentifiedObject {
50 pub fn from_block(b: &crate::base::RdfBlock) -> Self {
51 let mut obj = Self::default();
52 obj.id.clone_from(&b.mrid);
53 for (key, val) in &b.fields {
54 match key.as_str() {
55 "IdentifiedObject.description" => {
56 match val {
57 crate::base::FieldValue::Text(sv) => { obj.description = sv.clone(); }
58 crate::base::FieldValue::TextList(svs) => {
59 if let Some(sv) = svs.last() { obj.description = sv.clone(); }
60 }
61 _ => {}
62 }
63 }
64 "IdentifiedObject.energyIdentCodeEic" => {
65 match val {
66 crate::base::FieldValue::Text(sv) => { obj.energy_ident_code_eic = sv.clone(); }
67 crate::base::FieldValue::TextList(svs) => {
68 if let Some(sv) = svs.last() { obj.energy_ident_code_eic = sv.clone(); }
69 }
70 _ => {}
71 }
72 }
73 "IdentifiedObject.mRID" => {
74 match val {
75 crate::base::FieldValue::Text(sv) => { obj.m_rid = sv.clone(); }
76 crate::base::FieldValue::TextList(svs) => {
77 if let Some(sv) = svs.last() { obj.m_rid = sv.clone(); }
78 }
79 _ => {}
80 }
81 }
82 "IdentifiedObject.name" => {
83 match val {
84 crate::base::FieldValue::Text(sv) => { obj.name = sv.clone(); }
85 crate::base::FieldValue::TextList(svs) => {
86 if let Some(sv) = svs.last() { obj.name = sv.clone(); }
87 }
88 _ => {}
89 }
90 }
91 "IdentifiedObject.shortName" => {
92 match val {
93 crate::base::FieldValue::Text(sv) => { obj.short_name = sv.clone(); }
94 crate::base::FieldValue::TextList(svs) => {
95 if let Some(sv) = svs.last() { obj.short_name = sv.clone(); }
96 }
97 _ => {}
98 }
99 }
100 _ => {}
101 }
102 }
103 obj
104 }
105}