Skip to content

Commit

Permalink
collection import
Browse files Browse the repository at this point in the history
  • Loading branch information
proceps committed Dec 4, 2014
1 parent 7bafbca commit 7f03c67
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 43 deletions.
1 change: 0 additions & 1 deletion app/models/accession_provider.rb
Expand Up @@ -6,5 +6,4 @@ class AccessionProvider < Role::ProjectRole
#
# has_many :collection_objects


end
2 changes: 2 additions & 0 deletions app/models/collecting_event.rb
Expand Up @@ -58,6 +58,8 @@ class CollectingEvent < ActiveRecord::Base
has_many :error_geographic_items, through: :georeferences, source: :error_geographic_item
has_many :geographic_items, through: :georeferences # See also all_geographic_items, the union
has_many :georeferences, dependent: :destroy
has_one :accession_provider_role, class_name: 'AccessionProvider', as: :role_object, dependent: :destroy
has_one :deaccession_recipient_role, class_name: 'DeaccessionRecipient', as: :role_object, dependent: :destroy

# Todo: this needs work
has_one :verbatim_georeference, class_name: 'Georeference::VerbatimData'
Expand Down
1 change: 0 additions & 1 deletion app/models/collector.rb
@@ -1,4 +1,3 @@
class Collector < Role::ProjectRole

include Housekeeping
end
149 changes: 108 additions & 41 deletions lib/tasks/import/insects/insects.rake
Expand Up @@ -23,13 +23,20 @@ namespace :tw do
attr_accessor :people, :people_id, :keywords, :users, :collecting_events, :collection_objects, :otus, :namespaces
def initialize()
@namespaces = {}
@preparation_types = {}
@people = {}
@people_id = {}
@users = {}
@keywords = {}
@collecting_events = {}
@collection_objects = {}
@otus = {}
$project_id = nil
$user_id = nil
$repository = #Repository.find_by institutional_LSID: 'urn:lsid:biocol.org:col:34797'
$user_index = {}
$collecting_event_index = {}
$invalid_collecting_event_index = {}
end

def export_to_pg(data_directory)
Expand All @@ -40,38 +47,38 @@ namespace :tw do

# These are largely collecting event related
PREDICATES = [
"Country",
"County",
"State",
'Country',
'County',
'State',

#"AccessionNumber",
"BodyOfWater",
"Collection",
"Comments",
'BodyOfWater',
'Collection',
'Comments',

#"Datum",
"Description",
"DrainageBasinGreater",
"DrainageBasinLesser",
"Family",

"Genus",
"Host",
"HostGenus",
"HostSpecies",
"INDrainage",
"LedgerBook",
"LocalityCode",
"OldLocalityCode",
"Order",
"Park",
"Remarks",
"Sex",
"Species",
"StreamSize",
"WisconsinGlaciated",

"PrecisionCode", # tag on Georeference
'Description',
'DrainageBasinGreater',
'DrainageBasinLesser',
'Family',

'Genus',
'Host',
'HostGenus',
'HostSpecies',
'INDrainage',
'LedgerBook',
'LocalityCode',
'OldLocalityCode',
'Order',
'Park',
'Remarks',
'Sex',
'Species',
'StreamSize',
'WisconsinGlaciated',

'PrecisionCode', # tag on Georeference
#"GBIF_precission" # tag
]

Expand Down Expand Up @@ -194,19 +201,13 @@ namespace :tw do
# types.txt


$project_id = nil
$user_id = nil
$repository #= Repository.find_by institutional_LSID: 'urn:lsid:biocol.org:col:34797'
$user_index = {}
$collecting_event_index = {}
$invalid_collecting_event_index = {}

def main_build_loop
@import = Import.find_or_create_by(name: IMPORT_NAME)
@import.metadata ||= {}
handle_projects_and_users(@data, @import)
raise '$project_id or $user_id not set.' if $project_id.nil? || $user_id.nil?
handle_namespaces(@data, @import)
handle_preparation_types(@data, @import)
handle_controlled_vocabulary(@data, @import)

handle_people(@data, @import) ## !created as new
Expand All @@ -215,7 +216,7 @@ namespace :tw do

checkpoint_save(@import) if ENV['no_transaction']

# !! The following can not be loaded from the database they are always created anew.
# !! The following can not be loaded from the database they are always created anew.
handle_collecting_events(@data, @import)
handle_specimens(@data, @import)

Expand Down Expand Up @@ -257,21 +258,87 @@ namespace :tw do

def handle_namespaces(data, import)
print "Handling namespaces "

catalogue_namespaces = [
'Acari',
'Araneae',
'Coleoptera',
'Diplopoda',
'Diptera',
'Ephemeroptera',
'Heteroptera',
'Homoptera',
'Hymenoptera',
'Insect Collection',
'Lepidoptera',
'Loan Invoice',
'Mecoptera',
'Neuroptera',
'Odonata',
'Opiliones',
'Orthoptera',
'Phthiraptera',
'Plecoptera',
'Pseudoscorpiones',
'Psocoptera',
'Scorpiones',
'Strepsiptera',
'Trichoptera'
]

if import.metadata['namespaces']
@import_namespace = Namespace.where(name: 'INHS Import Identifiers', short_name: 'INHS Import').first
@accession_namespace = Namespace.where(name: 'INHS Legacy Accession Codes', short_name: 'INHS Legacy Accession Code').first
@import_namespace = Namespace.where(institution: 'INHS Insect Collection', name: 'INHS Import Identifiers', short_name: 'Import').first
@accession_namespace = Namespace.where(institution: 'INHS Insect Collection', name: 'INHS Legacy Accession Code', short_name: 'Accession Code').first
print "from database.\n"
else
print "as newly parsed.\n"
@import_namespace = Namespace.create(name: 'INHS Import Identifiers', short_name: 'INHS Import')
@accession_namespace = Namespace.create(name: 'INHS Legacy Accession Codes', short_name: 'INHS Legacy Accession Code')
@import_namespace = Namespace.create(institution: 'INHS Insect Collection', name: 'INHS Import Identifiers', short_name: 'Import')
@accession_namespace = Namespace.create(institution: 'INHS Insect Collection', name: 'INHS Legacy Accession Code', short_name: 'Accession Code')
import.metadata['namespaces'] = true
end

catalogue_namespaces.each do |cn|
n = Namespace.where(institution: 'INHS Insect Collection', short_name: cn)
if n.empty?
n = Namespace.create(institution: 'INHS Insect Collection', name: 'INHS ' + cn, short_name: cn)
else
n = n.first
end
@namespaces.megre!(cn => n)
end

data.namespaces.merge!(import_namespace: @import_namespace)
data.namespaces.merge!(accession_namespace: @accession_namespace)
end

# Builds all the controlled vocabulary terms (tags/keywords)
def handle_preparation_types(data, import)
print "Handling namespaces "

preaparation_types = [
'Bulk dry',
'Envelope',
'Jar',
'Pill box',
'Pin',
'Slide',
'Vial'
]
preparation_types.each do |pt|
t = PreparationType.where(name: pt)
if t.empty?
t = PreparationType.create(name: pt) if t.nil?
else
t = t.first
end
@preparation_types.megre!(pt => t)
end
@preparation_types.megre!('Slides' => @preparation_types['Slide'])
@preparation_types.megre!('Vials' => @preparation_types['Vial'])
@preparation_types.megre!('pill box' => @preparation_types['Pill box'])
end


# Builds all the controlled vocabulary terms (tags/keywords)
def handle_controlled_vocabulary(data, import)
print "Handling CV "
if import.metadata['controlled_vocabulary']
Expand Down

0 comments on commit 7f03c67

Please sign in to comment.