View | Details | Raw Unified | Return to bug 39345
Collapse All | Expand All

(-)a/Koha/ERM/EUsage/SushiCounter.pm (-2 / +2 lines)
Lines 49-56 sub new { Link Here
49
        require Koha::ERM::EUsage::COUNTER::5_1;
49
        require Koha::ERM::EUsage::COUNTER::5_1;
50
        $counter_release = Koha::ERM::EUsage::COUNTER::5_1->new;
50
        $counter_release = Koha::ERM::EUsage::COUNTER::5_1->new;
51
    } else {
51
    } else {
52
52
        Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease->throw(
53
        #TODO: Throw an exception stating release not found / not supported!
53
            { counter_release => $params->{response}->{Report_Header}->{Release} } );
54
    }
54
    }
55
55
56
    $counter_release->{sushi} = {
56
    $counter_release->{sushi} = {
(-)a/Koha/ERM/EUsage/UsageDataProvider.pm (-15 / +27 lines)
Lines 25-30 use LWP::UserAgent; Link Here
25
25
26
use Koha::Exceptions;
26
use Koha::Exceptions;
27
27
28
use Try::Tiny qw( catch try );
29
28
use base qw(Koha::Object);
30
use base qw(Koha::Object);
29
31
30
use Koha;
32
use Koha;
Lines 218-241 sub harvest_sushi { Link Here
218
    return if $self->_sushi_errors($result);
220
    return if $self->_sushi_errors($result);
219
221
220
    # Parse the SUSHI response
222
    # Parse the SUSHI response
221
    my $sushi_counter = Koha::ERM::EUsage::SushiCounter->new( { response => $result } );
223
    try {
222
    my $counter_file  = $sushi_counter->get_COUNTER_from_SUSHI;
224
        my $sushi_counter = Koha::ERM::EUsage::SushiCounter->new( { response => $result } );
223
225
        my $counter_file  = $sushi_counter->get_COUNTER_from_SUSHI;
224
    return if $self->_counter_file_size_too_large($counter_file);
225
226
226
    $self->counter_files(
227
        return if $self->_counter_file_size_too_large($counter_file);
227
        [
228
            {
229
                usage_data_provider_id => $self->erm_usage_data_provider_id,
230
                file_content           => $counter_file,
231
                date_uploaded          => POSIX::strftime( "%Y%m%d%H%M%S", localtime ),
232
228
233
                #TODO: add ".csv" to end of filename here
229
        $self->counter_files(
234
                filename => $self->name . "_" . $self->{report_type},
230
            [
235
            }
231
                {
236
        ]
232
                    usage_data_provider_id => $self->erm_usage_data_provider_id,
237
    );
233
                    file_content           => $counter_file,
234
                    date_uploaded          => POSIX::strftime( "%Y%m%d%H%M%S", localtime ),
238
235
236
                    #TODO: add ".csv" to end of filename here
237
                    filename => $self->name . "_" . $self->{report_type},
238
                }
239
            ]
240
        );
241
    } catch {
242
        if ( $_->isa('Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease') ) {
243
            $self->{job_callbacks}->{add_message_callback}->(
244
                {
245
                    type    => 'error',
246
                    message => 'COUNTER release ' . $_->{message}->{counter_release} . ' not supported',
247
                }
248
            ) if $self->{job_callbacks};
249
        }
250
    };
239
}
251
}
240
252
241
=head3 set_background_job_callbacks
253
=head3 set_background_job_callbacks
(-)a/Koha/Exceptions/ERM/EUsage/CounterFile.pm (-1 / +2 lines)
Lines 26-32 use Exception::Class ( Link Here
26
    },
26
    },
27
    'Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease' => {
27
    'Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease' => {
28
        isa         => 'Koha::Exceptions::ERM::EUsage::CounterFile',
28
        isa         => 'Koha::Exceptions::ERM::EUsage::CounterFile',
29
        description => 'This COUNTER release is not supported'
29
        description => 'This COUNTER release is not supported',
30
        fields      => ['counter_release'],
30
    }
31
    }
31
);
32
);
32
33
(-)a/t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t (-2 / +18 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::NoWarnings;
20
use Test::NoWarnings;
21
use Test::More tests => 4;
21
use Test::More tests => 6;
22
22
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::BackgroundJobs;
24
use Koha::BackgroundJobs;
Lines 37-43 my $builder = t::lib::TestBuilder->new; Link Here
37
37
38
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
38
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
39
39
40
my $sushi_response_file_TR_J1      = dirname(__FILE__) . "/../../data/erm/eusage/TR_J1.json";
40
my $sushi_response_file_TR_J1      = dirname(__FILE__) . "/../../data/erm/eusage/COUNTER_5/TR_J1.json";
41
my $sushi_counter_5_response_TR_J1 = read_file($sushi_response_file_TR_J1);
41
my $sushi_counter_5_response_TR_J1 = read_file($sushi_response_file_TR_J1);
42
my $sushi_counter_report_TR_J1 =
42
my $sushi_counter_report_TR_J1 =
43
    Koha::ERM::EUsage::SushiCounter->new( { response => decode_json($sushi_counter_5_response_TR_J1) } );
43
    Koha::ERM::EUsage::SushiCounter->new( { response => decode_json($sushi_counter_5_response_TR_J1) } );
Lines 306-308 subtest 'enqueue_sushi_harvest_jobs_error_handling' => sub { Link Here
306
    $schema->storage->txn_rollback;
306
    $schema->storage->txn_rollback;
307
307
308
};
308
};
309
310
my $unsupported_sushi_response_file =
311
    dirname(__FILE__) . "/../../data/erm/eusage/UnsupportedCOUNTER/UnsupportedCOUNTER.json";
312
my $unsupported_sushi_counter_5_response_TR_J1 = read_file($unsupported_sushi_response_file);
313
314
eval {
315
    Koha::ERM::EUsage::SushiCounter->new( { response => decode_json($unsupported_sushi_counter_5_response_TR_J1) } );
316
};
317
if ($@) {
318
    isa_ok(
319
        $@, 'Koha::Exceptions::ERM::EUsage::CounterFile::UnsupportedRelease',
320
        'Unsupported release throws UnsupportedRelease exception'
321
    );
322
323
    is( $@->{message}->{counter_release}, 99, 'exception message has counter_release set to 99' );
324
}
(-)a/t/db_dependent/data/erm/eusage/UnsupportedCOUNTER/UnsupportedCOUNTER.json (-1 / +101 lines)
Line 0 Link Here
0
- 
1
{
2
  "Report_Header": {
3
    "Release": "99",
4
    "Report_ID": "TR_B2",
5
    "Report_Name": "Book Access Denied",
6
    "Created": "2023-02-15T09:11:12Z",
7
    "Created_By": "Sample Publisher",
8
    "Institution_ID": {
9
      "ISNI": [
10
        "1234123412341234"
11
      ]
12
    },
13
    "Institution_Name": "Sample Institution",
14
    "Registry_Record": "https://registry.projectcounter.org/platform/99999999-9999-9999-9999-999999999999",
15
    "Report_Filters": {
16
      "Metric_Type": [
17
        "Limit_Exceeded",
18
        "No_License"
19
      ],
20
      "Begin_Date": "2022-01-01",
21
      "End_Date": "2022-03-31",
22
      "Data_Type": [
23
        "Book",
24
        "Reference_Work"
25
      ],
26
      "Access_Method": [
27
        "Regular"
28
      ]
29
    }
30
  },
31
  "Report_Items": [
32
    {
33
      "Title": "Title 1",
34
      "Publisher": "Sample Publisher",
35
      "Publisher_ID": {
36
        "ISNI": [
37
          "4321432143214321"
38
        ]
39
      },
40
      "Platform": "Platform 1",
41
      "Item_ID": {
42
        "DOI": "10.9999/xxxxt01",
43
        "Proprietary": "P1:T01",
44
        "ISBN": "979-8-88888-888-8",
45
        "URI": "https://doi.org/10.9999/xxxxt01"
46
      },
47
      "Attribute_Performance": [
48
        {
49
          "Data_Type": "Book",
50
          "YOP": "2022",
51
          "Performance": {
52
            "Limit_Exceeded": {
53
              "2022-01": 49,
54
              "2022-02": 90,
55
              "2022-03": 40
56
            },
57
            "No_License": {
58
              "2022-01": 50,
59
              "2022-02": 84,
60
              "2022-03": 47
61
            }
62
          }
63
        }
64
      ]
65
    },
66
    {
67
      "Title": "Title 7",
68
      "Publisher": "Sample Publisher",
69
      "Publisher_ID": {
70
        "ISNI": [
71
          "4321432143214321"
72
        ]
73
      },
74
      "Platform": "Platform 1",
75
      "Item_ID": {
76
        "DOI": "10.9999/xxxxt07",
77
        "Proprietary": "P1:T07",
78
        "ISBN": "979-8-88888-888-9",
79
        "URI": "https://doi.org/10.9999/xxxxt07"
80
      },
81
      "Attribute_Performance": [
82
        {
83
          "Data_Type": "Reference_Work",
84
          "YOP": "2019",
85
          "Performance": {
86
            "Limit_Exceeded": {
87
              "2022-01": 84,
88
              "2022-02": 84,
89
              "2022-03": 49
90
            },
91
            "No_License": {
92
              "2022-01": 70,
93
              "2022-02": 74,
94
              "2022-03": 54
95
            }
96
          }
97
        }
98
      ]
99
    }
100
  ]
101
}

Return to bug 39345