1 # ---------------------------------------------------------------
2 # Copyright (C) 2016 Equinox Software, Inc.
3 # Mike Rylander <mrylander@gmail.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 # ---------------------------------------------------------------
17 package OpenILS::Application::Circ::CircNotify;
18 use base qw/OpenILS::Application/;
19 use strict; use warnings;
20 use OpenSRF::EX qw(:try);
21 use vars q/$AUTOLOAD/;
23 use OpenSRF::Utils::JSON;
24 use OpenSRF::Utils::Logger qw(:logger);
25 use OpenILS::Utils::CStoreEditor q/:funcs/;
26 use OpenSRF::Utils::SettingsClient;
27 use OpenILS::Application::AppUtils;
28 use OpenILS::Const qw/:const/;
29 use OpenILS::Utils::Fieldmapper;
30 use OpenSRF::MultiSession;
33 use OpenSRF::EX qw/:try/;
34 my $U = 'OpenILS::Application::AppUtils';
38 sub circ_batch_notify {
39 my ($self, $client, $auth, $patronid, $circlist) = @_;
40 my $e = new_editor(authtoken => $auth);
41 return $e->event unless $e->checkauth;
42 return $e->event unless $e->allowed('STAFF_LOGIN');
44 my $circs = $e->search_action_circulation({ id => $circlist });
45 return $e->event if $e->event;
47 my $hook = 'circ.checkout.batch_notify';
48 $hook .= '.session' if $self->api_name =~ /session/;
50 for my $circ (@$circs) {
51 # WISHLIST: This may become more sophisticated and check "friend" permissions
52 # in the future, at lease in the non-session variant.
53 return OpenILS::Event->new('PATRON_CIRC_MISMATCH') if $circ->usr != $patronid;
54 return $e->event unless $e->allowed('VIEW_CIRCULATIONS', $circ->circ_lib);
58 my $multi = OpenSRF::MultiSession->new(
59 app => 'open-ils.trigger',
61 success_handler => sub {
65 return unless $req->{response}->[0];
66 my $event = $req->{response}->[0]->content;
68 $event = $e->retrieve_action_trigger_event($event);
71 $events{$event->event_def} ||= [];
72 push @{$events{$event->event_def}}, $event->id;
77 'open-ils.trigger.event.autocreate.ignore_opt_in',
78 $hook => $_ => $e->requestor->ws_ou
80 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
82 $multi->session_wait(1);
83 $client->status( new OpenSRF::DomainObject::oilsContinueStatus );
86 return $client->respond_complete;
89 $multi = OpenSRF::MultiSession->new(
90 app => 'open-ils.trigger',
92 success_handler => sub {
96 return unless $req->{response}->[0];
97 $client->respond( $req->{response}->[0]->content );
102 'open-ils.trigger.event_group.fire',
104 ) for ( sort keys %events );
106 $multi->session_wait(1);
107 return $client->respond_complete;
109 __PACKAGE__->register_method(
110 method => 'circ_batch_notify',
111 api_name => 'open-ils.circ.checkout.batch_notify',
114 desc => 'Creates and fires grouped events for a set of circulation IDs',
116 { name => 'authtoken', desc => 'Staff auth token', type => 'string' },
117 { name => 'patronid', desc => 'actor.usr.id of patron which must own the circulations', type => 'number' },
118 { name => 'circlist', desc => 'Arrayref of circulation IDs to bundle into the event group', type => 'array' }
121 desc => 'Event on error, stream of zero or more event group firing results '.
122 'otherwise. See: open-ils.trigger.event_group.fire'
126 __PACKAGE__->register_method(
127 method => 'circ_batch_notify',
128 api_name => 'open-ils.circ.checkout.batch_notify.session',
131 desc => 'Creates and fires grouped events for a set of circulation IDs. '.
132 'For use by session-specific actions such as self-checkout or circ desk checkout.',
134 { name => 'authtoken', desc => 'Staff auth token', type => 'string' },
135 { name => 'patronid', desc => 'actor.usr.id of patron which must own the circulations', type => 'number' },
136 { name => 'circlist', desc => 'Arrayref of circulation IDs to bundle into the event group', type => 'array' }
139 desc => 'Event on error, stream of zero or more event group firing results '.
140 'otherwise. See: open-ils.trigger.event_group.fire'