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);
}
);
+# "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 ||= {};
};
}
-# 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) = @_;
}
+__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;