Module: Sufia::FilesControllerBehavior
- Extended by:
- ActiveSupport::Concern, Sufia::FilesController::UploadCompleteBehavior
- Included in:
- GenericFilesController
- Defined in:
- lib/sufia/files_controller_behavior.rb
Instance Method Summary collapse
-
#audit ⇒ Object
routed to /files/:id/audit (POST).
-
#citation ⇒ Object
routed to /files/:id/citation.
-
#create ⇒ Object
routed to /files (POST).
- #create_from_upload(params) ⇒ Object
- #create_from_url(params) ⇒ Object
-
#destroy ⇒ Object
routed to /files/:id (DELETE).
-
#edit ⇒ Object
routed to /files/:id/edit.
-
#new ⇒ Object
routed to /files/new.
-
#show ⇒ Object
routed to /files/:id.
-
#update ⇒ Object
routed to /files/:id (PUT).
Methods included from Sufia::FilesController::UploadCompleteBehavior
destroy_complete_path, upload_complete_path
Instance Method Details
#audit ⇒ Object
routed to /files/:id/audit (POST)
129 130 131 |
# File 'lib/sufia/files_controller_behavior.rb', line 129 def audit render :json=>@generic_file.audit end |
#citation ⇒ Object
routed to /files/:id/citation
115 116 |
# File 'lib/sufia/files_controller_behavior.rb', line 115 def citation end |
#create ⇒ Object
routed to /files (POST)
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sufia/files_controller_behavior.rb', line 64 def create if params[:local_file].present? perform_local_ingest else case params['file_coming_from'] when 'dropbox' create_from_url(params) else create_from_upload(params) end end end |
#create_from_upload(params) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/sufia/files_controller_behavior.rb', line 92 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 elsif (!terms_accepted?) json_error "You must accept the terms of service!", file.original_filename else process_file(file) end rescue => 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 |
#create_from_url(params) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sufia/files_controller_behavior.rb', line 79 def create_from_url(params) params[:dropbox_urls].each do |db_file| next if db_file.blank? # do not remove :: @generic_file = ::GenericFile.new @generic_file.import_url = db_file @generic_file.label = File.basename(db_file) (@generic_file) Sufia.queue.push(ImportUrlJob.new(@generic_file.pid)) end redirect_to self.class.upload_complete_path( params[:batch_id]) end |
#destroy ⇒ Object
routed to /files/:id (DELETE)
56 57 58 59 60 61 |
# File 'lib/sufia/files_controller_behavior.rb', line 56 def destroy pid = @generic_file.noid @generic_file.destroy Sufia.queue.push(ContentDeleteEventJob.new(pid, current_user.user_key)) redirect_to self.class.destroy_complete_path(params), :notice => render_to_string(:partial=>'generic_files/asset_deleted_flash', :locals => { :generic_file => @generic_file }) end |
#edit ⇒ Object
routed to /files/:id/edit
50 51 52 53 |
# File 'lib/sufia/files_controller_behavior.rb', line 50 def edit @generic_file.initialize_fields @groups = current_user.groups end |
#new ⇒ Object
routed to /files/new
44 45 46 47 |
# File 'lib/sufia/files_controller_behavior.rb', line 44 def new @generic_file = ::GenericFile.new @batch_noid = Sufia::Noid.noidify(Sufia::IdService.mint) end |
#show ⇒ Object
routed to /files/:id
119 120 121 122 123 124 125 126 |
# File 'lib/sufia/files_controller_behavior.rb', line 119 def show respond_to do |format| format.html { @events = @generic_file.events(100) } format.endnote { render :text => @generic_file.export_as_endnote } end end |
#update ⇒ Object
routed to /files/:id (PUT)
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/sufia/files_controller_behavior.rb', line 134 def update version_event = false if params.has_key?(:revision) and params[:revision] != @generic_file.content.latest_version.versionID revision = @generic_file.content.get_version(params[:revision]) @generic_file.add_file(revision.content, datastream_id, revision.label) version_event = true Sufia.queue.push(ContentRestoredVersionEventJob.new(@generic_file.pid, current_user.user_key, params[:revision])) end if params.has_key?(:filedata) file = params[:filedata] @generic_file.add_file(file, datastream_id, file.original_filename) version_event = true end # only update metadata if there is a generic_file object which is not the case for version updates if params[:generic_file] #always save the file so the new version or metadata gets recorded if @generic_file.save # do not trigger an update event if a version event has already been triggered if version_event Sufia.queue.push(ContentNewVersionEventJob.new(@generic_file.pid, current_user.user_key)) if params.has_key?(:filedata) else Sufia.queue.push(ContentUpdateEventJob.new(@generic_file.pid, current_user.user_key)) end @generic_file.record_version_committer(current_user) redirect_to sufia.edit_generic_file_path(:tab => params[:redirect_tab]), :notice => render_to_string(:partial=>'generic_files/asset_updated_flash', :locals => { :generic_file => @generic_file }) else render action: 'edit' end rescue => error flash[:error] = error. logger.error "GenericFilesController::update rescued #{error.class}\n\t#{error.}\n #{error.backtrace.join("\n")}\n\n" render action: 'edit' end |