1 package Koha::REST::V1::Biblios;
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';
23 use Koha::RecordProcessor;
24 use C4::Biblio qw(DelBiblio);
26 use MARC::Record::MiJ;
36 Controller function that handles retrieving a single biblio object
41 my $c = shift->openapi->valid_input or return;
44 $attributes = { prefetch => [ 'metadata' ] } # don't prefetch metadata if not needed
45 unless $c->req->headers->accept =~ m/application\/json/;
47 my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, $attributes );
53 error => "Object not found."
60 if ( $c->req->headers->accept =~ m/application\/json/ ) {
63 json => $biblio->to_api
67 my $record = $biblio->metadata->record;
73 text => $record->as_xml_record
78 text => $record->to_mij
83 text => $record->as_usmarc
89 "application/marcxml+xml",
90 "application/marc-in-json",
100 openapi => { error => "Something went wrong, check the logs ($_)" }
107 Controller function that handles deleting a biblio object
112 my $c = shift->openapi->valid_input or return;
114 my $biblio = Koha::Biblios->find( $c->validation->param('biblio_id') );
116 if ( not defined $biblio ) {
119 openapi => { error => "Object not found" }
124 my $error = DelBiblio( $biblio->id );
129 openapi => { error => $error }
133 return $c->render( status => 204, openapi => "" );
137 if ( $_->isa('DBIx::Class::Exception') ) {
140 openapi => { error => $_->{msg} }
146 openapi => { error => "Something went wrong, check the logs." }
154 Controller function that handles retrieving a single biblio object
159 my $c = shift->openapi->valid_input or return;
161 my $biblio = Koha::Biblios->find(
162 { biblionumber => $c->validation->param('biblio_id') },
163 { prefetch => ['metadata'] } );
169 error => "Object not found."
176 my $record = $biblio->metadata->record;
178 my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems');
179 my $patron = $c->stash('koha.user');
181 # Check if the biblio should be hidden for unprivileged access
182 # unless there's a logged in user, and there's an exception for it's
184 unless ( $patron and $patron->category->override_hidden_items ) {
185 if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) )
190 error => "Object not found."
196 my $marcflavour = C4::Context->preference("marcflavour");
198 my $record_processor = Koha::RecordProcessor->new({
199 filters => 'ViewPolicy',
202 frameworkcode => $biblio->frameworkcode
205 # Apply framework's filtering to MARC::Record object
206 $record_processor->process($record);
212 text => $record->as_xml_record
217 text => $record->to_mij
222 text => $record->as_usmarc
226 format => 'text/plain',
227 text => $record->as_formatted
232 "application/marcxml+xml",
233 "application/marc-in-json",
243 openapi => { error => "Something went wrong, check the logs ($_)" }