Bugzilla – Attachment 30194 Details for
Bug 6536
Z3950 Search Enhancements: SRU targets and additional XSLT processing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 6536: Add XSLT transformation on Z3950 search results
Bug-6536-Add-XSLT-transformation-on-Z3950-search-r.patch (text/plain), 8.52 KB, created by
Marcel de Rooy
on 2014-07-28 10:47:21 UTC
(
hide
)
Description:
Bug 6536: Add XSLT transformation on Z3950 search results
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2014-07-28 10:47:21 UTC
Size:
8.52 KB
patch
obsolete
>From 3b43cfcaa7b84c3e5ec645934f174c21e6ca5ea5 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 10 Jul 2014 17:21:21 +0200 >Subject: [PATCH] Bug 6536: Add XSLT transformation on Z3950 search results >Content-Type: text/plain; charset=utf-8 > >Use the stylesheets listed in field add_xslt of z3950servers to transform >search results of Z3950/SRU search. >Additionally, the template has been changed to make more error messages (or >warnings) visible when displaying results. Until now, error message were >shown in the results table and when connection errors occurred, no results >were displayed at all. > >Test plan: >Create some stylesheets (or see the sample patch on bug 6536). >Add these stylesheets to some Z3950/SRU servers. >Do Z3950 search and verify the transformations. >Do a search with 2 targets; make one target fail (by manipulating its server >data). Do you see the connection error and the results for the other target? >Generate a XSLT error by modifying one stylesheet. Check search results. You >should see warnings. > >Signed-off-by: Giuseppe Angilella <giuseppe.angilella@ct.infn.it> >--- > C4/Breeding.pm | 45 +++++++++++++++++--- > .../prog/en/modules/cataloguing/z3950_search.tt | 31 +++++++------ > 2 files changed, 56 insertions(+), 20 deletions(-) > >diff --git a/C4/Breeding.pm b/C4/Breeding.pm >index 2001fa5..7125cb2 100644 >--- a/C4/Breeding.pm >+++ b/C4/Breeding.pm >@@ -27,7 +27,9 @@ use C4::Charset; > use MARC::File::USMARC; > use C4::ImportBatch; > use C4::AuthoritiesMarc; #GuessAuthTypeCode, FindDuplicateAuthority >+use C4::Languages; > use Koha::Database; >+use Koha::XSLT_Handler; > > use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); > >@@ -164,6 +166,7 @@ sub Z3950Search { > _translate_query( $server, $squery ))); > $s++; > } >+ my $xslh = Koha::XSLT_Handler->new; > > my $nremaining = $s; > while ( $nremaining-- ) { >@@ -185,17 +188,19 @@ sub Z3950Search { > else { > my $numresults = $oResult[$k]->size(); > my $i; >- my $result = ''; >+ my $res; > if ( $numresults > 0 and $numresults >= (($page-1)*20)) { > $show_next = 1 if $numresults >= ($page*20); > $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20); > for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) { >- if($oResult[$k]->record($i)) { >- my $res=_handle_one_result($oResult[$k]->record($i), $servers[$k], ++$imported, $biblionumber); #ignores error in sequence numbering >+ if ( $oResult[$k]->record($i) ) { >+ undef $error; >+ ( $res, $error ) = _handle_one_result( $oResult[$k]->record($i), $servers[$k], ++$imported, $biblionumber, $xslh ); #ignores error in sequence numbering > push @breeding_loop, $res if $res; >+ push @errconn, { server => $servers[$k]->{servername}, error => $error, seq => $i+1 } if $error; > } > else { >- push(@breeding_loop,{'server'=>$servers[$k]->{servername},'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1}); >+ push @errconn, { 'server' => $servers[$k]->{servername}, error => ( ( $oConnection[$k]->error_x() )[0] ), seq => $i+1 }; > } > } > } #if $numresults >@@ -258,7 +263,7 @@ sub _build_query { > } > > sub _handle_one_result { >- my ($zoomrec, $servhref, $seq, $bib)= @_; >+ my ( $zoomrec, $servhref, $seq, $bib, $xslh )= @_; > > my $raw= $zoomrec->raw(); > my $marcrecord; >@@ -269,6 +274,8 @@ sub _handle_one_result { > ($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encoding} // "iso-5426" ); #ignores charset return values > } > SetUTF8Flag($marcrecord); >+ my $error; >+ ( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh); > > my $batch_id = GetZ3950BatchId($servhref->{servername}); > my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0); >@@ -279,12 +286,38 @@ sub _handle_one_result { > > #call to TransformMarcToKoha replaced by next call > #we only need six fields from the marc record >- return _add_rowdata( >+ my $row; >+ $row = _add_rowdata( > { > biblionumber => $bib, > server => $servhref->{servername}, > breedingid => $breedingid, > }, $marcrecord) if $breedingid; >+ return ( $row, $error ); >+} >+ >+sub _do_xslt_proc { >+ my ( $marc, $server, $xslh ) = @_; >+ return $marc if !$server->{add_xslt}; >+ >+ my $htdocs = C4::Context->config('intrahtdocs'); >+ my $theme = C4::Context->preference("template"); #staff >+ my $lang = C4::Languages::getlanguage() || 'en'; >+ >+ my @files= split ',', $server->{add_xslt}; >+ my $xml = $marc->as_xml; >+ foreach my $f ( @files ) { >+ $f =~ s/^\s+//; $f =~ s/\s+$//; next if !$f; >+ $f = C4::XSLT::_get_best_default_xslt_filename( >+ $htdocs, $theme, $lang, $f ) unless $f =~ /^\//; >+ $xml = $xslh->transform( $xml, $f ); >+ last if $xslh->err; #skip other files >+ } >+ if( !$xslh->err ) { >+ return MARC::Record->new_from_xml($xml, 'UTF-8'); >+ } else { >+ return ( $marc, 'xslt_err' ); #original record in case of errors >+ } > } > > sub _add_rowdata { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt >index 6ae50ce..c25c2f1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt >@@ -148,6 +148,21 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color : > > [% ELSE %] > <h2>Results</h2> >+ >+ [% IF ( errconn ) %] >+ <div class="dialog alert"> >+ <ul> >+ [% FOREACH errcon IN errconn %] >+ [% IF ( errcon.error == '10000' ) %]<li>Connection failed to [% errcon.server %]</li> >+ [% ELSIF ( errcon.error == '10007' ) %]<li>Connection timeout to [% errcon.server %]</li> >+ [% ELSIF ( errcon.error == 'xslt_err' ) %]<li>[% errcon.server %]: Warning: XSLT error on search result [% errcon.seq %]</li> >+ [% ELSE %]<li>[% errcon.server %] record [% errcon.seq %]: [% errcon.error %]</li> >+ [% END %] >+ [% END %] >+ </ul> >+ </div> >+ [% END %] >+ > [% IF ( breeding_loop ) %] > <table id="resultst"> > <thead> <tr> >@@ -210,22 +225,10 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color : > <br />Go to page : <input id="goto_page" name="goto_page" value="[% current_page %]" size="4" /><input type="submit" name="changepage_goto" onclick="return validate_goto_page();" value="Go" /> > </form> > >-<p><form method="get" action="/cgi-bin/koha/cataloguing/z3950_search.pl"><input type="hidden" name="biblionumber" value="[% biblionumber %]"/><input type="hidden" name="frameworkcode" value="[% frameworkcode %]"/><input type="submit" value="Try Another Search"/></form></p> > [% ELSE %] >- [% IF ( errconn ) %] >- <div class="dialog alert"> >- <ul> >- [% FOREACH errcon IN errconn %] >- [% IF ( errcon.error == '10000' ) %]<li>Connection failed to [% errcon.server %]</li> >- [% ELSIF ( errcon.error == '10007' ) %]<li>Connection timeout to [% errcon.server %]</li>[% END %] >- [% END %] >- </ul> >- </div> >- [% END %] >- <div class="dialog message">Nothing found.</div> >- <p><form method="get" action="/cgi-bin/koha/cataloguing/z3950_search.pl"><input type="hidden" name="biblionumber" value="[% biblionumber %]"/><input type="hidden" name="frameworkcode" value="[% frameworkcode %]"/><input type="submit" value="Try Another Search"/></form></p> >+ <div class="dialog message">Nothing found.</div> > [% END %] >- >+<p><form method="get" action="/cgi-bin/koha/cataloguing/z3950_search.pl"><input type="hidden" name="biblionumber" value="[% biblionumber %]"/><input type="hidden" name="frameworkcode" value="[% frameworkcode %]"/><input type="submit" value="Try Another Search"/></form></p> > > [% END %] > >-- >1.7.7.6
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 6536
:
4540
|
4541
|
4959
|
6901
|
6919
|
6920
|
6924
|
13462
|
26169
|
26170
|
26171
|
26172
|
29754
|
29755
|
29756
|
29779
|
29780
|
29788
|
29790
|
29791
|
29812
|
29813
|
29814
|
29815
|
29816
|
29817
|
29818
|
29819
|
30189
|
30190
|
30191
|
30192
|
30193
|
30194
|
30900
|
30901
|
30902
|
30903
|
30904
|
30905
|
30906
|
30907
|
30929
|
30930
|
30931
|
30932
|
30933
|
30934
|
30935
|
30936
|
31046
|
31048
|
31137
|
31193
|
31194
|
31195
|
31227
|
31247
|
31248
|
37264