Bugzilla – Attachment 183815 Details for
Bug 40310
New authority framework plugin for MARC21 (marc21_field_083a_authorities.pl)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40310: add new Authority Framework plugin for MARC21 083$a
Bug-40310-add-new-Authority-Framework-plugin-for-M.patch (text/plain), 9.23 KB, created by
Andreas Roussos
on 2025-07-07 00:19:19 UTC
(
hide
)
Description:
Bug 40310: add new Authority Framework plugin for MARC21 083$a
Filename:
MIME Type:
Creator:
Andreas Roussos
Created:
2025-07-07 00:19:19 UTC
Size:
9.23 KB
patch
obsolete
>From 1fe5a47629605b0604b7c258176927c271dab1d1 Mon Sep 17 00:00:00 2001 >From: Andreas Roussos <a.roussos@dataly.gr> >Date: Mon, 7 Jul 2025 03:06:12 +0300 >Subject: [PATCH] Bug 40310: add new Authority Framework plugin for MARC21 > 083$a > >This Authority Framework plugin should be attached to MARC21 authority >subfield 083$a, which will then allow the cataloguer to lookup a single >DDC (or a DDC range if 083$b is also filled in) in exchange for a Dewey >Linked Data URL and Description that will be copied to subfields 083$1 >and 083$c, respectively. > >Test plan: > >1) Go to Administration > Authority types, and for each authtype > associate subfield 083$a with the marc21_field_083a_authorities.pl > plugin. > >2) Create a new authority, or edit an existing one. Click on the > 'Tag editor' button on the far right of the 083$a subfield. > Experiment with the behaviour of the plugin when no DDC has > been filled in, or when an erroneous DDC has been filled in, > or when 083$b has also been filled in. Monitor your browser's > JavaScript console for warnings/errors (there shouldn't be any!). > >3) Experiment with changing the values of the related System > Preferences (found under the 'OCLC Dewey Linked Data API' > heading) and seeing how it affects the behaviour of the > plugin launcher. >--- > .../marc21_field_083a_authorities.pl | 221 ++++++++++++++++++ > 1 file changed, 221 insertions(+) > create mode 100755 cataloguing/value_builder/marc21_field_083a_authorities.pl > >diff --git a/cataloguing/value_builder/marc21_field_083a_authorities.pl b/cataloguing/value_builder/marc21_field_083a_authorities.pl >new file mode 100755 >index 0000000000..202ee1e25a >--- /dev/null >+++ b/cataloguing/value_builder/marc21_field_083a_authorities.pl >@@ -0,0 +1,221 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Copyright (C) 2025 Dataly Tech >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use C4::Auth qw( check_cookie_auth get_template_and_user ); >+use C4::Context qw( preference ); >+use C4::Output qw( output_html_with_http_headers ); >+ >+use Koha::Caches; >+use Koha::ExternalContent::OCLC; >+ >+use CGI qw( -utf8 ); >+use JSON qw( from_json to_json ); >+use LWP::UserAgent; >+ >+use YAML; >+ >+my $input = CGI->new; >+my ($auth_status) = >+ check_cookie_auth( $input->cookie('CGISESSID'), { catalogue => 1 } ); >+if ( $auth_status ne "ok" ) { >+ print $input->header( -type => 'text/plain', -status => '403 Forbidden' ); >+ exit 0; >+} >+ >+my $builder = sub { >+ my ($params) = @_; >+ >+ my $function_name = $params->{id}; >+ >+ my $ddcregex = '^((T([1-6])--([0-9]+)))$|^([0-9]{3})$|^(([0-9]{3})\.([0-9]+))$'; >+ >+ my $res = " >+<script> >+ function Click$function_name(event) { >+ event.preventDefault(); >+ >+ const ddcregex = /$ddcregex/; >+ >+ const subfield_a = document.getElementById(event.data.id); >+ const subfield_b = subfield_a.closest(\".sortable_subfield\").querySelector(\"li[id^=subfield083b] input[id^=tag_083_subfield_b_]\"); >+ const subfield_c = subfield_a.closest(\".sortable_subfield\").querySelector(\"li[id^=subfield083c] input[id^=tag_083_subfield_c_]\"); >+ const subfield_1 = subfield_a.closest(\".sortable_subfield\").querySelector(\"li[id^=subfield0831] input[id^=tag_083_subfield_1_]\"); >+ >+ subfield_c.style.transition = \"background-color 1000ms linear\"; >+ subfield_1.style.transition = \"background-color 1000ms linear\"; >+ >+ if ( ! subfield_a.value ) { >+ updateContent( subfield_1, \"No DDC number provided\" ); >+ return 1; >+ } else if ( ! ddcregex.test(subfield_a.value) ) { >+ updateContent( subfield_1, \"Invalid DDC number provided in subfield \$a\" ); >+ return 1; >+ } else if ( subfield_b.value && ! ddcregex.test(subfield_b.value) ) { >+ updateContent( subfield_1, \"Invalid DDC number provided in subfield \$b\" ); >+ return 1; >+ } >+ >+ if ( subfield_a.value && subfield_b.value ) { >+ // It's a DDC range, separate the two numbers with a hyphen >+ ddc_request = subfield_a.value + '-' + subfield_b.value; >+ } else if ( subfield_a.value && ! subfield_b.value ) { >+ ddc_request = subfield_a.value; >+ } >+ >+ const url = \"../cataloguing/plugin_launcher.pl?plugin_name=marc21_field_083a_authorities.pl&ddc=\" + ddc_request; >+ var request = \$.get(url); >+ >+ request.done( function(response) { >+ const failregex = />Access denied/; >+ if ( failregex.test(response) ) { >+ updateContent( subfield_1, \"Access denied, you need at least the \\\"catalogue\\\" and \\\"editauthorities\\\" user permissions\" ); >+ return 1; >+ } else { >+ const json = JSON.parse(response)[0]; >+ if ( json.info ) { >+ updateContent( subfield_1, json.info ); >+ return 1; >+ } else { >+ updateContent( subfield_1, json.ld_url ); >+ updateContent( subfield_c, json.ld_descr ); >+ } >+ } >+ return 0; >+ }); >+ } >+ >+ // Credit to: https://stackoverflow.com/a/62468495 >+ function updateContent( element, content ) { >+ // update content >+ element.value = content; >+ // change the background color (will trigger the CSS configured transition) >+ element.style.backgroundColor = \"yellow\"; >+ // change the background color back (with a delay equal to transition length) >+ setTimeout(() => { element.style.backgroundColor = \"white\"; }, 2000); >+ } >+</script> >+"; >+ return $res; >+}; >+ >+my $launcher = sub { >+ my ($params) = @_; >+ my $input = $params->{cgi}; >+ my $ddc_number = $input->param('ddc'); >+ >+ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "cataloguing/value_builder/ajax.tt", >+ query => $input, >+ type => "intranet", >+ flagsrequired => { editauthorities => 1 }, >+ } >+ ); >+ >+ my @ret; >+ my $msg; >+ my $info = undef; >+ my $enabled = C4::Context->preference('OCLCDeweyLinkedDataAPI') ? 1 : 0; >+ my $language = C4::Context->preference('OCLCDeweyLinkedDataLanguage'); >+ >+ if ( not $enabled ) { >+ $info = 'Please enable the OCLCDeweyLinkedDataAPI System Preference in order to use this Framework Plugin'; >+ } >+ >+ my $access_token; >+ if ( not $info ) { >+ >+ my $scope = 'deweyLinkedData'; >+ >+ ( $access_token, $msg ) = Koha::ExternalContent::OCLC->get_access_token( >+ { >+ scope => $scope, >+ } >+ ); >+ if ( not $access_token ) { >+ $info = "Cannot obtain API token ($msg)"; >+ } >+ >+ } >+ >+ # Trim leading 'T' (uppercase 't') from DDC number (or range) before looking it up >+ my $ddc_lookup = $ddc_number =~ s/^T//r; >+ >+ my $ddc_uri; >+ if ( not $info ) { >+ >+ ( $ddc_uri, $msg ) = Koha::ExternalContent::OCLC->get_ddc_uri( >+ { >+ access_token => $access_token, >+ ddc_number => $ddc_lookup >+ } >+ ); >+ if ( not $ddc_uri and $msg eq 'Unauthorized' ) { >+ $info = 'The API access token has expired'; >+ } elsif ( $ddc_uri eq '' ) { >+ $info = "No Dewey Linked Data URI found for DDC '$ddc_number'"; >+ } >+ } >+ >+ my $ddc_url; >+ if ( not $info ) { >+ >+ ( $ddc_url, $msg ) = Koha::ExternalContent::OCLC->get_ddc_url( >+ { >+ access_token => $access_token, >+ ddc_number => $ddc_lookup >+ } >+ ); >+ if ( not $ddc_url and $msg eq 'Unauthorized' ) { >+ $info = 'The API access token has expired'; >+ } elsif ( $ddc_url eq '' ) { >+ $info = "No Dewey Linked Data URL found for DDC '$ddc_number'"; >+ } >+ >+ } >+ >+ my $ddc_descr; >+ if ( not $info ) { >+ >+ ( $ddc_descr, $msg ) = Koha::ExternalContent::OCLC->get_ddc_description( >+ { >+ access_token => $access_token, >+ ddc_uri => $ddc_uri, >+ language => $language, >+ } >+ ); >+ if ( not $ddc_descr and $msg eq 'Unauthorized' ) { >+ $info = 'The API access token has expired'; >+ } elsif ( not defined $ddc_descr ) { >+ $info = "No Dewey Linked Data Description found for DDC URI '$ddc_uri'"; >+ } >+ >+ } >+ >+ push @ret, { >+ info => $info, >+ ld_url => $ddc_url, >+ ld_descr => $ddc_descr, >+ }; >+ output_html_with_http_headers $input, $cookie, to_json( \@ret, { utf8 => 1 } ), 'json'; >+}; >+ >+return { builder => $builder, launcher => $launcher }; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40310
: 183815