Class: ObjectsController

Inherits:
ApplicationController show all
Includes:
ResultInfo
Defined in:
public/app/controllers/objects_controller.rb

Constant Summary collapse

DEFAULT_OBJ_FACET_TYPES =
%w(repository primary_type subjects published_agents langcode)
DEFAULT_OBJ_SEARCH_OPTS =
{
  'resolve[]' => ['repository:id', 'resource:id@compact_resource', 'ancestors:id@compact_resource', 'top_container_uri_u_sstr:id'],
  'facet.mincount' => 1,
  'sort' =>  'title_sort asc'
}

Constants included from Searchable

Searchable::ABSTRACT

Instance Method Summary collapse

Methods included from ResultInfo

#breadcrumb_info, #fill_request_info, #get_rep_image, #handle_dates, #handle_external_docs, #process_agents, #process_digital, #process_digital_instance, #process_extents, #process_file_versions, #process_repo_info, #process_subjects

Methods inherited from ApplicationController

#archivesspace, can_access?, permission_mappings, set_access_control

Methods included from JsonHelper

#merge_notes, #process_json_notes

Methods included from Searchable

#default_search_opts, #get_filter_years, #handle_results, #html_notes, #process_results, #process_search_results, #repo_context, #search_terms, #set_up_advanced_search, #set_up_and_run_search, #set_up_search, #strip_facet_fields

Methods included from HandleFaceting

#fetch_only_facets, #get_pretty_facet_value, #strip_facets

Methods included from ManipulateNode

#inheritance, #process_mixed_content, #strip_mixed_content

Instance Method Details

#indexObject



22
23
24
25
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
52
53
54
55
56
57
58
59
60
# File 'public/app/controllers/objects_controller.rb', line 22

def index
  repo_id = params.fetch(:rid, nil)
  if !params.fetch(:q, nil)
    params[:q] = ['*']
    params[:limit] = 'digital_object,archival_object' unless params.fetch(:limit, nil)
    params[:op] = ['OR']
  end
  page = Integer(params.fetch(:page, "1"))
  search_opts = default_search_opts(DEFAULT_OBJ_SEARCH_OPTS)
  search_opts['fq'] = ["repository:\"/repositories/#{repo_id}\""] if repo_id
  @base_search = repo_id ? "/repositories/#{repo_id}/objects?" : '/objects?'

  begin
    set_up_and_run_search( params[:limit].split(","), DEFAULT_OBJ_FACET_TYPES, search_opts, params)
  rescue NoResultsError
    flash[:error] = I18n.t('search_results.no_results')
    redirect_back(fallback_location: '/') and return
  rescue Exception => error
    flash[:error] = I18n.t('errors.unexpected_error')
    redirect_back(fallback_location: '/objects' ) and return
  end

  @context = repo_context(repo_id, 'record')
  if @results['total_hits'] > 1
    @search[:dates_within] = true if params.fetch(:filter_from_year, '').blank? && params.fetch(:filter_to_year, '').blank?
    @search[:text_within] = true
  end
  @sort_opts = []
  all_sorts = Search.get_sort_opts
  all_sorts.delete('relevance') unless params[:q].size > 1 || params[:q] != '*'
  all_sorts.keys.each do |type|
    @sort_opts.push(all_sorts[type])
  end

  @page_title = I18n.t('record._plural')
  @results_type = @page_title
  @no_statement = true
  render 'search/search_results'
end

#searchObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'public/app/controllers/objects_controller.rb', line 62

def search
  @base_search = "/objects/search?"
  page = Integer(params.fetch(:page, "1"))
  begin
    set_up_and_run_search(%w(digital_object archival_object), DEFAULT_OBJ_FACET_TYPES, DEFAULT_OBJ_SEARCH_OPTS, params)
  rescue NoResultsError
    flash[:error] = I18n.t('search_results.no_results')
    redirect_back(fallback_location: '/') and return
  rescue Exception => error
    flash[:error] = I18n.t('errors.unexpected_error')
    redirect_back(fallback_location: '/objects' ) and return
  end
  @page_title = I18n.t('record._plural')
  @results_type = @page_title
  @search_title = I18n.t('search_results.search_for', {:type => I18n.t('record._plural'), :term => params.fetch(:q)[0]})
  @no_statement = true
  render 'search/search_results'
end

#showObject



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
# File 'public/app/controllers/objects_controller.rb', line 81

def show
  uri = "/repositories/#{params[:rid]}/#{params[:obj_type]}/#{params[:id]}"
  url = uri
  if params[:obj_type] == 'archival_objects'
    url = uri += '#pui' if !uri.ends_with?('#pui')
  end
  uri = uri.sub("\#pui", '')
  @criteria = {}
  @criteria['resolve[]'] = ['repository:id', 'resource:id@compact_resource', 'top_container_uri_u_sstr:id', 'linked_instance_uris:id', 'digital_object_uris:id']

  begin
    @result = archivesspace.get_record(url, @criteria)

    if params[:obj_type] == 'digital_objects'
      tree_root = archivesspace.get_raw_record(uri + '/tree/root') rescue nil
      @has_children = tree_root && tree_root['child_count'] > 0
    end

    begin
      @repo_info =  @result.repository_information
      @page_title = @result.display_string
      @context = [
        {:uri => @repo_info['top']['uri'], :crumb => @repo_info['top']['name'], :type => 'repository'}
      ].concat(@result.breadcrumb)
      fill_request_info
      if @result['primary_type'] == 'digital_object' || @result['primary_type'] == 'digital_object_component'
        @dig = process_digital(@result['json'])
      else
        @dig = process_digital_instance(@result['json']['instances'])
        process_extents(@result['json'])
      end
    rescue Exception => error
      Pry::ColorPrinter.pp error.backtrace
      raise error
    end
    render
  rescue RecordNotFound
    type = "#{(params[:obj_type] == 'archival_objects' ? 'archival' : 'digital')}_object"
    record_not_found(uri, type)
  end
end