-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When moab not found on disk, looks for it. If found, updates catalog.
closes #1139
- Loading branch information
1 parent
d87a8ac
commit e7fef50
Showing
10 changed files
with
352 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# Service for handling a Moab that has moved | ||
class MoabMovedHandler | ||
attr_reader :complete_moab, :results | ||
|
||
def initialize(complete_moab, results) | ||
@complete_moab = complete_moab | ||
@results = results | ||
end | ||
|
||
def check_and_handle_moved_moab | ||
update_moab_storage_root if moved_moab.exist? | ||
end | ||
|
||
private | ||
|
||
def moved_moab | ||
@moved_moab ||= Moab::StorageServices.find_storage_object(complete_moab.preserved_object.druid) | ||
end | ||
|
||
def validation_errors? | ||
object_validator = Stanford::StorageObjectValidator.new(moved_moab) | ||
object_validator.validation_errors(Settings.moab.allow_content_subdirs).any? | ||
end | ||
|
||
def storage_root | ||
@storage_root ||= MoabStorageRoot.find_by!(storage_location: File.join(moved_moab.storage_root.to_path, Settings.moab.storage_trunk)) | ||
end | ||
|
||
def update_status_ok | ||
complete_moab.status = 'ok' | ||
return unless complete_moab.status_changed? | ||
|
||
results.add_result( | ||
AuditResults::CM_STATUS_CHANGED, old_status: complete_moab.status_was, new_status: complete_moab.status | ||
) | ||
end | ||
|
||
def update_storage_root | ||
old_storage_root = complete_moab.moab_storage_root | ||
complete_moab.moab_storage_root = storage_root | ||
results.add_result( | ||
AuditResults::CM_STORAGE_ROOT_CHANGED, old_storage_root: old_storage_root.storage_location, | ||
new_storage_root: complete_moab.moab_storage_root.storage_location | ||
) | ||
end | ||
|
||
def update_moab_storage_root | ||
version = nil | ||
transaction_ok = ActiveRecordUtils.with_transaction_and_rescue(results) do | ||
version = complete_moab.version | ||
end | ||
results.remove_db_updated_results unless transaction_ok | ||
# Ensures Moab at the current location matches the catalog in all ways (e.g. version, full validation) except for disk location | ||
return if moved_moab.current_version_id != version | ||
return if validation_errors? | ||
|
||
# Update the disk location in the catalog | ||
transaction_ok = ActiveRecordUtils.with_transaction_and_rescue(results) do | ||
update_storage_root | ||
update_status_ok | ||
complete_moab.save! | ||
end | ||
results.remove_db_updated_results unless transaction_ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.