Module: Cul::Hydra::Controllers::Resources
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cul_hydra/controllers/resources.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
- #update ⇒ Object
- #update_file ⇒ 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cul_hydra/controllers/resources.rb', line 48 def create if params.has_key?(:Filedata) or params.has_key?(:Fileurl) flash[:notice] = process_files # "The file #{params[:Filename]} has been saved in <a href=\"#{asset_url(@resource.pid)}\">#{@resource.pid}</a>." else flash[:notice] = "You must specify a file to upload." end if !params[:container_id].nil? redirect_params = {:controller=>"catalog", :id=>params[:container_id], :action=>:edit} end redirect_params ||= {:action=>:index} redirect_to redirect_params end |
#destroy ⇒ Object
Common destroy method for all AssetsControllers
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cul_hydra/controllers/resources.rb', line 110 def destroy # The correct implementation, with garbage collection: # if params.has_key?(:container_id) # container = ActiveFedora::Base.load_instance(params[:container_id]) # container.file_objects_remove(params[:id]) # FileAsset.garbage_collect(params[:id]) # else # The dirty implementation (leaves relationship in container object, deletes regardless of whether the file object has other containers) ActiveFedora::Base.load_instance(params[:id]).delete flash[:notice] = "Deleted #{params[:id]}." if !params[:container_id].nil? redirect_params = {:controller=>"catalog", :id=>params[:container_id], :action=>:edit} end redirect_params ||= {:action=>:index} redirect_to redirect_params end |
#index ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cul_hydra/controllers/resources.rb', line 16 def index if params[:layout] == "false" # action = "index_embedded" layout = false end if !params[:container_id].nil? container_uri = "info:fedora/#{params[:container_id]}" escaped_uri = container_uri.gsub(/(:)/, '\\:') extra_controller_params = {:q=>"cul_member_of_s:#{escaped_uri}"} @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[:container_id]) # Including these lines for backwards compatibility (until we can use Rails3 callbacks) @container = ActiveFedora::Base.load_instance(params[:container_id]) @solr_result = @container.file_objects(:response_format=>:solr) else # @solr_result = ActiveFedora::SolrService.instance.conn.query('has_model_field:info\:fedora/ldpd\:Resource', @search_params) @solr_result = Resource.find_by_solr(:all) end render :action=>params[:action], :layout=>layout end |
#new ⇒ Object
40 41 42 |
# File 'lib/cul_hydra/controllers/resources.rb', line 40 def new render :partial=>"new", :layout=>false end |
#process_files ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cul_hydra/controllers/resources.rb', line 79 def process_files @resources = create_and_save_resources_from_params notice = [] @resources.each do |resource| (resource) notice << "The file #{resource.label} has been saved in <a href=\"#{asset_url(resource.pid)}\">#{resource.pid}</a>." if !params[:container_id].nil? associate_resource_with_container(resource,params[:container_id]) end ## Apply any posted file metadata unless params[:asset].nil? logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}") (resource) end resource.save logger.debug("Created #{resource.pid}.") end end |
#show ⇒ Object
131 132 133 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 |
# File 'lib/cul_hydra/controllers/resources.rb', line 131 def show @file_asset = Resource.find(params[:id]) if (@file_asset.nil?) logger.warn("No such resource: " + params[:id]) flash[:notice]= "No such resource." redirect_to(:action => 'index', :q => nil , :f => nil) else # get array of parent (container) objects for this FileAsset @id_array = @file_asset.containers(:response_format => :id_array) @downloadable = false # A FileAsset is downloadable iff the user has read or higher access to a parent @id_array.each do |pid| @response, @document = get_solr_response_for_doc_id(pid) if reader? @downloadable = true break end end if @downloadable if @file_asset.datastreams_in_memory.include?("CONTENT") send_datastream @file_asset.datastreams_in_memory["CONTENT"] 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) end end end |
#update ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cul_hydra/controllers/resources.rb', line 64 def update if params.has_key?(:Filedata) or params.has_key?(:Fileurl) flash[:notice] = update_file # "The file #{params[:Filename]} has been saved in <a href=\"#{asset_url(@resource.pid)}\">#{@resource.pid}</a>." else flash[:notice] = "You must specify a file to upload." end if !params[:id].nil? redirect_params = {:controller=>"catalog", :id=>params[:id], :action=>:edit} end redirect_params ||= {:action=>:index} redirect_to redirect_params end |
#update_file ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cul_hydra/controllers/resources.rb', line 98 def update_file update_resource_from_params (@document_fedora) notice << "The file #{@document_fedora.label} has been saved in <a href=\"#{asset_url(@document_fedora.pid)}\">#{@document_fedora.pid}</a>." unless params[:asset].nil? logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}") (@document_fedora) end @document_fedora.save logger.debug("Created #{@document_fedora.pid}.") end |