cimoxide-validation 0.3.3

SHACL validation of CGMES datasets against the ENTSO-E profile constraints
Documentation
// Generated by cimgen — do not edit by hand.
#![allow(clippy::all, dead_code, unused)]
use cimdecoder::CimDataset;
use crate::Violation;
use crate::helpers::*;

pub fn validate_p61970_600_2_geographicallocation_ap_con_complex_shacl(dataset: &CimDataset) -> Vec<Violation> {
    let mut v = Vec::new();
    v.extend(check_p61970_600_2_geographicallocation_ap_con_complex_shacl_location_and(dataset));
    v
}

pub fn check_p61970_600_2_geographicallocation_ap_con_complex_shacl_location_and(dataset: &CimDataset) -> Vec<Violation> {
    let mut counts0: std::collections::HashMap<String, usize> = std::collections::HashMap::new();
    for src_mrid in dataset.by_type.get("PositionPoint").into_iter().flatten() {
        if let Some(src) = dataset.entries.get(src_mrid)
            .and_then(|e| e.element.as_any().downcast_ref::<cimstructs::PositionPoint>()) {
            if let Some(r) = &src.location {
                *counts0.entry(r.mrid.trim_start_matches('#').to_string()).or_insert(0) += 1;
            }
        }
    }
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("Location").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::Location>() {
            Some(o) => o, None => continue,
        };
        if obj.main_address.is_some() || counts0.get(mrid.as_str()).copied().unwrap_or(0) < 1 {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "gl600:Location-position".to_string(),
                class:       "Location".to_string(),
                property:    "C:600:GL:NA:position".to_string(),
                message:     "Either Location.mainAddress is provided or the Location is not referenced by a PositionPoint.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:600:GL:NA:position".to_string(),
                description: "IEC 61968-13 allows both PositionPoint and mainAddress to be exchanged. CGMES requires that PositionPoint is exchanged and mainAddress is not exchanged.".to_string(),
            });
        }
    }
    violations
}