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 OpenSRF::Utils::Logger qw($logger);
6 use OpenILS::Application::AppUtils;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Const qw/:const/;
10 my $U = 'OpenILS::Application::AppUtils';
11 my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
14 # generate a MARC XML document from a MARC XML string
17 my $marc_doc = XML::LibXML->new->parse_string($xml);
18 $marc_doc->documentElement->setNamespace($MARC_NAMESPACE, 'marc', 1);
19 $marc_doc->documentElement->setNamespace($MARC_NAMESPACE);
24 __PACKAGE__->register_method(
25 method => 'import_authority_record',
26 api_name => 'open-ils.cat.authority.record.import',
29 sub import_authority_record {
30 my($self, $conn, $auth, $marc_xml, $source) = @_;
31 my $e = new_editor(authtoken=>$auth, xact=>1);
32 return $e->die_event unless $e->checkauth;
33 return $e->die_event unless $e->allowed('CREATE_AUTHORITY_RECORD');
35 my $marc_doc = marc_xml_to_doc($marc_xml);
36 my $rec = Fieldmapper::authority::record_entry->new;
37 $rec->creator($e->requestor->id);
38 $rec->editor($e->requestor->id);
39 $rec->create_date('now');
40 $rec->edit_date('now');
41 $rec->marc($U->entityize($marc_doc->documentElement->toString));
43 $rec = $e->create_authority_record_entry($rec) or return $e->die_event;
46 $conn->respond_complete($rec);
48 # XXX non-readonly ingest?
49 #$U->simplereq('open-ils.ingest', 'open-ils.ingest.full.authority.record', $rec->id);
54 __PACKAGE__->register_method(
55 method => 'overlay_authority_record',
56 api_name => 'open-ils.cat.authority.record.overlay',
59 sub overlay_authority_record {
60 my($self, $conn, $auth, $rec_id, $marc_xml, $source) = @_;
61 my $e = new_editor(authtoken=>$auth, xact=>1);
62 return $e->die_event unless $e->checkauth;
63 return $e->die_event unless $e->allowed('UPDATE_AUTHORITY_RECORD');
65 my $marc_doc = marc_xml_to_doc($marc_xml);
66 my $rec = $e->retrieve_authority_record_entry($rec_id) or return $e->die_event;
67 $rec->editor($e->requestor->id);
68 $rec->edit_date('now');
69 $rec->marc($U->entityize($marc_doc->documentElement->toString));
71 $rec = $e->update_authority_record_entry($rec) or return $e->die_event;
74 $conn->respond_complete($rec);
76 # XXX non-readonly ingest?
77 #$U->simplereq('open-ils.ingest', 'open-ils.ingest.full.authority.record', $rec->id);
81 __PACKAGE__->register_method(
82 method => 'retrieve_authority_record',
83 api_name => 'open-ils.cat.authority.record.retrieve',
85 desc => q/Retrieve an authority record entry/,
87 {desc => q/hash of options. Options include "clear_marc" which clears
88 the MARC xml from the record before it is returned/}
92 sub retrieve_authority_record {
93 my($self, $conn, $auth, $rec_id, $options) = @_;
94 my $e = new_editor(authtoken=>$auth);
95 return $e->die_event unless $e->checkauth;
96 my $rec = $e->retrieve_authority_record($rec_id) or return $e->event;
97 $rec->clear_marc if $$options{clear_marc};
101 __PACKAGE__->register_method(
102 method => 'batch_retrieve_authority_record',
103 api_name => 'open-ils.cat.authority.record.batch.retrieve',
106 desc => q/Retrieve a set of authority record entry objects/,
108 {desc => q/hash of options. Options include "clear_marc" which clears
109 the MARC xml from the record before it is returned/}
113 sub batch_retrieve_authority_record {
114 my($self, $conn, $auth, $rec_id_list, $options) = @_;
115 my $e = new_editor(authtoken=>$auth);
116 return $e->die_event unless $e->checkauth;
117 for my $rec_id (@$rec_id_list) {
118 my $rec = $e->retrieve_authority_record($rec_id) or return $e->event;
119 $rec->clear_marc if $$options{clear_marc};
120 $conn->respond($rec);