Skip to content

Commit

Permalink
Extracting method to bring common abstraction
Browse files Browse the repository at this point in the history
This extraction is to ensure there is a common level of abstraction
for the primary method. Also renaming method to better explain it's
purpose.
  • Loading branch information
jeremyf committed Mar 30, 2017
1 parent 5f7c94c commit 976f6b4
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/controllers/concerns/hyrax/file_sets_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def create_from_upload(params)
return render_json_response(response_type: :bad_request, options: { message: 'Error! No file to save' }) unless params.key?(:file_set) && params.fetch(:file_set).key?(:files)

file = params[:file_set][:files].detect { |f| f.respond_to?(:original_filename) }
process_file_for_create_from_upload(file)
attempt_process_file_for_create_from_upload(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.' })
Expand All @@ -97,20 +97,24 @@ def create_from_upload(params)
file.tempfile.delete if file.respond_to?(:tempfile)
end

def process_file_for_create_from_upload(file)
def attempt_process_file_for_create_from_upload(file)
if !file
render_json_response(response_type: :bad_request, options: { message: 'Error! No file for upload', description: 'unknown file' })
elsif empty_file?(file)
empty_file_response(file)
else
update_metadata_from_upload_screen
if process_file(actor, file)
response_for_successfully_processed_file
else
msg = curation_concern.errors.full_messages.join(', ')
flash[:error] = msg
json_error "Error creating file #{file.original_filename}: #{msg}"
end
process_non_empty_file(file: file)
end
end

def process_non_empty_file(file:)
update_metadata_from_upload_screen
if process_file(actor, file)
response_for_successfully_processed_file
else
msg = curation_concern.errors.full_messages.join(', ')
flash[:error] = msg
json_error "Error creating file #{file.original_filename}: #{msg}"
end
end

Expand Down

0 comments on commit 976f6b4

Please sign in to comment.