use strict; use warnings;
use Data::Dumper;
+use Digest::MD5 qw(md5_hex);
+
use OpenSRF::EX qw(:try);
use OpenILS::EX;
__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 ) = @_;
}
+
+
__PACKAGE__->register_method(
method => "user_retrieve_fleshed_by_id",
api_name => "open-ils.actor.user.fleshed.retrieve",);
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;
}
+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;
+}
+
+
}
}
+
$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");
}
$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;
+
}
__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 ) = @_;
$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);
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",
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 } );
}
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();
}
-
__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;
+=head comment
__PACKAGE__->register_method(
method => "cat_biblio_search_class_id",
api_name => "open-ils.search.cat.biblio.class.id",
return { count =>$size, ids => \@ids };
}
+=cut
__PACKAGE__->register_method(
method => "biblio_search_class_count",
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 " .
-
-
1;