Skip to content
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

Merged
merged 1 commit into from Mar 14, 2023

Conversation

aaron-collier
Copy link
Contributor

@aaron-collier aaron-collier commented Mar 10, 2023

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 into SymphonyWriter

Example output with 2 previous catkey values:

        [
          {
            catalog_record_id: '123',
            druid: bare_druid
          },
          {
            catalog_record_id: '456',
            druid: bare_druid
          },
          {
            catalog_record_id: '8832162',
            druid: bare_druid,
            indicators: '41',
            subfields: [
              { code: 'u', value: "https://purl.stanford.edu/#{bare_druid}" },
              { code: 'x', value: 'SDR-PURL' },
              { code: 'x', value: 'item' },
              { code: 'x', value: "file:#{bare_druid}%2Fwt183gy6220_00_0001.jp2" },
              { code: 'x', value: "collection:#{collection_bare_druid}:8832162:Collection label & A Special character" },
              { code: 'x', value: 'rights:world' }
            ]
          }
        ]

Copy link
Member

@ndushay ndushay left a 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.

app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
app/services/catalog/marc_856_generator.rb Show resolved Hide resolved
app/services/catalog/symphony_writer.rb Outdated Show resolved Hide resolved
Copy link
Member

@ndushay ndushay left a 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.

@ndushay
Copy link
Member

ndushay commented Mar 10, 2023

Possibly useful for later: /sdrpurl_transfer is where to find the output file on a dsa box.

example:

9876	fg794df6815	.856. 41|uhttps://sul-purl-stage.stanford.edu/fg794df6815|xSDR-PURL|xcollection|xrights:world
4567	xj052tw5711	
9876	fg794df6815	
3060835	ff390ph1693	.856. 40|uhttps://sul-purl-stage.stanford.edu/ff390ph1693|xSDR-PURL|xitem|xrights:world
3060835	ff390ph1693	.856. 40|uhttps://sul-purl-stage.stanford.edu/ff390ph1693|xSDR-PURL|xitem|xrights:world
3060835	ff390ph1693	.856. 40|uhttps://sul-purl-stage.stanford.edu/ff390ph1693|xSDR-PURL|xitem|xrights:world
666	fk408xq4386	.856. 40|zAvailable to Stanford-affiliated users.|uhttps://sul-purl-stage.stanford.edu/fk408xq4386|xSDR-PURL|xitem|xrights:group=stanford

@aaron-collier aaron-collier force-pushed the 4419-refactor-marc856generator-new branch 6 times, most recently from 9abd243 to 9568f93 Compare March 13, 2023 17:51
@aaron-collier aaron-collier changed the title [DRAFT | REDO] Refactor of marc856generator to serialize 856 string [HOLD] Refactor of marc856generator to serialize 856 string Mar 13, 2023
@aaron-collier aaron-collier marked this pull request as ready for review March 13, 2023 17:51
Copy link
Member

@ndushay ndushay left a 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.

app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
@@ -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.
Copy link
Member

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)

app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
app/services/catalog/symphony_writer.rb Outdated Show resolved Hide resolved
@aaron-collier aaron-collier force-pushed the 4419-refactor-marc856generator-new branch 3 times, most recently from 8b2dc37 to de0d041 Compare March 13, 2023 21:15
collections,
parts,
rights
].compact.flatten
Copy link
Contributor Author

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

Copy link
Member

@ndushay ndushay left a 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.

app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
app/services/catalog/marc_856_generator.rb Outdated Show resolved Hide resolved
Copy link
Member

@ndushay ndushay left a 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
Copy link
Member

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?

Copy link
Contributor

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
Copy link
Member

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) }
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a not a

Copy link
Contributor

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
Copy link
Member

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
Copy link
Member

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' }
Copy link
Member

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)}" }
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor

@justinlittman justinlittman left a 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.

@justinlittman justinlittman force-pushed the 4419-refactor-marc856generator-new branch from 17c0935 to 60e35ef Compare March 14, 2023 13:16
@justinlittman
Copy link
Contributor

For the sake of expediency, I made the tweaks and squished the PR.

@justinlittman justinlittman changed the title [HOLD] Refactor of marc856generator to serialize 856 string Refactor of marc856generator to serialize 856 string Mar 14, 2023
@justinlittman justinlittman merged commit 85dbd5e into main Mar 14, 2023
@justinlittman justinlittman deleted the 4419-refactor-marc856generator-new branch March 14, 2023 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants