Class: ArchivalObjectsController
Constant Summary
Constants included
from Searchable
Searchable::ABSTRACT
Instance Method Summary
collapse
#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
#fetch_only_facets, #get_pretty_facet_value, #strip_facets
#inheritance, #process_mixed_content, #strip_mixed_content
Instance Method Details
#accept_children ⇒ Object
133
134
135
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 133
def accept_children
handle_accept_children(JSONModel(:archival_object))
end
|
#add_children ⇒ Object
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 234
def add_children
@parent = JSONModel(:archival_object).find(params[:id])
@resource_uri = @parent['resource']['ref']
if params[:archival_record_children].blank? or params[:archival_record_children]["children"].blank?
@children = ArchivalObjectChildren.new
flash.now[:error] = I18n.t("rde.messages.no_rows")
else
children_data = cleanup_params_for_schema(params[:archival_record_children], JSONModel(:archival_record_children).schema)
begin
@children = ArchivalObjectChildren.from_hash(children_data, false)
if params["validate_only"] == "true"
@exceptions = @children.children.collect {|c| JSONModel(:archival_object).from_hash(c, false)._exceptions}
error_count = @exceptions.select {|e| !e.empty?}.length
if error_count > 0
flash.now[:error] = I18n.t("rde.messages.rows_with_errors", :count => error_count)
else
flash.now[:success] = I18n.t("rde.messages.rows_no_errors")
end
return render_aspace_partial :partial => "shared/rde"
else
@children.save(:archival_object_id => @parent.id)
end
return render :plain => I18n.t("rde.messages.success")
rescue JSONModel::ValidationException => e
@exceptions = @children.children.collect {|c| JSONModel(:archival_object).from_hash(c, false)._exceptions}
if @exceptions.all?(&:blank?)
e.errors.each { |key, vals| flash.now[:error] = "#{key} : #{vals.join('<br/>')}" }
else
flash.now[:error] = I18n.t("rde.messages.rows_with_errors", :count => @exceptions.select {|e| !e.empty?}.length)
end
end
end
render_aspace_partial :partial => "shared/rde"
end
|
#create ⇒ Object
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
78
79
80
81
82
83
84
85
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 44
def create
handle_crud(:instance => :archival_object,
:find_opts => find_opts,
:on_invalid => ->() {
if inline?
render_aspace_partial :partial => "new_inline"
else
render action: :new
end
},
:on_valid => ->(id) {
success_message = @archival_object.parent ?
I18n.t("archival_object._frontend.messages.created_with_parent", JSONModelI18nWrapper.new(:archival_object => @archival_object, :resource => @archival_object['resource']['_resolved'], :parent => @archival_object['parent']['_resolved']).enable_parse_mixed_content!(url_for(:root))) :
I18n.t("archival_object._frontend.messages.created", JSONModelI18nWrapper.new(:archival_object => @archival_object, :resource => @archival_object['resource']['_resolved']).enable_parse_mixed_content!(url_for(:root)))
if params.has_key?(:plus_one)
flash[:success] = success_message
else
flash.now[:success] = success_message
end
if @archival_object["is_slug_auto"] == false &&
@archival_object["slug"] == nil &&
params["archival_object"] &&
params["archival_object"]["is_slug_auto"] == "1"
if params.has_key?(:plus_one)
flash[:warning] = I18n.t("slug.autogen_disabled")
else
flash.now[:warning] = I18n.t("slug.autogen_disabled")
end
end
if inline?
render_aspace_partial :partial => "archival_objects/edit_inline"
else
id = ArchivalObject.id_for(@archival_object.uri)
resource_id = Resource.id_for(@archival_object.resource['ref'])
redirect_to controller: :resources, action: :edit, id: resource_id, anchor: "tree::archival_object_#{id}"
end
})
end
|
#current_record ⇒ Object
115
116
117
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 115
def current_record
@archival_object
end
|
#defaults ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 138
def defaults
defaults = DefaultValues.get 'archival_object'
values = defaults ? defaults.form_values : {}
@archival_object = JSONModel(:archival_object).new(values)._always_valid!
@archival_object.display_string = I18n.t("default_values.form_title.archival_object")
render "defaults"
end
|
#delete ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 196
def delete
archival_object = JSONModel(:archival_object).find(params[:id])
previous_record = begin
JSONModel::HTTP.get_json("#{archival_object['uri']}/previous")
rescue RecordNotFound
nil
end
begin
archival_object.delete
rescue ConflictException => e
flash[:error] = I18n.t("archival_object._frontend.messages.delete_conflict", :error => I18n.t("errors.#{e.conflicts}", :default => e.message))
resolver = Resolver.new(archival_object['uri'])
return redirect_to resolver.view_uri
end
flash[:success] = I18n.t("archival_object._frontend.messages.deleted", JSONModelI18nWrapper.new(:archival_object => archival_object).enable_parse_mixed_content!(url_for(:root)))
if previous_record
redirect_to :controller => :resources, :action => :show, :id => JSONModel(:resource).id_for(archival_object['resource']['ref']), :anchor => "tree::archival_object_#{JSONModel(:archival_object).id_for(previous_record['uri'])}"
else
resolver = Resolver.new(archival_object['resource']['ref'])
redirect_to resolver.view_uri
end
end
|
#edit ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 30
def edit
new_find_opts = find_opts
new_find_opts["resolve[]"].push("top_container::container_locations")
@archival_object = JSONModel(:archival_object).find(params[:id], new_find_opts)
if @archival_object.suppressed
return redirect_to(:action => :show, :id => params[:id], :inline => params[:inline])
end
render_aspace_partial :partial => "archival_objects/edit_inline" if inline?
end
|
#models_in_graph ⇒ Object
340
341
342
343
344
345
346
347
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 340
def models_in_graph
list_uri = JSONModel(:archival_object).uri_for(params[:id]) + "/models_in_graph"
list = JSONModel::HTTP.get_json(list_uri)
render :json => list.select { |type| type != "lang_material" }.map {|type|
[type, I18n.t("#{type == 'archival_object' ? 'resource_component' : type}._singular")]
}
end
|
#new ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 9
def new
@archival_object = ArchivalObject.new._always_valid!
@archival_object.parent = {'ref' => ArchivalObject.uri_for(params[:archival_object_id])} if params.has_key?(:archival_object_id)
@archival_object.resource = {'ref' => Resource.uri_for(params[:resource_id])} if params.has_key?(:resource_id)
@archival_object.position = params[:position]
if defaults = user_defaults('archival_object')
@archival_object.update(defaults.values)
end
if params[:accession_id]
acc = Accession.find(params[:accession_id], find_opts)
@archival_object.populate_from_accession(acc)
flash.now[:info] = I18n.t("archival_object._frontend.messages.spawned", JSONModelI18nWrapper.new(:accession => acc).enable_parse_mixed_content!(url_for(:root)))
flash[:spawned_from_accession] = acc.id
end
return render_aspace_partial :partial => "archival_objects/new_inline" if inline?
end
|
#publish ⇒ Object
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 281
def publish
@archival_object = JSONModel(:archival_object).find(params[:id], find_opts)
response = JSONModel::HTTP.post_form("#{@archival_object.uri}/publish")
if response.code == '200'
flash[:success] = I18n.t("archival_object._frontend.messages.published", JSONModelI18nWrapper.new(:archival_object => @archival_object).enable_parse_mixed_content!(url_for(:root)))
else
flash[:error] = ASUtils.json_parse(response.body)['error'].to_s
end
redirect_to "#{request.referer}#tree::archival_object_#{params[:id]}"
end
|
#rde ⇒ Object
224
225
226
227
228
229
230
231
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 224
def rde
@parent = JSONModel(:archival_object).find(params[:id])
@resource_uri = @parent['resource']['ref']
@children = ArchivalObjectChildren.new
@exceptions = []
render_aspace_partial :partial => "shared/rde"
end
|
#show ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 119
def show
@resource_id = params['resource_id']
new_find_opts = find_opts
new_find_opts["resolve[]"].push("top_container::container_locations")
@archival_object = JSONModel(:archival_object).find(params[:id], new_find_opts)
flash.now[:info] = I18n.t("archival_object._frontend.messages.suppressed_info", JSONModelI18nWrapper.new(:archival_object => @archival_object).enable_parse_mixed_content!(url_for(:root))) if @archival_object.suppressed
render_aspace_partial :partial => "archival_objects/show_inline" if inline?
end
|
#suppress ⇒ Object
322
323
324
325
326
327
328
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 322
def suppress
archival_object = JSONModel(:archival_object).find(params[:id])
archival_object.set_suppressed(true)
flash[:success] = I18n.t("archival_object._frontend.messages.suppressed", JSONModelI18nWrapper.new(:archival_object => archival_object).enable_parse_mixed_content!(url_for(:root)))
redirect_to(:controller => :resources, :action => :show, :id => JSONModel(:resource).id_for(archival_object['resource']['ref']), :anchor => "tree::archival_object_#{params[:id]}")
end
|
#transfer ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 171
def transfer
begin
post_data = {
:target_resource => params["transfer"]["ref"],
:component => JSONModel(:archival_object).uri_for(params[:id])
}
response = JSONModel::HTTP.post_form("/repositories/#{session[:repo_id]}/component_transfers", post_data)
if response.code == '200'
@archival_object = JSONModel(:archival_object).find(params[:id], find_opts)
flash[:success] = I18n.t("archival_object._frontend.messages.transfer_success", JSONModelI18nWrapper.new(:archival_object => @archival_object, :resource => @archival_object['resource']['_resolved']).enable_parse_mixed_content!(url_for(:root)))
redirect_to :controller => :resources, :action => :edit, :id => JSONModel(:resource).id_for(params["transfer"]["ref"]), :anchor => "tree::archival_object_#{params[:id]}"
else
raise ASUtils.json_parse(response.body)['error'].to_s
end
rescue Exception => e
flash[:error] = I18n.t("archival_object._frontend.messages.transfer_error", :exception => e)
redirect_to :controller => :resources, :action => :edit, :id => params["transfer"]["current_resource_id"], :anchor => "tree::archival_object_#{params[:id]}"
end
end
|
#unpublish ⇒ Object
296
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 296
def unpublish
@archival_object = JSONModel(:archival_object).find(params[:id], find_opts)
response = JSONModel::HTTP.post_form("#{@archival_object.uri}/unpublish")
if response.code == '200'
flash[:success] = I18n.t("archival_object._frontend.messages.unpublished", JSONModelI18nWrapper.new(:archival_object => @archival_object).enable_parse_mixed_content!(url_for(:root)))
else
flash[:error] = ASUtils.json_parse(response.body)['error'].to_s
end
redirect_to "#{request.referer}#tree::archival_object_#{params[:id]}"
end
|
#unsuppress ⇒ Object
331
332
333
334
335
336
337
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 331
def unsuppress
archival_object = JSONModel(:archival_object).find(params[:id])
archival_object.set_suppressed(false)
flash[:success] = I18n.t("archival_object._frontend.messages.unsuppressed", JSONModelI18nWrapper.new(:archival_object => archival_object).enable_parse_mixed_content!(url_for(:root)))
redirect_to(:controller => :resources, :action => :show, :id => JSONModel(:resource).id_for(archival_object['resource']['ref']), :anchor => "tree::archival_object_#{params[:id]}")
end
|
#update ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 88
def update
params['archival_object']['position'] = params['archival_object']['position'].to_i if params['archival_object']['position']
@archival_object = JSONModel(:archival_object).find(params[:id], find_opts)
resource = @archival_object['resource']['_resolved']
parent = @archival_object['parent'] ? @archival_object['parent']['_resolved'] : false
handle_crud(:instance => :archival_object,
:obj => @archival_object,
:on_invalid => ->() { return render_aspace_partial :partial => "edit_inline" },
:on_valid => ->(id) {
flash.now[:success] = parent ?
I18n.t("archival_object._frontend.messages.updated_with_parent", JSONModelI18nWrapper.new(:archival_object => @archival_object, :resource => @archival_object['resource']['_resolved'], :parent => parent).enable_parse_mixed_content!(url_for(:root))) :
I18n.t("archival_object._frontend.messages.updated", JSONModelI18nWrapper.new(:archival_object => @archival_object, :resource => @archival_object['resource']['_resolved']).enable_parse_mixed_content!(url_for(:root)))
if @archival_object["is_slug_auto"] == false &&
@archival_object["slug"] == nil &&
params["archival_object"] &&
params["archival_object"]["is_slug_auto"] == "1"
flash.now[:warning] = I18n.t("slug.autogen_disabled")
end
render_aspace_partial :partial => "edit_inline"
})
end
|
#update_defaults ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 151
def update_defaults
begin
DefaultValues.from_hash({
"record_type" => "archival_object",
"lock_version" => params[:archival_object].delete('lock_version'),
"defaults" => cleanup_params_for_schema(
params[:archival_object],
JSONModel(:archival_object).schema
)
}).save
flash[:success] = I18n.t("default_values.messages.defaults_updated")
redirect_to :controller => :archival_objects, :action => :defaults
rescue Exception => e
flash[:error] = e.message
redirect_to :controller => :archival_objects, :action => :defaults
end
end
|
#validate_rows ⇒ Object
311
312
313
314
315
316
317
318
319
|
# File 'frontend/app/controllers/archival_objects_controller.rb', line 311
def validate_rows
row_data = cleanup_params_for_schema(params[:archival_record_children], JSONModel(:archival_record_children).schema)
aoc = ArchivalObjectChildren.from_hash(row_data, false, true)
render :json => aoc.children.collect {|c| JSONModel(:archival_object).from_hash(c, false)._exceptions}
end
|