Add index terms.
[working/Evergreen.git] / 1.6 / development / actiontriggers.xml
1 <?xml version="1.0" encoding="utf-8"?>\r
2 <chapter xml:id="actiontriggers" xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="EN"\r
3     xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xlink="http://www.w3.org/1999/xlink">\r
4     <info>\r
5         <title>Action Triggers</title>    \r
6         </info>\r
7         <para>Action Triggers were introduced to Evergreen in 1.6. They allow administrators the ability to set up actions for specific events. They are useful for notification events such as \r
8         hold notifications.</para>\r
9         \r
10                         \r
11         <para>To access the Action Triggers module, select\r
12                 <menuchoice>\r
13                         <guimenu>Admin</guimenu>  \r
14                         <guisubmenu>Local Administration</guisubmenu>\r
15                         <guisubmenu>Notifications / Action triggers</guisubmenu>\r
16                 </menuchoice>\r
17         </para>\r
18         <note><para>You must have Local Administrator permissions to access the Action Triggers module.</para></note>\r
19         <para>You will notice four tabs on this page: <guilabel><link linkend="eventdefinitions">Event Definitions</link></guilabel>, <guilabel><link linkend="Hooks">Hooks</link></guilabel>, \r
20         <guilabel><link linkend="Reactors">Reactors</link></guilabel> and <guilabel><link linkend="Validators">Validators</link></guilabel>.</para>\r
21                 \r
22         <section xml:id="eventdefinitions">\r
23                 <title>Event Definitions</title>\r
24                 <para><guilabel>Event Definitions</guilabel> is the main tab and contains the key fields when working with action triggers. These fields include:</para>\r
25                         <table xml:id="eventdefinitionstable">\r
26                                 <title>Action Trigger Event Definitions</title>\r
27                                 <tgroup cols="2">\r
28                                         <colspec colnum="1" colname="col1" colwidth="1.0*"/>\r
29                                         <colspec colnum="2" colname="col2" colwidth="3.0*"/>\r
30                                         <thead>\r
31                                                 <row>\r
32                                                         <entry>Field</entry>\r
33                                                         <entry>Description</entry>\r
34                                                 </row>\r
35                                         </thead>\r
36                                         <tbody>\r
37                                                 <row>\r
38                                                         <entry><guilabel>Owning library</guilabel></entry>\r
39                                                         <entry>The shortname of the library for which the action / trigger / hook is defined.</entry>\r
40                                                 </row>\r
41                                                 <row>\r
42                                                         <entry><guilabel>Name</guilabel></entry>\r
43                                                         <entry>The name of the trigger event, that links to a trigger event environment containing a set of fields  \r
44                                                         that will be returned to the <link linkend="Validators">Validators</link> / <link linkend="Reactors">Reactors</link> for processing.</entry>\r
45                                                 </row>\r
46                                                 <row>\r
47                                                         <entry><guilabel><link linkend="Hooks">Hooks</link></guilabel></entry>\r
48                                                         <entry>The name of the trigger for the trigger event. The underlying action_trigger.hook table defines the Fieldmapper \r
49                                                         class in the core_type column off of which the rest of the field definitions <quote>hang</quote>. </entry>\r
50                                                 </row>\r
51                                                 <row>\r
52                                                         <entry><guilabel>Enabled</guilabel></entry>\r
53                                                         <entry>Sets the given trigger as enabled or disabled. This must be set to enabled for the Action trigger to run.</entry>\r
54                                                 </row>\r
55                                                 <row>\r
56                                                         <entry><guilabel>Processing Delay</guilabel></entry>\r
57                                                         <entry>Defines how long after a given trigger / hook event has occurred before the associated action (<quote>Reactor</quote>) \r
58                                                         will be taken.</entry>\r
59                                                 </row>\r
60                                                 <row>\r
61                                                         <entry><guilabel>Processing Delay Field</guilabel></entry>\r
62                                                         <entry>Defines the field associated with the event on which the processing delay is calculated. For example, the processing delay \r
63                                                         context field on the hold.capture hook (which has a core_type of ahr) is <emphasis>capture_time</emphasis>.</entry>\r
64                                                 </row>\r
65                                                 <row>\r
66                                                         <entry><guilabel>Processing Group Context Field</guilabel></entry>\r
67                                                         <entry>Used to batch actions based on its associated group.</entry>\r
68                                                 </row>\r
69                                                 <row>\r
70                                                         <entry><guilabel><link linkend="Validators">Validators</link></guilabel></entry>\r
71                                                         <entry>The subroutines receive the trigger environment as an argument (see the linked <emphasis>Name</emphasis> for \r
72                                                         the environment definition) and returns either <emphasis>1</emphasis> if the validator is <emphasis>true</emphasis> or <emphasis>0</emphasis> \r
73                                                         if the validator returns <emphasis>false</emphasis>.</entry>\r
74                                                 </row>\r
75                                                 <row>\r
76                                                         <entry><guilabel><link linkend="Reactors">Reactors</link></guilabel></entry>\r
77                                                         <entry>Links the action trigger to the Reactor.</entry>\r
78                                                 </row>\r
79                                                 <row>\r
80                                                         <entry><guilabel>Max Event Validity Delay</guilabel></entry>\r
81                                                         <entry>Define the threshold for how far back the action_trigger_runner.pl script should reach to generate \r
82                                                         a batch of events.</entry>\r
83                                                 </row>\r
84                                         </tbody>        \r
85                                 </tgroup>\r
86                         </table>\r
87                 \r
88                 <procedure>\r
89                 <title>Creating New Action Triggers</title>\r
90                         <step>\r
91                                 <para>From the top menu, select\r
92                                         <menuchoice>\r
93                                                 <guimenu>Admin</guimenu>  \r
94                                                 <guisubmenu>Local Administration</guisubmenu>\r
95                                                 <guisubmenu>Notifications / Action triggers</guisubmenu>\r
96                                         </menuchoice>\r
97                                 </para>\r
98                         </step>\r
99                         <step><para>Click on the <guibutton>New</guibutton> button.</para></step>\r
100                         <step><para>Select an <guilabel>Owning Library</guilabel>.</para></step>\r
101                         <step><para>Create a unique <guilabel>Name</guilabel> for your new action trigger.</para></step>                                \r
102                         <step><para>Select the <guilabel>Hook</guilabel>.</para></step>\r
103                         <step><para>Check the <guilabel>Enabled</guilabel> check box.</para></step>\r
104                 \r
105                         <step><para>Create a unique <guilabel>Name</guilabel> for your new action trigger.</para></step>\r
106                         <step><para>Set the <guilabel>Processing Delay</guilabel> in the appropriate format. Eg. <emphasis class="bold">7 days</emphasis> to run 7 days from the trigger event \r
107                         or <emphasis class="bold">00:01:00</emphasis> to run 1 hour after the <guilabel>Processing Delay Context Field</guilabel>.</para></step>\r
108                         <step><para>Set the <guilabel>Processing Delay Context Field</guilabel> and <guilabel>Processing Group Context Field</guilabel>.</para></step>  \r
109                         <step><para>Select the <guilabel>Validator</guilabel>, <guilabel>Reactor</guilabel>, <guilabel>Failure Cleanup</guilabel> and <guilabel>Success Cleanup</guilabel>.\r
110                         </para></step>  \r
111                         <step><para>Set the <guilabel>Processing Delay Context Field</guilabel> and <guilabel>Processing Group Context Field</guilabel>.</para></step>  \r
112                         <step preformance="optional"><para>Enter text in the <guilabel>Template</guilabel> text box if required. These are for email messages. Here is an sample \r
113                         template for sending 90 day overdue notices:</para>\r
114 <programlisting><![CDATA[\r
115 [%- USE date -%]\r
116 [%- user = target.0.usr -%]\r
117 To: robert.soulliere@mohawkcollege.ca\r
118 From: robert.soulliere@mohawkcollege.ca\r
119 Subject: Overdue Notification\r
120 \r
121 Dear [% user.family_name %], [% user.first_given_name %]\r
122 Our records indicate the following items are overdue.\r
123 \r
124 [%- USE date -%]\r
125 [%- user = target.0.usr -%]\r
126 To: robert.soulliere@mohawkcollege.ca\r
127 From: robert.soulliere@mohawkcollege.ca\r
128 Subject: Overdue Items Marked Lost\r
129 \r
130 Dear [% user.family_name %], [% user.first_given_name %]\r
131 The following items are 90 days overdue and have been marked LOST.\r
132 [%- params.recipient_email || user.email %][%- params.sender_email || default_sender %]\r
133 [% FOR circ IN target %]\r
134     Title: [% circ.target_copy.call_number.record.simple_record.title %] \r
135     Barcode: [% circ.target_copy.barcode %] \r
136     Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]\r
137     Item Cost: [% helpers.get_copy_price(circ.target_copy) %]\r
138     Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]\r
139     Library: [% circ.circ_lib.name %]\r
140 [% END %]\r
141 \r
142 \r
143 [% FOR circ IN target %]\r
144     Title: [% circ.target_copy.call_number.record.simple_record.title %] \r
145     Barcode: [% circ.target_copy.barcode %] \r
146     Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]\r
147     Item Cost: [% helpers.get_copy_price(circ.target_copy) %]\r
148     Total Owed For Transaction: [% circ.billable_transaction.summary.total_owed %]\r
149     Library: [% circ.circ_lib.name %]\r
150 [% END %]\r
151 ]]>\r
152 </programlisting>       \r
153                         </step> \r
154                         <step><para>Once you are satisfied with your new event trigger , click the <guibutton>Save</guibutton> button located at the bottom of the \r
155                         form</para></step>\r
156                 </procedure>\r
157                 <tip><para>A quick and easy way to create new action triggers is to clone an existing action trigger.</para></tip>\r
158                 <procedure>\r
159                         <title>Cloning Existing Action Triggers</title>\r
160                         <step>\r
161                                 <para>Check the check box next to the action trigger you wish to clone</para>\r
162                         </step>\r
163                         <step>\r
164                                 <para>Click the <guibutton>Clone Selected</guibutton> on the top left of the page.</para>\r
165                         </step>\r
166                         <step>\r
167                                 <para>An editing window with open. Notice that the fields will be populated with content from the cloned action trigger. Edit as necessary and \r
168                         give the new action trigger a unique <guilabel>Name</guilabel>.</para>\r
169                         </step>\r
170                         <step>\r
171                                 <para>Click <guilabel>Save</guilabel>.</para>\r
172                         </step>\r
173                 </procedure>\r
174                 <procedure>\r
175                         <title>Editing Action Triggers</title>\r
176                         <step>\r
177                                 <para>Check the check box next to the action trigger you wish to delete</para>\r
178                         </step>\r
179                         <step>\r
180                                 <para>Click the <guibutton>Delete Selected</guibutton> on the top left of the page.</para>\r
181                         </step>\r
182                 </procedure>\r
183                 \r
184                 <note><para>Before deleting an action trigger, you should consider disabling it through the editing form. This way you can simply enable it if you decide that you would like to use \r
185                 the action trigger in the future.</para></note>\r
186                 <procedure>\r
187                         <title>Deleting Action Triggers</title>\r
188                         <step>\r
189                                 <para>Check the check box next to the action trigger you wish to delete</para>\r
190                         </step>\r
191                         <step>\r
192                                 <para>Click the <guibutton>Delete Selected</guibutton> on the top left of the page.</para>\r
193                         </step>\r
194                 </procedure>\r
195         </section>\r
196         <section xml:id="Hooks">\r
197                 <title>Hooks</title>\r
198                 <para><guilabel>Hooks</guilabel> define the Fieldmapper class in the core_type column off of which the rest of the field definitions <quote>hang</quote>.</para>\r
199                 <table xml:id="Hookstable">\r
200                         <title>Hooks</title>\r
201                         <tgroup cols="2">\r
202                                 <colspec colnum="1" colname="col1" colwidth="1.0*"/>\r
203                                 <colspec colnum="2" colname="col2" colwidth="3.0*"/>\r
204                                 <thead>\r
205                                         <row>\r
206                                                 <entry>Field</entry>\r
207                                                 <entry>Description</entry>\r
208                                         </row>\r
209                                 </thead>\r
210                                 <tbody>\r
211                                         <row>\r
212                                                 <entry><guilabel>Hook Key</guilabel></entry>\r
213                                                 <entry>A unique name given to the hook.</entry>\r
214                                         </row>\r
215                                         <row>\r
216                                                 <entry><guilabel>Core Type</guilabel></entry>\r
217                                                 <entry>Used to link the action trigger to the IDL class in fm_IDL.xml</entry>\r
218                                         </row>\r
219                                         <row>\r
220                                                 <entry><guilabel>Description</guilabel></entry>\r
221                                                 <entry>Text to describe the purpose of the hook. </entry>\r
222                                         </row>\r
223                                         <row>\r
224                                                 <entry><guilabel>Passive</guilabel></entry>\r
225                                                 <entry>Indicates whether or not an event is created by direct user action or is circumstantial.</entry>\r
226                                         </row>\r
227                                 </tbody>        \r
228                         </tgroup>\r
229                 </table>\r
230                 <para>You may also create, edit and delete Hooks but the <guilabel>Core Type</guilabel> must refer to an IDL class in the fm_IDL.xml file.</para>\r
231         </section>      \r
232         <section xml:id="Reactors">\r
233                 <title>Reactors</title>\r
234                 <para><guilabel>Reactors</guilabel> link the trigger definition to the action to be carried out.</para>\r
235                 <table xml:id="Reactorstable">\r
236                         <title>Action Trigger Reactors</title>\r
237                         <tgroup cols="2">\r
238                                 <colspec colnum="1" colname="col1" colwidth="1.0*"/>\r
239                                 <colspec colnum="2" colname="col2" colwidth="3.0*"/>\r
240                                 <thead>\r
241                                         <row>\r
242                                                 <entry>Field</entry>\r
243                                                 <entry>Description</entry>\r
244                                         </row>\r
245                                 </thead>\r
246                                 <tbody>\r
247                                         <row>\r
248                                                 <entry><guilabel>Module Name</guilabel></entry>\r
249                                                 <entry>The name of the Module to run if the action trigger is validated. It must be defined as a subroutine in \r
250                                                 <filename>/openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm</filename> or as a module\r
251                                                  in <filename>/openils/lib/perl5/OpenILS/Application/Trigger/Reactor/*.pm</filename>.</entry>\r
252                                         </row>\r
253                                         <row>\r
254                                                 <entry><guilabel>Description</guilabel></entry>\r
255                                                 <entry>Description of the Action to be carried out.</entry>\r
256                                         </row>\r
257                                 </tbody>        \r
258                         </tgroup>\r
259                 </table>\r
260                 <para>You may also create, edit and delete Reactors. Just remember that their must be an associated subroutine or module in the Reactor Perl module.</para>\r
261         </section>      \r
262         <section xml:id="Validators">\r
263                 <title>Validators</title>\r
264                 <para><guilabel>Validators</guilabel> set the validation test to be preformed to determine whether the action trigger is executed.</para>\r
265                 <table xml:id="Validatorstable">\r
266                         <title>Action Trigger Validators</title>\r
267                         \r
268                         <tgroup cols="2">\r
269                                 <colspec colnum="1" colname="col1" colwidth="1.0*"/>\r
270                                 <colspec colnum="2" colname="col2" colwidth="3.0*"/>\r
271                                 <thead>\r
272                                         <row>\r
273                                                 <entry>Field</entry>\r
274                                                 <entry>Description</entry>\r
275                                         </row>\r
276                                 </thead>\r
277                                 <tbody>\r
278                                         <row>\r
279                                                 <entry><guilabel>Module Name</guilabel></entry>\r
280                                                 <entry>The name of the subroutine in \r
281                                                 <filename>/openils/lib/perl5/OpenILS/Application/Trigger/Reactor.pm</filename> to validate the action trigger.</entry>\r
282                                         </row>\r
283                                         <row>\r
284                                                 <entry><guilabel>Description</guilabel></entry>\r
285                                                 <entry>Description of validation test to run.</entry>\r
286                                         </row>\r
287                                 </tbody>        \r
288                         </tgroup>\r
289                 </table>\r
290                 <para>You may also create, edit and delete Validators. Just remember that their must be an associated subroutine in the <filename>Reactor.pm</filename> Perl module.</para>\r
291         </section>      \r
292         <section xml:id="ProcessingActionTriggers">     \r
293                 <title>Processing Action Triggers</title>\r
294                 <para>To run the action triggers, an Evergreen administrator will need to run the trigger processing script <command>/openils/bin/action_trigger_runner.pl \r
295                 <option>--process-hooks</option> <option>--run-pending</option></command>. This should be set up as a cron job to run \r
296                 periodically.</para> \r
297                 <para>You have several options when running the script:</para>\r
298                 <itemizedlist>\r
299                         <listitem><option>--run-pending</option>: Run the pending events.</listitem>\r
300                         <listitem><option>--process-hooks</option>: Create hook events</listitem>\r
301                         <listitem><option>--osrf-config=[<varname>config_file</varname>]</option>: OpenSRF core config file.  Defaults to: \r
302                         <filename>/openils/conf/opensrf_core.xml</filename>.</listitem>\r
303                         <listitem><option>--custom-filters=[<varname>filter_file</varname>]</option>: File containing a JSON Object which describes any hooks that should\r
304                         use a user-defined filter to find their target objects.  Defaults to: <filename>/openils/conf/action_trigger_filters.json</filename></listitem>\r
305                         <listitem><option>--max-sleep=[<varname>seconds</varname>]</option>: When in process-hooks mode, wait up to [<varname>seconds</varname>] for the lock file to go away.  \r
306                         Defaults to 3600 (1 hour).</listitem>\r
307                         <listitem><option>--hooks=hook1[,hook2,hook3,...]</option>: Define which hooks to create events for.  If none are defined, it defaults to the list of hooks defined \r
308                         in the <option>--custom-filters</option> option.</listitem>\r
309                         <listitem><option>--debug-stdout</option>: Print server responses to stdout (as JSON) for debugging.</listitem>\r
310                         <listitem><option>--lock-file=[<varname>file_name</varname>]</option>: Sets the lock file for the process.</listitem>\r
311                         <listitem><option>--help</option>: Show help information.</listitem>\r
312                 </itemizedlist>\r
313         </section>                                                                                                                                      \r
314 </chapter>\r
315 \r