Skip to content

Commit

Permalink
Export all (#378)
Browse files Browse the repository at this point in the history
* working on export of all works

* initial export all logic

* do export in the background

* spec fix
  • Loading branch information
orangewolf authored Nov 21, 2021
1 parent 417ab3b commit 2d8937f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
16 changes: 12 additions & 4 deletions app/controllers/bulkrax/exporters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ def create
if @exporter.save
if params[:commit] == 'Create and Export'
# Use perform now for export
Bulkrax::ExporterJob.perform_now(@exporter.id)
Bulkrax::ExporterJob.perform_later(@exporter.id)
message = 'Exporter was successfully created. A download link will appear once it completes.'
else
message = 'Exporter was successfully created.'
end
redirect_to exporters_path, notice: 'Exporter was successfully created.'
redirect_to exporters_path, notice: message
else
render :new
end
Expand All @@ -63,8 +66,13 @@ def create
def update
field_mapping_params
if @exporter.update(exporter_params)
Bulkrax::ExporterJob.perform_now(@exporter.id) if params[:commit] == 'Update and Re-Export All Items'
redirect_to exporters_path, notice: 'Exporter was successfully updated.'
if params[:commit] == 'Update and Re-Export All Items'
Bulkrax::ExporterJob.perform_later(@exporter.id)
message = 'Exporter was successfully updated. A download link will appear once it completes.'
else
'Exporter was successfully updated.'
end
redirect_to exporters_path, notice: message
else
render :edit
end
Expand Down
1 change: 1 addition & 0 deletions app/jobs/bulkrax/exporter_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def perform(exporter_id)
exporter = Exporter.find(exporter_id)
exporter.export
exporter.write
exporter.save
true
end
end
Expand Down
7 changes: 5 additions & 2 deletions app/models/bulkrax/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Exporter < ApplicationRecord
validates :name, presence: true
validates :parser_klass, presence: true

delegate :write, :create_from_collection, :create_from_importer, :create_from_worktype, to: :parser
delegate :write, :create_from_collection, :create_from_importer, :create_from_worktype, :create_from_all, to: :parser

def export
current_run && setup_export_path
Expand All @@ -25,6 +25,8 @@ def export
create_from_importer
when 'worktype'
create_from_worktype
when 'all'
create_from_all
end
rescue StandardError => e
status_info(e)
Expand Down Expand Up @@ -77,7 +79,8 @@ def export_from_list
[
[I18n.t('bulkrax.exporter.labels.importer'), 'importer'],
[I18n.t('bulkrax.exporter.labels.collection'), 'collection'],
[I18n.t('bulkrax.exporter.labels.worktype'), 'worktype']
[I18n.t('bulkrax.exporter.labels.worktype'), 'worktype'],
[I18n.t('bulkrax.exporter.labels.all'), 'all']
]
end

Expand Down
3 changes: 3 additions & 0 deletions app/parsers/bulkrax/csv_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def extra_filters

def current_work_ids
case importerexporter.export_from
when 'all'
ActiveFedora::SolrService.query("has_model_ssim:(#{Hyrax.config.curation_concerns.join(' OR ')}) #{extra_filters}", rows: 2_147_483_647).map(&:id)
when 'collection'
ActiveFedora::SolrService.query("member_of_collection_ids_ssim:#{importerexporter.export_source + extra_filters}", rows: 2_000_000_000).map(&:id)
when 'worktype'
Expand Down Expand Up @@ -164,6 +166,7 @@ def create_new_entries
alias create_from_collection create_new_entries
alias create_from_importer create_new_entries
alias create_from_worktype create_new_entries
alias create_from_all create_new_entries

def entry_class
CsvEntry
Expand Down
3 changes: 2 additions & 1 deletion app/views/bulkrax/exporters/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
<strong><%= t('bulkrax.exporter.labels.limit') %>:</strong>
<%= @exporter.limit %>
</p>
<%= render partial: 'bulkrax/shared/bulkrax_errors', locals: {item: @exporter} %>

<%= render partial: 'bulkrax/shared/bulkrax_field_mapping', locals: {item: @exporter} %>
<%= render partial: 'bulkrax/shared/bulkrax_field_mapping', locals: {item: @exporter} %>

<%# Currently, no parser-specific fields exist on Exporter,
thus there's no real reason to always show this field %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/bulkrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ en:
importers: Importers
exporter:
labels:
all: All
collection: Collection
export_format: Export Format
export_from: Export From
Expand Down
3 changes: 2 additions & 1 deletion spec/models/bulkrax/exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module Bulkrax
[
[I18n.t('bulkrax.exporter.labels.importer'), 'importer'],
[I18n.t('bulkrax.exporter.labels.collection'), 'collection'],
[I18n.t('bulkrax.exporter.labels.worktype'), 'worktype']
[I18n.t('bulkrax.exporter.labels.worktype'), 'worktype'],
[I18n.t('bulkrax.exporter.labels.all'), 'all']
]
)
end
Expand Down

0 comments on commit 2d8937f

Please sign in to comment.