oca_bundle/state/oca/overlay/
entry_code_mapping.rs1use crate::state::{attribute::Attribute, oca::Overlay};
2use oca_ast::ast::OverlayType;
3use said::{sad::SerializationFormats, sad::SAD};
4use serde::{Deserialize, Serialize};
5use std::any::Any;
6use std::collections::BTreeMap;
7
8#[derive(SAD, Serialize, Deserialize, Debug, Clone)]
9pub struct EntryCodeMappingOverlay {
10 capture_base: Option<said::SelfAddressingIdentifier>,
11 #[said]
12 #[serde(rename = "d")]
13 said: Option<said::SelfAddressingIdentifier>,
14 #[serde(rename = "type")]
15 overlay_type: OverlayType,
16 pub attribute_entry_codes_mapping: BTreeMap<String, Vec<String>>,
17}
18
19impl Overlay for EntryCodeMappingOverlay {
20 fn as_any(&self) -> &dyn Any {
21 self
22 }
23 fn capture_base(&self) -> &Option<said::SelfAddressingIdentifier> {
24 &self.capture_base
25 }
26 fn set_capture_base(&mut self, said: &said::SelfAddressingIdentifier) {
27 self.capture_base = Some(said.clone());
28 }
29 fn said(&self) -> &Option<said::SelfAddressingIdentifier> {
30 &self.said
31 }
32 fn overlay_type(&self) -> &OverlayType {
33 &self.overlay_type
34 }
35 fn attributes(&self) -> Vec<&String> {
36 self.attribute_entry_codes_mapping
37 .keys()
38 .collect::<Vec<&String>>()
39 }
40
41 fn add(&mut self, attribute: &Attribute) {
42 if attribute.entry_codes_mapping.is_some() {
43 self.attribute_entry_codes_mapping.insert(
44 attribute.name.clone(),
45 attribute.entry_codes_mapping.as_ref().unwrap().clone(),
46 );
47 }
48 }
49}
50impl EntryCodeMappingOverlay {
51 pub fn new() -> Box<EntryCodeMappingOverlay> {
52 Box::new(EntryCodeMappingOverlay {
53 capture_base: None,
54 said: None,
55 overlay_type: OverlayType::EntryCodeMapping,
56 attribute_entry_codes_mapping: BTreeMap::new(),
57 })
58 }
59}