3 -- Build the event defintions, environment, and params, then apply the same
4 -- template to all CSV definitions.
6 -- All definitions assume a notify media of "V" (voice).
8 ---------------------------------------------------
10 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
11 validator, reactor, delay, delay_field, group_field, template, granularity)
13 'f', '1st Overdue CSV', 1, 'checkout.due','CircIsOverdue',
14 'ProcessTemplate', '7 days', 'due_date', 'usr', '', 'notify-csv'
17 INSERT INTO action_trigger.environment (event_def, path) VALUES
18 (currval('action_trigger.event_definition_id_seq'), 'circ_lib'),
19 (currval('action_trigger.event_definition_id_seq'), 'target_copy'),
20 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
23 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
24 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
25 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'),
26 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''OVERDUE''')
29 ---------------------------------------------------
31 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
32 validator, reactor, delay, delay_field, group_field, template, granularity)
34 'f', '2nd Overdue CSV', 1, 'checkout.due','CircIsOverdue',
35 'ProcessTemplate', '14 days', 'due_date', 'usr', '', 'notify-csv'
38 INSERT INTO action_trigger.environment (event_def, path) VALUES
39 (currval('action_trigger.event_definition_id_seq'), 'circ_lib'),
40 (currval('action_trigger.event_definition_id_seq'), 'target_copy'),
41 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
44 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
45 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
46 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '2'),
47 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''OVERDUE''')
50 ---------------------------------------------------
52 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
53 validator, reactor, delay, delay_field, group_field, template, granularity)
55 'f', '3rd Overdue CSV', 1, 'checkout.due','CircIsOverdue',
56 'ProcessTemplate', '28 days', 'due_date', 'usr', '', 'notify-csv'
59 INSERT INTO action_trigger.environment (event_def, path) VALUES
60 (currval('action_trigger.event_definition_id_seq'), 'circ_lib'),
61 (currval('action_trigger.event_definition_id_seq'), 'target_copy'),
62 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
65 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
66 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
67 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '3'),
68 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''OVERDUE''')
71 ---------------------------------------------------
73 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
74 validator, reactor, delay, delay_field, group_field, template, granularity)
76 'f', '3-Day Predue CSV', 1, 'checkout.due','CircIsOpen',
77 'ProcessTemplate', '-3 days', 'due_date', 'usr', '', 'notify-csv'
80 INSERT INTO action_trigger.environment (event_def, path) VALUES
81 (currval('action_trigger.event_definition_id_seq'), 'circ_lib'),
82 (currval('action_trigger.event_definition_id_seq'), 'target_copy'),
83 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
86 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
87 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
88 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'),
89 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''PREOVERDUE''')
92 ---------------------------------------------------
93 -- hold ready for pickup
94 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
95 validator, reactor, delay, delay_field, group_field, template, granularity)
97 'f', 'Hold Ready CSV', 1, 'hold.available','HoldIsAvailable',
98 'ProcessTemplate', '30 minutes', 'shelf_time', 'usr', '', 'notify-csv'
101 INSERT INTO action_trigger.environment (event_def, path) VALUES
102 (currval('action_trigger.event_definition_id_seq'), 'pickup_lib'),
103 (currval('action_trigger.event_definition_id_seq'), 'current_copy'),
104 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
107 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
108 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
109 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'),
110 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''RESERVE''')
113 ---------------------------------------------------
114 -- hold expires on shelf soon
115 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
116 validator, reactor, delay, delay_field, group_field, template, granularity)
118 'f', 'Hold Expires On Shelf Soon CSV', 1,
119 'hold_request.shelf_expires_soon',
120 'HoldIsAvailable', 'ProcessTemplate', '-1 days',
121 'shelf_expire_time', 'usr', '', 'notify-csv'
124 INSERT INTO action_trigger.environment (event_def, path) VALUES
125 (currval('action_trigger.event_definition_id_seq'), 'pickup_lib'),
126 (currval('action_trigger.event_definition_id_seq'), 'current_copy'),
127 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
130 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
131 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
132 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '2'),
133 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''PRERESERVE''')
136 ---------------------------------------------------
137 -- hold expired on shelf
138 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
139 validator, reactor, delay, delay_field, group_field, template, granularity)
141 'f', 'Hold Expired On Shelf CSV', 1,
142 'hold_request.cancel.expire_holds_shelf',
143 'HoldIsCancelled', 'ProcessTemplate', '30 minutes',
144 'cancel_time', 'usr', '', 'notify-csv'
147 INSERT INTO action_trigger.environment (event_def, path) VALUES
148 (currval('action_trigger.event_definition_id_seq'), 'pickup_lib'),
149 (currval('action_trigger.event_definition_id_seq'), 'current_copy'),
150 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
153 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
154 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
155 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'),
156 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''RESERVEEXPIRE''')
159 ---------------------------------------------------
161 -- see also hooks hold_request.cancel.staff and
162 -- hold_request.cancel.patron
163 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
164 validator, reactor, delay, delay_field, group_field, template, granularity)
166 'f', 'Hold Cancelled (no target) CSV', 1,
167 'hold_request.cancel.expire_no_target',
168 'HoldIsCancelled', 'ProcessTemplate', '30 minutes',
169 'cancel_time', 'usr', '', 'notify-csv'
172 INSERT INTO action_trigger.environment (event_def, path) VALUES
173 (currval('action_trigger.event_definition_id_seq'), 'pickup_lib'),
174 (currval('action_trigger.event_definition_id_seq'), 'current_copy'),
175 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
178 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
179 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
180 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'),
181 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''RESERVECANCEL''')
184 ---------------------------------------------------
186 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
187 validator, reactor, delay, delay_field, group_field, template, granularity)
189 'f', 'Copy Recall CSV', 1,
190 'circ.recall.target',
191 'NOOP_True', 'ProcessTemplate', DEFAULT,
192 NULL, 'usr', '', 'notify-csv'
195 INSERT INTO action_trigger.environment (event_def, path) VALUES
196 (currval('action_trigger.event_definition_id_seq'), 'circ_lib'),
197 (currval('action_trigger.event_definition_id_seq'), 'target_copy'),
198 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
201 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
202 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
203 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'),
204 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''RECALL''')
207 ---------------------------------------------------
208 -- patron exceeds fines threshold
209 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
210 validator, reactor, delay, delay_field, group_field, template, granularity)
212 'f', 'Patron Exceeds Fines CSV', 1,
213 'penalty.PATRON_EXCEEDS_FINES',
214 'NOOP_True', 'ProcessTemplate', DEFAULT,
215 NULL, 'usr', '', 'notify-csv'
218 INSERT INTO action_trigger.environment (event_def, path) VALUES
219 (currval('action_trigger.event_definition_id_seq'), 'org_unit'),
220 (currval('action_trigger.event_definition_id_seq'), 'usr.card')
223 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
224 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
225 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'),
226 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''FINES''')
229 ---------------------------------------------------
231 INSERT INTO action_trigger.event_definition (active, name, owner, hook,
232 validator, reactor, delay, delay_field, group_field, template, granularity)
234 'f', 'Patron Barred CSV', 1,
236 'PatronBarred', 'ProcessTemplate', DEFAULT,
237 NULL, NULL, '', 'notify-csv'
240 INSERT INTO action_trigger.environment (event_def, path) VALUES
241 (currval('action_trigger.event_definition_id_seq'), 'home_ou'),
242 (currval('action_trigger.event_definition_id_seq'), 'card')
245 INSERT INTO action_trigger.event_params (event_def, param, value) VALUES
246 (currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''),
247 (currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'),
248 (currval('action_trigger.event_definition_id_seq'), 'notify_type', '''SUSPEND''')
253 ---------------------------------------------------
254 -- apply the generic CVS template to all event defs
255 UPDATE action_trigger.event_definition SET template = $$
259 # accommodate grouped events
260 SET event = event.0 UNLESS event.id;
261 SET target = [target] UNLESS event.event_def.group_field;
263 core_type = event.event_def.hook.core_type;
264 notice_org_unit = helpers.get_org_unit(event.event_def.owner);
266 FOR target_obj IN target;
268 # Mangle the data into a consistent shape
277 IF core_type == 'circ';
281 copy = circ.target_copy;
282 org_unit = circ.circ_lib;
283 date_info = circ.due_date;
285 ELSIF core_type == 'ahr';
286 # e.g. hold ready for pickup
289 copy = hold.current_copy;
290 org_unit = hold.pickup_lib;
291 date_info = hold.shelf_expire_time;
293 ELSIF core_type == 'ausp';
295 user = target_obj.usr;
296 org_unit = target_obj.org_unit;
298 ELSIF core_type == 'au';
301 org_unit = user.home_ou;
304 user_locale = helpers.get_user_locale(user.id);
305 user_lang = user_locale | replace('-.*', ''); # ISO 639-1 language
306 user_phone = helpers.get_user_setting(
307 user.id, 'opac.default_phone') || user.day_phone;
310 bib_data = helpers.get_copy_bib_basics(copy.id);
311 title = bib_data.title;
315 date_info = date.format(
316 helpers.format_date(date_info), '%d/%m/%Y');
319 # Print the data for each target object as CSV
321 [%- '"' _ helpers.escape_csv(params.notify_media) _ '",' -%]
322 [%- '"' _ helpers.escape_csv(user_lang) _ '",' -%]
323 [%- '"' _ helpers.escape_csv(params.notify_type) _ '",' -%]
324 [%- '"' _ helpers.escape_csv(params.notify_level) _ '",' -%]
325 [%- '"' _ helpers.escape_csv(user.card.barcode) _ '",' -%]
326 [%- '"' _ helpers.escape_csv(user.prefix) _ '",' -%]
327 [%- '"' _ helpers.escape_csv(user.first_given_name) _ '",' -%]
328 [%- '"' _ helpers.escape_csv(user.family_name) _ '",' -%]
329 [%- '"' _ helpers.escape_csv(user_phone) _ '",' -%]
330 [%- '"' _ helpers.escape_csv(user.email) _ '",' -%]
331 [%- '"' _ helpers.escape_csv(notice_org_unit.shortname) _ '",' -%]
332 [%- '"' _ helpers.escape_csv(org_unit.shortname) _ '",' -%]
333 [%- '"' _ helpers.escape_csv(org_unit.name) _ '",' -%]
334 [%- '"' _ helpers.escape_csv(copy.barcode) _ '",' -%]
335 [%- '"' _ helpers.escape_csv(date_info) _ '",' -%]
336 [%- '"' _ helpers.escape_csv(title) _ '",' -%]
337 [%- '"' _ helpers.escape_csv(event.id) _ '"' %]
340 WHERE granularity = 'notify-csv';