cimoxide-validation 0.3.1

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_1_allprofiles_ap_con_complex_shacl(dataset: &CimDataset) -> Vec<Violation> {
    let mut v = Vec::new();
    v.extend(check_p61970_600_1_allprofiles_ap_con_complex_shacl_full_model_model_profile_in(dataset));
    v.extend(check_p61970_600_1_allprofiles_ap_con_complex_shacl_difference_model_model_profile_in(dataset));
    v
}

pub fn check_p61970_600_1_allprofiles_ap_con_complex_shacl_full_model_model_profile_in(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("FullModel").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::FullModel>() {
            Some(o) => o, None => continue,
        };
        let allowed: &[&str] = &["http://iec.ch/TC57/ns/CIM/CoreEquipment-EU/3.0", "http://iec.ch/TC57/ns/CIM/Operation-EU/3.0", "http://iec.ch/TC57/ns/CIM/ShortCircuit-EU/3.0", "http://iec.ch/TC57/ns/CIM/DiagramLayout-EU/3.0", "http://iec.ch/TC57/ns/CIM/SteadyStateHypothesis-EU/3.0", "http://iec.ch/TC57/ns/CIM/Topology-EU/3.0", "http://iec.ch/TC57/ns/CIM/StateVariables-EU/3.0", "http://iec.ch/TC57/ns/CIM/Dynamics-EU/1.0", "http://iec.ch/TC57/ns/CIM/GeographicalLocation-EU/3.0", "http://iec.ch/TC57/ns/CIM/EquipmentBoundary-EU/3.0"];
        for val in &obj.base.profile {
            if val.is_empty() { continue; }
            if !allowed.contains(&val.as_str()) {
                violations.push(Violation {
                    object_id:   mrid.clone(),
                    rule_id:     "all600:Model.profile-allowedValues".to_string(),
                    class:       "FullModel".to_string(),
                    property:    "Model.profile".to_string(),
                    message:     "The model does not include any of the  md:Model.profile defined for CGMES.".to_string(),
                    severity:    "sh:Violation".to_string(),
                    name:        "C:600:ALL:Model.profile:allowedValues".to_string(),
                    description: "The respective profile URI shall be declared in the file header. If the profile URI is not included in the header, all classes/attributes/associations part of the undeclared profile are considered optional. Therefore, the profile references in the file header specify which profiles validation the instance file data is valid for. The instance data file (distribution) can contain data from multiple profiles (such as Short-Circuit or Operation) without being declared in the header profile references. However, the data belonging to non-declared profiles does not need to be imported and re-exported as the profiles are not defined in the file header. The user shall be informed if the data is not imported. (refer also to R:452:ALL:NA:exchange3 and R:452:ALL:NA:exchange4)".to_string(),
                });
            }
        }
    }
    violations
}

pub fn check_p61970_600_1_allprofiles_ap_con_complex_shacl_difference_model_model_profile_in(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("DifferenceModel").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::DifferenceModel>() {
            Some(o) => o, None => continue,
        };
        let allowed: &[&str] = &["http://iec.ch/TC57/ns/CIM/CoreEquipment-EU/3.0", "http://iec.ch/TC57/ns/CIM/Operation-EU/3.0", "http://iec.ch/TC57/ns/CIM/ShortCircuit-EU/3.0", "http://iec.ch/TC57/ns/CIM/DiagramLayout-EU/3.0", "http://iec.ch/TC57/ns/CIM/SteadyStateHypothesis-EU/3.0", "http://iec.ch/TC57/ns/CIM/Topology-EU/3.0", "http://iec.ch/TC57/ns/CIM/StateVariables-EU/3.0", "http://iec.ch/TC57/ns/CIM/Dynamics-EU/1.0", "http://iec.ch/TC57/ns/CIM/GeographicalLocation-EU/3.0", "http://iec.ch/TC57/ns/CIM/EquipmentBoundary-EU/3.0"];
        for val in &obj.base.profile {
            if val.is_empty() { continue; }
            if !allowed.contains(&val.as_str()) {
                violations.push(Violation {
                    object_id:   mrid.clone(),
                    rule_id:     "all600:Model.profile-allowedValues".to_string(),
                    class:       "DifferenceModel".to_string(),
                    property:    "Model.profile".to_string(),
                    message:     "The model does not include any of the  md:Model.profile defined for CGMES.".to_string(),
                    severity:    "sh:Violation".to_string(),
                    name:        "C:600:ALL:Model.profile:allowedValues".to_string(),
                    description: "The respective profile URI shall be declared in the file header. If the profile URI is not included in the header, all classes/attributes/associations part of the undeclared profile are considered optional. Therefore, the profile references in the file header specify which profiles validation the instance file data is valid for. The instance data file (distribution) can contain data from multiple profiles (such as Short-Circuit or Operation) without being declared in the header profile references. However, the data belonging to non-declared profiles does not need to be imported and re-exported as the profiles are not defined in the file header. The user shall be informed if the data is not imported. (refer also to R:452:ALL:NA:exchange3 and R:452:ALL:NA:exchange4)".to_string(),
                });
            }
        }
    }
    violations
}