From: Lebbeous Fogle-Weekley Date: Fri, 17 Aug 2012 19:40:09 +0000 (-0400) Subject: ML methods to create sessions and do the searching/bucketing X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=cd061daddc45cb34cb1c8d6317cbbf9e50f2e121;p=evergreen%2Fequinox.git ML methods to create sessions and do the searching/bucketing We can't use PCRUD to create url_verify.session objects because a) you couldn't trust the creator field if we allowed that, and b) the container foreign key has a not-null constraint, so you have to create that first, and you can't do that with PCRUD. I've removed the C, U and D perms for PCRUD for url_verify.session, but I left the R in case we wind up using that. Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 2521678411..d685b20414 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -9359,10 +9359,7 @@ SELECT usr, - - - - + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm index 4e86dcd35e..0d6df0c00e 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm @@ -1,4 +1,7 @@ package OpenILS::Application::URLVerify; + +# For code searchability, I'm telling you this is the "link checker." + use base qw/OpenILS::Application/; use strict; use warnings; use OpenSRF::Utils::Logger qw(:logger); @@ -51,6 +54,9 @@ __PACKAGE__->register_method( } ); +# "validate_session" sounds like something to do with authentication, but it +# actually means for a given session, validate all the URLs associated with +# that session. sub validate_session { my ($self, $client, $auth, $session_id, $url_ids, $options) = @_; $options ||= {}; @@ -225,12 +231,14 @@ sub validate_session { }; } -# retrieves the URL domains and sorts them into buckets +# retrieves the URL domains and sorts them into buckets* # Iterates over the buckets and fires the multi-session call # the main drawback to this domain sorting approach is that # any domain used a lot more than the others will be the # only domain standing after the others are exhausted, which # means it will take a beating at the end of the batch. +# +# * local data structures, not container.* buckets sub sort_and_fire_domains { my ($e, $auth, $attempt, $url_ids, $multises) = @_; @@ -584,4 +592,114 @@ sub verify_one_url { } +__PACKAGE__->register_method( + method => "create_session", + api_name => "open-ils.url_verify.create_session", + signature => { + desc => q/Create a URL verify session. Also automatically create and + link a container./, + params => [ + {desc => "Authentication token", type => "string"}, + {desc => "session name", type => "string"}, + {desc => "QueryParser search", type => "string"}, + {desc => "owning_lib (defaults to ws_ou)", type => "number"}, + ], + return => {desc => "ID of new session or event on error", type => "number"} + } +); + +sub create_session { + my ($self, $client, $auth, $name, $search, $owning_lib) = @_; + + my $e = new_editor(authtoken => $auth, xact => 1); + return $e->die_event unless $e->checkauth; + + $owning_lib ||= $e->requestor->ws_ou; + return $e->die_event unless $e->allowed("VERIFY_URL", $owning_lib); + + my $session = Fieldmapper::url_verify::session->new; + $session->name($name); + $session->owning_lib($owning_lib); + $session->creator($e->requestor->id); + $session->search($search); + + my $container = Fieldmapper::container::biblio_record_entry_bucket->new; + $container->btype("url_verify"); + $container->owner($e->requestor->id); + $container->name($name); + $container->description("Automatically generated"); + + $e->create_container_biblio_record_entry_bucket($container) or + return $e->die_event; + + $session->container($e->data->id); + $e->create_url_verify_session($session) or + return $e->die_event; + + $e->commit or return $e->die_event; + + return $e->data->id; +} + + +__PACKAGE__->register_method( + method => "session_perform_search", + api_name => "open-ils.url_verify.session_perform_search", + signature => { + desc => q/ + Perform the search contained in the session, populating the linked bucket + /, + params => [ + {desc => "Authentication token", type => "string"}, + {desc => "url_verify.session id", type => "number"}, + ], + return => {desc => "1 for success, event on failure", type => "number"} + } +); + +# XXX TODO send progress updates? +# XXX TODO either blow away old search results or refuse to start (consider) +sub session_perform_search { + my ($self, $client, $auth, $ses_id) = @_; + + my $e = new_editor(authtoken => $auth); + return $e->die_event unless $e->checkauth; + + my $session = $e->retrieve_url_verify_session(int($ses_id)); + + return $e->die_event unless + $session and $e->allowed("VERIFY_URL", $session->owning_lib); + + # XXX TODO, if the following search takes too long, the caller of our method + # can time out + my $search_results = $U->simplereq( + "open-ils.search", "open-ils.search.biblio.multiclass.query.staff", + {}, $session->search + ); + + return new OpenILS::Event("UNKNOWN") unless $search_results; + return $search_results if $U->is_event($search_results); + + $e->xact_begin; + + # Make and save a bucket item for each search result. + + # remember, from search, each ID is nested in its own array ref + my $pos = 0; + foreach my $wrapper (@{$search_results->{ids}}) { + my $bucket_item = + Fieldmapper::container::biblio_record_entry_bucket_item->new; + + $bucket_item->bucket($session->container); + $bucket_item->target_biblio_record_entry(pop @$wrapper); + $bucket_item->pos($pos++); # we don't actually care + + $e->create_container_biblio_record_entry_bucket_item($bucket_item) or + return $e->die_event; + } + $e->xact_commit; + + return 1; +} + 1;