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
Signed-off-by: Eric Phetteplace <phette23@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 9482590909)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
0f7cd550a0
commit
d3aa5ec2d7
|
|
@ -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} = {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
try {
|
||||
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);
|
||||
return if $self->_counter_file_size_too_large($counter_file);
|
||||
|
||||
$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},
|
||||
}
|
||||
]
|
||||
);
|
||||
$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
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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' );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue