diff --git a/.rubocop.yml b/.rubocop.yml index 7f60b31b9..d3e3ba00c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,9 @@ Style/PredicateName: Style/MethodMissing: Exclude: - "lib/valkyrie/persistence/active_fedora/resource_factory.rb" +Lint/UselessAssignment: + Exclude: + - 'lib/valkyrie/persistence/active_fedora/orm/resource.rb' Metrics/BlockLength: Exclude: - 'config/environments/**/*' diff --git a/app/file_characterization_services/tika_file_characterization_service.rb b/app/file_characterization_services/tika_file_characterization_service.rb index 48c45977a..f4fbcadaa 100644 --- a/app/file_characterization_services/tika_file_characterization_service.rb +++ b/app/file_characterization_services/tika_file_characterization_service.rb @@ -34,7 +34,7 @@ def characterize(save: true) # Provides the SHA256 hexdigest string for the file # @return String def checksum - Digest::SHA256.file(filename).hexdigest + Digest::SHA256.file(filename).hexdigest if filename end def json_output diff --git a/lib/tasks/multispec.rake b/lib/tasks/multispec.rake index d33beb244..2deebe8c6 100644 --- a/lib/tasks/multispec.rake +++ b/lib/tasks/multispec.rake @@ -1,10 +1,10 @@ # frozen_string_literal: true desc "Runs tests with a variety of backends" task :multispec do - # TODO: fix fedora/fedora profiles = [ { metadata: 'memory', storage: 'memory' }, - { metadata: 'postgres', storage: 'disk' } + { metadata: 'postgres', storage: 'disk' }, + { metadata: 'fedora', storage: 'fedora' } ] profiles.each do |profile| ENV['VALKYRIE_METADATA'] = profile[:metadata] diff --git a/lib/valkyrie/persistence/active_fedora/orm/resource.rb b/lib/valkyrie/persistence/active_fedora/orm/resource.rb index 93780c97a..3dcf36b70 100644 --- a/lib/valkyrie/persistence/active_fedora/orm/resource.rb +++ b/lib/valkyrie/persistence/active_fedora/orm/resource.rb @@ -22,6 +22,7 @@ class Schema < ActiveTriples::Schema property :height, predicate: ::RDF::URI("http://example.com/height") property :width, predicate: ::RDF::URI("http://example.com/height") property :checksum, predicate: ::RDF::URI("http://example.com/checksum") + property :file_size, predicate: ::RDF::URI("http://example.com/file_size") end class NestedResource < ActiveTriples::Resource def initialize(uri = RDF::Node.new, _parent = ActiveTriples::Resource.new) @@ -52,6 +53,14 @@ class Resource < ActiveFedora::Base property :nested_resource, predicate: ::RDF::URI("http://example.com/nested_resource"), class_name: "Valkyrie::Persistence::ActiveFedora::ORM::NestedResource" accepts_nested_attributes_for :nested_resource + def size=(size) + file_size = size + end + + def size + file_size + end + def to_solr(doc = {}) super.merge( uri_ssi: uri.to_s diff --git a/spec/derivative_services/image_derivative_service_spec.rb b/spec/derivative_services/image_derivative_service_spec.rb index ba8a50f8d..d0fa3ea3b 100644 --- a/spec/derivative_services/image_derivative_service_spec.rb +++ b/spec/derivative_services/image_derivative_service_spec.rb @@ -50,7 +50,7 @@ expect(derivative).to be_present derivative_file = Valkyrie::StorageAdapter.find_by(id: derivative.file_identifiers.first) - image = MiniMagick::Image.open(derivative_file.io.path) + image = MiniMagick::Image.open(derivative_file.disk_path) expect(image.width).to eq 105 expect(image.height).to eq 150 end diff --git a/valkyrie/lib/valkyrie/storage/disk.rb b/valkyrie/lib/valkyrie/storage/disk.rb index fb82a1e4d..088c44052 100644 --- a/valkyrie/lib/valkyrie/storage/disk.rb +++ b/valkyrie/lib/valkyrie/storage/disk.rb @@ -30,10 +30,10 @@ def file_path(id) # Return the file associated with the given identifier # @param id [Valkyrie::ID] - # @return [Valkyrie::StorageAdapter::DiskFile] + # @return [Valkyrie::StorageAdapter::File] def find_by(id:) return unless handles?(id: id) - Valkyrie::StorageAdapter::DiskFile.new(id: Valkyrie::ID.new(id.to_s), io: ::File.open(file_path(id), 'rb')) + Valkyrie::StorageAdapter::File.new(id: Valkyrie::ID.new(id.to_s), io: ::File.open(file_path(id), 'rb')) end class BucketedStorage diff --git a/valkyrie/lib/valkyrie/storage/fedora.rb b/valkyrie/lib/valkyrie/storage/fedora.rb index 9aed53c93..9f25a53dd 100644 --- a/valkyrie/lib/valkyrie/storage/fedora.rb +++ b/valkyrie/lib/valkyrie/storage/fedora.rb @@ -42,7 +42,7 @@ def initialize(source, size) @source = source @size = size end - delegate :read, :rewind, to: :io + delegate :each, :read, :rewind, to: :io # There is no streaming support in faraday (https://github.com/lostisland/faraday/pull/604) # @return [StringIO] diff --git a/valkyrie/lib/valkyrie/storage_adapter.rb b/valkyrie/lib/valkyrie/storage_adapter.rb index 8c6f2de19..7976f13f5 100644 --- a/valkyrie/lib/valkyrie/storage_adapter.rb +++ b/valkyrie/lib/valkyrie/storage_adapter.rb @@ -45,6 +45,10 @@ def stream io end + def disk_path + Pathname.new(io.path) + end + # @param id [Valkyre::ID] # @param digests [Array] # @return [Array] @@ -70,12 +74,6 @@ def valid?(size: nil, digests:) end end - class DiskFile < File - def disk_path - Pathname.new(io.path) - end - end - class StreamFile < File def disk_path Pathname.new(tmp_file.path) @@ -84,7 +82,7 @@ def disk_path private def tmp_file_name - id.to_s.split('://').last + id.to_s.tr(':/', '__') end def tmp_file_path diff --git a/valkyrie/spec/valkyrie/storage_adapter/disk_file_spec.rb b/valkyrie/spec/valkyrie/storage_adapter/disk_file_spec.rb deleted file mode 100644 index 5dd6f6174..000000000 --- a/valkyrie/spec/valkyrie/storage_adapter/disk_file_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true -require 'spec_helper' -require 'valkyrie/specs/shared_specs' - -RSpec.describe Valkyrie::StorageAdapter::DiskFile do - let(:io) { instance_double(::File) } - let(:file) { described_class.new(id: "test_file", io: io) } - it_behaves_like "a Valkyrie::StorageAdapter::File" - describe '#disk_path' do - before do - allow(io).to receive(:read).and_return('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') - end - context 'with the disk or memory storage adapter' do - before do - allow(io).to receive(:path).and_return('/test/path') - end - - it 'provides a path to the file for the storage adapter' do - expect(file.disk_path).to eq Pathname.new('/test/path') - end - end - end -end diff --git a/valkyrie/spec/valkyrie/storage_adapter/file_spec.rb b/valkyrie/spec/valkyrie/storage_adapter/file_spec.rb index 436ec64ac..be72a1c95 100644 --- a/valkyrie/spec/valkyrie/storage_adapter/file_spec.rb +++ b/valkyrie/spec/valkyrie/storage_adapter/file_spec.rb @@ -3,7 +3,22 @@ require 'valkyrie/specs/shared_specs' RSpec.describe Valkyrie::StorageAdapter::File do - let(:io) { instance_double(IO) } + let(:io) { instance_double(::File) } let(:file) { described_class.new(id: "test_file", io: io) } it_behaves_like "a Valkyrie::StorageAdapter::File" + + describe '#disk_path' do + before do + allow(io).to receive(:read).and_return('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') + end + context 'with the disk or memory storage adapter' do + before do + allow(io).to receive(:path).and_return('/test/path') + end + + it 'provides a path to the file for the storage adapter' do + expect(file.disk_path).to eq Pathname.new('/test/path') + end + end + end end