Sha256: 7d5d1b6e67994e9286426b4e4f0d98881b7878a568a08bfb47007119817e1e80

Contents?: true

Size: 1.93 KB

Versions: 19

Compression:

Stored size: 1.93 KB

Contents

module Hydra
  module PermissionsQuery
    extend ActiveSupport::Concern

    def permissions_doc(pid)
      doc = cache.get(pid)
      unless doc
        doc = get_permissions_solr_response_for_doc_id(pid)
        cache.put(pid, doc)
      end
      doc
    end


    protected

    # a solr query method
    # retrieve a solr document, given the doc id
    # Modeled on Blacklight::SolrHelper.get_permissions_solr_response_for_doc_id
    # @param [String] id of the documetn to retrieve
    # @param [Hash] extra_controller_params (optional)
    def get_permissions_solr_response_for_doc_id(id=nil, extra_controller_params={})
      raise Blacklight::Exceptions::InvalidSolrID.new("The application is trying to retrieve permissions without specifying an asset id") if id.nil?
      solr_opts = permissions_solr_doc_params(id).merge(extra_controller_params)
      response = ActiveFedora::SolrService.instance.conn.get('select', :params=> solr_opts)
      solr_response = Blacklight::SolrResponse.new(response, solr_opts)

      raise Blacklight::Exceptions::InvalidSolrID.new("The solr permissions search handler didn't return anything for id \"#{id}\"") if solr_response.docs.empty?
      Hydra::PermissionsSolrDocument.new(solr_response.docs.first, solr_response)
    end

    #
    #  Solr integration
    #

    # returns a params hash with the permissions info for a single solr document
    # If the id arg is nil, then the value is fetched from params[:id]
    # This method is primary called by the get_permissions_solr_response_for_doc_id method.
    # Modeled on Blacklight::SolrHelper.solr_doc_params
    # @param [String] id of the documetn to retrieve
    def permissions_solr_doc_params(id=nil)
      id ||= params[:id]
      # just to be consistent with the other solr param methods:
      {
        :qt => :permissions,
        :id => id # this assumes the document request handler will map the 'id' param to the unique key field
      }
    end
  end    
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
hydra-access-controls-9.4.1 lib/hydra/permissions_query.rb
hydra-access-controls-9.4.0 lib/hydra/permissions_query.rb
hydra-access-controls-9.3.0 lib/hydra/permissions_query.rb
hydra-access-controls-9.2.2 lib/hydra/permissions_query.rb
hydra-access-controls-9.2.1 lib/hydra/permissions_query.rb
hydra-access-controls-9.2.0 lib/hydra/permissions_query.rb
hydra-access-controls-9.2.0.rc1 lib/hydra/permissions_query.rb
hydra-access-controls-9.1.4 lib/hydra/permissions_query.rb
hydra-access-controls-9.1.3 lib/hydra/permissions_query.rb
hydra-access-controls-9.1.2 lib/hydra/permissions_query.rb
hydra-access-controls-9.1.1 lib/hydra/permissions_query.rb
hydra-access-controls-9.1.0 lib/hydra/permissions_query.rb
hydra-access-controls-9.0.1 lib/hydra/permissions_query.rb
hydra-access-controls-9.0.0 lib/hydra/permissions_query.rb
hydra-access-controls-9.0.0.rc3 lib/hydra/permissions_query.rb
hydra-access-controls-9.0.0.rc2 lib/hydra/permissions_query.rb
hydra-access-controls-9.0.0.rc1 lib/hydra/permissions_query.rb
hydra-access-controls-9.0.0.beta2 lib/hydra/permissions_query.rb
hydra-access-controls-9.0.0.beta1 lib/hydra/permissions_query.rb