Class: RepositoriesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RepositoriesController
- Defined in:
- frontend/app/controllers/repositories_controller.rb,
public/app/controllers/repositories_controller.rb
Constant Summary collapse
- DEFAULT_SEARCH_FACET_TYPES =
['primary_type', 'subjects', 'published_agents']
- DEFAULT_REPO_SEARCH_OPTS =
{ 'sort' => 'title_sort asc', 'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource'], 'facet.mincount' => 1 }
- DEFAULT_TYPES =
%w{archival_object digital_object agent resource accession}
Instance Method Summary collapse
-
#create ⇒ Object
-
#current_record ⇒ Object
-
#delete ⇒ Object
-
#edit ⇒ Object
-
#generate_names(repository_with_agent) ⇒ Object
-
#index ⇒ Object
get all repositories TODO: get this somehow in line with using the Searchable module.
-
#metadata ⇒ Object
-
#new ⇒ Object
-
#reorder ⇒ Object
-
#run_reorder ⇒ Object
-
#run_transfer ⇒ Object
-
#search ⇒ Object
-
#select ⇒ Object
-
#show ⇒ Object
-
#transfer ⇒ Object
-
#typeahead ⇒ Object
-
#update ⇒ Object
Methods inherited from ApplicationController
#archivesspace, can_access?, permission_mappings, set_access_control
Instance Method Details
#create ⇒ Object
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 89 90 |
# File 'frontend/app/controllers/repositories_controller.rb', line 56 def create handle_repository_oai_params(params) generate_names(params[:repository]) handle_crud(:instance => :repository, :model => JSONModel(:repository_with_agent), :on_invalid => ->() { if @exceptions[:errors]["repo_code"] @exceptions[:errors]["repository/repo_code"] = @exceptions[:errors].delete("repo_code") end @enum = JSONModel(:enumeration).find("/names/archival_record_level") return render_aspace_partial :partial => "repositories/new" if inline? return render :action => :new }, :on_valid => ->(id) { MemoryLeak::Resources.refresh(:repository) return render :json => @repository.to_hash if inline? flash[:success] = t("repository._frontend.messages.created") if AppConfig[:use_human_readable_urls] && params["repository"]["repository"] && (params["repository"]["repository"]["slug"].nil? || params["repository"]["repository"]["slug"].empty?) && !params["repository"]["repository"]["is_slug_auto"] flash[:success] = t("slug.autogen_repo_slug") end return redirect_to :controller => :repositories, :action => :new, :last_repo_id => id if params.has_key?(:plus_one) redirect_to :controller => :repositories, :action => :show, :id => id }) end |
#current_record ⇒ Object
122 123 124 |
# File 'frontend/app/controllers/repositories_controller.rb', line 122 def current_record @repository end |
#delete ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'frontend/app/controllers/repositories_controller.rb', line 145 def delete repository = JSONModel(:repository).find(params[:id]) begin repository.delete rescue ConflictException => e flash[:error] = t("repository._frontend.messages.cannot_delete_nonempty") return redirect_to(:controller => :repositories, :action => :show, :id => params[:id]) end MemoryLeak::Resources.refresh(:repository) flash[:success] = t("repository._frontend.messages.deleted") redirect_to(:controller => :repositories, :action => :index, :deleted_uri => repository.uri) end |
#edit ⇒ Object
92 93 94 95 |
# File 'frontend/app/controllers/repositories_controller.rb', line 92 def edit @repository = JSONModel(:repository_with_agent).find(params[:id]) @enum = JSONModel(:enumeration).find("/names/archival_record_level") end |
#generate_names(repository_with_agent) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'frontend/app/controllers/repositories_controller.rb', line 42 def generate_names(repository_with_agent) name = JSONModel(:name_corporate_entity).new name['primary_name'] = repository_with_agent['repository']['name'].blank? ? '<generated>' : repository_with_agent['repository']['name'] name['source'] = 'local' name['sort_name'] = name['primary_name'] repository_with_agent['agent_representation']['names'] = [name] if repository_with_agent['agent_representation']['agent_contacts']['0']['name'].blank? repository_with_agent['agent_representation']['agent_contacts']['0']['name'] = name['primary_name'] repository_with_agent['agent_representation']['agent_contacts']['0']['is_representative'] = 1 end end |
#index ⇒ Object
get all repositories TODO: get this somehow in line with using the Searchable module
20 21 22 23 |
# File 'public/app/controllers/repositories_controller.rb', line 20 def index @search_data = Search.global(params_for_backend_search.merge({"facet[]" => []}), "repositories") end |
#metadata ⇒ Object
77 78 79 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 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 |
# File 'public/app/controllers/repositories_controller.rb', line 77 def md = { '@context' => "http://schema.org/", '@type' => 'ArchiveOrganization', '@id' => AppConfig[:public_proxy_url] + @result['uri'], #this next bit will always be the repo name, not the name associated with the agent record (which is overwritten if the repo record is updated) 'name' => @result['agent_representation']['_resolved']['display_name']['sort_name'], 'url' => @result['url'], 'logo' => @result['image_url'], #this next bit will never work since ASpace has a bug with how it enacts its repo-to-agent concept (at least in versions 2.4 and 2.5).... and you can't add an authority ID directly to a repo record. 'sameAs' => @result['agent_representation']['_resolved']['display_name']['authority_id'], 'parentOrganization' => { '@type' => 'Organization', 'name' => @result['parent_institution_name'] } # removing contactPoint, since this would need to be on the repo record (along with different contact types... e.g. reference assistance, digitization requests, whatever) # 'contactPoint' => @result['agent_representation']['_resolved']['agent_contacts'][0]['name'] } if @result['org_code'] if @result['country'] md['identifier'] = @result['country']+'-'+ @result['org_code'] else md['identifier'] = @result['org_code'] end end if @result['repo_info'] md['description'] = @result['repo_info']['top']['description'] if @result['repo_info']['top'] && @result['repo_info']['top']['description'] md['email'] = @result['repo_info']['email'] if @result['repo_info']['email'] if @result['repo_info']['telephones'] md['faxNumber'] = @result['repo_info']['telephones'] .select {|t| t['number_type'] == 'fax'} .map {|f| f['number']} md['telephone'] = @result['repo_info']['telephones'] .select {|t| t['number_type'] == 'business'} .map {|b| b['number']} end if @result['repo_info']['address'] md['address'] = { '@type' => 'PostalAddress', 'streetAddress' => @result['repo_info']['address'].join(", "), 'addressLocality' => @result['repo_info']['city'], 'addressRegion' => @result['repo_info']['region'], 'postalCode' => @result['repo_info']['post_code'], 'addressCountry' => @result['repo_info']['country'] } end end md.compact end |
#new ⇒ Object
33 34 35 36 37 38 39 |
# File 'frontend/app/controllers/repositories_controller.rb', line 33 def new @enum = JSONModel(:enumeration).find("/names/archival_record_level") @repository = JSONModel(:repository_with_agent).new('repository' => {}, 'agent_representation' => { 'agent_contacts' => [{}] })._always_valid! end |
#reorder ⇒ Object
18 19 20 |
# File 'frontend/app/controllers/repositories_controller.rb', line 18 def reorder @repositories = JSONModel(:repository).all.sort_by {|r| r.position } end |
#run_reorder ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'frontend/app/controllers/repositories_controller.rb', line 22 def run_reorder response = JSONModel::HTTP.post_form("#{JSONModel(:repository).uri_for(params[:id])}/position", :position => params[:position]) if response.code == '200' flash[:success] = I18n.t("actions.reorder_successful") else flash[:error] = ASUtils.json_parse(response.body)['error'] end redirect_to(:action => :reorder) end |
#run_transfer ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'frontend/app/controllers/repositories_controller.rb', line 167 def run_transfer old_uri = JSONModel(:repository).uri_for(params[:id]) response = JSONModel::HTTP.post_form(JSONModel(:repository).uri_for(params[:id]) + "/transfer", "target_repo" => params[:ref]) if response.code == '200' flash[:success] = t("actions.transfer_successful") redirect_to(:action => :index) else @transfer_errors = ASUtils.json_parse(response.body)['error'] return transfer end end |
#search ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'public/app/controllers/repositories_controller.rb', line 52 def search @repo_id = params.require(:rid) @base_search = "/repositories/#{repo_id}/search?" begin new_search_opts = DEFAULT_REPO_SEARCH_OPTS new_search_opts['repo_id'] = @repo_id set_up_advanced_search(DEFAULT_TYPES, DEFAULT_SEARCH_FACET_TYPES, new_search_opts, params) # NOTE the redirect back here on error! rescue Exception => error Rails.logger.debug( error.backtrace ) flash[:error] = I18n.t('errors.unexpected_error') redirect_back(fallback_location: "/repositories/#{@repo_id}/" ) and return end page = Integer(params.fetch(:page, "1")) @results = archivesspace.advanced_search('/search', page, @criteria) if @results['total_hits'].blank? || @results['total_hits'] == 0 flash[:notice] = I18n.t('search_results.no_results') redirect_back(fallback_location: @base_search) else process_search_results(@base_search) Rails.logger.debug("@repo_id: #{@repo_id}") render end end |
#select ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'frontend/app/controllers/repositories_controller.rb', line 132 def select # Clear top container previous search when switching repositories session[:top_container_previous_search] = {} selected = @repositories.find {|r| r.id.to_s == params[:id]} self.class.session_repo(session, selected.uri, selected.slug) selected.uri flash[:success] = t("repository._frontend.messages.changed", repository_repo_code: selected.repo_code) redirect_to :root end |
#show ⇒ Object
126 127 128 129 130 |
# File 'frontend/app/controllers/repositories_controller.rb', line 126 def show @repository = JSONModel(:repository_with_agent).find(params[:id]) flash.now[:info] = t("repository._frontend.messages.selected") if @repository.id === session[:repo_id] @enum = JSONModel(:enumeration).find("/names/archival_record_level") end |
#transfer ⇒ Object
161 162 163 164 |
# File 'frontend/app/controllers/repositories_controller.rb', line 161 def transfer @repository = JSONModel(:repository_with_agent).find(params[:id]) render :transfer end |
#typeahead ⇒ Object
182 183 184 |
# File 'frontend/app/controllers/repositories_controller.rb', line 182 def typeahead render :json => Search.global(params_for_backend_search, "repositories") end |
#update ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'frontend/app/controllers/repositories_controller.rb', line 97 def update handle_repository_oai_params(params) generate_names(params[:repository]) handle_crud(:instance => :repository, :model => JSONModel(:repository_with_agent), :replace => false, :obj => JSONModel(:repository_with_agent).find(params[:id]), :on_invalid => ->() { return render :action => :edit }, :on_valid => ->(id) { MemoryLeak::Resources.refresh(:repository) flash[:success] = t("repository._frontend.messages.updated") if AppConfig[:use_human_readable_urls] && params["repository"]["repository"] && (params["repository"]["repository"]["slug"].nil? || params["repository"]["repository"]["slug"].empty?) && !params["repository"]["repository"]["is_slug_auto"] flash[:warning] = t("slug.autogen_repo_slug") end redirect_to :controller => :repositories, :action => :show, :id => id }) end |