From: Bill Erickson Date: Thu, 6 Dec 2012 19:33:47 +0000 (-0500) Subject: Notify CSV seed data script X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0ad1ab742adf0b438b656bfb4cea91f85e5f9d59;p=evergreen%2Fequinox.git Notify CSV seed data script Optional SQL script for loading a large pile of seed data for various CSV notifications. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/sql/Pg/notify-csv-action-trigger.sql b/Open-ILS/src/sql/Pg/notify-csv-action-trigger.sql new file mode 100644 index 0000000000..925c47137d --- /dev/null +++ b/Open-ILS/src/sql/Pg/notify-csv-action-trigger.sql @@ -0,0 +1,197 @@ +BEGIN; + +-- Build the event defintions, environment, and params, then apply the same +-- template to all CSV definitions. + +-- All definitions assume a notify media of "V" (voice). + +--------------------------------------------------- +-- 1st overdue +INSERT INTO action_trigger.event_definition (active, name, owner, hook, + validator, reactor, delay, delay_field, group_field, template, granularity) +VALUES ( + 'f', '1st Overdue CSV', 1, 'checkout.due','CircIsOverdue', + 'ProcessTemplate', '7 days', 'due_date', 'usr', '', 'notify-csv' +); + +INSERT INTO action_trigger.environment (event_def, path) VALUES +(currval('action_trigger.event_definition_id_seq'), 'circ_lib'), +(currval('action_trigger.event_definition_id_seq'), 'target_copy'), +(currval('action_trigger.event_definition_id_seq'), 'usr.card') +; + +INSERT INTO action_trigger.event_params (event_def, param, value) VALUES +(currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''), +(currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'), +(currval('action_trigger.event_definition_id_seq'), 'notify_type', '''OVERDUE''') +; + +--------------------------------------------------- +-- 2nd overdue +INSERT INTO action_trigger.event_definition (active, name, owner, hook, + validator, reactor, delay, delay_field, group_field, template, granularity) +VALUES ( + 'f', '2nd Overdue CSV', 1, 'checkout.due','CircIsOverdue', + 'ProcessTemplate', '14 days', 'due_date', 'usr', '', 'notify-csv' +); + +INSERT INTO action_trigger.environment (event_def, path) VALUES +(currval('action_trigger.event_definition_id_seq'), 'circ_lib'), +(currval('action_trigger.event_definition_id_seq'), 'target_copy'), +(currval('action_trigger.event_definition_id_seq'), 'usr.card') +; + +INSERT INTO action_trigger.event_params (event_def, param, value) VALUES +(currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''), +(currval('action_trigger.event_definition_id_seq'), 'notify_level', '2'), +(currval('action_trigger.event_definition_id_seq'), 'notify_type', '''OVERDUE''') +; + +--------------------------------------------------- +-- 3rd overdue +INSERT INTO action_trigger.event_definition (active, name, owner, hook, + validator, reactor, delay, delay_field, group_field, template, granularity) +VALUES ( + 'f', '3rd Overdue CSV', 1, 'checkout.due','CircIsOverdue', + 'ProcessTemplate', '28 days', 'due_date', 'usr', '', 'notify-csv' +); + +INSERT INTO action_trigger.environment (event_def, path) VALUES +(currval('action_trigger.event_definition_id_seq'), 'circ_lib'), +(currval('action_trigger.event_definition_id_seq'), 'target_copy'), +(currval('action_trigger.event_definition_id_seq'), 'usr.card') +; + +INSERT INTO action_trigger.event_params (event_def, param, value) VALUES +(currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''), +(currval('action_trigger.event_definition_id_seq'), 'notify_level', '3'), +(currval('action_trigger.event_definition_id_seq'), 'notify_type', '''OVERDUE''') +; + +--------------------------------------------------- +-- predue +INSERT INTO action_trigger.event_definition (active, name, owner, hook, + validator, reactor, delay, delay_field, group_field, template, granularity) +VALUES ( + 'f', '3-Day Predue CSV', 1, 'checkout.due','CircIsOpen', + 'ProcessTemplate', '-3 days', 'due_date', 'usr', '', 'notify-csv' +); + +INSERT INTO action_trigger.environment (event_def, path) VALUES +(currval('action_trigger.event_definition_id_seq'), 'circ_lib'), +(currval('action_trigger.event_definition_id_seq'), 'target_copy'), +(currval('action_trigger.event_definition_id_seq'), 'usr.card') +; + +INSERT INTO action_trigger.event_params (event_def, param, value) VALUES +(currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''), +(currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'), +(currval('action_trigger.event_definition_id_seq'), 'notify_type', '''PREOVERDUE''') +; + +--------------------------------------------------- +-- hold ready for pickup +INSERT INTO action_trigger.event_definition (active, name, owner, hook, + validator, reactor, delay, delay_field, group_field, template, granularity) +VALUES ( + 'f', 'Hold Ready CSV', 1, 'hold.available','HoldIsAvailable', + 'ProcessTemplate', '30 minutes', 'shelf_time', 'usr', '', 'notify-csv' +); + +INSERT INTO action_trigger.environment (event_def, path) VALUES +(currval('action_trigger.event_definition_id_seq'), 'pickup_lib'), +(currval('action_trigger.event_definition_id_seq'), 'current_copy'), +(currval('action_trigger.event_definition_id_seq'), 'usr.card') +; + +INSERT INTO action_trigger.event_params (event_def, param, value) VALUES +(currval('action_trigger.event_definition_id_seq'), 'notify_media', '''V'''), +(currval('action_trigger.event_definition_id_seq'), 'notify_level', '1'), +(currval('action_trigger.event_definition_id_seq'), 'notify_type', '''RESERVE''') +; + +UPDATE action_trigger.event_definition SET template = +$$ +[% + USE date; + + # accommodate grouped events + SET event = event.0 IF event.size; + SET target = [target] UNLESS event.event_def.group_field; + + core_type = event.event_def.hook.core_type; + notice_org_unit = helpers.get_org_unit(event.event_def.owner); + + FOR target_obj IN target; + + # Mangle the data into a consistent shape + circ = ''; + hold = ''; + copy = ''; + user = ''; + title = ''; + org_unit = ''; + due_date = ''; + + IF core_type == 'circ'; + # e.g. overdue circ + circ = target_obj; + user = circ.usr; + copy = circ.target_copy; + org_unit = circ.circ_lib; + due_date = date.format( + helpers.format_date(circ.due_date), '%d/%m/%Y'); + + ELSIF core_type == 'ahr'; + # e.g. hold ready for pickup + hold = target_obj; + user = hold.usr; + copy = hold.current_copy; + org_unit = hold.pickup_lib; + + ELSIF core_type == 'ausp'; + # e.g. max fines + user = target_obj.usr; + org_unit = target_obj.org_unit; + + ELSIF core_type == 'au'; + # e.g. barred + user = target_obj; + org_unit = user.home_ou; + END; + + user_locale = helpers.get_user_locale(user.id); + user_lang = user_locale | replace('-.*', ''); # ISO 639-1 language + user_phone = helpers.get_user_setting( + user.id, 'opac.default_phone') || user.day_phone; + + IF copy; + bib_data = helpers.get_copy_bib_basics(copy.id); + title = bib_data.title; + END; + + # Print the data for each target object as CSV +%] +[%- '"' _ helpers.escape_csv(params.notify_media) _ '",' -%] +[%- '"' _ helpers.escape_csv(user_lang) _ '",' -%] +[%- '"' _ helpers.escape_csv(params.notify_type) _ '",' -%] +[%- '"' _ helpers.escape_csv(params.notify_level) _ '",' -%] +[%- '"' _ helpers.escape_csv(user.card.barcode) _ '",' -%] +[%- '"' _ helpers.escape_csv(user.prefix) _ '",' -%] +[%- '"' _ helpers.escape_csv(user.first_given_name) _ '",' -%] +[%- '"' _ helpers.escape_csv(user.family_name) _ '",' -%] +[%- '"' _ helpers.escape_csv(user_phone) _ '",' -%] +[%- '"' _ helpers.escape_csv(user.email) _ '",' -%] +[%- '"' _ helpers.escape_csv(notice_org_unit.shortname) _ '",' -%] +[%- '"' _ helpers.escape_csv(org_unit.shortname) _ '",' -%] +[%- '"' _ helpers.escape_csv(org_unit.name) _ '",' -%] +[%- '"' _ helpers.escape_csv(copy.barcode) _ '",' -%] +[%- '"' _ helpers.escape_csv(due_date) _ '",' -%] +[%- '"' _ helpers.escape_csv(title) _ '",' -%] +[%- '"' _ helpers.escape_csv(event.id) _ '"' %] +[% END -%] +$$ +WHERE granularity = 'notify-csv'; + +ROLLBACK; +--COMMIT;