Class: DigitalObjectsController

Inherits:
ApplicationController show all
Includes:
ExportHelper
Defined in:
frontend/app/controllers/digital_objects_controller.rb,
public/app/controllers/digital_objects_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

#accept_childrenObject



208
209
210
# File 'frontend/app/controllers/digital_objects_controller.rb', line 208

def accept_children
  handle_accept_children(JSONModel(:digital_object))
end

#add_childrenObject



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
279
280
281
282
283
284
285
286
# File 'frontend/app/controllers/digital_objects_controller.rb', line 239

def add_children
  @parent = JSONModel(:digital_object).find(params[:id])
  @digital_object_uri = @parent.uri

  if params[:digital_record_children].blank? or params[:digital_record_children]["children"].blank?

    @children = DigitalObjectChildren.new
    flash.now[:error] = I18n.t("rde.messages.no_rows")

  else
    children_data = cleanup_params_for_schema(params[:digital_record_children], JSONModel(:digital_record_children).schema)

    begin
      @children = DigitalObjectChildren.from_hash(children_data, false)

      if params["validate_only"] == "true"
        @exceptions = @children.children.collect {|c| JSONModel(:digital_object_component).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(:digital_object_id => @parent.id)
      end

      return render :plain => I18n.t("rde.messages.success")
    rescue JSONModel::ValidationException => e
      @exceptions = @children
                    .children
                    .collect {|c| JSONModel(:digital_object_component).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

#createObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'frontend/app/controllers/digital_objects_controller.rb', line 128

def create
  handle_crud(:instance => :digital_object,
              :on_invalid => ->() {
                return render_aspace_partial :partial => "new" if inline?
                render :action => "new"
              },
              :on_valid => ->(id) {
                flash[:success] = I18n.t("digital_object._frontend.messages.created", JSONModelI18nWrapper.new(:digital_object => @digital_object).enable_parse_mixed_content!(url_for(:root)))

                if @digital_object["is_slug_auto"] == false &&
                   @digital_object["slug"] == nil &&
                   params["digital_object"] &&
                   params["digital_object"]["is_slug_auto"] == "1"

                  flash[:warning] = I18n.t("slug.autogen_disabled")
                end

                return render :json => @digital_object.to_hash if inline?
                redirect_to({
                              :controller => :digital_objects,
                              :action => :edit,
                              :id => id
                            })
              })
end

#current_recordObject



28
29
30
# File 'frontend/app/controllers/digital_objects_controller.rb', line 28

def current_record
  @digital_object
end

#defaultsObject



76
77
78
79
80
81
82
83
84
85
86
# File 'frontend/app/controllers/digital_objects_controller.rb', line 76

def defaults
  defaults = DefaultValues.get 'digital_object'

  values = defaults ? defaults.form_values : {:title => I18n.t("digital_object.title_default", :default => "")}

  @digital_object = JSONModel(:digital_object).new(values)._always_valid!

  @form_title = I18n.t("default_values.form_title.digital_object")

  render "defaults"
end

#deleteObject



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'frontend/app/controllers/digital_objects_controller.rb', line 178

def delete
  digital_object = JSONModel(:digital_object).find(params[:id])

  begin
    digital_object.delete
  rescue ConflictException => e
    flash[:error] = I18n.t("digital_object._frontend.messages.delete_conflict", :error => I18n.t("errors.#{e.conflicts}", :default => e.message))
    return redirect_to(:controller => :digital_objects, :action => :show, :id => params[:id])
  end

  flash[:success] = I18n.t("digital_object._frontend.messages.deleted", JSONModelI18nWrapper.new(:digital_object => digital_object).enable_parse_mixed_content!(url_for(:root)))
  redirect_to(:controller => :digital_objects, :action => :index, :deleted_uri => digital_object.uri)
end

#editObject



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

def edit
  flash.keep if not flash.empty? # keep the notices so they display on the subsequent ajax call

  if params[:inline]
    # only fetch the fully resolved record when rendering the full form
    @digital_object = JSONModel(:digital_object).find(params[:id], find_opts)

    if @digital_object.suppressed
      return redirect_to(:action => :show, :id => params[:id], :inline => params[:inline])
    end

    return render_aspace_partial :partial => "digital_objects/edit_inline"
  end

  @digital_object = JSONModel(:digital_object).find(params[:id])
end

#indexObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'frontend/app/controllers/digital_objects_controller.rb', line 13

def index
  respond_to do |format|
    format.html {
      @search_data = Search.for_type(session[:repo_id], params[:include_components]==="true" ? ["digital_object", "digital_object_component"] : "digital_object", params_for_backend_search.merge({"facet[]" => SearchResultData.DIGITAL_OBJECT_FACETS}))
    }
    format.csv {
      search_params = params_for_backend_search.merge({"facet[]" => SearchResultData.DIGITAL_OBJECT_FACETS})
      search_params["type[]"] = params[:include_components] === "true" ? ["digital_object", "digital_object_component"] : [ "digital_object" ]
      uri = "/repositories/#{session[:repo_id]}/search"
      csv_response( uri, Search.build_filters(search_params), "#{I18n.t('digital_object._plural').downcase}." )
    }
  end
end

#mergeObject



213
214
215
216
217
# File 'frontend/app/controllers/digital_objects_controller.rb', line 213

def merge
  handle_merge( params[:refs] ,
                JSONModel(:digital_object).uri_for(params[:id]),
               'digital_object')
end

#newObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'frontend/app/controllers/digital_objects_controller.rb', line 60

def new
  @digital_object = JSONModel(:digital_object).new({:title => I18n.t("digital_object.title_default", :default => "")})._always_valid!

  if user_prefs['default_values']
    defaults = DefaultValues.get 'digital_object'

    if defaults
      @digital_object.update(defaults.values)
      @form_title = "#{I18n.t('actions.new_prefix')} #{I18n.t('digital_object._singular')}"
    end
  end

  return render_aspace_partial :partial => "digital_objects/new" if params[:inline]
end

#node_from_rootObject



312
313
314
315
316
317
# File 'frontend/app/controllers/digital_objects_controller.rb', line 312

def node_from_root
  digital_object_uri = JSONModel(:digital_object).uri_for(params[:id])

  render :json => JSONModel::HTTP.get_json("#{digital_object_uri}/tree/node_from_root",
                                           'node_ids[]' => params[:node_ids])
end

#publishObject



193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'frontend/app/controllers/digital_objects_controller.rb', line 193

def publish
  digital_object = JSONModel(:digital_object).find(params[:id])

  response = JSONModel::HTTP.post_form("#{digital_object.uri}/publish")

  if response.code == '200'
    flash[:success] = I18n.t("digital_object._frontend.messages.published", JSONModelI18nWrapper.new(:digital_object => digital_object).enable_parse_mixed_content!(url_for(:root)))
  else
    flash[:error] = ASUtils.json_parse(response.body)['error'].to_s
  end

  redirect_to request.referer
end

#rdeObject



227
228
229
230
231
232
233
234
235
236
# File 'frontend/app/controllers/digital_objects_controller.rb', line 227

def rde
  flash.clear

  @parent = JSONModel(:digital_object).find(params[:id])
  @digital_object_uri = @parent.uri
  @children = DigitalObjectChildren.new
  @exceptions = []

  render_aspace_partial :partial => "shared/rde"
end

#showObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'frontend/app/controllers/digital_objects_controller.rb', line 33

def show
  flash.keep if not flash.empty? # keep the notices so they display on the subsequent ajax call

  if params[:inline]
    # only fetch the fully resolved record when rendering the full form
    @digital_object = JSONModel(:digital_object).find(params[:id], find_opts)

    flash.now[:info] = I18n.t("digital_object._frontend.messages.suppressed_info", JSONModelI18nWrapper.new(:digital_object => @digital_object).enable_parse_mixed_content!(url_for(:root))) if @digital_object.suppressed

    return render_aspace_partial :partial => "digital_objects/show_inline"
  end

  @digital_object = JSONModel(:digital_object).find(params[:id])
end

#suppressObject



289
290
291
292
293
294
295
# File 'frontend/app/controllers/digital_objects_controller.rb', line 289

def suppress
  digital_object = JSONModel(:digital_object).find(params[:id])
  digital_object.set_suppressed(true)

  flash[:success] = I18n.t("digital_object._frontend.messages.suppressed", JSONModelI18nWrapper.new(:digital_object => digital_object).enable_parse_mixed_content!(url_for(:root)))
  redirect_to(:controller => :digital_objects, :action => :show, :id => params[:id])
end

#transferObject



49
50
51
52
53
54
55
56
57
# File 'frontend/app/controllers/digital_objects_controller.rb', line 49

def transfer
  begin
    handle_transfer(JSONModel(:digital_object))
  rescue ArchivesSpace::TransferConflictException => e
    @transfer_errors = e.errors
    show
    render :action => :show
  end
end

#treeObject



220
221
222
223
224
# File 'frontend/app/controllers/digital_objects_controller.rb', line 220

def tree
  flash.keep # keep the flash... just in case this fires before the form is loaded

  render :json => fetch_tree
end

#tree_nodeObject



319
320
321
322
323
324
325
326
327
328
329
# File 'frontend/app/controllers/digital_objects_controller.rb', line 319

def tree_node
  digital_object_uri = JSONModel(:digital_object).uri_for(params[:id])
  node_uri = if !params[:node].blank?
               params[:node]
             else
               nil
             end

  render :json => JSONModel::HTTP.get_json("#{digital_object_uri}/tree/node",
                                           :node_uri => node_uri)
end

#tree_node_from_rootObject



25
26
27
28
29
30
31
# File 'public/app/controllers/digital_objects_controller.rb', line 25

def tree_node_from_root
  @root_uri = "/repositories/#{params[:rid]}/digital_objects/#{params[:id]}"
  url = @root_uri + '/tree/node_from_root_' + params[:node_ids].first
  render json: archivesspace.get_raw_record(url)
rescue RecordNotFound
  render json: {}, status: 404
end

#tree_rootObject



306
307
308
309
310
# File 'frontend/app/controllers/digital_objects_controller.rb', line 306

def tree_root
  digital_object_uri = JSONModel(:digital_object).uri_for(params[:id])

  render :json => JSONModel::HTTP.get_json("#{digital_object_uri}/tree/root")
end

#tree_waypointObject



331
332
333
334
335
336
337
338
339
340
341
342
# File 'frontend/app/controllers/digital_objects_controller.rb', line 331

def tree_waypoint
  digital_object_uri = JSONModel(:digital_object).uri_for(params[:id])
  node_uri = if !params[:node].blank?
               params[:node]
             else
               nil
             end

  render :json => JSONModel::HTTP.get_json("#{digital_object_uri}/tree/waypoint",
                                           :parent_node => node_uri,
                                           :offset => params[:offset])
end

#unsuppressObject



298
299
300
301
302
303
304
# File 'frontend/app/controllers/digital_objects_controller.rb', line 298

def unsuppress
  digital_object = JSONModel(:digital_object).find(params[:id])
  digital_object.set_suppressed(false)

  flash[:success] = I18n.t("digital_object._frontend.messages.unsuppressed", JSONModelI18nWrapper.new(:digital_object => digital_object).enable_parse_mixed_content!(url_for(:root)))
  redirect_to(:controller => :digital_objects, :action => :show, :id => params[:id])
end

#updateObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'frontend/app/controllers/digital_objects_controller.rb', line 155

def update
  handle_crud(:instance => :digital_object,
              :obj => JSONModel(:digital_object).find(params[:id], find_opts),
              :on_invalid => ->() {
                render_aspace_partial :partial => "edit_inline"
              },
              :on_valid => ->(id) {

                flash.now[:success] = I18n.t("digital_object._frontend.messages.updated", JSONModelI18nWrapper.new(:digital_object => @digital_object).enable_parse_mixed_content!(url_for(:root)))

                if @digital_object["is_slug_auto"] == false &&
                   @digital_object["slug"] == nil &&
                   params["digital_object"] &&
                   params["digital_object"]["is_slug_auto"] == "1"

                  flash.now[:warning] = I18n.t("slug.autogen_disabled")
                end

                render_aspace_partial :partial => "edit_inline"
              })
end

#update_defaultsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'frontend/app/controllers/digital_objects_controller.rb', line 89

def update_defaults
  begin
    DefaultValues.from_hash({
                              "record_type" => "digital_object",
                              "lock_version" => params[:digital_object].delete('lock_version'),
                              "defaults" => cleanup_params_for_schema(
                                                                      params[:digital_object],
                                                                      JSONModel(:digital_object).schema
                                                                      )
                            }).save

    flash[:success] = "Defaults updated"

    redirect_to :controller => :digital_objects, :action => :defaults
  rescue Exception => e
    flash[:error] = e.message
    redirect_to :controller => :digital_objects, :action => :defaults
  end
end