added an 'import' method to search (for us) oclc.
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 10 May 2005 16:47:54 +0000 (16:47 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 10 May 2005 16:47:54 +0000 (16:47 +0000)
returns node trees

login info is  in the xml config.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@694 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm

index 8d418fb..96b1452 100755 (executable)
@@ -7,21 +7,40 @@ use base qw/OpenSRF::Application/;
 use Net::Z3950;
 use MARC::Record;
 use MARC::File::XML;
+use OpenSRF::Utils::SettingsClient;
+
+use OpenILS::Utils::FlatXML;
+use OpenILS::Application::Cat::Utils;
+my $utils = "OpenILS::Application::Cat::Utils";
 
 use OpenILS::Utils::ModsParser;
 
 my $output = "USMARC"; # only support output for now
-
+my $host;
+my $port;
+my $database;
+my $attr;
+my $username;
+my $password;
+
+my $settings_client;
+
+sub initialize {
+       $settings_client = OpenSRF::Utils::SettingsClient->new();
+       $host                   = $settings_client->config_value("z3950", "oclc", "host");
+       $port                   = $settings_client->config_value("z3950", "oclc", "port");
+       $database       = $settings_client->config_value("z3950", "oclc", "db");
+       $attr                   = $settings_client->config_value("z3950", "oclc", "attr");
+       $username       = $settings_client->config_value("z3950", "oclc", "username");
+       $password       = $settings_client->config_value("z3950", "oclc", "password");
+}
 
 
 __PACKAGE__->register_method(
        method  => "z39_search_by_string",
        api_name        => "open-ils.search.z3950.raw_string",
-       argc            => 1, 
-       note            => "z3950 search by raw query string",
 );
 
-
 sub z39_search_by_string {
 
        my( $self, $client, $server, 
@@ -30,6 +49,9 @@ sub z39_search_by_string {
        throw OpenSRF::EX::InvalidArg unless( 
                        $server and $port and $db and $search);
 
+
+       warn "Z39.50 search for $search\n";
+
        $user ||= "";
        $pw     ||= "";
 
@@ -43,6 +65,9 @@ sub z39_search_by_string {
 
 
        my $rs = $conn->search( $search );
+       if(!$rs) {
+               throw OpenSRF::EX::ERROR ("z39 search failed"); 
+       }
 
        my $records = [];
        my $hash = {};
@@ -50,15 +75,19 @@ sub z39_search_by_string {
        $hash->{count} =  $rs->size();
        warn "Z3950 Search recovered " . $hash->{count} . " records\n";
 
+       # until there is a more graceful way to handle this
+       if($hash->{count} > 20) { return $hash; }
+
+
        for( my $x = 0; $x != $hash->{count}; $x++ ) {
                my $rec = $rs->record($x+1);
                my $marc = MARC::Record->new_from_usmarc($rec->rawdata());
 
-               my $u = OpenILS::Utils::ModsParser->new();
-               $u->start_mods_batch($marc->as_xml());
-               my $mods = $u->finish_mods_batch();
+               my $nodes = OpenILS::Utils::FlatXML->new()->xml_to_nodeset( $marc->as_xml() ); 
+               warn "turning nodeset into tree\n";
+               my $tree = $utils->nodeset2tree( $nodes->nodeset );
 
-               push @$records, $mods;
+               push @$records, $tree;
        }
 
        $hash->{records} = $records;
@@ -67,4 +96,20 @@ sub z39_search_by_string {
 }
 
 
+__PACKAGE__->register_method(
+       method  => "import_search",
+       api_name        => "open-ils.search.z3950.import",
+);
+
+sub import_search {
+       my($self, $client, $string) = @_;
+
+       return $self->z39_search_by_string(
+               $client, $host, $port, $database, 
+                       "\@attr 1=$attr \"$string\"", $username, $password );
+}
+
+
+
+
 1;