New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor of marc856generator to serialize 856 string #4432
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few small notes on ...stuff we didn't fully understand before today. Tagging @justinlittman as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to talk about this; just making extra sure we don't merge by accident.
Possibly useful for later: example:
|
9abd243
to
9568f93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to pair or talk through my thinking on the 856 generator vs. the symphony writer -- what logic lives where and what the data structure needs to be.
My vision is that all the logic for exactly what data goes in the 856 lives in the 856 generator, and the writer classes are really stupid and just munge the data into the form needed by the consuming ILS. In Symphony's case, one string per identiier, with periods and "|" as markup. In Folio's case, not sure, but maybe a particular JSON structure.
@@ -2,7 +2,7 @@ | |||
|
|||
# rubocop:disable Metrics/ClassLength | |||
module Catalog | |||
# Creates a stub MARC 856 field (currently for transferring to symphony only) given a cocina object. | |||
# Creates a hash that is used to stub the MARC 856 field (currently for transferring to symphony only) given a cocina object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditch "currenty for symphony only" clause
And now were not talking about a stub any longer -- this class is returning identifiers and then a hash of data to build a plain old marc 856 field, or no such hash to imply 856 matching druid should be removed.
@justinlittman did you want to keep the identifier information and whether or not it has an 856 associated in THIS class? (makes sense to ... just confirming)
8b2dc37
to
de0d041
Compare
collections, | ||
parts, | ||
rights | ||
].compact.flatten |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this compact
and flatten
removes any nil
values returned from the list of methods, and then flattens the ones that return arrays like collections
and rights
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes to 856 looking good; a few small quibbles. I also float the idea that you migh somehow indicate that, for example, "access" is returning the hash for subfield z. Maybe access_subfield_z
or subfield_z_access
or maybe you have something better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, modulo:
- look for catkey and ckey in the 856 code and spec (can leave for symphony writer)
- typo in comment line 55
having Andrew (?) try it in test.
} | ||
] | ||
end | ||
let(:marc856) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call this marc856file or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
] | ||
end | ||
let(:marc856) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call this marc856file or something?
|
||
# first create "blank" records for any previous catkeys | ||
records = previous_ckeys.map { |previous_catkey| new_identifier_record(previous_catkey) } | ||
records = previous_catalog_record_ids.map { |previous_catkey| new_identifier_record(previous_catkey) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh - missed this before - previous_catkey
new856 += get_x2_part_info unless get_x2_part_info.nil? | ||
new856 += get_x2_rights_info unless get_x2_rights_info.nil? | ||
new856 | ||
# NOTE: this is the data to go in an 856 field (not a (not a properly formatted 856 field nor a marc record) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a not a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
# (future types of sets to describe other aggregations like albums, atlases, etc) | ||
# x - barcode (optional): the barcode if known (<identityMetadata><otherId name="barcode">, recorded as barcode:barcode-value | ||
# x - thumbnail (optional): the file-id to be used as thumb if available, recorded as file:file-id-value | ||
# x - collections (optional): Collection(s) this object is a member of, formatted as: druid:catkey:label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catkey
def subfield_x_thumbnail | ||
return unless @thumbnail_service.thumb | ||
|
||
{ code: 'x', value: "file:#{ERB::Util.url_encode(@thumbnail_service.thumb)}" } | ||
end | ||
|
||
# returns the collection information subfields if exists | ||
# @return [String] the collection information druid-value:catkey-value:title format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catkey
return unless @cocina_object.respond_to?(:structural) && @cocina_object.structural | ||
|
||
collections = @cocina_object.structural.isMemberOf | ||
collection_info = '' | ||
collection_info = [] | ||
|
||
collections.each do |collection_druid| | ||
collection = CocinaObjectStore.find(collection_druid) | ||
next unless released_to_searchworks?(collection) | ||
|
||
catkey = collection.identification&.catalogLinks&.find { |link| link.catalog == 'symphony' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catkey
|
||
collections.each do |collection_druid| | ||
collection = CocinaObjectStore.find(collection_druid) | ||
next unless released_to_searchworks?(collection) | ||
|
||
catkey = collection.identification&.catalogLinks&.find { |link| link.catalog == 'symphony' } | ||
collection_info += "|xcollection:#{collection.externalIdentifier.sub('druid:', | ||
'')}:#{catkey&.catalogRecordId}:#{Cocina::Models::Builders::TitleBuilder.build(collection.description.title)}" | ||
collection_info << { code: 'x', value: "collection:#{collection.externalIdentifier.sub('druid:', '')}:#{catkey&.catalogRecordId}:#{Cocina::Models::Builders::TitleBuilder.build(collection.description.title)}" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catkey
def previous_ckeys | ||
@previous_ckeys ||= fetch_ckeys(current: false) | ||
def previous_catalog_record_ids | ||
@previous_catalog_record_ids ||= fetch_catalog_record_ids(current: false) | ||
end | ||
|
||
# List of current or previous ckeys for the cocina object (depending on parameter passed) | ||
# @param current [boolean] if you want the current or previous ckeys | ||
# @return [Array] previous or current catkeys for the object in an array, empty array if none exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catkey
@@ -165,7 +165,7 @@ | |||
|
|||
context "when the druid object doesn't have catkey or previous catkeys" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look for catkey and ckey in the spec, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR gets us most of the way there. However, there is still some Symphony specific logic:
- Determining which records have 865s to be deleted and added.
- The inclusion of the catkey in subfield x collections. (Missed that before.)
That being said, I'd suggest that this is good enough (=huge improvement and step in the right direction) for this PR. I'd suggest that we make the minor tweaks recommended by Naomi, but leave all remaining catkey references as is. (Just renaming them to catalog record id doesn't solve the problem.) I'll address them in a follow-up PR that removes the last bits of Symphony-specific logic.
Also, makes sense to delay testing until the follow-up PR.
17c0935
to
60e35ef
Compare
For the sake of expediency, I made the tweaks and squished the PR. |
Why was this change made? 馃
This refactors
marc856generator
to return an array of hashed data used to create stub 856 records and moves all symphony specific serialization intoSymphonyWriter
Example output with 2 previous catkey values: