a371c49188fc782c58c20c5e47ae9f418492e81c
[irspy-moved-to-github.git] / web / htdocs / details / full.mc
1 %# $Id: full.mc,v 1.12 2006-11-06 17:40:04 mike Exp $
2 <%args>
3 $id
4 </%args>
5 <%once>
6 use ZOOM;
7 </%once>
8 <%perl>
9 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1");
10 $conn->option(elementSetName => "zeerex");
11 my $qid = $id;
12 $qid =~ s/"/\\"/g;
13 my $query = qq[rec.id="$qid"];
14 my $rs = $conn->search(new ZOOM::Query::CQL($query));
15 my $n = $rs->size();
16 if ($n == 0) {
17     $m->comp("/details/error.mc",
18              title => "Error", message => "No such ID '$id'");
19 } else {
20     my $rec = $rs->record(0);
21     my $xc = irspy_xpath_context($rec);
22     my @fields = (
23                   [ "Last Checked" => "i:status/i:probe[last()]" ],
24                   [ Protocol => "e:serverInfo/\@protocol" ],
25                   [ Host => "e:serverInfo/e:host" ],
26                   [ Port => "e:serverInfo/e:port" ],
27                   [ "Database Name" => "e:serverInfo/e:database" ],
28                   [ "Username (if needed)" =>
29                     "e:serverInfo/e:authentication/e:user" ],
30                   [ "Password (if needed)" =>
31                     "e:serverInfo/e:authentication/e:password" ],
32                   [ Title => "e:databaseInfo/e:title",
33                     lang => "en", primary => "true" ],
34                   [ Description => "e:databaseInfo/e:description",
35                     lang => "en", primary => "true" ],
36                   [ Author => "e:databaseInfo/e:author" ],
37                   [ Contact => "e:databaseInfo/e:contact" ],
38                   [ Extent => "e:databaseInfo/e:extent" ],
39                   [ History => "e:databaseInfo/e:history" ],
40                   [ "Language of Records" => "e:databaseInfo/e:langUsage" ],
41                   [ Restrictions => "e:databaseInfo/e:restrictions" ],
42                   [ Subjects => "e:databaseInfo/e:subjects" ],
43                   [ "Implementation ID" => "i:status/i:implementationId" ],
44                   [ "Implementation Name" => "i:status/i:implementationName" ],
45                   [ "Implementation Version" => "i:status/i:implementationVersion" ],
46                   [ "Reliability" => \&calc_reliability, $xc ],
47                   [ "Services" => sub { "
48 ### IRSpy does not yet check for search, present, delSet,
49 concurrentOperations, namedResultSets, etc. and store the information
50 is a usable form.  This information should probably be harvested from
51 the Init Response.
52 " } ],
53                   [ "Bib-1 Use attributes" => \&calc_ap, $xc, "bib-1" ],
54                   [ "Dan-1 Use attributes" => \&calc_ap, $xc, "dan-1" ],
55                   [ "Operators" => \&calc_boolean, $xc ],
56                   [ "Record syntaxes" => \&calc_recsyn, $xc ],
57                   [ "Explain" => \&calc_explain, $xc ],
58                   );
59 </%perl>
60      <h2><% xml_encode($xc->find("e:databaseInfo/e:title")) %></h2>
61      <table class="fullrecord" border="1" cellspacing="0" cellpadding="5" width="100%">
62 <%perl>
63     foreach my $ref (@fields) {
64         my($caption, $xpath, @args) = @$ref;
65         my $data;
66         if (ref $xpath && ref($xpath) eq "CODE") {
67             $data = &$xpath(@args);
68         } else {
69             $data = $xc->find($xpath);
70         }
71         if ($data) {
72 </%perl>
73       <tr>
74        <th><% xml_encode($caption) %></th>
75        <td><% xml_encode($data) %></td>
76       </tr>
77 %       }
78 %   }
79      </table>
80 % }
81 <%perl>
82
83 sub calc_reliability {
84     my($xc) = @_;
85
86     my @allpings = $xc->findnodes("i:status/i:probe");
87     my $nall = @allpings;
88     return "[untested]" if $nall == 0;
89     my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
90     my $nok = @okpings;
91     return "$nok/$nall = " . int(100*$nok/$nall) . "%";
92 }
93
94 sub calc_ap {
95     my($xc, $set) = @_;
96
97     my $expr = 'e:indexInfo/e:index/e:map/e:attr[
98         @set = "'.$set.'" and @type = "1"]';
99     my @bib1nodes = $xc->findnodes($expr);
100     my $nbib1 = @bib1nodes;
101     return "[none]" if $nbib1 == 0;
102
103     my $res = "";
104     my($first, $last);
105     @bib1nodes = sort { $a->findvalue(".") <=> $b->findvalue(".") } @bib1nodes;
106     foreach my $node (@bib1nodes) {
107         my $ap .= $node->findvalue(".");
108         if (!defined $first) {
109             $first = $ap;
110         } elsif (!defined $last || $last == $ap-1) {
111             $last = $ap;
112         } else {
113             # Got a complete range
114             $res .= ", " if $res ne "";
115             $res .= "$first";
116             $res .= "-$last" if defined $last;
117             $first = $ap;
118             $last = undef;
119         }
120     }
121
122     # Leftovers
123     if (defined $first) {
124         $res .= ", " if $res ne "";
125         $res .= "$first";
126         $res .= "-$last" if defined $last;
127     }
128
129     return "$nbib1 access points: $res";
130 }
131
132 sub calc_boolean {
133     my($xc) = @_;
134
135     ### Note that we are currently interrogating an IRSpy extension.
136     #   The standard ZeeRex record should be extended with a
137     #   "supports" type for this.
138     my @nodes = $xc->findnodes('i:status/i:boolean[@ok = "1"]');
139     my $res = join(", ", map { $_->findvalue('@operator') } @nodes);
140     $res = "[none]" if $res eq "";
141     return $res;
142 }
143
144 sub calc_recsyn {
145     my($xc) = @_;
146
147     my @nodes = $xc->findnodes('e:recordInfo/e:recordSyntax');
148     my $res = join(", ", map { $_->findvalue('@name') } @nodes);
149     $res = "[none]" if $res eq "";
150     return $res;
151 }
152
153 sub calc_explain {
154     my($xc) = @_;
155
156     my @nodes = $xc->findnodes('i:status/i:explain[@ok = "1"]');
157     my $res = join(", ", map { $_->findvalue('@category') } @nodes);
158     $res = "[none]" if $res eq "";
159     return $res;
160 }
161
162 </%perl>