Skip to content

Commit

Permalink
Retry and delete take 2 (#894)
Browse files Browse the repository at this point in the history
* working single item retry, delete and retry, and just delete

* remove all entries and works and then rebuild them

* call the cops
  • Loading branch information
orangewolf authored Jan 19, 2024
1 parent 1f2cd7d commit 3ae6402
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 110 deletions.
11 changes: 11 additions & 0 deletions app/assets/javascripts/bulkrax/bulkrax.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@ $(document).on('turbolinks:load ready', function() {
$('button#fm_toggle').click(function() {
$('#field_mapping').toggle();
});
$('#bulkraxItemModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('entry-id') // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('a').each(function() {
this.href = this.href.replace(/\d+\?/, recipient + '?')
})
return true
})
});
39 changes: 36 additions & 3 deletions app/controllers/bulkrax/entries_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require_dependency "bulkrax/application_controller"
require_dependency "oai"

module Bulkrax
class EntriesController < ApplicationController
include Hyrax::ThemedLayoutController if defined?(::Hyrax)
Expand All @@ -18,6 +15,42 @@ def show
end
end

def update
@entry = Entry.find(params[:id])
@entry.factory&.find&.destroy if params[:destroy_first]
@entry.build
@entry.save
item = @entry.importerexporter
entry_path = item.class.to_s.include?('Importer') ? bulkrax.importer_entry_path(item.id, @entry.id) : bulkrax.exporter_entry_path(item.id, @entry.id)

redirect_back fallback_location: entry_path, notice: "Entry update ran, new status is #{@entry.status}"
end

def destroy
@entry = Entry.find(params[:id])
@status = ""
begin
work = @entry.factory&.find
if work.present?
work.destroy
@entry.destroy
@status = "Entry and work deleted"
else
@entry.destroy
@status = "Entry deleted"
end
rescue StandardError => e
@status = "Error: #{e.message}"
end

item = @entry.importerexporter
entry_path = item.class.to_s.include?('Importer') ? bulkrax.importer_entry_path(item.id, @entry.id) : bulkrax.exporter_entry_path(item.id, @entry.id)

redirect_back fallback_location: entry_path, notice: @status
end

protected

# GET /importers/1/entries/1
def show_importer
@importer = Importer.find(params[:importer_id])
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/bulkrax/exporters_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_dependency "bulkrax/application_controller"

module Bulkrax
class ExportersController < ApplicationController
include Hyrax::ThemedLayoutController if defined?(::Hyrax)
Expand Down
11 changes: 7 additions & 4 deletions app/controllers/bulkrax/importers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# frozen_string_literal: true

require_dependency 'bulkrax/application_controller'
require_dependency 'oai'

module Bulkrax
# rubocop:disable Metrics/ClassLength
class ImportersController < ApplicationController
class ImportersController < ::Bulkrax::ApplicationController
include Hyrax::ThemedLayoutController if defined?(::Hyrax)
include Bulkrax::DownloadBehavior
include Bulkrax::API
Expand Down Expand Up @@ -310,10 +307,16 @@ def update_harvest
end

def set_files_parser_fields
@importer.parser_fields['update_files'] =
@importer.parser_fields['replace_files'] =
@importer.parser_fields['remove_and_rerun'] =
@importer.parser_fields['metadata_only'] = false
if params[:commit] == 'Update Metadata and Files'
@importer.parser_fields['update_files'] = true
elsif params[:commit] == ('Update and Replace Files' || 'Update and Re-Harvest All Items')
@importer.parser_fields['replace_files'] = true
elsif params[:commit] == 'Remove and Rerun'
@importer.parser_fields['remove_and_rerun'] = true
elsif params[:commit] == 'Update and Harvest Updated Items'
return
else
Expand Down
10 changes: 7 additions & 3 deletions app/helpers/bulkrax/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# frozen_string_literal: true
require 'coderay'

module Bulkrax
module ApplicationHelper
include ::Hyrax::HyraxHelperBehavior if defined?(::Hyrax)
def item_entry_path(item, e, opts = {})
an_importer?(item) ? bulkrax.importer_entry_path(item.id, e.id, opts) : bulkrax.exporter_entry_path(item.id, e.id, opts)
end

def an_importer?(item)
item.class.to_s.include?('Importer')
end

def coderay(value, opts)
CodeRay
Expand Down
20 changes: 15 additions & 5 deletions app/models/bulkrax/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'iso8601'

module Bulkrax
class Importer < ApplicationRecord
class Importer < ApplicationRecord # rubocop:disable Metrics/ClassLength
include Bulkrax::ImporterExporterBehavior
include Bulkrax::StatusInfo

Expand Down Expand Up @@ -135,6 +135,14 @@ def update_files
self.parser_fields['update_files']
end

def remove_and_rerun
self.parser_fields['remove_and_rerun']
end

def metadata_only?
parser.parser_fields['metadata_only'] == true
end

def import_works
import_objects(['work'])
end
Expand All @@ -157,6 +165,12 @@ 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
if remove_and_rerun
self.entries.find_each do |e|
e.factory.find&.destroy!
e.destroy!
end
end
parser.create_objects(types)
rescue StandardError => e
set_status_info(e)
Expand Down Expand Up @@ -192,9 +206,5 @@ def path_string
rescue
"#{self.id}_#{self.created_at.strftime('%Y%m%d%H%M%S')}"
end

def metadata_only?
parser.parser_fields['metadata_only'] == true
end
end
end
7 changes: 4 additions & 3 deletions app/views/bulkrax/exporters/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@
</ul>
<!-- Tab panes -->
<div class="tab-content outline">
<%= render partial: 'bulkrax/shared/work_entries_tab', locals: { item: @exporter, entries: @work_entries } %>
<%= render partial: 'bulkrax/shared/collection_entries_tab', locals: { item: @exporter, entries: @collection_entries } %>
<%= render partial: 'bulkrax/shared/file_set_entries_tab', locals: { item: @exporter, entries: @file_set_entries } %>
<%= render partial: 'bulkrax/shared/entries_tab', locals: { item: @exporter, entries: @work_entries, pagination_param_name: :work_entries_page, pagination_anchor: 'work-entries' } %>
<%= render partial: 'bulkrax/shared/entries_tab', locals: { item: @exporter, entries: @collection_entries, pagination_param_name: :collection_entries_path, pagination_anchor: 'collection-entries' } %>
<%= render partial: 'bulkrax/shared/entries_tab', locals: { item: @exporter, entries: @file_set_entries, pagination_param_name: :file_set_entries_path, pagination_anchor: 'file-set-entries' } %>
</div>

<br>
<%= link_to 'Edit', edit_exporter_path(@exporter) %>
|
Expand Down
9 changes: 8 additions & 1 deletion app/views/bulkrax/importers/_edit_form_buttons.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@
<%= form.button :submit,
value: 'Update and Replace Files',
class: 'btn btn-primary',
data: {confirm: "Are you sure? This will remove all files before adding them from the import."} %>
data: {confirm: "Are you sure? This will remove all files before adding them from the import."} %>
<hr />
<p>Remove all works and then run the import again from a clean slate. This will remove all files and associations and any edits made since the last import will be lost.</p>
<%= form.button :submit,
value: 'Remove and Rerun',
class: 'btn btn-primary',
data: {confirm: "Are you sure? This will delete all the works and any associated files and relationships before re running."} %>

<% end %>
<hr />

Expand Down
18 changes: 18 additions & 0 deletions app/views/bulkrax/importers/_edit_item_buttons.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="modal fade" id="bulkraxItemModal" tabindex="-1" role="dialog" aria-labelledby="bulkraxItemModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<h5>Options for Updating an Entry</h5>
<hr />
<p>Rebuild metadata and files.</p>
<%= link_to 'Build', item_entry_path(item, e), method: :patch, class: 'btn btn-primary' %>
<hr />
<p>Remove existing work and then recreate the works metadata and files.</p>
<%= link_to 'Remove and then Build', item_entry_path(item, e, destroy_first: true), method: :patch, class: 'btn btn-primary' %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t('helpers.action.cancel') %></button>
</div>
</div>
</div>
</div>
8 changes: 5 additions & 3 deletions app/views/bulkrax/importers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@
</ul>
<!-- Tab panes -->
<div class="tab-content outline">
<%= render partial: 'bulkrax/shared/work_entries_tab', locals: { item: @importer, entries: @work_entries } %>
<%= render partial: 'bulkrax/shared/collection_entries_tab', locals: { item: @importer, entries: @collection_entries } %>
<%= render partial: 'bulkrax/shared/file_set_entries_tab', locals: { item: @importer, entries: @file_set_entries } %>
<%= render partial: 'bulkrax/shared/entries_tab', locals: { item: @importer, entries: @work_entries, pagination_param_name: :work_entries_page, pagination_anchor: 'work-entries' } %>
<%= render partial: 'bulkrax/shared/entries_tab', locals: { item: @importer, entries: @collection_entries, pagination_param_name: :collection_entries_path, pagination_anchor: 'collection-entries' } %>
<%= render partial: 'bulkrax/shared/entries_tab', locals: { item: @importer, entries: @file_set_entries, pagination_param_name: :file_set_entries_path, pagination_anchor: 'file-set-entries' } %>
</div>
<% all_entries = @work_entries + @collection_entries + @file_set_entries %>
<%= render partial: 'bulkrax/importers/edit_item_buttons', locals: { item: @importer, e: all_entries.first } if all_entries.present? %>
</div>

<p class="bulkrax-p-align">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div role="tabpanel" class="tab-pane bulkrax-nav-tab-table-left-align" id="collection-entries">
<div role="tabpanel" class="tab-pane bulkrax-nav-tab-table-left-align <%= pagination_anchor == 'work-entries' ? 'active' : '' %>" id="<%= pagination_anchor %>">
<table class='table table-striped'>
<thead>
<tr>
Expand All @@ -12,9 +12,8 @@
</thead>
<tbody>
<% entries.each do |e| %>
<% entry_path = item.class.to_s.include?('Importer') ? bulkrax.importer_entry_path(item.id, e.id) : bulkrax.exporter_entry_path(item.id, e.id) %>
<tr>
<td><%= link_to e.identifier, entry_path %></td>
<td><%= link_to e.identifier, item_entry_path(item, e) %></td>
<td><%= e.id %></td>
<% if e.status == "Complete" %>
<td><span class="glyphicon glyphicon-ok" style="color: green;"></span> <%= e.status %></td>
Expand All @@ -24,16 +23,22 @@
<td><span class="glyphicon glyphicon-remove" style="color: <%= e.status == 'Deleted' ? 'green' : 'red' %>;"></span> <%= e.status %></td>
<% end %>
<% if e.last_error.present? %>
<td><%= link_to e.last_error.dig("error_class"), entry_path %></td>
<td><%= link_to e.last_error.dig("error_class"), item_entry_path(item, e) %></td>
<% else %>
<td></td>
<% end %>
<td><%= e.status_at %></td>
<td><%= link_to raw('<span class="glyphicon glyphicon-info-sign"></span>'), entry_path %></td>
<td>
<%= link_to raw('<span class="glyphicon glyphicon-info-sign"></span>'), item_entry_path(item, e) %>
<% if an_importer?(item) %>
<a class="glyphicon glyphicon-refresh" data-toggle="modal" data-target="#bulkraxItemModal" data-entry-id="<%= e.id %>"></a>
<% end %>
<%= link_to raw('<span class="glyphicon glyphicon-trash"></span>'), item_entry_path(item, e), method: :delete, data: { confirm: 'This will delete the entry and any work associated with it. Are you sure?' } %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= page_entries_info(entries) %><br />
<%= paginate(entries, theme: 'blacklight', param_name: :collections_entries_page, params: { anchor: 'collection-entries' }) %>
<%= paginate(entries, theme: 'blacklight', param_name: pagination_param_name, params: { anchor: pagination_anchor }) %>
</div>
39 changes: 0 additions & 39 deletions app/views/bulkrax/shared/_file_set_entries_tab.html.erb

This file was deleted.

39 changes: 0 additions & 39 deletions app/views/bulkrax/shared/_work_entries_tab.html.erb

This file was deleted.

4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Bulkrax::Engine.routes.draw do
resources :exporters do
get :download
resources :entries, only: %i[show]
resources :entries, only: %i[show update destroy]
end
resources :importers do
put :continue
get :export_errors
collection do
post :external_sets
end
resources :entries, only: %i[show]
resources :entries, only: %i[show update destroy]
get :upload_corrected_entries
post :upload_corrected_entries_file
end
Expand Down
2 changes: 2 additions & 0 deletions spec/test_app/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true

module ApplicationHelper
include ::Hyrax::HyraxHelperBehavior if defined?(::Hyrax)

end

0 comments on commit 3ae6402

Please sign in to comment.