-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
187 additions
and
87 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
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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
class FileNode < Valkyrie::Resource | ||
include Valkyrie::Resource::AccessControls | ||
attribute :id, Valkyrie::Types::ID.optional | ||
attribute :label, Valkyrie::Types::Set | ||
attribute :mime_type, Valkyrie::Types::Set | ||
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 | ||
|
||
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 title | ||
label | ||
end | ||
|
||
def download_id | ||
id | ||
end | ||
|
||
def valid? | ||
file = Valkyrie::StorageAdapter.find_by(id: file_identifiers.first) | ||
file.valid?(size: size.first, digests: { sha256: checksum.first }) | ||
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 was deleted.
Oops, something went wrong.
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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
class FileAppender | ||
attr_reader :storage_adapter, :persister, :files | ||
def initialize(storage_adapter:, persister:, files:) | ||
@storage_adapter = storage_adapter | ||
@persister = persister | ||
@files = files | ||
end | ||
|
||
def append_to(resource) | ||
return resource if files.blank? | ||
file_sets = build_file_sets || file_nodes | ||
resource.member_ids = resource.member_ids + file_sets.map(&:id) | ||
resource | ||
end | ||
|
||
def build_file_sets | ||
return if processing_derivatives? | ||
file_nodes.map do |node| | ||
file_set = create_file_set(node) | ||
Valkyrie::DerivativeService.for(FileSetChangeSet.new(file_set)).create_derivatives if node.use.include?(Valkyrie::Vocab::PCDMUse.OriginalFile) | ||
file_set | ||
end | ||
end | ||
|
||
def processing_derivatives? | ||
!file_nodes.first.use.include?(Valkyrie::Vocab::PCDMUse.OriginalFile) | ||
end | ||
|
||
def file_nodes | ||
@file_nodes ||= | ||
begin | ||
files.map do |file| | ||
create_node(file) | ||
end | ||
end | ||
end | ||
|
||
def create_node(file) | ||
node = persister.save(resource: FileNode.for(file: file)) | ||
stored_file = storage_adapter.upload(file: file, resource: node) | ||
node.file_identifiers = node.file_identifiers + [stored_file.id] | ||
node = Valkyrie::FileCharacterizationService.for(file_node: node, persister: persister).characterize(save: false) | ||
persister.save(resource: node) | ||
end | ||
|
||
def create_file_set(file_node) | ||
persister.save(resource: ::FileSet.new(title: file_node.original_filename, member_ids: file_node.id)) | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
class Queries | ||
class_attribute :metadata_adapter | ||
self.metadata_adapter = Valkyrie.config.metadata_adapter | ||
class << self | ||
delegate :find_all, :find_by, :find_members, :find_inverse_references_by, to: :default_adapter | ||
|
||
def default_adapter | ||
new(metadata_adapter: metadata_adapter) | ||
end | ||
end | ||
|
||
attr_reader :metadata_adapter | ||
delegate :find_all, :find_by, :find_members, :find_inverse_references_by, to: :metadata_adapter_query_service | ||
def initialize(metadata_adapter:) | ||
@metadata_adapter = metadata_adapter | ||
end | ||
|
||
delegate :query_service, to: :metadata_adapter, prefix: true | ||
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
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
Oops, something went wrong.