Module: Hydra::Controller::FileAssetsBehavior
- Extended by:
- ActiveSupport::Concern, Deprecation
- Included in:
- FileAssetsController
- Defined in:
- lib/hydra/controller/file_assets_behavior.rb
Instance Method Summary collapse
-
#create ⇒ Object
Creates and Saves a File Asset to contain the the Uploaded file If container_id is provided: * the File Asset will use RELS-EXT to assert that it’s a part of the specified container * the method will redirect to the container object’s edit view after saving.
-
#destroy ⇒ Object
Common destroy method for all AssetsControllers.
- #index ⇒ Object
- #new ⇒ Object
- #process_files ⇒ Object
- #show ⇒ Object
- #show_deprecation_message ⇒ Object
Instance Method Details
#create ⇒ Object
Creates and Saves a File Asset to contain the the Uploaded file If container_id is provided:
-
the File Asset will use RELS-EXT to assert that it’s a part of the specified container
-
the method will redirect to the container object’s edit view after saving
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hydra/controller/file_assets_behavior.rb', line 61 def create if params.has_key?(:number_of_files) and params[:number_of_files] != "0" return redirect_to edit_catalog_path(params[:id], :wf_step => :files, :number_of_files => params[:number_of_files]) elsif params.has_key?(:number_of_files) and params[:number_of_files] == "0" return redirect_to next_step(params[:id]) end :edit, (params[:container_id] || params[:id]) if params.has_key?(:Filedata) notice = process_files flash[:notice] = notice.join("<br/>".html_safe) unless notice.blank? else flash[:notice] = "You must specify a file to upload." end if params[:container_id] redirect_to next_step(params[:container_id]) else redirect_to catalog_index_path end end |
#destroy ⇒ Object
Common destroy method for all AssetsControllers
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/hydra/controller/file_assets_behavior.rb', line 109 def destroy :destroy, params[:id] ActiveFedora::Base.find(params[:id], :cast=>true).delete flash[:notice] = "Deleted #{params[:id]} from #{params[:container_id]}." if !params[:container_id].nil? redirect_params = edit_catalog_path(params[:container_id], :anchor => "file_assets") end redirect_params ||= {:action => 'index', :q => nil , :f => nil} redirect_to redirect_params end |
#index ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hydra/controller/file_assets_behavior.rb', line 26 def index if params[:layout] == "false" layout = false end if params[:asset_id].nil? @solr_result = FileAsset.find_with_conditions({}) else container_uri = "info:fedora/#{params[:asset_id]}" escaped_uri = ActiveFedora::SolrService.escape_uri_for_query(container_uri) extra_controller_params = {:q=>"is_part_of_s:#{escaped_uri}", 'qf'=>'is_part_of_s', 'qt'=>'standard', :rows=>10}.with_indifferent_access @response, @document_list = get_search_results( extra_controller_params ) # Including this line so permissions tests can be run against the container @container_response, @document = get_solr_response_for_doc_id(params[:asset_id]) # Including these lines for backwards compatibility (until we can use Rails3 callbacks) @container = ActiveFedora::Base.find(params[:asset_id], :cast=>true) @solr_result = @container.parts(:response_format=>:solr) end # Load permissions_solr_doc based on params[:asset_id] (params[:asset_id]) render :action=>params[:action], :layout=>layout end |
#new ⇒ Object
53 54 55 |
# File 'lib/hydra/controller/file_assets_behavior.rb', line 53 def new render :partial=>"new", :layout=>false end |
#process_files ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hydra/controller/file_assets_behavior.rb', line 85 def process_files @file_assets = create_and_save_file_assets_from_params notice = [] @file_assets.each do |file_asset| (file_asset) notice << render_to_string(:partial=>'hydra/file_assets/asset_saved_flash', :locals => { :file_asset => file_asset }) if !params[:container_id].nil? associate_file_asset_with_container(file_asset,'info:fedora/' + params[:container_id]) end ## Apply any posted file metadata unless params[:asset].nil? logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}") end # If redirect_params has not been set, use {:action=>:index} logger.debug "Created #{file_asset.pid}." end notice end |
#show ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/hydra/controller/file_assets_behavior.rb', line 125 def show begin @file_asset = FileAsset.find(params[:id]) rescue ActiveFedora::ObjectNotFoundError logger.warn("No such file asset: " + params[:id]) flash[:notice]= "No such file asset." redirect_to(:action => 'index', :q => nil , :f => nil) return end # get containing object for this FileAsset pid = @file_asset.container_id parent = ActiveFedora::Base.find(pid, :cast=>true) @downloadable = false # A FileAsset is downloadable iff the user has read or higher access to a parent if can? :read, parent # First try to use datastream_id value (set in FileAssetsHelper) if @file_asset.datastreams.include?(datastream_id) send_datastream @file_asset.datastreams[datastream_id] elsif @file_asset.datastreams.include?("DS1") send_datastream @file_asset.datastreams["DS1"] end else raise Hydra::AccessDenied.new("You do not have sufficient access privileges to download this file.") end end |
#show_deprecation_message ⇒ Object
22 23 24 |
# File 'lib/hydra/controller/file_assets_behavior.rb', line 22 def Deprecation.warn Hydra::Controller::FileAssetsBehavior, "Hydra::Controller::FileAssetsBehavior will be removed in hydra-head 6.0" end |