data_modelling_sdk/models/
workspace.rs

1//! Workspace model
2//!
3//! Defines the Workspace entity for the data modelling application.
4//! Workspaces are top-level containers that organize domains and their associated assets.
5//!
6//! ## File Naming Convention
7//!
8//! All files use a flat naming pattern:
9//! - `workspace.yaml` - workspace metadata with references to all assets and relationships
10//! - `{workspace}_{domain}_{system}_{resource}.odcs.yaml` - ODCS table files
11//! - `{workspace}_{domain}_{system}_{resource}.odps.yaml` - ODPS product files
12//! - `{workspace}_{domain}_{system}_{resource}.cads.yaml` - CADS asset files
13//!
14//! Where `{system}` is optional if the resource is at the domain level.
15
16use chrono::{DateTime, Utc};
17use serde::{Deserialize, Serialize};
18use uuid::Uuid;
19
20use super::Relationship;
21
22/// Asset reference within a workspace
23///
24/// Contains information about an asset file and its location in the domain/system hierarchy.
25#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
26pub struct AssetReference {
27    /// Asset identifier (UUID)
28    pub id: Uuid,
29    /// Asset name
30    pub name: String,
31    /// Domain name this asset belongs to
32    pub domain: String,
33    /// Optional system name (if asset is within a system)
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub system: Option<String>,
36    /// Asset type (odcs, odps, cads)
37    pub asset_type: AssetType,
38    /// File path relative to workspace (generated from naming convention)
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub file_path: Option<String>,
41}
42
43/// Type of asset or file in the workspace
44#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
45#[serde(rename_all = "lowercase")]
46pub enum AssetType {
47    /// Workspace configuration file
48    Workspace,
49    /// Relationships file
50    Relationships,
51    /// ODCS table definition
52    Odcs,
53    /// ODPS data product
54    Odps,
55    /// CADS compute asset
56    Cads,
57    /// BPMN process model
58    Bpmn,
59    /// DMN decision model
60    Dmn,
61    /// OpenAPI specification
62    Openapi,
63    /// MADR decision record
64    Decision,
65    /// Knowledge base article
66    Knowledge,
67    /// Decision log index file
68    DecisionIndex,
69    /// Knowledge base index file
70    KnowledgeIndex,
71}
72
73impl AssetType {
74    /// Get file extension for this asset type
75    pub fn extension(&self) -> &'static str {
76        match self {
77            AssetType::Workspace => "yaml",
78            AssetType::Relationships => "yaml",
79            AssetType::Odcs => "odcs.yaml",
80            AssetType::Odps => "odps.yaml",
81            AssetType::Cads => "cads.yaml",
82            AssetType::Bpmn => "bpmn.xml",
83            AssetType::Dmn => "dmn.xml",
84            AssetType::Openapi => "openapi.yaml",
85            AssetType::Decision => "madr.yaml",
86            AssetType::Knowledge => "kb.yaml",
87            AssetType::DecisionIndex => "yaml",
88            AssetType::KnowledgeIndex => "yaml",
89        }
90    }
91
92    /// Get the full filename for workspace-level files
93    pub fn filename(&self) -> Option<&'static str> {
94        match self {
95            AssetType::Workspace => Some("workspace.yaml"),
96            AssetType::Relationships => Some("relationships.yaml"),
97            AssetType::DecisionIndex => Some("decisions.yaml"),
98            AssetType::KnowledgeIndex => Some("knowledge.yaml"),
99            _ => None,
100        }
101    }
102
103    /// Check if this is a workspace-level file (not a domain/system asset)
104    pub fn is_workspace_level(&self) -> bool {
105        matches!(
106            self,
107            AssetType::Workspace
108                | AssetType::Relationships
109                | AssetType::DecisionIndex
110                | AssetType::KnowledgeIndex
111        )
112    }
113
114    /// Detect asset type from filename
115    pub fn from_filename(filename: &str) -> Option<Self> {
116        if filename == "workspace.yaml" {
117            Some(AssetType::Workspace)
118        } else if filename == "relationships.yaml" {
119            Some(AssetType::Relationships)
120        } else if filename == "decisions.yaml" {
121            Some(AssetType::DecisionIndex)
122        } else if filename == "knowledge.yaml" {
123            Some(AssetType::KnowledgeIndex)
124        } else if filename.ends_with(".odcs.yaml") {
125            Some(AssetType::Odcs)
126        } else if filename.ends_with(".odps.yaml") {
127            Some(AssetType::Odps)
128        } else if filename.ends_with(".cads.yaml") {
129            Some(AssetType::Cads)
130        } else if filename.ends_with(".madr.yaml") {
131            Some(AssetType::Decision)
132        } else if filename.ends_with(".kb.yaml") {
133            Some(AssetType::Knowledge)
134        } else if filename.ends_with(".bpmn.xml") {
135            Some(AssetType::Bpmn)
136        } else if filename.ends_with(".dmn.xml") {
137            Some(AssetType::Dmn)
138        } else if filename.ends_with(".openapi.yaml") || filename.ends_with(".openapi.json") {
139            Some(AssetType::Openapi)
140        } else {
141            None
142        }
143    }
144
145    /// Get all supported file extensions
146    pub fn supported_extensions() -> &'static [&'static str] {
147        &[
148            "workspace.yaml",
149            "relationships.yaml",
150            "decisions.yaml",
151            "knowledge.yaml",
152            ".odcs.yaml",
153            ".odps.yaml",
154            ".cads.yaml",
155            ".madr.yaml",
156            ".kb.yaml",
157            ".bpmn.xml",
158            ".dmn.xml",
159            ".openapi.yaml",
160            ".openapi.json",
161        ]
162    }
163
164    /// Check if a filename is a supported asset type
165    pub fn is_supported_file(filename: &str) -> bool {
166        Self::from_filename(filename).is_some()
167    }
168}
169
170/// Domain reference within a workspace
171///
172/// Contains information about a domain and its systems.
173#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
174pub struct DomainReference {
175    /// Domain identifier
176    pub id: Uuid,
177    /// Domain name
178    pub name: String,
179    /// Optional description
180    #[serde(skip_serializing_if = "Option::is_none")]
181    pub description: Option<String>,
182    /// Systems within this domain
183    #[serde(default, skip_serializing_if = "Vec::is_empty")]
184    pub systems: Vec<SystemReference>,
185}
186
187/// System reference within a domain
188#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
189pub struct SystemReference {
190    /// System identifier
191    pub id: Uuid,
192    /// System name
193    pub name: String,
194    /// Optional description
195    #[serde(skip_serializing_if = "Option::is_none")]
196    pub description: Option<String>,
197}
198
199/// Workspace - Top-level container for domains, assets, and relationships
200///
201/// Workspaces organize domains, systems, and their associated assets.
202/// All files use a flat naming convention: `{workspace}_{domain}_{system}_{resource}.xxx.yaml`
203#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
204pub struct Workspace {
205    /// Unique identifier for the workspace
206    pub id: Uuid,
207    /// Workspace name (used in file naming)
208    pub name: String,
209    /// Owner/creator user identifier
210    pub owner_id: Uuid,
211    /// Creation timestamp
212    pub created_at: DateTime<Utc>,
213    /// Last modification timestamp
214    pub last_modified_at: DateTime<Utc>,
215    /// Domain references with their systems
216    #[serde(default)]
217    pub domains: Vec<DomainReference>,
218    /// All asset references in this workspace
219    #[serde(default)]
220    pub assets: Vec<AssetReference>,
221    /// Relationships between assets in this workspace
222    #[serde(default, skip_serializing_if = "Vec::is_empty")]
223    pub relationships: Vec<Relationship>,
224}
225
226impl Workspace {
227    /// Create a new Workspace
228    pub fn new(name: String, owner_id: Uuid) -> Self {
229        let now = Utc::now();
230        Self {
231            id: Uuid::new_v4(),
232            name,
233            owner_id,
234            created_at: now,
235            last_modified_at: now,
236            domains: Vec::new(),
237            assets: Vec::new(),
238            relationships: Vec::new(),
239        }
240    }
241
242    /// Create a workspace with a specific ID
243    pub fn with_id(id: Uuid, name: String, owner_id: Uuid) -> Self {
244        let now = Utc::now();
245        Self {
246            id,
247            name,
248            owner_id,
249            created_at: now,
250            last_modified_at: now,
251            domains: Vec::new(),
252            assets: Vec::new(),
253            relationships: Vec::new(),
254        }
255    }
256
257    /// Add a relationship to the workspace
258    pub fn add_relationship(&mut self, relationship: Relationship) {
259        // Check if relationship already exists
260        if self.relationships.iter().any(|r| r.id == relationship.id) {
261            return;
262        }
263        self.relationships.push(relationship);
264        self.last_modified_at = Utc::now();
265    }
266
267    /// Remove a relationship by ID
268    pub fn remove_relationship(&mut self, relationship_id: Uuid) -> bool {
269        let initial_len = self.relationships.len();
270        self.relationships.retain(|r| r.id != relationship_id);
271        let removed = self.relationships.len() < initial_len;
272        if removed {
273            self.last_modified_at = Utc::now();
274        }
275        removed
276    }
277
278    /// Get relationships by source table ID
279    pub fn get_relationships_for_source(&self, source_table_id: Uuid) -> Vec<&Relationship> {
280        self.relationships
281            .iter()
282            .filter(|r| r.source_table_id == source_table_id)
283            .collect()
284    }
285
286    /// Get relationships by target table ID
287    pub fn get_relationships_for_target(&self, target_table_id: Uuid) -> Vec<&Relationship> {
288        self.relationships
289            .iter()
290            .filter(|r| r.target_table_id == target_table_id)
291            .collect()
292    }
293
294    /// Add a domain reference to the workspace
295    pub fn add_domain(&mut self, domain_id: Uuid, domain_name: String) {
296        // Check if domain already exists
297        if self.domains.iter().any(|d| d.id == domain_id) {
298            return;
299        }
300        self.domains.push(DomainReference {
301            id: domain_id,
302            name: domain_name,
303            description: None,
304            systems: Vec::new(),
305        });
306        self.last_modified_at = Utc::now();
307    }
308
309    /// Add a domain with description
310    pub fn add_domain_with_description(
311        &mut self,
312        domain_id: Uuid,
313        domain_name: String,
314        description: Option<String>,
315    ) {
316        if self.domains.iter().any(|d| d.id == domain_id) {
317            return;
318        }
319        self.domains.push(DomainReference {
320            id: domain_id,
321            name: domain_name,
322            description,
323            systems: Vec::new(),
324        });
325        self.last_modified_at = Utc::now();
326    }
327
328    /// Add a system to a domain
329    pub fn add_system_to_domain(
330        &mut self,
331        domain_name: &str,
332        system_id: Uuid,
333        system_name: String,
334        description: Option<String>,
335    ) -> bool {
336        if let Some(domain) = self.domains.iter_mut().find(|d| d.name == domain_name)
337            && !domain.systems.iter().any(|s| s.id == system_id)
338        {
339            domain.systems.push(SystemReference {
340                id: system_id,
341                name: system_name,
342                description,
343            });
344            self.last_modified_at = Utc::now();
345            return true;
346        }
347        false
348    }
349
350    /// Remove a domain reference by ID
351    pub fn remove_domain(&mut self, domain_id: Uuid) -> bool {
352        let initial_len = self.domains.len();
353        self.domains.retain(|d| d.id != domain_id);
354        // Also remove assets belonging to this domain
355        if let Some(domain) = self.domains.iter().find(|d| d.id == domain_id) {
356            let domain_name = domain.name.clone();
357            self.assets.retain(|a| a.domain != domain_name);
358        }
359        if self.domains.len() != initial_len {
360            self.last_modified_at = Utc::now();
361            true
362        } else {
363            false
364        }
365    }
366
367    /// Get a domain reference by ID
368    pub fn get_domain(&self, domain_id: Uuid) -> Option<&DomainReference> {
369        self.domains.iter().find(|d| d.id == domain_id)
370    }
371
372    /// Get a domain reference by name
373    pub fn get_domain_by_name(&self, name: &str) -> Option<&DomainReference> {
374        self.domains.iter().find(|d| d.name == name)
375    }
376
377    /// Add an asset reference
378    pub fn add_asset(&mut self, asset: AssetReference) {
379        // Check if asset already exists
380        if self.assets.iter().any(|a| a.id == asset.id) {
381            return;
382        }
383        self.assets.push(asset);
384        self.last_modified_at = Utc::now();
385    }
386
387    /// Remove an asset by ID
388    pub fn remove_asset(&mut self, asset_id: Uuid) -> bool {
389        let initial_len = self.assets.len();
390        self.assets.retain(|a| a.id != asset_id);
391        if self.assets.len() != initial_len {
392            self.last_modified_at = Utc::now();
393            true
394        } else {
395            false
396        }
397    }
398
399    /// Get an asset by ID
400    pub fn get_asset(&self, asset_id: Uuid) -> Option<&AssetReference> {
401        self.assets.iter().find(|a| a.id == asset_id)
402    }
403
404    /// Get assets by domain
405    pub fn get_assets_by_domain(&self, domain_name: &str) -> Vec<&AssetReference> {
406        self.assets
407            .iter()
408            .filter(|a| a.domain == domain_name)
409            .collect()
410    }
411
412    /// Get assets by type
413    pub fn get_assets_by_type(&self, asset_type: &AssetType) -> Vec<&AssetReference> {
414        self.assets
415            .iter()
416            .filter(|a| &a.asset_type == asset_type)
417            .collect()
418    }
419
420    /// Generate filename for an asset using the naming convention
421    /// Format: {workspace}_{domain}_{system}_{resource}.{extension}
422    pub fn generate_asset_filename(&self, asset: &AssetReference) -> String {
423        let mut parts = vec![sanitize_name(&self.name), sanitize_name(&asset.domain)];
424
425        if let Some(ref system) = asset.system {
426            parts.push(sanitize_name(system));
427        }
428
429        parts.push(sanitize_name(&asset.name));
430
431        format!("{}.{}", parts.join("_"), asset.asset_type.extension())
432    }
433
434    /// Parse a filename to extract workspace, domain, system, and resource names
435    /// Returns (domain, system, resource_name) or None if parsing fails
436    pub fn parse_asset_filename(
437        filename: &str,
438    ) -> Option<(String, Option<String>, String, AssetType)> {
439        // Determine asset type from extension
440        let (base, asset_type) = if filename.ends_with(".odcs.yaml") {
441            (filename.strip_suffix(".odcs.yaml")?, AssetType::Odcs)
442        } else if filename.ends_with(".odps.yaml") {
443            (filename.strip_suffix(".odps.yaml")?, AssetType::Odps)
444        } else if filename.ends_with(".cads.yaml") {
445            (filename.strip_suffix(".cads.yaml")?, AssetType::Cads)
446        } else if filename.ends_with(".bpmn.xml") {
447            (filename.strip_suffix(".bpmn.xml")?, AssetType::Bpmn)
448        } else if filename.ends_with(".dmn.xml") {
449            (filename.strip_suffix(".dmn.xml")?, AssetType::Dmn)
450        } else if filename.ends_with(".openapi.yaml") {
451            (filename.strip_suffix(".openapi.yaml")?, AssetType::Openapi)
452        } else {
453            return None;
454        };
455
456        let parts: Vec<&str> = base.split('_').collect();
457
458        match parts.len() {
459            // workspace_domain_resource (no system)
460            3 => Some((parts[1].to_string(), None, parts[2].to_string(), asset_type)),
461            // workspace_domain_system_resource
462            4 => Some((
463                parts[1].to_string(),
464                Some(parts[2].to_string()),
465                parts[3].to_string(),
466                asset_type,
467            )),
468            // More than 4 parts - treat remaining as resource name with underscores
469            n if n > 4 => Some((
470                parts[1].to_string(),
471                Some(parts[2].to_string()),
472                parts[3..].join("_"),
473                asset_type,
474            )),
475            _ => None,
476        }
477    }
478
479    /// Import workspace from YAML
480    pub fn from_yaml(yaml_content: &str) -> Result<Self, serde_yaml::Error> {
481        serde_yaml::from_str(yaml_content)
482    }
483
484    /// Export workspace to YAML
485    pub fn to_yaml(&self) -> Result<String, serde_yaml::Error> {
486        serde_yaml::to_string(self)
487    }
488
489    /// Import workspace from JSON
490    pub fn from_json(json_content: &str) -> Result<Self, serde_json::Error> {
491        serde_json::from_str(json_content)
492    }
493
494    /// Export workspace to JSON
495    pub fn to_json(&self) -> Result<String, serde_json::Error> {
496        serde_json::to_string(self)
497    }
498
499    /// Export workspace to pretty JSON
500    pub fn to_json_pretty(&self) -> Result<String, serde_json::Error> {
501        serde_json::to_string_pretty(self)
502    }
503}
504
505/// Sanitize a name for use in filenames (replace spaces/special chars with hyphens)
506fn sanitize_name(name: &str) -> String {
507    name.chars()
508        .map(|c| match c {
509            ' ' | '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|' => '-',
510            _ => c,
511        })
512        .collect::<String>()
513        .to_lowercase()
514}
515
516impl Default for Workspace {
517    fn default() -> Self {
518        Self::new("Default Workspace".to_string(), Uuid::new_v4())
519    }
520}
521
522#[cfg(test)]
523mod tests {
524    use super::*;
525
526    #[test]
527    fn test_workspace_new() {
528        let owner_id = Uuid::new_v4();
529        let workspace = Workspace::new("Test Workspace".to_string(), owner_id);
530
531        assert_eq!(workspace.name, "Test Workspace");
532        assert_eq!(workspace.owner_id, owner_id);
533        assert!(workspace.domains.is_empty());
534        assert!(workspace.assets.is_empty());
535    }
536
537    #[test]
538    fn test_workspace_add_domain() {
539        let mut workspace = Workspace::new("Test".to_string(), Uuid::new_v4());
540        let domain_id = Uuid::new_v4();
541
542        workspace.add_domain(domain_id, "customer-management".to_string());
543
544        assert_eq!(workspace.domains.len(), 1);
545        assert_eq!(workspace.domains[0].id, domain_id);
546        assert_eq!(workspace.domains[0].name, "customer-management");
547
548        // Adding same domain again should not duplicate
549        workspace.add_domain(domain_id, "customer-management".to_string());
550        assert_eq!(workspace.domains.len(), 1);
551    }
552
553    #[test]
554    fn test_workspace_add_system_to_domain() {
555        let mut workspace = Workspace::new("Test".to_string(), Uuid::new_v4());
556        let domain_id = Uuid::new_v4();
557        let system_id = Uuid::new_v4();
558
559        workspace.add_domain(domain_id, "sales".to_string());
560        let result = workspace.add_system_to_domain(
561            "sales",
562            system_id,
563            "kafka".to_string(),
564            Some("Kafka streaming".to_string()),
565        );
566
567        assert!(result);
568        assert_eq!(workspace.domains[0].systems.len(), 1);
569        assert_eq!(workspace.domains[0].systems[0].name, "kafka");
570    }
571
572    #[test]
573    fn test_workspace_remove_domain() {
574        let mut workspace = Workspace::new("Test".to_string(), Uuid::new_v4());
575        let domain_id = Uuid::new_v4();
576        workspace.add_domain(domain_id, "test-domain".to_string());
577
578        assert!(workspace.remove_domain(domain_id));
579        assert!(workspace.domains.is_empty());
580        assert!(!workspace.remove_domain(domain_id)); // Already removed
581    }
582
583    #[test]
584    fn test_workspace_add_asset() {
585        let mut workspace = Workspace::new("enterprise".to_string(), Uuid::new_v4());
586        let asset_id = Uuid::new_v4();
587
588        let asset = AssetReference {
589            id: asset_id,
590            name: "orders".to_string(),
591            domain: "sales".to_string(),
592            system: Some("kafka".to_string()),
593            asset_type: AssetType::Odcs,
594            file_path: None,
595        };
596
597        workspace.add_asset(asset);
598        assert_eq!(workspace.assets.len(), 1);
599        assert_eq!(workspace.assets[0].name, "orders");
600    }
601
602    #[test]
603    fn test_workspace_generate_asset_filename() {
604        let workspace = Workspace::new("enterprise".to_string(), Uuid::new_v4());
605
606        // With system
607        let asset_with_system = AssetReference {
608            id: Uuid::new_v4(),
609            name: "orders".to_string(),
610            domain: "sales".to_string(),
611            system: Some("kafka".to_string()),
612            asset_type: AssetType::Odcs,
613            file_path: None,
614        };
615        assert_eq!(
616            workspace.generate_asset_filename(&asset_with_system),
617            "enterprise_sales_kafka_orders.odcs.yaml"
618        );
619
620        // Without system
621        let asset_no_system = AssetReference {
622            id: Uuid::new_v4(),
623            name: "customers".to_string(),
624            domain: "crm".to_string(),
625            system: None,
626            asset_type: AssetType::Odcs,
627            file_path: None,
628        };
629        assert_eq!(
630            workspace.generate_asset_filename(&asset_no_system),
631            "enterprise_crm_customers.odcs.yaml"
632        );
633
634        // ODPS product
635        let odps_asset = AssetReference {
636            id: Uuid::new_v4(),
637            name: "analytics".to_string(),
638            domain: "finance".to_string(),
639            system: None,
640            asset_type: AssetType::Odps,
641            file_path: None,
642        };
643        assert_eq!(
644            workspace.generate_asset_filename(&odps_asset),
645            "enterprise_finance_analytics.odps.yaml"
646        );
647    }
648
649    #[test]
650    fn test_workspace_parse_asset_filename() {
651        // With system
652        let result = Workspace::parse_asset_filename("enterprise_sales_kafka_orders.odcs.yaml");
653        assert!(result.is_some());
654        let (domain, system, name, asset_type) = result.unwrap();
655        assert_eq!(domain, "sales");
656        assert_eq!(system, Some("kafka".to_string()));
657        assert_eq!(name, "orders");
658        assert_eq!(asset_type, AssetType::Odcs);
659
660        // Without system (3 parts)
661        let result = Workspace::parse_asset_filename("enterprise_crm_customers.odcs.yaml");
662        assert!(result.is_some());
663        let (domain, system, name, asset_type) = result.unwrap();
664        assert_eq!(domain, "crm");
665        assert_eq!(system, None);
666        assert_eq!(name, "customers");
667        assert_eq!(asset_type, AssetType::Odcs);
668
669        // ODPS type
670        let result = Workspace::parse_asset_filename("workspace_domain_product.odps.yaml");
671        assert!(result.is_some());
672        let (_, _, _, asset_type) = result.unwrap();
673        assert_eq!(asset_type, AssetType::Odps);
674    }
675
676    #[test]
677    fn test_workspace_yaml_roundtrip() {
678        let mut workspace = Workspace::new("Enterprise Models".to_string(), Uuid::new_v4());
679        workspace.add_domain(Uuid::new_v4(), "finance".to_string());
680        workspace.add_domain(Uuid::new_v4(), "risk".to_string());
681        workspace.add_asset(AssetReference {
682            id: Uuid::new_v4(),
683            name: "accounts".to_string(),
684            domain: "finance".to_string(),
685            system: None,
686            asset_type: AssetType::Odcs,
687            file_path: None,
688        });
689
690        let yaml = workspace.to_yaml().unwrap();
691        let parsed = Workspace::from_yaml(&yaml).unwrap();
692
693        assert_eq!(workspace.id, parsed.id);
694        assert_eq!(workspace.name, parsed.name);
695        assert_eq!(workspace.domains.len(), parsed.domains.len());
696        assert_eq!(workspace.assets.len(), parsed.assets.len());
697    }
698
699    #[test]
700    fn test_workspace_json_roundtrip() {
701        let workspace = Workspace::new("Test".to_string(), Uuid::new_v4());
702
703        let json = workspace.to_json().unwrap();
704        let parsed = Workspace::from_json(&json).unwrap();
705
706        assert_eq!(workspace.id, parsed.id);
707        assert_eq!(workspace.name, parsed.name);
708    }
709
710    #[test]
711    fn test_asset_type_extension() {
712        assert_eq!(AssetType::Workspace.extension(), "yaml");
713        assert_eq!(AssetType::Relationships.extension(), "yaml");
714        assert_eq!(AssetType::Odcs.extension(), "odcs.yaml");
715        assert_eq!(AssetType::Odps.extension(), "odps.yaml");
716        assert_eq!(AssetType::Cads.extension(), "cads.yaml");
717        assert_eq!(AssetType::Bpmn.extension(), "bpmn.xml");
718        assert_eq!(AssetType::Dmn.extension(), "dmn.xml");
719        assert_eq!(AssetType::Openapi.extension(), "openapi.yaml");
720    }
721
722    #[test]
723    fn test_asset_type_filename() {
724        assert_eq!(AssetType::Workspace.filename(), Some("workspace.yaml"));
725        assert_eq!(
726            AssetType::Relationships.filename(),
727            Some("relationships.yaml")
728        );
729        assert_eq!(AssetType::Odcs.filename(), None);
730    }
731
732    #[test]
733    fn test_asset_type_from_filename() {
734        assert_eq!(
735            AssetType::from_filename("workspace.yaml"),
736            Some(AssetType::Workspace)
737        );
738        assert_eq!(
739            AssetType::from_filename("relationships.yaml"),
740            Some(AssetType::Relationships)
741        );
742        assert_eq!(
743            AssetType::from_filename("test.odcs.yaml"),
744            Some(AssetType::Odcs)
745        );
746        assert_eq!(
747            AssetType::from_filename("test.odps.yaml"),
748            Some(AssetType::Odps)
749        );
750        assert_eq!(
751            AssetType::from_filename("test.cads.yaml"),
752            Some(AssetType::Cads)
753        );
754        assert_eq!(
755            AssetType::from_filename("test.bpmn.xml"),
756            Some(AssetType::Bpmn)
757        );
758        assert_eq!(
759            AssetType::from_filename("test.dmn.xml"),
760            Some(AssetType::Dmn)
761        );
762        assert_eq!(
763            AssetType::from_filename("test.openapi.yaml"),
764            Some(AssetType::Openapi)
765        );
766        assert_eq!(
767            AssetType::from_filename("test.openapi.json"),
768            Some(AssetType::Openapi)
769        );
770        assert_eq!(AssetType::from_filename("random.txt"), None);
771        assert_eq!(AssetType::from_filename("test.yaml"), None);
772    }
773
774    #[test]
775    fn test_asset_type_is_supported_file() {
776        assert!(AssetType::is_supported_file("workspace.yaml"));
777        assert!(AssetType::is_supported_file("relationships.yaml"));
778        assert!(AssetType::is_supported_file(
779            "enterprise_sales_orders.odcs.yaml"
780        ));
781        assert!(!AssetType::is_supported_file("readme.md"));
782        assert!(!AssetType::is_supported_file("config.json"));
783    }
784
785    #[test]
786    fn test_asset_type_is_workspace_level() {
787        assert!(AssetType::Workspace.is_workspace_level());
788        assert!(AssetType::Relationships.is_workspace_level());
789        assert!(!AssetType::Odcs.is_workspace_level());
790        assert!(!AssetType::Odps.is_workspace_level());
791    }
792
793    #[test]
794    fn test_sanitize_name() {
795        assert_eq!(sanitize_name("Hello World"), "hello-world");
796        assert_eq!(sanitize_name("Test/Path"), "test-path");
797        assert_eq!(sanitize_name("Normal"), "normal");
798    }
799}