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

create association in fileset to the file #3842

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions app/actors/hyrax/actors/file_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

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.

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
Expand All @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down
19 changes: 10 additions & 9 deletions lib/wings/hydra/works/services/add_file_node_to_file_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Copy link
Contributor Author

@elrayle elrayle Jun 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code grabbed from Hydra::Works::AddFileToFileSet #find_or_create_file_for_rdf_uri does not work. It fails to create the #original_file association which is needed in other places in Hyrax (e.g. CharacterizeJob).

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down
11 changes: 4 additions & 7 deletions lib/wings/services/file_node_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand All @@ -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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down