Class: JobsController
Instance Method Summary
collapse
#archivesspace, can_access?, permission_mappings, set_access_control
Instance Method Details
#cancel ⇒ Object
91
92
93
94
95
|
# File 'frontend/app/controllers/jobs_controller.rb', line 91
def cancel
Job.cancel(params[:id])
redirect_to :action => :show
end
|
#create ⇒ Object
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
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'frontend/app/controllers/jobs_controller.rb', line 32
def create
@job_type = params['job']['job_type']
job_data = params['job']
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]
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
rescue Exception => e
Rails.logger.error "An unexpected error occurred while creating a job. Please note the following for support: #{job_data}"
end
end
|
#current_record ⇒ Object
80
81
82
|
# File 'frontend/app/controllers/jobs_controller.rb', line 80
def current_record
@job
end
|
#download_file ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'frontend/app/controllers/jobs_controller.rb', line 123
def download_file
@job = JSONModel(:job).find(params[:job_id], "resolve[]" => "repository")
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
|
#index ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'frontend/app/controllers/jobs_controller.rb', line 9
def index
respond_to do |format|
format.html {
@search_data = Search.for_type(session[:repo_id], "job", params_for_backend_search.merge({"facet[]" => SearchResultData.JOB_FACETS}))
}
format.csv {
search_params = params_for_backend_search.merge({"facet[]" => SearchResultData.JOB_FACETS})
search_params["type[]"] = "job"
uri = "/repositories/#{session[:repo_id]}/search"
csv_response( uri, Search.build_filters(search_params), "#{I18n.t('job._plural').downcase}." )
}
end
end
|
#log ⇒ Object
98
99
100
101
102
103
104
|
# File 'frontend/app/controllers/jobs_controller.rb', line 98
def log
self.response_body = Enumerator.new do |y|
Job.log(params[:id], params[:offset] || 0) do |response|
y << response.body
end
end
end
|
#new ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'frontend/app/controllers/jobs_controller.rb', line 23
def new
@job = JSONModel(:job).new._always_valid!
@import_types = import_types
@report_data = JSONModel::HTTP::get_json("/reports")
@job_type = params['job_type']
end
|
#records ⇒ Object
139
140
141
142
|
# File 'frontend/app/controllers/jobs_controller.rb', line 139
def records
@search_data = Job.records(params[:id], params[:page] || 1)
render_aspace_partial :partial => "jobs/job_records"
end
|
#show ⇒ Object
85
86
87
88
|
# File 'frontend/app/controllers/jobs_controller.rb', line 85
def show
@job = JSONModel(:job).find(params[:id], "resolve[]" => "repository")
@files = JSONModel::HTTP::get_json("#{@job['uri']}/output_files")
end
|
#status ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'frontend/app/controllers/jobs_controller.rb', line 107
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 ? t("job._frontend.messages.queue_position_next") : t("job._frontend.messages.queue_position", :position => (job.queue_position+1).ordinalize)
end
render :json => json
end
|