Sha256: b2688e83bb66a268d0bbdf21d0102ea7e9a53fce11631043ca10b1206da8b79b

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module Hyrax
  # Responsible for retrieving information based on the given work.
  #
  # @see ProxyDepositRequest
  # @see Hyrax::WorkRelation
  # @see SolrDocument
  # @see Hyrax::SolrService
  # @see ActiveFedora::SolrQueryBuilder
  # @note This was extracted from the ProxyDepositRequest, which was coordinating lots of effort. It was also an ActiveRecord object that required lots of Fedora/Solr interactions.
  class WorkQueryService
    # @param [String] id - The id of the work
    # @param [#exists?, #find] work_relation - How we will query some of the related information
    def initialize(id:, work_relation: default_work_relation)
      @id = id
      @work_relation = work_relation
    end
    attr_reader :id, :work_relation

    private

      def default_work_relation
        Hyrax::WorkRelation.new
      end

    public

    # @return [Boolean] if the work has been deleted
    def deleted_work?
      !work_relation.exists?(id)
    end

    def work
      @work ||= work_relation.find(id)
    end

    def to_s
      if deleted_work?
        'work not found'
      else
        solr_doc.to_s
      end
    end

    private

      def solr_doc
        @solr_doc ||= ::SolrDocument.new(solr_response['response']['docs'].first, solr_response)
      end

      def solr_response
        @solr_response ||= Hyrax::SolrService.get(query)
      end

      def query
        Hyrax::SolrQueryBuilderService.construct_query_for_ids([id])
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyrax-3.0.0.pre.rc1 app/services/hyrax/work_query_service.rb
hyrax-3.0.0.pre.beta3 app/services/hyrax/work_query_service.rb