From b346c7496349b0e84354d9ecd1dd6ee48d3a5626 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Wed, 24 Jan 2024 11:21:55 -0500 Subject: [PATCH] Appeasing rubocop --- app/factories/bulkrax/object_factory.rb | 2 +- .../bulkrax/valkyrie_object_factory.rb | 60 +++++++++---------- app/models/bulkrax/importer.rb | 11 ++-- app/models/concerns/bulkrax/has_matchers.rb | 2 +- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/app/factories/bulkrax/object_factory.rb b/app/factories/bulkrax/object_factory.rb index 34e9b07a0..dc31ba19e 100644 --- a/app/factories/bulkrax/object_factory.rb +++ b/app/factories/bulkrax/object_factory.rb @@ -93,7 +93,7 @@ def find rescue Valkyrie::Persistence::ObjectNotFoundError false ensure - return search_by_identifier if attributes[work_identifier].present? + search_by_identifier if attributes[work_identifier].present? end def find_by_id diff --git a/app/factories/bulkrax/valkyrie_object_factory.rb b/app/factories/bulkrax/valkyrie_object_factory.rb index 9cbb5d9c7..28af180cb 100644 --- a/app/factories/bulkrax/valkyrie_object_factory.rb +++ b/app/factories/bulkrax/valkyrie_object_factory.rb @@ -10,9 +10,7 @@ def self.schema_properties(klass) @schema_properties_map ||= {} klass_key = klass.name - unless @schema_properties_map.has_key?(klass_key) - @schema_properties_map[klass_key] = klass.schema.map { |k| k.name.to_s } - end + @schema_properties_map[klass_key] = klass.schema.map { |k| k.name.to_s } unless @schema_properties_map.key?(klass_key) @schema_properties_map[klass_key] end @@ -42,25 +40,25 @@ def search_by_identifier def create attrs = transform_attributes - .merge(alternate_ids: [source_identifier_value]) - .symbolize_keys + .merge(alternate_ids: [source_identifier_value]) + .symbolize_keys # temporary workaround just to see if we can get the import to work - attrs.merge!(title: ['']) if attrs[:title].blank? - attrs.merge!(creator: ['']) if attrs[:creator].blank? + attrs[:title] = [''] if attrs[:title].blank? + attrs[:creator] = [''] if attrs[:creator].blank? cx = Hyrax::Forms::ResourceForm.for(klass.new).prepopulate! cx.validate(attrs) result = transaction - .with_step_args( + .with_step_args( # "work_resource.add_to_parent" => {parent_id: @related_parents_parsed_mapping, user: @user}, - "work_resource.add_bulkrax_files" => {files: get_s3_files(remote_files: attributes["remote_files"]), user: @user}, - "change_set.set_user_as_depositor" => {user: @user}, - "work_resource.change_depositor" => {user: @user}, + "work_resource.add_bulkrax_files" => { files: get_s3_files(remote_files: attributes["remote_files"]), user: @user }, + "change_set.set_user_as_depositor" => { user: @user }, + "work_resource.change_depositor" => { user: @user }, 'work_resource.save_acl' => { permissions_params: [attrs.try('visibility') || 'open'].compact } ) - .call(cx) + .call(cx) if result.failure? msg = result.failure[0].to_s @@ -84,26 +82,26 @@ def update cx.validate(attrs) result = update_transaction - .with_step_args( - "work_resource.add_bulkrax_files" => {files: get_s3_files(remote_files: attributes["remote_files"]), user: @user} + .with_step_args( + "work_resource.add_bulkrax_files" => { files: get_s3_files(remote_files: attributes["remote_files"]), user: @user } # TODO: uncomment when we upgrade Hyrax 4.x # 'work_resource.save_acl' => { permissions_params: [attrs.try('visibility') || 'open'].compact } ) - .call(cx) + .call(cx) @object = result.value! end def get_s3_files(remote_files: {}) if remote_files.blank? - Hyrax.logger.info "No remote files listed for #{attributes["source_identifier"]}" + Hyrax.logger.info "No remote files listed for #{attributes['source_identifier']}" return [] end s3_bucket_name = ENV.fetch("STAGING_AREA_S3_BUCKET", "comet-staging-area-#{Rails.env}") s3_bucket = Rails.application.config.staging_area_s3_connection - .directories.get(s3_bucket_name) + .directories.get(s3_bucket_name) remote_files.map { |r| r["url"] }.map do |key| s3_bucket.files.get(key) @@ -132,18 +130,18 @@ def apply_depositor_metadata(object, user) # @Override remove branch for FileSets replace validation with errors def new_remote_files @new_remote_files ||= if @object.is_a? FileSet - parsed_remote_files.select do |file| - # is the url valid? - is_valid = file[:url]&.match(URI::ABS_URI) - # does the file already exist - is_existing = @object.import_url && @object.import_url == file[:url] - is_valid && !is_existing - end - else - parsed_remote_files.select do |file| - file[:url]&.match(URI::ABS_URI) - end - end + parsed_remote_files.select do |file| + # is the url valid? + is_valid = file[:url]&.match(URI::ABS_URI) + # does the file already exist + is_existing = @object.import_url && @object.import_url == file[:url] + is_valid && !is_existing + end + else + parsed_remote_files.select do |file| + file[:url]&.match(URI::ABS_URI) + end + end end # @Override Destroy existing files with Hyrax::Transactions @@ -152,8 +150,8 @@ def destroy_existing_files existing_files.each do |fs| Hyrax::Transactions::Container["file_set.destroy"] - .with_step_args("file_set.remove_from_work" => {user: @user}, - "file_set.delete" => {user: @user}) + .with_step_args("file_set.remove_from_work" => { user: @user }, + "file_set.delete" => { user: @user }) .call(fs) .value! end diff --git a/app/models/bulkrax/importer.rb b/app/models/bulkrax/importer.rb index 9d88f552d..c577638ba 100644 --- a/app/models/bulkrax/importer.rb +++ b/app/models/bulkrax/importer.rb @@ -125,8 +125,8 @@ def last_run def failed_statuses @failed_statuses ||= Bulkrax::Status.latest_by_statusable - .includes(:statusable) - .where('bulkrax_statuses.statusable_id IN (?) AND bulkrax_statuses.statusable_type = ? AND status_message = ?', self.entries.pluck(:id), 'Bulkrax::Entry', 'Failed') + .includes(:statusable) + .where('bulkrax_statuses.statusable_id IN (?) AND bulkrax_statuses.statusable_type = ? AND status_message = ?', self.entries.pluck(:id), 'Bulkrax::Entry', 'Failed') end def failed_entries @@ -134,17 +134,16 @@ def failed_entries end def failed_messages - failed_statuses.inject({}) do |i, e| + failed_statuses.each_with_object({}) do |e, i| i[e.error_message] ||= [] i[e.error_message] << e.id - i end end def completed_statuses @completed_statuses ||= Bulkrax::Status.latest_by_statusable - .includes(:statusable) - .where('bulkrax_statuses.statusable_id IN (?) AND bulkrax_statuses.statusable_type = ? AND status_message = ?', self.entries.pluck(:id), 'Bulkrax::Entry', 'Complete') + .includes(:statusable) + .where('bulkrax_statuses.statusable_id IN (?) AND bulkrax_statuses.statusable_type = ? AND status_message = ?', self.entries.pluck(:id), 'Bulkrax::Entry', 'Complete') end def completed_entries diff --git a/app/models/concerns/bulkrax/has_matchers.rb b/app/models/concerns/bulkrax/has_matchers.rb index f0c547e75..3d50683b5 100644 --- a/app/models/concerns/bulkrax/has_matchers.rb +++ b/app/models/concerns/bulkrax/has_matchers.rb @@ -169,7 +169,7 @@ def ar_multiple?(field) end def valkyrie_multiple?(field) - # TODO there has got to be a better way. Only array types have 'of' + # TODO: there has got to be a better way. Only array types have 'of' sym_field = field.to_sym factory_class.schema.key(sym_field).respond_to?(:of) if factory_class.fields.include?(sym_field) end