]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Cat/Authority.pm
authority record import/overlay and notes handling code
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Cat / Authority.pm
1 package OpenILS::Application::Cat::Authority;
2 use strict; use warnings;
3 use OpenILS::Utils::CStoreEditor q/:funcs/;
4 use OpenSRF::Utils::Logger qw($logger);
5 use OpenILS::Application::AppUtils;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenILS::Const qw/:const/;
8 use OpenILS::Event;
9 my $U = 'OpenILS::Application::AppUtils';
10 my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
11
12
13 # generate a MARC XML document from a MARC XML string
14 sub marc_xml_to_doc {
15         my $xml = shift;
16         my $marc_doc = XML::LibXML->new->parse_string($xml);
17         $marc_doc->documentElement->setNamespace($MARC_NAMESPACE, 'marc', 1);
18         $marc_doc->documentElement->setNamespace($MARC_NAMESPACE);
19         return $marc_doc;
20 }
21
22
23 __PACKAGE__->register_method(
24         method  => 'import_authority_record',
25         api_name        => 'open-ils.cat.authority.record.import',
26 );
27
28 sub import_authority_record {
29     my($self, $conn, $auth, $marc_xml, $source) = @_;
30         my $e = new_editor(authtoken=>$auth, xact=>1);
31         return $e->die_event unless $e->checkauth;
32         return $e->die_event unless $e->allowed('CREATE_AUTHORITY_RECORD')
33     
34     my $marc_doc = marc_xml_to_doc($marc_xml);
35     my $rec = Fieldmapper::authority::record_entry->new;
36         $rec->creator($e->requestor->id);
37         $rec->editor($e->requestor->id);
38         $rec->create_date('now');
39         $rec->edit_date('now');
40         $rec->marc($U->entityize($marc_doc->documentElement->toString));
41
42     $rec = $e->create_authority_record_entry($rec) or return $e->die_event;
43     $e->commit;
44
45     $conn->respond_complete($rec);
46
47     # XXX non-readonly ingest?
48         #$U->simplereq('open-ils.ingest', 'open-ils.ingest.full.authority.record', $rec->id);
49         return undef;
50 }
51
52
53 __PACKAGE__->register_method(
54         method  => 'overlay_authority_record',
55         api_name        => 'open-ils.cat.authority.record.overlay',
56 );
57
58 sub import_authority_record {
59     my($self, $conn, $auth, $rec_id, $marc_xml, $source) = @_;
60         my $e = new_editor(authtoken=>$auth, xact=>1);
61         return $e->die_event unless $e->checkauth;
62         return $e->die_event unless $e->allowed('UPDATE_AUTHORITY_RECORD');
63     
64     my $marc_doc = marc_xml_to_doc($marc_xml);
65     my $rec = $e->retrieve_authority_record_entry($rec_id) or return $e->die_event;
66         $rec->editor($e->requestor->id);
67         $rec->edit_date('now');
68         $rec->marc($U->entityize($marc_doc->documentElement->toString));
69
70     $rec = $e->update_authority_record_entry($rec) or return $e->die_event;
71     $e->commit;
72
73     $conn->respond_complete($rec);
74
75     # XXX non-readonly ingest?
76         #$U->simplereq('open-ils.ingest', 'open-ils.ingest.full.authority.record', $rec->id);
77         return undef;
78 }
79
80 __PACKAGE__->register_method(
81         method  => 'retrieve_authority_record',
82         api_name        => 'open-ils.cat.authority.record.retrieve',
83     signature => {
84         desc => q/Retrieve an authority record entry/,
85         params => [
86             {desc => q/hash of options.  Options include "clear_marc" which clears
87                 the MARC xml from the record before it is returned/}
88         ]
89     }
90 );
91 sub retrieve_authority_record {
92     my($self, $conn, $auth, $rec_id, $options) = @_;
93         my $e = new_editor(authtoken=>$auth);
94         return $e->die_event unless $e->checkauth;
95     my $rec = $e->retrieve_authority_record($rec_id) or return $e->event;
96     $rec->clear_marc if $$options{clear_marc};
97     return $rec;
98 }
99
100 __PACKAGE__->register_method(
101         method  => 'retrieve_batch_authority_record',
102         api_name        => 'open-ils.cat.authority.record.batch.retrieve',
103     stream => 1,
104     signature => {
105         desc => q/Retrieve a set of authority record entry objects/,
106         params => [
107             {desc => q/hash of options.  Options include "clear_marc" which clears
108                 the MARC xml from the record before it is returned/}
109         ]
110     }
111 );
112 sub retrieve_authority_record {
113     my($self, $conn, $auth, $rec_id_list, $options) = @_;
114         my $e = new_editor(authtoken=>$auth);
115         return $e->die_event unless $e->checkauth;
116     for my $rec_id (@$rec_id_list) {
117         my $rec = $e->retrieve_authority_record($rec_id) or return $e->event;
118         $rec->clear_marc if $$options{clear_marc};
119         $conn->respond($rec);
120     }
121     return undef;
122 }
123