Class: BatchUpdateJob
- Inherits:
-
Object
- Object
- BatchUpdateJob
- Includes:
- Hydra::PermissionsQuery
- Defined in:
- lib/sufia/models/jobs/batch_update_job.rb
Instance Attribute Summary collapse
-
#batch_id ⇒ Object
Returns the value of attribute batch_id.
-
#file_attributes ⇒ Object
Returns the value of attribute file_attributes.
-
#login ⇒ Object
Returns the value of attribute login.
-
#title ⇒ Object
Returns the value of attribute title.
-
#visibility ⇒ Object
Returns the value of attribute visibility.
Instance Method Summary collapse
- #file_list(files) ⇒ Object
-
#initialize(login, params) ⇒ BatchUpdateJob
constructor
A new instance of BatchUpdateJob.
- #queue_name ⇒ Object
- #run ⇒ Object
- #update_file(gf, user) ⇒ Object
Constructor Details
#initialize(login, params) ⇒ BatchUpdateJob
Returns a new instance of BatchUpdateJob.
11 12 13 14 15 16 17 18 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 11 def initialize(login, params) self.login = login self.title = params[:title] self.file_attributes = params[:generic_file] self.visibility = params[:visibility] self.batch_id = params[:id] end |
Instance Attribute Details
#batch_id ⇒ Object
Returns the value of attribute batch_id.
9 10 11 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 9 def batch_id @batch_id end |
#file_attributes ⇒ Object
Returns the value of attribute file_attributes.
9 10 11 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 9 def file_attributes @file_attributes end |
#login ⇒ Object
Returns the value of attribute login.
9 10 11 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 9 def login @login end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 9 def title @title end |
#visibility ⇒ Object
Returns the value of attribute visibility.
9 10 11 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 9 def visibility @visibility end |
Instance Method Details
#file_list(files) ⇒ Object
66 67 68 69 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 66 def file_list ( files) return files.map {|gf| '<a href="'+Sufia::Engine.routes.url_helpers.generic_files_path+'/'+gf.noid+'">'+gf.to_s+'</a>'}.join(', ') end |
#queue_name ⇒ Object
5 6 7 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 5 def queue_name :batch_update end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 20 def run batch = Batch.find_or_create(self.batch_id) user = User.find_by_user_key(self.login) @saved = [] @denied = [] batch.generic_files.each do |gf| update_file(gf, user) end batch.update_attributes({status:["Complete"]}) job_user = User.batchuser() = '<span class="batchid ui-helper-hidden">ss-'+batch.noid+'</span>The file(s) '+ file_list(@saved)+ " have been saved." unless @saved.empty? job_user.(user, , 'Batch upload complete') unless @saved.empty? = '<span class="batchid ui-helper-hidden">'+batch.noid+'</span>The file(s) '+ file_list(@denied)+" could not be updated. You do not have sufficient privileges to edit it." unless @denied.empty? job_user.(user, , 'Batch upload permission denied') unless @denied.empty? end |
#update_file(gf, user) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sufia/models/jobs/batch_update_job.rb', line 41 def update_file(gf, user) unless user.can? :edit, gf logger.error "User #{user.user_key} DENIED access to #{gf.pid}!" @denied << gf return end gf.title = title[gf.pid] if title[gf.pid] rescue gf.label gf.attributes=file_attributes gf.visibility= visibility save_tries = 0 begin gf.save! rescue RSolr::Error::Http => error save_tries += 1 logger.warn "BatchUpdateJob caught RSOLR error on #{gf.pid}: #{error.inspect}" # fail for good if the tries is greater than 3 raise error if save_tries >=3 sleep 0.01 retry end # Sufia.queue.push(ContentUpdateEventJob.new(gf.pid, login)) @saved << gf end |