-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proxy deposit requests use valkyrie-specific query service when use_v…
…alkyrie? is true
- Loading branch information
Showing
8 changed files
with
241 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
# Responsible for retrieving information based on the given work. | ||
# | ||
# @see ProxyDepositRequest | ||
# @see SolrDocument | ||
# @see Hyrax::SolrService | ||
# @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 WorkResourceQueryService | ||
# @param [String] id - The id of the work | ||
def initialize(id:) | ||
@id = id | ||
end | ||
attr_reader :id | ||
|
||
# @return [Boolean] if the work has been deleted | ||
def deleted_work? | ||
Hyrax.query_service.find_by(id: id) | ||
false | ||
rescue Valkyrie::Persistence::ObjectNotFoundError | ||
true | ||
end | ||
|
||
def work | ||
# Need to ensure it is a work? | ||
resource = Hyrax.query_service.find_by(id: id) | ||
unless Hyrax.config.curation_concerns.include?(resource.class) || | ||
Hyrax.config.curation_concerns.map(&:to_s).include?(resource.class.to_s) || # Wings-wrapped models | ||
Hyrax.config.curation_concerns.map(&:to_s).include?(resource.class.name) # Wings-wrapped models | ||
raise ModelMismatchError, "Expected allowed work type but got #{resource.class}" | ||
end | ||
resource | ||
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(Hyrax::SolrService.search_by_id(id)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
RSpec.describe WorkResourceQueryService do | ||
let(:user) { create(:user) } | ||
let(:work) { FactoryBot.valkyrie_create(:monograph, title: ['Test work']) } | ||
let(:work_query_service) { described_class.new(id: work.id) } | ||
|
||
describe '#deleted_work?' do | ||
subject { work_query_service.deleted_work? } | ||
|
||
context 'when not in SOLR' do | ||
let(:work_query_service) { described_class.new(id: 'deleted-id') } | ||
|
||
it { is_expected.to be_truthy } | ||
end | ||
context 'when in SOLR' do | ||
it { is_expected.to be_falsey } | ||
end | ||
end | ||
describe '#work' do | ||
subject { work_query_service.work } | ||
|
||
context 'when in SOLR' do | ||
it { expect(subject.id).to eq(work.id) } | ||
end | ||
end | ||
describe '#to_s' do | ||
subject { work_query_service.to_s } | ||
|
||
context 'when the work is deleted' do | ||
let(:work_query_service) { described_class.new(id: 'deleted-id') } | ||
|
||
it { is_expected.to eq('work not found') } | ||
end | ||
|
||
context 'when the work is not deleted' do | ||
it 'will retrieve the SOLR document and use the #to_s method of that' do | ||
expect(subject).to eq(work.title.first) | ||
end | ||
end | ||
end | ||
end | ||
end |