]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Cat/Authority.pm
fixed import name
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Cat / Authority.pm
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::Application::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/;
10 use OpenILS::Event;
11 my $U = 'OpenILS::Application::AppUtils';
12 my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
13
14
15 # generate a MARC XML document from a MARC XML string
16 sub marc_xml_to_doc {
17         my $xml = shift;
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);
21         return $marc_doc;
22 }
23
24
25 __PACKAGE__->register_method(
26         method  => 'import_authority_record',
27         api_name        => 'open-ils.cat.authority.record.import',
28 );
29
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);
37     return $rec;
38 }
39
40
41 __PACKAGE__->register_method(
42         method  => 'overlay_authority_record',
43         api_name        => 'open-ils.cat.authority.record.overlay',
44 );
45
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);
53     return $rec;
54
55 }
56
57 __PACKAGE__->register_method(
58         method  => 'retrieve_authority_record',
59         api_name        => 'open-ils.cat.authority.record.retrieve',
60     signature => {
61         desc => q/Retrieve an authority record entry/,
62         params => [
63             {desc => q/hash of options.  Options include "clear_marc" which clears
64                 the MARC xml from the record before it is returned/}
65         ]
66     }
67 );
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};
74     return $rec;
75 }
76
77 __PACKAGE__->register_method(
78         method  => 'batch_retrieve_authority_record',
79         api_name        => 'open-ils.cat.authority.record.batch.retrieve',
80     stream => 1,
81     signature => {
82         desc => q/Retrieve a set of authority record entry objects/,
83         params => [
84             {desc => q/hash of options.  Options include "clear_marc" which clears
85                 the MARC xml from the record before it is returned/}
86         ]
87     }
88 );
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};
96         $conn->respond($rec);
97     }
98     return undef;
99 }
100
101 1;