Skip to content

Commit

Permalink
Merge pull request #597 from IU-Libraries-Joint-Development/essi-875_…
Browse files Browse the repository at this point in the history
…bulkrax_upgrade

[ESSI-875] bulkrax 5 upgrade
  • Loading branch information
aploshay authored Feb 11, 2025
2 parents 933cc84 + 016ed8e commit 03a8d3a
Show file tree
Hide file tree
Showing 32 changed files with 316 additions and 636 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ gem 'allinson_flex', github: 'IU-Libraries-Joint-Development/allinson_flex'
gem 'okcomputer'

# Bulk Import / Export
gem 'bulkrax', '~> 1.0.0'
gem 'willow_sword', github: 'notch8/willow_sword', ref: '0a669d7' # deprecate willow_sword in bulkrax 5 upgrade
gem 'bulkrax', '~> 5.0'
gem 'webpacker'
gem 'react-rails'

Expand Down
22 changes: 6 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
GIT
remote: https://github.com/IU-Libraries-Joint-Development/allinson_flex.git
revision: 86ecb693044f451811a52033b643c91f9a241c3b
revision: 0fadf99b61b6567f240927e7dd54830878b315ac
specs:
allinson_flex (0.1.0)
json_schemer
rails (>= 5.1.6)
react-rails
webpacker

GIT
remote: https://github.com/notch8/willow_sword.git
revision: 0a669d78617c6003e4aa1a46a10447be92be27d5
ref: 0a669d7
specs:
willow_sword (0.2.0)
bagit (~> 0.4.1)
rails (>= 5.1.6)
rubyzip (>= 1.0.0)

GIT
remote: https://github.com/rtomayko/posix-spawn.git
revision: 0fce38ed5458b638eda5f3bb711903424a4366db
Expand Down Expand Up @@ -206,18 +196,19 @@ GEM
sprockets (~> 3.7)
typhoeus
builder (3.2.4)
bulkrax (1.0.2)
bulkrax (5.5.1)
bagit (~> 0.4)
coderay
iso8601 (~> 0.9.0)
kaminari
language_list (~> 1.2, >= 1.2.1)
libxml-ruby (~> 3.1.0)
libxml-ruby (~> 3.2.4)
loofah (>= 2.2.3)
oai (>= 0.4, < 2.x)
rack (>= 2.0.6)
rails (>= 5.1.6)
rdf (>= 2.0.2, < 4.0)
rubyzip
simple_form
byebug (11.1.3)
cancancan (1.17.0)
Expand Down Expand Up @@ -637,7 +628,7 @@ GEM
rdf (~> 3.0)
legato (0.7.0)
multi_json
libxml-ruby (3.1.0)
libxml-ruby (3.2.4)
link_header (0.0.8)
linkeddata (3.1.1)
equivalent-xml (~> 0.6)
Expand Down Expand Up @@ -1119,7 +1110,7 @@ DEPENDENCIES
bixby
blacklight_iiif_search
browse-everything (= 1.1.0)
bulkrax (~> 1.0.0)
bulkrax (~> 5.0)
byebug
capybara
capybara-screenshot (~> 1.0)
Expand Down Expand Up @@ -1178,7 +1169,6 @@ DEPENDENCIES
webdrivers
webmock
webpacker
willow_sword!

BUNDLED WITH
2.4.22
5 changes: 5 additions & 0 deletions app/assets/stylesheets/brand_tweaks.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ html {
height: 1rem !important;
width: 1rem !important;
}

/* cherry-picked from bootstrap, for bulkrax 5 implicit requirement */
.d-none {
display: none !important;
}
76 changes: 76 additions & 0 deletions app/jobs/bulkrax/import_file_set_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# frozen_string_literal: true
# @todo drop this direct import after upgrading to bulkrax commit 0de8ee06 or later

module Bulkrax
class MissingParentError < ::StandardError; end

class ImportFileSetJob < ApplicationJob
include DynamicRecordLookup

queue_as Bulkrax.config.ingest_queue_name

attr_reader :importer_run_id

def perform(entry_id, importer_run_id)
@importer_run_id = importer_run_id
entry = Entry.find(entry_id)
# e.g. "parents" or "parents_1"
parent_identifier = (entry.raw_metadata[entry.related_parents_raw_mapping] || entry.raw_metadata["#{entry.related_parents_raw_mapping}_1"])&.strip

begin
validate_parent!(parent_identifier)
rescue MissingParentError => e
handle_retry(entry, importer_run_id, e)
return
end

entry.build
if entry.succeeded?
# rubocop:disable Rails/SkipsModelValidations
ImporterRun.increment_counter(:processed_records, importer_run_id)
ImporterRun.increment_counter(:processed_file_sets, importer_run_id)
else
ImporterRun.increment_counter(:failed_records, importer_run_id)
ImporterRun.increment_counter(:failed_file_sets, importer_run_id)
# rubocop:enable Rails/SkipsModelValidations
end
ImporterRun.decrement_counter(:enqueued_records, importer_run_id) unless ImporterRun.find(importer_run_id).enqueued_records <= 0 # rubocop:disable Rails/SkipsModelValidations
entry.save!
entry.importer.current_run = ImporterRun.find(importer_run_id)
entry.importer.record_status
end

private

attr_reader :parent_record

def validate_parent!(parent_identifier)
# if parent_identifier is missing, it will be caught by #validate_presence_of_parent!
return if parent_identifier.blank?

find_parent_record(parent_identifier)
check_parent_is_a_work!(parent_identifier)
end

def check_parent_is_a_work!(parent_identifier)
error_msg = %(A record with the ID "#{parent_identifier}" was found, but it was a #{parent_record.class}, which is not an valid/available work type)
raise ::StandardError, error_msg unless curation_concern?(parent_record)
end

def find_parent_record(parent_identifier)
_, @parent_record = find_record(parent_identifier, importer_run_id)
raise MissingParentError, %(Unable to find a record with the identifier "#{parent_identifier}") unless parent_record
end

def handle_retry(entry, importer_run_id, e)
entry.import_attempts += 1
entry.save!
if entry.import_attempts < 5
ImportFileSetJob.set(wait: (entry.import_attempts + 1).minutes).perform_later(entry.id, importer_run_id)
else
ImporterRun.decrement_counter(:enqueued_records, importer_run_id) # rubocop:disable Rails/SkipsModelValidations
entry.set_status_info(e)
end
end
end
end
21 changes: 21 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ def custom_permissions
end
end

# bulkrax import
def can_import_works?
can_create_any_work?
end

# bulkrax export
def can_export_works?
current_user.admin? || can_manage_works?
end

def can_manage_works?
@can_manage_works ||= begin
managing_role = Sipity::Role.find_by(name: Hyrax::RoleRegistry::MANAGING)
return false unless managing_role
Hyrax::Workflow::PermissionQuery.scope_processing_agents_for(user: current_user).any? do |agent|
agent.workflow_responsibilities.joins(:workflow_role)
.where('sipity_workflow_roles.role_id' => managing_role.id).any?
end
end
end

# Modified method from blacklight-access_controls Blacklight::AccessControls::Ability
# Grants registered status for authenticated visibility ("Institution") by ldap group membership, if so configured, and admins
def user_groups
Expand Down
4 changes: 4 additions & 0 deletions app/parsers/bulkrax/mets_xml_parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# @todo update for bulkrax 5+, where XML import isn't fully supported; currently broken
module Bulkrax
class MetsXmlParser < ApplicationParser
def entry_class
Expand All @@ -15,6 +16,9 @@ def create_collections; end
# @todo not yet supported
def import_fields; end

# @todo not yet supported
def file_set_entry_class; end

def valid_import?
raise StandardError, 'No metadata files found' if metadata_paths.blank?
raise StandardError, 'No records found' if records.blank?
Expand Down
124 changes: 0 additions & 124 deletions app/views/bulkrax/exporters/_form.html.erb

This file was deleted.

Loading

0 comments on commit 03a8d3a

Please sign in to comment.