Class: JobsController

Inherits:
ApplicationController show all
Includes:
ExportHelper
Defined in:
frontend/app/controllers/jobs_controller.rb

Constant Summary

Constants included from Searchable

Searchable::ABSTRACT

Instance Method Summary collapse

Methods included from ExportHelper

#csv_response, #xml_response

Methods inherited from ApplicationController

#archivesspace, can_access?, permission_mappings, set_access_control

Methods included from JsonHelper

#merge_notes, #process_json_notes

Methods included from Searchable

#default_search_opts, #get_filter_years, #handle_results, #html_notes, #process_results, #process_search_results, #repo_context, #search_terms, #set_up_advanced_search, #set_up_and_run_search, #set_up_search, #strip_facet_fields

Methods included from HandleFaceting

#fetch_only_facets, #get_pretty_facet_value, #strip_facets

Methods included from ManipulateNode

#inheritance, #process_mixed_content, #strip_mixed_content

Instance Method Details

#cancelObject



78
79
80
81
82
# File 'frontend/app/controllers/jobs_controller.rb', line 78

def cancel
  Job.cancel(params[:id])

  redirect_to :action => :show
end

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 'frontend/app/controllers/jobs_controller.rb', line 22

def create
  @job_type = params['job']['job_type']

  job_data = params['job']

  # Knock out the _resolved parameter because it's often very large
  # and clean up the job data to match the schema types.
  job_data = ASUtils.recursive_reject_key(job_data) { |k| k === '_resolved' }
  job_data = cleanup_params_for_schema(job_data, JSONModel(@job_type.intern).schema)

  files = Hash[Array(params['files']).reject(&:blank?).map {|file|
                                [file.original_filename, file.tempfile]}]

  job_params = ASUtils.recursive_reject_key(params['job']['job_params']) { |k| k === '_resolved' }

  job_data["repo_id"] ||= session[:repo_id]
  begin
    job = Job.new(@job_type, job_data, files,
                                job_params
                 )
    uploaded = job.upload

    if (params['ajax'])
      if params[:iframePOST] # IE saviour. Render the form in a textarea for the AjaxPost plugin to pick out.
        render :plain => "<textarea data-type='json'>#{uploaded.to_json}</textarea>"
      else
        render :json => uploaded
      end
    else
      redirect_to :action => :show, :id => JSONModel(:job).id_for(uploaded['uri'])
    end

  rescue JSONModel::ValidationException => e
    @exceptions = e.invalid_object._exceptions
    @job = e.invalid_object
    @import_types = import_types
    @report_data = JSONModel::HTTP::get_json("/reports")

    params['job_type'] = @job_type

    render :new, :status => 500
  end
end

#current_recordObject



67
68
69
# File 'frontend/app/controllers/jobs_controller.rb', line 67

def current_record
  @job
end

#download_fileObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'frontend/app/controllers/jobs_controller.rb', line 110

def download_file
  @job = JSONModel(:job).find(params[:job_id], "resolve[]" => "repository")

  # this is a hacky solution
  # there should be a better way for jobs to specify file names
  if @job['job_type'] == 'report_job'
    filename_end = "#{@job.job['report_type']}_#{@job['time_submitted'].split[0]}"
  else
    filename_end = "file_#{params[:id].to_s}"
  end

  url = "/repositories/#{JSONModel::repository}/jobs/#{params[:job_id]}/output_files/#{params[:id]}"
  stream_file(url, {:format => download_file_format(@job), :filename => "job_#{params[:job_id].to_s}_#{filename_end}" } )
end

#indexObject



9
10
11
# File 'frontend/app/controllers/jobs_controller.rb', line 9

def index
  @search_data = Search.for_type(session[:repo_id], "job", params_for_backend_search.merge({"facet[]" => SearchResultData.JOB_FACETS}))
end

#logObject



85
86
87
88
89
90
91
# File 'frontend/app/controllers/jobs_controller.rb', line 85

def log
  self.response_body = Enumerator.new do |y|
    Job.log(params[:id], params[:offset] || 0) do |response|
      y << response.body
    end
  end
end

#newObject



13
14
15
16
17
18
19
20
# File 'frontend/app/controllers/jobs_controller.rb', line 13

def new
  @job = JSONModel(:job).new._always_valid!
  @import_types = import_types
  @report_data = JSONModel::HTTP::get_json("/reports")

  # handle any options passed through via parameters
  @job_type = params['job_type']
end

#recordsObject



126
127
128
129
# File 'frontend/app/controllers/jobs_controller.rb', line 126

def records
  @search_data = Job.records(params[:id], params[:page] || 1)
  render_aspace_partial :partial => "jobs/job_records"
end

#showObject



72
73
74
75
# File 'frontend/app/controllers/jobs_controller.rb', line 72

def show
  @job = JSONModel(:job).find(params[:id], "resolve[]" => "repository")
  @files = JSONModel::HTTP::get_json("#{@job['uri']}/output_files")
end

#statusObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'frontend/app/controllers/jobs_controller.rb', line 94

def status
  job = JSONModel(:job).find(params[:id])

  json = {
      :status => job.status
  }

  if job.status === "queued"
    json[:queue_position] = job.queue_position
    json[:queue_position_message] = job.queue_position === 0 ? I18n.t("job._frontend.messages.queue_position_next") : I18n.t("job._frontend.messages.queue_position", :position => (job.queue_position+1).ordinalize)
  end

  render :json => json
end