From 294ce5c5cff4a6b8d1ba1fce71cc110501980796 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 21 May 2019 18:31:09 +0000 Subject: [PATCH] JBAS-2285 Browse authorit unauthorized db func Move the check to see if an authority browse entry is unauthorized into the database so we can limit to authority fields of the same metabib_field class (e.g. 'subject'). Signed-off-by: Bill Erickson --- KCLS/sql/schema/deploy/3.2-additions.sql | 23 +++++++++++ .../perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm | 44 ++++++---------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/KCLS/sql/schema/deploy/3.2-additions.sql b/KCLS/sql/schema/deploy/3.2-additions.sql index 6756ec07ae..3b8000515f 100644 --- a/KCLS/sql/schema/deploy/3.2-additions.sql +++ b/KCLS/sql/schema/deploy/3.2-additions.sql @@ -174,6 +174,29 @@ BEGIN END IF; -- insert_on_deploy END $INSERT$; +-- returns +CREATE OR REPLACE FUNCTION + metabib.browse_authority_is_unauthorized (mbe_id BIGINT, field_class TEXT) + RETURNS TABLE (auth_tag CHARACTER(3), atag INTEGER, auth_record BIGINT) AS +$$ + SELECT + acsaf.tag AS auth_tag, + ash.atag AS atag, + ash.record AS auth_record + FROM metabib.browse_entry_simple_heading_map map + JOIN authority.simple_heading ash ON (ash.id = map.simple_heading) + JOIN authority.control_set_authority_field acsaf on (acsaf.id = ash.atag) + JOIN authority.heading_field ahf ON (ahf.id = acsaf.heading_field) + JOIN authority.control_set_auth_field_metabib_field_map_refs refs_map + ON (ash.atag = refs_map.authority_field) + JOIN config.metabib_field cmf ON (cmf.id = refs_map.metabib_field) + WHERE map.entry = $1 + AND cmf.field_class = $2 + AND ahf.heading_purpose = 'variant' + LIMIT 1 +$$ LANGUAGE SQL; + + -- BACK-PORTING https://bugs.launchpad.net/evergreen/+bug/1811689 -- which is not yet merged to master, but needed for 3.2 upgrade. CREATE OR REPLACE FUNCTION reporter.enable_materialized_simple_record_trigger () RETURNS VOID AS $$ diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm index b9fa7c3622..4b1cdf4af6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm @@ -424,7 +424,8 @@ sub load_browse { } if ($results) { - $self->gather_display_headings($results); + my $field_class = $params[0]; + $self->gather_display_headings($results, $field_class); $self->ctx->{browse_results} = $self->infer_browse_paging($results); } @@ -439,11 +440,12 @@ sub load_browse { # Loops through the results and determines if the browse entry is authoritative or not # then passes that entry to the appropriate set_heading function. sub gather_display_headings { - my ($self, $results) = @_; + my ($self, $results, $field_class) = @_; for my $browse_term (@$results) { $browse_term->{ref_headings} = {}; - my $auth_id = $self->is_not_authoritative($browse_term->{browse_entry}); + my $auth_id = $self->is_not_authoritative( + $browse_term->{browse_entry}, $field_class); if($auth_id) { $self->set_see_heading($browse_term, $auth_id); } else { @@ -672,40 +674,18 @@ sub get_browse_entry_marc { # and checks to see if that entry is a 400, 430 or 450 reference in another authority # record. This is useful to know so we can filter out See Also references # for non-authoritative entries. +my %cmf_cache; sub is_not_authoritative { my $self = shift; my $id = shift; - - my $result = $self->editor->json_query({ - select => { - acsaf => ["tag"], - ash => ["record"] - }, - from => { - acsaf => { - ash => { - fkey => "id", field => "atag", - join => { - mbeshm => { - fkey => "id", field => "simple_heading", - join => { - mbe => { - fkey => "entry", field => "id" - } - } - } - } - } - } - }, - where => {"+mbe" => {id => $id}} - }); + my $field_class = shift; - # If the result tag begins with a 4 we have an unauthorized heading so return true. - if ($result->[0] && $result->[0]{tag} =~ /^4/) { - return $result->[0]{record}; - } + my $result = $self->editor->json_query({ + from => ['metabib.browse_authority_is_unauthorized', $id, $field_class] + })->[0]; + return $result->{record} if $result; + return 0; } -- 2.11.0