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 20, 2019
1 parent 293a62b commit a0166e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions app/actors/hyrax/actors/file_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def perform_ingest_file_through_valkyrie(io)
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 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)
fail 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

0 comments on commit a0166e8

Please sign in to comment.