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..f94446d6 --- /dev/null +++ b/app/models/concerns/bulkrax/has_local_processing.rb @@ -0,0 +1,32 @@ +# 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 + 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, 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/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/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/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