Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oai customizations #735

Merged
merged 8 commits into from
Aug 14, 2024
Merged
32 changes: 32 additions & 0 deletions app/models/concerns/bulkrax/has_local_processing.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions app/services/hyrax/work_uploads_handler_decorator.rb
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions app/services/listeners/file_set_thumbnail_listener.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions app/uploaders/hyrax/uploaded_file_uploader_decorator.rb
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions config/initializers/hyku_knapsack_listeners.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

Hyrax.publisher.subscribe(Listeners::SlugsListener.new)
Hyrax.publisher.subscribe(Listeners::FileSetThumbnailListener.new)
9 changes: 9 additions & 0 deletions config/initializers/wings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
158 changes: 158 additions & 0 deletions config/metadata/file_set_metadata.yaml
Original file line number Diff line number Diff line change
@@ -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"