LP1881607 Angular catalog located URIs user/berick/lp1881607-ang-cat-eresource-links-3
authorBill Erickson <berickxx@gmail.com>
Wed, 23 Sep 2020 15:15:22 +0000 (11:15 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 23 Sep 2020 15:15:24 +0000 (11:15 -0400)
Display in-range located URIs in the staff catalog record summary pane.

Also applies a fix to the staff catalog to clear cached record detail
summaries on new searches to ensure the correct org-scoped version of
the record summary is retrieved on each new navigation to the detail
page.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm

index a065274..acbb78c 100644 (file)
@@ -97,6 +97,9 @@ export class StaffCatalogService {
     search(): void {
         if (!this.searchContext.isSearchable()) { return; }
 
+        // Clear cached detail summary for new searches.
+        this.currentDetailRecordSummary = null;
+
         const params = this.catUrl.toUrlParams(this.searchContext);
 
         // Force a new search every time this method is called, even if
index 04834e2..7562078 100644 (file)
@@ -1533,6 +1533,26 @@ sub get_org_ancestors {
     return $orgs;
 }
 
+# Returns an array of org unit shortnames (codes) of ancestor+me orgs.
+sub get_org_ancestors_sn {
+    my($self, $org_id) = @_;
+
+    my $org_list = OpenILS::Utils::CStoreEditor->new->json_query({
+        select => {
+            aou => [{
+                transform => 'actor.org_unit_ancestors',
+                column => 'id',
+                result_field => 'shortname',
+                params => []
+            }],
+        },
+        from => 'aou',
+        where => {id => $org_id}
+    });
+
+    return [ map { $_->{shortname} } @$org_list ];
+}
+
 sub get_org_full_path {
     my($self, $org_id, $depth) = @_;
 
index 8016680..183d1e1 100644 (file)
@@ -2860,6 +2860,7 @@ __PACKAGE__->register_method(
     signature => {
         desc   => q/Returns bib record 856 URL content./,
         params => [
+            {desc => 'Context org unit ID', type => 'number'},
             {desc => 'Record ID or Array of Record IDs', type => 'number or array'}
         ],
         return => {
@@ -2870,12 +2871,14 @@ __PACKAGE__->register_method(
 );
 
 sub record_urls {
-    my ($self, $client, $record_ids) = @_;
+    my ($self, $client, $org_id, $record_ids) = @_;
 
     $record_ids = [$record_ids] unless ref $record_ids eq 'ARRAY';
 
     my $e = new_editor();
 
+    my %uri_orgs = map { lc($_) => 1 } @{$U->get_org_ancestors_sn($org_id)};
+
     for my $record_id (@$record_ids) {
         my $bib = $e->retrieve_biblio_record_entry($record_id)
             or return $e->event;
@@ -2889,12 +2892,18 @@ sub record_urls {
             '//*[@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"]');
+            next if $node->findnodes('./*[@code="w" or @code="n"]');
 
             my $url = {};
             my ($label) = $node->findnodes('./*[@code="y"]');
             my ($notes) = $node->findnodes('./*[@code="z" or @code="3"]');
 
+            # For located URIs, at least one of the $9 subfield values
+            # (org unit shortname) must be within our context org unit range.
+            if (my @orgsns = $node->findnodes('./*[@code="9"]')) {
+                next unless grep { $uri_orgs{lc($_->textContent)} } @orgsns;
+            }
+
             my $first = 1;
             for my $href_node ($node->findnodes('./*[@code="u"]')) {
                 next unless $href_node;
@@ -2987,8 +2996,8 @@ sub catalog_record_summary {
     for my $rec_id (@$record_ids) {
 
         my $response = $is_meta ? 
-            get_one_metarecord_summary($self, $e, $rec_id) :
-            get_one_record_summary($self, $e, $rec_id);
+            get_one_metarecord_summary($self, $e, $org_id, $rec_id) :
+            get_one_record_summary($self, $e, $org_id, $rec_id);
 
         ($response->{copy_counts}) = $copy_method->run($org_id, $rec_id);
 
@@ -3002,11 +3011,11 @@ sub catalog_record_summary {
 }
 
 sub get_one_rec_urls {
-    my ($self, $e, $bib_id) = @_;
+    my ($self, $e, $org_id, $bib_id) = @_;
 
     my ($resp) = $self->method_lookup(
         'open-ils.search.biblio.record.resource_urls.retrieve')
-        ->run($bib_id);
+        ->run($org_id, $bib_id);
 
     return $resp->{urls};
 }
@@ -3014,15 +3023,15 @@ sub get_one_rec_urls {
 # Start with a bib summary and augment the data with additional
 # metarecord content.
 sub get_one_metarecord_summary {
-    my ($self, $e, $rec_id) = @_;
+    my ($self, $e, $org_id, $rec_id) = @_;
 
     my $meta = $e->retrieve_metabib_metarecord($rec_id) or return {};
     my $maps = $e->search_metabib_metarecord_source_map({metarecord => $rec_id});
 
     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);
+    my $response = get_one_record_summary($e, $org_id, $bre_id);
+    $response->{urls} = get_one_rec_urls($self, $e, $org_id, $bre_id);
 
     $response->{metabib_id} = $rec_id;
     $response->{metabib_records} = [map {$_->source} @$maps];
@@ -3047,7 +3056,7 @@ sub get_one_metarecord_summary {
 }
 
 sub get_one_record_summary {
-    my ($self, $e, $rec_id) = @_;
+    my ($self, $e, $org_id, $rec_id) = @_;
 
     my $bre = $e->retrieve_biblio_record_entry([$rec_id, {
         flesh => 1,
@@ -3080,7 +3089,7 @@ sub get_one_record_summary {
         record => $bre,
         display => $display,
         attributes => $attributes,
-        urls => get_one_rec_urls($self, $e, $rec_id)
+        urls => get_one_rec_urls($self, $e, $org_id, $rec_id)
     };
 }