Skip to content

Commit

Permalink
create association in fileset to the file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
elrayle committed Jun 21, 2019
1 parent 7a7e3f8 commit 8254ccb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
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
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)
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)
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
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.
# @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.
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

0 comments on commit 8254ccb

Please sign in to comment.