From 79f29f9c5a00c3b081cf3f17fb2937b40421a3a8 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 15 Mar 2005 00:31:11 +0000 Subject: [PATCH] fixing so jason can search git-svn-id: svn://svn.open-ils.org/ILS/trunk@341 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Cat.pm | 64 ++++++++++++++++++- .../perlmods/OpenILS/Application/Cat/Utils.pm | 51 ++++++++++----- 2 files changed, 99 insertions(+), 16 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm index 065974b074..b83db7906b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm @@ -125,11 +125,12 @@ __PACKAGE__->register_method( ); sub biblio_mods_slim_retrieve { + my( $self, $client, @recordids ) = @_; my $name = "open-ils.storage.biblio.record_marc.retrieve"; + warn "looking up record_marc retrieve " . time() . "\n"; my $method = $self->method_lookup($name); - unless($method) { throw OpenSRF::EX::PANIC ("Could not lookup method $name"); } @@ -137,8 +138,49 @@ sub biblio_mods_slim_retrieve { my $u = $utils->new(); my $start = 1; + +=head new way, fix me + + my $last_xml = undef; + my $session = OpenSRF::AppSession->create( "open-ils.storage" ); + + # grab, process, wait, etc... for my $id (@recordids) { + + my $req = $session->request( $name, $id ); + if($last_xml) { + if($start) { + $u->start_mods_batch( $last_xml->marc ); + $start = 0; + } else { + $u->push_mods_batch( $last_xml->marc ); + } + $last_xml = undef; + } + $req->wait_complete; + $last_xml = $req->recv; + if(UNIVERSAL::isa($last_xml,"OpenSRF::EX")) { + throw $last_xml ($last_xml->stringify());; + } + $req->finish(); + $last_xml = $last_xml->content; + } + + if($last_xml) { #grab the last one + $u->push_mods_batch( $last_xml->marc ); + } + + $session->finish(); + $session->disconnect(); + $session->kill_me(); + +=cut + + + for my $id (@recordids) { + my ($marcxml) = $method->run($id); + warn "retrieved marcxml at " . time() . "\n"; if(!$marcxml) { warn "Nothing from storage"; return undef; } if(UNIVERSAL::isa($marcxml,"OpenSRF::EX")) { @@ -153,11 +195,31 @@ sub biblio_mods_slim_retrieve { } } + warn "returning mods batch " . time . "\n"; my $mods = $u->finish_mods_batch(); return $mods; } +__PACKAGE__->register_method( + method => "marc_test", + api_name => "open-ils.cat.biblio.record.tree.retrieve.test", + argc => 1, + note => "Returns the tree associated with the nodeset of the given doc id" +); + + +sub marc_test { + + my( $self, $client ) = @_; + my $doc = XML::LibXML->new()->parse_file( "/pines/ilsmods/Application/Cat/test_rec.xml" ); + my $marcxml = $doc->toString(); + my $nodes = OpenILS::Utils::FlatXML->new()->xml_to_nodeset( $marcxml ); + my $tree = $utils->nodeset2tree( $nodes->nodeset ); + $tree->owner_doc( 999999 ); + return $tree; + +} 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat/Utils.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat/Utils.pm index 9e18815934..75eaf1851e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat/Utils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat/Utils.pm @@ -12,11 +12,18 @@ my $utils = OpenILS::Application::Cat::Utils->new(); my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); -my $xslt_doc = $parser->parse_file( "/pines/cvs/ILS/Open-ILS/xsl/MARC21slim2MODS.xsl" ); +my $xslt_doc = $parser->parse_file( "/pines/cvs/ILS/Open-ILS/xsl/MARC21slim2MODS.xsl" ); my $mods_sheet = $xslt->parse_stylesheet( $xslt_doc ); -my $isbn_xpath = "//mods:mods/mods:identifier[\@type='isbn']"; -my $resource_xpath = "//mods:mods/mods:typeOfResource"; +my $isbn_xpath = "//mods:mods/mods:identifier[\@type='isbn']"; + +my $resource_xpath = "//mods:mods/mods:typeOfResource"; + +my $pub_xpath = "//mods:mods/mods:originInfo//mods:dateIssued[\@encoding='marc']|" . + "//mods:mods/mods:originInfo//mods:dateIssued[1]"; + +my $tcn_xpath = "//mods:mods/mods:recordInfo/mods:recordIdentifier"; +my $publisher_xpath = "//mods:mods/mods:originInfo//mods:publisher[1]"; sub new { @@ -53,12 +60,11 @@ sub nodeset2tree { # This method expects a blessed Fieldmapper::biblio::record_node object sub tree2nodeset { - my($self, $node, $newnodes) = @_; + my($self, $node, $newnodes) = @_; return $newnodes unless $node; if(!$newnodes) { $newnodes = []; } - push( @$newnodes, $node ); if( $node->children() ) { @@ -66,11 +72,10 @@ sub tree2nodeset { for my $child (@{ $node->children() }) { new Fieldmapper::biblio::record_node ($child); - if(!defined($child->parent_node)) { - $child->parent_node($node->intra_doc_id); $child->ischanged(1); #just to be sure + $child->parent_node($node->intra_doc_id); + $child->ischanged(1); #just to be sure } - $self->tree2nodeset( $child, $newnodes ); } } @@ -151,30 +156,46 @@ sub _marcxml_to_perl { # --------------------------------------------------------------------------- # Initializes a MARC -> Unified MODS batch process # --------------------------------------------------------------------------- -sub _start_mods_batch { - my( $self, $master_doc ) = @_; - $self->{master_doc} = $self->_marcxml_to_perl( $master_doc ); -} sub start_mods_batch { + my( $self, $master_doc ) = @_; - my $xmldoc = $parser->parse_string( $master_doc ); + if(!ref($self)) { + $self = new OpenILS::Application::Cat::Utils; + } + + my $xmldoc = $parser->parse_string($master_doc); my $mods = $mods_sheet->transform($xmldoc); + $self->{master_doc} = OpenILS::Application::WORM->modsdoc_to_values( $mods ); $self->{master_doc} = $utils->mods_values_to_mods_slim( $self->{master_doc} ); - $self->{master_doc}->{isbn} = OpenILS::Application::WORM::_get_field_value( $mods, $isbn_xpath ); + + $self->{master_doc}->{isbn} = + OpenILS::Application::WORM::_get_field_value( $mods, $isbn_xpath ); + $self->{master_doc}->{type_of_resource} = [ OpenILS::Application::WORM::_get_field_value( $mods, $resource_xpath ) ]; + + $self->{master_doc}->{tcn} = + OpenILS::Application::WORM::_get_field_value( $mods, $tcn_xpath ); + + $self->{master_doc}->{pubdate} = + OpenILS::Application::WORM::_get_field_value( $mods, $pub_xpath ); + + $self->{master_doc}->{publisher} = + OpenILS::Application::WORM::_get_field_value( $mods, $publisher_xpath ); + } # --------------------------------------------------------------------------- -# Takes a MARCXML string an adds it to the growing MODS doc +# Takes a MARCXML string and adds it to the growing MODS doc # --------------------------------------------------------------------------- sub push_mods_batch { my( $self, $marcxml ) = @_; my $xmldoc = $parser->parse_string($marcxml); my $mods = $mods_sheet->transform($xmldoc); + my $xmlperl = OpenILS::Application::WORM->modsdoc_to_values( $mods ); $xmlperl = $utils->mods_values_to_mods_slim( $xmlperl ); -- 2.43.2