Skip to content

Commit

Permalink
🧹 Remove commented out logic
Browse files Browse the repository at this point in the history
This commit will remove the commented out logic for the
csv_parser_decorator since it was not being used.  It seems the missing
fields check is working fine in Bulkrax so we'll use that.
  • Loading branch information
kirkkwang committed Jan 31, 2025
1 parent 0778d1c commit 10394ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 81 deletions.
60 changes: 0 additions & 60 deletions app/parsers/bulkrax/csv_parser_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,6 @@
module Bulkrax
module CsvParserDecorator
include OerCsvParser

# TODO: We need to revisit this for Valkyrie
#
# def valid_import?
# missing_fields_by_model = records.each_with_object({}) do |record, hash|
# record.compact!
# record.transform_keys!(&:downcase).transform_keys!(&:to_sym)
# missing_fields = missing_fields_for(record)
# hash[record[:model]] = missing_fields if missing_fields.present?
# end

# raise_error_for_missing_fields(missing_fields_by_model) if missing_fields_by_model.keys.present?

# file_paths.is_a?(Array)
# rescue StandardError => e
# set_status_info(e)
# false
# end

# private

# def missing_fields_for(record)
# required_fields = determine_required_fields_for(record[:model])
# required_fields.select do |field|
# # checks the field itself
# # any parser_mappings fields terms from `config/initializers/bulkrax.rb`
# # or any keys that has sequential numbers like creator_1
# (record[field] ||
# mapped_from(field).map { |f| record[f] }.any? ||
# handle_keys_with_numbers(field, record)).blank?
# end
# end

# def determine_required_fields_for(model)
# # TODO: Revisit when Valkyrized as we can use Hyrax::ModelRegistry
# case model
# when 'Collection' then Hyrax::Forms::CollectionForm.required_fields
# when 'FileSet' then []
# else "Hyrax::#{model}Form".constantize.required_fields
# end
# end

# def mapped_from(field)
# Bulkrax.config.field_mappings[self.class.to_s][field.to_s]&.fetch(:from, [])&.map(&:to_sym)
# end

# def handle_keys_with_numbers(_field, record)
# keys_with_numbers = record.keys.select { |k| k.to_s.match(/(.+)_\d+/) }
# keys_with_numbers.each do |key|
# return record[key]
# end
# end

# def raise_error_for_missing_fields(missing_fields_by_model)
# error_alert = missing_fields_by_model.keys.map do |model|
# "#{model} missing: #{missing_fields_by_model[model].join(', ')}"
# end.join('; ')
# # example alert: 'Collection missing: title; GenericWork missing: title, creator'
# raise StandardError, error_alert
# end
end
end

Expand Down
38 changes: 17 additions & 21 deletions lib/tasks/tenants.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,26 @@ namespace :tenants do
tenant_file_sizes = [] # Declare and initialize within the block

works.each do |work|
begin
document = SolrDocument.find(work.id)
files = document._source["file_set_ids_ssim"] || []

if files.any?
file_sizes = files.map do |file|
begin
f = SolrDocument.find(file.to_s)
f.to_h['file_size_lts'] || 0
rescue Blacklight::Exceptions::RecordNotFound => e
puts "Warning: File #{file} not found. Skipping. Error: #{e.message}"
0
end
end

total_file_size_bytes = file_sizes.inject(0, :+)
tenant_file_sizes << (total_file_size_bytes / 1.0.megabyte).round(2)
else
tenant_file_sizes << 0
document = SolrDocument.find(work.id)
files = document._source["file_set_ids_ssim"] || []

if files.any?
file_sizes = files.map do |file|
f = SolrDocument.find(file.to_s)
f.to_h['file_size_lts'] || 0
rescue Blacklight::Exceptions::RecordNotFound => e
puts "Warning: File #{file} not found. Skipping. Error: #{e.message}"
0
end
rescue Blacklight::Exceptions::RecordNotFound => e
puts "Warning: Work #{work.id} not found. Skipping. Error: #{e.message}"

total_file_size_bytes = file_sizes.inject(0, :+)
tenant_file_sizes << (total_file_size_bytes / 1.0.megabyte).round(2)
else
tenant_file_sizes << 0
end
rescue Blacklight::Exceptions::RecordNotFound => e
puts "Warning: Work #{work.id} not found. Skipping. Error: #{e.message}"
tenant_file_sizes << 0
end

total_mb = tenant_file_sizes.inject(0, :+)
Expand Down

0 comments on commit 10394ec

Please sign in to comment.