-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
valkyrize file_actor adding file_node to hold metadata_node values fr…
…om active fedora Remaining Work: * in wings persister - implement save_file_node * provide means to convert back and forth from resource file_node and AF metadata_node
- Loading branch information
Showing
11 changed files
with
645 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,69 @@ | ||
require 'wings/models/file_node' | ||
require 'wings/services/file_node_builder' | ||
|
||
module Hyrax | ||
class VersioningService | ||
# Make a version and record the version committer | ||
# @param [ActiveFedora::File] content | ||
# @param [User, String] user | ||
def self.create(content, user = nil) | ||
content.create_version | ||
record_committer(content, user) if user | ||
end | ||
class << self | ||
# Make a version and record the version committer | ||
# @param [ActiveFedora::File | Wings::FileNode] content | ||
# @param [User, String] user | ||
def create(content, user = nil) | ||
use_valkyrie = content.is_a? Wings::FileNode | ||
perform_create(content, user, use_valkyrie) | ||
end | ||
|
||
# @param [ActiveFedora::File] file | ||
def self.latest_version_of(file) | ||
file.versions.last | ||
end | ||
# @param [ActiveFedora::File | Wings::FileNode] content | ||
def latest_version_of(file) | ||
file.versions.last | ||
end | ||
|
||
# Record the version committer of the last version | ||
# @param [ActiveFedora::File | Wings::FileNode] content | ||
# @param [User, String] user_key | ||
def record_committer(content, user_key) | ||
user_key = user_key.user_key if user_key.respond_to?(:user_key) | ||
version = latest_version_of(content) | ||
return if version.nil? | ||
version_id = content.is_a?(Wings::FileNode) ? version.id.to_s : version.uri | ||
Hyrax::VersionCommitter.create(version_id: version_id, committer_login: user_key) | ||
end | ||
|
||
# TODO: Copied from valkyrie6 branch. Need to explore whether this is needed? | ||
# # @param [FileSet] file_set | ||
# # @param [Wings::FileNode] content | ||
# # @param [String] revision_id | ||
# # @param [User, String] user | ||
# def restore_version(file_set, content, revision_id, user = nil) | ||
# found_version = content.versions.find { |x| x.label == Array.wrap(revision_id) } | ||
# return unless found_version | ||
# node = Wings::FileNodeBuilder.new(storage_adapter: nil, persister: indexing_adapter.persister).attach_file_node(node: found_version, file_set: file_set) | ||
# create(node, user) | ||
# end | ||
|
||
private | ||
|
||
# # TODO: Should we create and use indexing adapter for persistence? This is what was used in branch valkyrie6. | ||
# def indexing_adapter | ||
# Valkyrie::MetadataAdapter.find(:indexing_persister) | ||
# end | ||
|
||
def perform_create(content, user, use_valkyrie) | ||
use_valkyrie ? perform_create_through_valkyrie(content, user) : perform_create_through_active_fedora(content, user) | ||
end | ||
|
||
def perform_create_through_active_fedora(content, user) | ||
content.create_version | ||
record_committer(content, user) if user | ||
end | ||
|
||
# Record the version committer of the last version | ||
# @param [ActiveFedora::File] content | ||
# @param [User, String] user_key | ||
def self.record_committer(content, user_key) | ||
user_key = user_key.user_key if user_key.respond_to?(:user_key) | ||
version = latest_version_of(content) | ||
return if version.nil? | ||
VersionCommitter.create(version_id: version.uri, committer_login: user_key) | ||
def perform_create_through_valkyrie(content, user) | ||
new_version = content.new(id: nil) | ||
new_version.label = "version#{content.member_ids.length + 1}" | ||
# new_version = indexing_adapter.persister.save(resource: new_version) | ||
content.member_ids = content.member_ids + [new_version.id] | ||
content = indexing_adapter.persister.save(resource: content) | ||
record_committer(content, user) if user | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# frozen_string_literal: true | ||
|
||
module Wings | ||
class FileNode < ::Valkyrie::Resource | ||
# TODO: Branch valkyrie6 included the valkyrie resource access controls. Including this now causes an exception. | ||
# Need to explore whether this line should be uncommented. | ||
# include ::Valkyrie::Resource::AccessControls | ||
attribute :id, ::Valkyrie::Types::ID.optional | ||
attribute :label, ::Valkyrie::Types::Set | ||
attribute :mime_type, ::Valkyrie::Types::Set | ||
attribute :format_label, ::Valkyrie::Types::Set # e.g. "JPEG Image" | ||
attribute :height, ::Valkyrie::Types::Set | ||
attribute :width, ::Valkyrie::Types::Set | ||
attribute :checksum, ::Valkyrie::Types::Set | ||
attribute :size, ::Valkyrie::Types::Set | ||
attribute :original_filename, ::Valkyrie::Types::Set | ||
attribute :file_identifiers, ::Valkyrie::Types::Set | ||
attribute :use, ::Valkyrie::Types::Set | ||
attribute :member_ids, ::Valkyrie::Types::Set | ||
|
||
# @param [ActionDispatch::Http::UploadedFile] file | ||
def self.for(file:) | ||
new(label: file.original_filename, | ||
original_filename: file.original_filename, | ||
mime_type: file.content_type, | ||
use: file.try(:use) || [::Valkyrie::Vocab::PCDMUse.OriginalFile]) | ||
end | ||
|
||
def original_file? | ||
use.include?(::Valkyrie::Vocab::PCDMUse.OriginalFile) | ||
end | ||
|
||
def thumbnail_file? | ||
use.include?(::Valkyrie::Vocab::PCDMUse.ThumbnailImage) | ||
end | ||
|
||
def extracted_file? | ||
use.include?(::Valkyrie::Vocab::PCDMUse.ExtractedImage) | ||
end | ||
|
||
def title | ||
label | ||
end | ||
|
||
def download_id | ||
id | ||
end | ||
|
||
# @return [Boolean] whether this instance is a Wings::FileNode. | ||
def file_node? | ||
true | ||
end | ||
|
||
# @return [Boolean] whether this instance is a Hydra::Works FileSet. | ||
def file_set? | ||
false | ||
end | ||
|
||
# @return [Boolean] whether this instance is a Hydra::Works Generic Work. | ||
def work? | ||
false | ||
end | ||
|
||
# @return [Boolean] whether this instance is a Hydra::Works Collection. | ||
def collection? | ||
false | ||
end | ||
|
||
def valid? | ||
file.valid?(size: size.first, digests: { sha256: checksum.first.sha256 }) | ||
end | ||
|
||
def file | ||
::Valkyrie::StorageAdapter.find_by(id: file_identifiers.first) | ||
end | ||
|
||
def versions | ||
query_service = Wings::Valkyrie::QueryService.new(adapter: ::Valkyrie.config.metadata_adapter) | ||
query_service.find_members(resource: self, model: Wings::FileNode).to_a | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Wings | ||
class MultiChecksum < ::Valkyrie::Resource | ||
attribute :sha256, ::Valkyrie::Types::SingleValuedString | ||
attribute :md5, ::Valkyrie::Types::SingleValuedString | ||
attribute :sha1, ::Valkyrie::Types::SingleValuedString | ||
|
||
def self.for(file_object) | ||
digests = file_object.checksum(digests: [::Digest::MD5.new, ::Digest::SHA256.new, ::Digest::SHA1.new]) | ||
MultiChecksum.new( | ||
md5: digests.shift, | ||
sha256: digests.shift, | ||
sha1: digests.shift | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.