[open-ils-commits] r15030 - in trunk/Open-ILS: examples src/perlmods/OpenILS/Application src/perlmods/OpenILS/Application/Trigger src/sql/Pg src/sql/Pg/upgrade (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Nov 25 16:38:43 EST 2009
Author: erickson
Date: 2009-11-25 16:38:37 -0500 (Wed, 25 Nov 2009)
New Revision: 15030
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0094.data.selfcheck-receipt-template.sql
Modified:
trunk/Open-ILS/examples/fm_IDL.xml
trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
Log:
Added sample self-checkout checkout receipt
added generic (public/perm-checkin) circ event runner
Added 'g' qualifier to event path-fleshing method name munging
Added explicit exception when environment path is not valid
Added virtual hours_of_operation field for org units
Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml 2009-11-25 20:45:18 UTC (rev 15029)
+++ trunk/Open-ILS/examples/fm_IDL.xml 2009-11-25 21:38:37 UTC (rev 15030)
@@ -3034,7 +3034,7 @@
<field reporter:label="Resources" name="resources" oils_persist:virtual="true" reporter:datatype="link"/>
<field reporter:label="Resource Attributes" name="rsrc_attrs" oils_persist:virtual="true" reporter:datatype="link"/>
<field reporter:label="Attribute Values" name="attr_vals" oils_persist:virtual="true" reporter:datatype="link"/>
-
+ <field reporter:label="Hours of Operation" name="hours_of_operation" oils_persist:virtual="true" reporter:datatype="link"/>
</fields>
<links>
<link field="billing_address" reltype="has_a" key="id" map="" class="aoa"/>
@@ -3062,6 +3062,7 @@
<link field="resources" reltype="has_many" key="owner" map="" class="brsrc"/>
<link field="rsrc_attrs" reltype="has_many" key="owner" map="" class="bra"/>
<link field="attr_vals" reltype="has_many" key="owner" map="" class="brav"/>
+ <link field="hours_of_operation" reltype="might_have" key="id" map="" class="aouhoo"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<actions>
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2009-11-25 20:45:18 UTC (rev 15029)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2009-11-25 21:38:37 UTC (rev 15030)
@@ -1481,7 +1481,7 @@
# most appropriate event. create the event, fire it, then return the resulting
# event with fleshed template_output and error_output
sub fire_object_event {
- my($self, $event_def, $hook, $object, $context_org) = @_;
+ my($self, $event_def, $hook, $object, $context_org, $granularity, $user_data) = @_;
my $e = OpenILS::Utils::CStoreEditor->new;
my $def;
@@ -1496,6 +1496,7 @@
} else {
# find the most appropriate event def depending on context org
+
my $orgs = $self->get_org_ancestors($context_org);
$orgs = $e->search_actor_org_unit(
[{id => $orgs}, {flesh => 1, flesh_fields => {aou => ['ou_type']}}]);
@@ -1511,26 +1512,51 @@
return $e->event unless $def;
}
- my $event_id = $self->simplereq(
- 'open-ils.trigger', $auto_method, $def->id, $object, $context_org);
+ if($def->group_field) {
+ # we have a list of objects
+ $object = [$object] unless ref $object eq 'ARRAY';
- my $fire = 'open-ils.trigger.event.fire';
+ my @event_ids;
+ $user_data ||= [];
+ for my $i (0..$#$object) {
+ my $obj = $$object[$i];
+ my $udata = $$user_data[$i];
+ my $event_id = $self->simplereq(
+ 'open-ils.trigger', $auto_method, $def->id, $obj, $context_org, $udata);
+ push(@event_ids, $event_id);
+ }
- if($def->group_field) {
- $fire =~ s/event/event_group/o;
- $event_id = [$event_id];
- }
+ $logger->info("EVENTS = " . OpenSRF::Utils::JSON->perl2JSON(\@event_ids));
- my $resp = $self->simplereq('open-ils.trigger', $fire, $event_id);
- return 0 unless $resp and ($resp->{event} or $resp->{events});
- my $evt = $resp->{event} ? $resp->{event} : $resp->{events}->[0];
+ my $resp = $self->simplereq(
+ 'open-ils.trigger',
+ 'open-ils.trigger.event_group.fire',
+ \@event_ids);
- return 0 unless $evt;
+ return undef unless $resp and $resp->{events} and @{$resp->{events}};
- return $e->retrieve_action_trigger_event([
- $evt->id,
- {flesh => 1, flesh_fields => {atev => ['template_output', 'error_output']}}
- ]);
+ return $e->retrieve_action_trigger_event([
+ $resp->{events}->[0]->id,
+ {flesh => 1, flesh_fields => {atev => ['template_output', 'error_output']}}
+ ]);
+
+ } else {
+
+ my $event_id = $self->simplereq(
+ 'open-ils.trigger', $auto_method, $def->id, $object, $context_org, $user_data);
+
+ my $resp = $self->simplereq(
+ 'open-ils.trigger',
+ 'open-ils.trigger.event.fire',
+ $event_id);
+
+ return undef unless $resp and $resp->{event};
+
+ return $e->retrieve_action_trigger_event([
+ $resp->{event}->id,
+ {flesh => 1, flesh_fields => {atev => ['template_output', 'error_output']}}
+ ]);
+ }
}
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm 2009-11-25 20:45:18 UTC (rev 15029)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm 2009-11-25 21:38:37 UTC (rev 15030)
@@ -1278,8 +1278,28 @@
return $U->fire_object_event($event_def, undef, $circ, $e->requestor->ws_ou)
}
+__PACKAGE__->register_method(
+ method => "fire_circ_events",
+ api_name => "open-ils.circ.fire_circ_trigger_events",
+ signature => q/
+ General event def runner for circ objects. If no event def ID
+ is provided, the hook will be used to find the best event_def
+ match based on the context org unit
+ /
+);
+sub fire_circ_events {
+ my($self, $conn, $auth, $org_id, $event_def, $hook, $granularity, $circ_ids, $user_data) = @_;
+ my $e = new_editor(authtoken => $auth);
+ return $e->event unless $e->checkauth;
+ return $e->event unless $e->allowed('VIEW_CIRCULATIONS', $org_id);
+
+ my $circs = $e->batch_retrieve_action_circulation($circ_ids);
+ return undef unless @$circs;
+ return $U->fire_object_event($event_def, $hook, $circs, $org_id, $granularity, $user_data)
+}
+
__PACKAGE__->register_method(
method => "user_payments_list",
api_name => "open-ils.circ.user_payments.filtered.batch",
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm 2009-11-25 20:45:18 UTC (rev 15029)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Event.pm 2009-11-25 21:38:37 UTC (rev 15030)
@@ -433,11 +433,17 @@
my $label = shift;
my $path = shift;
+
my $step = shift(@$path);
+
my $fhint = Fieldmapper->publish_fieldmapper->{$context->class_name}{links}{$step}{class};
my $fclass = $self->_fm_class_by_hint( $fhint );
+ OpenSRF::EX::ERROR->throw(
+ "$step is not a field on ".$context->class_name." Please repair the environment.")
+ unless $fhint;
+
my $ffield = Fieldmapper->publish_fieldmapper->{$context->class_name}{links}{$step}{key};
my $rtype = Fieldmapper->publish_fieldmapper->{$context->class_name}{links}{$step}{reltype};
@@ -452,7 +458,7 @@
$meth .= $fclass;
$meth =~ s/Fieldmapper:://;
- $meth =~ s/::/_/;
+ $meth =~ s/::/_/g;
my $ed = grep( /open-ils.cstore/, @{$fclass->Controller} ) ?
$self->editor :
@@ -460,6 +466,8 @@
my $obj = $context->$step();
+ $logger->debug("_object_by_path(): meth=$meth, obj=$obj, multi=$multi, step=$step, lfield=$lfield");
+
if (!ref $obj) {
$obj = $ed->$meth(
($multi) ?
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-11-25 20:45:18 UTC (rev 15029)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-11-25 21:38:37 UTC (rev 15030)
@@ -51,7 +51,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0093'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0094'); -- berick
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2009-11-25 20:45:18 UTC (rev 15029)
+++ trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2009-11-25 21:38:37 UTC (rev 15030)
@@ -2615,4 +2615,108 @@
'bool'
);
+-- self-check checkout receipt
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES (
+ 'format.selfcheck.checkout',
+ 'circ',
+ 'Formats circ objects for self-checkout receipt',
+ TRUE
+ );
+
+INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, group_field, granularity, template )
+ VALUES (
+ 10,
+ TRUE,
+ 1,
+ 'Self-Checkout Receipt',
+ 'format.selfcheck.checkout',
+ 'NOOP_True',
+ 'ProcessTemplate',
+ 'usr',
+ 'print-on-demand',
+$$
+[%- USE date -%]
+[%- SET user = target.0.usr -%]
+[%- SET lib = target.0.circ_lib -%]
+[%- SET lib_addr = target.0.circ_lib.billing_address -%]
+[%- SET hours = lib.hours_of_operation -%]
+<div>
+ <style> li { padding: 8px; margin 5px; }</style>
+ <div>[% date.format %]</div>
+ <div>[% lib.name %]</div>
+ <div>[% lib_addr.street1 %] [% lib_addr.street2 %]</div>
+ <div>[% lib_addr.city %], [% lib_addr.state %] [% lb_addr.post_code %]</div>
+ <div>[% lib.phone %]</div>
+ <br/>
+
+ [% user.family_name %], [% user.first_given_name %]
+ <ol>
+ [% FOR circ IN target %]
+ [%-
+ SET idx = loop.count - 1;
+ SET user_data = EventProcessor.findEvent( event.$idx ).environment.user_data
+ -%]
+ <li>
+ <div>[% helpers.get_copy_bib_basics(circ.target_copy.id).title %]</div>
+ <div>Barcode: [% circ.target_copy.barcode %]</div>
+ [% IF user_data.renewal_failure %]
+ <div style='color:red;'>Renewal Failed</div>
+ [% ELSE %]
+ <div>Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]</div>
+ [% END %]
+ </li>
+ [% END %]
+ </ol>
+
+ <div>
+ Library Hours
+ [%- BLOCK format_time; date.format(time _ ' 1/1/1000', format='%I:%M %p'); END -%]
+ <div>
+ Monday
+ [% PROCESS format_time time = hours.dow_0_open %]
+ [% PROCESS format_time time = hours.dow_0_close %]
+ </div>
+ <div>
+ Tuesday
+ [% PROCESS format_time time = hours.dow_1_open %]
+ [% PROCESS format_time time = hours.dow_1_close %]
+ </div>
+ <div>
+ Wednesday
+ [% PROCESS format_time time = hours.dow_2_open %]
+ [% PROCESS format_time time = hours.dow_2_close %]
+ </div>
+ <div>
+ Thursday
+ [% PROCESS format_time time = hours.dow_3_open %]
+ [% PROCESS format_time time = hours.dow_3_close %]
+ </div>
+ <div>
+ Friday
+ [% PROCESS format_time time = hours.dow_4_open %]
+ [% PROCESS format_time time = hours.dow_4_close %]
+ </div>
+ <div>
+ Saturday
+ [% PROCESS format_time time = hours.dow_5_open %]
+ [% PROCESS format_time time = hours.dow_5_close %]
+ </div>
+ <div>
+ Sunday
+ [% PROCESS format_time time = hours.dow_6_open %]
+ [% PROCESS format_time time = hours.dow_6_close %]
+ </div>
+ </div>
+</div>
+$$
+);
+
+
+INSERT INTO action_trigger.environment ( event_def, path) VALUES
+ ( 10, 'target_copy'),
+ ( 10, 'circ_lib.billing_address'),
+ ( 10, 'circ_lib.hours_of_operation'),
+ ( 10, 'usr');
+
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0094.data.selfcheck-receipt-template.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0094.data.selfcheck-receipt-template.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0094.data.selfcheck-receipt-template.sql 2009-11-25 21:38:37 UTC (rev 15030)
@@ -0,0 +1,108 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0094');
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES (
+ 'format.selfcheck.checkout',
+ 'circ',
+ 'Formats circ objects for self-checkout receipt',
+ TRUE
+ );
+
+INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, group_field, granularity, template )
+ VALUES (
+ 10,
+ TRUE,
+ 1,
+ 'Self-Checkout Receipt',
+ 'format.selfcheck.checkout',
+ 'NOOP_True',
+ 'ProcessTemplate',
+ 'usr',
+ 'print-on-demand',
+$$
+[%- USE date -%]
+[%- SET user = target.0.usr -%]
+[%- SET lib = target.0.circ_lib -%]
+[%- SET lib_addr = target.0.circ_lib.billing_address -%]
+[%- SET hours = lib.hours_of_operation -%]
+<div>
+ <style> li { padding: 8px; margin 5px; }</style>
+ <div>[% date.format %]</div>
+ <div>[% lib.name %]</div>
+ <div>[% lib_addr.street1 %] [% lib_addr.street2 %]</div>
+ <div>[% lib_addr.city %], [% lib_addr.state %] [% lb_addr.post_code %]</div>
+ <div>[% lib.phone %]</div>
+ <br/>
+
+ [% user.family_name %], [% user.first_given_name %]
+ <ol>
+ [% FOR circ IN target %]
+ [%-
+ SET idx = loop.count - 1;
+ SET user_data = EventProcessor.findEvent( event.$idx ).environment.user_data
+ -%]
+ <li>
+ <div>[% helpers.get_copy_bib_basics(circ.target_copy.id).title %]</div>
+ <div>Barcode: [% circ.target_copy.barcode %]</div>
+ [% IF user_data.renewal_failure %]
+ <div style='color:red;'>Renewal Failed</div>
+ [% ELSE %]
+ <div>Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]</div>
+ [% END %]
+ </li>
+ [% END %]
+ </ol>
+
+ <div>
+ Library Hours
+ [%- BLOCK format_time; date.format(time _ ' 1/1/1000', format='%I:%M %p'); END -%]
+ <div>
+ Monday
+ [% PROCESS format_time time = hours.dow_0_open %]
+ [% PROCESS format_time time = hours.dow_0_close %]
+ </div>
+ <div>
+ Tuesday
+ [% PROCESS format_time time = hours.dow_1_open %]
+ [% PROCESS format_time time = hours.dow_1_close %]
+ </div>
+ <div>
+ Wednesday
+ [% PROCESS format_time time = hours.dow_2_open %]
+ [% PROCESS format_time time = hours.dow_2_close %]
+ </div>
+ <div>
+ Thursday
+ [% PROCESS format_time time = hours.dow_3_open %]
+ [% PROCESS format_time time = hours.dow_3_close %]
+ </div>
+ <div>
+ Friday
+ [% PROCESS format_time time = hours.dow_4_open %]
+ [% PROCESS format_time time = hours.dow_4_close %]
+ </div>
+ <div>
+ Saturday
+ [% PROCESS format_time time = hours.dow_5_open %]
+ [% PROCESS format_time time = hours.dow_5_close %]
+ </div>
+ <div>
+ Sunday
+ [% PROCESS format_time time = hours.dow_6_open %]
+ [% PROCESS format_time time = hours.dow_6_close %]
+ </div>
+ </div>
+</div>
+$$
+);
+
+
+INSERT INTO action_trigger.environment ( event_def, path) VALUES
+ ( 10, 'target_copy'),
+ ( 10, 'circ_lib.billing_address'),
+ ( 10, 'circ_lib.hours_of_operation'),
+ ( 10, 'usr');
+
+COMMIT;
More information about the open-ils-commits
mailing list