diff --git a/lib/dor/models/identifiable.rb b/lib/dor/models/identifiable.rb
index dfcd96a6..d105e9f8 100644
--- a/lib/dor/models/identifiable.rb
+++ b/lib/dor/models/identifiable.rb
@@ -233,10 +233,15 @@ def solrize_related_obj_titles(solr_doc, relationships, title_hash, union_field_
# populate cache if necessary
unless title_hash.key?(rel_druid)
- related_obj = Dor.find(rel_druid)
- related_obj_title = get_related_obj_display_title(related_obj, rel_druid)
- is_from_hydrus = (related_obj && related_obj.tags.include?('Project : Hydrus'))
- title_hash[rel_druid] = {'related_obj_title' => related_obj_title, 'is_from_hydrus' => is_from_hydrus}
+ begin
+ related_obj = Dor.find(rel_druid)
+ related_obj_title = get_related_obj_display_title(related_obj, rel_druid)
+ is_from_hydrus = (related_obj && related_obj.tags.include?('Project : Hydrus'))
+ title_hash[rel_druid] = {'related_obj_title' => related_obj_title, 'is_from_hydrus' => is_from_hydrus}
+ rescue ActiveFedora::ObjectNotFoundError
+ # This may happen if the given APO or Collection does not exist (bad data)
+ title_hash[rel_druid] = {'related_obj_title' => rel_druid, 'is_from_hydrus' => false}
+ end
end
# cache should definitely be populated, so just use that to write solr field
diff --git a/spec/dor/identifiable_spec.rb b/spec/dor/identifiable_spec.rb
index a91242ba..0e6655fd 100644
--- a/spec/dor/identifiable_spec.rb
+++ b/spec/dor/identifiable_spec.rb
@@ -8,6 +8,18 @@ class IdentifiableItem < ActiveFedora::Base
before(:each) { stub_config }
after(:each) { unstub_config }
+ before(:all) do
+ @mock_rel_druid = 'druid:does_not_exist'
+ @mock_rels_ext_xml = %(
+
+
+
+
+
+ )
+ end
+
let(:item) do
item = instantiate_fixture('druid:ab123cd4567', IdentifiableItem)
allow(item).to receive(:new?).and_return(false)
@@ -192,29 +204,30 @@ class IdentifiableItem < ActiveFedora::Base
describe 'to_solr' do
it 'should generate collection and apo title fields' do
- mock_apo_druid = 'druid:fg890hi1234'
- mock_rels_ext_xml = %(
-
-
-
-
- )
-
- allow(item.datastreams['RELS-EXT']).to receive(:content).and_return(mock_rels_ext_xml)
- allow(Dor).to receive(:find).with(mock_apo_druid).and_return(nil)
-
+ allow(item.datastreams['RELS-EXT']).to receive(:content).and_return(@mock_rels_ext_xml)
+ allow(Dor).to receive(:find).with(@mock_rel_druid).and_raise(ActiveFedora::ObjectNotFoundError)
doc = item.to_solr
['apo_title', 'nonhydrus_apo_title'].each do |field_name|
- expect(doc[Solrizer.solr_name(field_name, :symbol)].first).to eq(mock_apo_druid)
- expect(doc[Solrizer.solr_name(field_name, :stored_searchable)].first).to eq(mock_apo_druid)
+ expect(doc[Solrizer.solr_name(field_name, :symbol)].first).to eq(@mock_rel_druid)
+ expect(doc[Solrizer.solr_name(field_name, :stored_searchable)].first).to eq(@mock_rel_druid)
end
end
it 'should index metadata source' do
expect(item.to_solr).to match a_hash_including('metadata_source_ssi' => 'Symphony')
end
+ it 'should generate set collection and apo fields to the druid if the collection or apo does not exist' do
+ allow(item.datastreams['RELS-EXT']).to receive(:content).and_return(@mock_rels_ext_xml)
+ allow(Dor).to receive(:find).with(@mock_rel_druid).and_raise(ActiveFedora::ObjectNotFoundError)
+ doc = item.to_solr
+
+ ['apo_title', 'collection_title'].each do |field_name|
+ expect(doc[Solrizer.solr_name(field_name, :symbol)].first).to eq(@mock_rel_druid)
+ expect(doc[Solrizer.solr_name(field_name, :stored_searchable)].first).to eq(@mock_rel_druid)
+ end
+ end
end
+
describe 'get_related_obj_display_title' do
it 'should return the dc:title if it is available' do
mock_apo_title = 'apo title'