From 1b17a77ed3571e9a7fa778edfcaa6f452cff2d8d Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Wed, 15 May 2024 11:45:03 -0700 Subject: [PATCH 01/28] Ran generator for EtdResource ```sh bundle exec rails generate hyku_knapsack:work_resource EtdResource ``` --- .../hyrax/etd_resources_controller.rb | 18 ++++++++++++++ app/forms/etd_resource_form.rb | 20 ++++++++++++++++ app/indexers/etd_resource_indexer.rb | 21 ++++------------ app/models/etd_resource.rb | 19 +++++++++++++++ .../etd_resources/_etd_resource.html.erb | 2 ++ config/initializers/hyrax.rb | 2 ++ config/metadata/etd_resource.yaml | 24 +++++++++++++++++++ spec/indexers/etd_resource_indexer_spec.rb | 13 ++++++++++ spec/models/etd_resource_spec.rb | 12 ++++++++++ .../_etd_resource.html.erb_spec.rb | 7 ++++++ 10 files changed, 122 insertions(+), 16 deletions(-) create mode 100644 app/controllers/hyrax/etd_resources_controller.rb create mode 100644 app/forms/etd_resource_form.rb create mode 100644 app/models/etd_resource.rb create mode 100644 app/views/hyrax/etd_resources/_etd_resource.html.erb create mode 100644 config/metadata/etd_resource.yaml create mode 100644 spec/indexers/etd_resource_indexer_spec.rb create mode 100644 spec/models/etd_resource_spec.rb create mode 100644 spec/views/etd_resources/_etd_resource.html.erb_spec.rb diff --git a/app/controllers/hyrax/etd_resources_controller.rb b/app/controllers/hyrax/etd_resources_controller.rb new file mode 100644 index 0000000..10f8c99 --- /dev/null +++ b/app/controllers/hyrax/etd_resources_controller.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource EtdResource` +module Hyrax + # Generated controller for EtdResource + class EtdResourcesController < ApplicationController + # Adds Hyrax behaviors to the controller. + include Hyrax::WorksControllerBehavior + include Hyku::WorksControllerBehavior + include Hyrax::BreadcrumbsForWorks + self.curation_concern_type = ::EtdResource + + # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style + # forms. + self.work_form_service = Hyrax::FormFactory.new + end +end diff --git a/app/forms/etd_resource_form.rb b/app/forms/etd_resource_form.rb new file mode 100644 index 0000000..bd0cd54 --- /dev/null +++ b/app/forms/etd_resource_form.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource EtdResource` +# +# @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms +# @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking +class EtdResourceForm < Hyrax::Forms::PcdmObjectForm(EtdResource) + include Hyrax::FormFields(:basic_metadata) + include Hyrax::FormFields(:etd_resource) + + # Define custom form fields using the Valkyrie::ChangeSet interface + # + # property :my_custom_form_field + + # if you want a field in the form, but it doesn't have a directly corresponding + # model attribute, make it virtual + # + # property :user_input_not_destined_for_the_model, virtual: true +end diff --git a/app/indexers/etd_resource_indexer.rb b/app/indexers/etd_resource_indexer.rb index 5c4580e..735e4c0 100644 --- a/app/indexers/etd_resource_indexer.rb +++ b/app/indexers/etd_resource_indexer.rb @@ -1,22 +1,11 @@ # frozen_string_literal: true - -# TODO: temporarily added to see if iiif print engine spec error would resolve. (it did) -# so some of the spec failures is because the models haven't been -# valkyrized - # Generated via -# `rails generate hyrax:work_resource GenericWorkResource` -class EtdResourceIndexer < Hyrax::ValkyrieWorkIndexer - # TODO: specify custom properties for this work type - - # include Hyrax::Indexer(:basic_metadata) - # include Hyrax::Indexer(:bulkrax_metadata) - # include Hyrax::Indexer(:generic_work_resource) - # include Hyrax::Indexer(:with_pdf_viewer) - # include Hyrax::Indexer(:with_video_embed) +# `rails generate hyrax:work_resource EtdResource` +class EtdResourceIndexer < Hyrax::Indexers::PcdmObjectIndexer(EtdResource) + include Hyrax::Indexer(:basic_metadata) + include Hyrax::Indexer(:etd_resource) - include HykuIndexing # Uncomment this block if you want to add custom indexing behavior: # def to_solr # super.tap do |index_document| @@ -24,4 +13,4 @@ class EtdResourceIndexer < Hyrax::ValkyrieWorkIndexer # index_document[:other_field_ssim] = resource.other_field # end # end -end \ No newline at end of file +end diff --git a/app/models/etd_resource.rb b/app/models/etd_resource.rb new file mode 100644 index 0000000..5ab4889 --- /dev/null +++ b/app/models/etd_resource.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource EtdResource` +class EtdResource < Hyrax::Work + include Hyrax::Schema(:basic_metadata) + include Hyrax::Schema(:etd_resource) + include Hyrax::Schema(:with_pdf_viewer) + include Hyrax::Schema(:with_video_embed) + include Hyrax::ArResource + include Hyrax::NestedWorks + + include IiifPrint.model_configuration( + pdf_split_child_model: GenericWorkResource, + pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter + ) + + prepend OrderAlready.for(:creator) +end diff --git a/app/views/hyrax/etd_resources/_etd_resource.html.erb b/app/views/hyrax/etd_resources/_etd_resource.html.erb new file mode 100644 index 0000000..f71dd2d --- /dev/null +++ b/app/views/hyrax/etd_resources/_etd_resource.html.erb @@ -0,0 +1,2 @@ +<%# This is a search result view %> +<%= render 'catalog/document', document: etd_resource, document_counter: etd_resource_counter %> diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index 4f98894..da2ce5e 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -9,6 +9,8 @@ config.register_curation_concern :etd # # Injected via `rails g hyrax:work Cdl` # config.register_curation_concern :cdl + # Injected via `rails g hyrax:work_resource EtdResource` + config.register_curation_concern :etd_resource # # See https://github.com/scientist-softserv/adventist-dl/issues/183 # # Also, we will continue to extract txt file's text using Adventist::TextFileTextExtractionService diff --git a/config/metadata/etd_resource.yaml b/config/metadata/etd_resource.yaml new file mode 100644 index 0000000..f9e15fb --- /dev/null +++ b/config/metadata/etd_resource.yaml @@ -0,0 +1,24 @@ +# Simple yaml config-driven schema which is used to define model attributes, +# index key names, and form properties. +# +# Attributes must have a type but all other configuration options are optional. +# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes +# must be placed here. +# +# attributes: +# attribute_name: +# type: string +# multiple: false +# index_keys: +# - "attribute_name_sim" +# form: +# required: true +# primary: true +# multiple: false +# +# @see config/metadata/basic_metadata.yaml for an example configuration +# +# Generated via +# `rails generate hyrax:work_resource EtdResource` + +attributes: {} diff --git a/spec/indexers/etd_resource_indexer_spec.rb b/spec/indexers/etd_resource_indexer_spec.rb new file mode 100644 index 0000000..88dc315 --- /dev/null +++ b/spec/indexers/etd_resource_indexer_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource EtdResource` +require 'rails_helper' +require 'hyrax/specs/shared_specs/indexers' + +RSpec.describe EtdResourceIndexer do + let(:indexer_class) { described_class } + let(:resource) { EtdResource.new } + + it_behaves_like 'a Hyrax::Resource indexer' +end diff --git a/spec/models/etd_resource_spec.rb b/spec/models/etd_resource_spec.rb new file mode 100644 index 0000000..3629e41 --- /dev/null +++ b/spec/models/etd_resource_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource EtdResource` +require 'rails_helper' +require 'hyrax/specs/shared_specs/hydra_works' + +RSpec.describe EtdResource do + subject(:work) { described_class.new } + + it_behaves_like 'a Hyrax::Work' +end diff --git a/spec/views/etd_resources/_etd_resource.html.erb_spec.rb b/spec/views/etd_resources/_etd_resource.html.erb_spec.rb new file mode 100644 index 0000000..3ade049 --- /dev/null +++ b/spec/views/etd_resources/_etd_resource.html.erb_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource EtdResource` +RSpec.describe 'etd_resources/etd_resource.html.erb', type: :view do # rubocop:disable RSpec/EmptyExampleGroup + # add etd_resource view specs +end From 7051ffbfe3a63a2d0b220cca5e6b7f4f91938fd0 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Wed, 15 May 2024 19:02:40 -0700 Subject: [PATCH 02/28] Correct EtdResoource properties and forms This commit will add the EtdResoource properties to match Etd --- app/forms/etd_resource_form.rb | 5 +- app/models/etd_resource.rb | 5 +- config/metadata/etd_resource.yaml | 329 +++++++++++++++++++++++++++++- 3 files changed, 336 insertions(+), 3 deletions(-) diff --git a/app/forms/etd_resource_form.rb b/app/forms/etd_resource_form.rb index bd0cd54..4029d2f 100644 --- a/app/forms/etd_resource_form.rb +++ b/app/forms/etd_resource_form.rb @@ -6,8 +6,11 @@ # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking class EtdResourceForm < Hyrax::Forms::PcdmObjectForm(EtdResource) - include Hyrax::FormFields(:basic_metadata) + # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. + # include Hyrax::FormFields(:basic_metadata) include Hyrax::FormFields(:etd_resource) + include Hyrax::FormFields(:with_pdf_viewer) + include Hyrax::FormFields(:with_video_embed) # Define custom form fields using the Valkyrie::ChangeSet interface # diff --git a/app/models/etd_resource.rb b/app/models/etd_resource.rb index 5ab4889..6d2ef34 100644 --- a/app/models/etd_resource.rb +++ b/app/models/etd_resource.rb @@ -3,13 +3,16 @@ # Generated via # `rails generate hyrax:work_resource EtdResource` class EtdResource < Hyrax::Work - include Hyrax::Schema(:basic_metadata) + # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. + # include Hyrax::Schema(:basic_metadata) include Hyrax::Schema(:etd_resource) include Hyrax::Schema(:with_pdf_viewer) include Hyrax::Schema(:with_video_embed) include Hyrax::ArResource include Hyrax::NestedWorks + Hyrax::ValkyrieLazyMigration.migrating(self, from: Etd) + include IiifPrint.model_configuration( pdf_split_child_model: GenericWorkResource, pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter diff --git a/config/metadata/etd_resource.yaml b/config/metadata/etd_resource.yaml index f9e15fb..e50d6f7 100644 --- a/config/metadata/etd_resource.yaml +++ b/config/metadata/etd_resource.yaml @@ -21,4 +21,331 @@ # Generated via # `rails generate hyrax:work_resource EtdResource` -attributes: {} +attributes: + creator: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "creator_sim" + - "creator_tesim" + predicate: http://purl.org/dc/elements/1.1/creator + keyword: + type: string + multiple: true + index_keys: + - "keyword_sim" + - "keyword_tesim" + form: + primary: true + required: true + predicate: http://schema.org/keywords + rights_statement: + type: string + multiple: true + form: + primary: true + required: true + index_keys: + - "rights_statement_sim" + - "rights_statement_tesim" + predicate: http://www.europeana.eu/schemas/edm/rights + date: + type: string + multiple: true + index_keys: + - "date_tesim" + - "date_sim" + form: + required: true + primary: true + multiple: true + predicate: https://hykucommons.org/terms/date + degree_name: + type: string + multiple: true + index_keys: + - "degree_name_tesim" + form: + required: true + primary: true + multiple: true + predicate: https://hykucommons.org/terms/degree_name + degree_level: + type: string + multiple: true + index_keys: + - "degree_level_tesim" + form: + required: true + primary: true + multiple: true + predicate: https://hykucommons.org/terms/degree_level + degree_discipline: + type: string + multiple: true + index_keys: + - "degree_discipline_tesim" + form: + required: true + primary: true + multiple: true + predicate: https://hykucommons.org/terms/degree_discipline + degree_grantor: + type: string + multiple: true + index_keys: + - "degree_grantor_tesim" + form: + required: true + primary: true + multiple: true + predicate: https://hykucommons.org/terms/degree_grantor + resource_type: + type: string + multiple: true + form: + primary: true + multiple: true + required: true + index_keys: + - "resource_type_sim" + - "resource_type_tesim" + predicate: http://purl.org/dc/terms/type + license: + type: string + multiple: true + form: + primary: false + index_keys: + - "license_sim" + - "license_tesim" + predicate: http://purl.org/dc/terms/license + abstract: + type: string + multiple: true + form: + primary: false + index_keys: + - "abstract_sim" + - "abstract_tesim" + predicate: http://purl.org/dc/terms/abstract + access_right: + type: string + multiple: true + form: + primary: false + index_keys: + - "access_right_sim" + - "access_right_tesim" + predicate: http://purl.org/dc/terms/accessRights + additional_information: + type: string + multiple: true + index_keys: + - "additional_information_tesim" + form: + required: false + primary: false + multiple: true + predicate: http://purl.org/dc/terms/accessRights + admin_note: + type: string + multiple: false + index_keys: + - "admin_note_tesim" + form: + required: false + primary: false + multiple: false + predicate: http://schema.org/positiveNotes + advisor: + type: string + multiple: true + index_keys: + - "advisor_tesim" + form: + required: false + primary: false + multiple: true + predicate: https://hykucommons.org/terms/advisor + alternative_title: + type: string + multiple: true + form: + primary: false + index_keys: + - "alternative_title_sim" + - "alternative_title_tesim" + predicate: http://purl.org/dc/terms/alternative + 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 + bibliographic_citation: + type: string + multiple: true + form: + primary: false + index_keys: + - "bibliographic_citation_sim" + - "bibliographic_citation_tesim" + predicate: http://purl.org/dc/terms/bibliographicCitation + committee_member: + type: string + multiple: true + index_keys: + - "committee_member_tesim" + form: + required: false + primary: false + multiple: true + predicate: https://hykucommons.org/terms/committee_member + contributor: + type: string + multiple: true + form: + primary: false + index_keys: + - "contributor_tesim" + - "contributor_sim" + predicate: http://purl.org/dc/elements/1.1/contributor + department: + type: string + multiple: true + index_keys: + - "department_tesim" + form: + required: false + primary: false + multiple: true + predicate: https://hykucommons.org/terms/department + description: + type: string + multiple: true + form: + primary: false + index_keys: + - "description_sim" + - "description_tesim" + predicate: http://purl.org/dc/elements/1.1/description + format: + type: string + multiple: true + index_keys: + - "format_tesim" + form: + required: false + primary: false + multiple: true + predicate: http://purl.org/dc/terms/format + identifier: + type: string + multiple: true + form: + primary: false + index_keys: + - "identifier_sim" + - "identifier_tesim" + predicate: http://purl.org/dc/terms/identifier + language: + type: string + multiple: true + form: + primary: false + index_keys: + - "language_sim" + - "language_tesim" + predicate: http://purl.org/dc/elements/1.1/language + publisher: + type: string + multiple: true + form: + primary: false + index_keys: + - "publisher_sim" + - "publisher_tesim" + predicate: http://purl.org/dc/elements/1.1/publisher + related_url: + type: string + multiple: true + form: + primary: false + index_keys: + - "related_url_sim" + - "related_url_tesim" + predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso + rights_notes: + type: string + multiple: true + form: + primary: false + index_keys: + - "rights_notes_sim" + - "rights_notes_tesim" + predicate: http://purl.org/dc/elements/1.1/rights + source: + type: string + multiple: true + form: + primary: false + index_keys: + - "source_sim" + - "source_tesim" + predicate: http://purl.org/dc/terms/source + subject: + type: string + multiple: true + index_keys: + - "subject_sim" + - "subject_tesim" + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/subject + bulkrax_identifier: + type: string + multiple: false + index_keys: + - "bulkrax_identifier_sim" + - "bulkrax_identifier_tesim" + # form: + # required: false + # primary: false + # multiple: false + predicate: https://hykucommons.org/terms/bulkrax_identifier + arkivo_checksum: + type: string + multiple: false + # form: + # primary: false + predicate: http://scholarsphere.psu.edu/ns#arkivoChecksum + date_created: + type: date_time + multiple: true + # form: + # primary: false + index_keys: + - "date_created_sim" + - "date_created_tesim" + predicate: http://purl.org/dc/terms/created + import_url: + type: string + predicate: http://scholarsphere.psu.edu/ns#importUrl + label: + type: string + # form: + # primary: false + index_keys: + - "label_sim" + - "label_tesim" + predicate: info:fedora/fedora-system:def/model#downloadFilename + relative_path: + type: string + predicate: http://scholarsphere.psu.edu/ns#relativePath From 6518dd6506042b049c3a1c541cb99665ff7cf086 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Wed, 15 May 2024 19:23:22 -0700 Subject: [PATCH 03/28] Update WorkResourceGenerator This update will add the with_pdf_viewer and with_video_embed includes to the generated forms. --- .../work_resource/work_resource_generator.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/generators/hyku_knapsack/work_resource/work_resource_generator.rb b/lib/generators/hyku_knapsack/work_resource/work_resource_generator.rb index 067f816..54c821a 100644 --- a/lib/generators/hyku_knapsack/work_resource/work_resource_generator.rb +++ b/lib/generators/hyku_knapsack/work_resource/work_resource_generator.rb @@ -138,6 +138,14 @@ def insert_hyku_extra_includes_into_model end end + def insert_hyku_extra_includes_into_form + form = File.join('../app/forms/', class_path, "#{file_name}_form.rb") + insert_into_file form, after: "include Hyrax::FormFields(:#{file_name})\n" do + " include Hyrax::FormFields(:with_pdf_viewer)\n" \ + " include Hyrax::FormFields(:with_video_embed)\n" + end + end + private def rspec_installed? From 68fd0b7930d661cd1d23a794d0b22da5672aa447 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Wed, 15 May 2024 21:40:09 -0700 Subject: [PATCH 04/28] Update WorkResourceGenerator This update will include the lazy migration line if the work ends with 'Resource' and the 'migrating from' work already exists. --- .../hyku_knapsack/work_resource/work_resource_generator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/generators/hyku_knapsack/work_resource/work_resource_generator.rb b/lib/generators/hyku_knapsack/work_resource/work_resource_generator.rb index 54c821a..1fb9435 100644 --- a/lib/generators/hyku_knapsack/work_resource/work_resource_generator.rb +++ b/lib/generators/hyku_knapsack/work_resource/work_resource_generator.rb @@ -121,13 +121,14 @@ def insert_hyku_works_controller_behavior def insert_hyku_extra_includes_into_model model = File.join('../app/models/', class_path, "#{file_name}.rb") + af_model = "#{class_name}".gsub('Resource', '')&.safe_constantize if class_name.end_with?('Resource') insert_into_file model, before: "end" do <<-RUBY.gsub(/^ {8}/, ' ') include Hyrax::Schema(:with_pdf_viewer) include Hyrax::Schema(:with_video_embed) include Hyrax::ArResource include Hyrax::NestedWorks - + #{ "\n Hyrax::ValkyrieLazyMigration.migrating(self, from: #{af_model})\n" if af_model } include IiifPrint.model_configuration( pdf_split_child_model: GenericWorkResource, pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter From baa2aa4aeb47536090d90ccf8853ca6e7ff1b97f Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Wed, 15 May 2024 22:31:00 -0700 Subject: [PATCH 05/28] Ran generator for OerResource and update hyrax.rb ```sh bundle exec rails generate hyku_knapsack:work_resource OerResource ``` --- .../hyrax/oer_resources_controller.rb | 18 ++++++++++++++ app/forms/oer_resource_form.rb | 22 +++++++++++++++++ app/indexers/oer_resource_indexer.rb | 16 +++++++++++++ app/models/oer_resource.rb | 21 ++++++++++++++++ .../oer_resources/_oer_resource.html.erb | 2 ++ config/initializers/hyrax.rb | 4 +++- config/metadata/oer_resource.yaml | 24 +++++++++++++++++++ spec/indexers/oer_resource_indexer_spec.rb | 13 ++++++++++ spec/models/oer_resource_spec.rb | 12 ++++++++++ .../_oer_resource.html.erb_spec.rb | 7 ++++++ 10 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 app/controllers/hyrax/oer_resources_controller.rb create mode 100644 app/forms/oer_resource_form.rb create mode 100644 app/indexers/oer_resource_indexer.rb create mode 100644 app/models/oer_resource.rb create mode 100644 app/views/hyrax/oer_resources/_oer_resource.html.erb create mode 100644 config/metadata/oer_resource.yaml create mode 100644 spec/indexers/oer_resource_indexer_spec.rb create mode 100644 spec/models/oer_resource_spec.rb create mode 100644 spec/views/oer_resources/_oer_resource.html.erb_spec.rb diff --git a/app/controllers/hyrax/oer_resources_controller.rb b/app/controllers/hyrax/oer_resources_controller.rb new file mode 100644 index 0000000..ef85e14 --- /dev/null +++ b/app/controllers/hyrax/oer_resources_controller.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource OerResource` +module Hyrax + # Generated controller for OerResource + class OerResourcesController < ApplicationController + # Adds Hyrax behaviors to the controller. + include Hyrax::WorksControllerBehavior + include Hyku::WorksControllerBehavior + include Hyrax::BreadcrumbsForWorks + self.curation_concern_type = ::OerResource + + # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style + # forms. + self.work_form_service = Hyrax::FormFactory.new + end +end diff --git a/app/forms/oer_resource_form.rb b/app/forms/oer_resource_form.rb new file mode 100644 index 0000000..606a9a3 --- /dev/null +++ b/app/forms/oer_resource_form.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource OerResource` +# +# @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms +# @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking +class OerResourceForm < Hyrax::Forms::PcdmObjectForm(OerResource) + include Hyrax::FormFields(:basic_metadata) + include Hyrax::FormFields(:oer_resource) + include Hyrax::FormFields(:with_pdf_viewer) + include Hyrax::FormFields(:with_video_embed) + + # Define custom form fields using the Valkyrie::ChangeSet interface + # + # property :my_custom_form_field + + # if you want a field in the form, but it doesn't have a directly corresponding + # model attribute, make it virtual + # + # property :user_input_not_destined_for_the_model, virtual: true +end diff --git a/app/indexers/oer_resource_indexer.rb b/app/indexers/oer_resource_indexer.rb new file mode 100644 index 0000000..8284d39 --- /dev/null +++ b/app/indexers/oer_resource_indexer.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource OerResource` +class OerResourceIndexer < Hyrax::Indexers::PcdmObjectIndexer(OerResource) + include Hyrax::Indexer(:basic_metadata) + include Hyrax::Indexer(:oer_resource) + + # Uncomment this block if you want to add custom indexing behavior: + # def to_solr + # super.tap do |index_document| + # index_document[:my_field_tesim] = resource.my_field.map(&:to_s) + # index_document[:other_field_ssim] = resource.other_field + # end + # end +end diff --git a/app/models/oer_resource.rb b/app/models/oer_resource.rb new file mode 100644 index 0000000..e93740e --- /dev/null +++ b/app/models/oer_resource.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource OerResource` +class OerResource < Hyrax::Work + include Hyrax::Schema(:basic_metadata) + include Hyrax::Schema(:oer_resource) + include Hyrax::Schema(:with_pdf_viewer) + include Hyrax::Schema(:with_video_embed) + include Hyrax::ArResource + include Hyrax::NestedWorks + + Hyrax::ValkyrieLazyMigration.migrating(self, from: Oer) + + include IiifPrint.model_configuration( + pdf_split_child_model: GenericWorkResource, + pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter + ) + + prepend OrderAlready.for(:creator) +end diff --git a/app/views/hyrax/oer_resources/_oer_resource.html.erb b/app/views/hyrax/oer_resources/_oer_resource.html.erb new file mode 100644 index 0000000..53ae27d --- /dev/null +++ b/app/views/hyrax/oer_resources/_oer_resource.html.erb @@ -0,0 +1,2 @@ +<%# This is a search result view %> +<%= render 'catalog/document', document: oer_resource, document_counter: oer_resource_counter %> diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index da2ce5e..7dfbddd 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -4,13 +4,15 @@ Hyrax.config do |config| # TODO: Valkyrize models and update this initializer # Injected via `rails g hyrax:work Oer` - # config.register_curation_concern :oer + config.register_curation_concern :oer # Injected via `rails g hyrax:work Etd` config.register_curation_concern :etd # # Injected via `rails g hyrax:work Cdl` # config.register_curation_concern :cdl # Injected via `rails g hyrax:work_resource EtdResource` config.register_curation_concern :etd_resource + # Injected via `rails g hyrax:work_resource OerResource` + config.register_curation_concern :oer_resource # # See https://github.com/scientist-softserv/adventist-dl/issues/183 # # Also, we will continue to extract txt file's text using Adventist::TextFileTextExtractionService diff --git a/config/metadata/oer_resource.yaml b/config/metadata/oer_resource.yaml new file mode 100644 index 0000000..53ea4b5 --- /dev/null +++ b/config/metadata/oer_resource.yaml @@ -0,0 +1,24 @@ +# Simple yaml config-driven schema which is used to define model attributes, +# index key names, and form properties. +# +# Attributes must have a type but all other configuration options are optional. +# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes +# must be placed here. +# +# attributes: +# attribute_name: +# type: string +# multiple: false +# index_keys: +# - "attribute_name_sim" +# form: +# required: true +# primary: true +# multiple: false +# +# @see config/metadata/basic_metadata.yaml for an example configuration +# +# Generated via +# `rails generate hyrax:work_resource OerResource` + +attributes: {} diff --git a/spec/indexers/oer_resource_indexer_spec.rb b/spec/indexers/oer_resource_indexer_spec.rb new file mode 100644 index 0000000..bbb63d9 --- /dev/null +++ b/spec/indexers/oer_resource_indexer_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource OerResource` +require 'rails_helper' +require 'hyrax/specs/shared_specs/indexers' + +RSpec.describe OerResourceIndexer do + let(:indexer_class) { described_class } + let(:resource) { OerResource.new } + + it_behaves_like 'a Hyrax::Resource indexer' +end diff --git a/spec/models/oer_resource_spec.rb b/spec/models/oer_resource_spec.rb new file mode 100644 index 0000000..421ea08 --- /dev/null +++ b/spec/models/oer_resource_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource OerResource` +require 'rails_helper' +require 'hyrax/specs/shared_specs/hydra_works' + +RSpec.describe OerResource do + subject(:work) { described_class.new } + + it_behaves_like 'a Hyrax::Work' +end diff --git a/spec/views/oer_resources/_oer_resource.html.erb_spec.rb b/spec/views/oer_resources/_oer_resource.html.erb_spec.rb new file mode 100644 index 0000000..cef97a7 --- /dev/null +++ b/spec/views/oer_resources/_oer_resource.html.erb_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource OerResource` +RSpec.describe 'oer_resources/oer_resource.html.erb', type: :view do # rubocop:disable RSpec/EmptyExampleGroup + # add oer_resource view specs +end From 1cccec283f63fa51fdf9425b487d2dd36f4829e7 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Thu, 16 May 2024 05:17:25 -0700 Subject: [PATCH 06/28] Correct OerResoource properties and forms This commit will add the OerResoource properties to match Oer and also fixes a view bug for table_of_contents. --- app/forms/oer_resource_form.rb | 57 ++- app/models/oer_resource.rb | 19 +- .../edit_fields/_table_of_contents.html.erb | 3 +- config/metadata/oer_resource.yaml | 365 +++++++++++++++++- 4 files changed, 439 insertions(+), 5 deletions(-) diff --git a/app/forms/oer_resource_form.rb b/app/forms/oer_resource_form.rb index 606a9a3..af7f481 100644 --- a/app/forms/oer_resource_form.rb +++ b/app/forms/oer_resource_form.rb @@ -6,7 +6,8 @@ # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking class OerResourceForm < Hyrax::Forms::PcdmObjectForm(OerResource) - include Hyrax::FormFields(:basic_metadata) + # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. + # include Hyrax::FormFields(:basic_metadata) include Hyrax::FormFields(:oer_resource) include Hyrax::FormFields(:with_pdf_viewer) include Hyrax::FormFields(:with_video_embed) @@ -19,4 +20,58 @@ class OerResourceForm < Hyrax::Forms::PcdmObjectForm(OerResource) # model attribute, make it virtual # # property :user_input_not_destined_for_the_model, virtual: true + + delegate :related_members_attributes=, :previous_version, :newer_version, :alternate_version, :related_item, to: :model + + def self.build_permitted_params + super + [ + { + related_members_attributes: %i[id _destroy relationship] + } + ] + end + + def previous_version_json + previous_version.map do |child| + { + id: child.id, + label: child.to_s, + path: @controller.url_for(child), + relationship: "previous-version" + } + end.to_json + end + + def newer_version_json + newer_version.map do |child| + { + id: child.id, + label: child.to_s, + path: @controller.url_for(child), + relationship: "newer-version" + } + end.to_json + end + + def alternate_version_json + alternate_version.map do |child| + { + id: child.id, + label: child.to_s, + path: @controller.url_for(child), + relationship: "alternate-version" + } + end.to_json + end + + def related_item_json + related_item.map do |child| + { + id: child.id, + label: child.to_s, + path: @controller.url_for(child), + relationship: "related-item" + } + end.to_json + end end diff --git a/app/models/oer_resource.rb b/app/models/oer_resource.rb index e93740e..20c0681 100644 --- a/app/models/oer_resource.rb +++ b/app/models/oer_resource.rb @@ -3,7 +3,8 @@ # Generated via # `rails generate hyrax:work_resource OerResource` class OerResource < Hyrax::Work - include Hyrax::Schema(:basic_metadata) + # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. + # include Hyrax::Schema(:basic_metadata) include Hyrax::Schema(:oer_resource) include Hyrax::Schema(:with_pdf_viewer) include Hyrax::Schema(:with_video_embed) @@ -18,4 +19,20 @@ class OerResource < Hyrax::Work ) prepend OrderAlready.for(:creator) + + def previous_version + @previous_version ||= Hyrax.query_service.find_by(id: previous_version_id) if previous_version_id + end + + def newer_version + @newer_version ||= Hyrax.query_service.find_by(id: newer_version_id) if newer_version_id + end + + def alternate_version + @alternate_version ||= Hyrax.query_service.find_by(id: alternate_version_id) if alternate_version_id + end + + def related_item + @related_item ||= Hyrax.query_service.find_by(id: related_item_id) if related_item_id + end end diff --git a/app/views/records/edit_fields/_table_of_contents.html.erb b/app/views/records/edit_fields/_table_of_contents.html.erb index 9b631ac..c71ce2c 100644 --- a/app/views/records/edit_fields/_table_of_contents.html.erb +++ b/app/views/records/edit_fields/_table_of_contents.html.erb @@ -1,6 +1,5 @@ -<% if curation_concern.class == Oer %> +<% if curation_concern.to_rdf_representation == 'Oer' %> <%= f.input :table_of_contents, as: :multi_value, - label: t("hyrax.oer.labels.table_of_contents"), hint: t("hyrax.oer.hints.table_of_contents"), input_html: { rows: '14', type: 'textarea'}, required: f.object.required?(key) %> <% end %> diff --git a/config/metadata/oer_resource.yaml b/config/metadata/oer_resource.yaml index 53ea4b5..4e798a1 100644 --- a/config/metadata/oer_resource.yaml +++ b/config/metadata/oer_resource.yaml @@ -21,4 +21,367 @@ # Generated via # `rails generate hyrax:work_resource OerResource` -attributes: {} +attributes: + creator: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "creator_sim" + - "creator_tesim" + predicate: http://purl.org/dc/elements/1.1/creator + resource_type: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "resource_type_sim" + - "resource_type_tesim" + predicate: http://purl.org/dc/terms/type + date_created: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "date_created_tesim" + predicate: http://purl.org/dc/terms/date + audience: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "audience_tesim" + - "audience_sim" + predicate: http://schema.org/EducationalAudience + education_level: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "education_level_tesim" + - "education_level_sim" + predicate: http://purl.org/dc/terms/educationLevel + learning_resource_type: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "learning_resource_type_tesim" + - "learning_resource_type_sim" + predicate: http://schema.org/learningResourceType + discipline: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "discipline_tesim" + predicate: https://hykucommons.org/terms/degree_discipline + rights_statement: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "rights_statement_sim" + - "rights_statement_tesim" + predicate: http://www.europeana.eu/schemas/edm/rights + license: + type: string + multiple: true + form: + primary: false + index_keys: + - "license_sim" + - "license_tesim" + predicate: http://purl.org/dc/terms/license + abstract: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "abstract_sim" + - "abstract_tesim" + predicate: http://purl.org/dc/terms/abstract + accessibility_feature: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "accessibility_feature_tesim" + - "accessibility_feature_sim" + predicate: http://schema.org/accessibilityFeature + accessibility_hazard: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "accessibility_hazard_tesim" + - "accessibility_hazard_sim" + predicate: http://schema.org/accessibilityHazard + accessibility_summary: + type: string + multiple: false + form: + primary: false + multiple: false + index_keys: + - "accessibility_summary_tesim" + - "accessibility_summary_sim" + predicate: http://schema.org/accessibilitySummary + additional_information: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "additional_information_tesim" + predicate: http://purl.org/dc/terms/accessRights + admin_note: + type: string + multiple: false + form: + primary: false + multiple: false + index_keys: + - "admin_note_tesim" + predicate: http://schema.org/positiveNotes + alternative_title: + type: string + multiple: true + form: + primary: false + index_keys: + - "alternative_title_sim" + - "alternative_title_tesim" + predicate: http://purl.org/dc/terms/alternative + bibliographic_citation: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "bibliographic_citation_sim" + - "bibliographic_citation_tesim" + predicate: http://purl.org/dc/terms/bibliographicCitation + contributor: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "contributor_tesim" + - "contributor_sim" + predicate: http://purl.org/dc/elements/1.1/contributor + description: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "description_sim" + - "description_tesim" + predicate: http://purl.org/dc/elements/1.1/description + identifier: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "identifier_sim" + - "identifier_tesim" + predicate: http://purl.org/dc/terms/identifier + keyword: + type: string + multiple: true + index_keys: + - "keyword_sim" + - "keyword_tesim" + form: + primary: false + multiple: true + predicate: http://schema.org/keywords + language: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "language_sim" + - "language_tesim" + predicate: http://purl.org/dc/elements/1.1/language + oer_size: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "oer_size_tesim" + predicate: http://purl.org/dc/terms/extent + publisher: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "publisher_sim" + - "publisher_tesim" + predicate: http://purl.org/dc/elements/1.1/publisher + related_url: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "related_url_sim" + - "related_url_tesim" + predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso + rights_holder: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "rights_holder_tesim" + - "rights_holder_sim" + predicate: http://purl.org/dc/terms/rightsHolder + rights_notes: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "rights_notes_tesim" + predicate: https://hykucommons.org/terms/rights_notes + source: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "source_sim" + - "source_tesim" + predicate: http://purl.org/dc/terms/source + subject: + type: string + multiple: true + index_keys: + - "subject_sim" + - "subject_tesim" + form: + primary: false + multiple: true + predicate: http://purl.org/dc/elements/1.1/subject + table_of_contents: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "table_of_contents_tesim" + predicate: http://purl.org/dc/terms/tableOfContents + bulkrax_identifier: + type: string + multiple: false + index_keys: + - "bulkrax_identifier_tesim" + - "bulkrax_identifier_sim" + predicate: https://hykucommons.org/terms/bulkrax_identifier" + previous_version_id: + type: string + multiple: true + index_keys: + - "previous_version_id_tesim" + - "previous_version_id_sim" + predicate: http://purl.org/dc/terms/replaces + newer_version_id: + type: string + multiple: true + index_keys: + - "newer_version_id_tesim" + - "newer_version_id_sim" + predicate: http://purl.org/dc/terms/isReplacedBy + alternate_version_id: + type: string + multiple: true + index_keys: + - "alternate_version_id_tesim" + - "alternate_version_id_sim" + predicate: http://purl.org/dc/terms/hasVersion + related_item_id: + type: string + multiple: true + index_keys: + - "related_item_id_tesim" + - "related_item_id_sim" + predicate: http://purl.org/dc/terms/relation + date: + type: string + multiple: false + index_keys: + - "date_tesim" + - "date_sim" + predicate: https://hykucommons.org/terms/date + access_right: + type: string + multiple: true + index_keys: + - "access_right_sim" + - "access_right_tesim" + predicate: http://purl.org/dc/terms/accessRights + arkivo_checksum: + type: string + multiple: false + predicate: http://scholarsphere.psu.edu/ns#arkivoChecksum + based_near: + type: string + multiple: true + index_keys: + - "based_near_sim" + - "based_near_tesim" + predicate: http://xmlns.com/foaf/0.1/based_near + import_url: + type: string + predicate: http://scholarsphere.psu.edu/ns#importUrl + label: + type: string + index_keys: + - "label_sim" + - "label_tesim" + predicate: info:fedora/fedora-system:def/model#downloadFilename + relative_path: + type: string + predicate: http://scholarsphere.psu.edu/ns#relativePath From a5de44c6f0d5108d08687a8c7f3d56a2db6c9513 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Thu, 16 May 2024 11:01:53 -0700 Subject: [PATCH 07/28] Ran generater and corrected properties for Cdl ```sh bundle exec rails generate hyku_knapsack:work_resource CdlResource ``` --- .../hyrax/cdl_resources_controller.rb | 18 ++ app/forms/cdl_resource_form.rb | 22 ++ app/indexers/cdl_resource_indexer.rb | 16 ++ app/models/cdl_resource.rb | 22 ++ .../cdl_resources/_cdl_resource.html.erb | 2 + config/initializers/hyrax.rb | 4 +- config/metadata/cdl_resource.yaml | 271 ++++++++++++++++++ spec/indexers/cdl_resource_indexer_spec.rb | 13 + spec/models/cdl_resource_spec.rb | 12 + .../_cdl_resource.html.erb_spec.rb | 7 + 10 files changed, 386 insertions(+), 1 deletion(-) create mode 100644 app/controllers/hyrax/cdl_resources_controller.rb create mode 100644 app/forms/cdl_resource_form.rb create mode 100644 app/indexers/cdl_resource_indexer.rb create mode 100644 app/models/cdl_resource.rb create mode 100644 app/views/hyrax/cdl_resources/_cdl_resource.html.erb create mode 100644 config/metadata/cdl_resource.yaml create mode 100644 spec/indexers/cdl_resource_indexer_spec.rb create mode 100644 spec/models/cdl_resource_spec.rb create mode 100644 spec/views/cdl_resources/_cdl_resource.html.erb_spec.rb diff --git a/app/controllers/hyrax/cdl_resources_controller.rb b/app/controllers/hyrax/cdl_resources_controller.rb new file mode 100644 index 0000000..7cfa09f --- /dev/null +++ b/app/controllers/hyrax/cdl_resources_controller.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource CdlResource` +module Hyrax + # Generated controller for CdlResource + class CdlResourcesController < ApplicationController + # Adds Hyrax behaviors to the controller. + include Hyrax::WorksControllerBehavior + include Hyku::WorksControllerBehavior + include Hyrax::BreadcrumbsForWorks + self.curation_concern_type = ::CdlResource + + # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style + # forms. + self.work_form_service = Hyrax::FormFactory.new + end +end diff --git a/app/forms/cdl_resource_form.rb b/app/forms/cdl_resource_form.rb new file mode 100644 index 0000000..fa7f7fa --- /dev/null +++ b/app/forms/cdl_resource_form.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource CdlResource` +# +# @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms +# @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking +class CdlResourceForm < Hyrax::Forms::PcdmObjectForm(CdlResource) + include Hyrax::FormFields(:basic_metadata) + include Hyrax::FormFields(:cdl_resource) + include Hyrax::FormFields(:with_pdf_viewer) + include Hyrax::FormFields(:with_video_embed) + + # Define custom form fields using the Valkyrie::ChangeSet interface + # + # property :my_custom_form_field + + # if you want a field in the form, but it doesn't have a directly corresponding + # model attribute, make it virtual + # + # property :user_input_not_destined_for_the_model, virtual: true +end diff --git a/app/indexers/cdl_resource_indexer.rb b/app/indexers/cdl_resource_indexer.rb new file mode 100644 index 0000000..3adf758 --- /dev/null +++ b/app/indexers/cdl_resource_indexer.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource CdlResource` +class CdlResourceIndexer < Hyrax::Indexers::PcdmObjectIndexer(CdlResource) + include Hyrax::Indexer(:basic_metadata) + include Hyrax::Indexer(:cdl_resource) + + # Uncomment this block if you want to add custom indexing behavior: + # def to_solr + # super.tap do |index_document| + # index_document[:my_field_tesim] = resource.my_field.map(&:to_s) + # index_document[:other_field_ssim] = resource.other_field + # end + # end +end diff --git a/app/models/cdl_resource.rb b/app/models/cdl_resource.rb new file mode 100644 index 0000000..b7d48e1 --- /dev/null +++ b/app/models/cdl_resource.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource CdlResource` +class CdlResource < Hyrax::Work + # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. + # include Hyrax::Schema(:basic_metadata) + include Hyrax::Schema(:cdl_resource) + include Hyrax::Schema(:with_pdf_viewer) + include Hyrax::Schema(:with_video_embed) + include Hyrax::ArResource + include Hyrax::NestedWorks + + Hyrax::ValkyrieLazyMigration.migrating(self, from: Cdl) + + include IiifPrint.model_configuration( + pdf_split_child_model: GenericWorkResource, + pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter + ) + + prepend OrderAlready.for(:creator) +end diff --git a/app/views/hyrax/cdl_resources/_cdl_resource.html.erb b/app/views/hyrax/cdl_resources/_cdl_resource.html.erb new file mode 100644 index 0000000..dfa344b --- /dev/null +++ b/app/views/hyrax/cdl_resources/_cdl_resource.html.erb @@ -0,0 +1,2 @@ +<%# This is a search result view %> +<%= render 'catalog/document', document: cdl_resource, document_counter: cdl_resource_counter %> diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index 7dfbddd..f81e987 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -8,11 +8,13 @@ # Injected via `rails g hyrax:work Etd` config.register_curation_concern :etd # # Injected via `rails g hyrax:work Cdl` - # config.register_curation_concern :cdl + config.register_curation_concern :cdl # Injected via `rails g hyrax:work_resource EtdResource` config.register_curation_concern :etd_resource # Injected via `rails g hyrax:work_resource OerResource` config.register_curation_concern :oer_resource + # Injected via `rails g hyrax:work_resource CdlResource` + config.register_curation_concern :cdl_resource # # See https://github.com/scientist-softserv/adventist-dl/issues/183 # # Also, we will continue to extract txt file's text using Adventist::TextFileTextExtractionService diff --git a/config/metadata/cdl_resource.yaml b/config/metadata/cdl_resource.yaml new file mode 100644 index 0000000..1cb4a82 --- /dev/null +++ b/config/metadata/cdl_resource.yaml @@ -0,0 +1,271 @@ +# Simple yaml config-driven schema which is used to define model attributes, +# index key names, and form properties. +# +# Attributes must have a type but all other configuration options are optional. +# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes +# must be placed here. +# +# attributes: +# attribute_name: +# type: string +# multiple: false +# index_keys: +# - "attribute_name_sim" +# form: +# required: true +# primary: true +# multiple: false +# +# @see config/metadata/basic_metadata.yaml for an example configuration +# +# Generated via +# `rails generate hyrax:work_resource CdlResource` + +attributes: + creator: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "creator_sim" + - "creator_tesim" + predicate: http://purl.org/dc/elements/1.1/creator + keyword: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "keyword_sim" + - "keyword_tesim" + predicate: http://schema.org/keywords + resource_type: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "resource_type_sim" + - "resource_type_tesim" + predicate: http://purl.org/dc/terms/type + rights_statement: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "rights_statement_sim" + - "rights_statement_tesim" + predicate: http://www.europeana.eu/schemas/edm/rights + license: + type: string + multiple: true + form: + primary: false + index_keys: + - "license_sim" + - "license_tesim" + predicate: http://purl.org/dc/terms/license + abstract: + type: string + multiple: true + form: + primary: false + index_keys: + - "abstract_sim" + - "abstract_tesim" + predicate: http://purl.org/dc/terms/abstract + access_right: + type: string + multiple: true + form: + primary: false + index_keys: + - "access_right_sim" + - "access_right_tesim" + predicate: http://purl.org/dc/terms/accessRights + additional_information: + type: string + predicate: http://purl.org/dc/terms/accessRights + multiple: true + form: + primary: false + index_keys: + - "additional_information_tesim" + admin_note: + type: string + form: + primary: false + predicate: http://schema.org/positiveNotes + multiple: false + index_keys: + - "admin_note_tesim" + alternative_title: + type: string + multiple: true + form: + primary: false + index_keys: + - "alternative_title_sim" + - "alternative_title_tesim" + predicate: http://purl.org/dc/terms/alternative + bibliographic_citation: + type: string + predicate: http://purl.org/dc/terms/bibliographicCitation + multiple: true + form: + primary: false + index_keys: + - "bibliographic_citation_tesim" + chronology_note: + type: string + predicate: https://hykucommons.org/terms/chronology_note + multiple: true + form: + primary: false + index_keys: + - "chronology_note_tesim" + - "chronology_note_sim" + contributing_library: + type: string + predicate: https://hykucommons.org/terms/contributing_library + multiple: true + form: + primary: false + index_keys: + - "contributing_library_tesim" + - "contributing_library_sim" + contributor: + type: string + multiple: true + form: + primary: false + index_keys: + - "contributor_tesim" + - "contributor_sim" + predicate: http://purl.org/dc/elements/1.1/contributor + date_created: + type: date_time + multiple: true + form: + primary: false + index_keys: + - "date_created_sim" + - "date_created_tesim" + predicate: http://purl.org/dc/terms/created + description: + type: string + multiple: true + form: + primary: false + index_keys: + - "description_sim" + - "description_tesim" + predicate: http://purl.org/dc/elements/1.1/description + identifier: + type: string + multiple: true + form: + primary: false + index_keys: + - "identifier_sim" + - "identifier_tesim" + predicate: http://purl.org/dc/terms/identifier + language: + type: string + multiple: true + form: + primary: false + index_keys: + - "language_sim" + - "language_tesim" + predicate: http://purl.org/dc/elements/1.1/language + library_catalog_identifier: + type: string + predicate: https://hykucommons.org/terms/library_catalog_identifier + multiple: true + form: + primary: false + index_keys: + - "library_catalog_identifier_tesim" + - "library_catalog_identifier_sim" + publisher: + type: string + multiple: true + form: + primary: false + index_keys: + - "publisher_sim" + - "publisher_tesim" + predicate: http://purl.org/dc/elements/1.1/publisher + related_url: + type: string + multiple: true + form: + primary: false + index_keys: + - "related_url_sim" + - "related_url_tesim" + predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso + rights_notes: + type: string + multiple: true + form: + primary: false + index_keys: + - "rights_notes_sim" + - "rights_notes_tesim" + predicate: http://purl.org/dc/elements/1.1/rights + source: + type: string + multiple: true + form: + primary: false + index_keys: + - "source_sim" + - "source_tesim" + predicate: http://purl.org/dc/terms/source + subject: + type: string + multiple: true + index_keys: + - "subject_sim" + - "subject_tesim" + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/subject + bulkrax_identifier: + type: string + predicate: https://hykucommons.org/terms/bulkrax_identifier + multiple: false + index_keys: + - "bulkrax_identifier_tesim" + - "bulkrax_identifier_sim" + arkivo_checksum: + type: string + multiple: false + predicate: http://scholarsphere.psu.edu/ns#arkivoChecksum + based_near: + type: string + multiple: true + index_keys: + - "based_near_sim" + - "based_near_tesim" + predicate: http://xmlns.com/foaf/0.1/based_near + import_url: + type: string + predicate: http://scholarsphere.psu.edu/ns#importUrl + label: + type: string + index_keys: + - "label_sim" + - "label_tesim" + predicate: info:fedora/fedora-system:def/model#downloadFilename + relative_path: + type: string + predicate: http://scholarsphere.psu.edu/ns#relativePath diff --git a/spec/indexers/cdl_resource_indexer_spec.rb b/spec/indexers/cdl_resource_indexer_spec.rb new file mode 100644 index 0000000..40aee8c --- /dev/null +++ b/spec/indexers/cdl_resource_indexer_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource CdlResource` +require 'rails_helper' +require 'hyrax/specs/shared_specs/indexers' + +RSpec.describe CdlResourceIndexer do + let(:indexer_class) { described_class } + let(:resource) { CdlResource.new } + + it_behaves_like 'a Hyrax::Resource indexer' +end diff --git a/spec/models/cdl_resource_spec.rb b/spec/models/cdl_resource_spec.rb new file mode 100644 index 0000000..14bbc39 --- /dev/null +++ b/spec/models/cdl_resource_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource CdlResource` +require 'rails_helper' +require 'hyrax/specs/shared_specs/hydra_works' + +RSpec.describe CdlResource do + subject(:work) { described_class.new } + + it_behaves_like 'a Hyrax::Work' +end diff --git a/spec/views/cdl_resources/_cdl_resource.html.erb_spec.rb b/spec/views/cdl_resources/_cdl_resource.html.erb_spec.rb new file mode 100644 index 0000000..a3120c4 --- /dev/null +++ b/spec/views/cdl_resources/_cdl_resource.html.erb_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Generated via +# `rails generate hyrax:work_resource CdlResource` +RSpec.describe 'cdl_resources/cdl_resource.html.erb', type: :view do # rubocop:disable RSpec/EmptyExampleGroup + # add cdl_resource view specs +end From ee2565637b84d5bf00b88fd9b98a893f01ecb848 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 16 May 2024 12:34:20 -0700 Subject: [PATCH 08/28] AF records should reroute to resources --- app/controllers/hyrax/etds_controller.rb | 7 ++++++- app/controllers/hyrax/oers_controller.rb | 7 ++++++- app/forms/etd_resource_form.rb | 4 ++-- app/forms/oer_resource_form.rb | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/hyrax/etds_controller.rb b/app/controllers/hyrax/etds_controller.rb index e0d3776..6cfb806 100644 --- a/app/controllers/hyrax/etds_controller.rb +++ b/app/controllers/hyrax/etds_controller.rb @@ -5,8 +5,13 @@ module Hyrax class EtdsController < ApplicationController # Adds Hyrax behaviors to the controller. include Hyrax::WorksControllerBehavior + include Hyku::WorksControllerBehavior include Hyrax::BreadcrumbsForWorks - self.curation_concern_type = ::Etd + self.curation_concern_type = ::EtdResource + + # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style + # forms. + self.work_form_service = Hyrax::FormFactory.new # Use this line if you want to use a custom presenter self.show_presenter = Hyrax::EtdPresenter diff --git a/app/controllers/hyrax/oers_controller.rb b/app/controllers/hyrax/oers_controller.rb index 20d66c1..ea4879c 100644 --- a/app/controllers/hyrax/oers_controller.rb +++ b/app/controllers/hyrax/oers_controller.rb @@ -5,8 +5,13 @@ module Hyrax class OersController < ApplicationController # Adds Hyrax behaviors to the controller. include Hyrax::WorksControllerBehavior + include Hyku::WorksControllerBehavior include Hyrax::BreadcrumbsForWorks - self.curation_concern_type = ::Oer + self.curation_concern_type = ::OerResource + + # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style + # forms. + self.work_form_service = Hyrax::FormFactory.new # Use this line if you want to use a custom presenter self.show_presenter = Hyrax::OerPresenter diff --git a/app/forms/etd_resource_form.rb b/app/forms/etd_resource_form.rb index 4029d2f..4838446 100644 --- a/app/forms/etd_resource_form.rb +++ b/app/forms/etd_resource_form.rb @@ -5,13 +5,13 @@ # # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking -class EtdResourceForm < Hyrax::Forms::PcdmObjectForm(EtdResource) +class EtdResourceForm < Hyrax::Forms::ResourceForm(EtdResource) # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. # include Hyrax::FormFields(:basic_metadata) include Hyrax::FormFields(:etd_resource) include Hyrax::FormFields(:with_pdf_viewer) include Hyrax::FormFields(:with_video_embed) - + include VideoEmbedBehavior::Validation # Define custom form fields using the Valkyrie::ChangeSet interface # # property :my_custom_form_field diff --git a/app/forms/oer_resource_form.rb b/app/forms/oer_resource_form.rb index af7f481..47bc3df 100644 --- a/app/forms/oer_resource_form.rb +++ b/app/forms/oer_resource_form.rb @@ -5,13 +5,13 @@ # # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking -class OerResourceForm < Hyrax::Forms::PcdmObjectForm(OerResource) +class OerResourceForm < Hyrax::Forms::ResourceForm(OerResource) # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. # include Hyrax::FormFields(:basic_metadata) include Hyrax::FormFields(:oer_resource) include Hyrax::FormFields(:with_pdf_viewer) include Hyrax::FormFields(:with_video_embed) - + include VideoEmbedBehavior::Validation # Define custom form fields using the Valkyrie::ChangeSet interface # # property :my_custom_form_field From 308a4a0fa35e1670c08f6f979150ddb4d4c35069 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 16 May 2024 15:12:20 -0700 Subject: [PATCH 09/28] update indexers and inherit from ValkyrieWorkIndexer --- app/indexers/etd_resource_indexer.rb | 7 ++++++- app/indexers/oer_resource_indexer.rb | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/indexers/etd_resource_indexer.rb b/app/indexers/etd_resource_indexer.rb index 735e4c0..cb0ae1d 100644 --- a/app/indexers/etd_resource_indexer.rb +++ b/app/indexers/etd_resource_indexer.rb @@ -2,9 +2,14 @@ # Generated via # `rails generate hyrax:work_resource EtdResource` -class EtdResourceIndexer < Hyrax::Indexers::PcdmObjectIndexer(EtdResource) +class EtdResourceIndexer < Hyrax::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) + include Hyrax::Indexer(:bulkrax_metadata) include Hyrax::Indexer(:etd_resource) + include Hyrax::Indexer(:with_pdf_viewer) + include Hyrax::Indexer(:with_video_embed) + + include HykuIndexing # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/app/indexers/oer_resource_indexer.rb b/app/indexers/oer_resource_indexer.rb index 8284d39..3ed693c 100644 --- a/app/indexers/oer_resource_indexer.rb +++ b/app/indexers/oer_resource_indexer.rb @@ -2,9 +2,14 @@ # Generated via # `rails generate hyrax:work_resource OerResource` -class OerResourceIndexer < Hyrax::Indexers::PcdmObjectIndexer(OerResource) +class OerResourceIndexer < Hyrax::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) + include Hyrax::Indexer(:bulkrax_metadata) include Hyrax::Indexer(:oer_resource) + include Hyrax::Indexer(:with_pdf_viewer) + include Hyrax::Indexer(:with_video_embed) + + include HykuIndexing # Uncomment this block if you want to add custom indexing behavior: # def to_solr From 7382b86e91d32d769ec25ff7b16d5ef33983e209 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 16 May 2024 16:28:49 -0700 Subject: [PATCH 10/28] Create wings.rb TODO: We can probably remove any code that matches Hyku's wings.rb --- config/initializers/wings.rb | 116 +++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 config/initializers/wings.rb diff --git a/config/initializers/wings.rb b/config/initializers/wings.rb new file mode 100644 index 0000000..ec775e5 --- /dev/null +++ b/config/initializers/wings.rb @@ -0,0 +1,116 @@ +# frozen_string_literal: true +# rubocop:disable Metrics/BlockLength + +Rails.application.config.after_initialize do + [ + Cdl, + Etd, + GenericWork, + Image, + Oer + ].each do |klass| + Wings::ModelRegistry.register("#{klass}Resource".constantize, klass) + # we register itself so we can pre-translate the class in Freyja instead of having to translate in each query_service + Wings::ModelRegistry.register(klass, klass) + end + Wings::ModelRegistry.register(Collection, Collection) + Wings::ModelRegistry.register(CollectionResource, Collection) + Wings::ModelRegistry.register(AdminSet, AdminSet) + Wings::ModelRegistry.register(AdminSetResource, AdminSet) + Wings::ModelRegistry.register(FileSet, FileSet) + Wings::ModelRegistry.register(Hyrax::FileSet, FileSet) + Wings::ModelRegistry.register(Hydra::PCDM::File, Hydra::PCDM::File) + Wings::ModelRegistry.register(Hyrax::FileMetadata, Hydra::PCDM::File) + + Valkyrie::MetadataAdapter.register( + Freyja::MetadataAdapter.new, + :freyja + ) + Valkyrie.config.metadata_adapter = :freyja + Hyrax.config.query_index_from_valkyrie = true + Hyrax.config.index_adapter = :solr_index + + Valkyrie::StorageAdapter.register( + Valkyrie::Storage::Disk.new(base_path: Rails.root.join("storage", "files"), + file_mover: FileUtils.method(:cp)), + :disk + ) + Valkyrie.config.storage_adapter = :disk + Valkyrie.config.indexing_adapter = :solr_index + + # load all the sql based custom queries + [ + Hyrax::CustomQueries::Navigators::CollectionMembers, + Hyrax::CustomQueries::Navigators::ChildCollectionsNavigator, + Hyrax::CustomQueries::Navigators::ParentCollectionsNavigator, + Hyrax::CustomQueries::Navigators::ChildFileSetsNavigator, + Hyrax::CustomQueries::Navigators::ChildWorksNavigator, + Hyrax::CustomQueries::Navigators::FindFiles, + Hyrax::CustomQueries::FindAccessControl, + Hyrax::CustomQueries::FindCollectionsByType, + Hyrax::CustomQueries::FindFileMetadata, + Hyrax::CustomQueries::FindIdsByModel, + Hyrax::CustomQueries::FindManyByAlternateIds, + Hyrax::CustomQueries::FindModelsByAccess, + Hyrax::CustomQueries::FindCountBy, + Hyrax::CustomQueries::FindByDateRange, + Hyrax::CustomQueries::FindBySourceIdentifier + ].each do |handler| + Hyrax.query_service.services[0].custom_queries.register_query_handler(handler) + end + + [ + Wings::CustomQueries::FindBySourceIdentifier + ].each do |handler| + Hyrax.query_service.services[1].custom_queries.register_query_handler(handler) + end + + Wings::ModelRegistry.register(CdlResource, Cdl) + Wings::ModelRegistry.register(EtdResource, Etd) + Wings::ModelRegistry.register(GenericWorkResource, GenericWork) + Wings::ModelRegistry.register(ImageResource, Image) + Wings::ModelRegistry.register(OerResource, Oer) +end + +Rails.application.config.to_prepare do + AdminSetResource.class_eval do + attribute :internal_resource, Valkyrie::Types::Any.default("AdminSet"), internal: true + end + + CollectionResource.class_eval do + attribute :internal_resource, Valkyrie::Types::Any.default("Collection"), internal: true + end + + Valkyrie.config.resource_class_resolver = lambda do |resource_klass_name| + # TODO: Can we use some kind of lookup. + klass_name = resource_klass_name.gsub(/Resource$/, '') + if %w[ + Cdl + Etd + GenericWork + Image + Oer + ].include?(klass_name) + "#{klass_name}Resource".constantize + elsif 'Collection' == klass_name + CollectionResource + elsif 'AdminSet' == klass_name + AdminSetResource + # Without this mapping, we'll see cases of Postgres Valkyrie adapter attempting to write to + # Fedora. Yeah! + elsif 'Hydra::AccessControl' == klass_name + Hyrax::AccessControl + elsif 'FileSet' == klass_name + Hyrax::FileSet + elsif 'Hydra::AccessControls::Embargo' == klass_name + Hyrax::Embargo + elsif 'Hydra::AccessControls::Lease' == klass_name + Hyrax::Lease + elsif 'Hydra::PCDM::File' == klass_name + Hyrax::FileMetadata + else + klass_name.constantize + end + end +end +# rubocop:enable Metrics/BlockLength From b3d7a5dd515a613bdf7764274f7d90e9dcf8e680 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Fri, 17 May 2024 08:54:18 -0700 Subject: [PATCH 11/28] Update wings to specify knapsack specific overrides --- config/initializers/wings.rb | 61 ------------------------------------ 1 file changed, 61 deletions(-) diff --git a/config/initializers/wings.rb b/config/initializers/wings.rb index ec775e5..31cc06c 100644 --- a/config/initializers/wings.rb +++ b/config/initializers/wings.rb @@ -13,73 +13,12 @@ # we register itself so we can pre-translate the class in Freyja instead of having to translate in each query_service Wings::ModelRegistry.register(klass, klass) end - Wings::ModelRegistry.register(Collection, Collection) - Wings::ModelRegistry.register(CollectionResource, Collection) - Wings::ModelRegistry.register(AdminSet, AdminSet) - Wings::ModelRegistry.register(AdminSetResource, AdminSet) - Wings::ModelRegistry.register(FileSet, FileSet) - Wings::ModelRegistry.register(Hyrax::FileSet, FileSet) - Wings::ModelRegistry.register(Hydra::PCDM::File, Hydra::PCDM::File) - Wings::ModelRegistry.register(Hyrax::FileMetadata, Hydra::PCDM::File) - - Valkyrie::MetadataAdapter.register( - Freyja::MetadataAdapter.new, - :freyja - ) - Valkyrie.config.metadata_adapter = :freyja - Hyrax.config.query_index_from_valkyrie = true - Hyrax.config.index_adapter = :solr_index - - Valkyrie::StorageAdapter.register( - Valkyrie::Storage::Disk.new(base_path: Rails.root.join("storage", "files"), - file_mover: FileUtils.method(:cp)), - :disk - ) - Valkyrie.config.storage_adapter = :disk - Valkyrie.config.indexing_adapter = :solr_index - - # load all the sql based custom queries - [ - Hyrax::CustomQueries::Navigators::CollectionMembers, - Hyrax::CustomQueries::Navigators::ChildCollectionsNavigator, - Hyrax::CustomQueries::Navigators::ParentCollectionsNavigator, - Hyrax::CustomQueries::Navigators::ChildFileSetsNavigator, - Hyrax::CustomQueries::Navigators::ChildWorksNavigator, - Hyrax::CustomQueries::Navigators::FindFiles, - Hyrax::CustomQueries::FindAccessControl, - Hyrax::CustomQueries::FindCollectionsByType, - Hyrax::CustomQueries::FindFileMetadata, - Hyrax::CustomQueries::FindIdsByModel, - Hyrax::CustomQueries::FindManyByAlternateIds, - Hyrax::CustomQueries::FindModelsByAccess, - Hyrax::CustomQueries::FindCountBy, - Hyrax::CustomQueries::FindByDateRange, - Hyrax::CustomQueries::FindBySourceIdentifier - ].each do |handler| - Hyrax.query_service.services[0].custom_queries.register_query_handler(handler) - end - - [ - Wings::CustomQueries::FindBySourceIdentifier - ].each do |handler| - Hyrax.query_service.services[1].custom_queries.register_query_handler(handler) - end Wings::ModelRegistry.register(CdlResource, Cdl) Wings::ModelRegistry.register(EtdResource, Etd) Wings::ModelRegistry.register(GenericWorkResource, GenericWork) Wings::ModelRegistry.register(ImageResource, Image) Wings::ModelRegistry.register(OerResource, Oer) -end - -Rails.application.config.to_prepare do - AdminSetResource.class_eval do - attribute :internal_resource, Valkyrie::Types::Any.default("AdminSet"), internal: true - end - - CollectionResource.class_eval do - attribute :internal_resource, Valkyrie::Types::Any.default("Collection"), internal: true - end Valkyrie.config.resource_class_resolver = lambda do |resource_klass_name| # TODO: Can we use some kind of lookup. From 1695788bbe54df37f06e27397cc63644432d92c4 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Fri, 17 May 2024 09:17:10 -0700 Subject: [PATCH 12/28] Update wings so you only need one point of change --- config/initializers/wings.rb | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/config/initializers/wings.rb b/config/initializers/wings.rb index 31cc06c..e4cb9d4 100644 --- a/config/initializers/wings.rb +++ b/config/initializers/wings.rb @@ -2,13 +2,10 @@ # rubocop:disable Metrics/BlockLength Rails.application.config.after_initialize do - [ - Cdl, - Etd, - GenericWork, - Image, - Oer - ].each do |klass| + # Add all concerns that are migrating from ActiveFedora here + CONCERNS = [Cdl, Etd, GenericWork, Image, Oer] + + CONCERNS.each do |klass| Wings::ModelRegistry.register("#{klass}Resource".constantize, klass) # we register itself so we can pre-translate the class in Freyja instead of having to translate in each query_service Wings::ModelRegistry.register(klass, klass) @@ -23,13 +20,7 @@ Valkyrie.config.resource_class_resolver = lambda do |resource_klass_name| # TODO: Can we use some kind of lookup. klass_name = resource_klass_name.gsub(/Resource$/, '') - if %w[ - Cdl - Etd - GenericWork - Image - Oer - ].include?(klass_name) + if CONCERNS.map(&:to_s).include?(klass_name) "#{klass_name}Resource".constantize elsif 'Collection' == klass_name CollectionResource From 6696d807bcade7050d9adc98319d2b962a1a1b39 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Fri, 17 May 2024 09:22:36 -0700 Subject: [PATCH 13/28] Update engine to load decorators earlier This commit will load the decorators earlier in the initialization. --- hyrax-webapp | 2 +- lib/hyku_knapsack/engine.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hyrax-webapp b/hyrax-webapp index 66c9217..0ceee1f 160000 --- a/hyrax-webapp +++ b/hyrax-webapp @@ -1 +1 @@ -Subproject commit 66c9217a72a9cf39c9fa467920fb701149f599b4 +Subproject commit 0ceee1f941731be2b358451d7b175567f9404d6f diff --git a/lib/hyku_knapsack/engine.rb b/lib/hyku_knapsack/engine.rb index cb94870..1b57df5 100644 --- a/lib/hyku_knapsack/engine.rb +++ b/lib/hyku_knapsack/engine.rb @@ -48,7 +48,7 @@ def self.load_translations! Hyrax::SimpleSchemaLoader.prepend(Hyrax::SimpleSchemaLoaderDecorator) end - config.after_initialize do + config.to_prepare do HykuKnapsack::Engine.root.glob("app/**/*_decorator*.rb").sort.each do |c| Rails.configuration.cache_classes ? require(c) : load(c) end @@ -56,7 +56,9 @@ def self.load_translations! HykuKnapsack::Engine.root.glob("lib/**/*_decorator*.rb").sort.each do |c| Rails.configuration.cache_classes ? require(c) : load(c) end + end + config.after_initialize do Hyrax::DerivativeService.services = [ IiifPrint::PluggableDerivativeService ] From bb639488d58694c18d2950adad735e10bfe195bf Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Fri, 17 May 2024 11:16:53 -0700 Subject: [PATCH 14/28] :gift: customize indexers In this commit I've added custom index terms to each resource indexer. --- app/indexers/cdl_indexer.rb | 1 + app/indexers/cdl_resource_indexer.rb | 2 ++ config/metadata/generic_work_resource.yaml | 0 config/metadata/image_resource.yaml | 34 ++++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 config/metadata/generic_work_resource.yaml create mode 100644 config/metadata/image_resource.yaml diff --git a/app/indexers/cdl_indexer.rb b/app/indexers/cdl_indexer.rb index 88f0a23..d2c0b4f 100644 --- a/app/indexers/cdl_indexer.rb +++ b/app/indexers/cdl_indexer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Generated via # `rails generate hyrax:work Cdl` class CdlIndexer < AppIndexer diff --git a/app/indexers/cdl_resource_indexer.rb b/app/indexers/cdl_resource_indexer.rb index 3adf758..eae11c5 100644 --- a/app/indexers/cdl_resource_indexer.rb +++ b/app/indexers/cdl_resource_indexer.rb @@ -6,6 +6,8 @@ class CdlResourceIndexer < Hyrax::Indexers::PcdmObjectIndexer(CdlResource) include Hyrax::Indexer(:basic_metadata) include Hyrax::Indexer(:cdl_resource) + include HykuIndexing + # Uncomment this block if you want to add custom indexing behavior: # def to_solr # super.tap do |index_document| diff --git a/config/metadata/generic_work_resource.yaml b/config/metadata/generic_work_resource.yaml new file mode 100644 index 0000000..e69de29 diff --git a/config/metadata/image_resource.yaml b/config/metadata/image_resource.yaml new file mode 100644 index 0000000..7c9fe3c --- /dev/null +++ b/config/metadata/image_resource.yaml @@ -0,0 +1,34 @@ +# Simple yaml config-driven schema which is used to define model attributes, +# index key names, and form properties. +# +# Attributes must have a type but all other configuration options are optional. +# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes +# must be placed here. +# +# attributes: +# attribute_name: +# type: string +# multiple: false +# index_keys: +# - "attribute_name_sim" +# form: +# required: true +# primary: true +# multiple: false +# +# @see config/metadata/basic_metadata.yaml for an example configuration +# +# Generated via +# `rails generate hyrax:work_resource GenericWorkResource` + +attributes: + admin_note: + type: string + multiple: false + index_keys: + - "admin_note_tesim" + form: + required: false + primary: false + multiple: false + predicate: http://schema.org/positiveNotes From 673335da2a919d4de9304c77caa7da0115670c14 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Fri, 17 May 2024 13:34:18 -0700 Subject: [PATCH 15/28] Remove the controllers for migrated models We remove the controllers because they are no longer needed and use the AF models' controllers instead. --- .../hyrax/cdl_resources_controller.rb | 18 ------------------ .../hyrax/etd_resources_controller.rb | 18 ------------------ .../hyrax/oer_resources_controller.rb | 18 ------------------ 3 files changed, 54 deletions(-) delete mode 100644 app/controllers/hyrax/cdl_resources_controller.rb delete mode 100644 app/controllers/hyrax/etd_resources_controller.rb delete mode 100644 app/controllers/hyrax/oer_resources_controller.rb diff --git a/app/controllers/hyrax/cdl_resources_controller.rb b/app/controllers/hyrax/cdl_resources_controller.rb deleted file mode 100644 index 7cfa09f..0000000 --- a/app/controllers/hyrax/cdl_resources_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -# Generated via -# `rails generate hyrax:work_resource CdlResource` -module Hyrax - # Generated controller for CdlResource - class CdlResourcesController < ApplicationController - # Adds Hyrax behaviors to the controller. - include Hyrax::WorksControllerBehavior - include Hyku::WorksControllerBehavior - include Hyrax::BreadcrumbsForWorks - self.curation_concern_type = ::CdlResource - - # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style - # forms. - self.work_form_service = Hyrax::FormFactory.new - end -end diff --git a/app/controllers/hyrax/etd_resources_controller.rb b/app/controllers/hyrax/etd_resources_controller.rb deleted file mode 100644 index 10f8c99..0000000 --- a/app/controllers/hyrax/etd_resources_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -# Generated via -# `rails generate hyrax:work_resource EtdResource` -module Hyrax - # Generated controller for EtdResource - class EtdResourcesController < ApplicationController - # Adds Hyrax behaviors to the controller. - include Hyrax::WorksControllerBehavior - include Hyku::WorksControllerBehavior - include Hyrax::BreadcrumbsForWorks - self.curation_concern_type = ::EtdResource - - # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style - # forms. - self.work_form_service = Hyrax::FormFactory.new - end -end diff --git a/app/controllers/hyrax/oer_resources_controller.rb b/app/controllers/hyrax/oer_resources_controller.rb deleted file mode 100644 index ef85e14..0000000 --- a/app/controllers/hyrax/oer_resources_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -# Generated via -# `rails generate hyrax:work_resource OerResource` -module Hyrax - # Generated controller for OerResource - class OerResourcesController < ApplicationController - # Adds Hyrax behaviors to the controller. - include Hyrax::WorksControllerBehavior - include Hyku::WorksControllerBehavior - include Hyrax::BreadcrumbsForWorks - self.curation_concern_type = ::OerResource - - # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style - # forms. - self.work_form_service = Hyrax::FormFactory.new - end -end From 894dd41f135b52106ce604ee71ff8ac222ea4a48 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Fri, 17 May 2024 14:58:30 -0700 Subject: [PATCH 16/28] :gift: Allow knapsack to override Hyku metadata TODO: add Image and generic work properties to the decorator yaml files --- app/models/generic_work_resource_decorator.rb | 16 +++++++++ app/models/image_resource_decorator.rb | 16 +++++++++ config/metadata/generic_work_resource.yaml | 0 ...l => generic_work_resource_decorator.yaml} | 0 config/metadata/image_resource_decorator.yaml | 34 +++++++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 app/models/generic_work_resource_decorator.rb create mode 100644 app/models/image_resource_decorator.rb delete mode 100644 config/metadata/generic_work_resource.yaml rename config/metadata/{image_resource.yaml => generic_work_resource_decorator.yaml} (100%) create mode 100644 config/metadata/image_resource_decorator.yaml diff --git a/app/models/generic_work_resource_decorator.rb b/app/models/generic_work_resource_decorator.rb new file mode 100644 index 0000000..bf6dd86 --- /dev/null +++ b/app/models/generic_work_resource_decorator.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# OVERRIDE to customize metadata +module GenericWorkResourceDecorator + extend ActiveSupport::Concern + + prepended do + include Hyrax::Schema(:basic_metadata) + include Hyrax::Schema(:bulkrax_metadata) + include Hyrax::Schema(:generic_work_resource_decorator) + include Hyrax::Schema(:with_pdf_viewer) + include Hyrax::Schema(:with_video_embed) + end +end + +GenericWorkResource.prepend(GenericWorkResourceDecorator) diff --git a/app/models/image_resource_decorator.rb b/app/models/image_resource_decorator.rb new file mode 100644 index 0000000..357b17c --- /dev/null +++ b/app/models/image_resource_decorator.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# OVERRIDE to customize metadata +module ImageResourceDecorator + extend ActiveSupport::Concern + + prepended do + include Hyrax::Schema(:basic_metadata) + include Hyrax::Schema(:bulkrax_metadata) + include Hyrax::Schema(:image_resource_decorator) + include Hyrax::Schema(:with_pdf_viewer) + include Hyrax::Schema(:with_video_embed) + end +end + +ImageResource.prepend(ImageResourceDecorator) diff --git a/config/metadata/generic_work_resource.yaml b/config/metadata/generic_work_resource.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/config/metadata/image_resource.yaml b/config/metadata/generic_work_resource_decorator.yaml similarity index 100% rename from config/metadata/image_resource.yaml rename to config/metadata/generic_work_resource_decorator.yaml diff --git a/config/metadata/image_resource_decorator.yaml b/config/metadata/image_resource_decorator.yaml new file mode 100644 index 0000000..7c9fe3c --- /dev/null +++ b/config/metadata/image_resource_decorator.yaml @@ -0,0 +1,34 @@ +# Simple yaml config-driven schema which is used to define model attributes, +# index key names, and form properties. +# +# Attributes must have a type but all other configuration options are optional. +# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes +# must be placed here. +# +# attributes: +# attribute_name: +# type: string +# multiple: false +# index_keys: +# - "attribute_name_sim" +# form: +# required: true +# primary: true +# multiple: false +# +# @see config/metadata/basic_metadata.yaml for an example configuration +# +# Generated via +# `rails generate hyrax:work_resource GenericWorkResource` + +attributes: + admin_note: + type: string + multiple: false + index_keys: + - "admin_note_tesim" + form: + required: false + primary: false + multiple: false + predicate: http://schema.org/positiveNotes From b51a93b290e0252b4111b1d63a4dcbe62b929146 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Fri, 17 May 2024 16:32:22 -0700 Subject: [PATCH 17/28] Review and adjusted some jobs These two jobs were adjusted to the Valkyrie paradigm. The AttachFilesToWorkJobDecorator needs more context before I can change it and the Bulkrax::RelatedMembershipsJob seems like it should work, but we'll see with testing. The spec for CreateGroupAndAddMembersJob will be addressed later. --- app/jobs/create_group_and_add_members_job.rb | 8 ++++---- app/jobs/iiif_print/create_relationships_job_decorator.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/jobs/create_group_and_add_members_job.rb b/app/jobs/create_group_and_add_members_job.rb index 53503a1..9211141 100644 --- a/app/jobs/create_group_and_add_members_job.rb +++ b/app/jobs/create_group_and_add_members_job.rb @@ -13,10 +13,10 @@ class CreateGroupAndAddMembersJob < ApplicationJob queue_as :default def perform(cdl_id, retries = 0) - work = Cdl.where(id: cdl_id).first + work = Hyrax.query_service.find_by(id: cdl_id) return if work.nil? - page_count = work.file_sets.first.page_count.first.to_i + page_count = work.members.first.original_file.page_count.first.to_i child_model = work.iiif_print_config.pdf_split_child_model child_works_count = work.members.select { |member| member.is_a?(child_model) }.count @@ -28,7 +28,7 @@ def perform(cdl_id, retries = 0) assign_read_groups(member, group.name) end - work.save + Hyrax.persister.save(resource: work) group.save else return if retries > RETRY_MAX @@ -42,7 +42,7 @@ def perform(cdl_id, retries = 0) def assign_read_groups(member, group_name) member.read_groups = [group_name] - member.save + Hyrax.persister.save(resource: member) member.members.each do |sub_member| assign_read_groups(sub_member, group_name) end diff --git a/app/jobs/iiif_print/create_relationships_job_decorator.rb b/app/jobs/iiif_print/create_relationships_job_decorator.rb index 0141351..c56e4b9 100644 --- a/app/jobs/iiif_print/create_relationships_job_decorator.rb +++ b/app/jobs/iiif_print/create_relationships_job_decorator.rb @@ -34,7 +34,7 @@ def perform(parent_id:, parent_model:, child_model:, retries: 0, **) # report failures & keep pending relationships raise "CreateRelationshipsJob failed for parent id: #{@parent_id} " \ "had #{@number_of_successes} successes & #{@number_of_failures} failures, " \ - "with errors: #{@errors}. Wanted #{@pending_children} children." + "with errors: #{@errors}. Wanted #{@pending_children.count} children." end # OVERRIDE begin From 7550093587605d57cc00a6083650ea79269662eb Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 20 May 2024 08:15:10 -0700 Subject: [PATCH 18/28] Update Image form, indexer, and yaml This commit will also add the same condition pattern we used in the model and update the yaml to mirror the old fields. --- app/forms/image_resource_form_decorator.rb | 13 + .../image_resource_indexer_decorator.rb | 13 + app/models/image_resource_decorator.rb | 2 - config/metadata/image_resource_decorator.yaml | 233 +++++++++++++++++- 4 files changed, 256 insertions(+), 5 deletions(-) create mode 100644 app/forms/image_resource_form_decorator.rb create mode 100644 app/indexers/image_resource_indexer_decorator.rb diff --git a/app/forms/image_resource_form_decorator.rb b/app/forms/image_resource_form_decorator.rb new file mode 100644 index 0000000..566a441 --- /dev/null +++ b/app/forms/image_resource_form_decorator.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module ImageResourceFormDecorator + extend ActiveSupport::Concern + + prepended do + include Hyrax::FormFields(:image_resource_decorator) + include Hyrax::FormFields(:with_pdf_viewer) + include Hyrax::FormFields(:with_video_embed) + end +end + +ImageResourceForm.prepend(ImageResourceFormDecorator) diff --git a/app/indexers/image_resource_indexer_decorator.rb b/app/indexers/image_resource_indexer_decorator.rb new file mode 100644 index 0000000..6558547 --- /dev/null +++ b/app/indexers/image_resource_indexer_decorator.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module ImageResourceIndexerDecorator + extend ActiveSupport::Concern + + prepended do + include Hyrax::Indexer(:image_resource_decorator) + include Hyrax::Indexer(:with_pdf_viewer) + include Hyrax::Indexer(:with_video_embed) + end +end + +ImageResourceIndexer.prepend(ImageResourceIndexerDecorator) diff --git a/app/models/image_resource_decorator.rb b/app/models/image_resource_decorator.rb index 357b17c..bb80807 100644 --- a/app/models/image_resource_decorator.rb +++ b/app/models/image_resource_decorator.rb @@ -5,8 +5,6 @@ module ImageResourceDecorator extend ActiveSupport::Concern prepended do - include Hyrax::Schema(:basic_metadata) - include Hyrax::Schema(:bulkrax_metadata) include Hyrax::Schema(:image_resource_decorator) include Hyrax::Schema(:with_pdf_viewer) include Hyrax::Schema(:with_video_embed) diff --git a/config/metadata/image_resource_decorator.yaml b/config/metadata/image_resource_decorator.yaml index 7c9fe3c..d8a3ae5 100644 --- a/config/metadata/image_resource_decorator.yaml +++ b/config/metadata/image_resource_decorator.yaml @@ -22,13 +22,240 @@ # `rails generate hyrax:work_resource GenericWorkResource` attributes: + creator: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "creator_sim" + - "creator_tesim" + predicate: http://purl.org/dc/elements/1.1/creator + keyword: + type: string + multiple: true + index_keys: + - "keyword_sim" + - "keyword_tesim" + form: + required: true + primary: true + predicate: http://schema.org/keywords + resource_type: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "resource_type_sim" + - "resource_type_tesim" + predicate: http://purl.org/dc/terms/type + rights_statement: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "rights_statement_sim" + - "rights_statement_tesim" + predicate: http://www.europeana.eu/schemas/edm/rights + license: + type: string + multiple: true + form: + primary: false + index_keys: + - "license_sim" + - "license_tesim" + predicate: http://purl.org/dc/terms/license + abstract: + type: string + multiple: true + form: + primary: false + index_keys: + - "abstract_sim" + - "abstract_tesim" + predicate: http://purl.org/dc/terms/abstract + access_right: + type: string + multiple: true + form: + primary: false + index_keys: + - "access_right_sim" + - "access_right_tesim" + predicate: http://purl.org/dc/terms/accessRights + additional_information: + type: string + multiple: true + form: + primary: false + index_keys: + - "additional_information_tesim" + predicate: http://purl.org/dc/terms/accessRights admin_note: type: string multiple: false + form: + primary: false index_keys: - "admin_note_tesim" + predicate: http://schema.org/positiveNotes + alternative_title: + type: string + multiple: true form: - required: false primary: false - multiple: false - predicate: http://schema.org/positiveNotes + index_keys: + - "alternative_title_sim" + - "alternative_title_tesim" + predicate: http://purl.org/dc/terms/alternative + 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 + bibliographic_citation: + type: string + multiple: true + form: + primary: false + index_keys: + - "bibliographic_citation_tesim" + predicate: http://purl.org/dc/terms/bibliographicCitation + contributor: + type: string + multiple: true + form: + primary: false + index_keys: + - "contributor_tesim" + - "contributor_sim" + predicate: http://purl.org/dc/elements/1.1/contributor + date_created: + type: date_time + multiple: true + form: + primary: false + index_keys: + - "date_created_sim" + - "date_created_tesim" + predicate: http://purl.org/dc/terms/created + description: + type: string + multiple: true + form: + primary: false + index_keys: + - "description_sim" + - "description_tesim" + predicate: http://purl.org/dc/elements/1.1/description + extent: + type: string + multiple: true + form: + primary: false + index_keys: + - "extent_tesim" + predicate: http://purl.org/dc/terms/extent + identifier: + type: string + multiple: true + form: + primary: false + index_keys: + - "identifier_sim" + - "identifier_tesim" + predicate: http://purl.org/dc/terms/identifier + language: + type: string + multiple: true + form: + primary: false + index_keys: + - "language_sim" + - "language_tesim" + predicate: http://purl.org/dc/elements/1.1/language + publisher: + type: string + multiple: true + form: + primary: false + index_keys: + - "publisher_sim" + - "publisher_tesim" + predicate: http://purl.org/dc/elements/1.1/publisher + related_url: + type: string + multiple: true + form: + primary: false + index_keys: + - "related_url_sim" + - "related_url_tesim" + predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso + rights_notes: + type: string + multiple: true + form: + primary: false + index_keys: + - "rights_notes_sim" + - "rights_notes_tesim" + predicate: http://purl.org/dc/elements/1.1/rights + source: + type: string + multiple: true + form: + primary: false + index_keys: + - "source_sim" + - "source_tesim" + predicate: http://purl.org/dc/terms/source + subject: + type: string + multiple: true + index_keys: + - "subject_sim" + - "subject_tesim" + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/subject + date: + type: string + multiple: false + index_keys: + - "date_tesim" + - "date_sim" + predicate: https://hykucommons.org/terms/date + arkivo_checksum: + type: string + multiple: false + predicate: http://scholarsphere.psu.edu/ns#arkivoChecksum + import_url: + type: string + predicate: http://scholarsphere.psu.edu/ns#importUrl + label: + type: string + index_keys: + - "label_sim" + - "label_tesim" + predicate: info:fedora/fedora-system:def/model#downloadFilename + relative_path: + type: string + predicate: http://scholarsphere.psu.edu/ns#relativePath + bulkrax_identifier: + type: string + predicate: https://hykucommons.org/terms/bulkrax_identifier + multiple: false + index_keys: + - "bulkrax_identifier_tesim" + - "bulkrax_identifier_sim" From 84e8e6b3643464f1d9e23037a4eb43665dd26dc7 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 20 May 2024 09:29:37 -0700 Subject: [PATCH 19/28] Valkyrize GenericWorkResourceDecorator --- .../generic_work_resource_form_decorator.rb | 13 + ...generic_work_resource_indexer_decorator.rb | 13 + app/models/generic_work_resource_decorator.rb | 2 - .../generic_work_resource_decorator.yaml | 229 +++++++++++++++++- hyrax-webapp | 2 +- 5 files changed, 253 insertions(+), 6 deletions(-) create mode 100644 app/forms/generic_work_resource_form_decorator.rb create mode 100644 app/indexers/generic_work_resource_indexer_decorator.rb diff --git a/app/forms/generic_work_resource_form_decorator.rb b/app/forms/generic_work_resource_form_decorator.rb new file mode 100644 index 0000000..260f735 --- /dev/null +++ b/app/forms/generic_work_resource_form_decorator.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module GenericWorkResourceFormDecorator + extend ActiveSupport::Concern + + prepended do + include Hyrax::FormFields(:generic_work_resource_decorator) + include Hyrax::FormFields(:with_pdf_viewer) + include Hyrax::FormFields(:with_video_embed) + end +end + +GenericWorkResourceForm.prepend(GenericWorkResourceFormDecorator) diff --git a/app/indexers/generic_work_resource_indexer_decorator.rb b/app/indexers/generic_work_resource_indexer_decorator.rb new file mode 100644 index 0000000..c6de0db --- /dev/null +++ b/app/indexers/generic_work_resource_indexer_decorator.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module GenericWorkResourceIndexerDecorator + extend ActiveSupport::Concern + + prepended do + include Hyrax::Indexer(:generic_work_resource_decorator) + include Hyrax::Indexer(:with_pdf_viewer) + include Hyrax::Indexer(:with_video_embed) + end +end + +GenericWorkResourceIndexer.prepend(GenericWorkResourceIndexerDecorator) diff --git a/app/models/generic_work_resource_decorator.rb b/app/models/generic_work_resource_decorator.rb index bf6dd86..b0a5ffa 100644 --- a/app/models/generic_work_resource_decorator.rb +++ b/app/models/generic_work_resource_decorator.rb @@ -5,8 +5,6 @@ module GenericWorkResourceDecorator extend ActiveSupport::Concern prepended do - include Hyrax::Schema(:basic_metadata) - include Hyrax::Schema(:bulkrax_metadata) include Hyrax::Schema(:generic_work_resource_decorator) include Hyrax::Schema(:with_pdf_viewer) include Hyrax::Schema(:with_video_embed) diff --git a/config/metadata/generic_work_resource_decorator.yaml b/config/metadata/generic_work_resource_decorator.yaml index 7c9fe3c..e915296 100644 --- a/config/metadata/generic_work_resource_decorator.yaml +++ b/config/metadata/generic_work_resource_decorator.yaml @@ -22,13 +22,236 @@ # `rails generate hyrax:work_resource GenericWorkResource` attributes: + creator: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "creator_sim" + - "creator_tesim" + predicate: http://purl.org/dc/elements/1.1/creator + keyword: + type: string + multiple: true + index_keys: + - "keyword_sim" + - "keyword_tesim" + form: + required: true + primary: true + predicate: http://schema.org/keywords + rights_statement: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "rights_statement_sim" + - "rights_statement_tesim" + predicate: http://www.europeana.eu/schemas/edm/rights + resource_type: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "resource_type_sim" + - "resource_type_tesim" + predicate: http://purl.org/dc/terms/type + license: + type: string + multiple: true + form: + primary: false + index_keys: + - "license_sim" + - "license_tesim" + predicate: http://purl.org/dc/terms/license + abstract: + type: string + multiple: true + form: + primary: false + index_keys: + - "abstract_sim" + - "abstract_tesim" + predicate: http://purl.org/dc/terms/abstract + access_right: + type: string + multiple: true + form: + primary: false + index_keys: + - "access_right_sim" + - "access_right_tesim" + predicate: http://purl.org/dc/terms/accessRights + additional_information: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "additional_information_tesim" + predicate: http://purl.org/dc/terms/accessRights admin_note: type: string multiple: false - index_keys: - - "admin_note_tesim" form: - required: false primary: false multiple: false + index_keys: + - "admin_note_tesim" predicate: http://schema.org/positiveNotes + alternative_title: + type: string + multiple: true + form: + primary: false + index_keys: + - "alternative_title_sim" + - "alternative_title_tesim" + predicate: http://purl.org/dc/terms/alternative + 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 + bibliographic_citation: + type: string + multiple: true + form: + primary: false + multiple: true + index_keys: + - "bibliographic_citation_tesim" + predicate: http://purl.org/dc/terms/bibliographicCitation + contributor: + type: string + multiple: true + form: + primary: false + index_keys: + - "contributor_tesim" + - "contributor_sim" + predicate: http://purl.org/dc/elements/1.1/contributor + date_created: + type: date_time + multiple: true + form: + primary: false + index_keys: + - "date_created_sim" + - "date_created_tesim" + predicate: http://purl.org/dc/terms/created + description: + type: string + multiple: true + form: + primary: false + index_keys: + - "description_sim" + - "description_tesim" + predicate: http://purl.org/dc/elements/1.1/description + identifier: + type: string + multiple: true + form: + primary: false + index_keys: + - "identifier_sim" + - "identifier_tesim" + predicate: http://purl.org/dc/terms/identifier + language: + type: string + multiple: true + form: + primary: false + index_keys: + - "language_sim" + - "language_tesim" + predicate: http://purl.org/dc/elements/1.1/language + publisher: + type: string + multiple: true + form: + primary: false + index_keys: + - "publisher_sim" + - "publisher_tesim" + predicate: http://purl.org/dc/elements/1.1/publisher + related_url: + type: string + multiple: true + form: + primary: false + index_keys: + - "related_url_sim" + - "related_url_tesim" + predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso + rights_notes: + type: string + multiple: true + form: + primary: false + index_keys: + - "rights_notes_sim" + - "rights_notes_tesim" + predicate: http://purl.org/dc/elements/1.1/rights + source: + type: string + multiple: true + form: + primary: false + index_keys: + - "source_sim" + - "source_tesim" + predicate: http://purl.org/dc/terms/source + subject: + type: string + multiple: true + index_keys: + - "subject_sim" + - "subject_tesim" + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/subject + + bulkrax_identifier: + type: string + multiple: false + index_keys: + - "bulkrax_identifier_tesim" + - "bulkrax_identifier_sim" + predicate: https://hykucommons.org/terms/bulkrax_identifier + date: + type: string + multiple: false + index_keys: + - "date_tesim" + - "date_sim" + predicate: https://hykucommons.org/terms/date + arkivo_checksum: + type: string + multiple: false + predicate: http://scholarsphere.psu.edu/ns#arkivoChecksum + import_url: + type: string + predicate: http://scholarsphere.psu.edu/ns#importUrl + label: + type: string + index_keys: + - "label_sim" + - "label_tesim" + predicate: info:fedora/fedora-system:def/model#downloadFilename + relative_path: + type: string + predicate: http://scholarsphere.psu.edu/ns#relativePath diff --git a/hyrax-webapp b/hyrax-webapp index 66c9217..e9fb702 160000 --- a/hyrax-webapp +++ b/hyrax-webapp @@ -1 +1 @@ -Subproject commit 66c9217a72a9cf39c9fa467920fb701149f599b4 +Subproject commit e9fb702ff9c15a7d9fee81f91f882e343a71a9ff From 88a0742503f454bdb6473c1a15e0eee6ad3fe684 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 20 May 2024 09:43:22 -0700 Subject: [PATCH 20/28] update submodule --- hyrax-webapp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyrax-webapp b/hyrax-webapp index 0ceee1f..e9fb702 160000 --- a/hyrax-webapp +++ b/hyrax-webapp @@ -1 +1 @@ -Subproject commit 0ceee1f941731be2b358451d7b175567f9404d6f +Subproject commit e9fb702ff9c15a7d9fee81f91f882e343a71a9ff From 80c9417fc6bce989bede8b35fa3e59e453c9936a Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Mon, 20 May 2024 10:38:18 -0700 Subject: [PATCH 21/28] :broom: Allow for custom metadata overrides This commit reworks the prior ones, to allow us to override metadata defined in Hyku. --- app/forms/generic_work_resource_form_decorator.rb | 13 ------------- app/forms/image_resource_form_decorator.rb | 13 ------------- .../generic_work_resource_indexer_decorator.rb | 13 ------------- app/indexers/image_resource_indexer_decorator.rb | 13 ------------- app/models/cdl_resource.rb | 1 + app/models/etd_resource.rb | 1 + app/models/generic_work_resource_decorator.rb | 14 -------------- app/models/image_resource_decorator.rb | 14 -------------- app/models/oer_resource.rb | 1 + .../hyrax/simple_schema_loader_decorator.rb | 2 +- config/metadata/basic_metadata.yaml | 5 +++++ config/metadata/bulkrax_metadata.yaml | 14 ++++++++++++++ config/metadata/cdl_resource.yaml | 7 ------- config/metadata/etd_resource.yaml | 11 ----------- ...e_decorator.yaml => generic_work_resource.yaml} | 8 -------- ...resource_decorator.yaml => image_resource.yaml} | 8 +------- config/metadata/oer_resource.yaml | 7 ------- 17 files changed, 24 insertions(+), 121 deletions(-) delete mode 100644 app/forms/generic_work_resource_form_decorator.rb delete mode 100644 app/forms/image_resource_form_decorator.rb delete mode 100644 app/indexers/generic_work_resource_indexer_decorator.rb delete mode 100644 app/indexers/image_resource_indexer_decorator.rb delete mode 100644 app/models/generic_work_resource_decorator.rb delete mode 100644 app/models/image_resource_decorator.rb create mode 100644 config/metadata/basic_metadata.yaml create mode 100644 config/metadata/bulkrax_metadata.yaml rename config/metadata/{generic_work_resource_decorator.yaml => generic_work_resource.yaml} (96%) rename config/metadata/{image_resource_decorator.yaml => image_resource.yaml} (96%) diff --git a/app/forms/generic_work_resource_form_decorator.rb b/app/forms/generic_work_resource_form_decorator.rb deleted file mode 100644 index 260f735..0000000 --- a/app/forms/generic_work_resource_form_decorator.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module GenericWorkResourceFormDecorator - extend ActiveSupport::Concern - - prepended do - include Hyrax::FormFields(:generic_work_resource_decorator) - include Hyrax::FormFields(:with_pdf_viewer) - include Hyrax::FormFields(:with_video_embed) - end -end - -GenericWorkResourceForm.prepend(GenericWorkResourceFormDecorator) diff --git a/app/forms/image_resource_form_decorator.rb b/app/forms/image_resource_form_decorator.rb deleted file mode 100644 index 566a441..0000000 --- a/app/forms/image_resource_form_decorator.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module ImageResourceFormDecorator - extend ActiveSupport::Concern - - prepended do - include Hyrax::FormFields(:image_resource_decorator) - include Hyrax::FormFields(:with_pdf_viewer) - include Hyrax::FormFields(:with_video_embed) - end -end - -ImageResourceForm.prepend(ImageResourceFormDecorator) diff --git a/app/indexers/generic_work_resource_indexer_decorator.rb b/app/indexers/generic_work_resource_indexer_decorator.rb deleted file mode 100644 index c6de0db..0000000 --- a/app/indexers/generic_work_resource_indexer_decorator.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module GenericWorkResourceIndexerDecorator - extend ActiveSupport::Concern - - prepended do - include Hyrax::Indexer(:generic_work_resource_decorator) - include Hyrax::Indexer(:with_pdf_viewer) - include Hyrax::Indexer(:with_video_embed) - end -end - -GenericWorkResourceIndexer.prepend(GenericWorkResourceIndexerDecorator) diff --git a/app/indexers/image_resource_indexer_decorator.rb b/app/indexers/image_resource_indexer_decorator.rb deleted file mode 100644 index 6558547..0000000 --- a/app/indexers/image_resource_indexer_decorator.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module ImageResourceIndexerDecorator - extend ActiveSupport::Concern - - prepended do - include Hyrax::Indexer(:image_resource_decorator) - include Hyrax::Indexer(:with_pdf_viewer) - include Hyrax::Indexer(:with_video_embed) - end -end - -ImageResourceIndexer.prepend(ImageResourceIndexerDecorator) diff --git a/app/models/cdl_resource.rb b/app/models/cdl_resource.rb index b7d48e1..bd29638 100644 --- a/app/models/cdl_resource.rb +++ b/app/models/cdl_resource.rb @@ -6,6 +6,7 @@ class CdlResource < Hyrax::Work # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. # include Hyrax::Schema(:basic_metadata) include Hyrax::Schema(:cdl_resource) + include Hyrax::Schema(:bulkrax_metadata) include Hyrax::Schema(:with_pdf_viewer) include Hyrax::Schema(:with_video_embed) include Hyrax::ArResource diff --git a/app/models/etd_resource.rb b/app/models/etd_resource.rb index 6d2ef34..27b4294 100644 --- a/app/models/etd_resource.rb +++ b/app/models/etd_resource.rb @@ -6,6 +6,7 @@ class EtdResource < Hyrax::Work # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. # include Hyrax::Schema(:basic_metadata) include Hyrax::Schema(:etd_resource) + include Hyrax::Schema(:bulkrax_metadata) include Hyrax::Schema(:with_pdf_viewer) include Hyrax::Schema(:with_video_embed) include Hyrax::ArResource diff --git a/app/models/generic_work_resource_decorator.rb b/app/models/generic_work_resource_decorator.rb deleted file mode 100644 index b0a5ffa..0000000 --- a/app/models/generic_work_resource_decorator.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -# OVERRIDE to customize metadata -module GenericWorkResourceDecorator - extend ActiveSupport::Concern - - prepended do - include Hyrax::Schema(:generic_work_resource_decorator) - include Hyrax::Schema(:with_pdf_viewer) - include Hyrax::Schema(:with_video_embed) - end -end - -GenericWorkResource.prepend(GenericWorkResourceDecorator) diff --git a/app/models/image_resource_decorator.rb b/app/models/image_resource_decorator.rb deleted file mode 100644 index bb80807..0000000 --- a/app/models/image_resource_decorator.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -# OVERRIDE to customize metadata -module ImageResourceDecorator - extend ActiveSupport::Concern - - prepended do - include Hyrax::Schema(:image_resource_decorator) - include Hyrax::Schema(:with_pdf_viewer) - include Hyrax::Schema(:with_video_embed) - end -end - -ImageResource.prepend(ImageResourceDecorator) diff --git a/app/models/oer_resource.rb b/app/models/oer_resource.rb index 20c0681..854bf6f 100644 --- a/app/models/oer_resource.rb +++ b/app/models/oer_resource.rb @@ -6,6 +6,7 @@ class OerResource < Hyrax::Work # Commented out basic_metadata because these terms were added to etd_resource so we can customize it. # include Hyrax::Schema(:basic_metadata) include Hyrax::Schema(:oer_resource) + include Hyrax::Schema(:bulkrax_metadata) include Hyrax::Schema(:with_pdf_viewer) include Hyrax::Schema(:with_video_embed) include Hyrax::ArResource diff --git a/app/services/hyrax/simple_schema_loader_decorator.rb b/app/services/hyrax/simple_schema_loader_decorator.rb index 07adc3b..413e44c 100644 --- a/app/services/hyrax/simple_schema_loader_decorator.rb +++ b/app/services/hyrax/simple_schema_loader_decorator.rb @@ -5,7 +5,7 @@ module Hyrax module SimpleSchemaLoaderDecorator def config_search_paths - super + [HykuKnapsack::Engine.root] + [HykuKnapsack::Engine.root] + super end end end diff --git a/config/metadata/basic_metadata.yaml b/config/metadata/basic_metadata.yaml new file mode 100644 index 0000000..47fdc51 --- /dev/null +++ b/config/metadata/basic_metadata.yaml @@ -0,0 +1,5 @@ +# This file is blank to override base Hyku +# Each model will have its own model resource metadata.yaml +# that includes basic metadata for more customizations + +attributes: {} \ No newline at end of file diff --git a/config/metadata/bulkrax_metadata.yaml b/config/metadata/bulkrax_metadata.yaml new file mode 100644 index 0000000..61d66e7 --- /dev/null +++ b/config/metadata/bulkrax_metadata.yaml @@ -0,0 +1,14 @@ +attributes: + bulkrax_identifier: + type: string + predicate: https://hykucommons.org/terms/bulkrax_identifier + multiple: false + index_keys: + # NOTE: For backwards compatibility, we specify `bulkrax_identifier_tesim` + # however if we want singular (which we do) and to have exact match + # (which we do) we don't want to use Text English Stored Indexed + # Multiple (e.g. _tesim suffix). Instead we want String Stored + # Index (e.g. _ssi). However, until we get all of our efforts + # coordinated; we'll continue to contend with this misalignment. + - "bulkrax_identifier_tesim" + - "bulkrax_identifier_ssi" diff --git a/config/metadata/cdl_resource.yaml b/config/metadata/cdl_resource.yaml index 1cb4a82..a4add70 100644 --- a/config/metadata/cdl_resource.yaml +++ b/config/metadata/cdl_resource.yaml @@ -239,13 +239,6 @@ attributes: form: primary: false predicate: http://purl.org/dc/elements/1.1/subject - bulkrax_identifier: - type: string - predicate: https://hykucommons.org/terms/bulkrax_identifier - multiple: false - index_keys: - - "bulkrax_identifier_tesim" - - "bulkrax_identifier_sim" arkivo_checksum: type: string multiple: false diff --git a/config/metadata/etd_resource.yaml b/config/metadata/etd_resource.yaml index e50d6f7..5e4fddb 100644 --- a/config/metadata/etd_resource.yaml +++ b/config/metadata/etd_resource.yaml @@ -309,17 +309,6 @@ attributes: form: primary: false predicate: http://purl.org/dc/elements/1.1/subject - bulkrax_identifier: - type: string - multiple: false - index_keys: - - "bulkrax_identifier_sim" - - "bulkrax_identifier_tesim" - # form: - # required: false - # primary: false - # multiple: false - predicate: https://hykucommons.org/terms/bulkrax_identifier arkivo_checksum: type: string multiple: false diff --git a/config/metadata/generic_work_resource_decorator.yaml b/config/metadata/generic_work_resource.yaml similarity index 96% rename from config/metadata/generic_work_resource_decorator.yaml rename to config/metadata/generic_work_resource.yaml index e915296..c750ae3 100644 --- a/config/metadata/generic_work_resource_decorator.yaml +++ b/config/metadata/generic_work_resource.yaml @@ -224,14 +224,6 @@ attributes: form: primary: false predicate: http://purl.org/dc/elements/1.1/subject - - bulkrax_identifier: - type: string - multiple: false - index_keys: - - "bulkrax_identifier_tesim" - - "bulkrax_identifier_sim" - predicate: https://hykucommons.org/terms/bulkrax_identifier date: type: string multiple: false diff --git a/config/metadata/image_resource_decorator.yaml b/config/metadata/image_resource.yaml similarity index 96% rename from config/metadata/image_resource_decorator.yaml rename to config/metadata/image_resource.yaml index d8a3ae5..f74b2cd 100644 --- a/config/metadata/image_resource_decorator.yaml +++ b/config/metadata/image_resource.yaml @@ -252,10 +252,4 @@ attributes: relative_path: type: string predicate: http://scholarsphere.psu.edu/ns#relativePath - bulkrax_identifier: - type: string - predicate: https://hykucommons.org/terms/bulkrax_identifier - multiple: false - index_keys: - - "bulkrax_identifier_tesim" - - "bulkrax_identifier_sim" + diff --git a/config/metadata/oer_resource.yaml b/config/metadata/oer_resource.yaml index 4e798a1..27aeb56 100644 --- a/config/metadata/oer_resource.yaml +++ b/config/metadata/oer_resource.yaml @@ -313,13 +313,6 @@ attributes: index_keys: - "table_of_contents_tesim" predicate: http://purl.org/dc/terms/tableOfContents - bulkrax_identifier: - type: string - multiple: false - index_keys: - - "bulkrax_identifier_tesim" - - "bulkrax_identifier_sim" - predicate: https://hykucommons.org/terms/bulkrax_identifier" previous_version_id: type: string multiple: true From 6fbe72b3ce1d25c566f538b293a932e85c8e6030 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Mon, 20 May 2024 10:38:50 -0700 Subject: [PATCH 22/28] :broom: replace glyphicon with font awesome --- app/helpers/hyrax/override_helper_behavior.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/hyrax/override_helper_behavior.rb b/app/helpers/hyrax/override_helper_behavior.rb index e1717a9..34309b3 100644 --- a/app/helpers/hyrax/override_helper_behavior.rb +++ b/app/helpers/hyrax/override_helper_behavior.rb @@ -49,7 +49,7 @@ def truncate_and_iconify_auto_link(field, show_link = true) # this block is only executed when a link is inserted; # if we pass text containing no links, it just returns text. auto_link(html_escape(text)) do |value| - "#{(' ' + value) if show_link}" + "#{(' ' + value) if show_link}" end text.truncate(230, separator: ' ') end From 9e303dc783066ee5d2ff0c42b328ace9d9f50be1 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Mon, 20 May 2024 10:40:04 -0700 Subject: [PATCH 23/28] Update submodule --- hyrax-webapp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyrax-webapp b/hyrax-webapp index e9fb702..1de2d9c 160000 --- a/hyrax-webapp +++ b/hyrax-webapp @@ -1 +1 @@ -Subproject commit e9fb702ff9c15a7d9fee81f91f882e343a71a9ff +Subproject commit 1de2d9c31a6d53536c47ebee32061d6f0498ac44 From 22b8d01c08d6aad2fe60cc6eff59ec517456e61f Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Mon, 20 May 2024 10:45:16 -0700 Subject: [PATCH 24/28] update submodule --- hyrax-webapp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyrax-webapp b/hyrax-webapp index e9fb702..1de2d9c 160000 --- a/hyrax-webapp +++ b/hyrax-webapp @@ -1 +1 @@ -Subproject commit e9fb702ff9c15a7d9fee81f91f882e343a71a9ff +Subproject commit 1de2d9c31a6d53536c47ebee32061d6f0498ac44 From 307edee052be68218824b7a1994aca629d4a8b44 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 20 May 2024 13:35:01 -0700 Subject: [PATCH 25/28] Fix some Oer stuff This commit will fix the Oer edit page because it was not loading correctly and also the required badge in the forms. --- app/forms/oer_resource_form.rb | 11 ++++++++++- app/models/oer_resource.rb | 8 ++++---- app/views/hyrax/oers/_related_items.html.erb | 8 ++++---- .../cultural_show/hyrax/oers/_related_items.html.erb | 9 ++++----- config/locales/hyrax.en.yml | 2 +- config/locales/locales/hyrax.de.yml | 2 +- config/locales/locales/hyrax.en.yml | 2 +- config/locales/locales/hyrax.es.yml | 2 +- config/locales/locales/hyrax.fr.yml | 2 +- config/locales/locales/hyrax.it.yml | 2 +- config/locales/locales/hyrax.pt-BR.yml | 2 +- config/locales/locales/hyrax.zh.yml | 2 +- 12 files changed, 30 insertions(+), 22 deletions(-) diff --git a/app/forms/oer_resource_form.rb b/app/forms/oer_resource_form.rb index 47bc3df..0efe325 100644 --- a/app/forms/oer_resource_form.rb +++ b/app/forms/oer_resource_form.rb @@ -21,7 +21,8 @@ class OerResourceForm < Hyrax::Forms::ResourceForm(OerResource) # # property :user_input_not_destined_for_the_model, virtual: true - delegate :related_members_attributes=, :previous_version, :newer_version, :alternate_version, :related_item, to: :model + delegate :related_members_attributes=, :previous_version, :newer_version, :alternate_version, :related_item, + :previous_version_id, :newer_version_id, :alternate_version_id, :related_item_id, to: :model def self.build_permitted_params super + [ @@ -32,6 +33,8 @@ def self.build_permitted_params end def previous_version_json + return unless previous_version.present? + previous_version.map do |child| { id: child.id, @@ -43,6 +46,8 @@ def previous_version_json end def newer_version_json + return unless newer_version.present? + newer_version.map do |child| { id: child.id, @@ -54,6 +59,8 @@ def newer_version_json end def alternate_version_json + return unless alternate_version.present? + alternate_version.map do |child| { id: child.id, @@ -65,6 +72,8 @@ def alternate_version_json end def related_item_json + return unless related_item.present? + related_item.map do |child| { id: child.id, diff --git a/app/models/oer_resource.rb b/app/models/oer_resource.rb index 854bf6f..ea6e0b7 100644 --- a/app/models/oer_resource.rb +++ b/app/models/oer_resource.rb @@ -22,18 +22,18 @@ class OerResource < Hyrax::Work prepend OrderAlready.for(:creator) def previous_version - @previous_version ||= Hyrax.query_service.find_by(id: previous_version_id) if previous_version_id + @previous_version ||= Hyrax.query_service.find_by(id: previous_version_id) if previous_version_id.present? end def newer_version - @newer_version ||= Hyrax.query_service.find_by(id: newer_version_id) if newer_version_id + @newer_version ||= Hyrax.query_service.find_by(id: newer_version_id) if newer_version_id.present? end def alternate_version - @alternate_version ||= Hyrax.query_service.find_by(id: alternate_version_id) if alternate_version_id + @alternate_version ||= Hyrax.query_service.find_by(id: alternate_version_id) if alternate_version_id.present? end def related_item - @related_item ||= Hyrax.query_service.find_by(id: related_item_id) if related_item_id + @related_item ||= Hyrax.query_service.find_by(id: related_item_id) if related_item_id.present? end end diff --git a/app/views/hyrax/oers/_related_items.html.erb b/app/views/hyrax/oers/_related_items.html.erb index bf9c2e1..551c12a 100644 --- a/app/views/hyrax/oers/_related_items.html.erb +++ b/app/views/hyrax/oers/_related_items.html.erb @@ -1,7 +1,7 @@ -<% previous_members = presenter.member_presenters_for(presenter.previous_versions) %> -<% newer_members = presenter.member_presenters_for(presenter.newer_versions) %> -<% alternate_members = presenter.member_presenters_for(presenter.alternate_versions) %> -<% related_items = presenter.member_presenters_for(presenter.related_items) %> +<% previous_members = presenter.member_presenters(presenter.previous_versions) %> +<% newer_members = presenter.member_presenters(presenter.newer_versions) %> +<% alternate_members = presenter.member_presenters(presenter.alternate_versions) %> +<% related_items = presenter.member_presenters(presenter.related_items) %> <% if previous_members.present? || newer_members.present? || alternate_members.present? || related_items.present? %>

<%= t('hyrax.oer.show.related_items') %>

diff --git a/app/views/themes/cultural_show/hyrax/oers/_related_items.html.erb b/app/views/themes/cultural_show/hyrax/oers/_related_items.html.erb index b38bf49..bfdfa4a 100644 --- a/app/views/themes/cultural_show/hyrax/oers/_related_items.html.erb +++ b/app/views/themes/cultural_show/hyrax/oers/_related_items.html.erb @@ -1,7 +1,7 @@ -<% previous_members = presenter.member_presenters_for(presenter.previous_versions) %> -<% newer_members = presenter.member_presenters_for(presenter.newer_versions) %> -<% alternate_members = presenter.member_presenters_for(presenter.alternate_versions) %> -<% related_items = presenter.member_presenters_for(presenter.related_items) %> +<% previous_members = presenter.member_presenters(presenter.previous_versions) %> +<% newer_members = presenter.member_presenters(presenter.newer_versions) %> +<% alternate_members = presenter.member_presenters(presenter.alternate_versions) %> +<% related_items = presenter.member_presenters(presenter.related_items) %> <% if previous_members.present? || newer_members.present? || alternate_members.present? || related_items.present? %>

<%= t('hyrax.oer.show.related_items') %>

@@ -26,4 +26,3 @@ <% end %> <% end %> - diff --git a/config/locales/hyrax.en.yml b/config/locales/hyrax.en.yml index 82b1786..2e253c1 100644 --- a/config/locales/hyrax.en.yml +++ b/config/locales/hyrax.en.yml @@ -1212,4 +1212,4 @@ en: find_child_work: Search for a work… member_of_collection_ids: Select a collection… required: - html: required \ No newline at end of file + html: required diff --git a/config/locales/locales/hyrax.de.yml b/config/locales/locales/hyrax.de.yml index b1ed408..daab142 100644 --- a/config/locales/locales/hyrax.de.yml +++ b/config/locales/locales/hyrax.de.yml @@ -1211,4 +1211,4 @@ de: find_child_work: Suche nach einer Arbeit… member_of_collection_ids: Sammlung auswählen… required: - html: erforderlich + html: erforderlich diff --git a/config/locales/locales/hyrax.en.yml b/config/locales/locales/hyrax.en.yml index d862ca1..10b783d 100644 --- a/config/locales/locales/hyrax.en.yml +++ b/config/locales/locales/hyrax.en.yml @@ -1216,4 +1216,4 @@ en: find_child_work: Search for a work… member_of_collection_ids: Select a collection… required: - html: required + html: required diff --git a/config/locales/locales/hyrax.es.yml b/config/locales/locales/hyrax.es.yml index 26e1354..f98966c 100644 --- a/config/locales/locales/hyrax.es.yml +++ b/config/locales/locales/hyrax.es.yml @@ -1212,4 +1212,4 @@ es: find_child_work: Busca trabajo ... member_of_collection_ids: Seleccione una colección ... required: - html: necesario + html: necesario diff --git a/config/locales/locales/hyrax.fr.yml b/config/locales/locales/hyrax.fr.yml index 828f8b3..c59b384 100644 --- a/config/locales/locales/hyrax.fr.yml +++ b/config/locales/locales/hyrax.fr.yml @@ -1212,4 +1212,4 @@ fr: find_child_work: Rechercher une œuvre… member_of_collection_ids: Sélectionnez une collection… required: - html: obligatoire + html: obligatoire diff --git a/config/locales/locales/hyrax.it.yml b/config/locales/locales/hyrax.it.yml index a329f20..755c8fd 100644 --- a/config/locales/locales/hyrax.it.yml +++ b/config/locales/locales/hyrax.it.yml @@ -1212,4 +1212,4 @@ it: find_child_work: Cerca un'opera ... member_of_collection_ids: Seleziona una collezione ... required: - html: necessario + html: necessario diff --git a/config/locales/locales/hyrax.pt-BR.yml b/config/locales/locales/hyrax.pt-BR.yml index 87d3196..9026a97 100644 --- a/config/locales/locales/hyrax.pt-BR.yml +++ b/config/locales/locales/hyrax.pt-BR.yml @@ -1212,4 +1212,4 @@ pt-BR: find_child_work: Procure um trabalho… member_of_collection_ids: Selecione uma coleção… required: - html: requeridos + html: requeridos diff --git a/config/locales/locales/hyrax.zh.yml b/config/locales/locales/hyrax.zh.yml index a59edcd..624a478 100644 --- a/config/locales/locales/hyrax.zh.yml +++ b/config/locales/locales/hyrax.zh.yml @@ -1212,4 +1212,4 @@ zh: find_child_work: 正在搜寻作品… member_of_collection_ids: 选择一个收藏夹… required: - html: 需要 + html: 需要 From 6da581c1acc53f772b002ed2908f67628199c8ce Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 20 May 2024 14:50:07 -0700 Subject: [PATCH 26/28] Address CDL listener This commit will add a CDL Listener that will replace the model callback. --- app/jobs/destroy_cdl_group_job.rb | 4 ++ .../active_fedora_property_locator.rb | 71 +++++++++++++++++++ app/services/listeners/cdl_listener.rb | 13 ++++ .../initializers/hyku_knapsack_listeners.rb | 3 + 4 files changed, 91 insertions(+) create mode 100644 app/services/hyku_knapsack/active_fedora_property_locator.rb create mode 100644 app/services/listeners/cdl_listener.rb create mode 100644 config/initializers/hyku_knapsack_listeners.rb diff --git a/app/jobs/destroy_cdl_group_job.rb b/app/jobs/destroy_cdl_group_job.rb index ddb9115..29d0204 100644 --- a/app/jobs/destroy_cdl_group_job.rb +++ b/app/jobs/destroy_cdl_group_job.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Probably not needed because we're only going to ever +# be destroying one group so a background job is unnecessary. +# Leaving it here for now because the Cdl model still references it. +# But in Valkyrie, we're going to just destroy the group in the Listener. class DestroyCdlGroupJob < ApplicationJob queue_as :default diff --git a/app/services/hyku_knapsack/active_fedora_property_locator.rb b/app/services/hyku_knapsack/active_fedora_property_locator.rb new file mode 100644 index 0000000..21fd87c --- /dev/null +++ b/app/services/hyku_knapsack/active_fedora_property_locator.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +module HykuKnapsack + class ActiveFedoraPropertyLocator + attr_reader :klass, :properties + + def initialize(klass) + @klass = klass + locate + generate_dynamic_methods + end + + def from_app + properties.select { |_k, file_path| from_root?(file_path) } + end + + def from_gems + properties.reject { |_k, file_path| from_root?(file_path) } + end + + private + + # @return [Hash] a hash of property names and their file paths (with line numbers) + # @example + # {:has_model=>"/usr/local/bundle/gems/active-fedora-14.0.1/lib/active_fedora/fedora_attributes.rb:15", + # :create_date=>"/usr/local/bundle/gems/active-fedora-14.0.1/lib/active_fedora/fedora_attributes.rb:16"} + def locate + @properties ||= klass.properties.keys.map(&:to_sym).index_with do |property_name| + find_property_definition(klass, property_name) + end + end + + def find_property_definition(klass, property_name) + klass.ancestors.each do |ancestor| + next unless ancestor.name # Skip anonymous modules + file_path, _line_num = Object.const_source_location(ancestor.name) + next unless file_path + + File.read(file_path).force_encoding("UTF-8").scrub.each_line.with_index do |line, line_num| + return "#{file_path}:#{line_num + 1}" if match_property_definition?(line, property_name) + end + end + + nil + end + + def match_property_definition?(line, property_name) + # TODO: If we get a nil as a file_path then we need to improve the regexp + regexp = /^\s*(property|[\w.]+\.property)\s*\(?\s*:\s*#{property_name}\b/ + !line.strip.start_with?('#') && line.match?(regexp) # Skip commented lines + end + + def from_root?(file_path) + file_path.starts_with?(HykuKnapsack::Engine.root.to_s) || file_path.starts_with?(Rails.root.to_s) + end + + def generate_dynamic_methods + method_suffixes = properties.values.each_with_object([]) do |file_path, arr| + next unless file_path + suffix = file_path.split('/').last.split('.').first + arr << suffix unless arr.include?(suffix) + end + + method_suffixes.each do |suffix| + self.class.define_method("from_#{suffix}") do + properties.select { |_k, file_path| file_path.split('.rb').first.include?(suffix) } + end + end + end + end +end diff --git a/app/services/listeners/cdl_listener.rb b/app/services/listeners/cdl_listener.rb new file mode 100644 index 0000000..d395e13 --- /dev/null +++ b/app/services/listeners/cdl_listener.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Listeners + class CdlListener + def on_object_deleted(event) + object = event[:object] + return unless object.is_a?(CdlResource) + + id = object.id + Hyrax::Group.find_by(name: id)&.destroy + end + end +end diff --git a/config/initializers/hyku_knapsack_listeners.rb b/config/initializers/hyku_knapsack_listeners.rb new file mode 100644 index 0000000..198b02d --- /dev/null +++ b/config/initializers/hyku_knapsack_listeners.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +Hyrax.publisher.subscribe(Listeners::CdlListener.new) From 45ec495711e3e93dbd41d81bcf550fdf8f67e9b0 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 20 May 2024 16:47:35 -0700 Subject: [PATCH 27/28] Fix CDLs We remove the registration of all the migrated work types but CDL was misbehaving. The reason is because the indexer and the form was inheriting from the wrong parent and the controller was not following the same pattern. --- app/controllers/hyrax/cdls_controller.rb | 7 ++++++- app/forms/cdl_resource_form.rb | 4 ++-- app/indexers/cdl_resource_indexer.rb | 2 +- config/initializers/hyrax.rb | 6 ------ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/controllers/hyrax/cdls_controller.rb b/app/controllers/hyrax/cdls_controller.rb index d298641..5e0b274 100644 --- a/app/controllers/hyrax/cdls_controller.rb +++ b/app/controllers/hyrax/cdls_controller.rb @@ -5,8 +5,13 @@ module Hyrax class CdlsController < ApplicationController # Adds Hyrax behaviors to the controller. include Hyrax::WorksControllerBehavior + include Hyku::WorksControllerBehavior include Hyrax::BreadcrumbsForWorks - self.curation_concern_type = ::Cdl + self.curation_concern_type = ::CdlResource + + # Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style + # forms. + self.work_form_service = Hyrax::FormFactory.new # Use this line if you want to use a custom presenter self.show_presenter = Hyrax::CdlPresenter diff --git a/app/forms/cdl_resource_form.rb b/app/forms/cdl_resource_form.rb index fa7f7fa..b2bcccd 100644 --- a/app/forms/cdl_resource_form.rb +++ b/app/forms/cdl_resource_form.rb @@ -5,8 +5,8 @@ # # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking -class CdlResourceForm < Hyrax::Forms::PcdmObjectForm(CdlResource) - include Hyrax::FormFields(:basic_metadata) +class CdlResourceForm < Hyrax::Forms::ResourceForm(CdlResource) + # include Hyrax::FormFields(:basic_metadata) include Hyrax::FormFields(:cdl_resource) include Hyrax::FormFields(:with_pdf_viewer) include Hyrax::FormFields(:with_video_embed) diff --git a/app/indexers/cdl_resource_indexer.rb b/app/indexers/cdl_resource_indexer.rb index eae11c5..4ef7488 100644 --- a/app/indexers/cdl_resource_indexer.rb +++ b/app/indexers/cdl_resource_indexer.rb @@ -2,7 +2,7 @@ # Generated via # `rails generate hyrax:work_resource CdlResource` -class CdlResourceIndexer < Hyrax::Indexers::PcdmObjectIndexer(CdlResource) +class CdlResourceIndexer < Hyrax::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) include Hyrax::Indexer(:cdl_resource) diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index f81e987..d3f66f9 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -9,12 +9,6 @@ config.register_curation_concern :etd # # Injected via `rails g hyrax:work Cdl` config.register_curation_concern :cdl - # Injected via `rails g hyrax:work_resource EtdResource` - config.register_curation_concern :etd_resource - # Injected via `rails g hyrax:work_resource OerResource` - config.register_curation_concern :oer_resource - # Injected via `rails g hyrax:work_resource CdlResource` - config.register_curation_concern :cdl_resource # # See https://github.com/scientist-softserv/adventist-dl/issues/183 # # Also, we will continue to extract txt file's text using Adventist::TextFileTextExtractionService From 9732eb4461db60eca2da76afbc957b6576d83626 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 21 May 2024 08:40:19 -0700 Subject: [PATCH 28/28] Fix some specs The collection factory was failing because we overrode the basic_metadata.yaml which it also uses so we need to add all the basic metadata into the collection_resource.yaml. There was a log that was failing because it was not being explicit in the root of the application though I'm unsure if it is needed. The major question is if we need to run hyku_specs or not. --- .../application_controller_decorator.rb | 2 +- config/metadata/collection_resource.yaml | 227 ++++++++++++++++++ 2 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 config/metadata/collection_resource.yaml diff --git a/app/controllers/application_controller_decorator.rb b/app/controllers/application_controller_decorator.rb index 3273c35..a02af69 100644 --- a/app/controllers/application_controller_decorator.rb +++ b/app/controllers/application_controller_decorator.rb @@ -47,7 +47,7 @@ def deny_access_for_anonymous_user(exception, json_message) # rubocop:disable Metrics/AbcSize def global_request_logging FileUtils.mkdir_p(Rails.root.join('log')) unless Dir.exist?(Rails.root.join('log')) - rl = ActiveSupport::Logger.new('log/request.log') + rl = ActiveSupport::Logger.new(Rails.root.join('log', 'request.log')) if request.host&.match('blc.hykucommons') http_request_header_keys = request.headers.env.keys.select { |header_name| header_name.match("^HTTP.*|^X-User.*") } http_request_headers = request.headers.env.select { |header_name, _header_value| http_request_header_keys.index(header_name) } diff --git a/config/metadata/collection_resource.yaml b/config/metadata/collection_resource.yaml new file mode 100644 index 0000000..a1fba95 --- /dev/null +++ b/config/metadata/collection_resource.yaml @@ -0,0 +1,227 @@ +# Simple yaml config-driven schema which is used to define model attributes, +# index key names, and form properties. +# +# Attributes must have a type but all other configuration options are optional. +# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes +# must be placed here. +# +# attributes: +# attribute_name: +# type: string +# multiple: false +# index_keys: +# - "attribute_name_sim" +# form: +# required: true +# primary: true +# multiple: false +# +# @see config/metadata/basic_metadata.yaml for an example configuration +# +# Generated via +# `rails generate hyrax:collection_resource CollectionResource` + +# This is a copy of the basic_metadata.yaml because we override basic_metadata.yaml and making it. +# We do this because we are grouping everything into the *_resource.yaml for more customizations. +attributes: + abstract: + type: string + multiple: true + form: + primary: false + index_keys: + - "abstract_sim" + - "abstract_tesim" + predicate: http://purl.org/dc/terms/abstract + access_right: + type: string + multiple: true + form: + primary: false + index_keys: + - "access_right_sim" + - "access_right_tesim" + predicate: http://purl.org/dc/terms/accessRights + alternative_title: + type: string + multiple: true + form: + primary: false + index_keys: + - "alternative_title_sim" + - "alternative_title_tesim" + predicate: http://purl.org/dc/terms/alternative + arkivo_checksum: + type: string + multiple: false + form: + primary: false + predicate: http://scholarsphere.psu.edu/ns#arkivoChecksum + 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 + bibliographic_citation: + type: string + multiple: true + form: + primary: false + index_keys: + - "bibliographic_citation_sim" + - "bibliographic_citation_tesim" + predicate: http://purl.org/dc/terms/bibliographicCitation + contributor: + type: string + multiple: true + form: + primary: false + index_keys: + - "contributor_tesim" + - "contributor_sim" + predicate: http://purl.org/dc/elements/1.1/contributor + creator: + type: string + multiple: true + form: + required: true + primary: true + index_keys: + - "creator_sim" + - "creator_tesim" + predicate: http://purl.org/dc/elements/1.1/creator + date_created: + type: date_time + multiple: true + form: + primary: false + index_keys: + - "date_created_sim" + - "date_created_tesim" + predicate: http://purl.org/dc/terms/created + description: + type: string + multiple: true + form: + primary: false + index_keys: + - "description_sim" + - "description_tesim" + predicate: http://purl.org/dc/elements/1.1/description + identifier: + type: string + multiple: true + form: + primary: false + index_keys: + - "identifier_sim" + - "identifier_tesim" + predicate: http://purl.org/dc/terms/identifier + import_url: + type: string + predicate: http://scholarsphere.psu.edu/ns#importUrl + keyword: + type: string + multiple: true + index_keys: + - "keyword_sim" + - "keyword_tesim" + form: + primary: false + predicate: http://schema.org/keywords + publisher: + type: string + multiple: true + form: + primary: false + index_keys: + - "publisher_sim" + - "publisher_tesim" + predicate: http://purl.org/dc/elements/1.1/publisher + label: + type: string + form: + primary: false + index_keys: + - "label_sim" + - "label_tesim" + predicate: info:fedora/fedora-system:def/model#downloadFilename + language: + type: string + multiple: true + form: + primary: false + index_keys: + - "language_sim" + - "language_tesim" + predicate: http://purl.org/dc/elements/1.1/language + license: + type: string + multiple: true + form: + primary: false + index_keys: + - "license_sim" + - "license_tesim" + predicate: http://purl.org/dc/terms/license + relative_path: + type: string + predicate: http://scholarsphere.psu.edu/ns#relativePath + related_url: + type: string + multiple: true + form: + primary: false + index_keys: + - "related_url_sim" + - "related_url_tesim" + predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso + 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 + form: + primary: false + index_keys: + - "rights_notes_sim" + - "rights_notes_tesim" + predicate: http://purl.org/dc/elements/1.1/rights + rights_statement: + type: string + multiple: true + form: + primary: true + index_keys: + - "rights_statement_sim" + - "rights_statement_tesim" + predicate: http://www.europeana.eu/schemas/edm/rights + source: + type: string + multiple: true + form: + primary: false + index_keys: + - "source_sim" + - "source_tesim" + predicate: http://purl.org/dc/terms/source + subject: + type: string + multiple: true + index_keys: + - "subject_sim" + - "subject_tesim" + form: + primary: false + predicate: http://purl.org/dc/elements/1.1/subject