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 rubocop:disable Metrics/AbcSize.
-
#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
-
#sample_csv_file ⇒ Object
POST /importers/sample_csv_file.
-
#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
176 177 178 179 180 181 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 176 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 rubocop:disable Metrics/AbcSize
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 91 def create # rubocop:disable Style/IfInsideElse if api_request? return return_json_response unless valid_create_params? end uploads = Hyrax::UploadedFile.find(params[:uploaded_files]) if params[:uploaded_files].present? 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, uploads) 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
166 167 168 169 170 171 172 173 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 166 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
78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 78 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
225 226 227 228 229 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 225 def export_errors @importer = Importer.find(params[:importer_id]) @importer.write_errored_entries_file send_content end |
#external_sets ⇒ Object
208 209 210 211 212 213 214 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 208 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
216 217 218 219 220 221 222 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 216 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 |
#sample_csv_file ⇒ Object
POST /importers/sample_csv_file
69 70 71 72 73 74 75 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 69 def sample_csv_file sample = Bulkrax::SampleCsvService.call(model_name: 'all', output: 'file') send_file sample, filename: File.basename(sample), type: 'text/csv' rescue StandardError => e flash[:error] = "Unable to generate sample CSV file: #{e.}" redirect_back fallback_location: bulkrax.importers_path 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
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 131 def update if api_request? return return_json_response unless valid_update_params? end uploads = Hyrax::UploadedFile.find(params[:uploaded_files]) if params[:uploaded_files].present? 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, uploads) # 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
184 185 186 187 188 189 190 191 192 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 184 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
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'app/controllers/bulkrax/importers_controller.rb', line 195 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 |