[open-ils-commits] r19176 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Search (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Jan 13 21:57:48 EST 2011
Author: dbs
Date: 2011-01-13 21:57:46 -0500 (Thu, 13 Jan 2011)
New Revision: 19176
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
Log:
Whitespace normalization: tabs to spaces
Also, remove vestigial Data::Dumper import.
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm 2011-01-14 02:49:33 UTC (rev 19175)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm 2011-01-14 02:57:46 UTC (rev 19176)
@@ -7,7 +7,6 @@
use MARC::File::XML;
use Unicode::Normalize;
use XML::LibXML;
-use Data::Dumper;
use OpenILS::Event;
use OpenSRF::EX qw(:try);
@@ -17,7 +16,7 @@
use OpenSRF::Utils::Logger qw/$logger/;
use OpenILS::Utils::CStoreEditor q/:funcs/;
-my $output = "usmarc";
+my $output = "usmarc";
my $U = 'OpenILS::Application::AppUtils';
my $sclient;
@@ -26,53 +25,53 @@
__PACKAGE__->register_method(
- method => 'do_class_search',
- api_name => 'open-ils.search.z3950.search_class',
- stream => 1,
- signature => q/
- Performs a class based Z search. The classes available
- are defined by the 'attr' fields in the config for the
- requested service.
- @param auth The login session key
- @param shash The search hash : { attr : value, attr2: value, ...}
- @param service The service to connect to
- @param username The username to use when connecting to the service
- @param password The password to use when connecting to the service
- /
+ method => 'do_class_search',
+ api_name => 'open-ils.search.z3950.search_class',
+ stream => 1,
+ signature => q/
+ Performs a class based Z search. The classes available
+ are defined by the 'attr' fields in the config for the
+ requested service.
+ @param auth The login session key
+ @param shash The search hash : { attr : value, attr2: value, ...}
+ @param service The service to connect to
+ @param username The username to use when connecting to the service
+ @param password The password to use when connecting to the service
+ /
);
__PACKAGE__->register_method(
- method => 'do_service_search',
- api_name => 'open-ils.search.z3950.search_service',
- signature => q/
- @param auth The login session key
- @param query The Z3950 search string to use
- @param service The service to connect to
- @param username The username to use when connecting to the service
- @param password The password to use when connecting to the service
- /
+ method => 'do_service_search',
+ api_name => 'open-ils.search.z3950.search_service',
+ signature => q/
+ @param auth The login session key
+ @param query The Z3950 search string to use
+ @param service The service to connect to
+ @param username The username to use when connecting to the service
+ @param password The password to use when connecting to the service
+ /
);
__PACKAGE__->register_method(
- method => 'do_service_search',
- api_name => 'open-ils.search.z3950.search_raw',
- signature => q/
- @param auth The login session key
- @param args An object of search params which must include:
- host, port, db and query.
- optional fields include username and password
- /
+ method => 'do_service_search',
+ api_name => 'open-ils.search.z3950.search_raw',
+ signature => q/
+ @param auth The login session key
+ @param args An object of search params which must include:
+ host, port, db and query.
+ optional fields include username and password
+ /
);
__PACKAGE__->register_method(
- method => "query_services",
- api_name => "open-ils.search.z3950.retrieve_services",
- signature => q/
- Returns a list of service names that we have config
- data for
- /
+ method => "query_services",
+ api_name => "open-ils.search.z3950.retrieve_services",
+ signature => q/
+ Returns a list of service names that we have config
+ data for
+ /
);
@@ -81,12 +80,12 @@
# What services do we have config info for?
# -------------------------------------------------------------------
sub query_services {
- my( $self, $client, $auth ) = @_;
- my $e = new_editor(authtoken=>$auth);
- return $e->event unless $e->checkauth;
- return $e->event unless $e->allowed('REMOTE_Z3950_QUERY');
+ my( $self, $client, $auth ) = @_;
+ my $e = new_editor(authtoken=>$auth);
+ return $e->event unless $e->checkauth;
+ return $e->event unless $e->allowed('REMOTE_Z3950_QUERY');
- return fetch_service_defs();
+ return fetch_service_defs();
}
# -------------------------------------------------------------------
@@ -168,31 +167,31 @@
# -------------------------------------------------------------------
sub do_class_search {
- fetch_service_defs() unless (scalar(keys(%services)));
+ fetch_service_defs() unless (scalar(keys(%services)));
- my $self = shift;
- my $conn = shift;
- my $auth = shift;
- my $args = shift;
+ my $self = shift;
+ my $conn = shift;
+ my $auth = shift;
+ my $args = shift;
- if (!ref($$args{service})) {
- $$args{service} = [$$args{service}];
- $$args{username} = [$$args{username}];
- $$args{password} = [$$args{password}];
- }
+ if (!ref($$args{service})) {
+ $$args{service} = [$$args{service}];
+ $$args{username} = [$$args{username}];
+ $$args{password} = [$$args{password}];
+ }
- $$args{async} = 1;
+ $$args{async} = 1;
- my @connections;
- my @results;
+ my @connections;
+ my @results;
my @services;
- for (my $i = 0; $i < @{$$args{service}}; $i++) {
- my %tmp_args = %$args;
- $tmp_args{service} = $$args{service}[$i];
- $tmp_args{username} = $$args{username}[$i];
- $tmp_args{password} = $$args{password}[$i];
+ for (my $i = 0; $i < @{$$args{service}}; $i++) {
+ my %tmp_args = %$args;
+ $tmp_args{service} = $$args{service}[$i];
+ $tmp_args{username} = $$args{username}[$i];
+ $tmp_args{password} = $$args{password}[$i];
- $logger->debug("z3950: service: $tmp_args{service}, async: $tmp_args{async}");
+ $logger->debug("z3950: service: $tmp_args{service}, async: $tmp_args{async}");
if ($tmp_args{service} eq 'native-evergreen-catalog') {
my $method = $self->method_lookup('open-ils.search.biblio.zstyle.staff');
@@ -216,13 +215,13 @@
}
}
- $logger->debug("z3950: Result object: $results[$i], Connection object: $connections[$i]");
- }
+ $logger->debug("z3950: Result object: $results[$i], Connection object: $connections[$i]");
+ }
- $logger->debug("z3950: Connections created");
+ $logger->debug("z3950: Connections created");
return undef unless (@connections);
- my @records;
+ my @records;
# local catalog search is not processed with other z39 results;
$$args{service} = [grep {$_ ne 'native-evergreen-catalog'} @{$$args{service}}];
@@ -230,17 +229,17 @@
@connections = grep {defined $_} @connections;
return undef unless @connections;
- while ((my $index = OpenILS::Utils::ZClient::event( \@connections )) != 0) {
- my $ev = $connections[$index - 1]->last_event();
- $logger->debug("z3950: Received event $ev");
- if ($ev == OpenILS::Utils::ZClient::EVENT_END()) {
- my $munged = process_results( $results[$index - 1], $$args{limit}, $$args{offset}, $$args{service}[$index -1] );
- $$munged{service} = $$args{service}[$index - 1];
- $conn->respond($munged);
- }
- }
+ while ((my $index = OpenILS::Utils::ZClient::event( \@connections )) != 0) {
+ my $ev = $connections[$index - 1]->last_event();
+ $logger->debug("z3950: Received event $ev");
+ if ($ev == OpenILS::Utils::ZClient::EVENT_END()) {
+ my $munged = process_results( $results[$index - 1], $$args{limit}, $$args{offset}, $$args{service}[$index -1] );
+ $$munged{service} = $$args{service}[$index - 1];
+ $conn->respond($munged);
+ }
+ }
- $logger->debug("z3950: Search Complete");
+ $logger->debug("z3950: Search Complete");
return undef;
}
@@ -250,21 +249,21 @@
# -------------------------------------------------------------------
sub do_service_search {
- fetch_service_defs() unless (scalar(keys(%services)));
+ fetch_service_defs() unless (scalar(keys(%services)));
- my $self = shift;
- my $conn = shift;
- my $auth = shift;
- my $args = shift;
-
- my $info = $services{$$args{service}};
+ my $self = shift;
+ my $conn = shift;
+ my $auth = shift;
+ my $args = shift;
+
+ my $info = $services{$$args{service}};
- $$args{host} = $$info{host};
- $$args{port} = $$info{port};
- $$args{db} = $$info{db};
+ $$args{host} = $$info{host};
+ $$args{port} = $$info{port};
+ $$args{db} = $$info{db};
$logger->debug("z3950: do_search...");
- return do_search( $self, $conn, $auth, $args );
+ return do_search( $self, $conn, $auth, $args );
}
@@ -275,72 +274,72 @@
# -------------------------------------------------------------------
sub do_search {
- fetch_service_defs() unless (scalar(keys(%services)));
+ fetch_service_defs() unless (scalar(keys(%services)));
- my $self = shift;
- my $conn = shift;
- my $auth = shift;
- my $args = shift;
+ my $self = shift;
+ my $conn = shift;
+ my $auth = shift;
+ my $args = shift;
- my $host = $$args{host} or return undef;
- my $port = $$args{port} or return undef;
- my $db = $$args{db} or return undef;
- my $query = $$args{query} or return undef;
- my $async = $$args{async} || 0;
+ my $host = $$args{host} or return undef;
+ my $port = $$args{port} or return undef;
+ my $db = $$args{db} or return undef;
+ my $query = $$args{query} or return undef;
+ my $async = $$args{async} || 0;
- my $limit = $$args{limit} || 10;
- my $offset = $$args{offset} || 0;
+ my $limit = $$args{limit} || 10;
+ my $offset = $$args{offset} || 0;
- my $username = $$args{username} || "";
- my $password = $$args{password} || "";
+ my $username = $$args{username} || "";
+ my $password = $$args{password} || "";
my $tformat = $services{$args->{service}}->{transmission_format} || $output;
- my $editor = new_editor(authtoken => $auth);
- return $editor->event unless $editor->checkauth;
- return $editor->event unless $editor->allowed('REMOTE_Z3950_QUERY');
+ my $editor = new_editor(authtoken => $auth);
+ return $editor->event unless $editor->checkauth;
+ return $editor->event unless $editor->allowed('REMOTE_Z3950_QUERY');
$logger->info("z3950: connecting to server $host:$port:$db as $username");
- my $connection = OpenILS::Utils::ZClient->new(
- $host, $port,
- databaseName => $db,
- user => $username,
- password => $password,
- async => $async,
- preferredRecordSyntax => $tformat,
- );
+ my $connection = OpenILS::Utils::ZClient->new(
+ $host, $port,
+ databaseName => $db,
+ user => $username,
+ password => $password,
+ async => $async,
+ preferredRecordSyntax => $tformat,
+ );
- if( ! $connection ) {
- $logger->error("z3950: Unable to connect to Z server: ".
- "$host:$port:$db:$username:$password");
- return OpenILS::Event->new('Z3950_LOGIN_FAILED') unless $connection;
- }
+ if( ! $connection ) {
+ $logger->error("z3950: Unable to connect to Z server: ".
+ "$host:$port:$db:$username:$password");
+ return OpenILS::Event->new('Z3950_LOGIN_FAILED') unless $connection;
+ }
- my $start = time;
- my $results;
- my $err;
+ my $start = time;
+ my $results;
+ my $err;
- $logger->info("z3950: query => $query");
+ $logger->info("z3950: query => $query");
- try {
- $results = $connection->search_pqf( $query );
- } catch Error with { $err = shift; };
+ try {
+ $results = $connection->search_pqf( $query );
+ } catch Error with { $err = shift; };
- return OpenILS::Event->new(
- 'Z3950_BAD_QUERY', payload => $query, debug => "$err") if $err;
+ return OpenILS::Event->new(
+ 'Z3950_BAD_QUERY', payload => $query, debug => "$err") if $err;
- return OpenILS::Event->new('Z3950_SEARCH_FAILED',
- debug => $connection->errcode." => ".$connection->errmsg." : query = $query") unless $results;
+ return OpenILS::Event->new('Z3950_SEARCH_FAILED',
+ debug => $connection->errcode." => ".$connection->errmsg." : query = $query") unless $results;
- $logger->info("z3950: search [$query] took ".(time - $start)." seconds");
+ $logger->info("z3950: search [$query] took ".(time - $start)." seconds");
- return {result => $results, connection => $connection} if ($async);
+ return {result => $results, connection => $connection} if ($async);
- my $munged = process_results($results, $limit, $offset, $$args{service});
- $munged->{query} = $query;
+ my $munged = process_results($results, $limit, $offset, $$args{service});
+ $munged->{query} = $query;
- return $munged;
+ return $munged;
}
@@ -350,11 +349,11 @@
# -------------------------------------------------------------------
sub process_results {
- fetch_service_defs() unless (scalar(keys(%services)));
+ fetch_service_defs() unless (scalar(keys(%services)));
- my $results = shift;
- my $limit = shift || 10;
- my $offset = shift || 0;
+ my $results = shift;
+ my $limit = shift || 10;
+ my $offset = shift || 0;
my $service = shift;
my $rformat = $services{$service}->{record_format};
@@ -364,61 +363,61 @@
$results->option(preferredRecordSyntax => $tformat);
$logger->info("z3950: using record format '$rformat' and transmission format '$tformat'");
- my @records;
- my $res = {};
- my $count = $$res{count} = $results->size;
+ my @records;
+ my $res = {};
+ my $count = $$res{count} = $results->size;
- $logger->info("z3950: search returned $count hits");
+ $logger->info("z3950: search returned $count hits");
- my $tend = $limit + $offset;
+ my $tend = $limit + $offset;
- my $end = ($tend <= $count) ? $tend : $count;
+ my $end = ($tend <= $count) ? $tend : $count;
- for($offset..$end - 1) {
+ for($offset..$end - 1) {
- my $err;
- my $mods;
- my $marc;
- my $marcs;
- my $marcxml;
+ my $err;
+ my $mods;
+ my $marc;
+ my $marcs;
+ my $marcxml;
- $logger->info("z3950: fetching record $_");
+ $logger->info("z3950: fetching record $_");
- try {
+ try {
- my $rec = $results->record($_);
+ my $rec = $results->record($_);
if ($tformat eq 'usmarc') {
- $marc = MARC::Record->new_from_usmarc($rec->raw());
+ $marc = MARC::Record->new_from_usmarc($rec->raw());
} elsif ($tformat eq 'xml') {
- $marc = MARC::Record->new_from_xml($rec->raw());
+ $marc = MARC::Record->new_from_xml($rec->raw());
} else {
die "Unsupported record transmission format $tformat"
}
- $marcs = $U->entityize($marc->as_xml_record);
- $marcs = $U->strip_ctrl_chars($marcs);
- my $doc = XML::LibXML->new->parse_string($marcs);
- $marcxml = $U->entityize($doc->documentElement->toString);
- $marcxml = $U->strip_ctrl_chars($marcxml);
-
- my $u = OpenILS::Utils::ModsParser->new();
- $u->start_mods_batch( $marcxml );
- $mods = $u->finish_mods_batch();
-
+ $marcs = $U->entityize($marc->as_xml_record);
+ $marcs = $U->strip_ctrl_chars($marcs);
+ my $doc = XML::LibXML->new->parse_string($marcs);
+ $marcxml = $U->entityize($doc->documentElement->toString);
+ $marcxml = $U->strip_ctrl_chars($marcxml);
+
+ my $u = OpenILS::Utils::ModsParser->new();
+ $u->start_mods_batch( $marcxml );
+ $mods = $u->finish_mods_batch();
+
- } catch Error with { $err = shift; };
+ } catch Error with { $err = shift; };
- push @records, { 'mvr' => $mods, 'marcxml' => $marcxml } unless $err;
- $logger->error("z3950: bad XML : $err") if $err;
+ push @records, { 'mvr' => $mods, 'marcxml' => $marcxml } unless $err;
+ $logger->error("z3950: bad XML : $err") if $err;
- if( $err ) {
- warn "\n\n$marcs\n\n";
- }
- }
-
- $res->{records} = \@records;
- return $res;
+ if( $err ) {
+ warn "\n\n$marcs\n\n";
+ }
+ }
+
+ $res->{records} = \@records;
+ return $res;
}
@@ -428,32 +427,33 @@
# -------------------------------------------------------------------
sub compile_query {
- fetch_service_defs() unless (scalar(keys(%services)));
+ fetch_service_defs() unless (scalar(keys(%services)));
- my $seperator = shift;
- my $service = shift;
- my $hash = shift;
+ my $separator = shift;
+ my $service = shift;
+ my $hash = shift;
- my $count = scalar(keys %$hash);
+ my $count = scalar(keys %$hash);
- my $str = "";
- $str .= "\@$seperator " for (1..$count-1);
-
+ my $str = "";
+ $str .= "\@$separator " for (1..$count-1);
+
# -------------------------------------------------------------------
# "code" is the bib-1 "use attribute", "format" is the bib-1
# "structure attribute"
# -------------------------------------------------------------------
- for( keys %$hash ) {
- next unless ( exists $services{$service}->{attrs}->{$_} );
- $str .= '@attr 1=' . $services{$service}->{attrs}->{$_}->{code} . # add the use attribute
- ' @attr 4=' . $services{$service}->{attrs}->{$_}->{format}; # add the structure attribute
- if (exists $services{$service}->{attrs}->{$_}->{truncation}
- && $services{$service}->{attrs}->{$_}->{truncation} >= 0) {
- $str .= ' @attr 5=' . $services{$service}->{attrs}->{$_}->{truncation};
- }
- $str .= " \"" . $$hash{$_} . "\" "; # add the search term
- }
- return $str;
+ for( keys %$hash ) {
+ next unless ( exists $services{$service}->{attrs}->{$_} );
+ $str .= '@attr 1=' . $services{$service}->{attrs}->{$_}->{code} . # add the use attribute
+ ' @attr 4=' . $services{$service}->{attrs}->{$_}->{format}; # add the structure attribute
+ if (exists $services{$service}->{attrs}->{$_}->{truncation}
+ && $services{$service}->{attrs}->{$_}->{truncation} >= 0) {
+ $str .= ' @attr 5=' . $services{$service}->{attrs}->{$_}->{truncation};
+ }
+ $str .= " \"" . $$hash{$_} . "\" "; # add the search term
+ }
+ return $str;
}
1;
+# vim:et:ts=4:sw=4:
More information about the open-ils-commits
mailing list