Class: Identifier::Local::CatalogNumber

Inherits:
Identifier::Local show all
Includes:
Shared::DwcOccurrenceHooks
Defined in:
app/models/identifier/local/catalog_number.rb

Overview

The Identifier that identifies a collection object. Examples include barcodes printed on labels.

Does not imply an accessioning process.

Constant Summary collapse

TARGETS =
%w{CollectionObject Container Extract FieldOccurrence}.freeze

Instance Method Summary collapse

Methods inherited from Identifier::Local

#build_cached, build_cached_prefix, #increment_identifier, #is_local?, #is_virtual?, update_cached, #with_namespaced_identifier

Instance Method Details

#assigned_to_valid_objectObject (private)



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/identifier/local/catalog_number.rb', line 34

def assigned_to_valid_object
  type_issue =
    identifier_object_type && !TARGETS.include?(identifier_object_type)

  object_issue = identifier_object &&
    TARGETS.none? { |c| identifier_object.kind_of?(c.constantize) }

  if type_issue || object_issue
    errors.add(:identifier_object_type, "only assignable to #{TARGETS.join(', ')}
    ")
  end
end

#dwc_occurrencesObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/identifier/local/catalog_number.rb', line 15

def dwc_occurrences

  # TODO: CONTAINERS UNION

  collection_object_scope = DwcOccurrence
    .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'")
    .joins("JOIN identifiers i on i.identifier_object_id = co.id AND i.identifier_object_type = 'CollectionObject'")
    .where(i: {id:})

  field_occurrence_scope = DwcOccurrence
    .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'")
    .joins("JOIN identifiers i on i.identifier_object_id = fo.id AND i.identifier_object_type = 'FieldOccurrence'")
    .where(i: {id:})

  DwcOccurrence.from("(#{collection_object_scope.to_sql} UNION #{field_occurrence_scope.to_sql}) AS dwc_occurrences")
end