Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge 6957ba8 into a873e12
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Mar 24, 2021
2 parents a873e12 + 6957ba8 commit 771bb7a
Show file tree
Hide file tree
Showing 3 changed files with 519 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ Style/SoleNestedConditional: # (new in 0.89)
Enabled: true
Style/StringConcatenation: # (new in 0.89)
Enabled: true
Style/WordArray:
MinSize: 3

Performance/AncestorsInclude: # (new in 1.7)
Enabled: true
Expand Down
60 changes: 57 additions & 3 deletions app/indexers/rights_metadata_indexer.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,71 @@
# frozen_string_literal: true

class RightsMetadataIndexer
attr_reader :resource
attr_reader :resource, :cocina

def initialize(resource:, **)
def initialize(resource:, cocina:, **)
@resource = resource
@cocina = cocina
end

def cocina_to_solr
{}.tap do |fields|
fields['copyright_ssim'] = cocina.access.copyright
fields['use_statement_ssim'] = cocina.access.useAndReproductionStatement
fields['use_license_machine_ssi'] = cocina.access.license
fields['rights_descriptions_ssim'] = rights_descriptions
end.compact
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/PerceivedComplexity
def rights_descriptions
results = []
root = case cocina.access.access
when 'dark'
'dark'
when 'citation-only'
'citation'
when 'location-based'
# FIXME: what if readLocation isn't present?
"location: #{cocina.access.readLocation}" if cocina.access.readLocation.present?
when 'stanford'
'stanford'
when 'world'
'world'
end

case cocina.access.download
when 'none'
if ['dark', 'citation'].include?(root)
results.push(root)
else
results.push("#{root} (no-download)")
end
when 'world'
results.push(root)
when 'stanford'
results.push(root) if root == 'stanford'
when 'location-based'
results.push(root) if root&.start_with?('location')
when nil
results.push(root)
end

results.push('controlled digital lending') if cocina.access.controlledDigitalLending.present?
results
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/PerceivedComplexity

# @return [Hash] the partial solr document for rightsMetadata
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/PerceivedComplexity
def to_solr
def fedora_to_solr
Rails.logger.debug "In #{self.class}"

solr_doc = {
Expand Down Expand Up @@ -71,6 +124,7 @@ def to_solr

solr_doc
end
alias to_solr fedora_to_solr
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength
Expand Down

0 comments on commit 771bb7a

Please sign in to comment.