1 package Koha::REST::V1::ERM::EHoldings::Titles::EBSCO;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Mojo::Base 'Mojolicious::Controller';
22 use JSON qw( decode_json );
23 use Koha::ERM::Providers::EBSCO;
25 use Scalar::Util qw( blessed );
26 use Try::Tiny qw( catch try );
37 my $c = shift->openapi->valid_input or return;
41 my $args = $c->validation->output;
43 my $ebsco = Koha::ERM::Providers::EBSCO->new;
45 # We cannot get base_total as a search kw is required by the API
47 my ( $per_page, $page ) = $ebsco->build_query_pagination($args);
49 my $additional_params = $ebsco->build_additional_params( $c->req->params->to_hash );
51 unless ( defined $additional_params->{publication_title} ) {
53 # TODO We can add search on publisher, isxn, [subject or zdbid]
60 "A search keyword on publication_title is required"
67 my $searchfield = 'titlename';
69 sprintf '?orderby=relevance&offset=%s&count=%s&searchfield=%s',
70 $page, $per_page, $searchfield;
72 $ebsco->request( GET => '/titles' . $params, $additional_params );
74 my $embed_header = $c->req->headers->header('x-koha-embed');
76 for my $t ( @{ $result->{titles} } ) {
77 my $title = $ebsco->build_title($t);
78 $title = $ebsco->embed( $title, $t, $embed_header );
81 my $total = $result->{totalResults};
82 $total = 10000 if $total > 10000;
84 $c->add_pagination_headers(
86 #base_total => $base_total,
91 return $c->render( status => 200, openapi => \@titles );
95 if ( $_->isa('Koha::Exceptions::Authorization::Unauthorized') ) {
101 message => "Check your ERMProviderEbscoApiKey/ERMProviderEbscoCustomerID system preferences."
108 $c->unhandled_exception($_);
117 my $c = shift->openapi->valid_input or return;
120 my $title_id = $c->validation->param('title_id');
121 my $ebsco = Koha::ERM::Providers::EBSCO->new;
122 my $t = $ebsco->request( GET => '/titles/' . $title_id );
126 openapi => { error => "Title not found" }
130 my $title = $ebsco->build_title($t);
132 $ebsco->embed( $title, $t, $c->req->headers->header('x-koha-embed') );
140 $c->unhandled_exception($_);