Resolve
authorMike Taylor <mike@indexdata.com>
Wed, 19 Dec 2012 10:04:25 +0000 (10:04 +0000)
committerMike Taylor <mike@indexdata.com>
Wed, 19 Dec 2012 10:04:25 +0000 (10:04 +0000)
.gitignore
Changes
MANIFEST
lib/ZOOM/IRSpy/Test/Quick.pm
lib/ZOOM/IRSpy/Test/Record/PiggyBack.pm [new file with mode: 0644]
web/htdocs/details/found.mc
web/htdocs/details/full.mc
xsl/irspy2zeerex.xsl

index 0b5bd39..d4567d4 100644 (file)
@@ -1,3 +1,4 @@
+MYMETA.yml
 Makefile
 blib
 pm_to_blib
diff --git a/Changes b/Changes
index 8e20cc8..dc1415c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -24,6 +24,10 @@ Revision history for Perl extension ZOOM::IRSpy.
          running an XPath with IRSpy-related namespaces established.
        - Record::Fetch test registers a fail when the syntax actually
          retrieved does not match that requested. Fixes bug IR-324.
+       - Add new test, Record::PiggyBack, with support for viewing,
+         editing and storing results. Fixes bug IR-333.
+       - IDs used in URLs for full-record links are properly
+         CQL-quoted. Fixes part of IR-303.
 
 1.02  Wed Jul  7 16:43:36 BST 2010
        - Enhance setrlimit program so that it can set maximum
index 0d2b86b..d2224dc 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -32,6 +32,7 @@ lib/ZOOM/IRSpy/Test/Quick.pm
 lib/ZOOM/IRSpy/Test/Record/Fetch.pm
 lib/ZOOM/IRSpy/Test/Record/Main.pm
 lib/ZOOM/IRSpy/Test/Record/OPAC.pm
+lib/ZOOM/IRSpy/Test/Record/PiggyBack.pm
 lib/ZOOM/IRSpy/Test/ResultSet/Main.pm
 lib/ZOOM/IRSpy/Test/ResultSet/Named.pm
 lib/ZOOM/IRSpy/Test/Search/Bath.pm
index c184ccd..a690c9e 100644 (file)
@@ -8,7 +8,7 @@ use warnings;
 use ZOOM::IRSpy::Test;
 our @ISA = qw(ZOOM::IRSpy::Test);
 
-sub subtests { qw(Ping Record::Fetch) }
+sub subtests { qw(Ping Record::PiggyBack) }
 
 sub timeout { 20 }
 
diff --git a/lib/ZOOM/IRSpy/Test/Record/PiggyBack.pm b/lib/ZOOM/IRSpy/Test/Record/PiggyBack.pm
new file mode 100644 (file)
index 0000000..9b62142
--- /dev/null
@@ -0,0 +1,93 @@
+# See the "Main" test package for documentation
+
+### Too much common code with OPAC.pm: need to refactor
+
+package ZOOM::IRSpy::Test::Record::PiggyBack;
+
+use 5.008;
+use strict;
+use warnings;
+
+use ZOOM::IRSpy::Test;
+our @ISA = qw(ZOOM::IRSpy::Test);
+
+my @queries = (
+              "\@attr 1=4 mineral",
+              "\@attr 1=4 computer",
+              "\@attr 1=44 mineral", # Smithsonian doesn't support AP 4!
+              "\@attr 1=1016 water", # Connector Framework only does 1016
+              ### We can add more queries here
+              );
+
+# We'd like to use this temporary-options hash to set
+# preferredRecordSyntax, as well  But that doesn't work because the
+# same value needs to be in force later on when we make the
+# record_immediate() call, otherwise it misses its cache.
+my %options = (
+    piggyback => 1,
+    count => 3,
+#    preferredRecordSyntax => "usmarc"
+    );
+
+sub start {
+    my $class = shift();
+    my($conn) = @_;
+
+    ### It would be better to consult previous tests to find a working RS
+    $conn->option(preferredRecordSyntax => "usmarc");
+    $conn->irspy_search_pqf($queries[0], { queryindex => 0 }, \%options,
+                           ZOOM::Event::ZEND, \&completed_search,
+                           exception => \&completed_search);
+}
+
+
+sub completed_search {
+    my($conn, $task, $udata, $event) = @_;
+
+    if ($event->isa("ZOOM::Exception") && $event->code() == 1005) {
+       $conn->log("irspy_test", "Piggyback searching not supported");  
+       $conn->record()->store_result('piggyback', 'ok' => 0);
+       return ZOOM::IRSpy::Status::TEST_BAD;
+    }
+
+    my $n = $task->{rs}->size();
+    $conn->log("irspy_test", "Piggyback test search (", $task->render_query(), ") ",
+              ref $event && $event->isa("ZOOM::Exception") ?
+              "failed: $event" : "found $n records (event=$event)");
+
+    # remember how often a target record hit a timeout
+    if (ref $event && $event->isa("ZOOM::Exception")) {
+       if ($event =~ /Timeout/i) {
+           $conn->record->zoom_error->{TIMEOUT}++;
+            $conn->log("irspy_test", "Increase timeout error counter to: " . 
+               $conn->record->zoom_error->{TIMEOUT});
+        }
+    }
+
+    if ($n < 3) {
+       $task->{rs}->destroy();
+       my $qindex = $udata->{queryindex}+1;
+       my $q = $queries[$qindex];
+       return ZOOM::IRSpy::Status::TEST_SKIPPED
+           if !defined $q || $conn->record->zoom_error->{TIMEOUT} >= $ZOOM::IRSpy::max_timeout_errors;
+
+       $conn->log("irspy_test", "Trying another search ...");
+       $conn->irspy_search_pqf($queries[$qindex], { queryindex => $qindex }, \%options,
+                               ZOOM::Event::ZEND, \&completed_search,
+                               exception => \&completed_search);
+       return ZOOM::IRSpy::Status::TASK_DONE;
+    }
+
+    # We have a result-set of three of more records, and we requested
+    # that those records be included in the Search Response using
+    # piggybacking.  Was it done?
+    my $rec = $task->{rs}->record_immediate(2);
+    my $ok = defined $rec && $rec->error() == 0;
+
+    $task->{rs}->destroy();
+    $conn->record()->store_result('piggyback', 'ok' => $ok);
+    return $ok ? ZOOM::IRSpy::Status::TEST_GOOD : ZOOM::IRSpy::Status::TEST_BAD;
+}
+
+
+1;
index e4312fb..84735fc 100644 (file)
@@ -124,7 +124,7 @@ push @ids, $id;
 </%perl>
       <tr style="background: <% ($i % 2) ? '#ffffc0' : 'white' %>">
        <td><% $i %></td>
-       <td><a href="<% xml_encode("/full.html?id=" . uri_escape_utf8($id))
+       <td><a href="<% xml_encode("/full.html?id==" . uri_escape_utf8(cql_quote($id)))
                %>"><% xml_encode($title) %></a></td>
        <td><% xml_encode($reliability, "", { nbsp => 1 }) %></td>
        <td><% xml_encode($host, "") %></td>
index 546419b..6003fc7 100644 (file)
@@ -51,6 +51,7 @@ if ($n == 0) {
                  [ "Record syntaxes" => \&calc_recsyn, $xc ],
                  [ "Explain" => \&calc_explain, $xc ],
                  [ "Multiple OPAC records" => \&calc_mor, $xc ],
+                 [ "Piggback searching" => \&calc_piggyback, $xc ],
                  );
     my $title = $xc->find("e:databaseInfo/e:title");
 </%perl>
@@ -183,6 +184,7 @@ sub calc_boolean {
 
 sub calc_nrs { _calc_boolean(@_, 'i:status/i:named_resultset[@ok = "1"]') }
 sub calc_mor { _calc_boolean(@_, 'i:status/i:multiple_opac[@ok = "1"]') }
+sub calc_piggyback { _calc_boolean(@_, 'i:status/i:piggback[@ok = "1"]') }
 
 sub _calc_boolean {
     my($id, $xc, $xpath) = @_;
index 6379a38..3926ad6 100644 (file)
       </xsl:call-template>
 
       <xsl:call-template name="insert-latest-nodes">
+        <xsl:with-param name="nodes" select="*/irspy:piggyback"/>
+        <xsl:with-param name="what" select="'piggyback'"/>
+      </xsl:call-template>
+
+      <xsl:call-template name="insert-latest-nodes">
         <xsl:with-param name="nodes" select="*/irspy:search_bath"/>
         <xsl:with-param name="what" select="'search_bath'"/>
       </xsl:call-template>