From c67680100625352f771e725115b4ef72e93a8dfa Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 6 Jun 2024 13:11:43 -0700 Subject: [PATCH 01/34] initial dynamic loading work --- .dassie/.env | 1 + app/models/concerns/hyrax/flexibility.rb | 80 ++++++++++++++++++++++++ app/models/hyrax/resource.rb | 2 + app/models/hyrax/work.rb | 2 +- lib/hyrax/schema.rb | 8 ++- 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 app/models/concerns/hyrax/flexibility.rb diff --git a/.dassie/.env b/.dassie/.env index 7404394ae3..10d98d4a25 100644 --- a/.dassie/.env +++ b/.dassie/.env @@ -18,6 +18,7 @@ HYRAX_ANALYTICS=false HYRAX_ANALYTICS_PROVIDER=google HYRAX_DERIVATIVES_PATH=/app/samvera/hyrax-webapp/derivatives/ HYRAX_ENGINE_PATH=/app/samvera/hyrax-engine +HYRAX_FLEXIBLE=true HYRAX_UPLOAD_PATH=/app/samvera/hyrax-webapp/uploads/ HYRAX_VALKYRIE=true IN_DOCKER=true diff --git a/app/models/concerns/hyrax/flexibility.rb b/app/models/concerns/hyrax/flexibility.rb new file mode 100644 index 0000000000..a293ad7066 --- /dev/null +++ b/app/models/concerns/hyrax/flexibility.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +module Hyrax + module Flexibility + extend ActiveSupport::Concern + class_methods do + ## Override dry-struct 1.6.0 to enable redefining schemas on the fly + def attributes(new_schema) + keys = new_schema.keys.map { |k| k.to_s.chomp("?").to_sym } + schema Hyrax::Resource.schema.schema(new_schema) + + define_accessors(keys) + + @attribute_names = nil + + direct_descendants = descendants&.select { |d| d.superclass == self } + direct_descendants&.each do |d| + inherited_attrs = new_schema.reject { |k, _| d.has_attribute?(k.to_s.chomp("?").to_sym) } + d.attributes(inherited_attrs) + end + + new_schema.each_key do |key| + key = key.to_s.chomp('?') + next if instance_methods.include?("#{key}=".to_sym) + + class_eval(<<-RUBY) + def #{key}=(value) + set_value("#{key}".to_sym, value) + end + RUBY + end + + self + end + + ## Override dry-struct 1.6.0 to filter attributes after schema reload happens + def new(attributes = default_attributes, safe = false, &block) # rubocop:disable Style/OptionalBooleanParameter + if attributes.is_a?(Struct) + if equal?(attributes.class) + attributes + else + # This implicit coercion is arguable but makes sense overall + # in cases there you pass child struct to the base struct constructor + # User.new(super_user) + # + # We may deprecate this behavior in future forcing people to be explicit + new(attributes.to_h, safe, &block) + end + else + load(attributes, safe) + end + rescue Dry::Types::CoercionError => e + raise Dry::Error, "[#{self}.new] #{e}", e.backtrace + end + + ## Read the schema from the database and load the correct schemas for the instance in to the class + def load(attributes, safe = false) + attributes[:schemas] ||= 'core_metadata:1' + struct = allocate + schema_name, schema_version = attributes[:schemas].split(':') + struct.singleton_class.attributes(Hyrax::Schema(schema_name, schema_version:).attributes) + clean_attributes = safe ? struct.singleton_class.schema.call_safe(attributes) { |output = attributes| return yield output } : struct.singleton_class.schema.call_unsafe(attributes) + struct.__send__(:initialize, clean_attributes) + struct + end + end + + # Override set_value from valkyrie 3.1.1 to enable dynamic schema loading + def set_value(key, value) + @attributes[key.to_sym] = self.singleton_class.schema.key(key.to_sym).type.call(value) + end + + # Override inspect from dry-struct 1.6.0 to enable dynamic schema loading + def inspect + klass = self.singleton_class + attrs = klass.attribute_names.map { |key| " #{key}=#{@attributes[key].inspect}" }.join + "#<#{klass.name || klass.inspect}#{attrs}>" + end + end +end diff --git a/app/models/hyrax/resource.rb b/app/models/hyrax/resource.rb index a0499e96f2..df24eae83c 100644 --- a/app/models/hyrax/resource.rb +++ b/app/models/hyrax/resource.rb @@ -31,12 +31,14 @@ module Hyrax # implementations). # class Resource < Valkyrie::Resource + include Hyrax::Flexibility if ENV.fetch('HYRAX_FLEXIBLE', false) include Hyrax::Naming include Hyrax::WithEvents attribute :alternate_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID) attribute :embargo_id, Valkyrie::Types::Params::ID attribute :lease_id, Valkyrie::Types::Params::ID + attribute :schemas, Valkyrie::Types::String delegate :edit_groups, :edit_groups=, :edit_users, :edit_users=, diff --git a/app/models/hyrax/work.rb b/app/models/hyrax/work.rb index 6ad04b35a0..10eda4b03d 100644 --- a/app/models/hyrax/work.rb +++ b/app/models/hyrax/work.rb @@ -94,7 +94,7 @@ module Hyrax # @see https://wiki.lyrasis.org/display/samvera/Hydra::Works+Shared+Modeling # for a historical perspective. class Work < Hyrax::Resource - include Hyrax::Schema(:core_metadata) + include Hyrax ::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBILE', false) attribute :admin_set_id, Valkyrie::Types::ID attribute :member_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID).meta(ordered: true) diff --git a/lib/hyrax/schema.rb b/lib/hyrax/schema.rb index 0a96b2c5ad..4965545bfb 100644 --- a/lib/hyrax/schema.rb +++ b/lib/hyrax/schema.rb @@ -58,14 +58,20 @@ class Schema < Module # @return [Symbol] attr_reader :name + ## + # Pick the default schema loader based on whether flex is on or not + def self.default_schema_loader + ENV.fetch('HYRAX_FLEXIBLE', false) ? SimpleSchemaLoader.new : SimpleSchemaLoader.new + end ## # @param [Symbol] schema_name # # @note use Hyrax::Schema(:my_schema) instead # # @api private - def initialize(schema_name, schema_loader: SimpleSchemaLoader.new) + def initialize(schema_name, schema_loader: Hyrax::Schema.default_schema_loader, schema_version: '1') @name = schema_name + @version = schema_version @schema_loader = schema_loader end From 8ca106abd04e1fe30635115cf15afad7439595eb Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 6 Jun 2024 13:48:05 -0700 Subject: [PATCH 02/34] typo --- app/models/hyrax/work.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/hyrax/work.rb b/app/models/hyrax/work.rb index 10eda4b03d..1299455a8e 100644 --- a/app/models/hyrax/work.rb +++ b/app/models/hyrax/work.rb @@ -94,7 +94,7 @@ module Hyrax # @see https://wiki.lyrasis.org/display/samvera/Hydra::Works+Shared+Modeling # for a historical perspective. class Work < Hyrax::Resource - include Hyrax ::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBILE', false) + include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBILE', false) attribute :admin_set_id, Valkyrie::Types::ID attribute :member_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID).meta(ordered: true) From 3d32fa741aa0ee0c41e4e4c6a28a8a4c8654f0a9 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 6 Jun 2024 16:15:26 -0700 Subject: [PATCH 03/34] do not load any metadata schemas if HYRAX_FLEXIBLE is true --- .dassie/app/models/collection_resource.rb | 4 ++-- .dassie/app/models/generic_work_resource.rb | 4 ++-- .dassie/app/models/monograph.rb | 4 ++-- app/models/hyrax/administrative_set.rb | 2 +- app/models/hyrax/file_set.rb | 4 ++-- app/models/hyrax/pcdm_collection.rb | 2 +- app/models/hyrax/work.rb | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.dassie/app/models/collection_resource.rb b/.dassie/app/models/collection_resource.rb index 324e7031f3..84caa165d2 100644 --- a/.dassie/app/models/collection_resource.rb +++ b/.dassie/app/models/collection_resource.rb @@ -30,8 +30,8 @@ class CollectionResource < Hyrax::PcdmCollection # * add Valkyrie attributes to this class # * update form and indexer to process the attributes # - include Hyrax::Schema(:basic_metadata) - include Hyrax::Schema(:collection_resource) + include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:collection_resource) unless ENV.fetch('HYRAX_FLEXIBLE', false) Hyrax::ValkyrieLazyMigration.migrating(self, from: ::Collection) end diff --git a/.dassie/app/models/generic_work_resource.rb b/.dassie/app/models/generic_work_resource.rb index 43848d95ee..9919ced533 100644 --- a/.dassie/app/models/generic_work_resource.rb +++ b/.dassie/app/models/generic_work_resource.rb @@ -3,8 +3,8 @@ # Generated via # `rails generate hyrax:work_resource GenericWorkResource` class GenericWorkResource < Hyrax::Work - include Hyrax::Schema(:basic_metadata) - include Hyrax::Schema(:generic_work_resource) + include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:generic_work_resource) unless ENV.fetch('HYRAX_FLEXIBLE', false) Hyrax::ValkyrieLazyMigration.migrating(self, from: GenericWork) end diff --git a/.dassie/app/models/monograph.rb b/.dassie/app/models/monograph.rb index fc3e67b2a5..5e1a863a72 100644 --- a/.dassie/app/models/monograph.rb +++ b/.dassie/app/models/monograph.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:work_resource Monograph` class Monograph < Hyrax::Work - include Hyrax::Schema(:basic_metadata) - include Hyrax::Schema(:monograph) + include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:monograph) unless ENV.fetch('HYRAX_FLEXIBLE', false) end diff --git a/app/models/hyrax/administrative_set.rb b/app/models/hyrax/administrative_set.rb index 0b82afa7e4..af91ada9e9 100644 --- a/app/models/hyrax/administrative_set.rb +++ b/app/models/hyrax/administrative_set.rb @@ -25,7 +25,7 @@ module Hyrax # @see Valkyrie query adapter's #find_inverse_references_by # class AdministrativeSet < Hyrax::Resource - include Hyrax::Schema(:core_metadata) + include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) attribute :alternative_title, Valkyrie::Types::Set.of(Valkyrie::Types::String) attribute :creator, Valkyrie::Types::Set.of(Valkyrie::Types::String) diff --git a/app/models/hyrax/file_set.rb b/app/models/hyrax/file_set.rb index 9c8f5cf116..93bb7d5627 100644 --- a/app/models/hyrax/file_set.rb +++ b/app/models/hyrax/file_set.rb @@ -49,8 +49,8 @@ module Hyrax # @see Hyrax::CustomQueries::Navigators::ParentWorkNavigator#find_parent_work # @see https://wiki.duraspace.org/display/samvera/Hydra%3A%3AWorks+Shared+Modeling class FileSet < Hyrax::Resource - include Hyrax::Schema(:core_metadata) - include Hyrax::Schema(:file_set_metadata) + include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:file_set_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) def self.model_name(name_class: Hyrax::Name) @_model_name ||= name_class.new(self, nil, 'FileSet') diff --git a/app/models/hyrax/pcdm_collection.rb b/app/models/hyrax/pcdm_collection.rb index efc479bee6..218e1a961d 100644 --- a/app/models/hyrax/pcdm_collection.rb +++ b/app/models/hyrax/pcdm_collection.rb @@ -40,7 +40,7 @@ module Hyrax # @see Hyrax::CustomQueries::Navigators::CollectionMembers#find_members_of # class PcdmCollection < Hyrax::Resource - include Hyrax::Schema(:core_metadata) + include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) attribute :collection_type_gid, Valkyrie::Types::String attribute :member_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID).meta(ordered: true) diff --git a/app/models/hyrax/work.rb b/app/models/hyrax/work.rb index 1299455a8e..e04410327d 100644 --- a/app/models/hyrax/work.rb +++ b/app/models/hyrax/work.rb @@ -94,7 +94,7 @@ module Hyrax # @see https://wiki.lyrasis.org/display/samvera/Hydra::Works+Shared+Modeling # for a historical perspective. class Work < Hyrax::Resource - include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBILE', false) + include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) attribute :admin_set_id, Valkyrie::Types::ID attribute :member_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID).meta(ordered: true) From 01b8ed1451ef7ee8a0695bd7630b9d3fe3cbd3ce Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 6 Jun 2024 16:20:40 -0700 Subject: [PATCH 04/34] dymanic loading of the model with m3 profiles --- ...606205215_create_hyrax_flexible_schemas.rb | 10 ++ .dassie/db/schema.rb | 9 +- app/models/concerns/hyrax/flexibility.rb | 10 +- app/models/hyrax/flexible_schema.rb | 33 ++++ app/models/hyrax/resource.rb | 1 - app/services/hyrax/m3_schema_loader.rb | 140 +++++++++++++++++ app/services/hyrax/simple_schema_loader.rb | 6 +- config/metadata/m3_profile.yaml | 148 ++++++++++++++++++ ...05215_create_hyrax_flexible_schemas.rb.erb | 10 ++ lib/hyrax/schema.rb | 8 +- spec/models/hyrax/flexible_schema_spec.rb | 5 + spec/services/hyrax/m3_schema_loader_spec.rb | 60 +++++++ 12 files changed, 428 insertions(+), 12 deletions(-) create mode 100644 .dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb create mode 100644 app/models/hyrax/flexible_schema.rb create mode 100644 app/services/hyrax/m3_schema_loader.rb create mode 100644 config/metadata/m3_profile.yaml create mode 100644 lib/generators/hyrax/templates/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb.erb create mode 100644 spec/models/hyrax/flexible_schema_spec.rb create mode 100644 spec/services/hyrax/m3_schema_loader_spec.rb diff --git a/.dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb b/.dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb new file mode 100644 index 0000000000..0bc7567dec --- /dev/null +++ b/.dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb @@ -0,0 +1,10 @@ +class CreateHyraxFlexibleSchemas < ActiveRecord::Migration[6.1] + def change + create_table :hyrax_flexible_schemas do |t| + t.string :version, index: { unique: true } + t.text :profile + + t.timestamps + end + end +end diff --git a/.dassie/db/schema.rb b/.dassie/db/schema.rb index 1515b687c5..d58a685ed5 100644 --- a/.dassie/db/schema.rb +++ b/.dassie/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_05_06_070809) do +ActiveRecord::Schema.define(version: 2024_06_06_205215) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -172,6 +172,13 @@ t.datetime "updated_at", null: false end + create_table "hyrax_flexible_schemas", force: :cascade do |t| + t.string "version" + t.text "profile" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "job_io_wrappers", force: :cascade do |t| t.bigint "user_id" t.bigint "uploaded_file_id" diff --git a/app/models/concerns/hyrax/flexibility.rb b/app/models/concerns/hyrax/flexibility.rb index a293ad7066..b20c03ac79 100644 --- a/app/models/concerns/hyrax/flexibility.rb +++ b/app/models/concerns/hyrax/flexibility.rb @@ -3,6 +3,10 @@ module Hyrax module Flexibility extend ActiveSupport::Concern + included do + attribute :schema_version, Valkyrie::Types::String + end + class_methods do ## Override dry-struct 1.6.0 to enable redefining schemas on the fly def attributes(new_schema) @@ -55,10 +59,10 @@ def new(attributes = default_attributes, safe = false, &block) # rubocop:disable ## Read the schema from the database and load the correct schemas for the instance in to the class def load(attributes, safe = false) - attributes[:schemas] ||= 'core_metadata:1' + attributes[:schema_version] ||= Hyrax::FlexibleSchema.order('created_at DESC').pick(:version) struct = allocate - schema_name, schema_version = attributes[:schemas].split(':') - struct.singleton_class.attributes(Hyrax::Schema(schema_name, schema_version:).attributes) + schema_version = attributes[:schema_version] + struct.singleton_class.attributes(Hyrax::Schema(self, schema_version:).attributes) clean_attributes = safe ? struct.singleton_class.schema.call_safe(attributes) { |output = attributes| return yield output } : struct.singleton_class.schema.call_unsafe(attributes) struct.__send__(:initialize, clean_attributes) struct diff --git a/app/models/hyrax/flexible_schema.rb b/app/models/hyrax/flexible_schema.rb new file mode 100644 index 0000000000..428978d7b1 --- /dev/null +++ b/app/models/hyrax/flexible_schema.rb @@ -0,0 +1,33 @@ +class Hyrax::FlexibleSchema < ApplicationRecord + serialize :profile, coder: YAML + + def attributes_for(class_name) + class_names[class_name] + end + + def class_names + return @class_names if @class_names + @class_names = {} + profile['classes'].keys.each do |class_name| + @class_names[class_name] = {} + end + profile['properties'].each do |key, value| + value['available_on']['class'].each do |property_class| + # map some m3 items to what Hyrax expects + value['type'] = lookup_type(value['range']) + value['predicate'] = value['property_uri'] + @class_names[property_class][key] = value + end + end + @class_names + end + + def lookup_type(range) + case range + when "http://www.w3.org/2001/XMLSchema#dateTime" + 'date_time' + else + range.split('#').last.underscore + end + end +end diff --git a/app/models/hyrax/resource.rb b/app/models/hyrax/resource.rb index df24eae83c..8ae43e372a 100644 --- a/app/models/hyrax/resource.rb +++ b/app/models/hyrax/resource.rb @@ -38,7 +38,6 @@ class Resource < Valkyrie::Resource attribute :alternate_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID) attribute :embargo_id, Valkyrie::Types::Params::ID attribute :lease_id, Valkyrie::Types::Params::ID - attribute :schemas, Valkyrie::Types::String delegate :edit_groups, :edit_groups=, :edit_users, :edit_users=, diff --git a/app/services/hyrax/m3_schema_loader.rb b/app/services/hyrax/m3_schema_loader.rb new file mode 100644 index 0000000000..094723fcbe --- /dev/null +++ b/app/services/hyrax/m3_schema_loader.rb @@ -0,0 +1,140 @@ +# frozen_string_literal: true + +module Hyrax + ## + # @api private + # + # Read m3 profiles from the database + # + # @see config/metadata/m3_profile.yaml for an example configuration + class M3SchemaLoader + ## + # @param [Symbol] schema + # + # @return [Hash] a map from attribute names to + # types + def attributes_for(schema:, version: 1) + definitions(schema, version).each_with_object({}) do |definition, hash| + hash[definition.name] = definition.type.meta(definition.config) + end + end + + ## + # @param [Symbol] schema + # + # @return [Hash{Symbol => Hash{Symbol => Object}}] + def form_definitions_for(schema:, version: 1) + definitions(schema, version).each_with_object({}) do |definition, hash| + next if definition.form_options.empty? + + hash[definition.name] = definition.form_options + end + end + + ## + # @param [Symbol] schema + # + # @return [{Symbol => Symbol}] a map from index keys to attribute names + def index_rules_for(schema:, version: 1) + definitions(schema, version).each_with_object({}) do |definition, hash| + definition.index_keys.each do |key| + hash[key] = definition.name + end + end + end + + ## + # @api private + class AttributeDefinition + ## + # @!attr_reader :config + # @return [Hash] + # @!attr_reader :name + # @return [#to_sym] + attr_reader :config, :name + + ## + # @param [#to_sym] name + # @param [Hash] config + def initialize(name, config) + @config = config + @name = name.to_sym + end + + ## + # @return [Hash{Symbol => Object}] + def form_options + config.fetch('form', {}).symbolize_keys + end + + ## + # @return [Enumerable] + def index_keys + config.fetch('indexing', []).map(&:to_sym) + end + + ## + # @return [Dry::Types::Type] + def type + collection_type = if config['multi_value'] + Valkyrie::Types::Array.constructor { |v| Array(v).select(&:present?) } + else + Identity + end + collection_type.of(type_for(config['type'])) + end + + ## + # @api private + # + # This class acts as a Valkyrie/Dry::Types collection with typed members, + # but instead of wrapping the given type with itself as the collection type + # (as in `Valkyrie::Types::Array.of(MyType)`), it returns the given type. + # + # @example + # Identity.of(Valkyrie::Types::String) # => Valkyrie::Types::String + # + class Identity + ## + # @param [Dry::Types::Type] + # @return [Dry::Types::Type] the type passed in + def self.of(type) + type + end + end + + private + + ## + # Maps a configuration string value to a `Valkyrie::Type`. + # + # @param [String] + # @return [Dry::Types::Type] + def type_for(type) + case type + when 'id' + Valkyrie::Types::ID + when 'uri' + Valkyrie::Types::URI + when 'date_time' + Valkyrie::Types::DateTime + else + "Valkyrie::Types::#{type.capitalize}".constantize + end + end + end + + class UndefinedSchemaError < ArgumentError; end + + private + + ## + # @param [#to_s] schema_name + # @return [Enumerable] a map from attribute names to # types - def attributes_for(schema:) + def attributes_for(schema:, version: 1) definitions(schema).each_with_object({}) do |definition, hash| hash[definition.name] = definition.type.meta(definition.config) end @@ -23,7 +23,7 @@ def attributes_for(schema:) # @param [Symbol] schema # # @return [Hash{Symbol => Hash{Symbol => Object}}] - def form_definitions_for(schema:) + def form_definitions_for(schema:, version: 1) definitions(schema).each_with_object({}) do |definition, hash| next if definition.form_options.empty? @@ -35,7 +35,7 @@ def form_definitions_for(schema:) # @param [Symbol] schema # # @return [{Symbol => Symbol}] a map from index keys to attribute names - def index_rules_for(schema:) + def index_rules_for(schema:, version: 1) definitions(schema).each_with_object({}) do |definition, hash| definition.index_keys.each do |key| hash[key] = definition.name diff --git a/config/metadata/m3_profile.yaml b/config/metadata/m3_profile.yaml new file mode 100644 index 0000000000..49d2a05d75 --- /dev/null +++ b/config/metadata/m3_profile.yaml @@ -0,0 +1,148 @@ +--- +m3_version: 1.0.beta2 +profile: + date_modified: '2024-06-01' + responsibility: https://samvera.org + responsibility_statement: Hyrax Initial Profile + type: + version: 1 +classes: + Hyrax::Work: + display_label: Work + Hyrax::AdministrativeSet: + diplay_label: AdministrativeSet + Hyrax::PcdmCollection: + display_label: PcdmCollection + Hyrax::FileSet: + display_label: FileSet +contexts: + flexible_context: + display_label: Flexible Metadata Example +mappings: + blacklight: + name: Additional Blacklight Solr Mappings + metatags: + name: Metatags + mods_oai_pmh: + name: MODS OAI PMH + qualified_dc_pmh: + name: Qualified DC OAI PMH + simple_dc_pmh: + name: Simple DC OAI PMH +properties: + title: + available_on: + class: + - Hyrax::AdministrativeSet + - Hyrax::FileSet + - Hyrax::PcdmCollection + - Hyrax::Work + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + definition: + default: Enter a standardized title for display. If only one + title is needed, transcribe the title from the source + itself. + display_label: + default: Title + index_documentation: displayable, searchable + indexing: + - 'title_sim' + - 'title_tesim' + form: + required: true + primary: true + multi_value: true + mappings: + metatags: twitter:title, og:title + mods_oai_pmh: mods:titleInfo/mods:title + qualified_dc_pmh: dcterms:title + simple_dc_pmh: dc:title + property_uri: http://purl.org/dc/terms/title + range: http://www.w3.org/2001/XMLSchema#string + requirement: required + sample_values: + - Pencil drawn portrait study of woman + date_modified: + available_on: + class: + - Hyrax::AdministrativeSet + - Hyrax::FileSet + - Hyrax::PcdmCollection + - Hyrax::Work + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + display_label: + default: Date Modified + property_uri: http://purl.org/dc/terms/modified + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + date_uploaded: + available_on: + class: + - Hyrax::AdministrativeSet + - Hyrax::FileSet + - Hyrax::PcdmCollection + - Hyrax::Work + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + display_label: + default: Date Uploaded + property_uri: http://purl.org/dc/terms/dateSubmitted + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + depositor: + available_on: + class: + - Hyrax::AdministrativeSet + - Hyrax::FileSet + - Hyrax::PcdmCollection + - Hyrax::Work + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Depositor + index_documentation: searchable + indexing: + - 'depositor_tesim' + property_uri: http://id.loc.gov/vocabulary/relators/dpt + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson + creator: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 1 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Creator + index_documentation: searchable + indexing: + - 'creator_tesim' + property_uri: http://purl.org/dc/elements/1.1/creator + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson diff --git a/lib/generators/hyrax/templates/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb.erb b/lib/generators/hyrax/templates/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb.erb new file mode 100644 index 0000000000..4cba9be7cc --- /dev/null +++ b/lib/generators/hyrax/templates/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb.erb @@ -0,0 +1,10 @@ +class CreateHyraxFlexibleSchemas < ActiveRecord::Migration<%= migration_version %> + def change + create_table :hyrax_flexible_schemas do |t| + t.string :version, index: { unique: true } + t.text :profile + + t.timestamps + end + end +end diff --git a/lib/hyrax/schema.rb b/lib/hyrax/schema.rb index 4965545bfb..90929a9340 100644 --- a/lib/hyrax/schema.rb +++ b/lib/hyrax/schema.rb @@ -56,12 +56,12 @@ class Schema < Module ## # @!attribute [r] name # @return [Symbol] - attr_reader :name + attr_reader :name, :version ## # Pick the default schema loader based on whether flex is on or not def self.default_schema_loader - ENV.fetch('HYRAX_FLEXIBLE', false) ? SimpleSchemaLoader.new : SimpleSchemaLoader.new + ENV.fetch('HYRAX_FLEXIBLE', false) ? M3SchemaLoader.new : SimpleSchemaLoader.new end ## # @param [Symbol] schema_name @@ -70,7 +70,7 @@ def self.default_schema_loader # # @api private def initialize(schema_name, schema_loader: Hyrax::Schema.default_schema_loader, schema_version: '1') - @name = schema_name + @name = schema_name.to_s @version = schema_version @schema_loader = schema_loader end @@ -78,7 +78,7 @@ def initialize(schema_name, schema_loader: Hyrax::Schema.default_schema_loader, ## # @return [Hash{Symbol => Dry::Types::Type}] def attributes - @schema_loader.attributes_for(schema: name) + @schema_loader.attributes_for(schema: name, version:) end ## diff --git a/spec/models/hyrax/flexible_schema_spec.rb b/spec/models/hyrax/flexible_schema_spec.rb new file mode 100644 index 0000000000..45531ade88 --- /dev/null +++ b/spec/models/hyrax/flexible_schema_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Hyrax::FlexibleSchema, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/services/hyrax/m3_schema_loader_spec.rb b/spec/services/hyrax/m3_schema_loader_spec.rb new file mode 100644 index 0000000000..9c8b900dd3 --- /dev/null +++ b/spec/services/hyrax/m3_schema_loader_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Hyrax::M3SchemaLoader do + subject(:schema_loader) { described_class.new } + + describe '#attributes_for' do + it 'provides an attributes hash' do + expect(schema_loader.attributes_for(schema: :core_metadata)) + .to include(title: Valkyrie::Types::Array.of(Valkyrie::Types::String), + depositor: Valkyrie::Types::String) + end + + it 'provides access to attribute metadata' do + expect(schema_loader.attributes_for(schema: :core_metadata)[:title].meta) + .to include({ "type" => "string", + "form" => { "multiple" => true, "primary" => true, "required" => true }, + "index_keys" => ["title_sim", "title_tesim"], + "multiple" => true, + "predicate" => "http://purl.org/dc/terms/title" }) + end + + context 'with generated resource' do + it 'provides an attributes hash' do + expect(schema_loader.attributes_for(schema: :sample_metadata)) + .to include(sample_attribute: Valkyrie::Types::Array.of(Valkyrie::Types::String)) + end + end + + it 'raises an error for an undefined schema' do + expect { schema_loader.attributes_for(schema: :NOT_A_SCHEMA) } + .to raise_error described_class::UndefinedSchemaError + end + end + + describe '#index_rules_for' do + it 'provides index configuration' do + expect(schema_loader.index_rules_for(schema: :core_metadata)).to include(title_sim: :title, title_tesim: :title) + end + end + + describe '#form_definitions_for' do + it 'provides form configuration' do + expect(schema_loader.form_definitions_for(schema: :core_metadata)) + .to eq(title: { required: true, primary: true, multiple: true }) + end + end + + describe '#permissive_schema_for_valkrie_adapter' do + let(:permissive_schema) { schema_loader.permissive_schema_for_valkrie_adapter } + + it 'provides the expected hash' do + expect(permissive_schema.size).to eq(66) + expect(permissive_schema.values.all? { |v| v.is_a? RDF::URI }).to be_truthy + expect(permissive_schema.values.all? { |v| v.value.present? }).to be_truthy + expect(permissive_schema[:sample_attribute].value).to eq("http://hyrax-example.com/sample_attribute") + end + end +end From 7e06f18a54aecb0ae1a8412d9f14548c3683a09e Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 6 Jun 2024 16:31:07 -0700 Subject: [PATCH 05/34] refactor schema loader to reduce code duplication --- app/models/hyrax/flexible_schema.rb | 17 ++- app/services/hyrax/m3_schema_loader.rb | 120 +------------------ app/services/hyrax/schema_loader.rb | 130 +++++++++++++++++++++ app/services/hyrax/simple_schema_loader.rb | 124 +------------------- 4 files changed, 147 insertions(+), 244 deletions(-) create mode 100644 app/services/hyrax/schema_loader.rb diff --git a/app/models/hyrax/flexible_schema.rb b/app/models/hyrax/flexible_schema.rb index 428978d7b1..b68d1ee688 100644 --- a/app/models/hyrax/flexible_schema.rb +++ b/app/models/hyrax/flexible_schema.rb @@ -11,17 +11,24 @@ def class_names profile['classes'].keys.each do |class_name| @class_names[class_name] = {} end - profile['properties'].each do |key, value| - value['available_on']['class'].each do |property_class| + profile['properties'].each do |key, values| + values['available_on']['class'].each do |property_class| # map some m3 items to what Hyrax expects - value['type'] = lookup_type(value['range']) - value['predicate'] = value['property_uri'] - @class_names[property_class][key] = value + values = values_map(values) + @class_names[property_class][key] = values end end @class_names end + def values_map(values) + values['type'] = lookup_type(value['range']) + values['predicate'] = value['property_uri'] + values['index_keys'] = values['indexing'] + values['multiple'] = values['multi_value'] + values + end + def lookup_type(range) case range when "http://www.w3.org/2001/XMLSchema#dateTime" diff --git a/app/services/hyrax/m3_schema_loader.rb b/app/services/hyrax/m3_schema_loader.rb index 094723fcbe..25554b81f5 100644 --- a/app/services/hyrax/m3_schema_loader.rb +++ b/app/services/hyrax/m3_schema_loader.rb @@ -7,125 +7,7 @@ module Hyrax # Read m3 profiles from the database # # @see config/metadata/m3_profile.yaml for an example configuration - class M3SchemaLoader - ## - # @param [Symbol] schema - # - # @return [Hash] a map from attribute names to - # types - def attributes_for(schema:, version: 1) - definitions(schema, version).each_with_object({}) do |definition, hash| - hash[definition.name] = definition.type.meta(definition.config) - end - end - - ## - # @param [Symbol] schema - # - # @return [Hash{Symbol => Hash{Symbol => Object}}] - def form_definitions_for(schema:, version: 1) - definitions(schema, version).each_with_object({}) do |definition, hash| - next if definition.form_options.empty? - - hash[definition.name] = definition.form_options - end - end - - ## - # @param [Symbol] schema - # - # @return [{Symbol => Symbol}] a map from index keys to attribute names - def index_rules_for(schema:, version: 1) - definitions(schema, version).each_with_object({}) do |definition, hash| - definition.index_keys.each do |key| - hash[key] = definition.name - end - end - end - - ## - # @api private - class AttributeDefinition - ## - # @!attr_reader :config - # @return [Hash] - # @!attr_reader :name - # @return [#to_sym] - attr_reader :config, :name - - ## - # @param [#to_sym] name - # @param [Hash] config - def initialize(name, config) - @config = config - @name = name.to_sym - end - - ## - # @return [Hash{Symbol => Object}] - def form_options - config.fetch('form', {}).symbolize_keys - end - - ## - # @return [Enumerable] - def index_keys - config.fetch('indexing', []).map(&:to_sym) - end - - ## - # @return [Dry::Types::Type] - def type - collection_type = if config['multi_value'] - Valkyrie::Types::Array.constructor { |v| Array(v).select(&:present?) } - else - Identity - end - collection_type.of(type_for(config['type'])) - end - - ## - # @api private - # - # This class acts as a Valkyrie/Dry::Types collection with typed members, - # but instead of wrapping the given type with itself as the collection type - # (as in `Valkyrie::Types::Array.of(MyType)`), it returns the given type. - # - # @example - # Identity.of(Valkyrie::Types::String) # => Valkyrie::Types::String - # - class Identity - ## - # @param [Dry::Types::Type] - # @return [Dry::Types::Type] the type passed in - def self.of(type) - type - end - end - - private - - ## - # Maps a configuration string value to a `Valkyrie::Type`. - # - # @param [String] - # @return [Dry::Types::Type] - def type_for(type) - case type - when 'id' - Valkyrie::Types::ID - when 'uri' - Valkyrie::Types::URI - when 'date_time' - Valkyrie::Types::DateTime - else - "Valkyrie::Types::#{type.capitalize}".constantize - end - end - end - - class UndefinedSchemaError < ArgumentError; end - + class M3SchemaLoader < Hyrax::SchemaLoader private ## diff --git a/app/services/hyrax/schema_loader.rb b/app/services/hyrax/schema_loader.rb new file mode 100644 index 0000000000..73728795db --- /dev/null +++ b/app/services/hyrax/schema_loader.rb @@ -0,0 +1,130 @@ +# frozen_string_literal: true + +module Hyrax + ## + # @api private + # + # This is a simple yaml config-driven schema loader + # + # @see config/metadata/basic_metadata.yaml for an example configuration + class SchemaLoader + ## + # @param [Symbol] schema + # + # @return [Hash] a map from attribute names to + # types + def attributes_for(schema:, version: 1) + definitions(schema).each_with_object({}) do |definition, hash| + hash[definition.name] = definition.type.meta(definition.config) + end + end + + ## + # @param [Symbol] schema + # + # @return [Hash{Symbol => Hash{Symbol => Object}}] + def form_definitions_for(schema:, version: 1) + definitions(schema).each_with_object({}) do |definition, hash| + next if definition.form_options.empty? + + hash[definition.name] = definition.form_options + end + end + + ## + # @param [Symbol] schema + # + # @return [{Symbol => Symbol}] a map from index keys to attribute names + def index_rules_for(schema:, version: 1) + definitions(schema).each_with_object({}) do |definition, hash| + definition.index_keys.each do |key| + hash[key] = definition.name + end + end + end + + ## + # @api private + class AttributeDefinition + ## + # @!attr_reader :config + # @return [Hash] + # @!attr_reader :name + # @return [#to_sym] + attr_reader :config, :name + + ## + # @param [#to_sym] name + # @param [Hash] config + def initialize(name, config) + @config = config + @name = name.to_sym + end + + ## + # @return [Hash{Symbol => Object}] + def form_options + config.fetch('form', {}).symbolize_keys + end + + ## + # @return [Enumerable] + def index_keys + config.fetch('index_keys', []).map(&:to_sym) + end + + ## + # @return [Dry::Types::Type] + def type + collection_type = if config['multiple'] + Valkyrie::Types::Array.constructor { |v| Array(v).select(&:present?) } + else + Identity + end + collection_type.of(type_for(config['type'])) + end + + ## + # @api private + # + # This class acts as a Valkyrie/Dry::Types collection with typed members, + # but instead of wrapping the given type with itself as the collection type + # (as in `Valkyrie::Types::Array.of(MyType)`), it returns the given type. + # + # @example + # Identity.of(Valkyrie::Types::String) # => Valkyrie::Types::String + # + class Identity + ## + # @param [Dry::Types::Type] + # @return [Dry::Types::Type] the type passed in + def self.of(type) + type + end + end + + private + + ## + # Maps a configuration string value to a `Valkyrie::Type`. + # + # @param [String] + # @return [Dry::Types::Type] + def type_for(type) + case type + when 'id' + Valkyrie::Types::ID + when 'uri' + Valkyrie::Types::URI + when 'date_time' + Valkyrie::Types::DateTime + else + "Valkyrie::Types::#{type.capitalize}".constantize + end + end + end + + class UndefinedSchemaError < ArgumentError; end + + end +end diff --git a/app/services/hyrax/simple_schema_loader.rb b/app/services/hyrax/simple_schema_loader.rb index f9c8a1b5a6..eba090961c 100644 --- a/app/services/hyrax/simple_schema_loader.rb +++ b/app/services/hyrax/simple_schema_loader.rb @@ -7,129 +7,13 @@ module Hyrax # This is a simple yaml config-driven schema loader # # @see config/metadata/basic_metadata.yaml for an example configuration - class SimpleSchemaLoader - ## - # @param [Symbol] schema - # - # @return [Hash] a map from attribute names to - # types - def attributes_for(schema:, version: 1) - definitions(schema).each_with_object({}) do |definition, hash| - hash[definition.name] = definition.type.meta(definition.config) - end - end - - ## - # @param [Symbol] schema - # - # @return [Hash{Symbol => Hash{Symbol => Object}}] - def form_definitions_for(schema:, version: 1) - definitions(schema).each_with_object({}) do |definition, hash| - next if definition.form_options.empty? - - hash[definition.name] = definition.form_options - end - end - - ## - # @param [Symbol] schema - # - # @return [{Symbol => Symbol}] a map from index keys to attribute names - def index_rules_for(schema:, version: 1) - definitions(schema).each_with_object({}) do |definition, hash| - definition.index_keys.each do |key| - hash[key] = definition.name - end - end - end - + class SimpleSchemaLoader < Hyrax::SchemaLoader def permissive_schema_for_valkrie_adapter metadata_files.each_with_object({}) do |schema_name, ret_hsh| predicate_pairs(ret_hsh, schema_name) end end - ## - # @api private - class AttributeDefinition - ## - # @!attr_reader :config - # @return [Hash] - # @!attr_reader :name - # @return [#to_sym] - attr_reader :config, :name - - ## - # @param [#to_sym] name - # @param [Hash] config - def initialize(name, config) - @config = config - @name = name.to_sym - end - - ## - # @return [Hash{Symbol => Object}] - def form_options - config.fetch('form', {}).symbolize_keys - end - - ## - # @return [Enumerable] - def index_keys - config.fetch('index_keys', []).map(&:to_sym) - end - - ## - # @return [Dry::Types::Type] - def type - collection_type = if config['multiple'] - Valkyrie::Types::Array.constructor { |v| Array(v).select(&:present?) } - else - Identity - end - collection_type.of(type_for(config['type'])) - end - - ## - # @api private - # - # This class acts as a Valkyrie/Dry::Types collection with typed members, - # but instead of wrapping the given type with itself as the collection type - # (as in `Valkyrie::Types::Array.of(MyType)`), it returns the given type. - # - # @example - # Identity.of(Valkyrie::Types::String) # => Valkyrie::Types::String - # - class Identity - ## - # @param [Dry::Types::Type] - # @return [Dry::Types::Type] the type passed in - def self.of(type) - type - end - end - - private - - ## - # Maps a configuration string value to a `Valkyrie::Type`. - # - # @param [String] - # @return [Dry::Types::Type] - def type_for(type) - case type - when 'id' - Valkyrie::Types::ID - when 'uri' - Valkyrie::Types::URI - when 'date_time' - Valkyrie::Types::DateTime - else - "Valkyrie::Types::#{type.capitalize}".constantize - end - end - end - class UndefinedSchemaError < ArgumentError; end private @@ -180,9 +64,9 @@ def predicate_pairs(ret_hsh, schema_name) def multiple_predicate_message(name, existing, incoming) message = "The attribute of #{name} has been assigned a predicate multiple times " \ - "within the metadata YAMLs. Please be aware that once the attribute's " \ - "predicate value is first assigned, any other value will be ignored. " \ - "The existing value is #{existing} preventing the use of #{incoming}" + "within the metadata YAMLs. Please be aware that once the attribute's " \ + "predicate value is first assigned, any other value will be ignored. " \ + "The existing value is #{existing} preventing the use of #{incoming}" Hyrax.logger.warn(message) end end From 382c6d915ea1c11f879f9e3486b19c5b1a955f94 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Mon, 10 Jun 2024 10:38:43 -0700 Subject: [PATCH 06/34] fix bugs, add db seed --- .dassie/config/metadata/m3_profile.yaml | 162 ++++++++++++++++++ ...606205215_create_hyrax_flexible_schemas.rb | 1 - .dassie/db/schema.rb | 1 - app/models/concerns/hyrax/flexibility.rb | 2 +- app/models/hyrax/flexible_schema.rb | 8 +- app/services/hyrax/m3_schema_loader.rb | 4 +- app/services/hyrax/schema_loader.rb | 8 +- app/services/hyrax/simple_schema_loader.rb | 4 +- app/utils/hyrax/required_data_seeder.rb | 1 + .../flexible_profile_seeder.rb | 28 +++ ...05215_create_hyrax_flexible_schemas.rb.erb | 1 - 11 files changed, 207 insertions(+), 13 deletions(-) create mode 100644 .dassie/config/metadata/m3_profile.yaml create mode 100644 app/utils/hyrax/required_data_seeders/flexible_profile_seeder.rb diff --git a/.dassie/config/metadata/m3_profile.yaml b/.dassie/config/metadata/m3_profile.yaml new file mode 100644 index 0000000000..e8d1dcb582 --- /dev/null +++ b/.dassie/config/metadata/m3_profile.yaml @@ -0,0 +1,162 @@ +--- +m3_version: 1.0.beta2 +profile: + date_modified: '2024-06-01' + responsibility: https://samvera.org + responsibility_statement: Hyrax Initial Profile + type: + version: 1 +classes: + GenericWorkResource: + display_label: Generic Work + Monograph: + display_label: Monograph + AdminSet: + diplay_label: AdminSet + AdminSetResource: + diplay_label: AdministrativeSet + Collection: + display_label: Collection + CollectionResource: + display_label: PcdmCollection + Hyrax::FileSet: + display_label: FileSet +contexts: + flexible_context: + display_label: Flexible Metadata Example +mappings: + blacklight: + name: Additional Blacklight Solr Mappings + metatags: + name: Metatags + mods_oai_pmh: + name: MODS OAI PMH + qualified_dc_pmh: + name: Qualified DC OAI PMH + simple_dc_pmh: + name: Simple DC OAI PMH +properties: + title: + available_on: + class: + - AdminSetResource + - AdminSet + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + definition: + default: Enter a standardized title for display. If only one + title is needed, transcribe the title from the source + itself. + display_label: + default: Title + index_documentation: displayable, searchable + indexing: + - 'title_sim' + - 'title_tesim' + form: + required: true + primary: true + multi_value: true + mappings: + metatags: twitter:title, og:title + mods_oai_pmh: mods:titleInfo/mods:title + qualified_dc_pmh: dcterms:title + simple_dc_pmh: dc:title + property_uri: http://purl.org/dc/terms/title + range: http://www.w3.org/2001/XMLSchema#string + requirement: required + sample_values: + - Pencil drawn portrait study of woman + date_modified: + available_on: + class: + - AdminSetResource + - AdminSet + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + display_label: + default: Date Modified + property_uri: http://purl.org/dc/terms/modified + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + date_uploaded: + available_on: + class: + - AdminSetResource + - AdminSet + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + display_label: + default: Date Uploaded + property_uri: http://purl.org/dc/terms/dateSubmitted + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + depositor: + available_on: + class: + - AdminSetResource + - AdminSet + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Depositor + index_documentation: searchable + indexing: + - 'depositor_tesim' + property_uri: http://id.loc.gov/vocabulary/relators/dpt + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson + creator: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 1 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Creator + index_documentation: searchable + indexing: + - 'creator_tesim' + property_uri: http://purl.org/dc/elements/1.1/creator + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson diff --git a/.dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb b/.dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb index 0bc7567dec..bdbac2bc49 100644 --- a/.dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb +++ b/.dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb @@ -1,7 +1,6 @@ class CreateHyraxFlexibleSchemas < ActiveRecord::Migration[6.1] def change create_table :hyrax_flexible_schemas do |t| - t.string :version, index: { unique: true } t.text :profile t.timestamps diff --git a/.dassie/db/schema.rb b/.dassie/db/schema.rb index d58a685ed5..639068a227 100644 --- a/.dassie/db/schema.rb +++ b/.dassie/db/schema.rb @@ -173,7 +173,6 @@ end create_table "hyrax_flexible_schemas", force: :cascade do |t| - t.string "version" t.text "profile" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false diff --git a/app/models/concerns/hyrax/flexibility.rb b/app/models/concerns/hyrax/flexibility.rb index b20c03ac79..3dfa2675ee 100644 --- a/app/models/concerns/hyrax/flexibility.rb +++ b/app/models/concerns/hyrax/flexibility.rb @@ -59,7 +59,7 @@ def new(attributes = default_attributes, safe = false, &block) # rubocop:disable ## Read the schema from the database and load the correct schemas for the instance in to the class def load(attributes, safe = false) - attributes[:schema_version] ||= Hyrax::FlexibleSchema.order('created_at DESC').pick(:version) + attributes[:schema_version] ||= Hyrax::FlexibleSchema.order('id DESC').pick(:id) struct = allocate schema_version = attributes[:schema_version] struct.singleton_class.attributes(Hyrax::Schema(self, schema_version:).attributes) diff --git a/app/models/hyrax/flexible_schema.rb b/app/models/hyrax/flexible_schema.rb index b68d1ee688..5d4bb99ef2 100644 --- a/app/models/hyrax/flexible_schema.rb +++ b/app/models/hyrax/flexible_schema.rb @@ -1,6 +1,10 @@ class Hyrax::FlexibleSchema < ApplicationRecord serialize :profile, coder: YAML + def title + "#{profile['profile']['responsibility_statement']} - version #{id}" + end + def attributes_for(class_name) class_names[class_name] end @@ -22,8 +26,8 @@ def class_names end def values_map(values) - values['type'] = lookup_type(value['range']) - values['predicate'] = value['property_uri'] + values['type'] = lookup_type(values['range']) + values['predicate'] = values['property_uri'] values['index_keys'] = values['indexing'] values['multiple'] = values['multi_value'] values diff --git a/app/services/hyrax/m3_schema_loader.rb b/app/services/hyrax/m3_schema_loader.rb index 25554b81f5..4fd7a7a2b8 100644 --- a/app/services/hyrax/m3_schema_loader.rb +++ b/app/services/hyrax/m3_schema_loader.rb @@ -14,9 +14,11 @@ class M3SchemaLoader < Hyrax::SchemaLoader # @param [#to_s] schema_name # @return [Enumerable] a map from attribute names to # types def attributes_for(schema:, version: 1) - definitions(schema).each_with_object({}) do |definition, hash| + definitions(schema, version).each_with_object({}) do |definition, hash| hash[definition.name] = definition.type.meta(definition.config) end end @@ -24,7 +26,7 @@ def attributes_for(schema:, version: 1) # # @return [Hash{Symbol => Hash{Symbol => Object}}] def form_definitions_for(schema:, version: 1) - definitions(schema).each_with_object({}) do |definition, hash| + definitions(schema, version).each_with_object({}) do |definition, hash| next if definition.form_options.empty? hash[definition.name] = definition.form_options @@ -36,7 +38,7 @@ def form_definitions_for(schema:, version: 1) # # @return [{Symbol => Symbol}] a map from index keys to attribute names def index_rules_for(schema:, version: 1) - definitions(schema).each_with_object({}) do |definition, hash| + definitions(schema, version).each_with_object({}) do |definition, hash| definition.index_keys.each do |key| hash[key] = definition.name end diff --git a/app/services/hyrax/simple_schema_loader.rb b/app/services/hyrax/simple_schema_loader.rb index eba090961c..69a015f0e4 100644 --- a/app/services/hyrax/simple_schema_loader.rb +++ b/app/services/hyrax/simple_schema_loader.rb @@ -14,14 +14,12 @@ def permissive_schema_for_valkrie_adapter end end - class UndefinedSchemaError < ArgumentError; end - private ## # @param [#to_s] schema_name # @return [Enumerable def change create_table :hyrax_flexible_schemas do |t| - t.string :version, index: { unique: true } t.text :profile t.timestamps From 6f9935b5e427cbb20700853d645543ef61ec21ae Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 10 Jun 2024 10:47:22 -0700 Subject: [PATCH 07/34] Add file_set_metadata properties to m3_profile --- config/metadata/m3_profile.yaml | 396 +++++++++++++++++++++++++++++++- 1 file changed, 394 insertions(+), 2 deletions(-) diff --git a/config/metadata/m3_profile.yaml b/config/metadata/m3_profile.yaml index 49d2a05d75..9c77360ae6 100644 --- a/config/metadata/m3_profile.yaml +++ b/config/metadata/m3_profile.yaml @@ -38,7 +38,7 @@ properties: - Hyrax::PcdmCollection - Hyrax::Work cardinality: - minimum: 0 + minimum: 1 multi_value: true controlled_values: format: http://www.w3.org/2001/XMLSchema#string @@ -139,10 +139,402 @@ properties: - 'null' display_label: default: Creator - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'creator_sim' - 'creator_tesim' + form: + required: true + primary: true property_uri: http://purl.org/dc/elements/1.1/creator range: http://www.w3.org/2001/XMLSchema#string sample_values: - Julie Allinson + license: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: License + index_documentation: searchable + indexing: + - 'license_tesim' + form: + required: false + primary: true + property_uri: http://purl.org/dc/terms/license + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://creativecommons.org/licenses/by/3.0/us/ + abstract: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Abstract + index_documentation: searchable + indexing: + - 'abstract_tesim' + property_uri: http://purl.org/dc/terms/abstract + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - This is an abstract. + based_near: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Location + index_documentation: displayable, searchable + indexing: + - 'based_near_sim' + - 'based_near_tesim' + form: + primary: false + property_uri: http://xmlns.com/foaf/0.1/based_near + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - San Diego, California, United States + contributor: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Contributor + index_documentation: searchable + indexing: + - 'contributor_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/contributor + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson + date_created: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#dateTime + sources: + - 'null' + display_label: + default: Date Created + index_documentation: searchable + indexing: + - 'date_created_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/created + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + description: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Description + index_documentation: searchable + indexing: + - 'description_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/description + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - This is a description. + identifier: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Identifier + index_documentation: searchable + indexing: + - 'identifier_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/identifier + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - abc123 + keyword: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Keyword + index_documentation: displayable, searchable + indexing: + - 'keyword_sim' + - 'keyword_tesim' + form: + primary: false + property_uri: http://schema.org/keywords + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Metadata + - Repository + label: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Label + property_uri: info:fedora/fedora-system:def/model#downloadFilename + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - file_label.txt + language: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Language + indexing: + - 'language_tesim' + index_documentation: searchable + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/language + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - English + - Spanish + publisher: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Publisher + indexing: + - 'publisher_tesim' + index_documentation: searchable + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/publisher + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Scholastic + related_url: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Related URL + index_documentation: searchable + indexing: + - 'related_url_tesim' + form: + primary: false + property_uri: http://www.w3.org/2000/01/rdf-schema#seeAlso + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://example.com/resource1 + relative_path: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Relative Path + property_uri: http://scholarsphere.psu.edu/ns#relativePath + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - /path/to/resource + resource_type: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Resource Type + index_documentation: displayable, searchable + indexing: + - 'resource_type_sim' + - 'resource_type_tesim' + property_uri: http://purl.org/dc/terms/type + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Article + - Conference Proceeding + rights_notes: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Rights Notes + indexing: + - 'rights_notes_tesim' + index_documentation: searchable + property_uri: http://purl.org/dc/elements/1.1/rights + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Creative Commons license. + rights_statement: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Rights Statement + index_documentation: searchable + indexing: + - 'rights_statement_tesim' + property_uri: http://www.europeana.eu/schemas/edm/rights + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://rightsstatements.org/vocab/InC/1.0/ + source: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Source + index_documentation: searchable + indexing: + - 'source_tesim' + property_uri: http://purl.org/dc/terms/source + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Original Manuscript + - Digital Archive + subject: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Subject + index_documentation: displayable, searchable + indexing: + - 'subject_sim' + - 'subject_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/subject + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Art + - Science From 6209db7e119d42d5b5c258c71c16923afdfcfd71 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Tue, 11 Jun 2024 11:20:50 -0700 Subject: [PATCH 08/34] :white_check_mark: test that Hyrax::Flexibility module is included In this commit, we test that a module is included when the HYRAX_FLEXIBLE env var is set. Issue: - https://github.com/scientist-softserv/amigos/issues/20 --- spec/models/hyrax/resource_spec.rb | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/spec/models/hyrax/resource_spec.rb b/spec/models/hyrax/resource_spec.rb index f1543d4b17..2fa2c237cf 100644 --- a/spec/models/hyrax/resource_spec.rb +++ b/spec/models/hyrax/resource_spec.rb @@ -9,6 +9,41 @@ it_behaves_like 'a Hyrax::Resource' + before do + @hyrax_flexible_env_var = ENV['HYRAX_FLEXIBLE'] + end + + after do + ENV.delete('HYRAX_FLEXIBLE') + end + + def load_resource_model + Hyrax.send(:remove_const, :Resource) if defined?(Hyrax::Resource) + load File.join('/app/samvera/hyrax-engine/app/models/hyrax/resource.rb') + end + + context 'when HYRAX_FLEXIBLE environment variable is set' do + before do + ENV['HYRAX_FLEXIBLE'] = 'true' + load_resource_model + end + + it 'includes the Hyrax::Flexibility module' do + expect(Hyrax::Resource.included_modules).to include(Hyrax::Flexibility) + end + end + + context 'when HYRAX_FLEXIBLE environment variable is not set' do + before do + ENV.delete('HYRAX_FLEXIBLE') + load_resource_model + end + + it 'does not include the Hyrax::Flexibility module' do + expect(Hyrax::Resource.included_modules).not_to include(Hyrax::Flexibility) + end + end + describe '#events' do it 'includes Hyrax::WithEvents' do expect(resource).to respond_to(:events) From c7ccccc4838b23d80bae325b314a9b9be69fa047 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 11 Jun 2024 11:50:29 -0700 Subject: [PATCH 09/34] Update dassie's m3_profile.yaml --- .dassie/config/metadata/m3_profile.yaml | 442 ++++++++++++++++++++++-- 1 file changed, 410 insertions(+), 32 deletions(-) diff --git a/.dassie/config/metadata/m3_profile.yaml b/.dassie/config/metadata/m3_profile.yaml index e8d1dcb582..9c77360ae6 100644 --- a/.dassie/config/metadata/m3_profile.yaml +++ b/.dassie/config/metadata/m3_profile.yaml @@ -7,17 +7,11 @@ profile: type: version: 1 classes: - GenericWorkResource: - display_label: Generic Work - Monograph: - display_label: Monograph - AdminSet: - diplay_label: AdminSet - AdminSetResource: + Hyrax::Work: + display_label: Work + Hyrax::AdministrativeSet: diplay_label: AdministrativeSet - Collection: - display_label: Collection - CollectionResource: + Hyrax::PcdmCollection: display_label: PcdmCollection Hyrax::FileSet: display_label: FileSet @@ -39,14 +33,12 @@ properties: title: available_on: class: - - AdminSetResource - - AdminSet + - Hyrax::AdministrativeSet - Hyrax::FileSet - - CollectionResource - - GenericWorkResource - - Monograph + - Hyrax::PcdmCollection + - Hyrax::Work cardinality: - minimum: 0 + minimum: 1 multi_value: true controlled_values: format: http://www.w3.org/2001/XMLSchema#string @@ -79,12 +71,10 @@ properties: date_modified: available_on: class: - - AdminSetResource - - AdminSet + - Hyrax::AdministrativeSet - Hyrax::FileSet - - CollectionResource - - GenericWorkResource - - Monograph + - Hyrax::PcdmCollection + - Hyrax::Work cardinality: minimum: 0 maximum: 1 @@ -98,12 +88,10 @@ properties: date_uploaded: available_on: class: - - AdminSetResource - - AdminSet + - Hyrax::AdministrativeSet - Hyrax::FileSet - - CollectionResource - - GenericWorkResource - - Monograph + - Hyrax::PcdmCollection + - Hyrax::Work cardinality: minimum: 0 maximum: 1 @@ -117,12 +105,10 @@ properties: depositor: available_on: class: - - AdminSetResource - - AdminSet + - Hyrax::AdministrativeSet - Hyrax::FileSet - - CollectionResource - - GenericWorkResource - - Monograph + - Hyrax::PcdmCollection + - Hyrax::Work cardinality: minimum: 0 maximum: 1 @@ -153,10 +139,402 @@ properties: - 'null' display_label: default: Creator - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'creator_sim' - 'creator_tesim' + form: + required: true + primary: true property_uri: http://purl.org/dc/elements/1.1/creator range: http://www.w3.org/2001/XMLSchema#string sample_values: - Julie Allinson + license: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: License + index_documentation: searchable + indexing: + - 'license_tesim' + form: + required: false + primary: true + property_uri: http://purl.org/dc/terms/license + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://creativecommons.org/licenses/by/3.0/us/ + abstract: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Abstract + index_documentation: searchable + indexing: + - 'abstract_tesim' + property_uri: http://purl.org/dc/terms/abstract + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - This is an abstract. + based_near: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Location + index_documentation: displayable, searchable + indexing: + - 'based_near_sim' + - 'based_near_tesim' + form: + primary: false + property_uri: http://xmlns.com/foaf/0.1/based_near + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - San Diego, California, United States + contributor: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Contributor + index_documentation: searchable + indexing: + - 'contributor_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/contributor + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson + date_created: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#dateTime + sources: + - 'null' + display_label: + default: Date Created + index_documentation: searchable + indexing: + - 'date_created_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/created + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + description: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Description + index_documentation: searchable + indexing: + - 'description_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/description + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - This is a description. + identifier: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Identifier + index_documentation: searchable + indexing: + - 'identifier_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/identifier + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - abc123 + keyword: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Keyword + index_documentation: displayable, searchable + indexing: + - 'keyword_sim' + - 'keyword_tesim' + form: + primary: false + property_uri: http://schema.org/keywords + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Metadata + - Repository + label: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Label + property_uri: info:fedora/fedora-system:def/model#downloadFilename + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - file_label.txt + language: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Language + indexing: + - 'language_tesim' + index_documentation: searchable + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/language + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - English + - Spanish + publisher: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Publisher + indexing: + - 'publisher_tesim' + index_documentation: searchable + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/publisher + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Scholastic + related_url: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Related URL + index_documentation: searchable + indexing: + - 'related_url_tesim' + form: + primary: false + property_uri: http://www.w3.org/2000/01/rdf-schema#seeAlso + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://example.com/resource1 + relative_path: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Relative Path + property_uri: http://scholarsphere.psu.edu/ns#relativePath + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - /path/to/resource + resource_type: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Resource Type + index_documentation: displayable, searchable + indexing: + - 'resource_type_sim' + - 'resource_type_tesim' + property_uri: http://purl.org/dc/terms/type + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Article + - Conference Proceeding + rights_notes: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Rights Notes + indexing: + - 'rights_notes_tesim' + index_documentation: searchable + property_uri: http://purl.org/dc/elements/1.1/rights + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Creative Commons license. + rights_statement: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Rights Statement + index_documentation: searchable + indexing: + - 'rights_statement_tesim' + property_uri: http://www.europeana.eu/schemas/edm/rights + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://rightsstatements.org/vocab/InC/1.0/ + source: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Source + index_documentation: searchable + indexing: + - 'source_tesim' + property_uri: http://purl.org/dc/terms/source + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Original Manuscript + - Digital Archive + subject: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Subject + index_documentation: displayable, searchable + indexing: + - 'subject_sim' + - 'subject_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/subject + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Art + - Science From eb5382c0f8f0c5ef0dc3ab584a691cfd3cbb4d8b Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Tue, 11 Jun 2024 12:14:02 -0700 Subject: [PATCH 10/34] :white_check_mark: [i19] add specs for Hyrax::FlexibleSchema Issue: - https://github.com/scientist-softserv/amigos/issues/19 --- app/models/hyrax/flexible_schema.rb | 3 + spec/fixtures/files/m3_profile.yaml | 162 ++++++++++++++++++++++ spec/models/hyrax/flexible_schema_spec.rb | 32 ++++- 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/files/m3_profile.yaml diff --git a/app/models/hyrax/flexible_schema.rb b/app/models/hyrax/flexible_schema.rb index 5d4bb99ef2..4437fc4f21 100644 --- a/app/models/hyrax/flexible_schema.rb +++ b/app/models/hyrax/flexible_schema.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Hyrax::FlexibleSchema < ApplicationRecord serialize :profile, coder: YAML @@ -9,6 +10,8 @@ def attributes_for(class_name) class_names[class_name] end + private + def class_names return @class_names if @class_names @class_names = {} diff --git a/spec/fixtures/files/m3_profile.yaml b/spec/fixtures/files/m3_profile.yaml new file mode 100644 index 0000000000..e8d1dcb582 --- /dev/null +++ b/spec/fixtures/files/m3_profile.yaml @@ -0,0 +1,162 @@ +--- +m3_version: 1.0.beta2 +profile: + date_modified: '2024-06-01' + responsibility: https://samvera.org + responsibility_statement: Hyrax Initial Profile + type: + version: 1 +classes: + GenericWorkResource: + display_label: Generic Work + Monograph: + display_label: Monograph + AdminSet: + diplay_label: AdminSet + AdminSetResource: + diplay_label: AdministrativeSet + Collection: + display_label: Collection + CollectionResource: + display_label: PcdmCollection + Hyrax::FileSet: + display_label: FileSet +contexts: + flexible_context: + display_label: Flexible Metadata Example +mappings: + blacklight: + name: Additional Blacklight Solr Mappings + metatags: + name: Metatags + mods_oai_pmh: + name: MODS OAI PMH + qualified_dc_pmh: + name: Qualified DC OAI PMH + simple_dc_pmh: + name: Simple DC OAI PMH +properties: + title: + available_on: + class: + - AdminSetResource + - AdminSet + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + definition: + default: Enter a standardized title for display. If only one + title is needed, transcribe the title from the source + itself. + display_label: + default: Title + index_documentation: displayable, searchable + indexing: + - 'title_sim' + - 'title_tesim' + form: + required: true + primary: true + multi_value: true + mappings: + metatags: twitter:title, og:title + mods_oai_pmh: mods:titleInfo/mods:title + qualified_dc_pmh: dcterms:title + simple_dc_pmh: dc:title + property_uri: http://purl.org/dc/terms/title + range: http://www.w3.org/2001/XMLSchema#string + requirement: required + sample_values: + - Pencil drawn portrait study of woman + date_modified: + available_on: + class: + - AdminSetResource + - AdminSet + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + display_label: + default: Date Modified + property_uri: http://purl.org/dc/terms/modified + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + date_uploaded: + available_on: + class: + - AdminSetResource + - AdminSet + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + display_label: + default: Date Uploaded + property_uri: http://purl.org/dc/terms/dateSubmitted + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + depositor: + available_on: + class: + - AdminSetResource + - AdminSet + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Depositor + index_documentation: searchable + indexing: + - 'depositor_tesim' + property_uri: http://id.loc.gov/vocabulary/relators/dpt + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson + creator: + available_on: + class: + - Hyrax::FileSet + cardinality: + minimum: 1 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Creator + index_documentation: searchable + indexing: + - 'creator_tesim' + property_uri: http://purl.org/dc/elements/1.1/creator + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson diff --git a/spec/models/hyrax/flexible_schema_spec.rb b/spec/models/hyrax/flexible_schema_spec.rb index 45531ade88..4d6a1a0055 100644 --- a/spec/models/hyrax/flexible_schema_spec.rb +++ b/spec/models/hyrax/flexible_schema_spec.rb @@ -1,5 +1,35 @@ require 'rails_helper' RSpec.describe Hyrax::FlexibleSchema, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + let(:profile_file_path) { File.join(fixture_path, 'files', 'm3_profile.yaml') } + let(:profile_data) { YAML.load_file(profile_file_path) } + + subject { described_class.create(profile: profile_data) } + + describe '#title' do + it 'returns the correct title' do + responsibility_statement = profile_data['profile']['responsibility_statement'] + expect(subject.title).to eq("#{responsibility_statement} - version #{subject.id}") + end + end + + describe '#attributes_for' do + context 'when class_name exists' do + it 'returns the correct attributes for each class' do + profile_data['classes'].keys.each do |class_name| + attributes = subject.attributes_for(class_name) + expect(attributes).to be_a(Hash) + attributes.each do |key, values| + expect(values).to include('type', 'predicate', 'index_keys', 'multiple') + end + end + end + end + + context 'when class_name does not exist' do + it 'returns nil' do + expect(subject.attributes_for('NonExistentClass')).to be_nil + end + end + end end From 797a48da83a88fd076e570785b919b249d259876 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Tue, 11 Jun 2024 12:15:29 -0700 Subject: [PATCH 11/34] :lipstick: rubocop fixes --- app/models/concerns/hyrax/solr_document_behavior.rb | 2 +- app/models/hyrax/file_set.rb | 2 +- app/services/hyrax/schema_loader.rb | 1 - app/services/hyrax/simple_schema_loader.rb | 2 +- spec/models/hyrax/flexible_schema_spec.rb | 3 ++- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/concerns/hyrax/solr_document_behavior.rb b/app/models/concerns/hyrax/solr_document_behavior.rb index 7cb16271e6..2c3ad4b274 100644 --- a/app/models/concerns/hyrax/solr_document_behavior.rb +++ b/app/models/concerns/hyrax/solr_document_behavior.rb @@ -82,7 +82,7 @@ def valkyrie? # Method to return the model def hydra_model(classifier: nil) - (first('has_model_ssim')&.+ 'Resource')&.safe_constantize || + (first('has_model_ssim') + 'Resource')&.safe_constantize || first('has_model_ssim')&.safe_constantize || model_classifier(classifier).classifier(self).best_model end diff --git a/app/models/hyrax/file_set.rb b/app/models/hyrax/file_set.rb index 93bb7d5627..4b068b7a24 100644 --- a/app/models/hyrax/file_set.rb +++ b/app/models/hyrax/file_set.rb @@ -50,7 +50,7 @@ module Hyrax # @see https://wiki.duraspace.org/display/samvera/Hydra%3A%3AWorks+Shared+Modeling class FileSet < Hyrax::Resource include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Schema(:file_set_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:file_set_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) def self.model_name(name_class: Hyrax::Name) @_model_name ||= name_class.new(self, nil, 'FileSet') diff --git a/app/services/hyrax/schema_loader.rb b/app/services/hyrax/schema_loader.rb index 1b9abe413f..d1516985e4 100644 --- a/app/services/hyrax/schema_loader.rb +++ b/app/services/hyrax/schema_loader.rb @@ -127,6 +127,5 @@ def type_for(type) end class UndefinedSchemaError < ArgumentError; end - end end diff --git a/app/services/hyrax/simple_schema_loader.rb b/app/services/hyrax/simple_schema_loader.rb index 69a015f0e4..1597ee96ce 100644 --- a/app/services/hyrax/simple_schema_loader.rb +++ b/app/services/hyrax/simple_schema_loader.rb @@ -61,7 +61,7 @@ def predicate_pairs(ret_hsh, schema_name) end def multiple_predicate_message(name, existing, incoming) - message = "The attribute of #{name} has been assigned a predicate multiple times " \ + message = "The attribute of #{name} has been assigned a predicate multiple times " \ "within the metadata YAMLs. Please be aware that once the attribute's " \ "predicate value is first assigned, any other value will be ignored. " \ "The existing value is #{existing} preventing the use of #{incoming}" diff --git a/spec/models/hyrax/flexible_schema_spec.rb b/spec/models/hyrax/flexible_schema_spec.rb index 4d6a1a0055..fefa70acd3 100644 --- a/spec/models/hyrax/flexible_schema_spec.rb +++ b/spec/models/hyrax/flexible_schema_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe Hyrax::FlexibleSchema, type: :model do @@ -19,7 +20,7 @@ profile_data['classes'].keys.each do |class_name| attributes = subject.attributes_for(class_name) expect(attributes).to be_a(Hash) - attributes.each do |key, values| + attributes.each do |_key, values| expect(values).to include('type', 'predicate', 'index_keys', 'multiple') end end From 0ddbab798887adedf06f66991ce04d16b75a57d2 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 11 Jun 2024 15:48:44 -0700 Subject: [PATCH 12/34] Add basic_metadata properties to dassie m3_profile --- .dassie/config/metadata/m3_profile.yaml | 230 ++++++++++++++++++++++-- 1 file changed, 216 insertions(+), 14 deletions(-) diff --git a/.dassie/config/metadata/m3_profile.yaml b/.dassie/config/metadata/m3_profile.yaml index 9c77360ae6..756c4f67f8 100644 --- a/.dassie/config/metadata/m3_profile.yaml +++ b/.dassie/config/metadata/m3_profile.yaml @@ -130,6 +130,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 1 multi_value: true @@ -154,6 +157,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -163,12 +169,12 @@ properties: - 'null' display_label: default: License - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'license_sim' - 'license_tesim' form: - required: false - primary: true + primary: false property_uri: http://purl.org/dc/terms/license range: http://www.w3.org/2001/XMLSchema#string sample_values: @@ -177,6 +183,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -186,17 +195,95 @@ properties: - 'null' display_label: default: Abstract - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'abstract_sim' - 'abstract_tesim' + form: + primary: false property_uri: http://purl.org/dc/terms/abstract range: http://www.w3.org/2001/XMLSchema#string sample_values: - This is an abstract. + access_right: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Access Right + index_documentation: displayable, searchable + indexing: + - 'access_right_sim' + - 'access_right_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/accessRights + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Open Access + alternative_title: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Alternative Title + index_documentation: displayable, searchable + indexing: + - 'alternative_title_sim' + - 'alternative_title_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/alternative + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Alternate Title Example + arkivo_checksum: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Arkivo Checksum + form: + primary: false + property_uri: http://scholarsphere.psu.edu/ns#arkivoChecksum + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - c0855931b7f1aefedb91d31af76873c0 based_near: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -216,10 +303,38 @@ properties: range: http://www.w3.org/2001/XMLSchema#string sample_values: - San Diego, California, United States + bibliographic_citation: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Bibliographic Citation + index_documentation: displayable, searchable + indexing: + - 'bibliographic_citation_sim' + - 'bibliographic_citation_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/bibliographicCitation + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - "Doe, J. (2024). Example Citation. Journal of Examples, 12(3), 45-67." contributor: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -229,9 +344,10 @@ properties: - 'null' display_label: default: Contributor - index_documentation: searchable + index_documentation: displayable, searchable indexing: - 'contributor_tesim' + - 'contributor_sim' form: primary: false property_uri: http://purl.org/dc/elements/1.1/contributor @@ -242,6 +358,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -251,19 +370,24 @@ properties: - 'null' display_label: default: Date Created - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'date_created_sim' - 'date_created_tesim' form: primary: false property_uri: http://purl.org/dc/terms/created range: http://www.w3.org/2001/XMLSchema#dateTime sample_values: + sample_values: - "2024-06-06 21:06:51 +0000" description: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -273,8 +397,9 @@ properties: - 'null' display_label: default: Description - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'description_sim' - 'description_tesim' form: primary: false @@ -286,6 +411,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -295,8 +423,9 @@ properties: - 'null' display_label: default: Identifier - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'identifier_sim' - 'identifier_tesim' form: primary: false @@ -304,10 +433,33 @@ properties: range: http://www.w3.org/2001/XMLSchema#string sample_values: - abc123 + import_url: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Import URL + property_uri: http://scholarsphere.psu.edu/ns#importUrl + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://example.com/resource1 keyword: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -332,6 +484,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 maximum: 1 @@ -342,6 +497,12 @@ properties: - 'null' display_label: default: Label + index_documentation: displayable, searchable + indexing: + - 'label_sim' + - 'label_tesim' + form: + primary: false property_uri: info:fedora/fedora-system:def/model#downloadFilename range: http://www.w3.org/2001/XMLSchema#string sample_values: @@ -350,6 +511,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -359,9 +523,10 @@ properties: - 'null' display_label: default: Language + index_documentation: displayable, searchable indexing: + - 'language_sim' - 'language_tesim' - index_documentation: searchable form: primary: false property_uri: http://purl.org/dc/elements/1.1/language @@ -373,6 +538,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -382,9 +550,10 @@ properties: - 'null' display_label: default: Publisher + index_documentation: displayable, searchable indexing: + - 'publisher_sim' - 'publisher_tesim' - index_documentation: searchable form: primary: false property_uri: http://purl.org/dc/elements/1.1/publisher @@ -395,6 +564,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -404,8 +576,9 @@ properties: - 'null' display_label: default: Related URL - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'related_url_sim' - 'related_url_tesim' form: primary: false @@ -417,6 +590,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 maximum: 1 @@ -435,6 +611,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -448,6 +627,8 @@ properties: indexing: - 'resource_type_sim' - 'resource_type_tesim' + form: + primary: false property_uri: http://purl.org/dc/terms/type range: http://www.w3.org/2001/XMLSchema#string sample_values: @@ -457,6 +638,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -466,9 +650,12 @@ properties: - 'null' display_label: default: Rights Notes + index_documentation: displayable, searchable indexing: + - 'rights_notes_sim' - 'rights_notes_tesim' - index_documentation: searchable + form: + primary: false property_uri: http://purl.org/dc/elements/1.1/rights range: http://www.w3.org/2001/XMLSchema#string sample_values: @@ -477,6 +664,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -486,9 +676,12 @@ properties: - 'null' display_label: default: Rights Statement - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'rights_statement_sim' - 'rights_statement_tesim' + form: + primary: true property_uri: http://www.europeana.eu/schemas/edm/rights range: http://www.w3.org/2001/XMLSchema#string sample_values: @@ -497,6 +690,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true @@ -506,9 +702,12 @@ properties: - 'null' display_label: default: Source - index_documentation: searchable + index_documentation: displayable, searchable indexing: + - 'source_sim' - 'source_tesim' + form: + primary: false property_uri: http://purl.org/dc/terms/source range: http://www.w3.org/2001/XMLSchema#string sample_values: @@ -518,6 +717,9 @@ properties: available_on: class: - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph cardinality: minimum: 0 multi_value: true From 42fca417795d7f790f65d1bc4e1b1562a72bbd1d Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 11 Jun 2024 16:41:05 -0700 Subject: [PATCH 13/34] Add collection_resource properties to m3_profile --- .dassie/config/metadata/m3_profile.yaml | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/.dassie/config/metadata/m3_profile.yaml b/.dassie/config/metadata/m3_profile.yaml index 756c4f67f8..1c512f57e2 100644 --- a/.dassie/config/metadata/m3_profile.yaml +++ b/.dassie/config/metadata/m3_profile.yaml @@ -740,3 +740,65 @@ properties: sample_values: - Art - Science + target_audience: + available_on: + class: + - CollectionResource + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Target Audience + form: + primary: true + multiple: true + property_uri: http://hyrax-example.com/target_audience + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Researchers + - Students + department: + available_on: + class: + - CollectionResource + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Department + form: + primary: true + property_uri: http://hyrax-example.com/department + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Mathematics + - History + course: + available_on: + class: + - CollectionResource + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Course + form: + primary: false + property_uri: http://hyrax-example.com/course + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Computer Science 50 From f186c18173dca8b9a3122bbd5c1ffbd692478aa8 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 11 Jun 2024 17:09:34 -0700 Subject: [PATCH 14/34] Add monograph.yaml properties to m3_profile.yaml --- .dassie/config/metadata/m3_profile.yaml | 162 ++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/.dassie/config/metadata/m3_profile.yaml b/.dassie/config/metadata/m3_profile.yaml index 1c512f57e2..b3aa013533 100644 --- a/.dassie/config/metadata/m3_profile.yaml +++ b/.dassie/config/metadata/m3_profile.yaml @@ -802,3 +802,165 @@ properties: range: http://www.w3.org/2001/XMLSchema#string sample_values: - Computer Science 50 + monograph_title: + available_on: + class: + - Monograph + cardinality: + minimum: 1 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Monograph Title + property_uri: http://hyrax-example.com/monograph_title + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Monograph Title + record_info: + available_on: + class: + - Monograph + cardinality: + minimum: 1 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Record Info + index_documentation: searchable + indexing: + - 'record_info_tesim' + form: + required: true + primary: true + property_uri: http://hyrax-example.com/record_info + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Record Info + place_of_publication: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Place of Publication + form: + required: false + primary: true + property_uri: http://hyrax-example.com/place_of_publication + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Place of Publication + genre: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Genre + form: + primary: true + property_uri: http://hyrax-example.com/genre + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Fiction + - Non-Fiction + series_title: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Series Title + form: + primary: false + property_uri: http://hyrax-example.com/series_title + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Series Title + target_audience: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Target Audience + form: + multiple: true + property_uri: http://hyrax-example.com/target_audience + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Researchers + - Students + table_of_contents: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Table of Contents + form: + multiple: false + property_uri: http://hyrax-example.com/table_of_contents + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Table of Contents + date_of_issuance: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Date of Issuance + property_uri: http://hyrax-example.com/date_of_issuance + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - 2024-06-07 From bcaf5ab9f653c1deab320360eaa270b6529bbb1a Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 11 Jun 2024 17:13:58 -0700 Subject: [PATCH 15/34] Copy m3_profile to Koppie --- .koppie/config/metadata/m3_profile.yaml | 966 ++++++++++++++++++++++++ 1 file changed, 966 insertions(+) create mode 100644 .koppie/config/metadata/m3_profile.yaml diff --git a/.koppie/config/metadata/m3_profile.yaml b/.koppie/config/metadata/m3_profile.yaml new file mode 100644 index 0000000000..b3aa013533 --- /dev/null +++ b/.koppie/config/metadata/m3_profile.yaml @@ -0,0 +1,966 @@ +--- +m3_version: 1.0.beta2 +profile: + date_modified: '2024-06-01' + responsibility: https://samvera.org + responsibility_statement: Hyrax Initial Profile + type: + version: 1 +classes: + Hyrax::Work: + display_label: Work + Hyrax::AdministrativeSet: + diplay_label: AdministrativeSet + Hyrax::PcdmCollection: + display_label: PcdmCollection + Hyrax::FileSet: + display_label: FileSet +contexts: + flexible_context: + display_label: Flexible Metadata Example +mappings: + blacklight: + name: Additional Blacklight Solr Mappings + metatags: + name: Metatags + mods_oai_pmh: + name: MODS OAI PMH + qualified_dc_pmh: + name: Qualified DC OAI PMH + simple_dc_pmh: + name: Simple DC OAI PMH +properties: + title: + available_on: + class: + - Hyrax::AdministrativeSet + - Hyrax::FileSet + - Hyrax::PcdmCollection + - Hyrax::Work + cardinality: + minimum: 1 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + definition: + default: Enter a standardized title for display. If only one + title is needed, transcribe the title from the source + itself. + display_label: + default: Title + index_documentation: displayable, searchable + indexing: + - 'title_sim' + - 'title_tesim' + form: + required: true + primary: true + multi_value: true + mappings: + metatags: twitter:title, og:title + mods_oai_pmh: mods:titleInfo/mods:title + qualified_dc_pmh: dcterms:title + simple_dc_pmh: dc:title + property_uri: http://purl.org/dc/terms/title + range: http://www.w3.org/2001/XMLSchema#string + requirement: required + sample_values: + - Pencil drawn portrait study of woman + date_modified: + available_on: + class: + - Hyrax::AdministrativeSet + - Hyrax::FileSet + - Hyrax::PcdmCollection + - Hyrax::Work + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + display_label: + default: Date Modified + property_uri: http://purl.org/dc/terms/modified + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + date_uploaded: + available_on: + class: + - Hyrax::AdministrativeSet + - Hyrax::FileSet + - Hyrax::PcdmCollection + - Hyrax::Work + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + display_label: + default: Date Uploaded + property_uri: http://purl.org/dc/terms/dateSubmitted + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + - "2024-06-06 21:06:51 +0000" + depositor: + available_on: + class: + - Hyrax::AdministrativeSet + - Hyrax::FileSet + - Hyrax::PcdmCollection + - Hyrax::Work + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Depositor + index_documentation: searchable + indexing: + - 'depositor_tesim' + property_uri: http://id.loc.gov/vocabulary/relators/dpt + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson + creator: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 1 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Creator + index_documentation: displayable, searchable + indexing: + - 'creator_sim' + - 'creator_tesim' + form: + required: true + primary: true + property_uri: http://purl.org/dc/elements/1.1/creator + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson + license: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: License + index_documentation: displayable, searchable + indexing: + - 'license_sim' + - 'license_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/license + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://creativecommons.org/licenses/by/3.0/us/ + abstract: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Abstract + index_documentation: displayable, searchable + indexing: + - 'abstract_sim' + - 'abstract_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/abstract + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - This is an abstract. + access_right: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Access Right + index_documentation: displayable, searchable + indexing: + - 'access_right_sim' + - 'access_right_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/accessRights + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Open Access + alternative_title: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Alternative Title + index_documentation: displayable, searchable + indexing: + - 'alternative_title_sim' + - 'alternative_title_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/alternative + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Alternate Title Example + arkivo_checksum: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Arkivo Checksum + form: + primary: false + property_uri: http://scholarsphere.psu.edu/ns#arkivoChecksum + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - c0855931b7f1aefedb91d31af76873c0 + based_near: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Location + index_documentation: displayable, searchable + indexing: + - 'based_near_sim' + - 'based_near_tesim' + form: + primary: false + property_uri: http://xmlns.com/foaf/0.1/based_near + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - San Diego, California, United States + bibliographic_citation: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Bibliographic Citation + index_documentation: displayable, searchable + indexing: + - 'bibliographic_citation_sim' + - 'bibliographic_citation_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/bibliographicCitation + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - "Doe, J. (2024). Example Citation. Journal of Examples, 12(3), 45-67." + contributor: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Contributor + index_documentation: displayable, searchable + indexing: + - 'contributor_tesim' + - 'contributor_sim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/contributor + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Julie Allinson + date_created: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#dateTime + sources: + - 'null' + display_label: + default: Date Created + index_documentation: displayable, searchable + indexing: + - 'date_created_sim' + - 'date_created_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/created + range: http://www.w3.org/2001/XMLSchema#dateTime + sample_values: + sample_values: + - "2024-06-06 21:06:51 +0000" + description: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Description + index_documentation: displayable, searchable + indexing: + - 'description_sim' + - 'description_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/description + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - This is a description. + identifier: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Identifier + index_documentation: displayable, searchable + indexing: + - 'identifier_sim' + - 'identifier_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/identifier + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - abc123 + import_url: + available_on: + class: + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Import URL + property_uri: http://scholarsphere.psu.edu/ns#importUrl + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://example.com/resource1 + keyword: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Keyword + index_documentation: displayable, searchable + indexing: + - 'keyword_sim' + - 'keyword_tesim' + form: + primary: false + property_uri: http://schema.org/keywords + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Metadata + - Repository + label: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Label + index_documentation: displayable, searchable + indexing: + - 'label_sim' + - 'label_tesim' + form: + primary: false + property_uri: info:fedora/fedora-system:def/model#downloadFilename + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - file_label.txt + language: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Language + index_documentation: displayable, searchable + indexing: + - 'language_sim' + - 'language_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/language + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - English + - Spanish + publisher: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Publisher + index_documentation: displayable, searchable + indexing: + - 'publisher_sim' + - 'publisher_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/publisher + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Scholastic + related_url: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Related URL + index_documentation: displayable, searchable + indexing: + - 'related_url_sim' + - 'related_url_tesim' + form: + primary: false + property_uri: http://www.w3.org/2000/01/rdf-schema#seeAlso + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://example.com/resource1 + relative_path: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Relative Path + property_uri: http://scholarsphere.psu.edu/ns#relativePath + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - /path/to/resource + resource_type: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Resource Type + index_documentation: displayable, searchable + indexing: + - 'resource_type_sim' + - 'resource_type_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/type + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Article + - Conference Proceeding + rights_notes: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Rights Notes + index_documentation: displayable, searchable + indexing: + - 'rights_notes_sim' + - 'rights_notes_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/rights + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Creative Commons license. + rights_statement: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Rights Statement + index_documentation: displayable, searchable + indexing: + - 'rights_statement_sim' + - 'rights_statement_tesim' + form: + primary: true + property_uri: http://www.europeana.eu/schemas/edm/rights + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - http://rightsstatements.org/vocab/InC/1.0/ + source: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Source + index_documentation: displayable, searchable + indexing: + - 'source_sim' + - 'source_tesim' + form: + primary: false + property_uri: http://purl.org/dc/terms/source + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Original Manuscript + - Digital Archive + subject: + available_on: + class: + - Hyrax::FileSet + - CollectionResource + - GenericWorkResource + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Subject + index_documentation: displayable, searchable + indexing: + - 'subject_sim' + - 'subject_tesim' + form: + primary: false + property_uri: http://purl.org/dc/elements/1.1/subject + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Art + - Science + target_audience: + available_on: + class: + - CollectionResource + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Target Audience + form: + primary: true + multiple: true + property_uri: http://hyrax-example.com/target_audience + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Researchers + - Students + department: + available_on: + class: + - CollectionResource + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Department + form: + primary: true + property_uri: http://hyrax-example.com/department + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Mathematics + - History + course: + available_on: + class: + - CollectionResource + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Course + form: + primary: false + property_uri: http://hyrax-example.com/course + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Computer Science 50 + monograph_title: + available_on: + class: + - Monograph + cardinality: + minimum: 1 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Monograph Title + property_uri: http://hyrax-example.com/monograph_title + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Monograph Title + record_info: + available_on: + class: + - Monograph + cardinality: + minimum: 1 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Record Info + index_documentation: searchable + indexing: + - 'record_info_tesim' + form: + required: true + primary: true + property_uri: http://hyrax-example.com/record_info + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Record Info + place_of_publication: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Place of Publication + form: + required: false + primary: true + property_uri: http://hyrax-example.com/place_of_publication + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Place of Publication + genre: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Genre + form: + primary: true + property_uri: http://hyrax-example.com/genre + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Fiction + - Non-Fiction + series_title: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Series Title + form: + primary: false + property_uri: http://hyrax-example.com/series_title + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Series Title + target_audience: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + multi_value: true + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Target Audience + form: + multiple: true + property_uri: http://hyrax-example.com/target_audience + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Researchers + - Students + table_of_contents: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Table of Contents + form: + multiple: false + property_uri: http://hyrax-example.com/table_of_contents + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Table of Contents + date_of_issuance: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Date of Issuance + property_uri: http://hyrax-example.com/date_of_issuance + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - 2024-06-07 From 6542b0d64081e2e940b1706ea7ca843189ecf6e9 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Wed, 12 Jun 2024 11:35:20 -0700 Subject: [PATCH 16/34] dynamic indexers --- .dassie/config/metadata/m3_profile.yaml | 74 ++++++++++++++----- .../indexers/administrative_set_indexer.rb | 2 +- .../hyrax/indexers/file_set_indexer.rb | 4 +- .../hyrax/indexers/pcdm_collection_indexer.rb | 2 +- .../hyrax/indexers/pcdm_object_indexer.rb | 8 +- app/services/hyrax/schema_loader.rb | 4 +- lib/hyrax/indexer.rb | 10 ++- 7 files changed, 75 insertions(+), 29 deletions(-) diff --git a/.dassie/config/metadata/m3_profile.yaml b/.dassie/config/metadata/m3_profile.yaml index b3aa013533..34e5c26b18 100644 --- a/.dassie/config/metadata/m3_profile.yaml +++ b/.dassie/config/metadata/m3_profile.yaml @@ -7,11 +7,19 @@ profile: type: version: 1 classes: - Hyrax::Work: - display_label: Work - Hyrax::AdministrativeSet: + GenericWork: + display_label: Generic Work + GenericWorkResource: + display_label: Generic Work + Monograph: + display_label: Monograph + AdminSet: + diplay_label: AdminSet + AdminSetResource: diplay_label: AdministrativeSet - Hyrax::PcdmCollection: + Collection: + display_label: Collection + CollectionResource: display_label: PcdmCollection Hyrax::FileSet: display_label: FileSet @@ -33,10 +41,12 @@ properties: title: available_on: class: - - Hyrax::AdministrativeSet + - AdminSet + - AdminSetResource - Hyrax::FileSet - - Hyrax::PcdmCollection - - Hyrax::Work + - CollectionResource + - GenericWorkResource + - GenericWork cardinality: minimum: 1 multi_value: true @@ -71,10 +81,12 @@ properties: date_modified: available_on: class: - - Hyrax::AdministrativeSet + - AdminSet + - AdminSetResource - Hyrax::FileSet - - Hyrax::PcdmCollection - - Hyrax::Work + - CollectionResource + - GenericWorkResource + - GenericWork cardinality: minimum: 0 maximum: 1 @@ -88,10 +100,12 @@ properties: date_uploaded: available_on: class: - - Hyrax::AdministrativeSet + - AdminSet + - AdminSetResource - Hyrax::FileSet - - Hyrax::PcdmCollection - - Hyrax::Work + - CollectionResource + - GenericWorkResource + - GenericWork cardinality: minimum: 0 maximum: 1 @@ -105,10 +119,12 @@ properties: depositor: available_on: class: - - Hyrax::AdministrativeSet + - AdminSet + - AdminSetResource - Hyrax::FileSet - - Hyrax::PcdmCollection - - Hyrax::Work + - CollectionResource + - GenericWorkResource + - GenericWork cardinality: minimum: 0 maximum: 1 @@ -132,6 +148,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 1 @@ -159,6 +176,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -185,6 +203,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -210,6 +229,7 @@ properties: class: - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -235,6 +255,7 @@ properties: class: - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -260,6 +281,7 @@ properties: class: - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -283,6 +305,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -308,6 +331,7 @@ properties: class: - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -334,6 +358,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -360,6 +385,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -387,6 +413,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -413,6 +440,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -438,6 +466,7 @@ properties: class: - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -459,6 +488,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -486,6 +516,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -513,6 +544,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -540,6 +572,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -566,6 +599,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -592,6 +626,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -613,6 +648,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -640,6 +676,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -666,6 +703,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -692,6 +730,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -719,6 +758,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -963,4 +1003,4 @@ properties: property_uri: http://hyrax-example.com/date_of_issuance range: http://www.w3.org/2001/XMLSchema#string sample_values: - - 2024-06-07 + - "2024-06-06 21:06:51 +0000" diff --git a/app/indexers/hyrax/indexers/administrative_set_indexer.rb b/app/indexers/hyrax/indexers/administrative_set_indexer.rb index 787cbe7e4e..6befb618ed 100644 --- a/app/indexers/hyrax/indexers/administrative_set_indexer.rb +++ b/app/indexers/hyrax/indexers/administrative_set_indexer.rb @@ -7,7 +7,7 @@ module Indexers class AdministrativeSetIndexer < Hyrax::Indexers::ResourceIndexer include Hyrax::PermissionIndexer include Hyrax::VisibilityIndexer - include Hyrax::Indexer(:core_metadata) + include Hyrax::Indexer(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength super.tap do |solr_doc| diff --git a/app/indexers/hyrax/indexers/file_set_indexer.rb b/app/indexers/hyrax/indexers/file_set_indexer.rb index b684753025..ec28cecf2e 100644 --- a/app/indexers/hyrax/indexers/file_set_indexer.rb +++ b/app/indexers/hyrax/indexers/file_set_indexer.rb @@ -8,8 +8,8 @@ class FileSetIndexer < Hyrax::Indexers::ResourceIndexer # rubocop:disable Metric include Hyrax::PermissionIndexer include Hyrax::VisibilityIndexer include Hyrax::ThumbnailIndexer - include Hyrax::Indexer(:core_metadata) - include Hyrax::Indexer(:file_set_metadata) + include Hyrax::Indexer(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Indexer(:file_set_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity super.tap do |solr_doc| # rubocop:disable Metrics/BlockLength diff --git a/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb b/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb index a146bc4d13..83791eea5f 100644 --- a/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb +++ b/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb @@ -9,7 +9,7 @@ class PcdmCollectionIndexer < Hyrax::Indexers::ResourceIndexer include Hyrax::VisibilityIndexer include Hyrax::LocationIndexer include Hyrax::ThumbnailIndexer - include Hyrax::Indexer(:core_metadata) + include Hyrax::Indexer(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) self.thumbnail_path_service = CollectionThumbnailPathService diff --git a/app/indexers/hyrax/indexers/pcdm_object_indexer.rb b/app/indexers/hyrax/indexers/pcdm_object_indexer.rb index 8451a7d59d..e5c098a29d 100644 --- a/app/indexers/hyrax/indexers/pcdm_object_indexer.rb +++ b/app/indexers/hyrax/indexers/pcdm_object_indexer.rb @@ -9,7 +9,7 @@ class PcdmObjectIndexer < Hyrax::Indexers::ResourceIndexer include Hyrax::VisibilityIndexer include Hyrax::LocationIndexer include Hyrax::ThumbnailIndexer - include Hyrax::Indexer(:core_metadata) + include Hyrax::Indexer(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength super.tap do |solr_doc| @@ -20,13 +20,13 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met solr_doc['admin_set_sim'] = admin_set_label solr_doc['admin_set_tesim'] = admin_set_label solr_doc["#{Hyrax.config.admin_set_predicate.qname.last}_ssim"] = [resource.admin_set_id.to_s] - solr_doc['member_of_collection_ids_ssim'] = resource.member_of_collection_ids.map(&:to_s) - solr_doc['member_ids_ssim'] = resource.member_ids.map(&:to_s) + solr_doc['member_of_collection_ids_ssim'] = resource.member_of_collection_ids&.map(&:to_s) + solr_doc['member_ids_ssim'] = resource.member_ids&.map(&:to_s) solr_doc['depositor_ssim'] = [resource.depositor] solr_doc['depositor_tesim'] = [resource.depositor] solr_doc['hasRelatedMediaFragment_ssim'] = [resource.representative_id.to_s] solr_doc['hasRelatedImage_ssim'] = [resource.thumbnail_id.to_s] - solr_doc['hasFormat_ssim'] = resource.rendering_ids.map(&:to_s) if resource.rendering_ids.present? + solr_doc['hasFormat_ssim'] = resource.rendering_ids&.map(&:to_s) if resource.rendering_ids.present? index_embargo(solr_doc) index_lease(solr_doc) end diff --git a/app/services/hyrax/schema_loader.rb b/app/services/hyrax/schema_loader.rb index d1516985e4..df694fb439 100644 --- a/app/services/hyrax/schema_loader.rb +++ b/app/services/hyrax/schema_loader.rb @@ -66,13 +66,13 @@ def initialize(name, config) ## # @return [Hash{Symbol => Object}] def form_options - config.fetch('form', {}).symbolize_keys + config.fetch('form', {})&.symbolize_keys || {} end ## # @return [Enumerable] def index_keys - config.fetch('index_keys', []).map(&:to_sym) + config.fetch('index_keys', [])&.map(&:to_sym) || [] end ## diff --git a/lib/hyrax/indexer.rb b/lib/hyrax/indexer.rb index f47630e9e4..4ab43dcd86 100644 --- a/lib/hyrax/indexer.rb +++ b/lib/hyrax/indexer.rb @@ -33,8 +33,14 @@ class Indexer < Module def initialize(rules) define_method :to_solr do |*args| super(*args).tap do |document| - rules.each do |index_key, method| - document[index_key] = resource.try(method) + if ENV.fetch('HYRAX_FLEXIBLE', false) + Hyrax::Schema.default_schema_loader.index_rules_for(schema: resource.class.to_s, version: resource.schema_version).each do |index_key, method| + document[index_key] = resource.try(method) + end + else + rules.each do |index_key, method| + document[index_key] = resource.try(method) + end end end end From 9115944ba308eb32b2fc427016336cd5a4bde798 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Wed, 12 Jun 2024 21:01:59 -0700 Subject: [PATCH 17/34] additional indexer calls --- .../collection_resource/collection_resource_generator.rb | 2 +- .../collection_resource/templates/collection_indexer.rb.erb | 2 +- lib/generators/hyrax/work_resource/templates/indexer.rb.erb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/generators/hyrax/collection_resource/collection_resource_generator.rb b/lib/generators/hyrax/collection_resource/collection_resource_generator.rb index 818c7a1f3d..f22c105c6d 100644 --- a/lib/generators/hyrax/collection_resource/collection_resource_generator.rb +++ b/lib/generators/hyrax/collection_resource/collection_resource_generator.rb @@ -84,7 +84,7 @@ def create_indexer template('collection_indexer.rb.erb', filepath) return unless include_basic_metadata? inject_into_file filepath, before: /include Hyrax::Indexer/ do - "include Hyrax::Indexer(:basic_metadata)\n " + "include Hyrax::Indexer(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false)\n " end end diff --git a/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb b/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb index 7a3309be0a..0b6d4572e8 100644 --- a/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb +++ b/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb @@ -3,5 +3,5 @@ # Generated via # `rails generate hyrax:collection_resource <%= class_name %>` class <%= class_name %>Indexer < Hyrax::Indexers::PcdmCollectionIndexer - include Hyrax::Indexer(:<%= file_name %>) + include Hyrax::Indexer(:<%= file_name %>) unless ENV.fetch('HYRAX_FLEXIBLE', false) end diff --git a/lib/generators/hyrax/work_resource/templates/indexer.rb.erb b/lib/generators/hyrax/work_resource/templates/indexer.rb.erb index 3ba45902f7..fb9066a8c8 100644 --- a/lib/generators/hyrax/work_resource/templates/indexer.rb.erb +++ b/lib/generators/hyrax/work_resource/templates/indexer.rb.erb @@ -3,8 +3,8 @@ # Generated via # `rails generate hyrax:work_resource <%= class_name %>` class <%= class_name %>Indexer < Hyrax::Indexers::PcdmObjectIndexer(<%= class_name %>) - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:<%= file_name %>) + include Hyrax::Indexer(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Indexer(:<%= file_name %>) unless ENV.fetch('HYRAX_FLEXIBLE', false) # Uncomment this block if you want to add custom indexing behavior: # def to_solr From 629bb680ed5b77e77218e4306782f17dbf1e6360 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 13 Jun 2024 11:51:57 -0700 Subject: [PATCH 18/34] seperate m3 profiles from other metadata --- .dassie/config/{metadata => metadata_profiles}/m3_profile.yaml | 0 .koppie/config/{metadata => metadata_profiles}/m3_profile.yaml | 0 app/services/hyrax/m3_schema_loader.rb | 2 +- .../hyrax/required_data_seeders/flexible_profile_seeder.rb | 2 +- config/{metadata => metadata_profiles}/m3_profile.yaml | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename .dassie/config/{metadata => metadata_profiles}/m3_profile.yaml (100%) rename .koppie/config/{metadata => metadata_profiles}/m3_profile.yaml (100%) rename config/{metadata => metadata_profiles}/m3_profile.yaml (100%) diff --git a/.dassie/config/metadata/m3_profile.yaml b/.dassie/config/metadata_profiles/m3_profile.yaml similarity index 100% rename from .dassie/config/metadata/m3_profile.yaml rename to .dassie/config/metadata_profiles/m3_profile.yaml diff --git a/.koppie/config/metadata/m3_profile.yaml b/.koppie/config/metadata_profiles/m3_profile.yaml similarity index 100% rename from .koppie/config/metadata/m3_profile.yaml rename to .koppie/config/metadata_profiles/m3_profile.yaml diff --git a/app/services/hyrax/m3_schema_loader.rb b/app/services/hyrax/m3_schema_loader.rb index 4fd7a7a2b8..4b1f614ae1 100644 --- a/app/services/hyrax/m3_schema_loader.rb +++ b/app/services/hyrax/m3_schema_loader.rb @@ -6,7 +6,7 @@ module Hyrax # # Read m3 profiles from the database # - # @see config/metadata/m3_profile.yaml for an example configuration + # @see config/metadata_profiles/m3_profile.yaml for an example configuration class M3SchemaLoader < Hyrax::SchemaLoader private diff --git a/app/utils/hyrax/required_data_seeders/flexible_profile_seeder.rb b/app/utils/hyrax/required_data_seeders/flexible_profile_seeder.rb index 331f0002e3..10d3be07c1 100644 --- a/app/utils/hyrax/required_data_seeders/flexible_profile_seeder.rb +++ b/app/utils/hyrax/required_data_seeders/flexible_profile_seeder.rb @@ -17,7 +17,7 @@ def generate_seeds(logger: Logger.new(STDOUT)) logger.info("Adding required collections...") flexible_schema = Hyrax::FlexibleSchema.first_or_create do |f| - f.profile = YAML.safe_load_file(Rails.root.join('config', 'metadata', 'm3_profile.yaml')) + f.profile = YAML.safe_load_file(Rails.root.join('config', 'metadata_profiles', 'm3_profile.yaml')) end logger.info " #{flexible_schema.title} -- FOUND OR CREATED" diff --git a/config/metadata/m3_profile.yaml b/config/metadata_profiles/m3_profile.yaml similarity index 100% rename from config/metadata/m3_profile.yaml rename to config/metadata_profiles/m3_profile.yaml From 39dfc2d47651fb1a85c2f0800257c8d56f2adcc1 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Thu, 13 Jun 2024 13:23:58 -0700 Subject: [PATCH 19/34] Update Koppie m3_profile and add ENV guards --- .koppie/app/models/collection_resource.rb | 4 +- .koppie/app/models/generic_work.rb | 4 +- .koppie/app/models/monograph.rb | 4 +- .../config/metadata_profiles/m3_profile.yaml | 74 ++++++++++--------- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/.koppie/app/models/collection_resource.rb b/.koppie/app/models/collection_resource.rb index 8ba57bc859..9cc9523b4b 100644 --- a/.koppie/app/models/collection_resource.rb +++ b/.koppie/app/models/collection_resource.rb @@ -27,6 +27,6 @@ class CollectionResource < Hyrax::PcdmCollection # * add Valkyrie attributes to this class # * update form and indexer to process the attributes # - include Hyrax::Schema(:basic_metadata) - include Hyrax::Schema(:collection_resource) + include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:collection_resource) unless ENV.fetch('HYRAX_FLEXIBLE', false) end diff --git a/.koppie/app/models/generic_work.rb b/.koppie/app/models/generic_work.rb index d884387774..429cfeb60d 100644 --- a/.koppie/app/models/generic_work.rb +++ b/.koppie/app/models/generic_work.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:work_resource GenericWork` class GenericWork < Hyrax::Work - include Hyrax::Schema(:basic_metadata) - include Hyrax::Schema(:generic_work) + include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:generic_work) unless ENV.fetch('HYRAX_FLEXIBLE', false) end diff --git a/.koppie/app/models/monograph.rb b/.koppie/app/models/monograph.rb index fc3e67b2a5..5e1a863a72 100644 --- a/.koppie/app/models/monograph.rb +++ b/.koppie/app/models/monograph.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:work_resource Monograph` class Monograph < Hyrax::Work - include Hyrax::Schema(:basic_metadata) - include Hyrax::Schema(:monograph) + include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:monograph) unless ENV.fetch('HYRAX_FLEXIBLE', false) end diff --git a/.koppie/config/metadata_profiles/m3_profile.yaml b/.koppie/config/metadata_profiles/m3_profile.yaml index b3aa013533..39fe059a67 100644 --- a/.koppie/config/metadata_profiles/m3_profile.yaml +++ b/.koppie/config/metadata_profiles/m3_profile.yaml @@ -7,11 +7,13 @@ profile: type: version: 1 classes: - Hyrax::Work: - display_label: Work + GenericWork: + display_label: Generic Work + Monograph: + display_label: Monograph Hyrax::AdministrativeSet: diplay_label: AdministrativeSet - Hyrax::PcdmCollection: + CollectionResource: display_label: PcdmCollection Hyrax::FileSet: display_label: FileSet @@ -35,8 +37,8 @@ properties: class: - Hyrax::AdministrativeSet - Hyrax::FileSet - - Hyrax::PcdmCollection - - Hyrax::Work + - CollectionResource + - GenericWork cardinality: minimum: 1 multi_value: true @@ -73,8 +75,8 @@ properties: class: - Hyrax::AdministrativeSet - Hyrax::FileSet - - Hyrax::PcdmCollection - - Hyrax::Work + - CollectionResource + - GenericWork cardinality: minimum: 0 maximum: 1 @@ -90,8 +92,8 @@ properties: class: - Hyrax::AdministrativeSet - Hyrax::FileSet - - Hyrax::PcdmCollection - - Hyrax::Work + - CollectionResource + - GenericWork cardinality: minimum: 0 maximum: 1 @@ -107,8 +109,8 @@ properties: class: - Hyrax::AdministrativeSet - Hyrax::FileSet - - Hyrax::PcdmCollection - - Hyrax::Work + - CollectionResource + - GenericWork cardinality: minimum: 0 maximum: 1 @@ -131,7 +133,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 1 @@ -158,7 +160,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -184,7 +186,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -209,7 +211,7 @@ properties: available_on: class: - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -234,7 +236,7 @@ properties: available_on: class: - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -259,7 +261,7 @@ properties: available_on: class: - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -282,7 +284,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -307,7 +309,7 @@ properties: available_on: class: - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -333,7 +335,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -359,7 +361,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -386,7 +388,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -412,7 +414,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -437,7 +439,7 @@ properties: available_on: class: - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -458,7 +460,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -485,7 +487,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -512,7 +514,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -539,7 +541,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -565,7 +567,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -591,7 +593,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -612,7 +614,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -639,7 +641,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -665,7 +667,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -691,7 +693,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -718,7 +720,7 @@ properties: class: - Hyrax::FileSet - CollectionResource - - GenericWorkResource + - GenericWork - Monograph cardinality: minimum: 0 @@ -963,4 +965,4 @@ properties: property_uri: http://hyrax-example.com/date_of_issuance range: http://www.w3.org/2001/XMLSchema#string sample_values: - - 2024-06-07 + - "2024-06-06 21:06:51 +0000" From 9f93a7f08a6e92d26392ba6f74b2247b2bed925e Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Thu, 13 Jun 2024 16:38:17 -0700 Subject: [PATCH 20/34] Add migration and schema to Koppie --- .../20240606205215_create_hyrax_flexible_schemas.rb | 9 +++++++++ .koppie/db/schema.rb | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .koppie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb diff --git a/.koppie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb b/.koppie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb new file mode 100644 index 0000000000..bdbac2bc49 --- /dev/null +++ b/.koppie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb @@ -0,0 +1,9 @@ +class CreateHyraxFlexibleSchemas < ActiveRecord::Migration[6.1] + def change + create_table :hyrax_flexible_schemas do |t| + t.text :profile + + t.timestamps + end + end +end diff --git a/.koppie/db/schema.rb b/.koppie/db/schema.rb index 90c60c8384..c4dfd4eafa 100644 --- a/.koppie/db/schema.rb +++ b/.koppie/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_08_03_165135) do +ActiveRecord::Schema.define(version: 2024_06_06_205215) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -164,6 +164,12 @@ t.datetime "updated_at", null: false end + create_table "hyrax_flexible_schemas", force: :cascade do |t| + t.text "profile" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "job_io_wrappers", force: :cascade do |t| t.bigint "user_id" t.bigint "uploaded_file_id" From bf5bbc4d9f809d23449ec95b28f953aad0d767af Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Fri, 14 Jun 2024 12:58:49 -0700 Subject: [PATCH 21/34] Introduce flexible? configuration --- .dassie/app/models/collection_resource.rb | 4 ++-- .dassie/app/models/generic_work_resource.rb | 4 ++-- .dassie/app/models/monograph.rb | 4 ++-- .koppie/app/models/collection_resource.rb | 4 ++-- .koppie/app/models/generic_work.rb | 4 ++-- .koppie/app/models/monograph.rb | 4 ++-- app/indexers/hyrax/indexers/administrative_set_indexer.rb | 2 +- app/indexers/hyrax/indexers/file_set_indexer.rb | 4 ++-- app/indexers/hyrax/indexers/pcdm_collection_indexer.rb | 2 +- app/indexers/hyrax/indexers/pcdm_object_indexer.rb | 2 +- app/models/hyrax/administrative_set.rb | 2 +- app/models/hyrax/file_set.rb | 4 ++-- app/models/hyrax/pcdm_collection.rb | 2 +- app/models/hyrax/resource.rb | 2 +- app/models/hyrax/work.rb | 2 +- app/utils/hyrax/required_data_seeder.rb | 2 +- .../collection_resource/collection_resource_generator.rb | 2 +- .../templates/collection_indexer.rb.erb | 2 +- .../hyrax/work_resource/templates/indexer.rb.erb | 4 ++-- lib/hyrax/configuration.rb | 8 ++++++++ lib/hyrax/indexer.rb | 2 +- lib/hyrax/schema.rb | 2 +- spec/spec_helper.rb | 1 + 23 files changed, 39 insertions(+), 30 deletions(-) diff --git a/.dassie/app/models/collection_resource.rb b/.dassie/app/models/collection_resource.rb index dd153110d9..63035e0771 100644 --- a/.dassie/app/models/collection_resource.rb +++ b/.dassie/app/models/collection_resource.rb @@ -30,8 +30,8 @@ class CollectionResource < Hyrax::PcdmCollection # * add Valkyrie attributes to this class # * update form and indexer to process the attributes # - include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Schema(:collection_resource) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Schema(:collection_resource) unless Hyrax.config.flexible? Hyrax::ValkyrieLazyMigration.migrating(self, from: ::Collection) if ENV.fetch('VALKYRIE_TRANSITION', false) end diff --git a/.dassie/app/models/generic_work_resource.rb b/.dassie/app/models/generic_work_resource.rb index 9919ced533..6619fe66bf 100644 --- a/.dassie/app/models/generic_work_resource.rb +++ b/.dassie/app/models/generic_work_resource.rb @@ -3,8 +3,8 @@ # Generated via # `rails generate hyrax:work_resource GenericWorkResource` class GenericWorkResource < Hyrax::Work - include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Schema(:generic_work_resource) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Schema(:generic_work_resource) unless Hyrax.config.flexible? Hyrax::ValkyrieLazyMigration.migrating(self, from: GenericWork) end diff --git a/.dassie/app/models/monograph.rb b/.dassie/app/models/monograph.rb index 5e1a863a72..34f9b195a4 100644 --- a/.dassie/app/models/monograph.rb +++ b/.dassie/app/models/monograph.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:work_resource Monograph` class Monograph < Hyrax::Work - include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Schema(:monograph) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Schema(:monograph) unless Hyrax.config.flexible? end diff --git a/.koppie/app/models/collection_resource.rb b/.koppie/app/models/collection_resource.rb index 9cc9523b4b..435cdf595f 100644 --- a/.koppie/app/models/collection_resource.rb +++ b/.koppie/app/models/collection_resource.rb @@ -27,6 +27,6 @@ class CollectionResource < Hyrax::PcdmCollection # * add Valkyrie attributes to this class # * update form and indexer to process the attributes # - include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Schema(:collection_resource) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Schema(:collection_resource) unless Hyrax.config.flexible? end diff --git a/.koppie/app/models/generic_work.rb b/.koppie/app/models/generic_work.rb index 429cfeb60d..0f3debda26 100644 --- a/.koppie/app/models/generic_work.rb +++ b/.koppie/app/models/generic_work.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:work_resource GenericWork` class GenericWork < Hyrax::Work - include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Schema(:generic_work) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Schema(:generic_work) unless Hyrax.config.flexible? end diff --git a/.koppie/app/models/monograph.rb b/.koppie/app/models/monograph.rb index 5e1a863a72..34f9b195a4 100644 --- a/.koppie/app/models/monograph.rb +++ b/.koppie/app/models/monograph.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:work_resource Monograph` class Monograph < Hyrax::Work - include Hyrax::Schema(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Schema(:monograph) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Schema(:monograph) unless Hyrax.config.flexible? end diff --git a/app/indexers/hyrax/indexers/administrative_set_indexer.rb b/app/indexers/hyrax/indexers/administrative_set_indexer.rb index 6befb618ed..575842ee4b 100644 --- a/app/indexers/hyrax/indexers/administrative_set_indexer.rb +++ b/app/indexers/hyrax/indexers/administrative_set_indexer.rb @@ -7,7 +7,7 @@ module Indexers class AdministrativeSetIndexer < Hyrax::Indexers::ResourceIndexer include Hyrax::PermissionIndexer include Hyrax::VisibilityIndexer - include Hyrax::Indexer(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Indexer(:core_metadata) unless Hyrax.config.flexible? def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength super.tap do |solr_doc| diff --git a/app/indexers/hyrax/indexers/file_set_indexer.rb b/app/indexers/hyrax/indexers/file_set_indexer.rb index ec28cecf2e..80d053c24c 100644 --- a/app/indexers/hyrax/indexers/file_set_indexer.rb +++ b/app/indexers/hyrax/indexers/file_set_indexer.rb @@ -8,8 +8,8 @@ class FileSetIndexer < Hyrax::Indexers::ResourceIndexer # rubocop:disable Metric include Hyrax::PermissionIndexer include Hyrax::VisibilityIndexer include Hyrax::ThumbnailIndexer - include Hyrax::Indexer(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Indexer(:file_set_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Indexer(:core_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:file_set_metadata) unless Hyrax.config.flexible? def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity super.tap do |solr_doc| # rubocop:disable Metrics/BlockLength diff --git a/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb b/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb index 83791eea5f..e33cf54e55 100644 --- a/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb +++ b/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb @@ -9,7 +9,7 @@ class PcdmCollectionIndexer < Hyrax::Indexers::ResourceIndexer include Hyrax::VisibilityIndexer include Hyrax::LocationIndexer include Hyrax::ThumbnailIndexer - include Hyrax::Indexer(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Indexer(:core_metadata) unless Hyrax.config.flexible? self.thumbnail_path_service = CollectionThumbnailPathService diff --git a/app/indexers/hyrax/indexers/pcdm_object_indexer.rb b/app/indexers/hyrax/indexers/pcdm_object_indexer.rb index e5c098a29d..3dcfc209f9 100644 --- a/app/indexers/hyrax/indexers/pcdm_object_indexer.rb +++ b/app/indexers/hyrax/indexers/pcdm_object_indexer.rb @@ -9,7 +9,7 @@ class PcdmObjectIndexer < Hyrax::Indexers::ResourceIndexer include Hyrax::VisibilityIndexer include Hyrax::LocationIndexer include Hyrax::ThumbnailIndexer - include Hyrax::Indexer(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Indexer(:core_metadata) unless Hyrax.config.flexible? def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength super.tap do |solr_doc| diff --git a/app/models/hyrax/administrative_set.rb b/app/models/hyrax/administrative_set.rb index af91ada9e9..325976a548 100644 --- a/app/models/hyrax/administrative_set.rb +++ b/app/models/hyrax/administrative_set.rb @@ -25,7 +25,7 @@ module Hyrax # @see Valkyrie query adapter's #find_inverse_references_by # class AdministrativeSet < Hyrax::Resource - include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:core_metadata) unless Hyrax.config.flexible? attribute :alternative_title, Valkyrie::Types::Set.of(Valkyrie::Types::String) attribute :creator, Valkyrie::Types::Set.of(Valkyrie::Types::String) diff --git a/app/models/hyrax/file_set.rb b/app/models/hyrax/file_set.rb index 4b068b7a24..601b6543de 100644 --- a/app/models/hyrax/file_set.rb +++ b/app/models/hyrax/file_set.rb @@ -49,8 +49,8 @@ module Hyrax # @see Hyrax::CustomQueries::Navigators::ParentWorkNavigator#find_parent_work # @see https://wiki.duraspace.org/display/samvera/Hydra%3A%3AWorks+Shared+Modeling class FileSet < Hyrax::Resource - include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Schema(:file_set_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:core_metadata) unless Hyrax.config.flexible? + include Hyrax::Schema(:file_set_metadata) unless Hyrax.config.flexible? def self.model_name(name_class: Hyrax::Name) @_model_name ||= name_class.new(self, nil, 'FileSet') diff --git a/app/models/hyrax/pcdm_collection.rb b/app/models/hyrax/pcdm_collection.rb index 218e1a961d..b1a8ceb895 100644 --- a/app/models/hyrax/pcdm_collection.rb +++ b/app/models/hyrax/pcdm_collection.rb @@ -40,7 +40,7 @@ module Hyrax # @see Hyrax::CustomQueries::Navigators::CollectionMembers#find_members_of # class PcdmCollection < Hyrax::Resource - include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:core_metadata) unless Hyrax.config.flexible? attribute :collection_type_gid, Valkyrie::Types::String attribute :member_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID).meta(ordered: true) diff --git a/app/models/hyrax/resource.rb b/app/models/hyrax/resource.rb index 8ae43e372a..e07f566f7b 100644 --- a/app/models/hyrax/resource.rb +++ b/app/models/hyrax/resource.rb @@ -31,7 +31,7 @@ module Hyrax # implementations). # class Resource < Valkyrie::Resource - include Hyrax::Flexibility if ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Flexibility if Hyrax.config.flexible? include Hyrax::Naming include Hyrax::WithEvents diff --git a/app/models/hyrax/work.rb b/app/models/hyrax/work.rb index e04410327d..a148009fad 100644 --- a/app/models/hyrax/work.rb +++ b/app/models/hyrax/work.rb @@ -94,7 +94,7 @@ module Hyrax # @see https://wiki.lyrasis.org/display/samvera/Hydra::Works+Shared+Modeling # for a historical perspective. class Work < Hyrax::Resource - include Hyrax::Schema(:core_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Schema(:core_metadata) unless Hyrax.config.flexible? attribute :admin_set_id, Valkyrie::Types::ID attribute :member_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID).meta(ordered: true) diff --git a/app/utils/hyrax/required_data_seeder.rb b/app/utils/hyrax/required_data_seeder.rb index 45250ac87b..a7bc33871d 100644 --- a/app/utils/hyrax/required_data_seeder.rb +++ b/app/utils/hyrax/required_data_seeder.rb @@ -14,7 +14,7 @@ def initialize(logger: Logger.new(STDOUT)) end def generate_seed_data - Hyrax::RequiredDataSeeders::FlexibleProfileSeeder.generate_seeds(logger: logger) if ENV.fetch('HYRAX_FLEXIBLE', false) + Hyrax::RequiredDataSeeders::FlexibleProfileSeeder.generate_seeds(logger: logger) if Hyrax.config.flexible? Hyrax::RequiredDataSeeders::CollectionTypeSeeder.generate_seeds(logger: logger) Hyrax::RequiredDataSeeders::CollectionSeeder.generate_seeds(logger: logger) end diff --git a/lib/generators/hyrax/collection_resource/collection_resource_generator.rb b/lib/generators/hyrax/collection_resource/collection_resource_generator.rb index f22c105c6d..8db0fbc9f9 100644 --- a/lib/generators/hyrax/collection_resource/collection_resource_generator.rb +++ b/lib/generators/hyrax/collection_resource/collection_resource_generator.rb @@ -84,7 +84,7 @@ def create_indexer template('collection_indexer.rb.erb', filepath) return unless include_basic_metadata? inject_into_file filepath, before: /include Hyrax::Indexer/ do - "include Hyrax::Indexer(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false)\n " + "include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible?\n " end end diff --git a/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb b/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb index 0b6d4572e8..c85cba5054 100644 --- a/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb +++ b/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb @@ -3,5 +3,5 @@ # Generated via # `rails generate hyrax:collection_resource <%= class_name %>` class <%= class_name %>Indexer < Hyrax::Indexers::PcdmCollectionIndexer - include Hyrax::Indexer(:<%= file_name %>) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Indexer(:<%= file_name %>) unless Hyrax.config.flexible? end diff --git a/lib/generators/hyrax/work_resource/templates/indexer.rb.erb b/lib/generators/hyrax/work_resource/templates/indexer.rb.erb index fb9066a8c8..1514165664 100644 --- a/lib/generators/hyrax/work_resource/templates/indexer.rb.erb +++ b/lib/generators/hyrax/work_resource/templates/indexer.rb.erb @@ -3,8 +3,8 @@ # Generated via # `rails generate hyrax:work_resource <%= class_name %>` class <%= class_name %>Indexer < Hyrax::Indexers::PcdmObjectIndexer(<%= class_name %>) - include Hyrax::Indexer(:basic_metadata) unless ENV.fetch('HYRAX_FLEXIBLE', false) - include Hyrax::Indexer(:<%= file_name %>) unless ENV.fetch('HYRAX_FLEXIBLE', false) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:<%= file_name %>) unless Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/lib/hyrax/configuration.rb b/lib/hyrax/configuration.rb index 99c3e47f4b..88ec3c5f41 100644 --- a/lib/hyrax/configuration.rb +++ b/lib/hyrax/configuration.rb @@ -305,6 +305,14 @@ def fixity_service @fixity_service ||= Hyrax::Fixity::ActiveFedoraFixityService end + # This value determines whether to use m3 flexible metadata schema or not + attr_writer :flexible + attr_reader :flexible + def flexible? + @flexible ||= + ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYRAX_FLEXIBLE', false)) + end + attr_writer :max_days_between_fixity_checks def max_days_between_fixity_checks @max_days_between_fixity_checks ||= 7 diff --git a/lib/hyrax/indexer.rb b/lib/hyrax/indexer.rb index 4ab43dcd86..508ef09ebd 100644 --- a/lib/hyrax/indexer.rb +++ b/lib/hyrax/indexer.rb @@ -33,7 +33,7 @@ class Indexer < Module def initialize(rules) define_method :to_solr do |*args| super(*args).tap do |document| - if ENV.fetch('HYRAX_FLEXIBLE', false) + if Hyrax.config.flexible? Hyrax::Schema.default_schema_loader.index_rules_for(schema: resource.class.to_s, version: resource.schema_version).each do |index_key, method| document[index_key] = resource.try(method) end diff --git a/lib/hyrax/schema.rb b/lib/hyrax/schema.rb index 90929a9340..7d545a9700 100644 --- a/lib/hyrax/schema.rb +++ b/lib/hyrax/schema.rb @@ -61,7 +61,7 @@ class Schema < Module ## # Pick the default schema loader based on whether flex is on or not def self.default_schema_loader - ENV.fetch('HYRAX_FLEXIBLE', false) ? M3SchemaLoader.new : SimpleSchemaLoader.new + Hyrax.config.flexible? ? M3SchemaLoader.new : SimpleSchemaLoader.new end ## # @param [Symbol] schema_name diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b788b3b6e8..55bd762749 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,7 @@ # Analytics is turned off by default ENV['HYRAX_ANALYTICS'] = 'false' +ENV['HYRAX_FLEXIBLE'] = 'false' require "bundler/setup" From 0980228f34cdeb2a8c1bfd9a4dbb03eac6c494e7 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Fri, 14 Jun 2024 13:02:27 -0700 Subject: [PATCH 22/34] Introduce valkyrie_transition? config option --- .dassie/app/controllers/hyrax/generic_works_controller.rb | 2 +- .dassie/app/models/collection_resource.rb | 2 +- .dassie/app/models/file_set.rb | 2 +- .dassie/config/initializers/hyrax.rb | 2 +- .dassie/config/initializers/wings.rb | 2 +- lib/hyrax/configuration.rb | 8 ++++++++ 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.dassie/app/controllers/hyrax/generic_works_controller.rb b/.dassie/app/controllers/hyrax/generic_works_controller.rb index c2a9ed726d..01435c0d16 100644 --- a/.dassie/app/controllers/hyrax/generic_works_controller.rb +++ b/.dassie/app/controllers/hyrax/generic_works_controller.rb @@ -6,7 +6,7 @@ class GenericWorksController < ApplicationController # Adds Hyrax behaviors to the controller. include Hyrax::WorksControllerBehavior include Hyrax::BreadcrumbsForWorks - if ENV.fetch('VALKYRIE_TRANSITION', false) + if Hyrax.config.valkyrie_transition? self.curation_concern_type = ::GenericWorkResource self.work_form_service = Hyrax::FormFactory.new diff --git a/.dassie/app/models/collection_resource.rb b/.dassie/app/models/collection_resource.rb index 63035e0771..1fd97de0e8 100644 --- a/.dassie/app/models/collection_resource.rb +++ b/.dassie/app/models/collection_resource.rb @@ -33,5 +33,5 @@ class CollectionResource < Hyrax::PcdmCollection include Hyrax::Schema(:basic_metadata) unless Hyrax.config.flexible? include Hyrax::Schema(:collection_resource) unless Hyrax.config.flexible? - Hyrax::ValkyrieLazyMigration.migrating(self, from: ::Collection) if ENV.fetch('VALKYRIE_TRANSITION', false) + Hyrax::ValkyrieLazyMigration.migrating(self, from: ::Collection) if Hyrax.config.valkyrie_transition? end diff --git a/.dassie/app/models/file_set.rb b/.dassie/app/models/file_set.rb index 362db10cfb..2363b66dc0 100644 --- a/.dassie/app/models/file_set.rb +++ b/.dassie/app/models/file_set.rb @@ -4,4 +4,4 @@ class FileSet < ActiveFedora::Base include ::Hyrax::FileSetBehavior end -Hyrax::ValkyrieLazyMigration.migrating(Hyrax::FileSet, from: ::FileSet) if ENV.fetch('VALKYRIE_TRANSITION', false) +Hyrax::ValkyrieLazyMigration.migrating(Hyrax::FileSet, from: ::FileSet) if Hyrax.config.valkyrie_transition? diff --git a/.dassie/config/initializers/hyrax.rb b/.dassie/config/initializers/hyrax.rb index 4fbca6976f..9f23ce6ba0 100644 --- a/.dassie/config/initializers/hyrax.rb +++ b/.dassie/config/initializers/hyrax.rb @@ -68,7 +68,7 @@ # dassie needs legacy AF models # If using Frayja/Frigg then use the resource they provide - if ENV.fetch('VALKYRIE_TRANSITION', false) + if Hyrax.config.valkyrie_transition? config.collection_model = 'CollectionResource' config.admin_set_model = 'AdminSetResource' config.file_set_model = 'Hyrax::FileSet' diff --git a/.dassie/config/initializers/wings.rb b/.dassie/config/initializers/wings.rb index 247735bd23..9b6d1eaa40 100644 --- a/.dassie/config/initializers/wings.rb +++ b/.dassie/config/initializers/wings.rb @@ -2,7 +2,7 @@ # rubocop:disable Metrics/BlockLength # Freyja setup adapted from hyku -if ENV.fetch('VALKYRIE_TRANSITION', false) +if Hyrax.config.valkyrie_transition? Rails.application.config.after_initialize do [ # List AF work models GenericWork diff --git a/lib/hyrax/configuration.rb b/lib/hyrax/configuration.rb index 88ec3c5f41..24c885f96e 100644 --- a/lib/hyrax/configuration.rb +++ b/lib/hyrax/configuration.rb @@ -313,6 +313,14 @@ def flexible? ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYRAX_FLEXIBLE', false)) end + # This value determines whether to use load the Freyja adapter in dassie + attr_writer :valkyrie_transition + attr_reader :valkyrie_transition + def valkyrie_transition? + @valkyrie_transition ||= + ActiveModel::Type::Boolean.new.cast(ENV.fetch('VALKYRIE_TRANSITION', false)) + end + attr_writer :max_days_between_fixity_checks def max_days_between_fixity_checks @max_days_between_fixity_checks ||= 7 From 1a32864a006e3afc3610a62aba8d5f54e71b90be Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Fri, 14 Jun 2024 13:45:32 -0700 Subject: [PATCH 23/34] Add Wings(Hyrax::Resource) to dassie m3 --- .../config/metadata_profiles/m3_profile.yaml | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.dassie/config/metadata_profiles/m3_profile.yaml b/.dassie/config/metadata_profiles/m3_profile.yaml index 34e5c26b18..c604814d24 100644 --- a/.dassie/config/metadata_profiles/m3_profile.yaml +++ b/.dassie/config/metadata_profiles/m3_profile.yaml @@ -11,6 +11,8 @@ classes: display_label: Generic Work GenericWorkResource: display_label: Generic Work + Wings(Hyrax::Resource): + display_label: Wings Resource Monograph: display_label: Monograph AdminSet: @@ -46,6 +48,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork cardinality: minimum: 1 @@ -86,6 +89,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork cardinality: minimum: 0 @@ -105,6 +109,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork cardinality: minimum: 0 @@ -124,6 +129,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork cardinality: minimum: 0 @@ -148,6 +154,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -176,6 +183,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -203,6 +211,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -229,6 +238,7 @@ properties: class: - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -255,6 +265,7 @@ properties: class: - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -281,6 +292,7 @@ properties: class: - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -305,6 +317,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -331,6 +344,7 @@ properties: class: - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -358,6 +372,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -385,6 +400,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -413,6 +429,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -440,6 +457,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -466,6 +484,7 @@ properties: class: - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -488,6 +507,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -516,6 +536,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -544,6 +565,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -572,6 +594,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -599,6 +622,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -626,6 +650,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -648,6 +673,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -676,6 +702,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -703,6 +730,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -730,6 +758,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: @@ -758,6 +787,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWorkResource + - Wings(Hyrax::Resource) - GenericWork - Monograph cardinality: From 44b75f9656cd610a34707af97a9aa7ba9158831b Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 17 Jun 2024 11:17:05 -0700 Subject: [PATCH 24/34] Update specs --- .../metadata_profiles/sample_attribute.yaml | 19 ++++ .../metadata_profiles/sample_attribute.yaml | 19 ++++ app/models/hyrax/flexible_schema.rb | 1 + app/services/hyrax/schema_loader.rb | 12 +- spec/hyrax/schema_spec.rb | 20 +++- spec/models/hyrax/resource_spec.rb | 33 +++--- spec/services/hyrax/m3_schema_loader_spec.rb | 39 ++++--- spec/services/hyrax/schema_loader_spec.rb | 105 ++++++++++++++++++ 8 files changed, 210 insertions(+), 38 deletions(-) create mode 100644 .dassie/config/metadata_profiles/sample_attribute.yaml create mode 100644 .koppie/config/metadata_profiles/sample_attribute.yaml create mode 100644 spec/services/hyrax/schema_loader_spec.rb diff --git a/.dassie/config/metadata_profiles/sample_attribute.yaml b/.dassie/config/metadata_profiles/sample_attribute.yaml new file mode 100644 index 0000000000..bc7e6883d8 --- /dev/null +++ b/.dassie/config/metadata_profiles/sample_attribute.yaml @@ -0,0 +1,19 @@ +properties: + sample_attribute: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Sample Attribute + property_uri: http://hyrax-example.com/sample_attribute + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Sample Attribute diff --git a/.koppie/config/metadata_profiles/sample_attribute.yaml b/.koppie/config/metadata_profiles/sample_attribute.yaml new file mode 100644 index 0000000000..bc7e6883d8 --- /dev/null +++ b/.koppie/config/metadata_profiles/sample_attribute.yaml @@ -0,0 +1,19 @@ +properties: + sample_attribute: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Sample Attribute + property_uri: http://hyrax-example.com/sample_attribute + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Sample Attribute diff --git a/app/models/hyrax/flexible_schema.rb b/app/models/hyrax/flexible_schema.rb index 4437fc4f21..e0cef5eb2b 100644 --- a/app/models/hyrax/flexible_schema.rb +++ b/app/models/hyrax/flexible_schema.rb @@ -30,6 +30,7 @@ def class_names def values_map(values) values['type'] = lookup_type(values['range']) + values['form']&.transform_keys!('multi_value' => 'multiple') values['predicate'] = values['property_uri'] values['index_keys'] = values['indexing'] values['multiple'] = values['multi_value'] diff --git a/app/services/hyrax/schema_loader.rb b/app/services/hyrax/schema_loader.rb index df694fb439..a7d2e04b67 100644 --- a/app/services/hyrax/schema_loader.rb +++ b/app/services/hyrax/schema_loader.rb @@ -121,11 +121,21 @@ def type_for(type) when 'date_time' Valkyrie::Types::DateTime else - "Valkyrie::Types::#{type.capitalize}".constantize + begin + "Valkyrie::Types::#{type.capitalize}".constantize + rescue NameError + raise ArgumentError, "Unrecognized type: #{type}" + end end end end class UndefinedSchemaError < ArgumentError; end + + private + + def definitions(_schema_name, _version) + raise NotImplementedError, 'Implement #definitions in a child class' + end end end diff --git a/spec/hyrax/schema_spec.rb b/spec/hyrax/schema_spec.rb index 855cbbd0d8..ca1baf3977 100644 --- a/spec/hyrax/schema_spec.rb +++ b/spec/hyrax/schema_spec.rb @@ -12,7 +12,7 @@ class Resource < Hyrax::Resource; end Hyrax::Test::Schema::Resource end - after { Hyrax::Test.send(:remove_const, :Schema) } + after { Hyrax::Test.send(:remove_const, :Schema) if defined?(Hyrax::Test::Schema) } describe 'including' do it 'applies the specified schema' do @@ -96,4 +96,22 @@ class Resource < Hyrax::Resource; end expect(saved[:date_created].map { |t| DateTime.parse(t.to_s).strftime("%FT%R") }).to match_array(times_parsed) end end + + describe '.default_schema_loader' do + context 'when using flexible metadata' do + it 'returns an M3SchemaLoader' do + allow(Hyrax.config).to receive(:flexible?).and_return(true) + + expect(described_class.default_schema_loader).to be_a(Hyrax::M3SchemaLoader) + end + end + + context 'when not using flexible metadata' do + it 'returns a SimpleSchemaLoader' do + allow(Hyrax.config).to receive(:flexible?).and_return(false) + + expect(described_class.default_schema_loader).to be_a(Hyrax::SimpleSchemaLoader) + end + end + end end diff --git a/spec/models/hyrax/resource_spec.rb b/spec/models/hyrax/resource_spec.rb index 2fa2c237cf..ad9982d968 100644 --- a/spec/models/hyrax/resource_spec.rb +++ b/spec/models/hyrax/resource_spec.rb @@ -9,37 +9,28 @@ it_behaves_like 'a Hyrax::Resource' - before do - @hyrax_flexible_env_var = ENV['HYRAX_FLEXIBLE'] - end - - after do - ENV.delete('HYRAX_FLEXIBLE') - end - + # Hyrax::Resource was loading earlier than the `allow(Hyrax.config).to receive(:flexible?)` line, + # so we remove it and load it again in order for the allow to take effect def load_resource_model Hyrax.send(:remove_const, :Resource) if defined?(Hyrax::Resource) - load File.join('/app/samvera/hyrax-engine/app/models/hyrax/resource.rb') + load Hyrax::Engine.root.join('app', 'models', 'hyrax', 'resource.rb') end - context 'when HYRAX_FLEXIBLE environment variable is set' do - before do - ENV['HYRAX_FLEXIBLE'] = 'true' - load_resource_model - end + before { load_resource_model } + context 'when using flexible metadata' do it 'includes the Hyrax::Flexibility module' do + allow(Hyrax.config).to receive(:flexible?).and_return(true) + load_resource_model + expect(Hyrax::Resource.included_modules).to include(Hyrax::Flexibility) end end - context 'when HYRAX_FLEXIBLE environment variable is not set' do - before do - ENV.delete('HYRAX_FLEXIBLE') - load_resource_model - end - + context 'when not using flexible metadata' do it 'does not include the Hyrax::Flexibility module' do + allow(Hyrax.config).to receive(:flexible?).and_return(false) + expect(Hyrax::Resource.included_modules).not_to include(Hyrax::Flexibility) end end @@ -55,6 +46,7 @@ def load_resource_model let(:embargo) { FactoryBot.create(:hyrax_embargo) } it 'saves the embargo id' do + # load_resource_model resource.embargo = Hyrax.persister.save(resource: embargo) expect(Hyrax.persister.save(resource: resource).embargo) @@ -67,6 +59,7 @@ def load_resource_model let(:lease) { FactoryBot.build(:hyrax_lease) } it 'saves the lease id' do + # load_resource_model resource.lease = Hyrax.persister.save(resource: lease) expect(Hyrax.persister.save(resource: resource).lease) diff --git a/spec/services/hyrax/m3_schema_loader_spec.rb b/spec/services/hyrax/m3_schema_loader_spec.rb index 9c8b900dd3..77fe4b2399 100644 --- a/spec/services/hyrax/m3_schema_loader_spec.rb +++ b/spec/services/hyrax/m3_schema_loader_spec.rb @@ -4,16 +4,27 @@ RSpec.describe Hyrax::M3SchemaLoader do subject(:schema_loader) { described_class.new } + let(:profile) { YAML.safe_load_file(Hyrax::Engine.root.join('spec', 'fixtures', 'files', 'm3_profile.yaml')) } + let(:schema) do + Hyrax::FlexibleSchema.create( + profile: profile + ) + end + + before do + allow(Hyrax.config).to receive(:flexible?).and_return(true) + allow(Hyrax::FlexibleSchema).to receive(:find).and_return(schema) + end describe '#attributes_for' do it 'provides an attributes hash' do - expect(schema_loader.attributes_for(schema: :core_metadata)) + expect(schema_loader.attributes_for(schema: Monograph.to_s)) .to include(title: Valkyrie::Types::Array.of(Valkyrie::Types::String), depositor: Valkyrie::Types::String) end it 'provides access to attribute metadata' do - expect(schema_loader.attributes_for(schema: :core_metadata)[:title].meta) + expect(schema_loader.attributes_for(schema: Monograph.to_s)[:title].meta) .to include({ "type" => "string", "form" => { "multiple" => true, "primary" => true, "required" => true }, "index_keys" => ["title_sim", "title_tesim"], @@ -22,8 +33,15 @@ end context 'with generated resource' do + let(:sample_attribute) { YAML.safe_load_file(Rails.root.join('config', 'metadata_profiles', 'sample_attribute.yaml')) } + let(:schema) do + Hyrax::FlexibleSchema.create( + profile: profile.deep_merge(sample_attribute) + ) + end + it 'provides an attributes hash' do - expect(schema_loader.attributes_for(schema: :sample_metadata)) + expect(schema_loader.attributes_for(schema: Monograph.to_s)) .to include(sample_attribute: Valkyrie::Types::Array.of(Valkyrie::Types::String)) end end @@ -36,25 +54,14 @@ describe '#index_rules_for' do it 'provides index configuration' do - expect(schema_loader.index_rules_for(schema: :core_metadata)).to include(title_sim: :title, title_tesim: :title) + expect(schema_loader.index_rules_for(schema: Monograph.to_s)).to include(title_sim: :title, title_tesim: :title) end end describe '#form_definitions_for' do it 'provides form configuration' do - expect(schema_loader.form_definitions_for(schema: :core_metadata)) + expect(schema_loader.form_definitions_for(schema: Monograph.to_s)) .to eq(title: { required: true, primary: true, multiple: true }) end end - - describe '#permissive_schema_for_valkrie_adapter' do - let(:permissive_schema) { schema_loader.permissive_schema_for_valkrie_adapter } - - it 'provides the expected hash' do - expect(permissive_schema.size).to eq(66) - expect(permissive_schema.values.all? { |v| v.is_a? RDF::URI }).to be_truthy - expect(permissive_schema.values.all? { |v| v.value.present? }).to be_truthy - expect(permissive_schema[:sample_attribute].value).to eq("http://hyrax-example.com/sample_attribute") - end - end end diff --git a/spec/services/hyrax/schema_loader_spec.rb b/spec/services/hyrax/schema_loader_spec.rb new file mode 100644 index 0000000000..139986d18b --- /dev/null +++ b/spec/services/hyrax/schema_loader_spec.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Hyrax::SchemaLoader do + subject(:schema_loader) { described_class.new } + + describe '#definitions' do + it 'raises NotImplementedError' do + expect { schema_loader.send(:definitions, :some_schema, 1) } + .to raise_error(NotImplementedError, 'Implement #definitions in a child class') + end + end +end + +RSpec.describe Hyrax::SchemaLoader::AttributeDefinition do + subject(:attribute_definition) { described_class.new(name, config) } + + let(:name) { 'title' } + let(:config) do + { 'type' => 'string', + 'form' => { 'multiple' => true, 'primary' => true, 'required' => true }, + 'index_keys' => ['title_sim', 'title_tesim'], + 'multiple' => true, + 'predicate' => 'http://purl.org/dc/terms/title' } + end + + describe '#form_options' do + it 'returns form options as a symbolized hash' do + expect(attribute_definition.form_options).to eq(multiple: true, primary: true, required: true) + end + + context 'when form options are missing' do + let(:config) { { 'type' => 'string' } } + + it 'returns an empty hash' do + expect(attribute_definition.form_options).to eq({}) + end + end + end + + describe '#index_keys' do + it 'returns index keys as symbols' do + expect(attribute_definition.index_keys).to eq([:title_sim, :title_tesim]) + end + + context 'when index keys are missing' do + let(:config) { { 'type' => 'string' } } + + it 'returns an empty array' do + expect(attribute_definition.index_keys).to eq([]) + end + end + end + + describe '#type' do + context 'when multiple is true' do + it 'returns a Valkyrie array type' do + expect(attribute_definition.type).to be_a(Dry::Types::Constructor) + expect(attribute_definition.type.to_s).to include('Array') + expect(attribute_definition.type.member).to eq(Valkyrie::Types::String) + end + end + + context 'when multiple is false' do + let(:config) { { 'type' => 'string', 'multiple' => false } } + + it 'returns a Valkyrie string type' do + expect(attribute_definition.type).to eq(Valkyrie::Types::String) + end + end + + context 'when type is id' do + let(:config) { { 'type' => 'id' } } + + it 'returns a Valkyrie ID type' do + expect(attribute_definition.type).to eq(Valkyrie::Types::ID) + end + end + + context 'when type is uri' do + let(:config) { { 'type' => 'uri' } } + + it 'returns a Valkyrie URI type' do + expect(attribute_definition.type).to eq(Valkyrie::Types::URI) + end + end + + context 'when type is date_time' do + let(:config) { { 'type' => 'date_time' } } + + it 'returns a Valkyrie DateTime type' do + expect(attribute_definition.type).to eq(Valkyrie::Types::DateTime) + end + end + + context 'when type is not recognized' do + let(:config) { { 'type' => 'custom' } } + + it 'raises an ArgumentError' do + expect { attribute_definition.type }.to raise_error(ArgumentError, 'Unrecognized type: custom') + end + end + end +end From 7d8710024013589cc8ed33d4ae564380f47c008a Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 17 Jun 2024 13:54:25 -0700 Subject: [PATCH 25/34] Add back nil guard in SolrDocumentBehavior --- app/models/concerns/hyrax/solr_document_behavior.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/hyrax/solr_document_behavior.rb b/app/models/concerns/hyrax/solr_document_behavior.rb index 2c3ad4b274..7cb16271e6 100644 --- a/app/models/concerns/hyrax/solr_document_behavior.rb +++ b/app/models/concerns/hyrax/solr_document_behavior.rb @@ -82,7 +82,7 @@ def valkyrie? # Method to return the model def hydra_model(classifier: nil) - (first('has_model_ssim') + 'Resource')&.safe_constantize || + (first('has_model_ssim')&.+ 'Resource')&.safe_constantize || first('has_model_ssim')&.safe_constantize || model_classifier(classifier).classifier(self).best_model end From 282709e8bce43716a43ec123770b02db4cce6ffe Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 17 Jun 2024 17:09:22 -0700 Subject: [PATCH 26/34] Move sample_attribute.yaml to fixtures --- .../metadata_profiles/sample_attribute.yaml | 19 ------------------- .../fixtures/files}/sample_attribute.yaml | 0 spec/services/hyrax/m3_schema_loader_spec.rb | 2 +- 3 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 .koppie/config/metadata_profiles/sample_attribute.yaml rename {.dassie/config/metadata_profiles => spec/fixtures/files}/sample_attribute.yaml (100%) diff --git a/.koppie/config/metadata_profiles/sample_attribute.yaml b/.koppie/config/metadata_profiles/sample_attribute.yaml deleted file mode 100644 index bc7e6883d8..0000000000 --- a/.koppie/config/metadata_profiles/sample_attribute.yaml +++ /dev/null @@ -1,19 +0,0 @@ -properties: - sample_attribute: - available_on: - class: - - Monograph - cardinality: - minimum: 0 - maximum: 1 - multi_value: false - controlled_values: - format: http://www.w3.org/2001/XMLSchema#string - sources: - - 'null' - display_label: - default: Sample Attribute - property_uri: http://hyrax-example.com/sample_attribute - range: http://www.w3.org/2001/XMLSchema#string - sample_values: - - Example Sample Attribute diff --git a/.dassie/config/metadata_profiles/sample_attribute.yaml b/spec/fixtures/files/sample_attribute.yaml similarity index 100% rename from .dassie/config/metadata_profiles/sample_attribute.yaml rename to spec/fixtures/files/sample_attribute.yaml diff --git a/spec/services/hyrax/m3_schema_loader_spec.rb b/spec/services/hyrax/m3_schema_loader_spec.rb index 77fe4b2399..57b383fb22 100644 --- a/spec/services/hyrax/m3_schema_loader_spec.rb +++ b/spec/services/hyrax/m3_schema_loader_spec.rb @@ -33,7 +33,7 @@ end context 'with generated resource' do - let(:sample_attribute) { YAML.safe_load_file(Rails.root.join('config', 'metadata_profiles', 'sample_attribute.yaml')) } + let(:sample_attribute) { YAML.safe_load_file(Hyrax::Engine.root.join('spec', 'fixtures', 'files', 'sample_attribute.yaml')) } let(:schema) do Hyrax::FlexibleSchema.create( profile: profile.deep_merge(sample_attribute) From 4f0688004ce5a4814a371c2a4cb42474141f26a6 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 18 Jun 2024 13:45:58 -0700 Subject: [PATCH 27/34] Add some tests for Hyrax::Flexibility --- .../models/concerns/hyrax/flexibility_spec.rb | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 spec/models/concerns/hyrax/flexibility_spec.rb diff --git a/spec/models/concerns/hyrax/flexibility_spec.rb b/spec/models/concerns/hyrax/flexibility_spec.rb new file mode 100644 index 0000000000..7c13917dcb --- /dev/null +++ b/spec/models/concerns/hyrax/flexibility_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Hyrax::Flexibility' do + subject(:flexibility_class) { Hyrax::Test::Flexibility::TestWork } + let(:schema) { Hyrax::FlexibleSchema.create(profile: profile.deep_merge(test_work_profile)) } + let(:profile) { YAML.safe_load_file(Hyrax::Engine.root.join('spec', 'fixtures', 'files', 'm3_profile.yaml')) } + let(:test_work_profile) do + YAML.safe_load(<<-YAML) + classes: + Hyrax::Test::Flexibility::TestWork: + display_label: Test Work + properties: + title: + available_on: + class: + - Hyrax::Test::Flexibility::TestWork + YAML + end + + before do + allow(Hyrax.config).to receive(:flexible?).and_return(true) + allow(Hyrax::FlexibleSchema).to receive(:find).and_return(schema) + + module Hyrax::Test::Flexibility + class TestWork < Hyrax::Resource + include Hyrax::Flexibility if Hyrax.config.flexible? + end + end + end + + after do + Hyrax::Test::Flexibility.send(:remove_const, :TestWork) + allow(Hyrax.config).to receive(:flexible?).and_return(false) + end + + its(:included_modules) { is_expected.to include(Hyrax::Flexibility) } + + describe '#schema_version' do + let(:flexibility_instance) { flexibility_class.new } + + it 'responds to #schema_version' do + expect(flexibility_instance).to respond_to(:schema_version) + end + end + + describe '.attributes' do + let(:flexibility_instance) { flexibility_class.new } + + it 'defines the attribute setter methods' do + expect(flexibility_instance).to respond_to(:title=) + end + end + + describe '.new' do + context 'when attributes is a Struct' do + it 'creates a new instance with attributes converted to a hash' do + new_instance = flexibility_class.new(Struct.new(:title).new(['Test Title'])) + expect(new_instance.title).to eq(['Test Title']) + end + end + + context 'when attributes is a hash' do + it 'loads the attributes' do + instance = flexibility_class.new(title: ['Test Title']) + expect(instance.title).to eq(['Test Title']) + end + end + end +end From 4275dbce53f44f336ac2964bf3f02b3bfa1c3d9a Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 18 Jun 2024 20:54:26 -0700 Subject: [PATCH 28/34] Revert resource_spec and remove sample_attribute --- spec/fixtures/files/sample_attribute.yaml | 19 --------------- spec/models/hyrax/resource_spec.rb | 28 ----------------------- 2 files changed, 47 deletions(-) delete mode 100644 spec/fixtures/files/sample_attribute.yaml diff --git a/spec/fixtures/files/sample_attribute.yaml b/spec/fixtures/files/sample_attribute.yaml deleted file mode 100644 index bc7e6883d8..0000000000 --- a/spec/fixtures/files/sample_attribute.yaml +++ /dev/null @@ -1,19 +0,0 @@ -properties: - sample_attribute: - available_on: - class: - - Monograph - cardinality: - minimum: 0 - maximum: 1 - multi_value: false - controlled_values: - format: http://www.w3.org/2001/XMLSchema#string - sources: - - 'null' - display_label: - default: Sample Attribute - property_uri: http://hyrax-example.com/sample_attribute - range: http://www.w3.org/2001/XMLSchema#string - sample_values: - - Example Sample Attribute diff --git a/spec/models/hyrax/resource_spec.rb b/spec/models/hyrax/resource_spec.rb index ad9982d968..f1543d4b17 100644 --- a/spec/models/hyrax/resource_spec.rb +++ b/spec/models/hyrax/resource_spec.rb @@ -9,32 +9,6 @@ it_behaves_like 'a Hyrax::Resource' - # Hyrax::Resource was loading earlier than the `allow(Hyrax.config).to receive(:flexible?)` line, - # so we remove it and load it again in order for the allow to take effect - def load_resource_model - Hyrax.send(:remove_const, :Resource) if defined?(Hyrax::Resource) - load Hyrax::Engine.root.join('app', 'models', 'hyrax', 'resource.rb') - end - - before { load_resource_model } - - context 'when using flexible metadata' do - it 'includes the Hyrax::Flexibility module' do - allow(Hyrax.config).to receive(:flexible?).and_return(true) - load_resource_model - - expect(Hyrax::Resource.included_modules).to include(Hyrax::Flexibility) - end - end - - context 'when not using flexible metadata' do - it 'does not include the Hyrax::Flexibility module' do - allow(Hyrax.config).to receive(:flexible?).and_return(false) - - expect(Hyrax::Resource.included_modules).not_to include(Hyrax::Flexibility) - end - end - describe '#events' do it 'includes Hyrax::WithEvents' do expect(resource).to respond_to(:events) @@ -46,7 +20,6 @@ def load_resource_model let(:embargo) { FactoryBot.create(:hyrax_embargo) } it 'saves the embargo id' do - # load_resource_model resource.embargo = Hyrax.persister.save(resource: embargo) expect(Hyrax.persister.save(resource: resource).embargo) @@ -59,7 +32,6 @@ def load_resource_model let(:lease) { FactoryBot.build(:hyrax_lease) } it 'saves the lease id' do - # load_resource_model resource.lease = Hyrax.persister.save(resource: lease) expect(Hyrax.persister.save(resource: resource).lease) From 258a2e761e3edc7e4813d9d915a17326dea43875 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 18 Jun 2024 22:04:10 -0700 Subject: [PATCH 29/34] Fix m3_schema_loader_spec and format inline YAML --- .../models/concerns/hyrax/flexibility_spec.rb | 16 ++++++------- spec/services/hyrax/m3_schema_loader_spec.rb | 24 ++++++++++++++++++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/spec/models/concerns/hyrax/flexibility_spec.rb b/spec/models/concerns/hyrax/flexibility_spec.rb index 7c13917dcb..85c2f49bfe 100644 --- a/spec/models/concerns/hyrax/flexibility_spec.rb +++ b/spec/models/concerns/hyrax/flexibility_spec.rb @@ -8,14 +8,14 @@ let(:profile) { YAML.safe_load_file(Hyrax::Engine.root.join('spec', 'fixtures', 'files', 'm3_profile.yaml')) } let(:test_work_profile) do YAML.safe_load(<<-YAML) - classes: - Hyrax::Test::Flexibility::TestWork: - display_label: Test Work - properties: - title: - available_on: - class: - - Hyrax::Test::Flexibility::TestWork + classes: + Hyrax::Test::Flexibility::TestWork: + display_label: Test Work + properties: + title: + available_on: + class: + - Hyrax::Test::Flexibility::TestWork YAML end diff --git a/spec/services/hyrax/m3_schema_loader_spec.rb b/spec/services/hyrax/m3_schema_loader_spec.rb index 57b383fb22..1c626c5035 100644 --- a/spec/services/hyrax/m3_schema_loader_spec.rb +++ b/spec/services/hyrax/m3_schema_loader_spec.rb @@ -33,7 +33,29 @@ end context 'with generated resource' do - let(:sample_attribute) { YAML.safe_load_file(Hyrax::Engine.root.join('spec', 'fixtures', 'files', 'sample_attribute.yaml')) } + let(:sample_attribute) do + YAML.safe_load(<<-YAML) + properties: + sample_attribute: + available_on: + class: + - Monograph + cardinality: + minimum: 0 + maximum: 1 + multi_value: false + controlled_values: + format: http://www.w3.org/2001/XMLSchema#string + sources: + - 'null' + display_label: + default: Sample Attribute + property_uri: http://hyrax-example.com/sample_attribute + range: http://www.w3.org/2001/XMLSchema#string + sample_values: + - Example Sample Attribute + YAML + end let(:schema) do Hyrax::FlexibleSchema.create( profile: profile.deep_merge(sample_attribute) From 77c665c5af9dcc75d3f5864041efc1798e231f86 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Mon, 24 Jun 2024 16:59:46 -0700 Subject: [PATCH 30/34] make sure attributes defined in code are kept too --- app/models/concerns/hyrax/flexibility.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/hyrax/flexibility.rb b/app/models/concerns/hyrax/flexibility.rb index 3dfa2675ee..e1d580bf92 100644 --- a/app/models/concerns/hyrax/flexibility.rb +++ b/app/models/concerns/hyrax/flexibility.rb @@ -11,7 +11,7 @@ module Flexibility ## Override dry-struct 1.6.0 to enable redefining schemas on the fly def attributes(new_schema) keys = new_schema.keys.map { |k| k.to_s.chomp("?").to_sym } - schema Hyrax::Resource.schema.schema(new_schema) + schema self.schema.schema(new_schema) define_accessors(keys) From 2fb4906a38624fb0fb1db4e5c27150d23e2c77dc Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Mon, 24 Jun 2024 17:15:18 -0700 Subject: [PATCH 31/34] smarter schema reservation and fix some new indexers --- .dassie/app/indexers/generic_work_resource_indexer.rb | 4 ++-- app/models/concerns/hyrax/flexibility.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.dassie/app/indexers/generic_work_resource_indexer.rb b/.dassie/app/indexers/generic_work_resource_indexer.rb index 7598e2a597..d4251f64af 100644 --- a/.dassie/app/indexers/generic_work_resource_indexer.rb +++ b/.dassie/app/indexers/generic_work_resource_indexer.rb @@ -3,8 +3,8 @@ # Generated via # `rails generate hyrax:work_resource GenericWorkResource` class GenericWorkResourceIndexer < Hyrax::ValkyrieWorkIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:generic_work_resource) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:generic_work_resource) unless Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/app/models/concerns/hyrax/flexibility.rb b/app/models/concerns/hyrax/flexibility.rb index e1d580bf92..1f96672f5b 100644 --- a/app/models/concerns/hyrax/flexibility.rb +++ b/app/models/concerns/hyrax/flexibility.rb @@ -11,7 +11,8 @@ module Flexibility ## Override dry-struct 1.6.0 to enable redefining schemas on the fly def attributes(new_schema) keys = new_schema.keys.map { |k| k.to_s.chomp("?").to_sym } - schema self.schema.schema(new_schema) + schema_location = singleton_class? ? self.superclass : self + schema schema_location.schema.schema(new_schema) define_accessors(keys) From 6bd4caceea884ba7bfa65df8060f971eb683f226 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Mon, 24 Jun 2024 21:32:21 -0700 Subject: [PATCH 32/34] Update flexible_schema.rb --- app/models/hyrax/flexible_schema.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/hyrax/flexible_schema.rb b/app/models/hyrax/flexible_schema.rb index e0cef5eb2b..5ab42e5e94 100644 --- a/app/models/hyrax/flexible_schema.rb +++ b/app/models/hyrax/flexible_schema.rb @@ -28,6 +28,7 @@ def class_names @class_names end + private def values_map(values) values['type'] = lookup_type(values['range']) values['form']&.transform_keys!('multi_value' => 'multiple') From e455106ee429724462fc02b3f4d0bafc200bf0a9 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Mon, 24 Jun 2024 21:46:20 -0700 Subject: [PATCH 33/34] sigh --- app/models/hyrax/flexible_schema.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/hyrax/flexible_schema.rb b/app/models/hyrax/flexible_schema.rb index 5ab42e5e94..e0cef5eb2b 100644 --- a/app/models/hyrax/flexible_schema.rb +++ b/app/models/hyrax/flexible_schema.rb @@ -28,7 +28,6 @@ def class_names @class_names end - private def values_map(values) values['type'] = lookup_type(values['range']) values['form']&.transform_keys!('multi_value' => 'multiple') From 857f57911639aed47c0888cd5689123d58b0a3e5 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Thu, 27 Jun 2024 14:19:56 -0400 Subject: [PATCH 34/34] Load the indexer module for flexible metadata Configures dassie, koppie, hyrax app, and generators for flexible metadata indexing to occur. --- .dassie/app/indexers/collection_resource_indexer.rb | 5 +++-- .dassie/app/indexers/generic_work_resource_indexer.rb | 1 + .dassie/app/indexers/monograph_indexer.rb | 5 +++-- .koppie/app/indexers/collection_resource_indexer.rb | 5 +++-- .koppie/app/indexers/generic_work_indexer.rb | 5 +++-- .koppie/app/indexers/monograph_indexer.rb | 5 +++-- app/indexers/hyrax/indexers/administrative_set_indexer.rb | 1 + app/indexers/hyrax/indexers/file_set_indexer.rb | 1 + app/indexers/hyrax/indexers/pcdm_collection_indexer.rb | 1 + .../collection_resource/templates/collection_indexer.rb.erb | 1 + lib/generators/hyrax/work_resource/templates/indexer.rb.erb | 1 + lib/hyrax/indexer.rb | 1 + 12 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.dassie/app/indexers/collection_resource_indexer.rb b/.dassie/app/indexers/collection_resource_indexer.rb index c8dd88b84e..76a4ace871 100644 --- a/.dassie/app/indexers/collection_resource_indexer.rb +++ b/.dassie/app/indexers/collection_resource_indexer.rb @@ -3,6 +3,7 @@ # Generated via # `rails generate hyrax:collection_resource CollectionResource` class CollectionResourceIndexer < Hyrax::PcdmCollectionIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:collection_resource) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:collection_resource) unless Hyrax.config.flexible? + include Hyrax::Indexer('CollectionResource') if Hyrax.config.flexible? end diff --git a/.dassie/app/indexers/generic_work_resource_indexer.rb b/.dassie/app/indexers/generic_work_resource_indexer.rb index d4251f64af..6fb90b0083 100644 --- a/.dassie/app/indexers/generic_work_resource_indexer.rb +++ b/.dassie/app/indexers/generic_work_resource_indexer.rb @@ -5,6 +5,7 @@ class GenericWorkResourceIndexer < Hyrax::ValkyrieWorkIndexer include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? include Hyrax::Indexer(:generic_work_resource) unless Hyrax.config.flexible? + include Hyrax::Indexer('GenericWorkResource') if Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/.dassie/app/indexers/monograph_indexer.rb b/.dassie/app/indexers/monograph_indexer.rb index 73fac4e9a6..092a84a4ba 100644 --- a/.dassie/app/indexers/monograph_indexer.rb +++ b/.dassie/app/indexers/monograph_indexer.rb @@ -3,8 +3,9 @@ # Generated via # `rails generate hyrax:work_resource Monograph` class MonographIndexer < Hyrax::ValkyrieWorkIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:monograph) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:monograph) unless Hyrax.config.flexible? + include Hyrax::Indexer('Monograph') if Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/.koppie/app/indexers/collection_resource_indexer.rb b/.koppie/app/indexers/collection_resource_indexer.rb index c8dd88b84e..76a4ace871 100644 --- a/.koppie/app/indexers/collection_resource_indexer.rb +++ b/.koppie/app/indexers/collection_resource_indexer.rb @@ -3,6 +3,7 @@ # Generated via # `rails generate hyrax:collection_resource CollectionResource` class CollectionResourceIndexer < Hyrax::PcdmCollectionIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:collection_resource) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:collection_resource) unless Hyrax.config.flexible? + include Hyrax::Indexer('CollectionResource') if Hyrax.config.flexible? end diff --git a/.koppie/app/indexers/generic_work_indexer.rb b/.koppie/app/indexers/generic_work_indexer.rb index c71c28b6b3..27345aecaf 100644 --- a/.koppie/app/indexers/generic_work_indexer.rb +++ b/.koppie/app/indexers/generic_work_indexer.rb @@ -3,8 +3,9 @@ # Generated via # `rails generate hyrax:work_resource GenericWork` class GenericWorkIndexer < Hyrax::ValkyrieWorkIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:generic_work) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:generic_work) unless Hyrax.config.flexible? + include Hyrax::Indexer('GenericWork') if Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/.koppie/app/indexers/monograph_indexer.rb b/.koppie/app/indexers/monograph_indexer.rb index 73fac4e9a6..092a84a4ba 100644 --- a/.koppie/app/indexers/monograph_indexer.rb +++ b/.koppie/app/indexers/monograph_indexer.rb @@ -3,8 +3,9 @@ # Generated via # `rails generate hyrax:work_resource Monograph` class MonographIndexer < Hyrax::ValkyrieWorkIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:monograph) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:monograph) unless Hyrax.config.flexible? + include Hyrax::Indexer('Monograph') if Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/app/indexers/hyrax/indexers/administrative_set_indexer.rb b/app/indexers/hyrax/indexers/administrative_set_indexer.rb index 575842ee4b..5c69a8e589 100644 --- a/app/indexers/hyrax/indexers/administrative_set_indexer.rb +++ b/app/indexers/hyrax/indexers/administrative_set_indexer.rb @@ -8,6 +8,7 @@ class AdministrativeSetIndexer < Hyrax::Indexers::ResourceIndexer include Hyrax::PermissionIndexer include Hyrax::VisibilityIndexer include Hyrax::Indexer(:core_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer('Hyrax::AdministrativeSet') if Hyrax.config.flexible? def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength super.tap do |solr_doc| diff --git a/app/indexers/hyrax/indexers/file_set_indexer.rb b/app/indexers/hyrax/indexers/file_set_indexer.rb index 80d053c24c..5862e2d32a 100644 --- a/app/indexers/hyrax/indexers/file_set_indexer.rb +++ b/app/indexers/hyrax/indexers/file_set_indexer.rb @@ -10,6 +10,7 @@ class FileSetIndexer < Hyrax::Indexers::ResourceIndexer # rubocop:disable Metric include Hyrax::ThumbnailIndexer include Hyrax::Indexer(:core_metadata) unless Hyrax.config.flexible? include Hyrax::Indexer(:file_set_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer('Hyrax::FileSet') if Hyrax.config.flexible? def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity super.tap do |solr_doc| # rubocop:disable Metrics/BlockLength diff --git a/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb b/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb index e33cf54e55..deb9e52338 100644 --- a/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb +++ b/app/indexers/hyrax/indexers/pcdm_collection_indexer.rb @@ -10,6 +10,7 @@ class PcdmCollectionIndexer < Hyrax::Indexers::ResourceIndexer include Hyrax::LocationIndexer include Hyrax::ThumbnailIndexer include Hyrax::Indexer(:core_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer('Hyrax::PcdmCollection') if Hyrax.config.flexible? self.thumbnail_path_service = CollectionThumbnailPathService diff --git a/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb b/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb index c85cba5054..1715502ebd 100644 --- a/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb +++ b/lib/generators/hyrax/collection_resource/templates/collection_indexer.rb.erb @@ -4,4 +4,5 @@ # `rails generate hyrax:collection_resource <%= class_name %>` class <%= class_name %>Indexer < Hyrax::Indexers::PcdmCollectionIndexer include Hyrax::Indexer(:<%= file_name %>) unless Hyrax.config.flexible? + include Hyrax::Indexer('<%= class_name %>') if Hyrax.config.flexible? end diff --git a/lib/generators/hyrax/work_resource/templates/indexer.rb.erb b/lib/generators/hyrax/work_resource/templates/indexer.rb.erb index 1514165664..626cdac9d6 100644 --- a/lib/generators/hyrax/work_resource/templates/indexer.rb.erb +++ b/lib/generators/hyrax/work_resource/templates/indexer.rb.erb @@ -5,6 +5,7 @@ class <%= class_name %>Indexer < Hyrax::Indexers::PcdmObjectIndexer(<%= class_name %>) include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? include Hyrax::Indexer(:<%= file_name %>) unless Hyrax.config.flexible? + include Hyrax::Indexer('<%= class_name %>') if Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/lib/hyrax/indexer.rb b/lib/hyrax/indexer.rb index 508ef09ebd..7851bd39bd 100644 --- a/lib/hyrax/indexer.rb +++ b/lib/hyrax/indexer.rb @@ -37,6 +37,7 @@ def initialize(rules) Hyrax::Schema.default_schema_loader.index_rules_for(schema: resource.class.to_s, version: resource.schema_version).each do |index_key, method| document[index_key] = resource.try(method) end + document['schema_version_ssi'] = resource.schema_version else rules.each do |index_key, method| document[index_key] = resource.try(method)