Bugzilla – Attachment 185621 Details for
Bug 39345
Koha must support COUNTER 5.1
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39345: (QA follow-up): Add exception handling for unsupported counter release
Bug-39345-QA-follow-up-Add-exception-handling-for-.patch (text/plain), 9.09 KB, created by
Pedro Amorim
on 2025-08-21 09:35:20 UTC
(
hide
)
Description:
Bug 39345: (QA follow-up): Add exception handling for unsupported counter release
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2025-08-21 09:35:20 UTC
Size:
9.09 KB
patch
obsolete
>From fc42094e0ae44d5c70d5f8f7bc1380d827db5fc4 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@openfifth.co.uk> >Date: Thu, 21 Aug 2025 09:32:41 +0000 >Subject: [PATCH] Bug 39345: (QA follow-up): Add exception handling for > unsupported counter release > >To test this on the UI, you can add the following line of code at the beginning on 'new' in SushiCounter.pm: >->{response}->{Report_Header}->{Release} = 6; > >This will force the release to be '6'. Then you can perform a harvest using the UI. The background job will fail with the error message saying that counter release 6 is not supported > >prove t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t >--- > Koha/ERM/EUsage/SushiCounter.pm | 4 +- > Koha/ERM/EUsage/UsageDataProvider.pm | 42 +++++--- > Koha/Exceptions/ERM/EUsage/CounterFile.pm | 3 +- > .../Koha/BackgroundJobs/ErmSushiHarvester.t | 20 +++- > .../UnsupportedCOUNTER.json | 101 ++++++++++++++++++ > 5 files changed, 150 insertions(+), 20 deletions(-) > create mode 100644 t/db_dependent/data/erm/eusage/UnsupportedCOUNTER/UnsupportedCOUNTER.json > >diff --git a/Koha/ERM/EUsage/SushiCounter.pm b/Koha/ERM/EUsage/SushiCounter.pm >index 349245d5f23..78e8b8694d8 100644 >--- a/Koha/ERM/EUsage/SushiCounter.pm >+++ b/Koha/ERM/EUsage/SushiCounter.pm >@@ -49,8 +49,8 @@ sub new { > require Koha::ERM::EUsage::COUNTER::5_1; > $counter_release = Koha::ERM::EUsage::COUNTER::5_1->new; > } else { >- >- #TODO: Throw an exception stating release not found / not supported! >+ Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease->throw( >+ { counter_release => $params->{response}->{Report_Header}->{Release} } ); > } > > $counter_release->{sushi} = { >diff --git a/Koha/ERM/EUsage/UsageDataProvider.pm b/Koha/ERM/EUsage/UsageDataProvider.pm >index 876b6dc2f8e..9f7fb5c6c76 100644 >--- a/Koha/ERM/EUsage/UsageDataProvider.pm >+++ b/Koha/ERM/EUsage/UsageDataProvider.pm >@@ -25,6 +25,8 @@ use LWP::UserAgent; > > use Koha::Exceptions; > >+use Try::Tiny qw( catch try ); >+ > use base qw(Koha::Object); > > use Koha; >@@ -218,24 +220,34 @@ sub harvest_sushi { > return if $self->_sushi_errors($result); > > # Parse the SUSHI response >- my $sushi_counter = Koha::ERM::EUsage::SushiCounter->new( { response => $result } ); >- my $counter_file = $sushi_counter->get_COUNTER_from_SUSHI; >- >- return if $self->_counter_file_size_too_large($counter_file); >+ try { >+ my $sushi_counter = Koha::ERM::EUsage::SushiCounter->new( { response => $result } ); >+ my $counter_file = $sushi_counter->get_COUNTER_from_SUSHI; > >- $self->counter_files( >- [ >- { >- usage_data_provider_id => $self->erm_usage_data_provider_id, >- file_content => $counter_file, >- date_uploaded => POSIX::strftime( "%Y%m%d%H%M%S", localtime ), >+ return if $self->_counter_file_size_too_large($counter_file); > >- #TODO: add ".csv" to end of filename here >- filename => $self->name . "_" . $self->{report_type}, >- } >- ] >- ); >+ $self->counter_files( >+ [ >+ { >+ usage_data_provider_id => $self->erm_usage_data_provider_id, >+ file_content => $counter_file, >+ date_uploaded => POSIX::strftime( "%Y%m%d%H%M%S", localtime ), > >+ #TODO: add ".csv" to end of filename here >+ filename => $self->name . "_" . $self->{report_type}, >+ } >+ ] >+ ); >+ } catch { >+ if ( $_->isa('Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease') ) { >+ $self->{job_callbacks}->{add_message_callback}->( >+ { >+ type => 'error', >+ message => 'COUNTER release ' . $_->{message}->{counter_release} . ' not supported', >+ } >+ ) if $self->{job_callbacks}; >+ } >+ }; > } > > =head3 set_background_job_callbacks >diff --git a/Koha/Exceptions/ERM/EUsage/CounterFile.pm b/Koha/Exceptions/ERM/EUsage/CounterFile.pm >index 70b00998187..db6eda07b43 100644 >--- a/Koha/Exceptions/ERM/EUsage/CounterFile.pm >+++ b/Koha/Exceptions/ERM/EUsage/CounterFile.pm >@@ -26,7 +26,8 @@ use Exception::Class ( > }, > 'Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease' => { > isa => 'Koha::Exceptions::ERM::EUsage::CounterFile', >- description => 'This COUNTER release is not supported' >+ description => 'This COUNTER release is not supported', >+ fields => ['counter_release'], > } > ); > >diff --git a/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t b/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t >index 3bc6a70e113..bcf0d47729a 100755 >--- a/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t >+++ b/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 4; >+use Test::More tests => 6; > > use Koha::Database; > use Koha::BackgroundJobs; >@@ -37,7 +37,7 @@ my $builder = t::lib::TestBuilder->new; > > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > >-my $sushi_response_file_TR_J1 = dirname(__FILE__) . "/../../data/erm/eusage/TR_J1.json"; >+my $sushi_response_file_TR_J1 = dirname(__FILE__) . "/../../data/erm/eusage/COUNTER_5/TR_J1.json"; > my $sushi_counter_5_response_TR_J1 = read_file($sushi_response_file_TR_J1); > my $sushi_counter_report_TR_J1 = > Koha::ERM::EUsage::SushiCounter->new( { response => decode_json($sushi_counter_5_response_TR_J1) } ); >@@ -306,3 +306,19 @@ subtest 'enqueue_sushi_harvest_jobs_error_handling' => sub { > $schema->storage->txn_rollback; > > }; >+ >+my $unsupported_sushi_response_file = >+ dirname(__FILE__) . "/../../data/erm/eusage/UnsupportedCOUNTER/UnsupportedCOUNTER.json"; >+my $unsupported_sushi_counter_5_response_TR_J1 = read_file($unsupported_sushi_response_file); >+ >+eval { >+ Koha::ERM::EUsage::SushiCounter->new( { response => decode_json($unsupported_sushi_counter_5_response_TR_J1) } ); >+}; >+if ($@) { >+ isa_ok( >+ $@, 'Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease', >+ 'Unsupported release throws UnsupportedRelease exception' >+ ); >+ >+ is( $@->{message}->{counter_release}, 99, 'exception message has counter_release set to 99' ); >+} >diff --git a/t/db_dependent/data/erm/eusage/UnsupportedCOUNTER/UnsupportedCOUNTER.json b/t/db_dependent/data/erm/eusage/UnsupportedCOUNTER/UnsupportedCOUNTER.json >new file mode 100644 >index 00000000000..eac8d339f15 >--- /dev/null >+++ b/t/db_dependent/data/erm/eusage/UnsupportedCOUNTER/UnsupportedCOUNTER.json >@@ -0,0 +1,101 @@ >+{ >+ "Report_Header": { >+ "Release": "99", >+ "Report_ID": "TR_B2", >+ "Report_Name": "Book Access Denied", >+ "Created": "2023-02-15T09:11:12Z", >+ "Created_By": "Sample Publisher", >+ "Institution_ID": { >+ "ISNI": [ >+ "1234123412341234" >+ ] >+ }, >+ "Institution_Name": "Sample Institution", >+ "Registry_Record": "https://registry.projectcounter.org/platform/99999999-9999-9999-9999-999999999999", >+ "Report_Filters": { >+ "Metric_Type": [ >+ "Limit_Exceeded", >+ "No_License" >+ ], >+ "Begin_Date": "2022-01-01", >+ "End_Date": "2022-03-31", >+ "Data_Type": [ >+ "Book", >+ "Reference_Work" >+ ], >+ "Access_Method": [ >+ "Regular" >+ ] >+ } >+ }, >+ "Report_Items": [ >+ { >+ "Title": "Title 1", >+ "Publisher": "Sample Publisher", >+ "Publisher_ID": { >+ "ISNI": [ >+ "4321432143214321" >+ ] >+ }, >+ "Platform": "Platform 1", >+ "Item_ID": { >+ "DOI": "10.9999/xxxxt01", >+ "Proprietary": "P1:T01", >+ "ISBN": "979-8-88888-888-8", >+ "URI": "https://doi.org/10.9999/xxxxt01" >+ }, >+ "Attribute_Performance": [ >+ { >+ "Data_Type": "Book", >+ "YOP": "2022", >+ "Performance": { >+ "Limit_Exceeded": { >+ "2022-01": 49, >+ "2022-02": 90, >+ "2022-03": 40 >+ }, >+ "No_License": { >+ "2022-01": 50, >+ "2022-02": 84, >+ "2022-03": 47 >+ } >+ } >+ } >+ ] >+ }, >+ { >+ "Title": "Title 7", >+ "Publisher": "Sample Publisher", >+ "Publisher_ID": { >+ "ISNI": [ >+ "4321432143214321" >+ ] >+ }, >+ "Platform": "Platform 1", >+ "Item_ID": { >+ "DOI": "10.9999/xxxxt07", >+ "Proprietary": "P1:T07", >+ "ISBN": "979-8-88888-888-9", >+ "URI": "https://doi.org/10.9999/xxxxt07" >+ }, >+ "Attribute_Performance": [ >+ { >+ "Data_Type": "Reference_Work", >+ "YOP": "2019", >+ "Performance": { >+ "Limit_Exceeded": { >+ "2022-01": 84, >+ "2022-02": 84, >+ "2022-03": 49 >+ }, >+ "No_License": { >+ "2022-01": 70, >+ "2022-02": 74, >+ "2022-03": 54 >+ } >+ } >+ } >+ ] >+ } >+ ] >+} >\ No newline at end of file >-- >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 39345
:
185593
|
185594
|
185595
|
185596
|
185618
|
185619
|
185620
|
185621
|
185658
|
185659
|
185660
|
185661
|
185662
|
185663
|
185664
|
185922
|
185923
|
185924
|
185925
|
185926
|
185927
|
185928
|
186016
|
186042
|
186043
|
186044
|
186060
|
186061
|
186062
|
186063
|
186064
|
186065
|
186066
|
186067
|
186068