Bug 25009: [18.11.x] Add missing biblio_metadata stuffs
It adds methods, DBIC rs and Exceptions class for biblio metadata. Note that schema is marcflavour in 18.11 Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
This commit is contained in:
parent
eb3d1f373d
commit
b0015b1e31
|
|
@ -30,6 +30,7 @@ use base qw(Koha::Object);
|
||||||
|
|
||||||
use Koha::Items;
|
use Koha::Items;
|
||||||
use Koha::Biblioitems;
|
use Koha::Biblioitems;
|
||||||
|
use Koha::Biblio::Metadata;
|
||||||
use Koha::ArticleRequests;
|
use Koha::ArticleRequests;
|
||||||
use Koha::ArticleRequest::Status;
|
use Koha::ArticleRequest::Status;
|
||||||
use Koha::IssuingRules;
|
use Koha::IssuingRules;
|
||||||
|
|
@ -61,6 +62,21 @@ sub store {
|
||||||
return $self->SUPER::store;
|
return $self->SUPER::store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head3 metadata
|
||||||
|
|
||||||
|
my $metadata = $biblio->metadata();
|
||||||
|
|
||||||
|
Returns a Koha::Biblio::Metadata object
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub metadata {
|
||||||
|
my ( $self ) = @_;
|
||||||
|
|
||||||
|
my $metadata = $self->_result->metadata;
|
||||||
|
return Koha::Biblio::Metadata->_new_from_dbic($metadata);
|
||||||
|
}
|
||||||
|
|
||||||
=head3 subtitles
|
=head3 subtitles
|
||||||
|
|
||||||
my @subtitles = $biblio->subtitles();
|
my @subtitles = $biblio->subtitles();
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ use Modern::Perl;
|
||||||
use Carp;
|
use Carp;
|
||||||
|
|
||||||
use Koha::Database;
|
use Koha::Database;
|
||||||
|
use Koha::Exceptions::Metadata;
|
||||||
|
|
||||||
use base qw(Koha::Object);
|
use base qw(Koha::Object);
|
||||||
|
|
||||||
|
|
@ -33,6 +34,58 @@ Koha::Metadata - Koha Metadata Object class
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
=head3 record
|
||||||
|
|
||||||
|
my $record = $metadata->record;
|
||||||
|
|
||||||
|
Returns an object representing the metadata record. The expected record type
|
||||||
|
corresponds to this table:
|
||||||
|
|
||||||
|
-------------------------------
|
||||||
|
| format | object type |
|
||||||
|
-------------------------------
|
||||||
|
| marcxml | MARC::Record |
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
=head4 Error handling
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item If an unsupported format is found, it throws a I<Koha::Exceptions::Metadata> exception.
|
||||||
|
|
||||||
|
=item If it fails to create the record object, it throws a I<Koha::Exceptions::Metadata::Invalid> exception.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub record {
|
||||||
|
|
||||||
|
my ($self) = @_;
|
||||||
|
|
||||||
|
my $record;
|
||||||
|
|
||||||
|
if ( $self->format eq 'marcxml' ) {
|
||||||
|
$record = eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->marcflavour ); };
|
||||||
|
my $marcxml_error = $@;
|
||||||
|
chomp $marcxml_error;
|
||||||
|
unless ($record) {
|
||||||
|
Koha::Exceptions::Metadata::Invalid->throw(
|
||||||
|
id => $self->id,
|
||||||
|
format => $self->format,
|
||||||
|
marcflavour => $self->marcflavour,
|
||||||
|
decoding_error => $marcxml_error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Koha::Exceptions::Metadata->throw(
|
||||||
|
'Koha::Biblio::Metadata->record called on unhandled format: ' . $self->format );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
=head3 type
|
=head3 type
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package Koha::Exceptions::Metadata;
|
||||||
|
|
||||||
|
# This file is part of Koha.
|
||||||
|
#
|
||||||
|
# Koha is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Koha is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||||
|
|
||||||
|
use Modern::Perl;
|
||||||
|
|
||||||
|
use Exception::Class (
|
||||||
|
|
||||||
|
'Koha::Exceptions::Metadata' => {
|
||||||
|
description => 'Something went wrong!',
|
||||||
|
},
|
||||||
|
'Koha::Exceptions::Metadata::Invalid' => {
|
||||||
|
isa => 'Koha::Exceptions::Metadata',
|
||||||
|
description => 'Invalid data',
|
||||||
|
fields => ['id','format','marcflavour', 'decoding_error']
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
sub full_message {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my $msg = $self->message;
|
||||||
|
|
||||||
|
unless ($msg) {
|
||||||
|
if ( $self->isa('Koha::Exceptions::Metadata::Invalid') ) {
|
||||||
|
$msg = sprintf( "Invalid data, cannot decode object (id=%s, format=%s, marcflavour=%s, decoding_error='%s')",
|
||||||
|
$self->id, $self->format, $self->marcflavour, $self->decoding_error );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Koha::Exceptions::Metadata - Base class for metadata exceptions
|
||||||
|
|
||||||
|
=head1 Exceptions
|
||||||
|
|
||||||
|
=head2 Koha::Exceptions::Metadata
|
||||||
|
|
||||||
|
Generic metadata exception
|
||||||
|
|
||||||
|
=head2 Koha::Exceptions::Metadata::Invalid
|
||||||
|
|
||||||
|
The metadata is invalid.
|
||||||
|
|
||||||
|
=head1 Class methods
|
||||||
|
|
||||||
|
=head2 full_message
|
||||||
|
|
||||||
|
Overloaded method for exception stringifying.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
@ -351,4 +351,11 @@ __PACKAGE__->has_many(
|
||||||
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
|
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
|
||||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bUv00JjY09Hj2Zj4klqyxA
|
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bUv00JjY09Hj2Zj4klqyxA
|
||||||
|
|
||||||
|
__PACKAGE__->has_one(
|
||||||
|
"metadata",
|
||||||
|
"Koha::Schema::Result::BiblioMetadata",
|
||||||
|
{ "foreign.biblionumber" => "self.biblionumber" },
|
||||||
|
{ cascade_copy => 0, cascade_delete => 0 },
|
||||||
|
);
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue