From 09a79c2206f56d7cf2274c66a56648e2852ba9b8 Mon Sep 17 00:00:00 2001 From: Eliot Jordan Date: Fri, 28 Oct 2016 17:09:34 -0500 Subject: [PATCH] catch document build errors --- .../document_builder/date_builder.rb | 2 ++ .../document_builder/spatial_builder.rb | 2 ++ .../discovery/document_builder_spec.rb | 26 +++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/services/geo_concerns/discovery/document_builder/date_builder.rb b/app/services/geo_concerns/discovery/document_builder/date_builder.rb index 17b46b6e..35599801 100644 --- a/app/services/geo_concerns/discovery/document_builder/date_builder.rb +++ b/app/services/geo_concerns/discovery/document_builder/date_builder.rb @@ -25,6 +25,8 @@ def layer_year date = geo_concern.temporal.first year = date.match(/(?<=\D|^)(\d{4})(?=\D|$)/) year ? year[0].to_i : nil + rescue + '' end # Returns the date the work was modified. diff --git a/app/services/geo_concerns/discovery/document_builder/spatial_builder.rb b/app/services/geo_concerns/discovery/document_builder/spatial_builder.rb index 8f3a8282..20a6d182 100644 --- a/app/services/geo_concerns/discovery/document_builder/spatial_builder.rb +++ b/app/services/geo_concerns/discovery/document_builder/spatial_builder.rb @@ -28,6 +28,8 @@ def coverage # @return [String] coverage in solr format def to_solr "ENVELOPE(#{coverage.w}, #{coverage.e}, #{coverage.n}, #{coverage.s})" + rescue + '' end end end diff --git a/spec/services/geo_concerns/discovery/document_builder_spec.rb b/spec/services/geo_concerns/discovery/document_builder_spec.rb index 6f1ba044..ebe94f6c 100644 --- a/spec/services/geo_concerns/discovery/document_builder_spec.rb +++ b/spec/services/geo_concerns/discovery/document_builder_spec.rb @@ -156,12 +156,12 @@ context 'with a missing required metadata field' do before do - attributes.delete(:title) + attributes.delete(:coverage) allow(geo_concern_presenter).to receive(:file_set_presenters).and_return([geo_file_presenter, metadata_presenter]) end it 'returns an error document' do - expect(document['error'][0]).to include('dc_title_s') + expect(document['error'][0]).to include('solr_geom') expect(document['error'].size).to eq(1) end end @@ -177,6 +177,28 @@ end end + context 'with a missing temporal field' do + before do + attributes.delete(:temporal) + allow(geo_concern_presenter).to receive(:file_set_presenters).and_return([geo_file_presenter, metadata_presenter]) + end + + it 'returns a document without the field but valid' do + expect(document['dct_temporal_sm']).to be_nil + end + end + + context 'with a missing issued field' do + before do + attributes.delete(:issued) + allow(geo_concern_presenter).to receive(:file_set_presenters).and_return([geo_file_presenter, metadata_presenter]) + end + + it 'returns a document without the field but valid' do + expect(document['dct_issued_dt']).to be_nil + end + end + context 'with a public visibility' do before do viz = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC