app/models/import_dataset/darwin_core/occurrences.rb
# Stages core (Occurrence) records and all extension records.
Stages core (Occurrence) records and all extension records.
Stages core ( Occurrence ) records and all extension records .
def perform_staging
    records, headers = get_records(source)
    update!(metadata:
      metadata.merge({
        core_headers: headers[:core],
        extensions_headers: headers[:extensions],
        catalog_numbers_namespaces: []
      })
    )
    core_records = records[:core].map do |record|
      {
        src_data: record,
        basisOfRecord: record["basisOfRecord"]
      }
    end
    catalog_numbers_namespaces = Set[]
    core_records.each do |record|
      dwc_occurrence = DatasetRecord::DarwinCore::Occurrence.new(import_dataset: self)
      dwc_occurrence.initialize_data_fields(record[:src_data].map { |k, v| v })
      catalog_numbers_namespaces << [
        [
          dwc_occurrence.get_field_value(:institutionCode),
          dwc_occurrence.get_field_value(:collectionCode)
        ],
        nil 
      ]
      if dwc_occurrence.get_field_value(:catalogNumber).blank?
        dwc_occurrence.status = "Ready"
      else
        dwc_occurrence.status = "NotReady"
        record["error_data"] = { messages: { catalogNumber: ["Record cannot be imported until namespace is set."] } }
      end
      record.delete(:src_data)
      dwc_occurrence.metadata = record
      dwc_occurrence.save!
    end
    records[:extensions].each do |extension_type, records|
      records.each do |record|
        dwc_extension = DatasetRecord::DarwinCore::Extension.new(import_dataset: self)
        dwc_extension.initialize_data_fields(record.map { |k, v| v })
        dwc_extension.status = "Unsupported"
        dwc_extension.metadata = { "type" => extension_type }
        dwc_extension.save!
      end
    end
    update!(metadata: self.metadata.merge!(catalog_numbers_namespaces: catalog_numbers_namespaces))
  end
def perform_staging records , headers = get_records ( source ) update! ( metadata : metadata . merge ( { core_headers : headers [ :core ] , extensions_headers : headers [ :extensions ] , catalog_numbers_namespaces : [ ] } ) ) core_records = records [ :core ] . map do | record | { src_data : record , basisOfRecord : record [ "basisOfRecord" ] } end catalog_numbers_namespaces = Set [ ] core_records . each do | record | dwc_occurrence = DatasetRecord :: DarwinCore :: Occurrence . new ( import_dataset : self ) dwc_occurrence . initialize_data_fields ( record [ :src_data ] . map { | k , v | v } ) catalog_numbers_namespaces << [ [ dwc_occurrence . get_field_value ( :institutionCode ) , dwc_occurrence . get_field_value ( :collectionCode ) ] , nil ] if dwc_occurrence . get_field_value ( :catalogNumber ) . blank? dwc_occurrence . status = "Ready" else dwc_occurrence . status = "NotReady" record [ "error_data" ] = { messages : { catalogNumber : [ "Record cannot be imported until namespace is set." ] } } end record . delete ( :src_data ) dwc_occurrence . metadata = record dwc_occurrence . save! end records [ :extensions ] . each do | extension_type , records | records . each do | record | dwc_extension = DatasetRecord :: DarwinCore :: Extension . new ( import_dataset : self ) dwc_extension . initialize_data_fields ( record . map { | k , v | v } ) dwc_extension . status = "Unsupported" dwc_extension . metadata = { "type" => extension_type } dwc_extension . save! end end update! ( metadata : self . metadata . merge! ( catalog_numbers_namespaces : catalog_numbers_namespaces ) ) end
Stages core (Occurrence) records and all extension records.
Stages core ( Occurrence ) records and all extension records .
# User will select namespace through UI. TODO: Should we attempt guessing here?