Class: Bulkrax::ImportersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Bulkrax::ImportersController
- Includes:
- API, DownloadBehavior, ValidationHelper, Hyrax::ThemedLayoutController
- Defined in:
- app/controllers/bulkrax/importers_controller.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#continue ⇒ Object
PUT /importers/1.
-
#create ⇒ Object
POST /importers rubocop:disable Metrics/MethodLength.
-
#destroy ⇒ Object
DELETE /importers/1.
-
#edit ⇒ Object
GET /importers/1/edit.
-
#export_errors ⇒ Object
GET /importers/1/export_errors.
- #external_sets ⇒ Object
-
#index ⇒ Object
GET /importers.
-
#new ⇒ Object
GET /importers/new.
-
#show ⇒ Object
GET /importers/1.
-
#update ⇒ Object
PATCH/PUT /importers/1 # @todo refactor so as to not need to disable rubocop rubocop:disable all.
-
#upload_corrected_entries ⇒ Object
GET /importer/1/upload_corrected_entries.
-
#upload_corrected_entries_file ⇒ Object
POST /importer/1/upload_corrected_entries_file.
Methods included from ValidationHelper
#check_admin_set, #check_user, #return_json_response, #return_value, #valid_bagit?, #valid_commit?, #valid_commit_message?, #valid_create_params?, #valid_csv?, #valid_importer?, #valid_name?, #valid_oai?, #valid_parser_fields?, #valid_parser_klass?, #valid_update_params?
Methods included from DownloadBehavior
#content_head, #content_options, #file, #file_name, #prepare_file_headers, #send_content, #send_file_contents
Instance Method Details
#continue ⇒ Object
PUT /importers/1
152 153 154 155 156 157 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 152 def continue @importer = Importer.find(params[:importer_id]) params[:importer] = { name: @importer.name } @importer.validate_only = false update end |
#create ⇒ Object
POST /importers rubocop:disable Metrics/MethodLength
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 69 def create # rubocop:disable Style/IfInsideElse if api_request? return return_json_response unless valid_create_params? end file = file_param cloud_files = cloud_params @importer = Importer.new(importer_params) field_mapping_params @importer.validate_only = true if params[:commit] == 'Create and Validate' # the following line is needed to handle updating remote files of a FileSet # on a new import otherwise it only gets updated during the update path @importer.parser_fields['update_files'] = true if params[:commit] == 'Create and Import' if @importer.save files_for_import(file, cloud_files) if params[:commit] == 'Create and Import' Bulkrax::ImporterJob.send(@importer.parser.perform_method, @importer.id) render_request('Importer was successfully created and import has been queued.') elsif params[:commit] == 'Create and Validate' Bulkrax::ImporterJob.send(@importer.parser.perform_method, @importer.id) render_request('Importer validation completed. Please review and choose to either Continue with or Discard the import.', true) else render_request('Importer was successfully created.') end else if api_request? json_response('create', :unprocessable_entity) else render :new end end # rubocop:enable Style/IfInsideElse end |
#destroy ⇒ Object
DELETE /importers/1
142 143 144 145 146 147 148 149 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 142 def destroy @importer.destroy if api_request? json_response('destroy', :ok, notice: 'Importer was successfully destroyed.') else redirect_to importers_url, notice: 'Importer was successfully destroyed.' end end |
#edit ⇒ Object
GET /importers/1/edit
57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 57 def edit if api_request? json_response('edit') elsif defined?(::Hyrax) @importer.name, bulkrax.importer_path(@importer.id) 'Edit' end end |
#export_errors ⇒ Object
GET /importers/1/export_errors
193 194 195 196 197 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 193 def export_errors @importer = Importer.find(params[:importer_id]) @importer.write_errored_entries_file send_content end |
#external_sets ⇒ Object
184 185 186 187 188 189 190 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 184 def external_sets if list_external_sets render json: { base_url: params[:base_url], sets: @sets } else render json: { base_url: params[:base_url], error: "unable to pull data from #{params[:base_url]}" } end end |
#index ⇒ Object
GET /importers
22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 22 def index # NOTE: We're paginating this in the browser. @importers = Importer.order(created_at: :desc).all if api_request? json_response('index') elsif defined?(::Hyrax) end end |
#new ⇒ Object
GET /importers/new
46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 46 def new @importer = Importer.new if api_request? json_response('new') elsif defined?(::Hyrax) 'New' end end |
#show ⇒ Object
GET /importers/1
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 33 def show if api_request? json_response('show') elsif defined?(::Hyrax) @importer.name end @work_entries = @importer.entries.where(type: @importer.parser.entry_class.to_s).page(params[:work_entries_page]).per(30) @collection_entries = @importer.entries.where(type: @importer.parser.collection_entry_class.to_s).page(params[:collections_entries_page]).per(30) @file_set_entries = @importer.entries.where(type: @importer.parser.file_set_entry_class.to_s).page(params[:file_set_entries_page]).per(30) end |
#update ⇒ Object
PATCH/PUT /importers/1 # @todo refactor so as to not need to disable rubocop rubocop:disable all
107 108 109 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 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 107 def update if api_request? return return_json_response unless valid_update_params? end file = file_param cloud_files = cloud_params # Skipped during a continue field_mapping_params if params[:importer][:parser_fields].present? if @importer.update(importer_params) files_for_import(file, cloud_files) unless file.nil? && cloud_files.nil? # do not perform the import unless params[:commit] == 'Update Importer' set_files_parser_fields Bulkrax::ImporterJob.send(@importer.parser.perform_method, @importer.id, update_harvest) end if api_request? json_response('updated', :ok, 'Importer was successfully updated.') else redirect_to importers_path, notice: 'Importer was successfully updated.' end else if api_request? json_response('update', :unprocessable_entity, 'Something went wrong.') else render :edit end end end |
#upload_corrected_entries ⇒ Object
GET /importer/1/upload_corrected_entries
160 161 162 163 164 165 166 167 168 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 160 def upload_corrected_entries @importer = Importer.find(params[:importer_id]) return unless defined?(::Hyrax) t(:'hyrax.controls.home'), main_app.root_path t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path 'Importers', bulkrax.importers_path @importer.name, bulkrax.importer_path(@importer.id) 'Upload Corrected Entries' end |
#upload_corrected_entries_file ⇒ Object
POST /importer/1/upload_corrected_entries_file
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 171 def upload_corrected_entries_file file = params[:importer][:parser_fields].delete(:file) @importer = Importer.find(params[:importer_id]) if file.present? @importer[:parser_fields]['partial_import_file_path'] = @importer.parser.write_partial_import_file(file) @importer.save Bulkrax::ImporterJob.perform_later(@importer.id, true) redirect_to importer_path(@importer), notice: 'Corrected entries uploaded successfully.' else redirect_to importer_upload_corrected_entries_path(@importer), alert: 'Importer failed to update with new file.' end end |