Module: BiologicalAssociation::DwcExtensions

Extended by:
ActiveSupport::Concern
Included in:
BiologicalAssociation
Defined in:
app/models/biological_association/dwc_extensions.rb

Instance Method Summary collapse

Instance Method Details

#darwin_core_extension_json(inverted = false) ⇒ Object



47
48
49
# File 'app/models/biological_association/dwc_extensions.rb', line 47

def darwin_core_extension_json(inverted = false)

end

#darwin_core_extension_row(inverted: false) ⇒ Object

Don’t use dwc_ !! inverted means subject and object have already been switched, but relationship must use ‘inverted_name` instead of `name`.



25
26
27
# File 'app/models/biological_association/dwc_extensions.rb', line 25

def darwin_core_extension_row(inverted: false)
  Export::CSV::Dwc::Extension::BiologicalAssociations::HEADERS.collect{|h| send(DWC_EXTENSION_MAP[h.to_sym], inverted)}
end


97
98
99
100
101
102
103
104
# File 'app/models/biological_association/dwc_extensions.rb', line 97

def dwc_related_resource(inverted = false)
  case biological_association_object.class.base_class.name
  when 'Otu'
    ApplicationController.helpers.label_for_otu(biological_association_object)
  when 'CollectionObject'
    ApplicationController.helpers.label_for_collection_object(biological_association_object)
  end
end


88
89
90
91
92
93
94
95
# File 'app/models/biological_association/dwc_extensions.rb', line 88

def dwc_related_resource_id(inverted = false)
  case biological_association_object.class.base_class.name
  when 'Otu'
    biological_association_object.uuid || biological_association_object.uri || biological_association_object.id
  when 'CollectionObject'
    biological_association_object.dwc_occurrence_id
  end
end

#dwc_relationship_according_to(inverted = false) ⇒ Object

TODO: Should reference DOIs, Identifiers, or identifiers in lieu of short citations



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/models/biological_association/dwc_extensions.rb', line 107

def dwc_relationship_according_to(inverted = false)
  ApplicationController.helpers.short_sources_tag(sources)

  # Could be collectors (ORCID or ...)
  # Could be citation providers

  t = [biological_association_subject_type , biological_association_object_type]

  case t
  when %w{Otu Otu} # Published or nothing
    ApplicationController.helpers.short_sources_tag(sources)
  when %w{CollectionObject Otu} # Assume exists on label
    biological_association_subject.dwc_recorded_by || ApplicationController.helpers.short_sources_tag(sources)
  when %w{Otu CollectionObject} # Assume exists on label
    biological_association_object.dwc_recorded_by || ApplicationController.helpers.short_sources_tag(sources)
  when %w{CollectionObject CollectionObject}
    # Lots of assumptions behind this.  What if specimens were marked as collected in 2 different events, that would be odd
    # but perhaps not impossible
    biological_association_subject.dwc_recorded_by || biological_association_object.dwc_recorded_by
  else
    'BAD DATA: TYPE ERROR'
  end
end

#dwc_relationship_established_date(inverted = false) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'app/models/biological_association/dwc_extensions.rb', line 131

def dwc_relationship_established_date(inverted = false)
  t = [biological_association_subject_type , biological_association_object_type]

  case t
  when %w{Otu Otu}
    ApplicationController.helpers.short_sources_year_tag(sources)
  when %w{CollectionObject Otu}
    biological_association_subject.dwc_event_date || ApplicationController.helpers.short_sources_year_tag(sources)
  when %w{Otu CollectionObject}
    biological_association_object.dwc_event_date || ApplicationController.helpers.short_sources_year_tag(sources)
  when %w{CollectionObject CollectionObject}
    # Lots of assumptions behind this.  What if specimens were marked as collected in 2 different events, that would be odd
    # but perhaps not impossible
    biological_association_subject.dwc_event_date || biological_association_object.dwc_event_date
  else
    'BAD DATA: TYPE ERROR'
  end
end

#dwc_relationship_of_resource(inverted = false) ⇒ Object



80
81
82
83
84
85
86
# File 'app/models/biological_association/dwc_extensions.rb', line 80

def dwc_relationship_of_resource(inverted = false)
  if inverted
    biological_relationship.inverted_name
  else
    biological_relationship.name
  end
end

#dwc_relationship_of_resource_id(inverted = false) ⇒ Object



73
74
75
76
77
78
# File 'app/models/biological_association/dwc_extensions.rb', line 73

def dwc_relationship_of_resource_id(inverted = false)
  s = biological_relationship.uris.first&.cached || biological_relationship_id

  # TODO: this might mess up uri handling
  inverted ? "#{s} inverted" : s
end

#dwc_relationship_remarks(inverted = false) ⇒ Object

TODO: Generic helper



151
152
153
# File 'app/models/biological_association/dwc_extensions.rb', line 151

def dwc_relationship_remarks(inverted = false)
  Utilities::Strings.sanitize_for_csv( notes.collect{|n| n.text}.join(' | ')).presence
end

#dwc_resource(inverted = false) ⇒ Object



64
65
66
67
68
69
70
71
# File 'app/models/biological_association/dwc_extensions.rb', line 64

def dwc_resource(inverted = false)
  case biological_association_subject.class.base_class.name
  when 'Otu'
    ApplicationController.helpers.label_for_otu(biological_association_subject)
  when 'CollectionObject'
    ApplicationController.helpers.label_for_collection_object(biological_association_subject)
  end
end

#dwc_resource_id(inverted = false) ⇒ Object



55
56
57
58
59
60
61
62
# File 'app/models/biological_association/dwc_extensions.rb', line 55

def dwc_resource_id(inverted = false)
  case biological_association_subject.class.base_class.name
  when 'Otu'
    biological_association_subject.uuid || biological_association_subject.uri || biological_association_subject.id
  when 'CollectionObject'
    biological_association_subject.dwc_occurrence_id
  end
end

#dwc_resource_relationship_coreid(inverted = false) ⇒ Object



40
41
42
43
44
45
# File 'app/models/biological_association/dwc_extensions.rb', line 40

def dwc_resource_relationship_coreid(inverted = false)
  core_object_klass = biological_association_subject.class.base_class.name
  if core_object_klass == 'CollectionObject'
    return biological_association_subject.dwc_occurrence.id
  end
end

#dwc_resource_relationship_id(inverted = false) ⇒ Object



51
52
53
# File 'app/models/biological_association/dwc_extensions.rb', line 51

def dwc_resource_relationship_id(inverted = false)
  uuid || id
end

#globi_extension_jsonObject

Don’t use dwc_



30
31
32
33
34
35
36
37
38
# File 'app/models/biological_association/dwc_extensions.rb', line 30

def globi_extension_json
  r = {}
   Export::CSV::Dwc::Extension::BiologicalAssociations::HEADERS.each do |h|
    if m = DWC_EXTENSION_MAP[h.to_sym]
      r[h] = send(m, false)
    end
  end
  r
end