-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds deposit date into cocina description.
closes #2368
- Loading branch information
1 parent
dadb3de
commit 9e05eab
Showing
7 changed files
with
242 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module CocinaGenerator | ||
module Description | ||
# Helper methods for EDTF | ||
class Edtf | ||
def self.props(date) | ||
new(date).props | ||
end | ||
|
||
def initialize(date) | ||
@date = date | ||
end | ||
|
||
def props | ||
{ | ||
encoding: { code: 'edtf' } | ||
}.merge(date.is_a?(EDTF::Interval) ? interval_props : date_props) | ||
end | ||
|
||
private | ||
|
||
attr_reader :date | ||
|
||
def interval_props | ||
{ | ||
structuredValue: interval_structured_values | ||
}.tap do |props| | ||
if date.from&.uncertain? || date.to&.uncertain? | ||
props[:qualifier] = 'approximate' | ||
props[:structuredValue].each { |struct_date_val| struct_date_val.delete(:qualifier) } | ||
end | ||
end.compact | ||
end | ||
|
||
def interval_structured_values | ||
[].tap do |structured_values| | ||
structured_values << date_props_for(date.from, type: 'start') if date.from | ||
structured_values << date_props_for(date.to, type: 'end') if date.to | ||
end | ||
end | ||
|
||
def date_props | ||
date_props_for(date) | ||
end | ||
|
||
def date_props_for(props_date, type: nil) | ||
{ | ||
qualifier: props_date.uncertain? ? 'approximate' : nil, | ||
value: props_date.edtf.chomp('?'), | ||
type: type | ||
}.compact | ||
end | ||
end | ||
end | ||
end |
89 changes: 89 additions & 0 deletions
89
app/services/cocina_generator/description/events_generator.rb
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,89 @@ | ||
# frozen_string_literal: true | ||
|
||
module CocinaGenerator | ||
module Description | ||
# This generates Events for a work | ||
class EventsGenerator | ||
def self.generate(work_version:) | ||
new(work_version: work_version).generate | ||
end | ||
|
||
def initialize(work_version:) | ||
@work_version = work_version | ||
end | ||
|
||
def generate | ||
events = deposit_events + Array(created_date_event) | ||
events += publisher_events.presence || Array(published_date_event) | ||
events | ||
end | ||
|
||
private | ||
|
||
attr_reader :work_version | ||
|
||
def publisher_events | ||
@publisher_events ||= ContributorsGenerator.events_from_publisher_contributors(work_version: work_version, | ||
pub_date: published_date_event) | ||
end | ||
|
||
def published_date_event | ||
edtf_event_for(date: work_version.published_edtf, event_type: 'publication', date_type: 'publication') | ||
end | ||
|
||
def created_date_event | ||
edtf_event_for(date: work_version.created_edtf, event_type: 'creation', date_type: 'creation') | ||
end | ||
|
||
def deposit_events | ||
return [] if deposit_versions.blank? | ||
|
||
Array(deposit_publication_event) + deposit_modification_events | ||
end | ||
|
||
def deposit_publication_event | ||
w3cdtf_event_for(work_version: deposit_publication_version, event_type: 'deposit', date_type: 'publication') | ||
end | ||
|
||
def deposit_modification_events | ||
deposit_modification_versions.map do |deposit_version| | ||
w3cdtf_event_for(work_version: deposit_version, event_type: 'deposit', date_type: 'modification') | ||
end | ||
end | ||
|
||
def deposit_versions | ||
# Treating this version as a deposit version | ||
@deposit_versions ||= work_version.work.work_versions.filter do |check_work_version| | ||
check_work_version.deposited? || check_work_version == work_version | ||
end | ||
end | ||
|
||
def deposit_publication_version | ||
deposit_versions.first | ||
end | ||
|
||
def deposit_modification_versions | ||
deposit_versions.slice(1..-1) | ||
end | ||
|
||
def edtf_event_for(date:, event_type:, date_type:) | ||
return unless date | ||
|
||
Cocina::Models::Event.new( | ||
type: event_type, | ||
date: [Edtf.props(date).merge(type: date_type)] | ||
) | ||
end | ||
|
||
def w3cdtf_event_for(work_version:, event_type:, date_type:) | ||
date = work_version.published_at || work_version.updated_at | ||
return unless date | ||
|
||
Cocina::Models::Event.new( | ||
type: event_type, | ||
date: [W3cdtf.props(date).merge(type: date_type)] | ||
) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module CocinaGenerator | ||
module Description | ||
# Helper methods for W3CDTF | ||
class W3cdtf | ||
def self.props(date) | ||
{ | ||
value: date.strftime('%Y-%m-%d'), | ||
encoding: { code: 'w3cdtf' } | ||
} | ||
end | ||
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
Oops, something went wrong.