-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support typed EDTF data for the
Etd#date
field
An `RDF::Literal` subclass for EDTF datatypes is introduced. This supports the id.loc.gov namespaced datatype for EDTF and can accept any string value as its lexical value. We test that when a date is set to this type, it is correctly serialized in the object's `.ttl` view. Handling is added to `EtdIndexer#generate_solr_document` to ensure edtf dates are indexed text values (they are also indexed as dates, but we do not consume them in catalog controller or elsewhere). The correct appearance of typed data in the show view is tested. Dates input through the `EtdForm` are cast to the typed literal so they can be serialized to Fedora with the correct type. We assume any value put into the "EDTF Date" form field is intended to be interpreted as typed data. Factories are updated to set an EDTF date on build. Closes #186.
- Loading branch information
1 parent
f4ef5e7
commit 31c021f
Showing
11 changed files
with
87 additions
and
3 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
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mahonia | ||
class EdtfLiteral < RDF::Literal | ||
DATATYPE = RDF::URI('http://id.loc.gov/datatypes/edtf/EDTF') | ||
|
||
# support ActiveJob serialization | ||
include GlobalID::Identification | ||
|
||
def self.find(id) | ||
new(id) | ||
end | ||
|
||
def initialize(value, **opts) | ||
value = EDTF.parse(value) || value | ||
@string = value.edtf if value.respond_to? :edtf | ||
super | ||
end | ||
|
||
def id | ||
value | ||
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,12 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe Mahonia::EdtfLiteral do | ||
subject(:literal) { described_class.new(edtf_str) } | ||
let(:edtf_str) { '199x' } | ||
|
||
it 'has an EDTF datatype' do | ||
expect(literal) | ||
.to have_attributes(datatype: RDF::URI('http://id.loc.gov/datatypes/edtf/EDTF')) | ||
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