From 8254ccb3aa0621fa74e972baaed199e824bba947 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Thu, 20 Jun 2019 14:53:17 -0400 Subject: [PATCH] create association in fileset to the file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes some of the remaining issue for PR #3814. Specifically… * image is viewable on the work show page * thumbnail is shown in dashboard -> works * file will now download * characterization job completes Still need to write tests --- app/actors/hyrax/actors/file_actor.rb | 15 ++++++++++----- .../services/add_file_node_to_file_set.rb | 19 ++++++++++--------- lib/wings/services/file_node_builder.rb | 11 ++++------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/app/actors/hyrax/actors/file_actor.rb b/app/actors/hyrax/actors/file_actor.rb index 81b08ac1ca..138e16a953 100644 --- a/app/actors/hyrax/actors/file_actor.rb +++ b/app/actors/hyrax/actors/file_actor.rb @@ -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) + 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) diff --git a/lib/wings/hydra/works/services/add_file_node_to_file_set.rb b/lib/wings/hydra/works/services/add_file_node_to_file_set.rb index 1c674fe953..80728afb42 100644 --- a/lib/wings/hydra/works/services/add_file_node_to_file_set.rb +++ b/lib/wings/hydra/works/services/add_file_node_to_file_set.rb @@ -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) - 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 end # Persist a new file with its containing file set; otherwise, just save the file itself diff --git a/lib/wings/services/file_node_builder.rb b/lib/wings/services/file_node_builder.rb index f15cc372c2..4cb07cd7f3 100644 --- a/lib/wings/services/file_node_builder.rb +++ b/lib/wings/services/file_node_builder.rb @@ -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. # @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. - 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)