Sha256: a6a740acf0d895f804b0e542df9ad5897352d41cc1c1667350ee91e92cef81ca

Contents?: true

Size: 1.43 KB

Versions: 11

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true
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::SolrQueryService.new.with_ids(ids: [id]).build
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/services/hyrax/work_query_service.rb
hyrax-5.0.0 app/services/hyrax/work_query_service.rb
hyrax-5.0.0.rc3 app/services/hyrax/work_query_service.rb
hyrax-5.0.0.rc2 app/services/hyrax/work_query_service.rb
hyrax-5.0.0.rc1 app/services/hyrax/work_query_service.rb
hyrax-4.0.0 app/services/hyrax/work_query_service.rb
hyrax-4.0.0.rc3 app/services/hyrax/work_query_service.rb
hyrax-4.0.0.rc2 app/services/hyrax/work_query_service.rb
hyrax-4.0.0.rc1 app/services/hyrax/work_query_service.rb
hyrax-4.0.0.beta2 app/services/hyrax/work_query_service.rb
hyrax-4.0.0.beta1 app/services/hyrax/work_query_service.rb