From f3ff3144242923509b06e84cd2af051860c877f0 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 14 Sep 2014 17:49:41 -0400 Subject: [PATCH 1/1] Add some "smarts" to _problem_from_event in NCIP::ILS::Evergreen. Signed-off-by: Jason Stephenson --- lib/NCIP/ILS/Evergreen.pm | 55 ++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/lib/NCIP/ILS/Evergreen.pm b/lib/NCIP/ILS/Evergreen.pm index 4766ca7..3cb590b 100644 --- a/lib/NCIP/ILS/Evergreen.pm +++ b/lib/NCIP/ILS/Evergreen.pm @@ -1818,23 +1818,60 @@ sub _expired { } # Creates a NCIP Problem from an event. Takes a string for the problem -# type, the event hashref, and optional arguments for the -# ProblemElement and ProblemValue fields. +# type, the event hashref (or a string to use for the detail), and +# optional arguments for the ProblemElement and ProblemValue fields. sub _problem_from_event { my ($type, $evt, $element, $value) = @_; my $detail; - # This block will likely need to get smarter in the near future. - if ($evt) { - if ($evt->{textcode} eq 'PERM_FAILURE') { - $detail = 'Permission Failure: ' . $evt->{ilsperm}; - $detail =~ s/\.override$//; + # Check the event. + if (ref($evt)) { + my ($textcode, $desc); + + # Get the textcode, if available. We favor those defined in + # ils_events.xml over those made up on the fly. + if ($evt->{ilsevent} && $evt->{ilsevent}->{textcode}) { + $textcode = $evt->{ilsevent}->{textcode}; + } elsif ($evt->{textcode}) { + $textcode = $evt->{textcode}; + } + + # Get the description. We favor translated descriptions over + # the English in ils_events.xml. + if ($evt->{desc}) { + $desc = $evt->{desc}; + } elsif ($evt->{ilsevent} && $evt->{ilsevent}->{desc}) { + $desc = $evt->{ilsevent}->{desc}; + } + + # Check if $type was set. As an "undocumented" feature, you + # can pass undef, and we'll use the textcode from the event. + unless ($type) { + if ($textcode) { + $type = $textcode; + } else { + # Because we have to give them something. + $type = 'Temporary Processing Failure'; + } + } + + # Set the detail from some combination of the above. + if ($desc) { + $detail = $desc; + } elsif ($textcode eq 'PERM_FAILURE') { + if ($evt->{ilsperm}) { + $detail = "Permission denied: " . $evt->{ilsperm}; + $detail =~ s/\.override$//; + } + } elsif ($textcode) { + $detail = "ILS returned $textcode error."; } else { - $detail = 'ILS returned ' . $evt->{textcode} . ' error.'; + $detail = 'Detail not available.'; } + } else { - $detail = 'Detail not available.'; + $detail = $evt; } return NCIP::Problem->new( -- 2.43.2