Class: Identifier::Global

Inherits:
Identifier
  • Object
show all
Defined in:
app/models/identifier/global.rb

Overview

The identifier that is globally unique.

Curators of a specific project assert one canonical global identifier per type for each object, this identifier is identified by having .relation.nil?. If the curators feel there are multiple global identifiers for a given instance they must provide an explicit relationship between the canonical identifier and the alternate identifiers.

Direct Known Subclasses

Doi, Isbn, Issn, Lccn, Lsid, Orcid, Uri, Uuid

Defined Under Namespace

Classes: Doi, Isbn, Issn, Lccn, Lsid, Orcid, Uri, Uuid

Constant Summary

Constant Summary

Constants inherited from Identifier

SHORT_NAMES

Instance Attribute Summary (collapse)

Attributes inherited from Identifier

#cached, #identifier, #identifier_object_id, #namespace_id, #project_id, #type

Instance Method Summary (collapse)

Methods inherited from Identifier

#annotated_object, class_name, find_for_autocomplete, generate_download, #klass_name, prototype_identifier

Methods included from Housekeeping

#has_polymorphic_relationship?

Instance Attribute Details

- (String) relation

Defines the relationship between the curator asserted canonical identifier and other identifiers of the same type. Must be provided for every global identifier of the same type beyond the first. Relations are drawn from skos (www.w3.org/TR/skos-reference/#mapping)

Returns:

  • (String)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/identifier/global.rb', line 14

class Identifier::Global < Identifier

  validates :namespace_id, absence: true
  validates :relation, inclusion: {in: SKOS_RELATIONS.keys}, allow_nil: true
  validate :permit_only_one_global_without_relation_supplied_per_type

  # Identifier can only be used once, i.e. mapped to a single TW concept
  validates_uniqueness_of :identifier, scope: [:project_id]

  protected

  def set_cached
    self.cached = identifier
  end

  def permit_only_one_global_without_relation_supplied_per_type
    if identifier_object && identifier_object.identifiers.where(type:self.type.to_s).where.not(id: self.id ).any?
      errors.add(:relation, " an existing identifier of type #{self.type} exists, a relation for this identifier must be provided") if self.relation.nil?
    end
  end

end

Instance Method Details

- (Object) permit_only_one_global_without_relation_supplied_per_type (protected)



29
30
31
32
33
# File 'app/models/identifier/global.rb', line 29

def permit_only_one_global_without_relation_supplied_per_type
  if identifier_object && identifier_object.identifiers.where(type:self.type.to_s).where.not(id: self.id ).any?
    errors.add(:relation, " an existing identifier of type #{self.type} exists, a relation for this identifier must be provided") if self.relation.nil?
  end
end

- (Object) set_cached (protected)



25
26
27
# File 'app/models/identifier/global.rb', line 25

def set_cached
  self.cached = identifier
end