Module: CurationConcerns::FileSetsControllerBehavior

Extended by:
ActiveSupport::Concern
Includes:
Blacklight::AccessControls::Catalog, Blacklight::Base
Included in:
FileSetsController
Defined in:
app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb

Instance Method Summary collapse

Instance Method Details

#after_update_responseObject



108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 108

def after_update_response
  respond_to do |wants|
    wants.html do
      redirect_to [main_app, curation_concern], notice: "The file #{view_context.link_to(curation_concern, [main_app, curation_concern])} has been updated."
    end
    wants.json do
      @presenter = show_presenter.new(curation_concern, current_ability)
      render :show, status: :ok, location: polymorphic_path([main_app, curation_concern])
    end
  end
end

#createObject

routed to /files (POST)



40
41
42
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 40

def create
  create_from_upload(params)
end

#create_from_upload(params) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 44

def create_from_upload(params)
  # check error condition No files
  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) }
  if !file
    render_json_response(response_type: :bad_request, options: { message: 'Error! No file for upload', description: 'unknown file' })
  elsif empty_file?(file)
    render_json_response(response_type: :unprocessable_entity, options: { errors: { files: "#{file.original_filename} has no content! (Zero length file)" }, description: t('curation_concerns.api.unprocessable_entity.empty_file') })
  else
    process_file(file)
  end
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
  # remove the tempfile (only if it is a temp file)
  file.tempfile.delete if file.respond_to?(:tempfile)
end

#destroyObject



73
74
75
76
77
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 73

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



35
36
37
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 35

def edit
  initialize_edit_form
end

#newObject

routed to /files/new



31
32
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 31

def new
end

#showObject

routed to /files/:id



65
66
67
68
69
70
71
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 65

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

#updateObject

routed to /files/:id (PUT)



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 80

def update
  success = if wants_to_revert?
              actor.revert_content(params[:revision])
            elsif params.key?(:file_set)
              if params[:file_set].key?(:files)
                actor.update_content(params[:file_set][:files].first)
              else
                
              end
            end
  if success
    after_update_response
  else
    respond_to do |wants|
      wants.html do
        initialize_edit_form
        flash[:error] = "There was a problem processing your request."
        render 'edit', status: :unprocessable_entity
      end
      wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: curation_concern.errors }) }
    end
  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

#update_metadataObject

this is provided so that implementing application can override this behavior and map params to different attributes



125
126
127
128
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 125

def 
  file_attributes = form_class.model_attributes(attributes)
  actor.(file_attributes)
end

#versionsObject



120
121
122
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 120

def versions
  @version_list = version_list
end