Bug 33270: Attempt to recover from invalid metadata exception
authorNick Clemens <nick@bywatersolutions.com>
Thu, 22 Jun 2023 11:22:18 +0000 (11:22 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 18 Jul 2023 15:46:57 +0000 (12:46 -0300)
commitc71468537b4fa589e91e7fd5823ddd4f54379e21
tree4fcc0ba88b16e88a6de5061f4c5cbd31fca7b187
parent4997d59c83ec1c63a3dc2c089fed79e3ad5fa764
Bug 33270: Attempt to recover from invalid metadata exception

This patch uses the new record_strip_nonxml routine to attempt to display
the record when it contains invalid characters

Rather than silently strippg these, we warn in the logs, then add an 'about'
container to the response. It is displayed nicely in the web view or sent as "INVALID_METADATA" in
the xml response

The 'error' codes for OAI seem to be at the request level, and the offered codes don't have a match
for a bad record. Adding the about when we can recover seems the most generous response

To test:
Test plan, assumes using KTD default data - otherwise you need to find and import a record with encoding issues:
 1 - Enable OAI-PMH system preference
 2 - Browse to:
    http://localhost:8080/cgi-bin/koha/oai.pl?verb=ListRecords&resumptionToken=marcxml/350////0/0/352
 3 - 500 error:
    Invalid data, cannot decode metadata object (biblio_metadata.id=368, biblionumber=369, format=marcxml, schema=MARC21, decoding_error=':8: parser error : PCDATA invalid Char value 31...
 4 - Apply patch, restart all
 5 - Reload the page
 6 - It loads!
 7 - Click 'Metadata' for record 369 - it succeeds!
 8 - Check the logs - confirm you see a warning of the record problem
 9 - Confirm 369 has an about section
10 - Check the individul 'GetRecord' response as well
    http://localhost:8080/cgi-bin/koha/oai.pl?verb=GetRecord&metadataPrefix=oai_dc&identifier=KOHA-OAI-TEST:369

Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/OAI/Server/GetRecord.pm
Koha/OAI/Server/ListBase.pm
Koha/OAI/Server/Repository.pm
koha-tmpl/opac-tmpl/xslt/OAI.xslt