more batch committing
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 21 Jun 2005 14:40:26 +0000 (14:40 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 21 Jun 2005 14:40:26 +0000 (14:40 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@889 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
Open-ILS/src/perlmods/OpenILS/Application/Search.pm
Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm

index d49b53f..59b66e2 100644 (file)
@@ -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 {
        }
 }
 
+
index ad7409e..fabcae3 100644 (file)
@@ -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");
        }
 
index aed611d..9b25a10 100644 (file)
@@ -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);
index 9ea48f8..e512b61 100644 (file)
@@ -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 } );
        }
index b3a6d73..7d187f5 100644 (file)
@@ -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;
index 1cd6711..3fa5f9e 100644 (file)
@@ -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;