Class: BatchUpdateJob

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

Overview

Resque job that updates files uploaded via the BatchController

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, batch_id, title, file_attributes, visibility) ⇒ BatchUpdateJob

Called from BatchController

Parameters:

  • login (String)

    of the current user

  • batch_id (String)

    for the Batch object containing the files

  • title (Hash)

    contains the filename of each file

  • file_attributes (Hash)

    applied to every file in the batch

  • visibility (String)


19
20
21
22
23
24
25
# File 'app/jobs/batch_update_job.rb', line 19

def initialize(, batch_id, title, file_attributes, visibility)
  @login = 
  @batch_id = batch_id
  @title = title || {}
  @file_attributes = file_attributes
  @visibility = visibility
end

Instance Attribute Details

#batch_idObject (readonly)

Returns the value of attribute batch_id.



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

def batch_id
  @batch_id
end

#denied=(value) ⇒ Object

Sets the attribute denied

Parameters:

  • value

    the value to set the attribute denied to.



11
12
13
# File 'app/jobs/batch_update_job.rb', line 11

def denied=(value)
  @denied = value
end

#file_attributesObject (readonly)

Returns the value of attribute file_attributes.



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

def file_attributes
  @file_attributes
end

#loginObject (readonly)

Returns the value of attribute login.



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

def 
  @login
end

#saved=(value) ⇒ Object

Sets the attribute saved

Parameters:

  • value

    the value to set the attribute saved to.



11
12
13
# File 'app/jobs/batch_update_job.rb', line 11

def saved=(value)
  @saved = value
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



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

def visibility
  @visibility
end

Instance Method Details

#apply_metadata(gf) ⇒ Object

Updates the metadata for one file in the batch. Override this method if you wish to perform additional operations to these files.

Parameters:



36
37
38
39
40
# File 'app/jobs/batch_update_job.rb', line 36

def (gf)
  gf.title = title[gf.id] if title[gf.id]
  gf.attributes = file_attributes
  gf.visibility = visibility
end

#queue_additional_jobs(gf) ⇒ Object

Queues jobs to run on each file. By default, this includes ContentUpdateEventJob, but can be augmented with additional custom jobs

Parameters:



45
46
47
48
# File 'app/jobs/batch_update_job.rb', line 45

def queue_additional_jobs(gf)
  Sufia.queue.push(ContentUpdateEventJob.new(gf.id, ))
  Sufia.queue.push(ResolrizeGenericFileJob.new(gf.id)) unless Sufia.config.collection_facet.nil?
end

#queue_nameObject



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

def queue_name
  :batch_update
end

#runObject



27
28
29
30
31
# File 'app/jobs/batch_update_job.rb', line 27

def run
  batch.generic_files.each { |gf| update_file(gf) }
  batch.update(status: ["Complete"])
  send_user_message
end

#send_user_failure_messageObject



55
56
57
58
# File 'app/jobs/batch_update_job.rb', line 55

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

#send_user_success_messageObject



50
51
52
53
# File 'app/jobs/batch_update_job.rb', line 50

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