From 6972c354b6917e4f66182956e8b48b52ed95ac3e Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 1 Jun 2020 12:32:21 -0400 Subject: [PATCH] LP1881607 Angular catalog e-resource links display Display electronic resource links (MARC 856's) in the Angular staff catalog. The extraction logic, which matches the TPAC, has been put into its own API. To test in concerto, navigate to: /eg2/staff/catalog/record/208 Signed-off-by: Bill Erickson --- .../src/app/share/catalog/bib-record.service.ts | 7 ++ .../share/bib-summary/bib-summary.component.html | 13 ++++ .../perlmods/lib/OpenILS/Application/AppUtils.pm | 15 +++- .../lib/OpenILS/Application/Cat/Authority.pm | 8 +- .../lib/OpenILS/Application/Search/Biblio.pm | 89 ++++++++++++++++++++-- 5 files changed, 119 insertions(+), 13 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts index 7510fe0d0b..ce352c7868 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts @@ -17,6 +17,11 @@ export const NAMESPACE_MAPS = { export const HOLDINGS_XPATH = '/holdings:holdings/holdings:counts/holdings:count'; +interface EResourceUrl { + href: string; + note: string; + label: string; +} export class BibRecordSummary { id: number; // == record.id() for convenience @@ -32,6 +37,7 @@ export class BibRecordSummary { bibCallNumber: string; net: NetService; displayHighlights: {[name: string]: string | string[]} = {}; + eResourceUrls: EResourceUrl[] = []; constructor(record: IdlObject, orgId: number, orgDepth?: number) { this.id = Number(record.id()); @@ -106,6 +112,7 @@ export class BibRecordService { summary.attributes = bibSummary.attributes; summary.holdCount = bibSummary.hold_count; summary.holdingsSummary = bibSummary.copy_counts; + summary.eResourceUrls = bibSummary.urls; return summary; })); } diff --git a/Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.html b/Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.html index 3fd955888f..07d9bc0f57 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/bib-summary/bib-summary.component.html @@ -91,6 +91,19 @@
{{summary.record.edit_date() | date:'short'}}
+ +
  • +
    +
    + Electronic Resource: +
    + +
    {{url.note}}
    +
    +
  • +
    diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index 9190ad81b8..04834e20b0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -1,5 +1,7 @@ package OpenILS::Application::AppUtils; use strict; use warnings; +use MARC::Record; +use MARC::File::XML (BinaryEncoding => 'utf8', RecordFormat => 'USMARC'); use OpenILS::Application; use base qw/OpenILS::Application/; use OpenSRF::Utils::Cache; @@ -23,7 +25,7 @@ use Digest::MD5 qw(md5_hex); # Pile of utilty methods used accross applications. # --------------------------------------------------------------------------- my $cache_client = "OpenSRF::Utils::Cache"; - +my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim'; # --------------------------------------------------------------------------- # on sucess, returns the created session, on failure throws ERROR exception @@ -2414,5 +2416,16 @@ sub verify_migrated_user_password { } +# generate a MARC XML document from a MARC XML string +sub marc_xml_to_doc { + my ($class, $xml) = @_; + my $marc_doc = XML::LibXML->new->parse_string($xml); + $marc_doc->documentElement->setNamespace($MARC_NAMESPACE, 'marc', 1); + $marc_doc->documentElement->setNamespace($MARC_NAMESPACE); + return $marc_doc; +} + + + 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm index 82d04f56e9..746f528150 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm @@ -11,19 +11,13 @@ use OpenILS::Utils::Fieldmapper; use OpenILS::Const qw/:const/; use OpenILS::Event; my $U = 'OpenILS::Application::AppUtils'; -my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim'; - # generate a MARC XML document from a MARC XML string sub marc_xml_to_doc { my $xml = shift; - my $marc_doc = XML::LibXML->new->parse_string($xml); - $marc_doc->documentElement->setNamespace($MARC_NAMESPACE, 'marc', 1); - $marc_doc->documentElement->setNamespace($MARC_NAMESPACE); - return $marc_doc; + return $U->marc_xml_to_doc($xml); } - __PACKAGE__->register_method( method => 'import_authority_record', api_name => 'open-ils.cat.authority.record.import', diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index b07440e65a..847427e217 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -2740,6 +2740,73 @@ sub mk_copy_query { return $query; } +__PACKAGE__->register_method( + method => 'record_urls', + api_name => 'open-ils.search.biblio.record.resource_urls.retrieve', + argc => 1, + stream => 1, + signature => { + desc => q/Returns bib record 856 URL content./, + params => [ + {desc => 'Record ID or Array of Record IDs', type => 'number or array'} + ], + return => { + desc => 'Stream of URL objects, one collection object per record', + type => 'object' + } + } +); + +sub record_urls { + my ($self, $client, $record_ids) = @_; + + $record_ids = [$record_ids] unless ref $record_ids eq 'ARRAY'; + + my $e = new_editor(); + + for my $record_id (@$record_ids) { + my $bib = $e->retrieve_biblio_record_entry($record_id) + or return $e->event; + + my $marc_doc = $U->marc_xml_to_doc($bib->marc); + + # Logic copied from TPAC misc_utils.tts + my @urls; + + for my $node ($marc_doc->findnodes( + '//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]')) { + + # asset.uri's + next if $node->findnodes('./*[@code="9" or @code="w" or @code="n"]'); + + my $url = {}; + my ($label) = $node->findnodes('./*[@code="y"]'); + my ($notes) = $node->findnodes('./*[@code="z" or @code="3"]'); + + my $first = 1; + for my $href_node ($node->findnodes('./*[@code="u"]')) { + next unless $href_node; + + # it's possible for multiple $u's to exist within 1 856 tag. + # in that case, honor the label/notes data for the first $u, but + # leave any subsequent $u's as unadorned href's. + # use href/link/note keys to be consistent with args.uri's + + my $href = $href_node->textContent; + push(@urls, { + href => $href, + label => ($first && $label) ? $label->textContent : $href, + note => ($first && $notes) ? $notes->textContent : '' + }); + $first = 0; + } + } + + $client->respond({id => $record_id, urls => \@urls}); + } + + return undef; +} __PACKAGE__->register_method( method => 'catalog_record_summary', @@ -2808,8 +2875,8 @@ sub catalog_record_summary { for my $rec_id (@$record_ids) { my $response = $is_meta ? - get_one_metarecord_summary($e, $rec_id) : - get_one_record_summary($e, $rec_id); + get_one_metarecord_summary($self, $e, $rec_id) : + get_one_record_summary($self, $e, $rec_id); ($response->{copy_counts}) = $copy_method->run($org_id, $rec_id); @@ -2822,10 +2889,20 @@ sub catalog_record_summary { return undef; } +sub get_one_rec_urls { + my ($self, $e, $bib_id) = @_; + + my ($resp) = $self->method_lookup( + 'open-ils.search.biblio.record.resource_urls.retrieve') + ->run($bib_id); + + return $resp->{urls}; +} + # Start with a bib summary and augment the data with additional # metarecord content. sub get_one_metarecord_summary { - my ($e, $rec_id) = @_; + my ($self, $e, $rec_id) = @_; my $meta = $e->retrieve_metabib_metarecord($rec_id) or return {}; my $maps = $e->search_metabib_metarecord_source_map({metarecord => $rec_id}); @@ -2833,6 +2910,7 @@ sub get_one_metarecord_summary { my $bre_id = $meta->master_record; my $response = get_one_record_summary($e, $bre_id); + $response->{urls} = get_one_rec_urls($self, $e, $bre_id); $response->{metabib_id} = $rec_id; $response->{metabib_records} = [map {$_->source} @$maps]; @@ -2857,7 +2935,7 @@ sub get_one_metarecord_summary { } sub get_one_record_summary { - my ($e, $rec_id) = @_; + my ($self, $e, $rec_id) = @_; my $bre = $e->retrieve_biblio_record_entry([$rec_id, { flesh => 1, @@ -2889,7 +2967,8 @@ sub get_one_record_summary { id => $rec_id, record => $bre, display => $display, - attributes => $attributes + attributes => $attributes, + urls => get_one_rec_urls($self, $e, $rec_id) }; } -- 2.11.0