Module: Shared::Dwc::MediaTargetExtensions

Extended by:
ActiveSupport::Concern
Included in:
CollectionObject::DwcExtensions, FieldOccurrence::DwcExtensions
Defined in:
app/models/concerns/shared/dwc/media_target_extensions.rb

Overview

A concern on media ‘targets’ (i.e. things that are conveyed or depicted by media) like CollectionObjects and FieldOccurrences.

Constant Summary collapse

DWC_MEDIA_EXTENSION_MAP =

See rs.gbif.org/extension/ac/audiovisual_2024_11_07.xml and Export::CSV::Dwc::Extension::Media::HEADERS for the original list. The list here is uncommented only for those properties actually mapped by this concern; see concerns on Image, Sound, and Observation for others.

{
  coreid: :dwc_media_coreid,
  # identifier - !? should be the file SHA
  #'dc:type': :dwc_media_dc_type, # TODO: is the prefix the way to do this?
  #'dcmi:type': :dwc_media_dcmi_type,
  # 'subtypeLiteral',
  # 'subtype',
  # 'title',
  # 'modified', # TODO: updated_at ??
  # 'MetadataDate',
  # 'metadataLanguageLiteral',
  # 'metadataLanguage',
  #providerManagedID: :dwc_media_provider_managed_id, # currently id ??
  # #'Rating',
  # #'commenterLiteral',
  # #'commenter',
  # #'comments',
  # #'reviewerLiteral',
  # #'reviewer',
  # #'reviewerComments',
  # 'available',
  # 'hasServiceAccessPoint',
  # !! 'dc:rights': :dwc_media_dc_rights,
  # 'dcterms:rights': :dwc_media_dcterms_rights,
  # !! Owner: :dwc_media_owner,
  # !? 'UsageTerms',
  # 'WebStatement',
  # 'licenseLogoURL',
  # !! Credit: :dwc_media_credit,
  # 'attributionLogoURL',
  # 'attributionLinkURL',
  # #'fundingAttribution',
  # 'dc:source',
  # 'dcterms:source',
  # !! 'dc:creator': :dwc_media_dc_creator,
  # !! 'dcterms:creator',
  # 'providerLiteral', TODO??
  # 'provider', TODO?? (really vague concept)
  # 'metadataCreatorLiteral',
  # 'metadataCreator',
  # 'metadataProviderLiteral',
  # 'metadataProvider',
  description: :dwc_media_description, # currently from depiction/conveyance <-- this is right
  caption: :dwc_media_caption,
  # 'dc:language',
  # 'dcterms:language',
  # #'physicalSetting',
  # 'CVterm',
  # 'subjectCategoryVocabulary',
  #tag: :dwc_media_tag, # TODO list tags??
  # 'LocationShown', # TODO?? could be AD of depiction/conveyance of image/sound (on otu)
  # 'WorldRegion',
  #CountryCode: :dwc_media_country_code,
  #CountryName: :dwc_media_country_name, # !! Not needed, inferred from core
  #ProvinceState: :dwc_media_province_state, # !! Not needed, inferred from core
  # 'City',
  # 'Sublocation',
  # 'temporal',
  # 'CreateDate',
  # 'timeOfDay',
  #taxonCoverage: :dwc_media_taxon_coverage,
  #scientificName: :dwc_media_scientific_name, # !! Not needed, inferred from core
  # 'identificationQualifier',
  #vernacularName: :dwc_media_vernacular_name, # !! Not needed, inferred from core
  # 'nameAccordingTo',
  # 'scientificNameID',
  # 'otherScientificName',
  #identifiedBy: :dwc_media_identified_by, # !! Not needed, inferred from core
  #dateIdentified: :dwc_media_date_identified, # !! Not needed, inferred from core
  # 'taxonCount',
  # #'subjectPart',
  #sex: :dwc_media_sex,  # !! not needed, inferred from core
  #lifeStage: :dwc_media_life_stage, # !! not needed, inferred from core
  # 'subjectOrientation',
  # 'preparations',
  # 'LocationCreated',
  # 'digitizationDate',
  # #'captureDevice',
  # #'resourceCreationTechnique',
  # #'IDofContainingCollection',
  # 'relatedResourceID',
  # 'providerID',
  # 'derivedFrom',
  associatedSpecimenReference: :dwc_media_associated_specimen_reference,
  # !! associatedObservationReference: :dwc_media_associated_observation_reference,
  # !! accessURI: dwc_media_access_uri,
  # !! 'dc:format': :dwc_media_dc_format,
  # 'dcterms:format',
  # 'variantLiteral',
  # 'variant',
  # 'variantDescription',
  # !! furtherInformationURL: :dwc_media_further_information_url,
  #'licensingException',
  #'serviceExpectation',
  #'hashFunction',
  #'hashValue',
  # !! PixelXDimension: dwc_pixel_x_dimension,
  # !! PixelYDimension: dwc_pixel_y_dimension
}.freeze

Instance Method Summary collapse

Instance Method Details

#darwin_core_media_extension_rowsObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 110

def darwin_core_media_extension_rows
  rv = []
  images_array = (
    images.map { |i| { image: i, observation: nil }} +
    observations.map { |o| o.images.map { |i| { image: i, observation: o }} }
  ).flatten
  rv += images_array.collect do |i|
    image_dwc_array =
      Export::CSV::Dwc::Extension::Media::HEADERS.collect do |h|
        dwc_reader = DWC_MEDIA_EXTENSION_MAP[h.to_sym]
        dwc_reader.present? && respond_to?(dwc_reader) ?
          send(dwc_reader, i[:image]) : nil
      end

    image_fields_hash = i[:image].darwin_core_media_extension_image_row
    # Merge image_fields_hash data into image_dwc_array.
    image_fields_hash.each { |k, v| image_dwc_array[extension_map_index(k)] = v }

    if i[:observation]
      observation_fields_hash = i[:observation].darwin_core_media_extension_image_row
      observation_fields_hash.each { |k, v| image_dwc_array[extension_map_index(k)] = v }
    end

    image_dwc_array
  end

  sounds_array = (
    sounds.map { |s| { sound: s, observation: nil }} #+
    #observations.map { |o| o.sounds.map { |s| { sound: s, observation: o }} }
  ).flatten
  rv += sounds_array.collect do |s|
    sound_dwc_array =
      Export::CSV::Dwc::Extension::Media::HEADERS.collect do |h|
        dwc_reader = DWC_MEDIA_EXTENSION_MAP[h.to_sym]
        dwc_reader.present? && respond_to?(dwc_reader) ?
          send(dwc_reader, s[:sound]) : nil
      end

    sound_fields_hash = s[:sound].darwin_core_media_extension_sound_row
    # Merge sound_fields_hash data into sound_dwc_array.
    sound_fields_hash.each { |k, v| sound_dwc_array[extension_map_index(k)] = v }

    # TODO: bring this back once conveyances are back on Observations.
    # if s[:observation]
    #   observation_fields_hash = s[:observation].darwin_core_media_extension_sound_row
    #   observation_fields_hash.each { |k, v| sound_dwc_array[extension_map_index(k)] = v }
    # end

    sound_dwc_array
  end

  rv
end

#dwc_media_associated_specimen_reference(o) ⇒ Object

def dwc_media_life_stage(o)

dwc_life_stage

end



239
240
241
242
243
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 239

def dwc_media_associated_specimen_reference(o)
  if self.is_a?(CollectionObject)
    Shared::Api.api_link(self)
  end
end

#dwc_media_caption(o) ⇒ Object



184
185
186
187
188
189
190
191
192
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 184

def dwc_media_caption(o)
  case o.class.name
  when 'Image'
    d = depictions.select { |d| d.image_id == o.id }.first
    d.caption if d
  else
    nil
  end
end

#dwc_media_coreid(o) ⇒ Object



168
169
170
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 168

def dwc_media_coreid(o)
  dwc_occurrence.occurrenceID
end

#dwc_media_description(o) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 172

def dwc_media_description(o)
  case o.class.name
  when 'Image'
    d = depictions.select { |d| d.image_id == o.id }.first
    d.figure_label if d
  when 'Sound'
    o.name
  else
    nil
  end
end

#extension_map_index(key) ⇒ Object



164
165
166
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 164

def extension_map_index(key)
  Export::CSV::Dwc::Extension::Media::HEADERS_INDEX[key.to_sym]
end