Class: Bulkrax::ImportersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Bulkrax::ImportersController
- Includes:
- API, DatatablesBehavior, 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.
- #entry_table ⇒ Object
-
#export_errors ⇒ Object
GET /importers/1/export_errors.
- #external_sets ⇒ Object
- #importer_table ⇒ Object
-
#index ⇒ Object
GET /importers.
-
#new ⇒ Object
GET /importers/new.
- #original_file ⇒ Object
-
#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 DatatablesBehavior
#download_zip, #entry_table_search, #entry_util_links, #exporter_table_search, #exporter_util_links, #format_entries, #format_exporters, #format_importers, #importer_table_search, #importer_util_links, #order_value, #status_message_for, #table_order, #table_page, #table_per_page
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
164 165 166 167 168 169 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 164 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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 81 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
154 155 156 157 158 159 160 161 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 154 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
69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 69 def edit if api_request? json_response('edit') elsif defined?(::Hyrax) @importer.name, bulkrax.importer_path(@importer.id) 'Edit' end end |
#entry_table ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 49 def entry_table @entries = @importer.entries.order(table_order).page(table_page).per(table_per_page) @entries = @entries.where(entry_table_search) if entry_table_search.present? respond_to do |format| format.json { render json: format_entries(@entries, @importer) } end end |
#export_errors ⇒ Object
GET /importers/1/export_errors
213 214 215 216 217 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 213 def export_errors @importer = Importer.find(params[:importer_id]) @importer.write_errored_entries_file send_content end |
#external_sets ⇒ Object
196 197 198 199 200 201 202 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 196 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 |
#importer_table ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 30 def importer_table @importers = Importer.order(table_order).page(table_page).per(table_per_page) @importers = @importers.where(importer_table_search) if importer_table_search.present? respond_to do |format| format.json { render json: format_importers(@importers) } end end |
#index ⇒ Object
GET /importers
20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 20 def index # NOTE: We're paginating this in the browser. if api_request? @importers = Importer.order(created_at: :desc).all json_response('index') elsif defined?(::Hyrax) end end |
#new ⇒ Object
GET /importers/new
58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 58 def new @importer = Importer.new if api_request? json_response('new') elsif defined?(::Hyrax) 'New' end end |
#original_file ⇒ Object
204 205 206 207 208 209 210 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 204 def original_file if @importer.original_file? send_file @importer.original_file else redirect_to @importer, alert: 'Importer does not support file re-download or the imported file is not found on the server.' end end |
#show ⇒ Object
GET /importers/1
39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 39 def show if api_request? json_response('show') elsif defined?(::Hyrax) @importer.name end @first_entry = @importer.entries.first end |
#update ⇒ Object
PATCH/PUT /importers/1 # @todo refactor so as to not need to disable rubocop rubocop:disable all
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 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 119 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
172 173 174 175 176 177 178 179 180 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 172 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
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 183 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 |