Module: Worthwhile::FilesController

Extended by:
ActiveSupport::Concern
Includes:
WithoutNamespace
Included in:
CurationConcern::GenericFilesController
Defined in:
app/controllers/concerns/worthwhile/files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

routed to /files (POST)



30
31
32
# File 'app/controllers/concerns/worthwhile/files_controller.rb', line 30

def create
  create_from_upload(params)
end

#create_from_upload(params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/concerns/worthwhile/files_controller.rb', line 34

def create_from_upload(params)
  # check error condition No files
  return json_error("Error! No file to save") if !params.has_key?(:files)

  file = params[:files].detect {|f| f.respond_to?(:original_filename) }
  if !file
    json_error "Error! No file for upload", 'unknown file', :status => :unprocessable_entity
  elsif (empty_file?(file))
    json_error "Error! Zero Length File!", file.original_filename
  else
    process_file(file)
  end
rescue RSolr::Error::Http => error
  logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error.to_s}\n #{error.backtrace.join("\n")}\n\n"
  json_error "Error occurred while creating generic file."
ensure
  # remove the tempfile (only if it is a temp file)
  file.tempfile.delete if file.respond_to?(:tempfile)
end

#curation_concernObject



14
15
16
# File 'app/controllers/concerns/worthwhile/files_controller.rb', line 14

def curation_concern
  @generic_file
end

#destroyObject



58
59
60
61
# File 'app/controllers/concerns/worthwhile/files_controller.rb', line 58

def destroy
  @generic_file.destroy
  redirect_to [:curation_concern, @generic_file.batch], notice: "The file has been deleted."
end

#editObject

routed to /files/:id/edit



24
25
26
27
# File 'app/controllers/concerns/worthwhile/files_controller.rb', line 24

def edit
  @generic_file.initialize_fields
  @groups = current_user.groups
end

#newObject

routed to /files/new



19
20
21
# File 'app/controllers/concerns/worthwhile/files_controller.rb', line 19

def new
  @batch_noid = Sufia::Noid.noidify(Sufia::IdService.mint)
end

#showObject

routed to /files/:id



55
56
# File 'app/controllers/concerns/worthwhile/files_controller.rb', line 55

def show
end

#updateObject

routed to /files/:id (PUT)



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/concerns/worthwhile/files_controller.rb', line 64

def update
  success = if wants_to_revert?
    actor.revert_content(params[:revision], datastream_id)
  elsif params.has_key? :files
    actor.update_content(params[:files].first, datastream_id)
  elsif params.has_key? :generic_file
    actor.(params[:generic_file], params[:generic_file][:visibility])
  end

  if success
    redirect_to [:curation_concern, @generic_file], notice:
      "The file #{view_context.link_to(@generic_file, [main_app, :curation_concern, @generic_file])} has been updated."
  else
    render action: 'edit'
  end
rescue RSolr::Error::Http => error
  flash[:error] = error.message
  logger.error "GenericFilesController::update rescued #{error.class}\n\t#{error.message}\n #{error.backtrace.join("\n")}\n\n"
  render action: 'edit'
end