diff --git a/app/actors/hyrax/actors/collections_membership_actor.rb b/app/actors/hyrax/actors/collections_membership_actor.rb index b02bc00b..24b09ff4 100644 --- a/app/actors/hyrax/actors/collections_membership_actor.rb +++ b/app/actors/hyrax/actors/collections_membership_actor.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -# OVERRIDE Hyrax 2.9 Skips the single collection assignment logic if importing -# OVERRIDE Hyrax 2.9 Skips permission checks if importing +# OVERRIDE Hyrax 3.5.0 Skips the single collection assignment logic if importing +# OVERRIDE Hyrax 3.5.0 Skips permission checks if importing module Hyrax module Actors @@ -18,7 +18,7 @@ class CollectionsMembershipActor < AbstractActor # @param [Hyrax::Actors::Environment] env # @return [Boolean] true if create was successful def create(env) - extract_collection_id(env) unless env.importing # OVERRIDE Hyrax 2.9 + extract_collection_id(env) unless env.importing # OVERRIDE Hyrax 3.5.0 assign_nested_attributes_for_collection(env) && next_actor.create(env) end @@ -30,148 +30,103 @@ def update(env) private - ## - # Attaches any unattached members. Deletes those that are marked _delete - # - # @param env [Hyrax::Actors::Enviornment] - # @return [Boolean] - # - def assign_nested_attributes_for_collection(env) - attributes_collection = env.attributes.delete(:member_of_collections_attributes) - - return assign_for_collection_ids(env) unless attributes_collection - - emit_deprecation if env.attributes.delete(:member_of_collection_ids) - # OVERRIDE Hyrax 2.9 - collection_id_map = attributes_collection.map { |_, attributes| attributes['id'] } - return false unless env.importing || - valid_membership?(env, collection_ids: collection_id_map) - - attributes_collection = attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes } - # checking for existing works to avoid rewriting/loading works that are already attached - existing_collections = env.curation_concern.member_of_collection_ids - boolean_type_caster = ActiveModel::Type::Boolean.new - attributes_collection.each do |attributes| - next if attributes['id'].blank? - if boolean_type_caster.cast(attributes['_destroy']) - # Likely someone in the UI sought to add the collection, then - # changed their mind and checked the "delete" checkbox and posted - # their update. - next unless existing_collections.include?(attributes['id']) - remove(env.curation_concern, attributes['id']) - else - next if existing_collections.include?(attributes['id']) - add(env, attributes['id']) - end - end - - true - end - # rubocop:enable Metrics/MethodLength, Metrics/AbcSize - # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity - - ## - # @deprecated supports old :member_of_collection_ids arguments - def emit_deprecation - Deprecation.warn(self, ':member_of_collections_attributes and :member_of_collection_ids were both ' \ - ' passed. :member_of_collection_ids is ignored when both are passed and is ' \ - 'deprecated for removal in Hyrax 3.0.') - end - - ## - # @deprecated supports old :member_of_collection_ids arguments - def assign_for_collection_ids(env) - collection_ids = env.attributes.delete(:member_of_collection_ids) - - return false unless valid_membership?(env, collection_ids: collection_ids) - - if collection_ids - Deprecation.warn(self, ':member_of_collection_ids has been deprecated for removal in Hyrax 3.0. ' \ - 'use :member_of_collections_attributes instead.') - - collection_ids = [] if collection_ids.empty? - other_collections = collections_without_edit_access(env) - - collections = ::Collection.find(collection_ids) - raise "Tried to assign collections with ids: #{collection_ids}, but none were found" unless - collections - - env.curation_concern.member_of_collections = collections - env.curation_concern.member_of_collections.concat(other_collections) - end - - true - end - - ## - # @deprecated supports old :member_of_collection_ids arguments - def collections_without_edit_access(env) - env.curation_concern.member_of_collections.select { |coll| env.current_ability.cannot?(:edit, coll) } - end - - # Adds the item to the ordered members so that it displays in the items - # along side the FileSets on the show page - def add(env, id) - collection = Collection.find(id) - collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX - - return unless env.current_ability.can?(:deposit, collection) - env.curation_concern.member_of_collections << collection - end - - # Remove the object from the members set and the ordered members list - def remove(curation_concern, id) - collection = Collection.find(id) - curation_concern.member_of_collections.delete(collection) - end - - # Extact a singleton collection id from the collection attributes and save it in env. Later in the actor stack, - # in apply_permission_template_actor.rb, `env.attributes[:collection_id]` will be used to apply the - # permissions of the collection to the created work. With one and only one collection, the work is seen as - # being created directly in that collection. The permissions will not be applied to the work if the collection - # type is configured not to allow that or if the work is being created in more than one collection. - # - # @param env [Hyrax::Actors::Enviornment] - # - # Given an array of collection_attributes when it is size: - # * 0 do not set `env.attributes[:collection_id]` - # * 1 set `env.attributes[:collection_id]` to the one and only one collection - # * 2+ do not set `env.attributes[:collection_id]` - # - # NOTE: Only called from create. All collections are being added as parents of a work. None are being removed. - def extract_collection_id(env) - attributes_collection = - env.attributes.fetch(:member_of_collections_attributes) { nil } - - if attributes_collection - # Determine if the work is being created in one and only one collection. - return unless attributes_collection && attributes_collection.size == 1 - - # Extract the collection id from attributes_collection, - collection_id = attributes_collection.first.second['id'] + ## + # Attaches any unattached members. Deletes those that are marked _delete + # + # @param env [Hyrax::Actors::Enviornment] + # @return [Boolean] + # + # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/PerceivedComplexity + # rubocop:disable Metrics/CyclomaticComplexity + def assign_nested_attributes_for_collection(env) + attributes_collection = env.attributes.delete(:member_of_collections_attributes) + return true unless attributes_collection + + # OVERRIDE Hyrax 3.5.0 to skip permission checks if importing + return false unless env.importing || + valid_membership?(env, collection_ids: attributes_collection.map { |_, attributes| attributes['id'] }) + + attributes_collection = attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes } + # checking for existing works to avoid rewriting/loading works that are already attached + existing_collections = env.curation_concern.member_of_collection_ids + boolean_type_caster = ActiveModel::Type::Boolean.new + attributes_collection.each do |attributes| + next if attributes['id'].blank? + if boolean_type_caster.cast(attributes['_destroy']) + # Likely someone in the UI sought to add the collection, then + # changed their mind and checked the "delete" checkbox and posted + # their update. + next unless existing_collections.include?(attributes['id']) + remove(env.curation_concern, attributes['id']) else - collection_ids = env.attributes.fetch(:member_of_collection_ids) { [] } - return unless collection_ids.size == 1 - collection_id = collection_ids.first + # Let's not try to add an item already + next if existing_collections.include?(attributes['id']) + add(env, attributes['id']) end + end + true + end + # rubocop:enable Metrics/MethodLength + # rubocop:enable Metrics/PerceivedComplexity + # rubocop:enable Metrics/CyclomaticComplexity + + # Adds the item to the ordered members so that it displays in the items + # along side the FileSets on the show page + def add(env, id) + collection = Hyrax.config.collection_class.find(id) + collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX) + + return unless env.current_ability.can?(:deposit, collection) + env.curation_concern.member_of_collections << collection + end - # Do not apply permissions to work if collection type is configured not to - collection = ::Collection.find(collection_id) - return unless collection.share_applies_to_new_works? + # Remove the object from the members set and the ordered members list + def remove(curation_concern, id) + collection = Hyrax.config.collection_class.find(id) + curation_concern.member_of_collections.delete(collection) + end - # Save the collection id in env for use in apply_permission_template_actor - env.attributes[:collection_id] = collection_id - end + # Extact a singleton collection id from the collection attributes and save it in env. Later in the actor stack, + # in apply_permission_template_actor.rb, `env.attributes[:collection_id]` will be used to apply the + # permissions of the collection to the created work. With one and only one collection, the work is seen as + # being created directly in that collection. The permissions will not be applied to the work if the collection + # type is configured not to allow that or if the work is being created in more than one collection. + # + # @param env [Hyrax::Actors::Enviornment] + # + # Given an array of collection_attributes when it is size: + # * 0 do not set `env.attributes[:collection_id]` + # * 1 set `env.attributes[:collection_id]` to the one and only one collection + # * 2+ do not set `env.attributes[:collection_id]` + # + # NOTE: Only called from create. All collections are being added as parents of a work. None are being removed. + def extract_collection_id(env) + attributes_collection = + env.attributes.fetch(:member_of_collections_attributes) { nil } + + # Determine if the work is being created in one and only one collection. + return unless attributes_collection && attributes_collection.size == 1 + + # Extract the collection id from attributes_collection, + collection_id = attributes_collection.first.second['id'] + + # Do not apply permissions to work if collection type is configured not to + collection = Hyrax.config.collection_class.find(collection_id) + return unless collection.share_applies_to_new_works? + + # Save the collection id in env for use in apply_permission_template_actor + env.attributes[:collection_id] = collection_id + end - def valid_membership?(env, collection_ids:) - multiple_memberships = Hyrax::MultipleMembershipChecker.new(item: env.curation_concern) - multiple_memberships = multiple_memberships.check(collection_ids: collection_ids) - if multiple_memberships - env.curation_concern.errors.add(:collections, multiple_memberships) - return false - end - true + def valid_membership?(env, collection_ids:) + multiple_memberships = Hyrax::MultipleMembershipChecker.new(item: env.curation_concern).check(collection_ids: collection_ids) + if multiple_memberships + env.curation_concern.errors.add(:collections, multiple_memberships) + return false end + true + end end end end diff --git a/app/actors/hyrax/actors/environment.rb b/app/actors/hyrax/actors/environment.rb new file mode 100644 index 00000000..6c1654ac --- /dev/null +++ b/app/actors/hyrax/actors/environment.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# OVERRIDE Hyrax 2.9 to add in import flag +module Hyrax + module Actors + class Environment + # @param [ActiveFedora::Base] curation_concern work to operate on + # @param [Ability] current_ability the authorizations of the acting user + # @param [ActionController::Parameters] attributes user provided form attributes + def initialize(curation_concern, current_ability, attributes, importing = false) + @curation_concern = curation_concern + @current_ability = current_ability + @attributes = attributes.to_h.with_indifferent_access + @importing = importing + end + + attr_accessor :curation_concern, :current_ability, :attributes, :importing + + # @return [User] the user from the current_ability + def user + current_ability.current_user + end + end + end +end diff --git a/app/models/.#solr_document_decoraotor.rb b/app/models/.#solr_document_decoraotor.rb deleted file mode 120000 index f6b43a7c..00000000 --- a/app/models/.#solr_document_decoraotor.rb +++ /dev/null @@ -1 +0,0 @@ -rob@Robs-MacBook-Pro.local.8776 \ No newline at end of file diff --git a/app/models/concerns/slug_bug.rb b/app/models/concerns/slug_bug.rb index b0d67130..3e4002db 100644 --- a/app/models/concerns/slug_bug.rb +++ b/app/models/concerns/slug_bug.rb @@ -4,9 +4,9 @@ module SlugBug extend ActiveSupport::Concern included do - before_save :set_slug + try(:before_save, :set_slug) # Cribbed from https://gitlab.com/notch8/louisville-hyku/-/blob/main/app/models/custom_slugs/slug_behavior.rb#L14 - after_update :remove_index_and_reindex + try(:after_update, :remove_index_and_reindex) end def to_param diff --git a/app/models/generic_work_decorator.rb b/app/models/generic_work_decorator.rb index ff505716..6e1763ab 100644 --- a/app/models/generic_work_decorator.rb +++ b/app/models/generic_work_decorator.rb @@ -1,29 +1,37 @@ # frozen_string_literal: true -module GenericWorkDecorator - extend ActiveSupport::Concern - - include VideoEmbedViewer - include ::Hyrax::WorkBehavior - include DogBiscuits::Abstract - include DogBiscuits::BibliographicCitation - include DogBiscuits::DateIssued - include DogBiscuits::Geo - include DogBiscuits::PartOf - include DogBiscuits::PlaceOfPublication - include SlugBug - include IiifPrint.model_configuration( - pdf_split_child_model: self, - pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter, - derivative_service_plugins: [ - IiifPrint::TextExtractionDerivativeService - ] - ) -end - -GenericWork.prepend(GenericWorkDecorator) +GenericWork.include(VideoEmbedViewer) +GenericWork.include(::Hyrax::WorkBehavior) +GenericWork.include(DogBiscuits::Abstract) +GenericWork.include(DogBiscuits::BibliographicCitation) +GenericWork.include(DogBiscuits::DateIssued) +GenericWork.include(DogBiscuits::Geo) +GenericWork.include(DogBiscuits::PartOf) +GenericWork.include(DogBiscuits::PlaceOfPublication) +GenericWork.include(SlugBug) +GenericWork.include(IiifPrint.model_configuration( + pdf_split_child_model: self, + pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter, + derivative_service_plugins: [ + IiifPrint::TextExtractionDerivativeService + ] +)) # This must come after the properties because it finalizes the metadata # schema (by adding accepts_nested_attributes) GenericWork.include SlugMetadata GenericWork.include AdventistMetadata + +GenericWork.instance_variable_set(:@generated_resource_class, nil) +GenericWork.resource_class + +GenericWork.resource_class.send(:include, SlugMetadata) +GenericWork.resource_class.send(:include, AdventistMetadata) +GenericWork.resource_class.send(:include, VideoEmbedViewer) +GenericWork.resource_class.send(:include, DogBiscuits::Abstract) +GenericWork.resource_class.send(:include, DogBiscuits::BibliographicCitation) +GenericWork.resource_class.send(:include, DogBiscuits::DateIssued) +GenericWork.resource_class.send(:include, DogBiscuits::Geo) +GenericWork.resource_class.send(:include, DogBiscuits::PartOf) +GenericWork.resource_class.send(:include, DogBiscuits::PlaceOfPublication) +GenericWork.resource_class.send(:include, SlugBug) diff --git a/app/models/solr_document_decorator.rb b/app/models/solr_document_decorator.rb index 2d6f3ad2..62020204 100644 --- a/app/models/solr_document_decorator.rb +++ b/app/models/solr_document_decorator.rb @@ -2,36 +2,165 @@ module SolrDocumentDecorator extend ActiveSupport::Concern + class_methods do + def attribute(name, type, field) + define_method name do + type.coerce(self[field]) + end + end - # Adds Hyrax behaviors to the SolrDocument. - include DogBiscuits::ExtendedSolrDocument + def solr_name(*args) + ActiveFedora.index_field_mapper.solr_name(*args) + end + end + + module Solr + class Array + # @return [Array] + def self.coerce(input) + ::Array.wrap(input) + end + end + class String + # @return [String] + def self.coerce(input) + ::Array.wrap(input).first + end + end + + class Date + # @return [Date] + def self.coerce(input) + field = String.coerce(input) + return if field.blank? + begin + ::Date.parse(field) + rescue ArgumentError + Rails.logger.info "Unable to parse date: #{field.first.inspect}" + end + end + end + end + # Keep these alphebetized; comments indicate those in basic_metadata + # see https://github.com/samvera/hyrax/blob/master/app/models/concerns/hyrax/solr_document/metadata.rb included do - attribute :slug, Solr::String, solr_name('slug') + attribute :abstract, Solr::Array, solr_name('abstract') + attribute :access_provided_by, Solr::Array, solr_name('access_provided_by') + attribute :advisor, Solr::Array, solr_name('advisor') + attribute :alt, Solr::Array, solr_name('alt') + attribute :awarding_institution, Solr::Array, solr_name('awarding_institution') + # based_near and based_near + attribute :content_version, Solr::Array, solr_name('content_version') + # contributor + # creator + attribute :date, Solr::Array, solr_name('date') + attribute :date_accepted, Solr::Array, solr_name('date_accepted') + attribute :date_available, Solr::Array, solr_name('date_available') + attribute :date_collected, Solr::Array, solr_name('date_collected') + attribute :date_copyrighted, Solr::Array, solr_name('date_copyrighted') + attribute :date_issued, Solr::Array, solr_name('date_issued') + # date_created + attribute :date_of_award, Solr::Array, solr_name('date_of_award') + attribute :date_published, Solr::Array, solr_name('date_published') + attribute :date_submitted, Solr::Array, solr_name('date_submitted') + attribute :date_updated, Solr::Array, solr_name('date_updated') + attribute :date_valid, Solr::Array, solr_name('date_valid') + attribute :dc_access_rights, Solr::Array, solr_name('dc_access_rights') + attribute :department, Solr::Array, solr_name('department') + # description + attribute :doi, Solr::Array, solr_name('doi') + attribute :edition, Solr::Array, solr_name('edition') + attribute :editor, Solr::Array, solr_name('editor') + attribute :end_date, Solr::Array, solr_name('end_date') + attribute :event_date, Solr::Array, solr_name('event_date') + attribute :extent, Solr::Array, solr_name('extent') + attribute :dc_format, Solr::Array, solr_name('dc_format') + attribute :former_identifier, Solr::Array, solr_name('former_identifier') + attribute :funder, Solr::Array, solr_name('funder') + attribute :resource_type_general, Solr::Array, solr_name('resource_type_general') + attribute :has_restriction, Solr::Array, solr_name('has_restriction') + # rubocop:enable Naming/PredicateName + + # identifier + attribute :isbn, Solr::Array, solr_name('isbn') + attribute :issue_number, Solr::Array, solr_name('issue_number') + # keyword + # language + attribute :last_access, Solr::Array, solr_name('last_access') + attribute :lat, Solr::Array, solr_name('lat') + # license + attribute :location, Solr::Array, solr_name('location') + attribute :long, Solr::Array, solr_name('long') + attribute :managing_organisation, Solr::Array, solr_name('managing_organisation') + attribute :module_code, Solr::Array, solr_name('module_code') + attribute :note, Solr::Array, solr_name('note') + attribute :number_of_downloads, Solr::Array, solr_name('last_access') + attribute :official_url, Solr::Array, solr_name('official_url') + attribute :output_of, Solr::Array, solr_name('output_of') + attribute :official_url, Solr::Array, solr_name('official_url') + attribute :packaged_by_ids, Solr::Array, solr_name('packaged_by_ids', :symbol) + attribute :package_ids, Solr::Array, solr_name('package_ids', :symbol) + attribute :pagination, Solr::Array, solr_name('pagination') + attribute :part, Solr::Array, solr_name('part') + attribute :place_of_publication, Solr::Array, solr_name('place_of_publication') + attribute :presented_at, Solr::Array, solr_name('presented_at') + attribute :part_of, Solr::Array, solr_name('part_of') + attribute :project, Solr::Array, solr_name('project') + attribute :publication_status, Solr::Array, solr_name('publication_status') + # publisher + attribute :qualification_level, Solr::Array, solr_name('qualification_level') + attribute :qualification_name, Solr::Array, solr_name('qualification_name') + attribute :refereed, Solr::Array, solr_name('refereed') + attribute :related_url, Solr::Array, solr_name('related_url') + # resource_type + # rights_statement + attribute :series, Solr::Array, solr_name('series') + # source + attribute :start_date, Solr::Array, solr_name('start_date') + # subject + attribute :subtitle, Solr::Array, solr_name('subtitle') + attribute :volume_number, Solr::Array, solr_name('volume_number') + # archivematica + attribute :aip_uuid, Solr::Array, solr_name('aip_uuid') + attribute :transfer_uuid, Solr::Array, solr_name('transfer_uuid') + attribute :sip_uuid, Solr::Array, solr_name('sip_uuid') + attribute :dip_uuid, Solr::Array, solr_name('dip_uuid') + attribute :aip_status, Solr::Array, solr_name('aip_status') + attribute :dip_status, Solr::Array, solr_name('dip_status') + attribute :aip_size, Solr::Array, solr_name('aip_size') + attribute :dip_size, Solr::Array, solr_name('dip_size') + attribute :aip_current_path, Solr::Array, solr_name('aip_current_path') + attribute :dip_current_path, Solr::Array, solr_name('dip_current_path') + attribute :aip_current_location, Solr::Array, solr_name('aip_current_location') + attribute :dip_current_location, Solr::Array, solr_name('dip_current_location') + attribute :aip_resource_uri, Solr::Array, solr_name('aip_resource_uri') + attribute :dip_resource_uri, Solr::Array, solr_name('dip_resource_uri') + attribute :origin_pipeline, Solr::Array, solr_name('origin_pipeline') + attribute :slug, Solr::String, 'slug_tesim' attribute :fedora_id, Solr::String, 'fedora_id_ssi' attribute :aark_id, Solr::String, 'aark_id_tesim' - attribute :bibliographic_citation, Solr::String, solr_name('bibliographic_citation') - attribute :alt, Solr::String, solr_name('alt') + attribute :bibliographic_citation, Solr::String, 'bibliographic_citation_tesim' + attribute :alt, Solr::String, 'alt_tesim' attribute :file_set_ids, Solr::Array, 'file_set_ids_ssim' attribute :video_embed, Solr::String, 'video_embed_tesim' - field_semantics.merge!( - contributor: 'contributor_tesim', - creator: 'creator_tesim', - date: 'date_created_tesim', - description: 'description_tesim', - identifier: 'aark_id_tesim', - language: 'language_tesim', - publisher: 'publisher_tesim', - relation: 'nesting_collection__pathnames_ssim', - related_url: 'related_url_tesim', - rights: 'rights_statement_tesim', - subject: 'subject_tesim', - title: 'title_tesim', - type: 'human_readable_type_tesim' - ) - +field_semantics.merge!( + contributor: 'contributor_tesim', + creator: 'creator_tesim', + date: 'date_created_tesim', + description: 'description_tesim', + identifier: 'aark_id_tesim', + language: 'language_tesim', + publisher: 'publisher_tesim', + relation: 'nesting_collection__pathnames_ssim', + related_url: 'related_url_tesim', + rights: 'rights_statement_tesim', + subject: 'subject_tesim', + title: 'title_tesim', + type: 'human_readable_type_tesim' +) end def to_param @@ -43,9 +172,8 @@ def thumbnail_url end def remote_url - self[Solrizer.solr_name('remote_url')] + self['remote_url_tesim'] end - end -SolrDocument.prepend(SolrDocumentDecorator) +SolrDocument.include(SolrDocumentDecorator) diff --git a/hyrax-webapp b/hyrax-webapp index 00a4b4af..7740cfd6 160000 --- a/hyrax-webapp +++ b/hyrax-webapp @@ -1 +1 @@ -Subproject commit 00a4b4af7a0dd18f5a3b393d60e9728322f4943e +Subproject commit 7740cfd6a07ee2a54de6af277b81ef56f492fb87 diff --git a/lib/dog_biscuits.rb b/lib/dog_biscuits.rb index c023e3a6..4c6fc643 100755 --- a/lib/dog_biscuits.rb +++ b/lib/dog_biscuits.rb @@ -97,10 +97,6 @@ module Vocab autoload :Thesis end - autoload_under 'models/concerns' do - autoload :ExtendedSolrDocument - end - autoload_under 'models/concerns/model_property_sets' do autoload :AgentMetadata autoload :ConferenceItemMetadata diff --git a/lib/dog_biscuits/models/concerns/extended_solr_document.rb b/lib/dog_biscuits/models/concerns/extended_solr_document.rb deleted file mode 100644 index 212efa23..00000000 --- a/lib/dog_biscuits/models/concerns/extended_solr_document.rb +++ /dev/null @@ -1,147 +0,0 @@ -# frozen_string_literal: true - -module DogBiscuits - module ExtendedSolrDocument - extend ActiveSupport::Concern - - # Duplicated from https://github.com/samvera/hyrax/blob/master/app/models/concerns/hyrax/solr_document/metadata.rb - - class_methods do - def attribute(name, type, field) - define_method name do - type.coerce(self[field]) - end - end - - def solr_name(*args) - ActiveFedora.index_field_mapper.solr_name(*args) - end - end - - module Solr - class Array - # @return [Array] - def self.coerce(input) - ::Array.wrap(input) - end - end - - class String - # @return [String] - def self.coerce(input) - ::Array.wrap(input).first - end - end - - class Date - # @return [Date] - def self.coerce(input) - field = String.coerce(input) - return if field.blank? - begin - ::Date.parse(field) - rescue ArgumentError - Rails.logger.info "Unable to parse date: #{field.first.inspect}" - end - end - end - end - - # Keep these alphebetized; comments indicate those in basic_metadata - # see https://github.com/samvera/hyrax/blob/master/app/models/concerns/hyrax/solr_document/metadata.rb - included do - attribute :abstract, Solr::Array, solr_name('abstract') - attribute :access_provided_by, Solr::Array, solr_name('access_provided_by') - attribute :advisor, Solr::Array, solr_name('advisor') - attribute :alt, Solr::Array, solr_name('alt') - attribute :awarding_institution, Solr::Array, solr_name('awarding_institution') - # based_near and based_near - attribute :content_version, Solr::Array, solr_name('content_version') - # contributor - # creator - attribute :date, Solr::Array, solr_name('date') - attribute :date_accepted, Solr::Array, solr_name('date_accepted') - attribute :date_available, Solr::Array, solr_name('date_available') - attribute :date_collected, Solr::Array, solr_name('date_collected') - attribute :date_copyrighted, Solr::Array, solr_name('date_copyrighted') - attribute :date_issued, Solr::Array, solr_name('date_issued') - # date_created - attribute :date_of_award, Solr::Array, solr_name('date_of_award') - attribute :date_published, Solr::Array, solr_name('date_published') - attribute :date_submitted, Solr::Array, solr_name('date_submitted') - attribute :date_updated, Solr::Array, solr_name('date_updated') - attribute :date_valid, Solr::Array, solr_name('date_valid') - attribute :dc_access_rights, Solr::Array, solr_name('dc_access_rights') - attribute :department, Solr::Array, solr_name('department') - # description - attribute :doi, Solr::Array, solr_name('doi') - attribute :edition, Solr::Array, solr_name('edition') - attribute :editor, Solr::Array, solr_name('editor') - attribute :end_date, Solr::Array, solr_name('end_date') - attribute :event_date, Solr::Array, solr_name('event_date') - attribute :extent, Solr::Array, solr_name('extent') - attribute :dc_format, Solr::Array, solr_name('dc_format') - attribute :former_identifier, Solr::Array, solr_name('former_identifier') - attribute :funder, Solr::Array, solr_name('funder') - attribute :resource_type_general, Solr::Array, solr_name('resource_type_general') - attribute :has_restriction, Solr::Array, solr_name('has_restriction') - # rubocop:enable Naming/PredicateName - - # identifier - attribute :isbn, Solr::Array, solr_name('isbn') - attribute :issue_number, Solr::Array, solr_name('issue_number') - # keyword - # language - attribute :last_access, Solr::Array, solr_name('last_access') - attribute :lat, Solr::Array, solr_name('lat') - # license - attribute :location, Solr::Array, solr_name('location') - attribute :long, Solr::Array, solr_name('long') - attribute :managing_organisation, Solr::Array, solr_name('managing_organisation') - attribute :module_code, Solr::Array, solr_name('module_code') - attribute :note, Solr::Array, solr_name('note') - attribute :number_of_downloads, Solr::Array, solr_name('last_access') - attribute :official_url, Solr::Array, solr_name('official_url') - attribute :output_of, Solr::Array, solr_name('output_of') - attribute :official_url, Solr::Array, solr_name('official_url') - attribute :packaged_by_ids, Solr::Array, solr_name('packaged_by_ids', :symbol) - attribute :package_ids, Solr::Array, solr_name('package_ids', :symbol) - attribute :pagination, Solr::Array, solr_name('pagination') - attribute :part, Solr::Array, solr_name('part') - attribute :place_of_publication, Solr::Array, solr_name('place_of_publication') - attribute :presented_at, Solr::Array, solr_name('presented_at') - attribute :part_of, Solr::Array, solr_name('part_of') - attribute :project, Solr::Array, solr_name('project') - attribute :publication_status, Solr::Array, solr_name('publication_status') - # publisher - attribute :qualification_level, Solr::Array, solr_name('qualification_level') - attribute :qualification_name, Solr::Array, solr_name('qualification_name') - attribute :refereed, Solr::Array, solr_name('refereed') - attribute :related_url, Solr::Array, solr_name('related_url') - # resource_type - # rights_statement - attribute :series, Solr::Array, solr_name('series') - # source - attribute :start_date, Solr::Array, solr_name('start_date') - # subject - attribute :subtitle, Solr::Array, solr_name('subtitle') - attribute :volume_number, Solr::Array, solr_name('volume_number') - # archivematica - attribute :aip_uuid, Solr::Array, solr_name('aip_uuid') - attribute :transfer_uuid, Solr::Array, solr_name('transfer_uuid') - attribute :sip_uuid, Solr::Array, solr_name('sip_uuid') - attribute :dip_uuid, Solr::Array, solr_name('dip_uuid') - attribute :aip_status, Solr::Array, solr_name('aip_status') - attribute :dip_status, Solr::Array, solr_name('dip_status') - attribute :aip_size, Solr::Array, solr_name('aip_size') - attribute :dip_size, Solr::Array, solr_name('dip_size') - attribute :aip_current_path, Solr::Array, solr_name('aip_current_path') - attribute :dip_current_path, Solr::Array, solr_name('dip_current_path') - attribute :aip_current_location, Solr::Array, solr_name('aip_current_location') - attribute :dip_current_location, Solr::Array, solr_name('dip_current_location') - attribute :aip_resource_uri, Solr::Array, solr_name('aip_resource_uri') - attribute :dip_resource_uri, Solr::Array, solr_name('dip_resource_uri') - attribute :origin_pipeline, Solr::Array, solr_name('origin_pipeline') - end - end -end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/common/common_labels.rb b/lib/dog_biscuits/models/concerns/model_property_sets/common/common_labels.rb index 3aef6b32..d7557b5f 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/common/common_labels.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/common/common_labels.rb @@ -3,7 +3,9 @@ module DogBiscuits module CommonLabels extend ActiveSupport::Concern - include DogBiscuits::SkosLabels - include DogBiscuits::RdfsLabel + included do + include DogBiscuits::SkosLabels + include DogBiscuits::RdfsLabel + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/common/common_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/common/common_metadata.rb index d139852f..6166f2ac 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/common/common_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/common/common_metadata.rb @@ -5,47 +5,47 @@ module DogBiscuits module CommonMetadata extend ActiveSupport::Concern - # BasicMetadata: Omitting label, relative_url and import_url - are these fileset only? + included do + # BasicMetadata: Omitting label, relative_url and import_url - are these fileset only? - # Other Common concerns - include DogBiscuits::CommonLabels - include DogBiscuits::CommonRights # BasicMetadata + # Other Common concerns + include DogBiscuits::CommonLabels + include DogBiscuits::CommonRights # BasicMetadata - # Common dc properties - # dc:title is included in Core Metadata - include DogBiscuits::BibliographicCitation # BasicMetadata - include DogBiscuits::Creator # BasicMetadata - include DogBiscuits::Contributor # BasicMetadata - include DogBiscuits::Date - include DogBiscuits::DateCreated # BasicMetadata - include DogBiscuits::Department - include DogBiscuits::Description # BasicMetadata - include DogBiscuits::Funder - include DogBiscuits::Identifier # BasicMetadata - include DogBiscuits::Keyword # BasicMetadata (schema:keywords) - include DogBiscuits::Language # BasicMetadata - include DogBiscuits::OutputOf - include DogBiscuits::Publisher # BasicMetadata - include DogBiscuits::ResourceType # BasicMetadata - include DogBiscuits::Source # BasicMetadata - include DogBiscuits::Subject # BasicMetadata + # Common dc properties + # dc:title is included in Core Metadata + include DogBiscuits::BibliographicCitation # BasicMetadata + include DogBiscuits::Creator # BasicMetadata + include DogBiscuits::Contributor # BasicMetadata + include DogBiscuits::Date + include DogBiscuits::DateCreated # BasicMetadata + include DogBiscuits::Department + include DogBiscuits::Description # BasicMetadata + include DogBiscuits::Funder + include DogBiscuits::Identifier # BasicMetadata + include DogBiscuits::Keyword # BasicMetadata (schema:keywords) + include DogBiscuits::Language # BasicMetadata + include DogBiscuits::OutputOf + include DogBiscuits::Publisher # BasicMetadata + include DogBiscuits::ResourceType # BasicMetadata + include DogBiscuits::Source # BasicMetadata + include DogBiscuits::Subject # BasicMetadata - # Common other properties - include DogBiscuits::Doi - include DogBiscuits::Geo - include DogBiscuits::Location - include DogBiscuits::ManagingOrganisation - include DogBiscuits::RelatedUrl # BasicMetadata - include DogBiscuits::SkosNote - include DogBiscuits::RelatedUrl # BasicMetadata + # Common other properties + include DogBiscuits::Doi + include DogBiscuits::Geo + include DogBiscuits::Location + include DogBiscuits::ManagingOrganisation + include DogBiscuits::RelatedUrl # BasicMetadata + include DogBiscuits::SkosNote + include DogBiscuits::RelatedUrl # BasicMetadata - # Common dlib properties - include DogBiscuits::FormerIdentifier + # Common dlib properties + include DogBiscuits::FormerIdentifier - # Controlled properties - must go at the end - include DogBiscuits::BasedNear # BasicMetadata + # Controlled properties - must go at the end + include DogBiscuits::BasedNear # BasicMetadata - included do # From BasicMetadata property :label, predicate: ActiveFedora::RDF::Fcrepo::Model.downloadFilename, multiple: false property :relative_path, predicate: ::RDF::URI.new('http://scholarsphere.psu.edu/ns#relativePath'), multiple: false diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/common/common_rights.rb b/lib/dog_biscuits/models/concerns/model_property_sets/common/common_rights.rb index 4fbacd29..fcdf4ae3 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/common/common_rights.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/common/common_rights.rb @@ -3,8 +3,11 @@ module DogBiscuits module CommonRights extend ActiveSupport::Concern - include DogBiscuits::RightsHolder - include DogBiscuits::EdmRights - include DogBiscuits::Rights + + included do + include DogBiscuits::RightsHolder + include DogBiscuits::EdmRights + include DogBiscuits::Rights + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/conference_item_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/conference_item_metadata.rb index d7624962..30d7794a 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/conference_item_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/conference_item_metadata.rb @@ -3,22 +3,25 @@ module DogBiscuits module ConferenceItemMetadata extend ActiveSupport::Concern - include DogBiscuits::Abstract - include DogBiscuits::DateAvailable - include DogBiscuits::DatePublished - include DogBiscuits::DateSubmitted - include DogBiscuits::DateAccepted - include DogBiscuits::Editor - include DogBiscuits::EventDate - include DogBiscuits::Isbn - include DogBiscuits::OfficialUrl - include DogBiscuits::Pagination - include DogBiscuits::PartOf - include DogBiscuits::PlaceOfPublication - include DogBiscuits::PublicationStatus - include DogBiscuits::Refereed - include DogBiscuits::PresentedAt - # Controlled Properties must go last - include DogBiscuits::CommonMetadata + + included do + include DogBiscuits::Abstract + include DogBiscuits::DateAvailable + include DogBiscuits::DatePublished + include DogBiscuits::DateSubmitted + include DogBiscuits::DateAccepted + include DogBiscuits::Editor + include DogBiscuits::EventDate + include DogBiscuits::Isbn + include DogBiscuits::OfficialUrl + include DogBiscuits::Pagination + include DogBiscuits::PartOf + include DogBiscuits::PlaceOfPublication + include DogBiscuits::PublicationStatus + include DogBiscuits::Refereed + include DogBiscuits::PresentedAt + # Controlled Properties must go last + include DogBiscuits::CommonMetadata + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/dataset_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/dataset_metadata.rb index d1b37583..2ced86c5 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/dataset_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/dataset_metadata.rb @@ -4,33 +4,35 @@ module DogBiscuits module DatasetMetadata extend ActiveSupport::Concern - include DogBiscuits::Abstract # added - include DogBiscuits::AccessRights - include DogBiscuits::DateAvailable - include DogBiscuits::ContentVersion # added - include DogBiscuits::DateAccepted # added - include DogBiscuits::DateCollected # added - include DogBiscuits::DateCopyrighted # added - include DogBiscuits::DateIssued # added - include DogBiscuits::DatePublished # added - include DogBiscuits::DateSubmitted # added - include DogBiscuits::DateUpdated # added - include DogBiscuits::DateValid # added - include DogBiscuits::Extent # added - include DogBiscuits::ForIndexing - include DogBiscuits::Format # added - include DogBiscuits::Funder # added - include DogBiscuits::ResourceTypeGeneral # added - include DogBiscuits::HasRestriction - include DogBiscuits::LastAccess - include DogBiscuits::NumberOfDownloads - include DogBiscuits::PackagedBy - # include DogBiscuits::Pure # removed - include DogBiscuits::ReadmeFile - include DogBiscuits::RequestorEmail - include DogBiscuits::SimpleVersions - include DogBiscuits::Subtitle - # Controlled Properties must go last - include DogBiscuits::CommonMetadata + included do + include DogBiscuits::Abstract # added + include DogBiscuits::AccessRights + include DogBiscuits::DateAvailable + include DogBiscuits::ContentVersion # added + include DogBiscuits::DateAccepted # added + include DogBiscuits::DateCollected # added + include DogBiscuits::DateCopyrighted # added + include DogBiscuits::DateIssued # added + include DogBiscuits::DatePublished # added + include DogBiscuits::DateSubmitted # added + include DogBiscuits::DateUpdated # added + include DogBiscuits::DateValid # added + include DogBiscuits::Extent # added + include DogBiscuits::ForIndexing + include DogBiscuits::Format # added + include DogBiscuits::Funder # added + include DogBiscuits::ResourceTypeGeneral # added + include DogBiscuits::HasRestriction + include DogBiscuits::LastAccess + include DogBiscuits::NumberOfDownloads + include DogBiscuits::PackagedBy + # include DogBiscuits::Pure # removed + include DogBiscuits::ReadmeFile + include DogBiscuits::RequestorEmail + include DogBiscuits::SimpleVersions + include DogBiscuits::Subtitle + # Controlled Properties must go last + include DogBiscuits::CommonMetadata + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/digital_archival_object_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/digital_archival_object_metadata.rb index 0d0a9e3f..86da6155 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/digital_archival_object_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/digital_archival_object_metadata.rb @@ -3,11 +3,14 @@ module DogBiscuits module DigitalArchivalObjectMetadata extend ActiveSupport::Concern - include DogBiscuits::AccessProvidedBy - include DogBiscuits::Extent - include DogBiscuits::PackagedBy - include DogBiscuits::PartOf - # Controlled Properties must go last - include DogBiscuits::CommonMetadata + + included do + include DogBiscuits::AccessProvidedBy + include DogBiscuits::Extent + include DogBiscuits::PackagedBy + include DogBiscuits::PartOf + # Controlled Properties must go last + include DogBiscuits::CommonMetadata + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/exam_paper_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/exam_paper_metadata.rb index 3d4578e8..6b9f37df 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/exam_paper_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/exam_paper_metadata.rb @@ -4,11 +4,14 @@ module DogBiscuits # add exam paper metadata module ExamPaperMetadata extend ActiveSupport::Concern - include DogBiscuits::ModuleCode - include DogBiscuits::MainFile - include DogBiscuits::Qualification - include DogBiscuits::DateAvailable - # Controlled Properties must go last - include DogBiscuits::CommonMetadata + + included do + include DogBiscuits::ModuleCode + include DogBiscuits::MainFile + include DogBiscuits::Qualification + include DogBiscuits::DateAvailable + # Controlled Properties must go last + include DogBiscuits::CommonMetadata + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/journal_article_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/journal_article_metadata.rb index 673df567..215fe7e1 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/journal_article_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/journal_article_metadata.rb @@ -4,21 +4,24 @@ module DogBiscuits # add journal article metadata module JournalArticleMetadata extend ActiveSupport::Concern - include DogBiscuits::Abstract - include DogBiscuits::DateAvailable - include DogBiscuits::DatePublished - include DogBiscuits::DateSubmitted - include DogBiscuits::DateAccepted - include DogBiscuits::IssueNumber - include DogBiscuits::ManagingOrganisation - include DogBiscuits::OfficialUrl - include DogBiscuits::Orcid - include DogBiscuits::Pagination - include DogBiscuits::PartOf - include DogBiscuits::PublicationStatus - include DogBiscuits::Refereed - include DogBiscuits::VolumeNumber - # Controlled Properties must go last - include DogBiscuits::CommonMetadata + + included do + include DogBiscuits::Abstract + include DogBiscuits::DateAvailable + include DogBiscuits::DatePublished + include DogBiscuits::DateSubmitted + include DogBiscuits::DateAccepted + include DogBiscuits::IssueNumber + include DogBiscuits::ManagingOrganisation + include DogBiscuits::OfficialUrl + include DogBiscuits::Orcid + include DogBiscuits::Pagination + include DogBiscuits::PartOf + include DogBiscuits::PublicationStatus + include DogBiscuits::Refereed + include DogBiscuits::VolumeNumber + # Controlled Properties must go last + include DogBiscuits::CommonMetadata + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/package_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/package_metadata.rb index 2d104828..cf8e152c 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/package_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/package_metadata.rb @@ -4,10 +4,12 @@ module DogBiscuits # add package metadata module PackageMetadata extend ActiveSupport::Concern - include DogBiscuits::Archivematica - include DogBiscuits::RdfType - include DogBiscuits::SimpleVersions - # Controlled Properties must go last - include DogBiscuits::CommonMetadata + included do + include DogBiscuits::Archivematica + include DogBiscuits::RdfType + include DogBiscuits::SimpleVersions + # Controlled Properties must go last + include DogBiscuits::CommonMetadata + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/published_work_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/published_work_metadata.rb index 4a98507b..351b1e67 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/published_work_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/published_work_metadata.rb @@ -3,24 +3,27 @@ module DogBiscuits module PublishedWorkMetadata extend ActiveSupport::Concern - include DogBiscuits::Abstract - include DogBiscuits::DateAvailable - include DogBiscuits::DatePublished - include DogBiscuits::DateSubmitted - include DogBiscuits::DateAccepted - include DogBiscuits::Edition - include DogBiscuits::Editor - include DogBiscuits::IssueNumber - include DogBiscuits::Isbn - include DogBiscuits::OfficialUrl - include DogBiscuits::Pagination - include DogBiscuits::Part - include DogBiscuits::PlaceOfPublication - include DogBiscuits::PublicationStatus - include DogBiscuits::Refereed - include DogBiscuits::Series - include DogBiscuits::VolumeNumber - # Controlled Properties must go last - include DogBiscuits::CommonMetadata + + included do + include DogBiscuits::Abstract + include DogBiscuits::DateAvailable + include DogBiscuits::DatePublished + include DogBiscuits::DateSubmitted + include DogBiscuits::DateAccepted + include DogBiscuits::Edition + include DogBiscuits::Editor + include DogBiscuits::IssueNumber + include DogBiscuits::Isbn + include DogBiscuits::OfficialUrl + include DogBiscuits::Pagination + include DogBiscuits::Part + include DogBiscuits::PlaceOfPublication + include DogBiscuits::PublicationStatus + include DogBiscuits::Refereed + include DogBiscuits::Series + include DogBiscuits::VolumeNumber + # Controlled Properties must go last + include DogBiscuits::CommonMetadata + end end end diff --git a/lib/dog_biscuits/models/concerns/model_property_sets/thesis_metadata.rb b/lib/dog_biscuits/models/concerns/model_property_sets/thesis_metadata.rb index 03c934fc..94bbdde7 100644 --- a/lib/dog_biscuits/models/concerns/model_property_sets/thesis_metadata.rb +++ b/lib/dog_biscuits/models/concerns/model_property_sets/thesis_metadata.rb @@ -3,15 +3,18 @@ module DogBiscuits module ThesisMetadata extend ActiveSupport::Concern - include DogBiscuits::Abstract - include DogBiscuits::Advisor - include DogBiscuits::AwardingInstitution - include DogBiscuits::DateOfAward - include DogBiscuits::Department - include DogBiscuits::MainFile - include DogBiscuits::Orcid - include DogBiscuits::Qualification - # Controlled Properties must go last - include DogBiscuits::CommonMetadata + + included do + include DogBiscuits::Abstract + include DogBiscuits::Advisor + include DogBiscuits::AwardingInstitution + include DogBiscuits::DateOfAward + include DogBiscuits::Department + include DogBiscuits::MainFile + include DogBiscuits::Orcid + include DogBiscuits::Qualification + # Controlled Properties must go last + include DogBiscuits::CommonMetadata + end end end