Skip to content

Commit

Permalink
Select existing entries for update (#924)
Browse files Browse the repository at this point in the history
* We may want to rebuild entries without getting a new file, this allows for that

* call the cops
  • Loading branch information
orangewolf authored Feb 9, 2024
1 parent b9f8fcd commit 8f5c0e4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
16 changes: 15 additions & 1 deletion app/assets/javascripts/bulkrax/importers.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ function handleFileToggle(file_path) {
$('#file_path').hide()
$('#file_upload').hide()
$('#cloud').hide()
$('#existing_options').hide()
$('#file_path input').attr('required', null)
$('#file_upload input').attr('required', null)
} else {
$('#file_path').show()
$('#file_upload').hide()
$('#cloud').hide()
$('#existing_options').hide()
$('#file_path input').attr('required', 'required')
$('#file_upload input').attr('required', null)
$('#importer_parser_fields_file_style_specify_a_path_on_the_server').attr('checked', true)
Expand All @@ -89,23 +91,35 @@ function handleFileToggle(file_path) {
$('#file_path').hide()
$('#file_upload').show()
$('#cloud').hide()
$('#existing_options').hide()
$('#file_path input').attr('required', null)
$('#file_upload input').attr('required', 'required')
})
$('#importer_parser_fields_file_style_specify_a_path_on_the_server').click(function(e){
$('#file_path').show()
$('#file_upload').hide()
$('#cloud').hide()
$('#existing_options').hide()
$('#file_path input').attr('required', 'required')
$('#file_upload input').attr('required', null)
})
$('#importer_parser_fields_file_style_add_cloud_file').click(function(e){
$('#file_path').hide()
$('#file_upload').hide()
$('#cloud').show()
$('#existing_options').hide()
$('#file_path input').attr('required', null)
$('#file_upload input').attr('required', null)
})
$('#importer_parser_fields_file_style_existing_entries').click(function(e){
$('#file_path').hide()
$('#file_upload').hide()
$('#cloud').hide()
$('#existing_options').show()
$('#file_path input').attr('required', null)
$('#file_upload input').attr('required', null)
})

}

function handleParserKlass() {
Expand Down Expand Up @@ -189,4 +203,4 @@ function setError(selector, error) {
selector.attr('disabled', true)
}

$(document).on({'ready': prepBulkrax, 'turbolinks:load': prepBulkrax})
$(document).on({'ready': prepBulkrax, 'turbolinks:load': prepBulkrax})
7 changes: 6 additions & 1 deletion app/assets/stylesheets/bulkrax/import_export.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ div#s2id_exporter_export_source_collection {

.bulkrax-clear-toggles {
clear: both;
}
}

#existing_options .collection_check_boxes {
margin-left: 10px;
margin-right: 10px;
}
2 changes: 1 addition & 1 deletion app/controllers/bulkrax/importers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def importable_params
end

def importable_parser_fields
params&.[](:importer)&.[](:parser_fields)&.except(:file)&.keys
params&.[](:importer)&.[](:parser_fields)&.except(:file, :entry_statuses)&.keys&. + [{ "entry_statuses" => [] }]
end

# Only allow a trusted parameters through.
Expand Down
6 changes: 5 additions & 1 deletion app/models/bulkrax/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def metadata_only?
parser.parser_fields['metadata_only'] == true
end

def existing_entries?
parser.parser_fields['file_style']&.match(/Existing Entries/)
end

def import_works
import_objects(['work'])
end
Expand All @@ -189,7 +193,7 @@ def import_objects(types_array = nil)
self.only_updates ||= false
self.save if self.new_record? # Object needs to be saved for statuses
types = types_array || DEFAULT_OBJECT_TYPES
parser.create_objects(types)
existing_entries? ? parser.rebuild_entries(types) : parser.create_objects(types)
mark_unseen_as_skipped
rescue StandardError => e
set_status_info(e)
Expand Down
14 changes: 14 additions & 0 deletions app/parsers/bulkrax/application_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ def create_objects(types_array = nil)
set_status_info(e)
end

def rebuild_entries(_types_array = nil)
index = 0
importer.entries.where(status_message: parser_fields['entry_statuses']).find_each do |e|
seen[e.identifier] = true
if remove_and_rerun
"Bulkrax::DeleteAndImport#{type.camelize}Job".constantize.send(perform_method, e, current_run)
else
"Bulkrax::Import#{type.camelize}Job".constantize.send(perform_method, e.id, current_run.id)
end
increment_counters(index)
index += 1
end
end

def create_entry_and_job(current_record, type, identifier = nil)
identifier ||= current_record[source_identifier]
new_entry = find_or_create_entry(send("#{type}_entry_class"),
Expand Down
6 changes: 5 additions & 1 deletion app/views/bulkrax/importers/_csv_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
<h4>Add CSV File to Import:</h4>
<%# accept a single file upload; data files and bags will need to be added another way %>

<%= fi.input :file_style, collection: ['Upload a File', 'Specify a Path on the Server'], as: :radio_buttons, label: false %>
<%= fi.input :file_style, collection: ['Upload a File', 'Specify a Path on the Server', 'Existing Entries'], as: :radio_buttons, label: false %>
<div id='file_upload'>
<%= fi.input 'file', as: :file, input_html: { accept: 'text/csv,application/zip' } %><br />
</div>
<div id='file_path'>
<%= fi.input :import_file_path, as: :string, input_html: { value: importer.parser_fields['import_file_path'] } %>
</div>
<div id='existing_options'>
<%= fi.collection_check_boxes :entry_statuses, [['Failed'], ['Pending'], ['Skipped'], ['Deleted'], ['Complete']], :first, :first %>
</div>

<% if defined?(::Hyrax) && Hyrax.config.browse_everything? %>
<h4>Add Files to Import:</h4>
<p>Choose files to upload. The filenames must be unique, and the filenames must be referenced in a column called 'file' in the accompanying CSV file.</p>
Expand Down

0 comments on commit 8f5c0e4

Please sign in to comment.