From 8c37dde01147085ffc4f5e073c7f097f1f28d58a Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 21 Jun 2005 14:40:26 +0000 Subject: [PATCH] more batch committing git-svn-id: svn://svn.open-ils.org/ILS/trunk@889 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Actor.pm | 79 ++++++++++- .../src/perlmods/OpenILS/Application/AppUtils.pm | 2 +- Open-ILS/src/perlmods/OpenILS/Application/Cat.pm | 19 ++- Open-ILS/src/perlmods/OpenILS/Application/Circ.pm | 5 + .../src/perlmods/OpenILS/Application/Search.pm | 155 +++++---------------- .../perlmods/OpenILS/Application/Search/Biblio.pm | 12 +- 6 files changed, 129 insertions(+), 143 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index d49b53f5af..59b66e201a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -3,6 +3,8 @@ use base qw/OpenSRF::Application/; use strict; use warnings; use Data::Dumper; +use Digest::MD5 qw(md5_hex); + use OpenSRF::EX qw(:try); use OpenILS::EX; @@ -17,9 +19,7 @@ my $cache_client = OpenSRF::Utils::Cache->new("global", 0); __PACKAGE__->register_method( method => "update_patron", - api_name => "open-ils.actor.patron.update", -); - + api_name => "open-ils.actor.patron.update",); sub update_patron { my( $self, $client, $user_session, $patron ) = @_; @@ -89,6 +89,8 @@ sub update_patron { } + + __PACKAGE__->register_method( method => "user_retrieve_fleshed_by_id", api_name => "open-ils.actor.user.fleshed.retrieve",); @@ -574,15 +576,19 @@ __PACKAGE__->register_method( sub get_org_unit { - my( $self, $client, $user_session ) = @_; + my( $self, $client, $user_session, $org_id ) = @_; my $user_obj = OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error + if(!$org_id) { + $org_id = $user_obj->home_ou; + } + my $home_ou = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage", "open-ils.storage.direct.actor.org_unit.retrieve", - $user_obj->home_ou ); + $org_id ); return $home_ou; } @@ -740,6 +746,68 @@ sub patron_adv_search { +sub _verify_password { + my($user_session, $password) = @_; + my $user_obj = $apputils->check_user_session($user_session); + + #grab the user with password + $user_obj = $apputils->simple_scalar_request( + "open-ils.storage", + "open-ils.storage.direct.actor.user.retrieve", + $user_obj->id ); + + if($user_obj->passwd eq $password) { + return 1; + } + + return 0; +} + + +__PACKAGE__->register_method( + method => "update_password", + api_name => "open-ils.actor.user.password.update"); + +__PACKAGE__->register_method( + method => "update_password", + api_name => "open-ils.actor.user.username.update"); + +__PACKAGE__->register_method( + method => "update_password", + api_name => "open-ils.actor.user.email.update"); + +sub update_password { + my( $self, $client, $user_session, $new_value, $current_password ) = @_; + + my $user_obj = $apputils->check_user_session($user_session); + warn "Updating user with method " .$self->api_name . "\n"; + + if($self->api_name =~ /password/) { + + #make sure they know the current password + if(!_verify_password($user_session, md5_hex($current_password))) { + return OpenILS::EX->new("USER_WRONG_PASSWORD")->ex; + } + + $user_obj->passwd($new_value); + } + elsif($self->api_name =~ /username/) { + $user_obj->usrname($new_value); + } + + elsif($self->api_name =~ /email/) { + $user_obj->email($new_value); + } + + my $session = $apputils->start_db_session(); + $user_obj = _update_patron($session, $user_obj); + $apputils->commit_db_session($session); + + if($user_obj) { return 1; } + return undef; +} + + @@ -822,3 +890,4 @@ sub _delete_patron { } } + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index ad7409e7d1..fabcae3e2e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -112,7 +112,7 @@ sub simple_scalar_request { $request->wait_complete; if(!$request->complete) { - throw $response ("Call to $service for method $method with params @params" . + throw OpenSRF::EX::ERROR ("Call to $service for method $method with params @params" . "\n did not complete successfully"); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm index aed611d137..9b25a10c28 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm @@ -247,10 +247,15 @@ sub biblio_record_tree_commit { $tree = $utils->nodeset2tree($nodeset->nodeset); $tree->owner_doc($docid); - $client->respond_complete($tree); +# $client->respond_complete($tree); warn "Done wormizing\n"; + use Data::Dumper; + warn "Returning tree:\n"; + warn Dumper $tree; + return $tree; + } @@ -424,14 +429,13 @@ sub orgs_for_title { __PACKAGE__->register_method( method => "retrieve_copies", - api_name => "open-ils.cat.asset.copy_tree.retrieve", -); + api_name => "open-ils.cat.asset.copy_tree.retrieve"); __PACKAGE__->register_method( method => "retrieve_copies", - api_name => "open-ils.cat.asset.copy_tree.global.retrieve", -); + api_name => "open-ils.cat.asset.copy_tree.global.retrieve"); +# user_session may be null/undef sub retrieve_copies { my( $self, $client, $user_session, $docid, @org_ids ) = @_; @@ -440,9 +444,10 @@ sub retrieve_copies { $docid = "$docid"; - warn " $$ retrieving copy tree for doc $docid at " . time() . "\n"; + warn " $$ retrieving copy tree for orgs @org_ids and doc $docid at " . time() . "\n"; - if(!@org_ids) { + # grabbing copy trees should be available for everyone.. + if(!@org_ids and $user_session) { my $user_obj = OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error @org_ids = ($user_obj->home_ou); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index 9ea48f8773..e512b618a4 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -36,6 +36,9 @@ sub checkouts_by_user { my( $self, $client, $user_session, $user_id ) = @_; my $session = OpenSRF::AppSession->create("open-ils.storage"); + my $user_obj = $apputils->check_user_session($user_session); + + if(!$user_id) { $user_id = $user_obj->id(); } my $circs = $session->request( "open-ils.storage.direct.action.circulation.search.atomic", @@ -64,6 +67,8 @@ sub checkouts_by_user { my $u = OpenILS::Utils::ModsParser->new(); $u->start_mods_batch( $record->marc() ); my $mods = $u->finish_mods_batch(); + warn "Doc id is " . $record->id() . "\n"; + $mods->doc_id($record->id()); push( @results, { copy => $copy, circ => $circ, record => $mods } ); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search.pm index b3a6d73f35..7d187f514b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search.pm @@ -19,11 +19,10 @@ use OpenILS::Application::AppUtils; use Time::HiRes qw(time); use OpenSRF::EX qw(:try); -# Houses generic search utilites +use Text::Aspell; # spell checking... -sub child_init { - OpenILS::Application::SearchCache->child_init(); -} + +# Houses generic search utilites sub initialize { OpenILS::Application::Search::Z3950->initialize(); @@ -101,131 +100,39 @@ sub filter_search { } - __PACKAGE__->register_method( - method => "get_org_sub_tree", - api_name => "open-ils.search.actor.org_subtree.retrieve", - argc => 1, - note => "Returns the entire org tree structure", -); - -sub get_sub_org_tree { - - my( $self, $client, $user_session ) = @_; - - if(!$user_session) { - throw OpenSRF::EX::InvalidArg - ("No User session provided to org_subtree.retrieve"); - } - - if( $user_session ) { - - my $user_obj = - OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error - - - my $session = OpenSRF::AppSession->create("open-ils.storage"); - my $request = $session->request( - "open-ils.storage.direct.actor.org_unit.retrieve", $user_obj->home_ou ); - my $response = $request->recv(); - - if(!$response) { - throw OpenSRF::EX::ERROR ( - "No response from storage for org_unit retrieve"); + method => "check_spelling", + api_name => "open-ils.search.spell_check"); + +sub check_spelling { + my( $self, $client, $phrase ) = @_; + + my @resp_objects = (); + my $speller = Text::Aspell->new(); + $speller->set_option('lang', 'en_US'); + my $return_something = 0; + + my $return_phrase = ""; + + for my $word (split(' ',$phrase) ) { + if( ! $speller->check($word) ) { + if( $speller->suggest($word) ) { $return_something = 1; } + $return_something = 1; + my $word_stuff = {}; + $word_stuff->{'word'} = $word; + $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ]; + if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; } + else { $return_phrase .= " " . ($speller->suggest($word))[0];} + + } else { + if( ! $return_phrase ) { $return_phrase = $word; } + else { $return_phrase .= " $word"; } } - if(UNIVERSAL::isa($response,"Error")) { - throw $response ($response->stringify); - } - - my $home_ou = $response->content; - - # XXX grab descendants and build org tree from them -=head comment - my $request = $session->request( - "open-ils.storage.actor.org_unit_descendants" ); - my $response = $request->recv(); - if(!$response) { - throw OpenSRF::EX::ERROR ( - "No response from storage for org_unit retrieve"); - } - if(UNIVERSAL::isa($response,"Error")) { - throw $response ($response->stringify); - } - - my $descendants = $response->content; -=cut - - $request->finish(); - $session->disconnect(); - - return $home_ou; - } - - return undef; - -} - - - - - - - - -package OpenILS::Application::SearchCache; -use strict; use warnings; - -my $cache_handle; -my $max_timeout; - -sub child_init { - - my $config_client = OpenSRF::Utils::SettingsClient->new(); - my $memcache_servers = - $config_client->config_value( - "apps","open-ils.search", "app_settings","memcache" ); - - if( !$memcache_servers ) { - throw OpenSRF::EX::Config (" - No Memcache servers specified for open-ils.search!"); - } - - if(!ref($memcache_servers)) { - $memcache_servers = [$memcache_servers]; - } - $cache_handle = OpenSRF::Utils::Cache->new( "open-ils.search", 0, $memcache_servers ); - $max_timeout = $config_client->config_value( - "apps", "open-ils.search", "app_settings", "max_cache_time" ); - - if(ref($max_timeout) eq "ARRAY") { - $max_timeout = $max_timeout->[0]; } -} - -sub new {return bless({},shift());} - -sub put_cache { - my($self, $key, $data, $timeout) = @_; - return undef unless( $key and $data ); - - $timeout ||= $max_timeout; - $timeout = ($timeout <= $max_timeout) ? $timeout : $max_timeout; + if( $return_something ) { return $return_phrase; } + return 0; - warn "putting $key into cache for $timeout seconds\n"; - $cache_handle->put_cache( "_open-ils.search_$key", JSON->perl2JSON($data), $timeout ); } -sub get_cache { - my( $self, $key ) = @_; - my $json = $cache_handle->get_cache("_open-ils.search_$key"); - if($json) { - warn "retrieving from cache $key\n =>>> $json"; - } - return JSON->JSON2perl($json); -} - - - - 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm index 1cd671189d..3fa5f9e11b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm @@ -501,6 +501,7 @@ sub cat_biblio_search_class { +=head comment __PACKAGE__->register_method( method => "cat_biblio_search_class_id", api_name => "open-ils.search.cat.biblio.class.id", @@ -568,6 +569,7 @@ sub cat_biblio_search_class_id { return { count =>$size, ids => \@ids }; } +=cut __PACKAGE__->register_method( method => "biblio_search_class_count", @@ -668,10 +670,10 @@ sub biblio_search_class { warn "org: $org_id : depth: $org_type : limit: $limit : offset: $offset\n"; - $offset ||= 0; - $limit = 100 unless defined($limit and $limit > 0 ); - $org_id = "1" unless defined($org_id); # xxx - $org_type = 0 unless defined($org_type); + $offset = 0 unless (defined($offset) and $offset > 0); + $limit = 100 unless (defined($limit) and $limit > 0); + $org_id = "1" unless (defined($org_id)); # xxx + $org_type = 0 unless (defined($org_type)); warn "Searching biblio.class.id\n" . "string: $string " . @@ -961,6 +963,4 @@ sub retrieve_all_copy_statuses { - - 1; -- 2.11.0