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;
10 my $U = 'OpenILS::Application::AppUtils';
11 my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
14 # ---------------------------------------------------------------------------
15 # Shared authority mangling code. Do not publish methods from here.
16 # ---------------------------------------------------------------------------
18 # generate a MARC XML document from a MARC XML string
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);
28 sub import_authority_record {
29 my($class, $e, $marc_xml, $source) = @_;
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));
39 my ($arn, $evt) = find_arn($e, $marc_doc);
41 $rec->arn_value($arn);
43 $rec = $e->create_authority_record_entry($rec) or return $e->die_event;
45 # we don't care about the result, just fire off the request
46 #my $ses = OpenSRF::AppSession->create('open-ils.ingest');
47 #$ses->request('open-ils.ingest.full.authority.record', $recid);
53 sub overlay_authority_record {
54 my($class, $e, $rec_id, $marc_xml, $source) = @_;
56 my $marc_doc = marc_xml_to_doc($marc_xml);
57 my $rec = $e->retrieve_authority_record_entry($rec_id) or return $e->die_event;
58 $rec->editor($e->requestor->id);
59 $rec->edit_date('now');
60 $rec->marc($U->entityize($marc_doc->documentElement->toString));
62 $rec = $e->update_authority_record_entry($rec) or return $e->die_event;
64 # we don't care about the result, just fire off the request
65 #my $ses = OpenSRF::AppSession->create('open-ils.ingest');
66 #$ses->request('open-ils.ingest.full.authority.record', $recid);
72 my($e, $marc_doc) = @_;
74 my $xpath = '//marc:controlfield[@tag="001"]';
75 my ($arn) = $marc_doc->documentElement->findvalue($xpath);
77 if(my $existing_rec = $e->search_authority_record_entry({arn_value => $arn, deleted => 'f'})->[0]) {
82 'AUTHORITY_RECORD_NUMBER_EXISTS',
83 payload => {existing_record => $existing_rec, arn => $arn}