Class: Hyrax::FileSetsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Blacklight::AccessControls::Catalog, Blacklight::Base, Breadcrumbs, ParentContainer
Defined in:
app/controllers/hyrax/file_sets_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ParentContainer

#find_parent_by_id, #lookup_parent_from_child, #parent, #parent_id

Methods included from Breadcrumbs

#build_breadcrumbs, #default_trail, #trail_from_referer

Instance Attribute Details

#file_setObject Also known as: curation_concern

A little bit of explanation, CanCan(Can) sets the @file_set via the .load_and_authorize_resource method. However the interface for various CurationConcern modules leverages the #curation_concern method Thus we have file_set and curation_concern that are aliases for each other.



25
26
27
# File 'app/controllers/hyrax/file_sets_controller.rb', line 25

def file_set
  @file_set
end

Instance Method Details

#citationObject

routed to /files/:id/citation



87
# File 'app/controllers/hyrax/file_sets_controller.rb', line 87

def citation; end

#createObject

routed to /files (POST)



41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/hyrax/file_sets_controller.rb', line 41

def create
  file = params.fetch(:file_set, {}).fetch(:files, []).detect { |f| f.respond_to?(:original_filename) }
  return render_json_response(response_type: :bad_request, options: { message: 'Error! No file uploaded', description: 'missing file' }) unless file
  return empty_file_response(file) if empty_file?(file)
  process_non_empty_file(file: file)
rescue RSolr::Error::Http => error
  logger.error "FileSetController::create rescued #{error.class}\n\t#{error}\n #{error.backtrace.join("\n")}\n\n"
  render_json_response(response_type: :internal_error, options: { message: 'Error occurred while creating a FileSet.' })
ensure
  file.tempfile.delete if file.respond_to?(:tempfile) # remove tempfile (only if it is a temp file)
end

#destroyObject



62
63
64
65
66
# File 'app/controllers/hyrax/file_sets_controller.rb', line 62

def destroy
  parent = curation_concern.parent
  actor.destroy
  redirect_to [main_app, parent], notice: 'The file has been deleted.'
end

#editObject

routed to /files/:id/edit



36
37
38
# File 'app/controllers/hyrax/file_sets_controller.rb', line 36

def edit
  initialize_edit_form
end

#newObject

routed to /files/new



33
# File 'app/controllers/hyrax/file_sets_controller.rb', line 33

def new; end

#showObject

routed to /files/:id



54
55
56
57
58
59
60
# File 'app/controllers/hyrax/file_sets_controller.rb', line 54

def show
  respond_to do |wants|
    wants.html { presenter }
    wants.json { presenter }
    additional_response_formats(wants)
  end
end

#statsObject

routed to /files/:id/stats



82
83
84
# File 'app/controllers/hyrax/file_sets_controller.rb', line 82

def stats
  @stats = FileUsage.new(params[:id])
end

#updateObject

routed to /files/:id (PUT)



69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/hyrax/file_sets_controller.rb', line 69

def update
  if attempt_update
    after_update_response
  else
    after_update_failure_response
  end
rescue RSolr::Error::Http => error
  flash[:error] = error.message
  logger.error "FileSetsController::update rescued #{error.class}\n\t#{error.message}\n #{error.backtrace.join("\n")}\n\n"
  render action: 'edit'
end