1 package OpenILS::Application::Cat::Authority;
2 use strict; use warnings;
3 use base qw/OpenILS::Application/;
4 use OpenILS::Utils::CStoreEditor q/:funcs/;
5 use OpenILS::Utils::Cat::AuthCommon;
6 use OpenSRF::Utils::Logger qw($logger);
7 use OpenILS::Application::AppUtils;
8 use OpenILS::Utils::Fieldmapper;
9 use OpenILS::Const qw/:const/;
11 my $U = 'OpenILS::Application::AppUtils';
12 my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
15 # generate a MARC XML document from a MARC XML string
18 my $marc_doc = XML::LibXML->new->parse_string($xml);
19 $marc_doc->documentElement->setNamespace($MARC_NAMESPACE, 'marc', 1);
20 $marc_doc->documentElement->setNamespace($MARC_NAMESPACE);
25 __PACKAGE__->register_method(
26 method => 'import_authority_record',
27 api_name => 'open-ils.cat.authority.record.import',
30 sub import_authority_record {
31 my($self, $conn, $auth, $marc_xml, $source) = @_;
32 my $e = new_editor(authtoken=>$auth, xact=>1);
33 return $e->die_event unless $e->checkauth;
34 return $e->die_event unless $e->allowed('CREATE_AUTHORITY_RECORD');
35 my $rec = OpenILS::Utils::Cat::AuthCommon->import_authority_record($marc_xml, $source);
36 $e->commit unless $U->event_code($rec);
41 __PACKAGE__->register_method(
42 method => 'overlay_authority_record',
43 api_name => 'open-ils.cat.authority.record.overlay',
46 sub overlay_authority_record {
47 my($self, $conn, $auth, $rec_id, $marc_xml, $source) = @_;
48 my $e = new_editor(authtoken=>$auth, xact=>1);
49 return $e->die_event unless $e->checkauth;
50 return $e->die_event unless $e->allowed('UPDATE_AUTHORITY_RECORD');
51 my $rec = OpenILS::Utils::Cat::AuthCommon->overlay_authority_record($rec_id, $marc_xml, $source);
52 $e->commit unless $U->event_code($rec);
57 __PACKAGE__->register_method(
58 method => 'retrieve_authority_record',
59 api_name => 'open-ils.cat.authority.record.retrieve',
61 desc => q/Retrieve an authority record entry/,
63 {desc => q/hash of options. Options include "clear_marc" which clears
64 the MARC xml from the record before it is returned/}
68 sub retrieve_authority_record {
69 my($self, $conn, $auth, $rec_id, $options) = @_;
70 my $e = new_editor(authtoken=>$auth);
71 return $e->die_event unless $e->checkauth;
72 my $rec = $e->retrieve_authority_record($rec_id) or return $e->event;
73 $rec->clear_marc if $$options{clear_marc};
77 __PACKAGE__->register_method(
78 method => 'batch_retrieve_authority_record',
79 api_name => 'open-ils.cat.authority.record.batch.retrieve',
82 desc => q/Retrieve a set of authority record entry objects/,
84 {desc => q/hash of options. Options include "clear_marc" which clears
85 the MARC xml from the record before it is returned/}
89 sub batch_retrieve_authority_record {
90 my($self, $conn, $auth, $rec_id_list, $options) = @_;
91 my $e = new_editor(authtoken=>$auth);
92 return $e->die_event unless $e->checkauth;
93 for my $rec_id (@$rec_id_list) {
94 my $rec = $e->retrieve_authority_record($rec_id) or return $e->event;
95 $rec->clear_marc if $$options{clear_marc};