@@ -6,7 +6,7 @@ class AgentIdentifier < LinkedData::Models::Base
66
77 model :Identifier , namespace : :adms , name_with : lambda { |i | generate_identifier ( i . notation , i . schemaAgency ) }
88
9- attribute :notation , namespace : :skos , enforce : %i[ existence no_url ]
9+ attribute :notation , namespace : :skos , enforce : %i[ existence no_url notation_format ]
1010 attribute :schemaAgency , namespace : :adms , enforcedValues : IDENTIFIER_SCHEMES . keys , enforce : [ :existence ]
1111 attribute :schemeURI , handler : :scheme_uri_infer
1212 attribute :creator , type : :user , enforce : [ :existence ]
@@ -31,6 +31,33 @@ def no_url(inst,attr)
3131 return notation &.start_with? ( 'http' ) ? [ :no_url , "`notation` must not be a URL" ] : [ ]
3232 end
3333
34+ def notation_format ( inst , attr )
35+ inst . bring ( [ attr , :schemaAgency ] ) if inst . bring? ( attr )
36+ notation = inst . send ( attr )
37+ schema_agency = inst . send ( :schemaAgency )
38+
39+ # Validate notation format depending on schema to not have weird ids
40+ case schema_agency
41+ when "ROR"
42+ unless notation . match? ( /^[0-9a-z]{9}$/i ) # ROR IDs are 9-char base32
43+ return [ :notation_format , "`notation` must be compliant with ROR format" ]
44+ end
45+ when "ORCID"
46+ unless notation . match? ( /^\d {4}-\d {4}-\d {4}-\d {3}[\d X]$/ )
47+ return [ :notation_format , "`notation` must be compliant with ORCID format" ]
48+ end
49+ when "ISNI"
50+ unless notation . match? ( /^\d {4}\s ?\d {4}\s ?\d {4}\s ?\d {3}[\d X]$/ )
51+ return [ :notation_format , "`notation` must be compliant with ISNI format" ]
52+ end
53+ when "GRID"
54+ unless notation . match? ( /^grid\. [0-9]+\. [a-f0-9]{1,2}$/i )
55+ return [ :notation_format , "`notation` must be compliant with GRID format" ]
56+ end
57+ end
58+
59+ end
60+
3461 def scheme_uri_infer
3562 self . bring ( :schemaAgency ) if self . bring? ( :schemaAgency )
3663 IDENTIFIER_SCHEMES [ self . schemaAgency . to_sym ] if self . schemaAgency
0 commit comments