]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Cat/AuthCommon.pm
like bib, moved the authority create/overlay logic to an external module for use...
[Evergreen.git] / Open-ILS / src / perlmods / 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 my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
12
13
14 # ---------------------------------------------------------------------------
15 # Shared authority mangling code.  Do not publish methods from here.
16 # ---------------------------------------------------------------------------
17
18 # generate a MARC XML document from a MARC XML string
19 sub marc_xml_to_doc {
20         my $xml = shift;
21         my $marc_doc = XML::LibXML->new->parse_string($xml);
22         $marc_doc->documentElement->setNamespace($MARC_NAMESPACE, 'marc', 1);
23         $marc_doc->documentElement->setNamespace($MARC_NAMESPACE);
24         return $marc_doc;
25 }
26
27
28 sub import_authority_record {
29     my($e, $marc_xml, $source) = @_;
30     
31     my $marc_doc = marc_xml_to_doc($marc_xml);
32     my $rec = Fieldmapper::authority::record_entry->new;
33         $rec->creator($e->requestor->id);
34         $rec->editor($e->requestor->id);
35         $rec->create_date('now');
36         $rec->edit_date('now');
37         $rec->marc($U->entityize($marc_doc->documentElement->toString));
38
39     $rec = $e->create_authority_record_entry($rec) or return $e->die_event;
40
41     # we don't care about the result, just fire off the request
42     #my $ses = OpenSRF::AppSession->create('open-ils.ingest');
43     #$ses->request('open-ils.ingest.full.authority.record', $recid);
44
45         return $rec;
46 }
47
48
49 sub overlay_authority_record {
50     my($e, $rec_id, $marc_xml, $source) = @_;
51     
52     my $marc_doc = marc_xml_to_doc($marc_xml);
53     my $rec = $e->retrieve_authority_record_entry($rec_id) or return $e->die_event;
54         $rec->editor($e->requestor->id);
55         $rec->edit_date('now');
56         $rec->marc($U->entityize($marc_doc->documentElement->toString));
57
58     $rec = $e->update_authority_record_entry($rec) or return $e->die_event;
59
60     # we don't care about the result, just fire off the request
61     #my $ses = OpenSRF::AppSession->create('open-ils.ingest');
62     #$ses->request('open-ils.ingest.full.authority.record', $recid);
63
64         return $rec;
65 }
66
67 1;