Skip to content

Commit

Permalink
Valkyrie Fedora metadata/storage adapter compatibility (#6329)
Browse files Browse the repository at this point in the history
* Use StreamFile#disk_path instead of io directly

The Fedora storage adapter sets io to be an IOProxy which basename cannot make use of.

* Do not use shovel operator << when setting ids

The Fedora metadata adapter provides frozen empty arrays as default values. It is unknown why the Postgres adapter defaults are unfrozen.

* Patch File to workaround samvera/valkyrie#936

* Add config for valkyrie fedora faraday connection

* Rubocop
  • Loading branch information
dlpierce authored Sep 26, 2023
1 parent 50cc8f0 commit 1c4060d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/hyrax/file_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.FileMetadata(file)
"with id #{file.id}. Initializing a new one")

FileMetadata.new(file_identifier: file.id,
original_filename: File.basename(file.io))
original_filename: File.basename(file.disk_path))
end

class FileMetadata < Valkyrie::Resource
Expand Down
2 changes: 1 addition & 1 deletion app/models/hyrax/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Hyrax
# `it_behaves_like 'has_members'`. Shared specs are defined in /lib/hyrax/specs/shared_specs/hydra_works.rb.
# * Work to File Set: (0..m) A work can have many file sets.
# @example Add a file set to a work (code from Hyrax::WorkUploadsHandler#append_to_work)
# work.member_ids << file_set.id
# work.member_ids += [file_set.id]
# work.representative_id = file_set.id if work.respond_to?(:representative_id) && work.representative_id.blank?
# work.thumbnail_id = file_set.id if work.respond_to?(:thumbnail_id) && work.thumbnail_id.blank?
# Hyrax.persister.save(resource: work)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def add_member_by_id(collection_id:, new_member_id:, user:)
def add_member(collection_id:, new_member:, user:)
message = Hyrax::MultipleMembershipChecker.new(item: new_member).check(collection_ids: [collection_id], include_current_members: true)
raise Hyrax::SingleMembershipError, message if message.present?
new_member.member_of_collection_ids << collection_id # only populate this direction
new_member.member_of_collection_ids += [collection_id] # only populate this direction
new_member = Hyrax.persister.save(resource: new_member)
publish_metadata_updated(new_member, user)
new_member
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/valkyrie_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def version_upload(file_set:, io:, user:)
#
# @return [Hyrax::FileSet] updated file set
def add_file_to_file_set(file_set:, file_metadata:, user:)
file_set.file_ids << file_metadata.id
file_set.file_ids += [file_metadata.id]
Hyrax.persister.save(resource: file_set)
Hyrax.publisher.publish('object.membership.updated', object: file_set, user: user)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/work_uploads_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def make_file_set_and_ingest(file)
#
# @todo figure out how to know less about Work's ideas about FileSet use here. Maybe post-Wings, work.
def append_to_work(file_set)
work.member_ids << file_set.id
work.member_ids += [file_set.id]
work.representative_id = file_set.id if work.respond_to?(:representative_id) && work.representative_id.blank?
work.thumbnail_id = file_set.id if work.respond_to?(:thumbnail_id) && work.thumbnail_id.blank?
end
Expand Down
2 changes: 1 addition & 1 deletion app/validators/hyrax/collection_membership_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def collections_ids(record)
record.member_of_collections_attributes
.each do |_k, h|
next if h["_destroy"] == "true"
collection_ids << Valkyrie::ID.new(h["id"])
collection_ids += [Valkyrie::ID.new(h["id"])]
end
end

Expand Down
6 changes: 6 additions & 0 deletions config/initializers/file_length_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# Valkyrie::Storage::Fedora expects io objects to have #length
class ::File
alias length size unless ::File.respond_to? :length
end
14 changes: 14 additions & 0 deletions lib/hyrax/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,20 @@ def derivatives_storage_adapter=(adapter)
@derivatives_storage_adapter = Valkyrie::StorageAdapter.find(adapter.to_sym)
end

# A HTTP connection to use for Valkyrie Fedora requests
#
# @return [#call] lambda/proc that generates a Faraday connection
def fedora_connection_builder
@fedora_connection_builder ||= lambda { |url|
Faraday.new(url) do |f|
f.request :multipart
f.request :url_encoded
f.adapter Faraday.default_adapter
end
}
end
attr_writer :fedora_connection_builder

##
# @return [#save, #save_all, #delete, #wipe!] an indexing adapter
def index_adapter
Expand Down
2 changes: 1 addition & 1 deletion lib/hyrax/transactions/steps/add_to_parent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call(obj, parent_id: nil, user: nil)
return Success(obj) if parent_id.blank?

parent = Hyrax.query_service.find_by(id: parent_id)
parent.member_ids << obj.id
parent.member_ids += [obj.id]
Hyrax.persister.save(resource: parent)

user ||= ::User.find_by_user_key(obj.depositor)
Expand Down

0 comments on commit 1c4060d

Please sign in to comment.