-
Notifications
You must be signed in to change notification settings - Fork 125
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
create association in fileset to the file #3842
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,10 +76,6 @@ def perform_ingest_file_through_active_fedora(io) | |
|
||
def perform_ingest_file_through_valkyrie(io) | ||
# Skip versioning because versions will be minted by VersionCommitter as necessary during save_characterize_and_record_committer. | ||
storage_adapter = Valkyrie.config.storage_adapter | ||
persister = Valkyrie.config.metadata_adapter.persister # TODO: Explore why valkyrie6 branch used indexing_persister adapter for this | ||
node_builder = Wings::FileNodeBuilder.new(storage_adapter: storage_adapter, | ||
persister: persister) | ||
unsaved_node = io.to_file_node | ||
unsaved_node.use = relation | ||
begin | ||
|
@@ -89,7 +85,16 @@ def perform_ingest_file_through_valkyrie(io) | |
return false | ||
end | ||
Hyrax::VersioningService.create(saved_node, user) | ||
saved_node | ||
pathhint = io.uploaded_file.uploader.path if io.uploaded_file # in case next worker is on same filesystem | ||
id = Hyrax.config.translate_uri_to_id.call saved_node.file_identifiers.first | ||
CharacterizeJob.perform_later(file_set, id, pathhint || io.path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perform characterization after creating the resource. |
||
end | ||
|
||
def node_builder | ||
storage_adapter = Valkyrie.config.storage_adapter | ||
persister = Valkyrie.config.metadata_adapter.persister # TODO: Explore why valkyrie6 branch used indexing_persister adapter for this | ||
Wings::FileNodeBuilder.new(storage_adapter: storage_adapter, | ||
persister: persister) | ||
end | ||
|
||
def normalize_relation(relation, use_valkyrie: false) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ def initialize(af_file_set, file_node, file, update_existing) | |
@af_file_set = af_file_set | ||
@file_node = file_node | ||
@file = file | ||
@current_file = find_or_create_file(file_node.use, update_existing) | ||
@current_file = find_or_create_file(association_type(file_node.use), update_existing) | ||
end | ||
|
||
# @param [#read] file object that will be interrogated using the methods: :path, :original_name, :original_filename, :mime_type, :content_type | ||
|
@@ -45,14 +45,15 @@ def update | |
|
||
# @param [RDF::URI] the identified use of the file (e.g. Valkyrie::Vocab::PCDMUse.OriginalFile, Valkyrie::Vocab::PCDMUse.ThumbnailImage, etc.) | ||
# @param [true, false] update_existing when true, try to retrieve existing element before building one | ||
def find_or_create_file(use, update_existing) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code grabbed from Switched to using the code from #find_or_create_file_for_symbol which requires that the URI passed in be converted to a symbol first. |
||
current_file = af_file_set.filter_files_by_type(use).first if update_existing | ||
unless current_file | ||
af_file_set.files.build | ||
current_file = af_file_set.files.last | ||
Hydra::PCDM::AddTypeToFile.call(current_file, use) | ||
end | ||
current_file | ||
def find_or_create_file(type, update_existing) | ||
association = af_file_set.association(type) | ||
raise ArgumentError, "you're attempting to add a file to a file_set using '#{type}' association but the file_set does not have an association called '#{type}''" unless association | ||
current_file = association.reader if update_existing | ||
current_file || association.build | ||
end | ||
|
||
def association_type(use) | ||
use.first.to_s.split('#').second.underscore.to_sym | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the conversion from URI to symbol which allows the original_file association to be created. |
||
end | ||
|
||
# Persist a new file with its containing file set; otherwise, just save the file itself | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ def initialize(storage_adapter:, persister:) | |
|
||
# @param io_wrapper [JobIOWrapper] with details about the uploaded file | ||
# @param node [FileNode] the metadata to represent the file | ||
# @param file_set [Valkyrie::Resouce, Hydra::Works::FileSet] the associated FileSet # TODO: Remove Hydra::Works::FileSet as a potential type when valkyrization is complete. | ||
# @param file_set [Valkyrie::Resouce, Hydra::Works::FileSet] the associated FileSet # TODO: WINGS - Remove Hydra::Works::FileSet as a potential type when valkyrization is complete. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marking TODOs as WINGS related to make them easier to find and resolve. |
||
# @return [FileNode] the persisted metadata node that represents the file | ||
def create(io_wrapper:, node:, file_set:) | ||
io_wrapper = build_file(io_wrapper, node.use) | ||
|
@@ -33,16 +33,13 @@ def create(io_wrapper:, node:, file_set:) | |
end | ||
|
||
def attach_file_node(node:, file_set:) | ||
saved_node = file_set.is_a?(::Valkyrie::Resource) ? attach_file_node_to_valkyrie_file_set(node, file_set) : node | ||
|
||
# note the returned saved_node does not yet contain the characterization done in the async job | ||
CharacterizeJob.perform_later(saved_node.file_identifiers.first.to_s) # TODO: What id is the correct one for the file? Check where this is called outside of wings. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this here. It wasn't working and is now done in the file_actor. The file_actor performs this when not working with Valkyrie, so it seems like a consistent place to do it when working with Valkyrie. |
||
saved_node | ||
file_set.is_a?(::Valkyrie::Resource) ? attach_file_node_to_valkyrie_file_set(node, file_set) : node | ||
end | ||
|
||
def attach_file_node_to_valkyrie_file_set(node, file_set) | ||
# This is for storage adapters other than wings. The wings storage adapter already attached the file to the file_set. | ||
# This process is a no-op for wings. TODO: May need to verify this is a no-op once file_set is passed in as a resource. | ||
# This process is a no-op for wings. # TODO: WINGS - May need to verify this is a no-op for wings once file_set is passed in as a resource. | ||
# TODO: WINGS - Need to test this against other adapters once they are available for use. | ||
existing_node = file_set.original_file || node | ||
node = existing_node.new(node.to_h.except(:id, :member_ids)) | ||
saved_node = persister.save(resource: node) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to separate method to make rubocop happy about the method size.