Module: Cul::Hydra::Controllers::Datastreams
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cul_hydra/controllers/datastreams.rb
Instance Method Summary collapse
-
#create ⇒ Object
Creates and Saves a Datastream to contain the the Uploaded file.
-
#destroy ⇒ Object
Datastream destroy method.
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
Creates and Saves a Datastream to contain the the Uploaded file
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cul_hydra/controllers/datastreams.rb', line 42 def create if params[:asset_id].nil? raise "Cannot created a datastream without a containing object" else @container = ActiveFedora::Base.load_instance(params[:asset_id]) end if params[:id].nil? raise "Cannot created a datastream without a datastream id" end if params.has_key?(:Filedata) file_name = filename_from_params mime_type = params[:mime_type] || mime_type(file_name) @container.add_file_datastream(posted_file, :dsid=>params[:id], :label=>file_name, :mimeType=>mime_type, :size=>posted_file.size) @container.save # apply_depositor_metadata(@file_asset) flash[:notice] = "The file #{params[:Filename]} has been saved as #{params[:datastream_id]} in <a href=\"#{asset_url(@container.pid)}\">#{@container.pid}</a>." ## Apply any posted file metadata unless params[:asset].nil? # logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}") # apply_file_metadata end # If redirect_params has not been set, use {:action=>:index} logger.debug "Created #{@container.pid}##{params[:datastream_id]}." elsif params.has_key?(:Source) file_name = filename_from_url(params[:Source]) mime_type = params[:mime_type] || mime_type(file_name) ds_props = {:dsid=>params[:id], :label=>file_name, :mimeType=>mime_type, :dsLocation=>params[:Source]} @container.add_datastream(ActiveFedora::Datastream.new(ds_props)) @container.save flash[:notice] = "#{params[:Source]} has been saved as #{params[:datastream_id]} in <a href=\"#{asset_url(@container.pid)}\">#{@container.pid}</a>." else flash[:notice] = "You must specify a file to upload or a source URL." end unless params[:container_id].nil? redirect_params = {:controller=>"catalog", :id=>params[:asset_id], :action=>:edit} end redirect_params ||= {:action=>:index} redirect_to redirect_params end |
#destroy ⇒ Object
Datastream destroy method
91 92 93 94 95 96 97 |
# File 'lib/cul_hydra/controllers/datastreams.rb', line 91 def destroy @container = ActiveFedora::Base.load_instance(params[:asset_id]) @container.datastreams[params[:datastream_id]].delete render :text => "Deleted #{params[:datastream_id]} from #{params[:asset_id]}." # Does the index need to be updated on delete here? @container.save end |
#index ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cul_hydra/controllers/datastreams.rb', line 17 def index if params[:layout] == "false" # action = "index_embedded" layout = false end unless params[:asset_id].nil? # 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.load_instance(params[:asset_id]) @ds = @container.datastreams(params[:id]) else # What are we doing here without a containing object? raise "called DatastreamsController#index without containing object" end render :action=>params[:action], :layout=>layout end |
#new ⇒ Object
37 38 39 |
# File 'lib/cul_hydra/controllers/datastreams.rb', line 37 def new render :partial=>"new", :layout=>false end |
#show ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cul_hydra/controllers/datastreams.rb', line 103 def show @container = ActiveFedora::Base.find(params[:asset_id]) if (@container.nil?) logger.warn("No such fedora object: " + params[:asset_id]) flash[:notice]= "No such fedora object." redirect_to(:action => 'index', :q => nil , :f => nil) return else # get array of parent (container) objects for this FileAsset @downloadable = false # A FileAsset is downloadable iff the user has read or higher access to a parent @response, @document = get_solr_response_for_doc_id(params[:asset_id]) if reader? @downloadable = true end if @downloadable if @container.datastreams_in_memory.include?(params[:id]) ds = @container.datastreams_in_memory[params[:id]] opts = {:filename => ds.label} if params[:mime_type].nil? opts[:type] = ds.attributes["mimeType"] else opts[:type] = params[:mime_type] end if params[:disposition].nil? opts[:disposition] = "attachment" else opts[:disposition] = params[:disposition] end logger.debug opts.inspect send_data ds.content, opts return end else flash[:notice]= "You do not have sufficient access privileges to download this document, which has been marked private." redirect_to(:action => 'index', :q => nil , :f => nil) return end end end |
#update ⇒ Object
99 100 101 |
# File 'lib/cul_hydra/controllers/datastreams.rb', line 99 def update self.create end |