Sha256: d7df9934a94e4099cd1f39027fd83893f1061dbf10b94c64bff42e32f9d11c5e

Contents?: true

Size: 1.44 KB

Versions: 14

Compression:

Stored size: 1.44 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::SolrQueryBuilderService.construct_query_for_ids([id])
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/services/hyrax/work_query_service.rb
hyrax-3.5.0 app/services/hyrax/work_query_service.rb
hyrax-3.4.2 app/services/hyrax/work_query_service.rb
hyrax-3.4.1 app/services/hyrax/work_query_service.rb
hyrax-3.4.0 app/services/hyrax/work_query_service.rb
hyrax-3.3.0 app/services/hyrax/work_query_service.rb
hyrax-3.2.0 app/services/hyrax/work_query_service.rb
hyrax-3.1.0 app/services/hyrax/work_query_service.rb
hyrax-3.0.2 app/services/hyrax/work_query_service.rb
hyrax-3.0.1 app/services/hyrax/work_query_service.rb
hyrax-3.0.0 app/services/hyrax/work_query_service.rb
hyrax-3.0.0.pre.rc4 app/services/hyrax/work_query_service.rb
hyrax-3.0.0.pre.rc3 app/services/hyrax/work_query_service.rb
hyrax-3.0.0.pre.rc2 app/services/hyrax/work_query_service.rb