Skip to content

Commit

Permalink
Update document.rb
Browse files Browse the repository at this point in the history
Better commentary on the switchover
  • Loading branch information
ewlarson committed Nov 22, 2024
1 parent 3004c0b commit e302b37
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,48 @@ def a_downloadable_resource?

attr_json :dct_references_s, Document::Reference.to_type, array: true, default: -> { [] }

# Index Transformations - *_json functions
# Distributions
# - BEFORE DocumentDistributions
# - Use dct_references_s
# - Use multiple downloads
# - Use distributable assets
# - AFTER DocumentDistributions
# - Use document_distributions
# - Use distributable assets
# @TODO: Remove BEFORE path once we've migrated to DocumentDistributions
def distributions
distributions = ActiveSupport::HashWithIndifferentAccess.new

# Add DocumentDistributions to distributions
# AFTER - Add DocumentDistributions to distributions
if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "true"
distributions = document_distributions.to_aardvark_distributions
end

# Prep value arrays
# BEFORE - Prep value arrays
# @TODO: Remove this once we've migrated to DocumentDistributions
send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
if ref.category.present?
distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = []
end
end

# Seed value arrays
# BEFORE - Seed value arrays
# @TODO: Remove this once we've migrated to DocumentDistributions
send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
if ref.category.present?
distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] << ref.value
end
end
logger.debug("\n\nDocument#distributions > seeded: #{distributions}")

# Apply Multiple Downloads
distributions = apply_downloads(distributions)
logger.debug("Document#distributions > downloads: #{distributions}")
# BEFORE - Apply Multiple Downloads
# @TODO: Remove this once we've migrated to DocumentDistributions
if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "false"
distributions = apply_downloads(distributions)
logger.debug("Document#distributions > downloads: #{distributions}")
end

# Apply Distributable Assets
# BEFORE & AFTER - Apply Distributable Assets
distributions = apply_assets(distributions)
logger.debug("Document#distributions > assets: #{distributions}")

Expand Down Expand Up @@ -216,7 +229,8 @@ def apply_assets(distributions)
distributions
end

# Apply Downloads
# BEFORE - Apply Downloads
# @TODO: Remove this once we've migrated to DocumentDistributions
# 1. Native Aardvark Downloads
# 2. Multiple Document Download Links
# 3. Downloadable Document Assets
Expand Down Expand Up @@ -254,6 +268,8 @@ def apply_downloads(distributions)
distributions
end

# BEFORE - Multiple Downloads Array
# @TODO: Remove this once we've migrated to DocumentDistributions
def multiple_downloads_array
document_downloads.collect { |d| {label: d.label, url: d.value} }
end
Expand Down

0 comments on commit e302b37

Please sign in to comment.