Class: Identifier::Local

Inherits:
Identifier show all
Defined in:
app/models/identifier/local.rb

Overview

The identifier that is generated for local use, i.e. no signficant effort (countering example DOIs) was made to ensure global uniqueness. While most identifiers are intended to be unique globally, few consider mechanisms for ensuring this.

Local identifiers of the same type may be stacked on a single record without defining the relation between each identifier (see conceptual difference in Identfier::Global).

Local identifiers require a namespace. See Namespace.

Multiple local identfiers of the same namespace can be applied to the same object, while this is rarely useful in real life it does have physical-world analogs, see in particular Accession numbers on Collecting Events linked to Specimens that are in the process of being accessioned.

Foo 123 (CatalogNumber)
Foo 345 (CatalogNumber)

You can also do this on the same object:

Foo 123 (CatalogNumber)
Bar 123 (CatalogNumber)

In addition, identifiers of a certain type (subclass) must be unique across namespaces within a project.

Defined Under Namespace

Classes: AccessionCode, CatalogNumber, ContainerCode, Import, LoanCode, OtuUtility, TripCode

Constant Summary

Constants included from Shared::DualAnnotator

Shared::DualAnnotator::ALWAYS_COMMUNITY

Instance Attribute Summary

Attributes inherited from Identifier

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Identifier

#build_cached_numeric_identifier, #is_global?, prototype_identifier, #set_cached, #type_name

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Labels

#labeled?

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from Shared::PolymorphicAnnotator

#annotated_object_is_persisted?

Methods inherited from ApplicationRecord

transaction_with_retry

Class Method Details

.build_cached_prefix(namespace) ⇒ Object (protected)



69
70
71
72
73
74
75
76
77
78
# File 'app/models/identifier/local.rb', line 69

def self.build_cached_prefix(namespace)
  if namespace.is_virtual?
    ''
  else
    delimiter = namespace.read_attribute(:delimiter) || ' '
    delimiter = '' if delimiter == 'NONE'

    [namespace&.verbatim_short_name, namespace&.short_name, ''].compact.first + delimiter
  end
end

.update_cached(namespace) ⇒ Object

Update cached values for all local identifiers within namespace (if needed)

Parameters:



44
45
46
47
48
49
50
51
52
53
# File 'app/models/identifier/local.rb', line 44

def self.update_cached(namespace)
  where(namespace: namespace).update_all(
    cached: Arel::Nodes::NamedFunction.new('concat',
      [
        Arel::Nodes.build_quoted(build_cached_prefix(namespace)),
        Identifier::Local.arel_table[:identifier]
      ]
    )
  ) if [:short_name, :verbatim_short_name, :delimiter, :is_virtual].detect { |a| namespace.saved_change_to_attribute?(a) }
end

Instance Method Details

#build_cachedObject (protected)



61
62
63
64
65
66
67
# File 'app/models/identifier/local.rb', line 61

def build_cached
  if namespace.is_virtual
    identifier
  else
    Identifier::Local.build_cached_prefix(namespace) + identifier.to_s
  end
end

#is_local?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/identifier/local.rb', line 55

def is_local?
  true
end

#with_namespaced_identifier(namespace_name, identifier) ⇒ Scope

Exact match on identifier + namespace

Parameters:

  • (String, String)

Returns:

  • (Scope)


34
35
36
37
38
39
40
# File 'app/models/identifier/local.rb', line 34

def with_namespaced_identifier(namespace_name, identifier)
  ret_val = includes(:identifiers).where(identifiers: {namespace: {name: namespace_name}}, identifier: identifier).references(:identifiers)
  if ret_val.count == 0
    ret_val = includes(:identifiers).where(identifiers: {namespace: {short_name: namespace_name}}, identifier: identifier).references(:identifiers)
  end
  ret_val
end