-
Notifications
You must be signed in to change notification settings - Fork 0
Adjust fulfillment link logic #322
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,13 +107,55 @@ def links | |
| links << { 'url' => record_link, 'kind' => 'full record' } | ||
| end | ||
|
|
||
| # Add openurl if available | ||
| links << { 'url' => openurl, 'kind' => 'openurl' } if openurl.present? | ||
| # If $$Topenurl_article | ||
| if @record['pnx']['links'] && @record['pnx']['links']['openurl'] && openurl.present? | ||
| links << { 'url' => openurl, 'kind' => 'Check Availability' } | ||
| end | ||
|
|
||
| # Add PDF if available | ||
| if @record['pnx']['links'] && @record['pnx']['links']['linktopdf'] | ||
|
|
||
| parsed_string = parse_link_string(@record['pnx']['links']['linktopdf'].first) | ||
|
|
||
| if parsed_string['U'].present? | ||
| links << { 'url' => parsed_string['U'], | ||
| 'kind' => 'View PDF' } | ||
| end | ||
| end | ||
|
|
||
| # Add HTML if available | ||
| if @record['pnx']['links'] && @record['pnx']['links']['linktohtml'] | ||
|
|
||
| parsed_string = parse_link_string(@record['pnx']['links']['linktohtml'].first) | ||
|
|
||
| if parsed_string['U'].present? | ||
| links << { 'url' => parsed_string['U'], | ||
| 'kind' => 'View HTML' } | ||
| end | ||
| end | ||
|
|
||
| # Return links if we found any | ||
| links.any? ? links : [] | ||
| end | ||
|
|
||
| # Parses a link string into a hash of key-value pairs. | ||
| # The link string is a series of key-value pairs separated by $$, where each pair is prefixed by a single character. | ||
| # For example: "$$Uhttps://example.com$$TView PDF" would be parsed into { 'U' => 'https://example.com', 'T' => 'View PDF' } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking question: I like having a method that will decompose a single string like this into its component parts, and agree with not trying to pluck out values in this method - that happens in the context of whatever logic is fishing for something.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no documentation anywhere, we've never used this in Bento so it is new to our applications with this code. The Primo API doesn't seem to ever change in terms of new features being added and the documentation is genuinely awful. Nearly everything we do with it is reverse engineered and this is sadly no different. This seems to work... but we have no idea if they ever meant it to work this way. If it stops working, we should still get our OpenURL links which do not rely on this logic. These are basically "extra" links that often (but not always) get replaced with LibKey links. |
||
| def parse_link_string(link_string) | ||
| return unless link_string.start_with?('$$') | ||
|
|
||
| parts = link_string.split('$$') | ||
| hash = {} | ||
| parts.each do |part| | ||
| next if part.empty? | ||
|
|
||
| key = part[0] | ||
| value = part[1..-1] | ||
| hash[key] = value | ||
| end | ||
| hash | ||
| end | ||
|
|
||
| def citation | ||
| # We don't want to include citations for Alma records at this time. If we include them in the future they need | ||
| # to be cleaned up as they currently look like `Engineering village 2$$QEngineering village 2` | ||
|
|
@@ -263,22 +305,26 @@ def openurl | |
|
|
||
| def construct_primo_openurl | ||
| return unless @record['delivery']['almaOpenurl'] | ||
| # Primo OpenURL links to some formats are not helpful | ||
| return if format == 'Journal' | ||
| return if format == 'Video' | ||
|
|
||
| # Here we are converting the Alma link resolver URL provided by the Primo | ||
| # Search API to redirect to the Primo UI. This is done for UX purposes, | ||
| # as the regular Alma link resolver URLs redirect to a plaintext | ||
| # disambiguation page. | ||
| primo_openurl_base = [ENV.fetch('MIT_PRIMO_URL', nil), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking comment: This is probably not this ticket, and may be part of the refactoring that Isra is looking at, but I'm realizing that we're doing very similar things in this method and the I don't know if it needs to be, but part of me wants to recommend a ticket to refactor how we build links into Primo, to try and adopt a common syntax / approach.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed feelings about this and have only had two sips of coffee so far so this may make more sense later... Isn't one creating an API link and another creating UI links? While they may be similar, I don't think they'll ever be the same and abstracting the things that are similar when things are distinct feels like it could get confusing rather than simplifying over time. I'm not against looking into this further, but I want us to consider it from both a "DRY" and a "is this really repeating even if it looks like it" perspective. |
||
| '/discovery/openurl?institution=', | ||
| ENV.fetch('EXL_INST_ID', nil), | ||
| ENV.fetch('PRIMO_INST_ID', nil), | ||
| '&vid=', | ||
| ENV.fetch('PRIMO_VID', nil), | ||
| '&'].join | ||
| primo_openurl = @record['delivery']['almaOpenurl'].gsub(ENV.fetch('ALMA_OPENURL', nil), primo_openurl_base) | ||
|
|
||
| # The ctx params appear to break Primo openurls, so we need to remove them. | ||
| params = Rack::Utils.parse_nested_query(primo_openurl) | ||
| filtered = params.delete_if { |key, _value| key.starts_with?('ctx') } | ||
| # params = Rack::Utils.parse_nested_query(primo_openurl) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doh!... I meant to go back and do additional testing. I couldn't find an example where the old conditions made sense but hadn't done exhaustive testing. I'll either update this after doing additional testing or open a ticket to look into this further.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matt-bernhardt I've opened a ticket to do more testing of the OpenURLs to see if we can find any that don't work with this simpler logic. Success criteria are either to revert to stripping ctx or cleaning up the logic if we confirm we no longer need to strip that. |
||
| # filtered = params.delete_if { |key, _value| key.starts_with?('ctx') } | ||
| filtered = primo_openurl | ||
| URI::DEFAULT_PARSER.unescape(filtered.to_param) | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| <% if Libkey.enabled? && @libkey.present? %> | ||
| <%= link_to( @libkey[:text], @libkey[:link], class: 'button', style: 'border: none;' ) %> | ||
| <%= link_to( @libkey[:text], @libkey[:link], class: 'button libkey-link' ) %> | ||
| <% end %> |
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.
Non-blocking comment:
This is probably a question for @djanelle-mit , but I'm wondering if we can track these removals somehow, to know how often they occur. The one test search I did for
exoplanet signature detection methodsreturned 15 different primo links, most of which ended up being suppressed, although some remained.My guess at a question around this would be something like: "How many times do links with the
primo-linkclass appear on a results page? How many times to links with that class get removed from a results page?" . I don't remember what trigger options exist for Matomo tag containers, so I'm not sure what this might look like in practice.If we're going to leave a structure like this in place for long, however, I'd like to consider having it be something that we record analytics about.
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.
Add it to the analytics doc! I'm still operating with an assumption that we can detect if an element with a particular selector was loaded (and not seen), let's make sure we try to track this.