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/;
9 my $U = 'OpenILS::Application::AppUtils';
10 my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
13 # generate a MARC XML document from a MARC XML string
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);
23 __PACKAGE__->register_method(
24 method => 'import_authority_record',
25 api_name => 'open-ils.cat.authority.record.import',
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')
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));
42 $rec = $e->create_authority_record_entry($rec) or return $e->die_event;
45 $conn->respond_complete($rec);
47 # XXX non-readonly ingest?
48 #$U->simplereq('open-ils.ingest', 'open-ils.ingest.full.authority.record', $rec->id);
53 __PACKAGE__->register_method(
54 method => 'overlay_authority_record',
55 api_name => 'open-ils.cat.authority.record.overlay',
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');
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));
70 $rec = $e->update_authority_record_entry($rec) or return $e->die_event;
73 $conn->respond_complete($rec);
75 # XXX non-readonly ingest?
76 #$U->simplereq('open-ils.ingest', 'open-ils.ingest.full.authority.record', $rec->id);
80 __PACKAGE__->register_method(
81 method => 'retrieve_authority_record',
82 api_name => 'open-ils.cat.authority.record.retrieve',
84 desc => q/Retrieve an authority record entry/,
86 {desc => q/hash of options. Options include "clear_marc" which clears
87 the MARC xml from the record before it is returned/}
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};
100 __PACKAGE__->register_method(
101 method => 'retrieve_batch_authority_record',
102 api_name => 'open-ils.cat.authority.record.batch.retrieve',
105 desc => q/Retrieve a set of authority record entry objects/,
107 {desc => q/hash of options. Options include "clear_marc" which clears
108 the MARC xml from the record before it is returned/}
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);