# PartyIdentityAnchored — a facility's related party has a DIA in the graph.

@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:    <http://www.w3.org/2002/07/owl#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .
@prefix unece:  <https://test.uncefact.org/vocabulary/> .
@prefix gv:     <https://vocabulary.uncefact.org/untp/shapes/> .

gv:PartyIdentityAnchored
    a owl:Ontology, sh:NodeShape ;
    owl:versionInfo "0.8.0" ;
    rdfs:label "Party identity anchored"@en ;
    rdfs:comment "A facility's related party (owner or operator) must have a Digital Identity Anchor in the graph. Otherwise the facility record names a party whose identity is not bound to an authoritative register."@en ;
    rdfs:seeAlso <https://untp.unece.org/docs/design-patterns/TrustGraphs> ;
    sh:declare
        [ sh:prefix "unece" ; sh:namespace "https://test.uncefact.org/vocabulary/"^^xsd:anyURI ] ;
    sh:targetClass unece:Facility ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "This facility names a related party that has no Digital Identity Anchor in the graph."@en ;
        sh:prefixes gv:PartyIdentityAnchored ;
        sh:select """
            PREFIX unece: <https://test.uncefact.org/vocabulary/>
            SELECT $this ?party
            WHERE {
              $this unece:relatedParty / unece:relatedParty? ?party .
              FILTER(isIRI(?party))
              FILTER NOT EXISTS { ?party a unece:RegisteredIdentity }
            }
        """ ;
    ] .
