Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESSI-875] bulkrax 5 upgrade #597

Merged
merged 29 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2c7acd8
[ESSI-875] bulkrax upgrade to 5.5.1
aploshay Dec 20, 2023
4510bae
[ESSI-875] update db schema with new bulkrax migrations
aploshay Jan 11, 2024
fd99c60
[ESSI-875] add parent, child mapping
aploshay May 30, 2024
bcae3d5
[ESSI-875] bulkrax extensions: deprecate user permission template bugfix
aploshay Dec 20, 2023
bfc9781
[ESSI-875] bulkrax extensions: deprecate round-tripping patches
aploshay Dec 21, 2023
4a10e58
[ESSI-875] bulkrax extensions: deprecate homebrewed support for files…
aploshay Dec 21, 2023
d00f077
[ESSI-875] bulkrax extensions: comment and regroup
aploshay Dec 22, 2023
8854af3
[ESSI-875] bulkrax extensions: deprecate #add_work_type for #establis…
aploshay Jan 11, 2024
f9db580
[ESSI-875] bulkrax extensions: prepare dynamic schema patch update to…
aploshay Jan 11, 2024
b3fa315
[ESSI-875] bulkrax extensions: update dynamic schema patch for 5.x
aploshay Jan 11, 2024
4d204d1
[ESSI-875] bulkrax extensions: deprecate collection association bugfix
aploshay Jan 11, 2024
e3a6541
[ESSI-875] bulkrax extensions: deprecate identifier_hash bugfix
aploshay Jan 11, 2024
8470f62
[ESSI-875] temporarily skip failing MetsXmlEntry specs
aploshay Jan 12, 2024
cc8526a
[ESSI-875] update CSV import fixture, temporarily skip feature spec test
aploshay Jan 12, 2024
47db67a
[ESSI-875] explicitly set bulkrax ingest queue to match hyrax
aploshay May 30, 2024
e280a1f
[ESSI-875] import ImportFileSetJob from bulkrax 5.5.1
aploshay May 30, 2024
b485c3a
[ESSI-875] cherry-pick ImportFileSetJob retry logic from 0de8ee06
aploshay May 30, 2024
9936b92
[ESSI-875] note broken METS, XML importer options in UI
aploshay Sep 4, 2024
0184a72
[ESSI-857] [ESSI-2050] restrict export to admins and managers, only
aploshay Jan 10, 2025
5d86561
[ESSI-857] [ESSI-2050] prep monkeypatch for disabling files export
aploshay Jan 10, 2025
39626a8
[ESSI-857] [ESSI-2050] monkeypatch to disable files export
aploshay Jan 10, 2025
62671eb
[ESSI-875] [ESSI-2057] add bootstrap d-none css class for export form
aploshay Jan 14, 2025
e8df85f
[ESSI-875] [ESSI-2057] prepare #export_from_list monkeypatch
aploshay Jan 14, 2025
982b13a
[ESSI-875] [ESSI-2057] monkeypatch #export_from_list, restrict to Col…
aploshay Jan 14, 2025
286a825
[ESSI-875] [ESSI-2052] prepare monkeypatch for importing nil single v…
aploshay Jan 22, 2025
76b03cd
[ESSI-875] [ESSI-2052] apply monkeypatch for correctly importing nil …
aploshay Jan 22, 2025
2d540a1
[ESSI-875] [ESSI-2052] prepare monkeypatch for title_1 import bug
aploshay Jan 23, 2025
0625d25
[ESSI-875] [ESSI-2052] apply monkeypatch for title_1 import bug
aploshay Jan 23, 2025
016ed8e
[ESSI-875] drop willow_sword gem
aploshay Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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