Skip to content

Commit

Permalink
Appeasing rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyf committed Jan 24, 2024
1 parent 2f65930 commit b346c74
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/factories/bulkrax/object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 29 additions & 31 deletions app/factories/bulkrax/valkyrie_object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions app/models/bulkrax/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,25 @@ 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
@failed_entries ||= failed_statuses.map(&:statusable)
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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/bulkrax/has_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b346c74

Please sign in to comment.