like bib, moved the authority create/overlay logic to an external module for use...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 19 Sep 2008 17:47:03 +0000 (17:47 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 19 Sep 2008 17:47:03 +0000 (17:47 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@10643 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Cat/AuthCommon.pm [new file with mode: 0644]
Open-ILS/src/perlmods/OpenILS/Application/Cat/Authority.pm

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat/AuthCommon.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat/AuthCommon.pm
new file mode 100644 (file)
index 0000000..cf310bc
--- /dev/null
@@ -0,0 +1,67 @@
+package OpenILS::Application::Cat::AuthCommon;
+use strict; use warnings;
+use OpenILS::Utils::CStoreEditor q/:funcs/;
+use OpenSRF::Utils::Logger qw($logger);
+use OpenILS::Application::AppUtils;
+use OpenILS::Utils::Fieldmapper;
+use OpenILS::Const qw/:const/;
+use OpenSRF::AppSession;
+use OpenILS::Event;
+my $U = 'OpenILS::Application::AppUtils';
+my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
+
+
+# ---------------------------------------------------------------------------
+# Shared authority mangling code.  Do not publish methods from here.
+# ---------------------------------------------------------------------------
+
+# generate a MARC XML document from a MARC XML string
+sub marc_xml_to_doc {
+       my $xml = shift;
+       my $marc_doc = XML::LibXML->new->parse_string($xml);
+       $marc_doc->documentElement->setNamespace($MARC_NAMESPACE, 'marc', 1);
+       $marc_doc->documentElement->setNamespace($MARC_NAMESPACE);
+       return $marc_doc;
+}
+
+
+sub import_authority_record {
+    my($e, $marc_xml, $source) = @_;
+    
+    my $marc_doc = marc_xml_to_doc($marc_xml);
+    my $rec = Fieldmapper::authority::record_entry->new;
+       $rec->creator($e->requestor->id);
+       $rec->editor($e->requestor->id);
+       $rec->create_date('now');
+       $rec->edit_date('now');
+       $rec->marc($U->entityize($marc_doc->documentElement->toString));
+
+    $rec = $e->create_authority_record_entry($rec) or return $e->die_event;
+
+    # we don't care about the result, just fire off the request
+    #my $ses = OpenSRF::AppSession->create('open-ils.ingest');
+    #$ses->request('open-ils.ingest.full.authority.record', $recid);
+
+       return $rec;
+}
+
+
+sub overlay_authority_record {
+    my($e, $rec_id, $marc_xml, $source) = @_;
+    
+    my $marc_doc = marc_xml_to_doc($marc_xml);
+    my $rec = $e->retrieve_authority_record_entry($rec_id) or return $e->die_event;
+       $rec->editor($e->requestor->id);
+       $rec->edit_date('now');
+       $rec->marc($U->entityize($marc_doc->documentElement->toString));
+
+    $rec = $e->update_authority_record_entry($rec) or return $e->die_event;
+
+    # we don't care about the result, just fire off the request
+    #my $ses = OpenSRF::AppSession->create('open-ils.ingest');
+    #$ses->request('open-ils.ingest.full.authority.record', $recid);
+
+       return $rec;
+}
+
+1;
index 876f3fd..847d511 100644 (file)
@@ -2,6 +2,7 @@ package OpenILS::Application::Cat::Authority;
 use strict; use warnings;
 use base qw/OpenILS::Application/;
 use OpenILS::Utils::CStoreEditor q/:funcs/;
+use OpenILS::Utils::Cat::AuthCommon;
 use OpenSRF::Utils::Logger qw($logger);
 use OpenILS::Application::AppUtils;
 use OpenILS::Utils::Fieldmapper;
@@ -31,23 +32,9 @@ sub import_authority_record {
        my $e = new_editor(authtoken=>$auth, xact=>1);
        return $e->die_event unless $e->checkauth;
        return $e->die_event unless $e->allowed('CREATE_AUTHORITY_RECORD');
-    
-    my $marc_doc = marc_xml_to_doc($marc_xml);
-    my $rec = Fieldmapper::authority::record_entry->new;
-       $rec->creator($e->requestor->id);
-       $rec->editor($e->requestor->id);
-       $rec->create_date('now');
-       $rec->edit_date('now');
-       $rec->marc($U->entityize($marc_doc->documentElement->toString));
-
-    $rec = $e->create_authority_record_entry($rec) or return $e->die_event;
-    $e->commit;
-
-    $conn->respond_complete($rec);
-
-    # XXX non-readonly ingest?
-       #$U->simplereq('open-ils.ingest', 'open-ils.ingest.full.authority.record', $rec->id);
-       return undef;
+    my $rec = OpenILS::Utils::Cat::AuthCommon->import_authority_record($marc_xml, $source);
+    $e->commit unless $U->event_code($rec);
+    return $rec;
 }
 
 
@@ -61,21 +48,10 @@ sub overlay_authority_record {
        my $e = new_editor(authtoken=>$auth, xact=>1);
        return $e->die_event unless $e->checkauth;
        return $e->die_event unless $e->allowed('UPDATE_AUTHORITY_RECORD');
-    
-    my $marc_doc = marc_xml_to_doc($marc_xml);
-    my $rec = $e->retrieve_authority_record_entry($rec_id) or return $e->die_event;
-       $rec->editor($e->requestor->id);
-       $rec->edit_date('now');
-       $rec->marc($U->entityize($marc_doc->documentElement->toString));
-
-    $rec = $e->update_authority_record_entry($rec) or return $e->die_event;
-    $e->commit;
-
-    $conn->respond_complete($rec);
+    my $rec = OpenILS::Utils::Cat::AuthCommon->overlay_authority_record($rec_id, $marc_xml, $source);
+    $e->commit unless $U->event_code($rec);
+    return $rec;
 
-    # XXX non-readonly ingest?
-       #$U->simplereq('open-ils.ingest', 'open-ils.ingest.full.authority.record', $rec->id);
-       return undef;
 }
 
 __PACKAGE__->register_method(