Skip to content

Commit

Permalink
Set date_issued to unknown/unknown if not a valid EDTF date
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar committed May 3, 2022
1 parent 0060294 commit 91ad159
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ source 'https://rubygems.org'

# :default group gems
gem 'dotenv'
gem 'edtf'
gem 'nokogiri'
gem 'rake'
gem 'rest-client'
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ GEM
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.5)
edtf (3.0.8)
activesupport (>= 3.0, < 8.0)
hashdiff (1.0.1)
highline (2.0.3)
http-accept (1.7.0)
Expand Down Expand Up @@ -174,6 +176,7 @@ DEPENDENCIES
capybara
coveralls
dotenv
edtf
highline
mysql2
nokogiri
Expand All @@ -191,4 +194,4 @@ DEPENDENCIES
whenever

BUNDLED WITH
2.0.2
2.3.6
5 changes: 4 additions & 1 deletion lib/objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require 'nokogiri'
require 'restclient'
require 'date'
require 'edtf'

# Class for creating and working with media objects
class Objects
Expand Down Expand Up @@ -506,7 +507,9 @@ def get_fields_from_mods(object)
# TODO: Stick me in a block
begin
fields[:date_issued] = mods.xpath("//mods[1]/originInfo/dateIssued[@encoding='marc']")[0].text
fields[:date_issued] = 'unknown/unknown' if fields[:date_issued] == '' || fields[:date_issued] == 'uuuu'
# Attempt EDTF parsing just like avalon will do to avoid 422 Unprocessable Entity errors due to non-compliant dates
edtf_date = Date.edtf(fields[:date_issued])
fields[:date_issued] = 'unknown/unknown' if edtf_date.nil? || edtf_date.class == EDTF::Unknown
rescue
fields[:date_issued] = 'unknown/unknown'
end
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/objects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@
expect(fields.keys.include? :creator).to be_truthy
expect(fields[:creator]).to eq 'Unknown'
end
it 'should parse to "unknown/unknown" if date_issued is invalid EDTF' do
@object = Objects.new(posted_content: load_sample_obj(filename: 'GR00063679.txt')).parse_request_body
fields = @media_object.get_fields_from_mods(@object)
expect(fields.keys.include? :date_issued).to be_truthy
expect(fields[:date_issued]).to eq 'unknown/unknown'
end

context 'when mods is nested in a modscollection' do
it 'should have a bibliographic id if provided' do
Expand Down

0 comments on commit 91ad159

Please sign in to comment.