diff --git a/.dassie/db/schema.rb b/.dassie/db/schema.rb index 9b2f524316..368cd762fb 100644 --- a/.dassie/db/schema.rb +++ b/.dassie/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_11_30_181150) do +ActiveRecord::Schema.define(version: 2023_07_25_222727) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -140,6 +140,17 @@ t.index ["machine_id"], name: "index_hyrax_collection_types_on_machine_id", unique: true end + create_table "hyrax_counter_metrics", force: :cascade do |t| + t.string "worktype" + t.string "resource_type" + t.integer "work_id" + t.date "date" + t.integer "total_item_investigations" + t.integer "total_item_requests" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "hyrax_default_administrative_set", force: :cascade do |t| t.string "default_admin_set_id", null: false t.datetime "created_at", null: false diff --git a/app/indexers/hyrax/file_set_indexer.rb b/app/indexers/hyrax/file_set_indexer.rb index 5c02ea4cc9..5d05a09692 100644 --- a/app/indexers/hyrax/file_set_indexer.rb +++ b/app/indexers/hyrax/file_set_indexer.rb @@ -30,6 +30,7 @@ def generate_solr_document # rubocop:disable Metrics/AbcSize, Metrics/MethodLeng solr_doc['original_checksum_tesim'] = object.original_checksum solr_doc['alpha_channels_ssi'] = object.alpha_channels solr_doc['original_file_id_ssi'] = original_file_id + solr_doc['extracted_text_id_ssi'] = extracted_text_id solr_doc['generic_type_si'] = 'FileSet' end end @@ -46,6 +47,11 @@ def original_file_id Hyrax::VersioningService.versioned_file_id object.original_file end + def extracted_text_id + return unless object.extracted_text + Hyrax::VersioningService.versioned_file_id object.extracted_text + end + def file_format if object.mime_type.present? && object.format_label.present? "#{object.mime_type.split('/').last} (#{object.format_label.join(', ')})" diff --git a/app/indexers/hyrax/valkyrie_file_set_indexer.rb b/app/indexers/hyrax/valkyrie_file_set_indexer.rb index 618cb59262..8409782066 100644 --- a/app/indexers/hyrax/valkyrie_file_set_indexer.rb +++ b/app/indexers/hyrax/valkyrie_file_set_indexer.rb @@ -39,12 +39,13 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met solr_doc['file_format_tesim'] = file_format(file_metadata) solr_doc['file_format_sim'] = file_format(file_metadata) - solr_doc['file_size_lts'] = file_metadata.size[0] - solr_doc['type_tesim'] = file_metadata.type.map(&:to_s) if file_metadata.type.present? + solr_doc['file_size_lts'] = file_metadata.recorded_size[0] + solr_doc['type_tesim'] = file_metadata.pcdm_use.map(&:to_s) if file_metadata.pcdm_use.present? + solr_doc['pcdm_use_tesim'] = file_metadata.pcdm_use.map(&:to_s) if file_metadata.pcdm_use.present? # attributes set by fits solr_doc['format_label_tesim'] = file_metadata.format_label if file_metadata.format_label.present? - solr_doc['size_tesim'] = file_metadata.size if file_metadata.size.present? + solr_doc['size_tesim'] = file_metadata.recorded_size if file_metadata.recorded_size.present? solr_doc['well_formed_tesim'] = file_metadata.well_formed if file_metadata.well_formed.present? solr_doc['valid_tesim'] = file_metadata.valid if file_metadata.valid.present? solr_doc['fits_version_tesim'] = file_metadata.fits_version if file_metadata.fits_version.present? diff --git a/app/jobs/valkyrie_ingest_job.rb b/app/jobs/valkyrie_ingest_job.rb index d8be3cfc05..590344ec94 100644 --- a/app/jobs/valkyrie_ingest_job.rb +++ b/app/jobs/valkyrie_ingest_job.rb @@ -25,7 +25,6 @@ def perform(file, pcdm_use: Hyrax::FileMetadata::Use::ORIGINAL_FILE) def ingest(file:, pcdm_use:) file_set_uri = Valkyrie::ID.new(file.file_set_uri) file_set = Hyrax.query_service.find_by(id: file_set_uri) - updated_metadata = upload_file( file: file, file_set: file_set, diff --git a/app/models/concerns/hyrax/file_set/derivatives.rb b/app/models/concerns/hyrax/file_set/derivatives.rb index 2ea74ce411..e20b52adc7 100644 --- a/app/models/concerns/hyrax/file_set/derivatives.rb +++ b/app/models/concerns/hyrax/file_set/derivatives.rb @@ -43,8 +43,9 @@ module Derivatives # # ./spec/jobs/create_derivatives_job_spec.rb:7:in `block (2 levels) in ' # Hydra::Derivatives.source_file_service = Hyrax::LocalFileService - Hydra::Derivatives.output_file_service = Hyrax::PersistDerivatives - Hydra::Derivatives::FullTextExtract.output_file_service = Hyrax::PersistDirectlyContainedOutputFileService + Hydra::Derivatives.output_file_service = Hyrax::ValkyriePersistDerivatives + # Hydra::Derivatives::FullTextExtract.output_file_service = Hyrax::PersistDirectlyContainedOutputFileService + Hydra::Derivatives::FullTextExtract.output_file_service = Hyrax::ValkyriePersistDerivatives before_destroy :cleanup_derivatives # This completely overrides the version in Hydra::Works so that we # read and write to a local file. It's important that characterization runs diff --git a/app/models/hyrax/file_metadata.rb b/app/models/hyrax/file_metadata.rb index d521ae8418..cebfc34db8 100644 --- a/app/models/hyrax/file_metadata.rb +++ b/app/models/hyrax/file_metadata.rb @@ -18,7 +18,6 @@ def self.FileMetadata(file) "with id #{file.id}. Initializing a new one") FileMetadata.new(file_identifier: file.id, - alternative_ids: [file.id], original_filename: File.basename(file.io)) end @@ -67,11 +66,11 @@ def uri_for(use:) attribute :label, ::Valkyrie::Types::Set attribute :original_filename, ::Valkyrie::Types::String attribute :mime_type, ::Valkyrie::Types::String.default(GENERIC_MIME_TYPE) - attribute :type, ::Valkyrie::Types::Set.default([Use::ORIGINAL_FILE].freeze) # Use += to add types, not << + attribute :pcdm_use, ::Valkyrie::Types::Set.default([Use::ORIGINAL_FILE].freeze) # Use += to add pcdm_uses, not << # attributes set by fits attribute :format_label, ::Valkyrie::Types::Set - attribute :size, ::Valkyrie::Types::Set + attribute :recorded_size, ::Valkyrie::Types::Set attribute :well_formed, ::Valkyrie::Types::Set attribute :valid, ::Valkyrie::Types::Set attribute :date_created, ::Valkyrie::Types::Set @@ -130,19 +129,19 @@ def uri_for(use:) ## # @return [Boolean] def original_file? - type.include?(Use::ORIGINAL_FILE) + pcdm_use.include?(Use::ORIGINAL_FILE) end ## # @return [Boolean] def thumbnail_file? - type.include?(Use::THUMBNAIL) + pcdm_use.include?(Use::THUMBNAIL) end ## # @return [Boolean] def extracted_file? - type.include?(Use::EXTRACTED_TEXT) + pcdm_use.include?(Use::EXTRACTED_TEXT) end def title @@ -154,7 +153,7 @@ def download_id end def valid? - file.valid?(size: size.first, digests: { sha256: checksum&.first&.sha256 }) + file.valid?(size: recorded_size.first, digests: { sha256: checksum&.first&.sha256 }) end ## diff --git a/app/services/hyrax/custom_queries/find_file_metadata.rb b/app/services/hyrax/custom_queries/find_file_metadata.rb index a1ae3ce45f..dd3df0b63e 100644 --- a/app/services/hyrax/custom_queries/find_file_metadata.rb +++ b/app/services/hyrax/custom_queries/find_file_metadata.rb @@ -67,7 +67,7 @@ def find_many_file_metadata_by_use(resource:, use:) return [] unless resource.try(:file_ids) results = find_many_file_metadata_by_ids(ids: resource.file_ids) - results.select { |fm| fm.type.include?(use) } + results.select { |fm| fm.pcdm_use.include?(use) } end end end diff --git a/app/services/hyrax/derivative_path.rb b/app/services/hyrax/derivative_path.rb index a14b31eb90..47088d2882 100644 --- a/app/services/hyrax/derivative_path.rb +++ b/app/services/hyrax/derivative_path.rb @@ -68,6 +68,8 @@ def extension case destination_name when 'thumbnail' ".#{MIME::Types.type_for('jpg').first.extensions.first}" + when 'extracted_text' + ".#{MIME::Types.type_for('txt').first.extensions.first}" else ".#{destination_name}" end diff --git a/app/services/hyrax/file_set_derivatives_service.rb b/app/services/hyrax/file_set_derivatives_service.rb index 0db61703a0..6b28f216cd 100644 --- a/app/services/hyrax/file_set_derivatives_service.rb +++ b/app/services/hyrax/file_set_derivatives_service.rb @@ -75,7 +75,7 @@ def create_pdf_derivatives(filename) url: derivative_url('thumbnail'), layer: 0 }]) - extract_full_text(filename, uri) + extract_full_text(filename, derivative_url('extracted_text')) end def create_office_document_derivatives(filename) @@ -86,7 +86,7 @@ def create_office_document_derivatives(filename) url: derivative_url('thumbnail'), layer: 0 }]) - extract_full_text(filename, uri) + extract_full_text(filename, derivative_url('extracted_text')) end def create_audio_derivatives(filename) @@ -122,6 +122,7 @@ def derivative_path_factory # @param [String] uri to the file set (deligated to file_set) def extract_full_text(filename, uri) return unless Hyrax.config.extract_full_text? + Hydra::Derivatives::FullTextExtract.create(filename, outputs: [{ url: uri, container: "extracted_text" }]) end diff --git a/app/services/hyrax/persist_directly_contained_output_file_service.rb b/app/services/hyrax/persist_directly_contained_output_file_service.rb index 14fdc05dc1..965e4d698a 100644 --- a/app/services/hyrax/persist_directly_contained_output_file_service.rb +++ b/app/services/hyrax/persist_directly_contained_output_file_service.rb @@ -24,11 +24,33 @@ def self.call(content, directives) # @option directives [String] url URI for the parent object. def self.retrieve_file_set(directives) uri = URI(directives.fetch(:url)) - raise ArgumentError, "#{uri} is not an http(s) uri" unless uri.is_a?(URI::HTTP) - Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: Hyrax::Base.uri_to_id(uri.to_s), use_valkyrie: false) + if uri.is_a?(URI::HTTP) + Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: Hyrax::Base.uri_to_id(uri.to_s), use_valkyrie: false) + else + raise ArgumentError, "#{uri} is not an file/http(s) uri" unless uri.is_a?(URI::File) + + fileset_for_directives(directives) + end end private_class_method :retrieve_file_set + # The filepath will look something like + # /app/samvera/hyrax-webapp/derivatives/95/93/tv/12/3-thumbnail.jpeg and + # we want to extract the FileSet id, which in this case would be 9593tv123 + # + # @param [String] path + # @return [Hyrax::FileSet] + def self.fileset_for_directives(directives) + path = URI(directives.fetch(:url)).path + id = path.sub(Hyrax.config.derivatives_path.to_s, "") + .delete('/') + .match(/^(.*)-\w*(\.\w+)*$/) { |m| m[1] } + raise "Could not extract fileset id from path #{path}" unless id + + Hyrax.metadata_adapter.query_service.find_by(id: id) + end + private_class_method :fileset_for_directives + # Override this implementation if you need a remote file from a different location # @param file_set [FileSet] the container of the remote file # @param directives [Hash] directions which can be used to determine where to persist to diff --git a/app/services/hyrax/valkyrie_persist_derivatives.rb b/app/services/hyrax/valkyrie_persist_derivatives.rb index 22336da9de..5afba625ca 100644 --- a/app/services/hyrax/valkyrie_persist_derivatives.rb +++ b/app/services/hyrax/valkyrie_persist_derivatives.rb @@ -22,22 +22,17 @@ def self.call(stream, file_set = fileset_for_directives(directives) # Valkyrie storage adapters will typically expect an IO-like object that - # responds to #path -- here we only have a StringIO, so some - # transformation is in order + # responds to #rewind and #read so we have created a StringIO tmpfile = Tempfile.new(file_set.id, encoding: 'ascii-8bit') + stream = StringIO.new(stream) if stream.is_a?(String) stream.rewind output = tmpfile.write(stream.read) tmpfile.flush raise 'blank file detected' if output.zero? filename = filename(directives) - Hyrax.logger.debug "Uploading thumbnail for FileSet #{file_set.id} as #{filename}" - uploader.upload( - io: tmpfile, - filename: filename, - file_set: file_set, - use: Hyrax::FileMetadata::Use::THUMBNAIL - ) + Hyrax.logger.debug "Uploading derivative for FileSet #{file_set.id} as #{filename}" + uploader.upload(io: tmpfile, filename: filename, file_set: file_set, use: file_metadata(directives)) end # The filepath will look something like @@ -59,5 +54,13 @@ def self.fileset_for_directives(directives) def self.filename(directives) URI(directives.fetch(:url)).path.split('/').last end + + def self.file_metadata(directives) + if directives.key?(:container) + "Hyrax::FileMetadata::Use::#{directives[:container].upcase}".constantize + else + Hyrax::FileMetadata::Use::THUMBNAIL + end + end end end diff --git a/app/services/hyrax/valkyrie_upload.rb b/app/services/hyrax/valkyrie_upload.rb index ea9240f679..f0c11738cb 100644 --- a/app/services/hyrax/valkyrie_upload.rb +++ b/app/services/hyrax/valkyrie_upload.rb @@ -38,7 +38,8 @@ def upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FI streamfile = storage_adapter.upload(file: io, original_filename: filename, resource: file_set) file_metadata = Hyrax::FileMetadata(streamfile) file_metadata.file_set_id = file_set.id - file_metadata.type += [use] + file_metadata.pcdm_use = [use] + file_metadata.recorded_size = [io.size] if use == Hyrax::FileMetadata::Use::ORIGINAL_FILE # Set file set label. @@ -50,6 +51,7 @@ def upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FI end saved_metadata = Hyrax.persister.save(resource: file_metadata) + saved_metadata.original_filename = filename if saved_metadata.original_filename.blank? Hyrax.publisher.publish("object.file.uploaded", metadata: saved_metadata) add_file_to_file_set(file_set: file_set, @@ -83,7 +85,7 @@ def add_file_to_file_set(file_set:, file_metadata:, user:) # the file to add # @return [void] def set_file_use_ids(file_set, file_metadata) - file_metadata.type.each do |type| + file_metadata.pcdm_use.each do |type| case type when Hyrax::FileMetadata::Use::ORIGINAL_FILE file_set.original_file_id = file_metadata.id diff --git a/app/services/hyrax/versioning_service.rb b/app/services/hyrax/versioning_service.rb index be1d906dcc..b9177760d5 100644 --- a/app/services/hyrax/versioning_service.rb +++ b/app/services/hyrax/versioning_service.rb @@ -41,6 +41,7 @@ def versions [] end else + return resource.versions if resource.versions.is_a?(Array) resource.versions.all.to_a end end diff --git a/lib/wings/active_fedora_converter.rb b/lib/wings/active_fedora_converter.rb index 4a4e6c0dca..5b5dcfe1fd 100644 --- a/lib/wings/active_fedora_converter.rb +++ b/lib/wings/active_fedora_converter.rb @@ -138,19 +138,30 @@ def apply_attributes_to_model(af_object) when ActiveFedora::File add_file_attributes(af_object) else - converted_attrs = normal_attributes - members = Array.wrap(converted_attrs.delete(:members)) - files = converted_attrs.delete(:files) - af_object.attributes = converted_attrs - perform_lease_conversion(af_object: af_object, resource: resource) if resource.try(:lease) && af_object.reflections.include?(:lease) - perform_embargo_conversion(af_object: af_object, resource: resource) if resource.try(:embargo) && af_object.reflections.include?(:embargo) - members.empty? ? af_object.try(:ordered_members)&.clear : af_object.try(:ordered_members=, members) - af_object.try(:members)&.replace(members) - af_object.files.build_or_set(files) if files + parse_attributes(af_object) end end # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength + def parse_attributes(af_object) + converted_attrs = normal_attributes + members = Array.wrap(converted_attrs.delete(:members)) + files = converted_attrs.delete(:files) + af_object.attributes = converted_attrs + af_object.extracted_text = create_extrated_text(af_object) if resource.attributes[:extracted_text_id].present? + perform_lease_conversion(af_object: af_object, resource: resource) + perform_embargo_conversion(af_object: af_object, resource: resource) + members.empty? ? af_object.try(:ordered_members)&.clear : af_object.try(:ordered_members=, members) + af_object.try(:members)&.replace(members) + af_object.files.build_or_set(files) if files + end + + def create_extrated_text(af_object) + pcdm_et_file = af_object.extracted_text.presence || af_object.create_extracted_text + pcdm_et_file.content = Hyrax.custom_queries.find_many_file_metadata_by_use(resource: resource, use: Hyrax::FileMetadata::Use::EXTRACTED_TEXT).first&.content + pcdm_et_file + end + # Add attributes from resource which aren't AF properties into af_object def add_access_control_attributes(af_object) normal_attributes[:permissions].each { |p| p.access_to_id = resource.access_to&.id } @@ -159,9 +170,12 @@ def add_access_control_attributes(af_object) # for files, add attributes to metadata_node, plus some other work def add_file_attributes(af_object) - af_object.metadata_node.attributes = normal_attributes + converted_attrs = normal_attributes + pcdm_use = converted_attrs.delete(:pcdm_use) + af_object.metadata_node.attributes = converted_attrs + af_object.pcdm_use = pcdm_use.first if pcdm_use.present? && pcdm_use.first.present? af_object.original_name = resource.original_filename - new_type = (resource.type - af_object.metadata_node.type.to_a).first + new_type = (resource.pcdm_use - af_object.metadata_node.type.to_a).first af_object.metadata_node.type = new_type if new_type af_object.mime_type = resource.mime_type end @@ -169,7 +183,7 @@ def add_file_attributes(af_object) def perform_lease_conversion(af_object:, resource:) # TODO(#6134): af_object.lease.class has the same name as resource.lease.class; however, each class has a different object_id # so a type mismatch happens. the code below coerces the one object into the other - return if af_object.lease&.id + return if !resource.try(:lease) || !af_object.reflections.include?(:lease) || af_object.lease&.id resource_lease_dup = af_object.reflections.fetch(:lease).klass.new(resource.lease.attributes.except(:id, :internal_resource, :created_at, :updated_at, :new_record)) af_object.lease = resource_lease_dup @@ -178,7 +192,7 @@ def perform_lease_conversion(af_object:, resource:) def perform_embargo_conversion(af_object:, resource:) # TODO(#6134): af_object.embargo.class has the same name as resource.embargo.class; however, each class has a different object_id # so a type mismatch happens. the code below coerces the one object into the other - return if af_object.embargo&.id + return if !resource.try(:embargo) || !af_object.reflections.include?(:embargo) || af_object.embargo&.id resource_embargo_dup = af_object.reflections.fetch(:embargo).klass.new(resource.embargo.attributes.except(:id, :internal_resource, :created_at, :updated_at, :new_record)) af_object.embargo = resource_embargo_dup diff --git a/lib/wings/active_fedora_converter/default_work.rb b/lib/wings/active_fedora_converter/default_work.rb index ada7e8853f..0c7ca3b25a 100644 --- a/lib/wings/active_fedora_converter/default_work.rb +++ b/lib/wings/active_fedora_converter/default_work.rb @@ -118,7 +118,7 @@ def model_name(*) end def to_rdf_representation - "Wings(#{valkyrie_class})" + "Wings(#{valkyrie_class})" unless valkyrie_class&.to_s&.include?('Wings(') end alias inspect to_rdf_representation alias to_s inspect diff --git a/lib/wings/active_fedora_converter/file_metadata_node.rb b/lib/wings/active_fedora_converter/file_metadata_node.rb index 90dd2b0939..9139da52e8 100644 --- a/lib/wings/active_fedora_converter/file_metadata_node.rb +++ b/lib/wings/active_fedora_converter/file_metadata_node.rb @@ -29,7 +29,7 @@ def model_name(*) end def to_rdf_representation - "Wings(#{valkyrie_class})" + "Wings(#{valkyrie_class})" unless valkyrie_class&.to_s&.include?('Wings(') end alias inspect to_rdf_representation alias to_s inspect diff --git a/lib/wings/model_transformer.rb b/lib/wings/model_transformer.rb index b21cb8e52c..c8623ee4a1 100644 --- a/lib/wings/model_transformer.rb +++ b/lib/wings/model_transformer.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Metrics/ClassLength module Wings ## # Transforms ActiveFedora models or objects into Valkyrie::Resource models or @@ -57,10 +58,24 @@ def build klass.new(**attrs).tap do |resource| resource.lease = pcdm_object.lease&.valkyrie_resource if pcdm_object.respond_to?(:lease) && pcdm_object.lease resource.embargo = pcdm_object.embargo&.valkyrie_resource if pcdm_object.respond_to?(:embargo) && pcdm_object.embargo + check_size(resource) + check_pcdm_use(resource) ensure_current_permissions(resource) end end + def check_size(resource) + return unless resource.respond_to?(:recorded_size) && pcdm_object.respond_to?(:size) + resource.recorded_size = [pcdm_object.size.to_i] + end + + def check_pcdm_use(resource) + return unless resource.respond_to?(:pcdm_use) && + pcdm_object.respond_to?(:metadata_node) && + pcdm_object&.metadata_node&.respond_to?(:type) + resource.pcdm_use = pcdm_object.metadata_node.type.to_a + end + def ensure_current_permissions(resource) return if pcdm_object.try(:access_control).blank? @@ -189,3 +204,4 @@ def append_permissions(attrs) end end end +# rubocop:enable Metrics/ClassLength diff --git a/lib/wings/setup.rb b/lib/wings/setup.rb index 83f8b5f1a1..b5c466de0f 100644 --- a/lib/wings/setup.rb +++ b/lib/wings/setup.rb @@ -36,6 +36,7 @@ class File alias eql? == def self.supports_property?(property) + return true if ['pcdm_use'].include?(property.to_s) properties.key?(property.to_s) end @@ -46,6 +47,14 @@ def self.properties def self.default_sort_params ["system_create_dtsi asc"] end + + def pcdm_use + metadata.type + end + + def pcdm_use=(value) + metadata.type = value + end end module WithMetadata @@ -56,6 +65,14 @@ class MetadataNode def changed_attributes super.except(:file_hash) end + + def pcdm_use + type + end + + def pcdm_use=(value) + self.type = value + end end end diff --git a/spec/factories/hyrax_file_metadata.rb b/spec/factories/hyrax_file_metadata.rb index aa8d59e653..b7ce189b06 100644 --- a/spec/factories/hyrax_file_metadata.rb +++ b/spec/factories/hyrax_file_metadata.rb @@ -15,7 +15,7 @@ .new(resource: file_metadata) .assign_access_for(visibility: evaluator.visibility_setting) end - file_metadata.type = Hyrax::FileMetadata::Use.uri_for(use: evaluator.use) if evaluator.use + file_metadata.pcdm_use = Hyrax::FileMetadata::Use.uri_for(use: evaluator.use) if evaluator.use end after(:create) do |file_metadata, evaluator| diff --git a/spec/indexers/hyrax/valkyrie_file_set_indexer_spec.rb b/spec/indexers/hyrax/valkyrie_file_set_indexer_spec.rb index 6165a582de..22221bb2ab 100644 --- a/spec/indexers/hyrax/valkyrie_file_set_indexer_spec.rb +++ b/spec/indexers/hyrax/valkyrie_file_set_indexer_spec.rb @@ -168,7 +168,7 @@ expect(subject['file_format_tesim']).to eq 'jpeg (JPEG Image)' expect(subject['file_format_sim']).to eq 'jpeg (JPEG Image)' - expect(subject['file_size_lts']).to eq mock_file.size[0] + expect(subject['file_size_lts']).to eq mock_file.recorded_size[0] expect(subject['type_tesim']).to eq ['http://pcdm.org/use#OriginalFile'] # attributes set by fits diff --git a/spec/jobs/create_derivatives_job_spec.rb b/spec/jobs/create_derivatives_job_spec.rb index 8418333306..c4d1d97904 100644 --- a/spec/jobs/create_derivatives_job_spec.rb +++ b/spec/jobs/create_derivatives_job_spec.rb @@ -124,7 +124,7 @@ url: String, layer: 0 }]) expect(Hydra::Derivatives::FullTextExtract).to receive(:create) - .with(/test\.pdf/, outputs: [{ url: RDF::URI, container: "extracted_text" }]) + .with(/test\.pdf/, outputs: [{ url: String, container: "extracted_text" }]) described_class.perform_now(file_set, file.id) end end diff --git a/spec/jobs/valkyrie_ingest_job_spec.rb b/spec/jobs/valkyrie_ingest_job_spec.rb index cff82218e0..37a89d618d 100644 --- a/spec/jobs/valkyrie_ingest_job_spec.rb +++ b/spec/jobs/valkyrie_ingest_job_spec.rb @@ -38,13 +38,11 @@ # programatically for a spec. context "when in Valkyrie mode" do it 'runs derivatives', index_adapter: :solr_index, perform_enqueued: true do - allow(ValkyrieCreateDerivativesJob).to receive(:perform_later).and_call_original - allow(Hyrax::ValkyrieUpload).to receive(:file).and_call_original + expect(Hyrax::ValkyrieUpload).to receive(:file).and_call_original + expect(ValkyrieCreateDerivativesJob).to receive(:perform_later) described_class.perform_now(upload) - expect(Hyrax::ValkyrieUpload).to have_received(:file) - expect(ValkyrieCreateDerivativesJob).to have_received(:perform_later) solr_doc = Hyrax.index_adapter.connection.get("select", params: { q: "id:#{file_set.id}" })["response"]["docs"].first expect(solr_doc["thumbnail_path_ss"]).not_to be_empty end diff --git a/spec/models/hyrax/file_metadata_spec.rb b/spec/models/hyrax/file_metadata_spec.rb index 5de51888f5..3df6f772ef 100644 --- a/spec/models/hyrax/file_metadata_spec.rb +++ b/spec/models/hyrax/file_metadata_spec.rb @@ -52,7 +52,7 @@ .to have_attributes(id: 'test_id', format_label: contain_exactly('test_format_label'), label: contain_exactly('world.png'), - type: contain_exactly(described_class::Use::ORIGINAL_FILE)) + pcdm_use: contain_exactly(described_class::Use::ORIGINAL_FILE)) end context 'when saved with a file' do @@ -82,7 +82,7 @@ describe '#original_file?' do context 'when use says file is the original file' do before do - file_metadata.type = [described_class::Use::ORIGINAL_FILE, pcdm_file_uri] + file_metadata.pcdm_use = [described_class::Use::ORIGINAL_FILE, pcdm_file_uri] end it { is_expected.to be_original_file } @@ -90,7 +90,7 @@ context 'when use does not say file is the original file' do before do - file_metadata.type = [described_class::Use::THUMBNAIL, pcdm_file_uri] + file_metadata.pcdm_use = [described_class::Use::THUMBNAIL, pcdm_file_uri] end it { is_expected.not_to be_original_file } @@ -100,7 +100,7 @@ describe '#thumbnail_file?' do context 'when use says file is the thumbnail file' do before do - file_metadata.type = [described_class::Use::THUMBNAIL, pcdm_file_uri] + file_metadata.pcdm_use = [described_class::Use::THUMBNAIL, pcdm_file_uri] end it { is_expected.to be_thumbnail_file } @@ -108,7 +108,7 @@ context 'when use does not say file is the thumbnail file' do before do - file_metadata.type = [described_class::Use::ORIGINAL_FILE, pcdm_file_uri] + file_metadata.pcdm_use = [described_class::Use::ORIGINAL_FILE, pcdm_file_uri] end it { is_expected.not_to be_thumbnail_file } @@ -118,7 +118,7 @@ describe '#extracted_file?' do context 'when use says file is the extracted file' do before do - file_metadata.type = [described_class::Use::EXTRACTED_TEXT, pcdm_file_uri] + file_metadata.pcdm_use = [described_class::Use::EXTRACTED_TEXT, pcdm_file_uri] end it { is_expected.to be_extracted_file } @@ -126,7 +126,7 @@ context 'when use does not say file is the extracted file' do before do - file_metadata.type = [described_class::Use::ORIGINAL_FILE, pcdm_file_uri] + file_metadata.pcdm_use = [described_class::Use::ORIGINAL_FILE, pcdm_file_uri] end it { is_expected.not_to be_extracted_file } diff --git a/spec/services/hyrax/characterization/file_set_description_spec.rb b/spec/services/hyrax/characterization/file_set_description_spec.rb index ab71ce8ccb..42c6aa2066 100644 --- a/spec/services/hyrax/characterization/file_set_description_spec.rb +++ b/spec/services/hyrax/characterization/file_set_description_spec.rb @@ -49,7 +49,7 @@ resource = Hyrax::FileMetadata.new(label: other_file.original_filename, original_filename: other_file.original_filename, mime_type: other_file.content_type) - resource.type = custom_type + resource.pcdm_use = custom_type Hyrax.persister.save(resource: resource) end diff --git a/spec/services/hyrax/custom_queries/find_file_metadata_spec.rb b/spec/services/hyrax/custom_queries/find_file_metadata_spec.rb index d3db281f02..47c5215a2e 100644 --- a/spec/services/hyrax/custom_queries/find_file_metadata_spec.rb +++ b/spec/services/hyrax/custom_queries/find_file_metadata_spec.rb @@ -114,7 +114,7 @@ result = query_handler.find_many_file_metadata_by_use(resource: file_set, use: requested_use) expect(result.size).to eq 1 expect(result.first).to be_a Hyrax::FileMetadata - expect(result.first.type.first).to eq requested_use + expect(result.first.pcdm_use.first).to eq requested_use end end diff --git a/spec/services/hyrax/listeners/file_metadata_listener_spec.rb b/spec/services/hyrax/listeners/file_metadata_listener_spec.rb index 023af08e5b..f2f0ead9be 100644 --- a/spec/services/hyrax/listeners/file_metadata_listener_spec.rb +++ b/spec/services/hyrax/listeners/file_metadata_listener_spec.rb @@ -47,7 +47,7 @@ let(:metadata) do FactoryBot.valkyrie_create(:hyrax_file_metadata, file_set_id: file_set.id, - type: Hyrax::FileMetadata::Use::THUMBNAIL) + pcdm_use: Hyrax::FileMetadata::Use::THUMBNAIL) end it 'does not index the file_set' do diff --git a/spec/wings/active_fedora_converter_spec.rb b/spec/wings/active_fedora_converter_spec.rb index 7d0c87d065..8f4f4d274e 100644 --- a/spec/wings/active_fedora_converter_spec.rb +++ b/spec/wings/active_fedora_converter_spec.rb @@ -347,7 +347,7 @@ class Resource < Valkyrie::Resource end it 'converts pcdm use URIs as types' do - expect { resource.type = custom_type } + expect { resource.pcdm_use = custom_type } .to change { converter.convert.metadata_node.type } .to contain_exactly(custom_type) end diff --git a/spec/wings/hydra/works/services/add_file_to_file_set_spec.rb b/spec/wings/hydra/works/services/add_file_to_file_set_spec.rb index 68f7a1c8bd..3d31fb02f0 100644 --- a/spec/wings/hydra/works/services/add_file_to_file_set_spec.rb +++ b/spec/wings/hydra/works/services/add_file_to_file_set_spec.rb @@ -67,19 +67,17 @@ let(:transcript_use) { Valkyrie::Vocab::PCDMUse.Transcript } let(:service_file_use) { Valkyrie::Vocab::PCDMUse.ServiceFile } - subject do - updated_file_set = described_class.call(file_set: file_set, file: pdf_file, type: service_file_use) - described_class.call(file_set: updated_file_set, file: text_file, type: transcript_use) - end + let(:updated_file_set) { described_class.call(file_set: file_set, file: pdf_file, type: service_file_use) } + let(:transcript_file_set) { described_class.call(file_set: updated_file_set, file: text_file, type: transcript_use) } + it 'adds the given file and applies the specified RDF::URI use to it' do - ids = subject.file_ids + ids = transcript_file_set.file_ids expect(ids.size).to eq 2 expect(ids.first).to be_a Valkyrie::ID expect(ids.first.to_s).to start_with "#{file_set.id}/files/" - - expect(Hyrax.custom_queries.find_many_file_metadata_by_use(resource: subject, use: transcript_use).first.type) + expect(Hyrax.custom_queries.find_many_file_metadata_by_use(resource: transcript_file_set, use: transcript_use).first.pcdm_use) .to include transcript_use - expect(Hyrax.custom_queries.find_many_file_metadata_by_use(resource: subject, use: service_file_use).first.type) + expect(Hyrax.custom_queries.find_many_file_metadata_by_use(resource: transcript_file_set, use: service_file_use).first.pcdm_use) .to include service_file_use end end diff --git a/spec/wings/services/custom_queries/find_file_metadata_spec.rb b/spec/wings/services/custom_queries/find_file_metadata_spec.rb index daf6c469b0..ac70a7f302 100644 --- a/spec/wings/services/custom_queries/find_file_metadata_spec.rb +++ b/spec/wings/services/custom_queries/find_file_metadata_spec.rb @@ -169,8 +169,8 @@ let!(:file_set) do file_set = af_file_set.valkyrie_resource file_set = Wings::Works::AddFileToFileSet.call(file_set: file_set, file: pdf_file, type: original_file_use) - file_set = Wings::Works::AddFileToFileSet.call(file_set: file_set, file: text_file, type: extracted_text_use) - Wings::Works::AddFileToFileSet.call(file_set: file_set, file: image_file, type: thumbnail_use) + file_set = Wings::Works::AddFileToFileSet.call(file_set: file_set, file: image_file, type: thumbnail_use) + Wings::Works::AddFileToFileSet.call(file_set: file_set, file: text_file, type: extracted_text_use) end context 'and use_valkyrie is false' do @@ -187,7 +187,7 @@ result = query_handler.find_many_file_metadata_by_use(resource: file_set, use: extracted_text_use, use_valkyrie: true) expect(result.size).to eq 1 expect(result.first).to be_a Hyrax::FileMetadata - expect(result.first.type).to include extracted_text_use + expect(result.first.pcdm_use).to include extracted_text_use end end end diff --git a/spec/wings/valkyrie/persister_spec.rb b/spec/wings/valkyrie/persister_spec.rb index 9709841018..d5bfa15b87 100644 --- a/spec/wings/valkyrie/persister_spec.rb +++ b/spec/wings/valkyrie/persister_spec.rb @@ -201,7 +201,7 @@ class Book < ActiveFedora::Base it "uses OriginalFile as type by default" do expect(persister.save(resource: resource)) - .to have_attributes(type: contain_exactly(RDF::URI("http://pcdm.org/use#OriginalFile"))) + .to have_attributes(pcdm_use: contain_exactly(RDF::URI("http://pcdm.org/use#OriginalFile"))) end it "saves file metadata attributes" do diff --git a/spec/wings/valkyrie/storage_spec.rb b/spec/wings/valkyrie/storage_spec.rb index 1ee2f97284..a4eba55ac5 100644 --- a/spec/wings/valkyrie/storage_spec.rb +++ b/spec/wings/valkyrie/storage_spec.rb @@ -60,7 +60,7 @@ .to have_attributes original_filename: file.original_filename, mime_type: 'image/png', file_identifier: upload.id, - size: [file.size] + recorded_size: [file.size] end it 'can find content from its metadata node ' do