From fa26d7acd1f1c29f7df8b814d871e32e4e0aefb7 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 4 Dec 2012 16:06:32 -0500 Subject: [PATCH] csv reactor Signed-off-by: Bill Erickson --- .../lib/OpenILS/Application/Trigger/Reactor.pm | 21 ++++++ .../Application/Trigger/Reactor/NotifyCSV.pm | 46 +++++++++++++ itiva_pusher.pl | 5 ++ notify-csv.tt2 | 76 ++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/NotifyCSV.pm create mode 100644 itiva_pusher.pl create mode 100644 notify-csv.tt2 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm index a56a2cd9fe..d53a52dad2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm @@ -98,6 +98,12 @@ $_TT_helpers = { return $U->get_copy_price(new_editor(xact=>1), $copy_id); }, + get_org_unit => sub { + my $org_id = shift; + return $org_id if ref $org_id; + return new_editor()->get_actor_org_unit($org_id); + }, + # given a copy, returns the title and author in a hash get_copy_bib_basics => sub { my $copy_id = shift; @@ -165,6 +171,14 @@ $_TT_helpers = { return $U->ou_ancestor_setting_value($org_id, $setting); }, + get_user_setting => sub { + my ($user_id, $setting) = @_; + my $val = new_editor()->search_actor_user_setting( + {usr => $user_id, name => $setting})->[0]; + return undef unless $val; + return OpenSRF::Utils::JSON->JSON2perl($val->value); + }, + # This basically greps/maps out ths isbn string values, but also promotes the first isbn-13 to the # front of the line (so that the EDI translator takes it as primary) if there is one. get_li_isbns => sub { @@ -351,6 +365,13 @@ $_TT_helpers = { my $unapi = new_editor()->json_query($query); return undef unless @$unapi; return $_TT_helpers->{xml_doc}->($unapi->[0]->{'unapi.bre'}); + }, + + # escapes quotes in csv string values + escape_csv => sub { + my $string = shift; + $string =~ s/"/""/og; + return $string; } }; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/NotifyCSV.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/NotifyCSV.pm new file mode 100644 index 0000000000..c4fd23f78b --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/NotifyCSV.pm @@ -0,0 +1,46 @@ +package OpenILS::Application::Trigger::Reactor::NotifyCSV; +use base "OpenILS::Application::Trigger::Reactor"; +use strict; use warnings; + +sub ABOUT { + return q| +Creates a CSV representation of patron actions for the purposes of notifying +the patron via external notification mechanisms. + +Event Environment Requirements + +* patron object with card +* org unit + +Required Event Parameters + +notify_media (e.g. phone) +notify_type (e.g. overdue) +notify_level (e.g. "1" -- first overdue) + +The set of options for each event parameter is dependent on the 3rd-party +processing the CSV file. Using iTiva as the reference implementation, event +parameter values options include: + +notify_media : 'V' (voice), 'T' (text) +notify_level : '1' (1st notice), '2' (2nd notice...) , '3' +notify_type : + 'FINES', + 'OVERDUE', + 'PREOVERDUE', + 'PRERESERVE', + 'RECALL', + 'RESERVE', + 'RESERVECANCEL', + 'RESERVEEXPIRE', + 'SUSPEND' +|; +} + +sub handler { + my ($self, $env) = @_; + return 1 if $self->run_TT($env); + return 0; +} + +1; diff --git a/itiva_pusher.pl b/itiva_pusher.pl new file mode 100644 index 0000000000..b923a7fff8 --- /dev/null +++ b/itiva_pusher.pl @@ -0,0 +1,5 @@ + + +my $header = <