View | Details | Raw Unified | Return to bug 12836
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/services/explain-biblios.tt (+239 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
[%- USE Koha -%]
4
[%- USE date( format = '%Y-%m-%d %H:%M:%S' ) -%]
5
6
<!-- this file configures the SRU/SRW explain response -->
7
<!-- see: http://explain.z3950.org/dtd/commentary.html -->
8
<!-- validate this using zeerex-2.0.xsd -->
9
<!-- Extensions see: http://explain.z3950.org/dtd/extensions.html -->
10
11
<explain xmlns="http://explain.z3950.org/dtd/2.0/">
12
13
  <serverInfo protocol="[% IF ( config.protocol ) %][% config.protocol %][% ELSE %]SRW/SRU/Z39.50[% END %]" 
14
              version="2.0" 
15
              transport="[% IF ( config.transport ) %][% config.transport %][% ELSE %]http[% END %]">
16
    <host>[% host %]</host>
17
    <port>[% port %]</port>
18
    <database>biblios</database>
19
  </serverInfo>
20
21
  <databaseInfo>
22
23
    [% IF ( config.title ) -%]
24
        [%- FOREACH title IN config.title -%]
25
            <title lang="[% title.lang %]"[% IF ( title.primary ) %] primary="true"[% END %]>[% title.text %]</title>
26
        [% END -%]
27
    [% ELSE -%]
28
        <title lang="en" primary="true">Koha Bibliographic SRU/SRW/Z39.50 server</title>
29
    [% END -%]
30
31
    [%- IF ( config.description ) -%]
32
        [%- FOREACH description IN config.description -%]
33
            <description lang="[% description.lang %]"[% IF ( description.primary ) %] primary="true"[% END %]>[% description.text %]</description>
34
        [% END -%]
35
    [% ELSE -%]
36
        <description lang="en" primary="true">Koha Bibliographic Server</description>
37
    [% END -%]
38
39
    <author>
40
        [%- IF ( config.author ) -%]
41
            [%- config.author -%]
42
        [%- ELSIF ( Koha.Preference( 'LibraryName' ) != '' ) -%]
43
            [% Koha.Preference( 'LibraryName' ) -%]
44
        [%- ELSE -%]
45
            Koha
46
        [%- END -%]</author>
47
48
    <contact>
49
        [%- IF ( config.contact ) -%]
50
            [%- config.contact -%]
51
        [%- ELSIF ( Koha.Preference( 'KohaAdminEmailAddress' ) != '' ) -%]
52
            [%- Koha.Preference( 'KohaAdminEmailAddress' ) -%]
53
        [%- END -%]</contact>
54
55
    [% IF ( config.extent ) -%]
56
        [%- FOREACH extent IN config.extent -%]
57
            <extent lang="[% extent.lang %]"[% IF ( extent.primary ) %] primary="true"[% END %]>[% extent.text %]</extent>
58
        [% END -%]
59
    [% END -%]
60
61
    [% IF ( config.history ) -%]
62
        [%- FOREACH history IN config.history -%]
63
            <history lang="[% history.lang %]"[% IF ( history.primary ) %] primary="true"[% END %]>[% history.text %]</history>
64
        [% END -%]
65
    [% END -%]
66
67
    [% IF ( config.langUsage ) %]
68
        [% FOREACH lang IN config.langUsage %]
69
            <langUsage lang="[% lang.lang %]"[% IF ( lang.primary ) %] primary="true"[% END %][% IF ( lang.codes ) %] codes="[% lang.codes %]"[% END %]>[% lang.text %]</langUsage>
70
        [% END %]
71
    [% END %]
72
73
    [% IF ( config.restrictions ) -%]
74
        [%- FOREACH restriction IN config.restrictions -%]
75
            <restrictions lang="[% restriction.lang %]"[% IF ( restriction.primary ) %] primary="true"[% END %]>[% restriction.text %]</restrictions>
76
        [% END -%]
77
    [% END -%]
78
79
    [% IF ( config.subjects ) -%]
80
        <subjects>
81
            [% FOREACH sub IN config.subjects -%]
82
                <subject>[% sub %]</subject>
83
            [% END -%]
84
        </subjects>
85
    [% END %]
86
87
    <implementation identifier="zebra" version="2.0">
88
      <title>Index Data YAZ/ZEBRA http://www.indexdata.dk/zebra</title>
89
    </implementation>
90
    
91
    <links> 
92
      [% IF ( Koha.Preference( 'OPACBaseURL' ) ) %]<link type="www">[% Koha.Preference( 'OPACBaseURL' ) %]/</link>[% END %]
93
      <link type="z39.50">[% IF ( config.transport ) %][% config.transport %][% ELSE %]http[% END %]://[% host %]:[% port %]</link>
94
      <link type="srw">[% IF ( config.transport ) %][% config.transport %][% ELSE %]http[% END %]://[% host %]:[% port %]</link>
95
      <link type="sru">[% IF ( config.transport ) %][% config.transport %][% ELSE %]http[% END %]://[% host %]:[% port %]</link>
96
      [% IF ( Koha.Preference( 'OAI-PMH' ) ) %]<link type="oai">[% Koha.Preference( 'OPACBaseURL' ) %]/cgi-bin/koha/oai.pl</link>[% END %]
97
      [% IF ( Koha.Preference( 'OpacFavicon' ) ) %]<link type="icon">[% Koha.Preference( 'OpacFavicon' ) %]</link>[% END %]
98
    </links>
99
    
100
  </databaseInfo>
101
102
  <metaInfo>
103
    <dateModified>[% date.format %]</dateModified>
104
  </metaInfo>
105
106
  <indexInfo>
107
108
    [% FOREACH set IN pqf.sets -%]
109
        <set identifier="[% set.identifier %]" name="[% set.name %]"/>
110
    [% END -%]
111
112
    [% FOREACH index IN pqf.indexes %]
113
        <index search="true" scan="true" sort="false">
114
            [%- IF config.indexnames.${index.id} -%]
115
                [%- FOREACH this IN config.indexnames.${index.id} %]
116
                    <title lang="[% this.lang %]">[% this.title %]</title>
117
                [%- END %]
118
            [%- END %]
119
            <map><name set="[% index.set %]">[% index.index %]</name></map>
120
            <map primary="true">
121
                <attr type="[% index.type %]">[% index.value %]</attr>
122
            </map>
123
        </index>
124
    [% END -%]
125
126
  </indexInfo>
127
128
  <configInfo>
129
130
    <!-- searchRetrieve settings -->
131
132
    <!-- default context set -->
133
    <default type="contextSet">cql</default>
134
135
    <default type="index">all</default>
136
137
    <!-- default relation -->
138
    <default type="relation">=</default>
139
140
    <!-- relation supported by the server or index -->
141
    <supports type="relation">&lt;</supports> <!-- 2=1 OK -->
142
    <supports type="relation">&lt;=</supports> <!-- 2=2 OK -->
143
    <supports type="relation">=</supports> <!-- 2=3 OK -->
144
    <supports type="relation">&gt;=</supports> <!-- 2=4 OK -->
145
    <supports type="relation">&gt;</supports> <!-- 2=5 OK -->
146
    <!-- <supports type="relation">&lt;&gt;</supports> --><!-- 2=6 DEAD !!! -->
147
    <!-- <supports type="relation">all</supports> --><!-- 2=3 OK -->
148
    <!-- <supports type="relation">any</supports> --><!-- 2=3 OK -->
149
150
    <!-- relation modifier supported by the server or index -->
151
    <!-- <supports type="relationModifier">relevant</supports> --><!-- 2=102 OK, makes no difference .. sic -->
152
    <!-- <supports type="relationModifier">phonetic</supports> --> <!-- 2=100 DEAD -->
153
    <!-- <supports type="relationModifier">stem</supports> --> <!-- 2=101 DEAD !! -->
154
155
    <!-- support proximity (Empty) -->
156
    <!-- <supports type="proximity"></supports> --> <!-- DEAD,  title = (house prox/distance=1/unit=word  the) FAILS -->
157
158
    <!-- proximity modifier supported by the server or index 
159
         (relation, distance, unit, ordering) -->
160
    <!-- <supports type="proximityModifier"></supports> -->
161
162
    <!-- boolean modifier supported by the server or index -->
163
    <!-- <supports type="booleanModifier"></supports> -->
164
165
    <!-- masking character supported (* or ?) -->
166
    <supports type="maskingCharacter">*</supports>
167
    <supports type="maskingCharacter">?</supports>
168
169
    <!-- anchoring supported? (^ character) -->
170
    <!-- empty terms supported (Empty) -->
171
    <supports type="emptyTerm"></supports>
172
173
    <!-- sorting settings -->
174
175
    <!-- default schema used in sorting, in short name form -->
176
    <!-- <default type="sortSchema"></default> -->
177
    <!-- MIKE: deprecated -->
178
179
    <!-- server support sort -->
180
181
    <!-- supported sortmodifier (ascending, missingValue, caseSensitive) -->
182
    <!-- <supports type="sortModifier"></supports> -->
183
184
    <!-- presentation settings --> 
185
186
    <!-- default number of records that a server will return at once  -->
187
    <default type="numberOfRecords">0</default>
188
189
    <!-- default schema used for retrieved records -->
190
    <default type="retrieveSchema">index</default>
191
    <!-- default stylesheet URL, or if stylesheets are supported -->
192
    <setting type="stylesheet">docpath/sru.xsl</setting>
193
194
    <!-- default record packing returned (string or xml) -->
195
    <default type="recordPacking">xml</default>
196
197
    <!-- maximum number of records that a server will return at once -->
198
    <!-- <setting type="maximumRecords">1000</setting> -->
199
200
    <!-- support result sets (Empty) -->
201
    <!-- <supports type="resultSets"></supports>  --> 
202
203
    <!-- XPath retrieval supported -->
204
    <!-- <supports type="recordXPath"></supports> -->
205
206
    <!-- scan settings -->
207
208
    <!-- scan operation supported -->
209
    <supports type="scan"></supports>
210
211
    <!-- default number of terms to be returned in scan -->
212
    <default type="numberOfTerms">20</default>
213
214
    <!-- other server settings -->
215
216
    <!-- older version of the protocol supported  -->
217
    <!-- <supports type="version">1.1</supports> -->
218
219
    <!-- number of seconds that a result set will be maintained for -->
220
    <setting type="resultSetTTL">0</setting>
221
222
    <!-- A type of extraRequestData available in the
223
         searchRetrieveRequest. The extra*Data fields are represented as two
224
         space separated words, the first the identifier for the extension and
225
         the second the individual element name from the extension. If there is
226
         only one word, then it is the extension id and all elements from
227
         within are supported. -->
228
    <!-- <supports type="extraSearchData"></supports> -->
229
230
    <!-- A type of extraRequestData available in the explainRequest -->
231
    <!-- <supports type="extraExplainData"></supports> -->
232
233
    <!-- A type of extraRequestData available in the scanRequest -->
234
    <!-- <supports type="extraScanData"></supports> -->
235
    <!-- The URI identifier of a supported profile -->
236
    <!-- <supports type="profile"></supports> -->
237
  </configInfo>
238
   
239
</explain>
(-)a/misc/maintenance/generate_explain.pl (-1 / +302 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2017 Magnus Enger Libriotech
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head1 NAME
21
22
generate_explain.pl
23
24
=head1 SYNOPSIS
25
26
sudo koha-shell -c "perl generate_explain.pl -v" mykoha
27
28
sudo PERL5LIB=/usr/share/koha/lib KOHA_CONF=/etc/koha/sites/kohadev/koha-conf.xml perl generate_explain.pl -c /path/to/explain.yaml --overwrite -v
29
30
=head1 DESCRIPTION
31
32
Reads an optional config file, some of Koha's config files and generates an 
33
Explain document that can be served by the Zebra SRU server.
34
35
By default, the generated Explain document will be written to STDOUT. Specify
36
the --overwrite command line option to actually overwrite the existing Explain
37
document.
38
39
=cut
40
41
use File::Slurp;
42
use YAML::Syck qw( LoadFile );
43
use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
44
use XML::Simple;
45
use Modern::Perl;
46
use Getopt::Long;
47
use Pod::Usage;
48
use Data::Dumper; # Debug
49
50
use C4::Context;
51
use C4::Templates;
52
53
=head1 OPTIONS
54
55
=over 8
56
57
=item B<-c | --configfile>
58
59
Path to a configfile that should be used to generate parts of the Explain 
60
document.
61
62
=item B<--overwrite>
63
64
Actually overwrite the existing explain document. If this is not specified, the
65
generated Explain document will be written to STDOUT and no files will be
66
overwritten.
67
68
=item B<-h | --help>
69
70
Print this usage statement.
71
72
=item B<-v | --verbose>
73
74
More verbose output.
75
76
=back
77
78
=cut
79
80
my ( $configfile, $overwrite, $help, $verbose );
81
GetOptions(
82
    'c|configfile=s'  => \$configfile,
83
    'o|overwrite'     => \$overwrite,
84
    'h|help'          => \$help,
85
    'v|verbose'       => \$verbose,
86
);
87
88
if ( $help ) {
89
    pod2usage( -verbose => 2 );
90
    exit;
91
}
92
93
=head1 CONFIG FILE
94
95
The config file should be in YAML format. Here is an example config that shows
96
all the available options. See http://zeerex.z3950.org/dtd/commentary.html for
97
further details about the options.
98
99
    ---
100
    # Protocol
101
    # Default: SRW/SRU/Z39.50
102
    protocol: "SRU"
103
104
    # Transport
105
    # Default: http
106
    transport: "https"
107
108
    # Title
109
    # Should have a two letter language code.
110
    # One title can be marked as primary
111
    title:
112
        - text: This is some title
113
          lang: en
114
          primary: true
115
        - text: Dette er en tittel
116
          lang: nb
117
118
    # Description
119
    # Should have a two letter language code.
120
    # One description can be marked as primary
121
    description:
122
        - text: This is some description
123
          lang: en
124
          primary: true
125
        - text: Dette er en beskrivelse
126
          lang: nb
127
128
    # Author
129
    # If author is not set in the config, the LibraryName syspref will be used. If
130
    # that is not set, the string "Koha" will be used.
131
    author: "The librarian"
132
133
    # Contact
134
    # If the contact is not set in the config, the KohaAdminEmailAddress syspref
135
    # will be used.
136
    contact: "librarian@example.org"
137
138
    # Extent
139
    extent: 
140
        - text: "This is the extent of the database."
141
          lang: "en"
142
          primary: "true"
143
144
    # History
145
    history: 
146
        - text: "This is the history of the database."
147
          lang: "en"
148
          primary: "true"
149
150
    # langUsage
151
    langUsage: 
152
        - text: "Records are in English and Norwegian"
153
          codes: "en nb"
154
          lang: "en"
155
          primary: "true"
156
157
    # Restrictions
158
    restrictions: 
159
        - text: "Free for all!"
160
          lang: "en"
161
          primary: "true"
162
163
    # Subjects
164
    subjects: 
165
        - "Subject A"
166
        - "Subject B"
167
168
    # Index names
169
    # Indexes can be given more explanatory names, but this is optional.
170
    indexnames:
171
        dc_title:
172
          - title: "Title"
173
            lang: "en"
174
          - title: "Tittel"
175
            lang: "nb"
176
        dc_subject:
177
          - title: "Subject"
178
            lang: "en"
179
        rec_identifier:
180
          - title: "Record identifier"
181
            lang: "en"
182
183
=cut
184
185
# Load the config file, if one is specified
186
my $config;
187
if ( $configfile ) {
188
    if ( -e $configfile ) {
189
        say "Reading config from $configfile" if $verbose;
190
        $config = LoadFile( $configfile );
191
    } else {
192
        die "$configfile not found";
193
    }
194
}
195
196
# Get the path to he Koha config file from the KOHA_CONF environment variable
197
my $koha_conf = $ENV{ 'KOHA_CONF' };
198
say "Looking at $koha_conf" if $verbose;
199
200
# Read the Koha config file
201
my $conf = XMLin(
202
    $koha_conf,
203
    keyattr => ['id'],
204
    forcearray => ['listen', 'server', 'serverinfo'],
205
    suppressempty => ''
206
);
207
208
# Get the SRU host and port from the Koha config file
209
my $publicserver = $conf->{'listen'}->{'publicserver'}->{'content'};
210
my ( $tcp, $host, $port ) = split /:/, $publicserver;
211
say "SRU is listening on port $port" if $verbose;
212
213
# Find the path to pqf.properties file
214
my $pqf_properties_file = $conf->{'server'}->{'publicserver'}->{'cql2rpn'};
215
say "Looking at $pqf_properties_file" if $verbose;
216
217
# Read the pqf.properties file, and extract the information we need
218
my %pqf;
219
my @lines = read_file( $pqf_properties_file );
220
foreach my $line ( @lines ) {
221
222
    # Remove trailing whitespace
223
    chomp $line;
224
    # Skip commented lines - start of line, zero or more spaces, comment sign
225
    next if $line =~ m/^ {0,}#/;
226
    # Skip empty lines - start of line, zero or more spaces, end of line
227
    next if $line =~ m/^ {0,}$/;
228
229
    # Look for lines that start with "set."
230
    if ( $line =~ m/^set\.(.*?) {0,}= {0,}(.*)/ ) {
231
        push @{ $pqf{'sets'} }, { 
232
            'name' => $1,
233
            'identifier' => $2,
234
        };
235
    }
236
237
    # Look for lines that start with "index."
238
    if ( $line =~ m/^index\.(.*?)\.(.*?) {0,}= (.*?)=(.*?) {0,}$/ ) {
239
        push @{ $pqf{'indexes'} }, {
240
            'set'   => $1,
241
            'index' => $2,
242
            'id'    => "$1_$2",
243
            'type'  => $3,
244
            'value' => $4,
245
        };
246
    }
247
248
}
249
250
# Set up the template
251
my $template = C4::Templates::gettemplate(
252
    'services/explain-biblios.tt',
253
    'intranet',
254
    new CGI
255
);
256
257
# Pass some values to the template
258
$template->param(
259
    'config' => $config,
260
    'pqf'    => \%pqf,
261
    'host'   => $host,
262
    'port'   => $port,
263
);
264
265
# Get the output from the template
266
my $output = $template->output;
267
if ( $overwrite ) {
268
    # Find the path to the Explain doc
269
    my $explain_doc;
270
    foreach my $inc ( @{ $conf->{'server'}->{'publicserver'}->{'xi:include'} } ) {
271
        my $href = $inc->{'href'};
272
        if ( $href =~ m/explain/ ) {
273
            $explain_doc = $href;
274
        }
275
    }
276
    say "Going to write to $explain_doc" if $verbose;
277
    # Make a backup of the existing file
278
    rename $explain_doc, "$explain_doc-old";
279
    # Do the actual write
280
    write_file( $explain_doc, $output );
281
} else {
282
    say $output;
283
}
284
285
=head1 AUTHOR
286
287
Magnus Enger, <magnus [at] libriotech.no>
288
289
=head1 LICENSE
290
291
    This program is free software: you can redistribute it and/or modify
292
    it under the terms of the GNU General Public License as published by
293
    the Free Software Foundation, either version 3 of the License, or
294
    (at your option) any later version.
295
    This program is distributed in the hope that it will be useful,
296
    but WITHOUT ANY WARRANTY; without even the implied warranty of
297
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
298
    GNU General Public License for more details.
299
    You should have received a copy of the GNU General Public License
300
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
301
302
=cut

Return to bug 12836