Class: Tasks::Import::Dwca::PsuImportController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/import/dwca/psu_import_controller.rb

Instance Method Summary (collapse)

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

- (Object) do_not_psu_import

POST



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/tasks/import/dwca/psu_import_controller.rb', line 24

def do_not_psu_import
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :psu_import_md5)
    @result = BatchLoad::Import::DWCA.new(import_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} rows processed."
      render 'collecting_events/batch_load/simple/create' and return
    else
      flash[:alert] = 'Batch import failed.'
    end
  else
    flash[:alert] = 'File to batch upload must be supplied.'
  end
  render :index
end

- (Object) do_psu_import

POST



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/tasks/import/dwca/psu_import_controller.rb', line 11

def do_psu_import
  if params[:file]
    psuc_params = import_params.merge(pre_load)
    @result     = BatchLoad::Import::DWCA.new(psuc_params).rows
    digest_cookie(params[:file].tempfile, :psu_import_md5)
    render 'do_psu_import'
  else
    flash[:notice] = "No file provided!"
    redirect_to action: :index
  end
end

- (Object) import_params (private)



41
42
43
44
45
# File 'app/controllers/tasks/import/dwca/psu_import_controller.rb', line 41

def import_params
  params.permit(:dwca_namespace, :file, :import_level)
    .merge(user_id:    sessions_current_user_id,
           project_id: sessions_current_project_id).to_h.symbolize_keys
end

- (Object) index

GET



7
8
# File 'app/controllers/tasks/import/dwca/psu_import_controller.rb', line 7

def index
end

- (Object) pre_load (private)

what to do (because you are PSUC_FEM) before you try to load the entire file



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/tasks/import/dwca/psu_import_controller.rb', line 48

def pre_load
  p_id            = import_params[:project_id]
  pre_load        = {}
  root            = Protonym.find_or_create_by(name:       'Root',
                                               rank_class: 'NomenclaturalRank',
                                               parent_id:  nil,
                                               project_id: p_id)
  pre_load[:root] = root

  kingdom            = Protonym.find_or_create_by(name:       'Animalia',
                                                  parent_id:  root.id,
                                                  rank_class: 'NomenclaturalRank::Iczn::HigherClassificationGroup::Kingdom',
                                                  project_id: p_id)
  pre_load[:kingdom] = kingdom

  cat_no_pred            = Predicate.find_or_create_by(name:       'catalogNumber',
                                                       definition: 'The verbatim value imported from PSUC for "catalogNumber".',
                                                       project_id: p_id)
  pre_load[:cat_no_pred] = cat_no_pred

  geo_rem_kw            = Keyword.find_or_create_by(name:       'georeferenceRemarks',
                                                    definition: 'The verbatim value imported from PSUC for "georeferenceRemarks".',
                                                    project_id: p_id)
  pre_load[:geo_rem_kw] = geo_rem_kw

  repo            = Repository.find_or_create_by(name:                 'Frost Entomological Museum, Penn State University',
                                                 url:                  'http://grbio.org/institution/frost-entomological-museum-penn-state-university',
                                                 status:               'Yes',
                                                 acronym:              'PSUC',
                                                 is_index_herbariorum: false)
  pre_load[:repo] = repo

  # Namespace requires name and short_name to be present, and unique
  namespace            = Namespace.find_or_create_by(institution: 'Penn State University Collection',
                                                     name:        'Frost Entomological Museum',
                                                     short_name:  'PSUC_FEM')
  pre_load[:namespace] = namespace

  pre_load
end