]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AuthCommon.pm
LP2045292 Color contrast for AngularJS patron bills
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / Application / Cat / AuthCommon.pm
1 package OpenILS::Application::Cat::AuthCommon;
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 OpenSRF::AppSession;
9 use OpenILS::Event;
10 my $U = 'OpenILS::Application::AppUtils';
11
12
13 # ---------------------------------------------------------------------------
14 # Shared authority mangling code.  Do not publish methods from here.
15 # ---------------------------------------------------------------------------
16
17 # generate a MARC XML document from a MARC XML string
18 sub marc_xml_to_doc {
19     my $xml = shift;
20     my $marc_doc = XML::LibXML->new->parse_string($xml);
21     $marc_doc->documentElement->setNamespace(MARC_NAMESPACE, 'marc', 1);
22     $marc_doc->documentElement->setNamespace(MARC_NAMESPACE);
23     return $marc_doc;
24 }
25
26
27 sub import_authority_record {
28     my($class, $e, $marc_xml, $source) = @_;
29     
30     my $marc_doc = marc_xml_to_doc($marc_xml);
31     my $rec = Fieldmapper::authority::record_entry->new;
32     $rec->creator($e->requestor->id);
33     $rec->editor($e->requestor->id);
34     $rec->create_date('now');
35     $rec->edit_date('now');
36     $rec->marc($U->entityize($marc_doc->documentElement->toString));
37
38     $rec = $e->create_authority_record_entry($rec) or return $e->die_event;
39
40     return $rec;
41 }
42
43
44 sub overlay_authority_record {
45     my($class, $e, $rec_id, $marc_xml, $source) = @_;
46     
47     my $marc_doc = marc_xml_to_doc($marc_xml);
48     my $rec = $e->retrieve_authority_record_entry($rec_id) or return $e->die_event;
49     $rec->editor($e->requestor->id);
50     $rec->edit_date('now');
51     $rec->marc($U->entityize($marc_doc->documentElement->toString));
52
53     $rec = $e->update_authority_record_entry($rec) or return $e->die_event;
54
55     return $rec;
56 }
57
58 1;