[open-ils-commits] r10643 -
trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Sep 19 13:47:06 EDT 2008
Author: erickson
Date: 2008-09-19 13:47:03 -0400 (Fri, 19 Sep 2008)
New Revision: 10643
Added:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/AuthCommon.pm
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/Authority.pm
Log:
like bib, moved the authority create/overlay logic to an external module for use by non-open-ils.cat apps
Added: trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/AuthCommon.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/AuthCommon.pm (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/AuthCommon.pm 2008-09-19 17:47:03 UTC (rev 10643)
@@ -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;
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/Authority.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/Authority.pm 2008-09-19 17:07:36 UTC (rev 10642)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Cat/Authority.pm 2008-09-19 17:47:03 UTC (rev 10643)
@@ -2,6 +2,7 @@
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 @@
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 @@
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));
+ my $rec = OpenILS::Utils::Cat::AuthCommon->overlay_authority_record($rec_id, $marc_xml, $source);
+ $e->commit unless $U->event_code($rec);
+ return $rec;
- $rec = $e->update_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;
}
__PACKAGE__->register_method(
More information about the open-ils-commits
mailing list