From 4787234662446e59a03700f51666e91954b48f62 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Tue, 6 Aug 2024 12:10:29 -0700 Subject: [PATCH 1/6] Adds support to set filename on an uploaded file works with bulkrax: handle-remote-files-for-valkyrie --- .../hyrax/uploaded_file_uploader_decorator.rb | 15 +++++++++++++++ ...40806161142_add_file_name_to_uploaded_files.rb | 5 +++++ 2 files changed, 20 insertions(+) create mode 100644 app/uploaders/hyrax/uploaded_file_uploader_decorator.rb create mode 100644 db/migrate/20240806161142_add_file_name_to_uploaded_files.rb diff --git a/app/uploaders/hyrax/uploaded_file_uploader_decorator.rb b/app/uploaders/hyrax/uploaded_file_uploader_decorator.rb new file mode 100644 index 00000000..16bc2da7 --- /dev/null +++ b/app/uploaders/hyrax/uploaded_file_uploader_decorator.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true +module Hyrax + module UploadedFileUploaderDecorator + # Override Hyrax 5 to fetch the filename if available + def filename + original_file_name || super + end + + def original_file_name + model.filename + end + end +end + +Hyrax::UploadedFileUploader.prepend(Hyrax::UploadedFileUploaderDecorator) \ No newline at end of file diff --git a/db/migrate/20240806161142_add_file_name_to_uploaded_files.rb b/db/migrate/20240806161142_add_file_name_to_uploaded_files.rb new file mode 100644 index 00000000..c9633510 --- /dev/null +++ b/db/migrate/20240806161142_add_file_name_to_uploaded_files.rb @@ -0,0 +1,5 @@ +class AddFileNameToUploadedFiles < ActiveRecord::Migration[6.1] + def change + add_column :uploaded_files, :filename, :string + end +end From 0d9bb61a3991782e24b5196a36c1dcc8de199e84 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 7 Aug 2024 07:17:08 -0700 Subject: [PATCH 2/6] adds override_default_thumbnail property to fileset metadata --- config/metadata/file_set_metadata.yaml | 158 +++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 config/metadata/file_set_metadata.yaml diff --git a/config/metadata/file_set_metadata.yaml b/config/metadata/file_set_metadata.yaml new file mode 100644 index 00000000..3b049a30 --- /dev/null +++ b/config/metadata/file_set_metadata.yaml @@ -0,0 +1,158 @@ +# This is the metadata used for `Hyrax::FileSet`s.` It is similar to +# `basic_metadata.yaml`, but not exactly the same. +# +# Terms which are already present in `core_metadata.yaml` are not repeated here. +attributes: + # Required attributes: + creator: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "creator_tesim" + predicate: http://purl.org/dc/elements/1.1/creator + license: + type: string + multiple: true + form: + required: false + primary: true + predicate: http://purl.org/dc/terms/license + index_keys: + - "license_tesim" + + # Other attributes: + abstract: + type: string + multiple: true + predicate: http://purl.org/dc/terms/abstract + # form: + # primary: false + # missing: access_right + # missing: alternative_title + based_near: + type: string + multiple: true + form: + primary: false + index_keys: + - "based_near_sim" + - "based_near_tesim" + predicate: http://xmlns.com/foaf/0.1/based_near + # missing: bibliograpic_citation + contributor: + type: string + multiple: true + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/contributor + # required: creator + date_created: + type: date_time + multiple: true + form: + primary: false + index_keys: + - "date_created_tesim" + predicate: http://purl.org/dc/terms/created + description: + type: string + multiple: true + form: + primary: false + index_keys: + - "description_tesim" + predicate: http://purl.org/dc/elements/1.1/description + identifier: + type: string + multiple: true + form: + primary: false + predicate: http://purl.org/dc/terms/identifier + # missing: import_url + keyword: + type: string + multiple: true + form: + primary: false + index_keys: + - "keyword_sim" + - "keyword_tesim" + predicate: http://schema.org/keywords + # missing: publisher + label: + type: string + predicate: info:fedora/fedora-system:def/model#downloadFilename + # form: + # primary: false + language: + type: string + multiple: true + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/language + # required: license + publisher: + type: string + multiple: true + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/publisher + related_url: + type: string + multiple: true + form: + primary: false + index_keys: + - "related_url_tesim" + predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso + relative_path: + type: string + predicate: http://scholarsphere.psu.edu/ns#relativePath + resource_type: + type: string + multiple: true + # form: + # primary: false + index_keys: + - "resource_type_sim" + - "resource_type_tesim" + predicate: http://purl.org/dc/terms/type + rights_notes: + type: string + multiple: true + predicate: http://purl.org/dc/elements/1.1/rights + # form: + # primary: false + rights_statement: + type: string + multiple: true + # form: + # primary: true + index_keys: + - "rights_statement_tesim" + predicate: http://www.europeana.eu/schemas/edm/rights + source: + type: string + multiple: true + predicate: http://purl.org/dc/terms/source + # form: + # primary: false + subject: + type: string + multiple: true + form: + primary: false + index_keys: + - "subject_sim" + - "subject_tesim" + predicate: http://purl.org/dc/elements/1.1/subject + override_default_thumbnail: + type: string + form: + primary: false + predicate: https://b2.adventistdigitallibrary.org/terms/overrideDefaultThumbnail + index_keys: + - "override_default_thumbnail_ssi" \ No newline at end of file From fa6d3ea5c6309b5af5cc61f684ea5e237708008e Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 7 Aug 2024 10:30:30 -0700 Subject: [PATCH 3/6] Delete file_set_metadata.yaml the override thumbnail feature was intentionally deprecated. ref: - https://github.com/scientist-softserv/adventist-dl/blob/main/app/models/concerns/bulkrax/has_local_processing.rb#L9-L11 --- config/metadata/file_set_metadata.yaml | 158 ------------------------- 1 file changed, 158 deletions(-) delete mode 100644 config/metadata/file_set_metadata.yaml diff --git a/config/metadata/file_set_metadata.yaml b/config/metadata/file_set_metadata.yaml deleted file mode 100644 index 3b049a30..00000000 --- a/config/metadata/file_set_metadata.yaml +++ /dev/null @@ -1,158 +0,0 @@ -# This is the metadata used for `Hyrax::FileSet`s.` It is similar to -# `basic_metadata.yaml`, but not exactly the same. -# -# Terms which are already present in `core_metadata.yaml` are not repeated here. -attributes: - # Required attributes: - creator: - type: string - multiple: true - form: - required: true - primary: true - index_keys: - - "creator_tesim" - predicate: http://purl.org/dc/elements/1.1/creator - license: - type: string - multiple: true - form: - required: false - primary: true - predicate: http://purl.org/dc/terms/license - index_keys: - - "license_tesim" - - # Other attributes: - abstract: - type: string - multiple: true - predicate: http://purl.org/dc/terms/abstract - # form: - # primary: false - # missing: access_right - # missing: alternative_title - based_near: - type: string - multiple: true - form: - primary: false - index_keys: - - "based_near_sim" - - "based_near_tesim" - predicate: http://xmlns.com/foaf/0.1/based_near - # missing: bibliograpic_citation - contributor: - type: string - multiple: true - form: - primary: false - predicate: http://purl.org/dc/elements/1.1/contributor - # required: creator - date_created: - type: date_time - multiple: true - form: - primary: false - index_keys: - - "date_created_tesim" - predicate: http://purl.org/dc/terms/created - description: - type: string - multiple: true - form: - primary: false - index_keys: - - "description_tesim" - predicate: http://purl.org/dc/elements/1.1/description - identifier: - type: string - multiple: true - form: - primary: false - predicate: http://purl.org/dc/terms/identifier - # missing: import_url - keyword: - type: string - multiple: true - form: - primary: false - index_keys: - - "keyword_sim" - - "keyword_tesim" - predicate: http://schema.org/keywords - # missing: publisher - label: - type: string - predicate: info:fedora/fedora-system:def/model#downloadFilename - # form: - # primary: false - language: - type: string - multiple: true - form: - primary: false - predicate: http://purl.org/dc/elements/1.1/language - # required: license - publisher: - type: string - multiple: true - form: - primary: false - predicate: http://purl.org/dc/elements/1.1/publisher - related_url: - type: string - multiple: true - form: - primary: false - index_keys: - - "related_url_tesim" - predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso - relative_path: - type: string - predicate: http://scholarsphere.psu.edu/ns#relativePath - resource_type: - type: string - multiple: true - # form: - # primary: false - index_keys: - - "resource_type_sim" - - "resource_type_tesim" - predicate: http://purl.org/dc/terms/type - rights_notes: - type: string - multiple: true - predicate: http://purl.org/dc/elements/1.1/rights - # form: - # primary: false - rights_statement: - type: string - multiple: true - # form: - # primary: true - index_keys: - - "rights_statement_tesim" - predicate: http://www.europeana.eu/schemas/edm/rights - source: - type: string - multiple: true - predicate: http://purl.org/dc/terms/source - # form: - # primary: false - subject: - type: string - multiple: true - form: - primary: false - index_keys: - - "subject_sim" - - "subject_tesim" - predicate: http://purl.org/dc/elements/1.1/subject - override_default_thumbnail: - type: string - form: - primary: false - predicate: https://b2.adventistdigitallibrary.org/terms/overrideDefaultThumbnail - index_keys: - - "override_default_thumbnail_ssi" \ No newline at end of file From ad938c18722aa93d0b8ea3c3d9ce8adfb7ea8f63 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Wed, 7 Aug 2024 14:42:54 -0400 Subject: [PATCH 4/6] Handle bulkrax thumbnail url OAI import was not using the thumbnail url. --- .../concerns/bulkrax/has_local_processing.rb | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/models/concerns/bulkrax/has_local_processing.rb diff --git a/app/models/concerns/bulkrax/has_local_processing.rb b/app/models/concerns/bulkrax/has_local_processing.rb new file mode 100644 index 00000000..226fd727 --- /dev/null +++ b/app/models/concerns/bulkrax/has_local_processing.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Bulkrax + module HasLocalProcessing + # This method is called during build_metadata + # add any special processing here, for example to reset a metadata property + # to add a custom property from outside of the import data + def add_local + # Because of the DerivativeRodeo and SpaceStone, we may already have the appropriate thumbnail + # ready to attach to the file_sets. If we proceed with using the thumbnail_url, we end up + # attaching that thumbnail as it's own file_set. Which is likely non-desirous behavior. + # + each_candidate_metadata_node do |node| + raw_metadata['thumbnail_url'] = node.content if node.name == 'thumbnail_url' + end if self.respond_to?(:each_candidate_metadata_node) + + if parser.parser_fields['skip_thumbnail_url'] == "1" + parsed_metadata.delete('thumbnail_url') + elsif raw_metadata['thumbnail_url'] + parsed_metadata['thumbnail_url'] = parse_thumbnail_url(raw_metadata['thumbnail_url']) + end + end + + def parse_thumbnail_url(src) + return if src.blank? + src.strip! + name = Bulkrax::Importer.safe_uri_filename(src) + { url: src, file_name: name, default_thumbnail: "true" } + end + end +end From f2e638673892900659e1ed4b76b2d23a79e12e1c Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 7 Aug 2024 15:44:23 -0700 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=99=83=20re=20adds=20override=5Fdefau?= =?UTF-8?q?lt=5Fthumbnail=20to=20fileset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/metadata/file_set_metadata.yaml | 158 +++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 config/metadata/file_set_metadata.yaml diff --git a/config/metadata/file_set_metadata.yaml b/config/metadata/file_set_metadata.yaml new file mode 100644 index 00000000..3b049a30 --- /dev/null +++ b/config/metadata/file_set_metadata.yaml @@ -0,0 +1,158 @@ +# This is the metadata used for `Hyrax::FileSet`s.` It is similar to +# `basic_metadata.yaml`, but not exactly the same. +# +# Terms which are already present in `core_metadata.yaml` are not repeated here. +attributes: + # Required attributes: + creator: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "creator_tesim" + predicate: http://purl.org/dc/elements/1.1/creator + license: + type: string + multiple: true + form: + required: false + primary: true + predicate: http://purl.org/dc/terms/license + index_keys: + - "license_tesim" + + # Other attributes: + abstract: + type: string + multiple: true + predicate: http://purl.org/dc/terms/abstract + # form: + # primary: false + # missing: access_right + # missing: alternative_title + based_near: + type: string + multiple: true + form: + primary: false + index_keys: + - "based_near_sim" + - "based_near_tesim" + predicate: http://xmlns.com/foaf/0.1/based_near + # missing: bibliograpic_citation + contributor: + type: string + multiple: true + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/contributor + # required: creator + date_created: + type: date_time + multiple: true + form: + primary: false + index_keys: + - "date_created_tesim" + predicate: http://purl.org/dc/terms/created + description: + type: string + multiple: true + form: + primary: false + index_keys: + - "description_tesim" + predicate: http://purl.org/dc/elements/1.1/description + identifier: + type: string + multiple: true + form: + primary: false + predicate: http://purl.org/dc/terms/identifier + # missing: import_url + keyword: + type: string + multiple: true + form: + primary: false + index_keys: + - "keyword_sim" + - "keyword_tesim" + predicate: http://schema.org/keywords + # missing: publisher + label: + type: string + predicate: info:fedora/fedora-system:def/model#downloadFilename + # form: + # primary: false + language: + type: string + multiple: true + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/language + # required: license + publisher: + type: string + multiple: true + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/publisher + related_url: + type: string + multiple: true + form: + primary: false + index_keys: + - "related_url_tesim" + predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso + relative_path: + type: string + predicate: http://scholarsphere.psu.edu/ns#relativePath + resource_type: + type: string + multiple: true + # form: + # primary: false + index_keys: + - "resource_type_sim" + - "resource_type_tesim" + predicate: http://purl.org/dc/terms/type + rights_notes: + type: string + multiple: true + predicate: http://purl.org/dc/elements/1.1/rights + # form: + # primary: false + rights_statement: + type: string + multiple: true + # form: + # primary: true + index_keys: + - "rights_statement_tesim" + predicate: http://www.europeana.eu/schemas/edm/rights + source: + type: string + multiple: true + predicate: http://purl.org/dc/terms/source + # form: + # primary: false + subject: + type: string + multiple: true + form: + primary: false + index_keys: + - "subject_sim" + - "subject_tesim" + predicate: http://purl.org/dc/elements/1.1/subject + override_default_thumbnail: + type: string + form: + primary: false + predicate: https://b2.adventistdigitallibrary.org/terms/overrideDefaultThumbnail + index_keys: + - "override_default_thumbnail_ssi" \ No newline at end of file From bf0aea4ad01f5d39745fdfa960de7cf2f7f87f5e Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Tue, 13 Aug 2024 17:27:59 -0400 Subject: [PATCH 6/6] Set thumbnail id via remote files - Refactors some previous remote_files logic, including moving the migration to Bulkrax since the new column is used in bulkrax. - Supports overriding the standard thumbnail via the thumbnail_url coming through the bulkrax import data. - Modifies registering custom queries so they don't get clobbered. --- .../concerns/bulkrax/has_local_processing.rb | 3 ++- .../hyrax/work_uploads_handler_decorator.rb | 25 +++++++++++++++++++ .../listeners/file_set_thumbnail_listener.rb | 15 +++++++++++ .../initializers/hyku_knapsack_listeners.rb | 1 + config/initializers/wings.rb | 9 +++++++ ...6161142_add_file_name_to_uploaded_files.rb | 5 ---- 6 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 app/services/hyrax/work_uploads_handler_decorator.rb create mode 100644 app/services/listeners/file_set_thumbnail_listener.rb delete mode 100644 db/migrate/20240806161142_add_file_name_to_uploaded_files.rb diff --git a/app/models/concerns/bulkrax/has_local_processing.rb b/app/models/concerns/bulkrax/has_local_processing.rb index 226fd727..f94446d6 100644 --- a/app/models/concerns/bulkrax/has_local_processing.rb +++ b/app/models/concerns/bulkrax/has_local_processing.rb @@ -19,13 +19,14 @@ def add_local elsif raw_metadata['thumbnail_url'] parsed_metadata['thumbnail_url'] = parse_thumbnail_url(raw_metadata['thumbnail_url']) end + self end def parse_thumbnail_url(src) return if src.blank? src.strip! name = Bulkrax::Importer.safe_uri_filename(src) - { url: src, file_name: name, default_thumbnail: "true" } + { url: src, file_name: name, override_default_thumbnail: "true" } end end end diff --git a/app/services/hyrax/work_uploads_handler_decorator.rb b/app/services/hyrax/work_uploads_handler_decorator.rb new file mode 100644 index 00000000..2c1bfc1f --- /dev/null +++ b/app/services/hyrax/work_uploads_handler_decorator.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# OVERRIDE Hyrax 5 to customize file_set_args for thumbnail override +module Hyrax + module WorkUploadsHandlerDecorator + private + + ## + # @api private + # + # @return [Hash{Symbol => Object}] + def file_set_args(file) + { depositor: file.user.user_key, + creator: file.user.user_key, + date_uploaded: file.created_at, + date_modified: Hyrax::TimeService.time_in_utc, + label: file.uploader.filename, + title: file.uploader.filename, + override_default_thumbnail: file_set_extra_params(file)["override_default_thumbnail"] + } + end + end +end + +Hyrax::WorkUploadsHandler.prepend(Hyrax::WorkUploadsHandlerDecorator) diff --git a/app/services/listeners/file_set_thumbnail_listener.rb b/app/services/listeners/file_set_thumbnail_listener.rb new file mode 100644 index 00000000..70cbfd3f --- /dev/null +++ b/app/services/listeners/file_set_thumbnail_listener.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Listeners + class FileSetThumbnailListener + def on_file_set_attached(event) + file_set = event.payload[:file_set] + work = Hyrax.custom_queries.find_parent_work(resource: file_set) + return if work.thumbnail_id.present? && file_set.override_default_thumbnail != 'true' + # add the file_set as the work's thumbnail + work.thumbnail_id = file_set.id + Hyrax.persister.save(resource: work) + Hyrax.index_adapter.save(resource: work) + end + end +end diff --git a/config/initializers/hyku_knapsack_listeners.rb b/config/initializers/hyku_knapsack_listeners.rb index 13ab5612..383b1046 100644 --- a/config/initializers/hyku_knapsack_listeners.rb +++ b/config/initializers/hyku_knapsack_listeners.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true Hyrax.publisher.subscribe(Listeners::SlugsListener.new) +Hyrax.publisher.subscribe(Listeners::FileSetThumbnailListener.new) \ No newline at end of file diff --git a/config/initializers/wings.rb b/config/initializers/wings.rb index 6f323857..75485668 100644 --- a/config/initializers/wings.rb +++ b/config/initializers/wings.rb @@ -45,5 +45,14 @@ klass_name.constantize end end + + Valkyrie::MetadataAdapter.register( + Freyja::MetadataAdapter.new, + :freyja + ) + Valkyrie.config.metadata_adapter = :freyja + + Hyrax.query_service.services[0].custom_queries.register_query_handler(Hyrax::CustomQueries::FindBySlug) + Hyrax.query_service.services[1].custom_queries.register_query_handler(Wings::CustomQueries::FindBySlug) end # rubocop:enable Metrics/BlockLength diff --git a/db/migrate/20240806161142_add_file_name_to_uploaded_files.rb b/db/migrate/20240806161142_add_file_name_to_uploaded_files.rb deleted file mode 100644 index c9633510..00000000 --- a/db/migrate/20240806161142_add_file_name_to_uploaded_files.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddFileNameToUploadedFiles < ActiveRecord::Migration[6.1] - def change - add_column :uploaded_files, :filename, :string - end -end