Class: BatchUpdateJob

Inherits:
Object
  • Object
show all
Includes:
Hydra::PermissionsQuery, Sufia::Messages
Defined in:
app/jobs/batch_update_job.rb

Instance Attribute Summary collapse

Attributes included from Sufia::Messages

#output_buffer

Instance Method Summary collapse

Methods included from Sufia::Messages

#failure_subject, #file_list, #link_to_file, #multiple_failure, #multiple_success, #single_failure, #single_success, #success_subject

Constructor Details

#initialize(login, params) ⇒ BatchUpdateJob

Returns a new instance of BatchUpdateJob.



11
12
13
14
15
16
17
18
19
# File 'app/jobs/batch_update_job.rb', line 11

def initialize(, params)
  self. = 
  self.title = params[:title]
  self.file_attributes = params[:generic_file]
  self.visibility = params[:visibility]
  self.batch_id = params[:id]
  self.saved = []
  self.denied = []
end

Instance Attribute Details

#batch_idObject

Returns the value of attribute batch_id.



9
10
11
# File 'app/jobs/batch_update_job.rb', line 9

def batch_id
  @batch_id
end

#deniedObject

Returns the value of attribute denied.



9
10
11
# File 'app/jobs/batch_update_job.rb', line 9

def denied
  @denied
end

#file_attributesObject

Returns the value of attribute file_attributes.



9
10
11
# File 'app/jobs/batch_update_job.rb', line 9

def file_attributes
  @file_attributes
end

#loginObject

Returns the value of attribute login.



9
10
11
# File 'app/jobs/batch_update_job.rb', line 9

def 
  @login
end

#savedObject

Returns the value of attribute saved.



9
10
11
# File 'app/jobs/batch_update_job.rb', line 9

def saved
  @saved
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'app/jobs/batch_update_job.rb', line 9

def title
  @title
end

#visibilityObject

Returns the value of attribute visibility.



9
10
11
# File 'app/jobs/batch_update_job.rb', line 9

def visibility
  @visibility
end

Instance Method Details

#queue_nameObject



5
6
7
# File 'app/jobs/batch_update_job.rb', line 5

def queue_name
  :batch_update
end

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/jobs/batch_update_job.rb', line 21

def run
  batch = Batch.find_or_create(self.batch_id)
  user = User.find_by_user_key(self.)

  batch.generic_files.each do |gf|
    update_file(gf, user)
  end
  batch.update_attributes({status:["Complete"]})
  if denied.empty?
    send_user_success_message(user, batch) unless saved.empty?
  else
    send_user_failure_message(user, batch)
  end
end

#send_user_failure_message(user, batch) ⇒ Object



66
67
68
69
# File 'app/jobs/batch_update_job.rb', line 66

def send_user_failure_message user, batch
  message = denied.count > 1 ? multiple_failure(batch.noid, denied) : single_failure(batch.noid, denied.first)
  User.batchuser.send_message(user, message, failure_subject, sanitize_text = false)
end

#send_user_success_message(user, batch) ⇒ Object



61
62
63
64
# File 'app/jobs/batch_update_job.rb', line 61

def send_user_success_message user, batch
  message = saved.count > 1 ? multiple_success(batch.noid, saved) : single_success(batch.noid, saved.first)
  User.batchuser.send_message(user, message, success_subject, sanitize_text = false)
end

#update_file(gf, user) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/jobs/batch_update_job.rb', line 36

def update_file(gf, user)
  unless user.can? :edit, gf
    ActiveFedora::Base.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
    ActiveFedora::Base.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, ))
  saved << gf
end