From fd6fec5fc8c88b2d166ea252dec12db2b7586a7e Mon Sep 17 00:00:00 2001 From: phasefx Date: Fri, 4 Jun 2010 21:36:03 +0000 Subject: [PATCH] Email/print methods for printing A/T templated bib information git-svn-id: svn://svn.open-ils.org/ILS/trunk@16601 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Search/Biblio.pm | 90 +++++++++++ .../OpenILS/Application/Trigger/Cleanup.pm | 23 +++ Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 142 +++++++++++++++++ .../sql/Pg/upgrade/0294.data.bre_format.sql | 149 ++++++++++++++++++ 5 files changed, 405 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0294.data.bre_format.sql diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm index fe8b06f754..08a71335bb 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm @@ -1688,6 +1688,96 @@ sub biblio_record_to_marc_html { return $html->documentElement->toString(); } +__PACKAGE__->register_method( + method => "format_biblio_record_entry", + api_name => "open-ils.search.biblio.record.print", + signature => { + desc => 'Returns a printable version of the specified bib record', + params => [ + { desc => 'Biblio record entry ID or array of IDs', type => 'number' }, + ], + return => { + desc => q/An action_trigger.event object or error event./, + type => 'object', + } + } +); +__PACKAGE__->register_method( + method => "format_biblio_record_entry", + api_name => "open-ils.search.biblio.record.email", + signature => { + desc => 'Emails an A/T templated version of the specified bib records to the authorized user', + params => [ + { desc => 'Authentication token', type => 'string'}, + { desc => 'Biblio record entry ID or array of IDs', type => 'number' }, + ], + return => { + desc => q/Undefined on success, otherwise an error event./, + type => 'object', + } + } +); + +sub format_biblio_record_entry { + my($self, $conn, $arg1, $arg2) = @_; + + my $for_print = ($self->api_name =~ /print/); + my $for_email = ($self->api_name =~ /email/); + + my $e; my $auth; my $bib_id; my $context_org; + + if ($for_print) { + $bib_id = $arg1; + $context_org = $arg2 || $U->fetch_org_tree->id; + $e = new_editor(xact => 1); + } elsif ($for_email) { + $auth = $arg1; + $bib_id = $arg2; + $e = new_editor(authtoken => $auth, xact => 1); + return $e->die_event unless $e->checkauth; + $context_org = $e->requestor->home_ou; + } + + my $bib_ids; + if (ref $bib_id ne 'ARRAY') { + $bib_ids = [ $bib_id ]; + } else { + $bib_ids = $bib_id; + } + + my $bucket = Fieldmapper::container::biblio_record_entry_bucket->new; + $bucket->btype('temp'); + $bucket->name('format_biblio_record_entry ' . $U->create_uuid_string); + if ($for_email) { + $bucket->owner($e->requestor) + } else { + $bucket->owner(1); + } + my $bucket_obj = $e->create_container_biblio_record_entry_bucket($bucket); + + for my $id (@$bib_ids) { + + my $bib = $e->retrieve_biblio_record_entry([$id]) or return $e->die_event; + + my $bucket_entry = Fieldmapper::container::biblio_record_entry_bucket_item->new; + $bucket_entry->target_biblio_record_entry($bib); + $bucket_entry->bucket($bucket_obj->id); + $e->create_container_biblio_record_entry_bucket_item($bucket_entry); + } + + $e->commit; + + if ($for_print) { + + return $U->fire_object_event(undef, 'biblio.format.record_entry.print', [ $bucket ], $context_org); + + } elsif ($for_email) { + + $U->create_events_for_hook('biblio.format.record_entry.email', $bucket, $context_org, undef, undef, 1); + } + + return undef; +} __PACKAGE__->register_method( diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Cleanup.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Cleanup.pm index 8250eb8c3c..495a60a0f8 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Cleanup.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Cleanup.pm @@ -1,6 +1,29 @@ package OpenILS::Application::Trigger::Cleanup; use strict; use warnings; +use OpenILS::Utils::CStoreEditor q/:funcs/; +use OpenSRF::Utils::Logger qw/:logger/; + sub fourty_two { return 42 } sub NOOP_True { return 1 } sub NOOP_False { return 0 } + +sub DeleteTempBiblioBucket { + my($self, $env) = @_; + my $e = new_editor(xact => 1); + my $buckets = $env->{target}; + + for my $bucket (@$buckets) { + + foreach my $item (@{ $bucket->items }) { + $e->delete_container_biblio_record_entry_bucket_item($item); + } + + $e->delete_container_biblio_record_entry_bucket($bucket); + } + + $e->commit or $e->die_event; + + return 1; +} + 1; diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 68adf49850..faee60f270 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -65,7 +65,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0293'); -- Scott McKellar +INSERT INTO config.upgrade_log (version) VALUES ('0294'); -- phasefx CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 10a48e897d..4a49ba41e9 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -5246,6 +5246,148 @@ INSERT INTO action_trigger.environment ( ,( 30, 'xact.summary' ) ; +-- 0294.data.bre_format.sql + +INSERT INTO container.biblio_record_entry_bucket_type( code, label ) VALUES ( + 'temp', + oils_i18n_gettext( + 'temp', + 'Temporary bucket which gets deleted after use.', + 'cbrebt', + 'label' + ) +); + +INSERT INTO action_trigger.cleanup ( module, description ) VALUES ( + 'DeleteTempBiblioBucket', + oils_i18n_gettext( + 'DeleteTempBiblioBucket', + 'Deletes a cbreb object used as a target if it has a btype of "temp"', + 'atclean', + 'description' + ) +); + +INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ( + 'biblio.format.record_entry.email', + 'cbreb', + oils_i18n_gettext( + 'biblio.format.record_entry.email', + 'An email has been requested for one or more biblio record entries.', + 'ath', + 'description' + ), + FALSE + ) + ,( + 'biblio.format.record_entry.print', + 'cbreb', + oils_i18n_gettext( + 'biblio.format.record_entry.print', + 'One or more biblio record entries need to be formatted for printing.', + 'ath', + 'description' + ), + FALSE + ) +; + +INSERT INTO action_trigger.event_definition ( + id, + active, + owner, + name, + hook, + validator, + reactor, + cleanup_success, + cleanup_failure, + group_field, + granularity, + template + ) VALUES ( + 31, + TRUE, + 1, + 'biblio.record_entry.email', + 'biblio.format.record_entry.email', + 'NOOP_True', + 'SendEmail', + 'DeleteTempBiblioBucket', + 'DeleteTempBiblioBucket', + 'owner', + NULL, +$$ +[%- USE date -%] +[%- SET user = target.0.owner -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || default_sender %] +Subject: Bibliographic Records + + [% FOR cbreb IN target %] + [% FOR cbrebi IN cbreb.items %] + Bib ID# [% cbrebi.target_biblio_record_entry.id %] ISBN: [% crebi.target_biblio_record_entry.simple_record.isbn %] + Title: [% cbrebi.target_biblio_record_entry.simple_record.title %] + Author: [% cbrebi.target_biblio_record_entry.simple_record.author %] + Publication Year: [% cbrebi.target_biblio_record_entry.simple_record.pubdate %] + + [% END %] + [% END %] +$$ + ) + ,( + 32, + TRUE, + 1, + 'biblio.record_entry.print', + 'biblio.format.record_entry.print', + 'NOOP_True', + 'ProcessTemplate', + 'DeleteTempBiblioBucket', + 'DeleteTempBiblioBucket', + 'owner', + 'print-on-demand', +$$ +[%- USE date -%] +
+ +
    + [% FOR cbreb IN target %] + [% FOR cbrebi IN cbreb.items %] +
  1. Bib ID# [% cbrebi.target_biblio_record_entry.id %] ISBN: [% crebi.target_biblio_record_entry.simple_record.isbn %]
    + Title: [% cbrebi.target_biblio_record_entry.simple_record.title %]
    + Author: [% cbrebi.target_biblio_record_entry.simple_record.author %]
    + Publication Year: [% cbrebi.target_biblio_record_entry.simple_record.pubdate %] +
  2. + [% END %] + [% END %] +
+
+$$ + ) +; + +INSERT INTO action_trigger.environment ( + event_def, + path + ) VALUES -- for fleshing cbreb objects + ( 31, 'owner' ) + ,( 31, 'items' ) + ,( 31, 'items.target_biblio_record_entry' ) + ,( 31, 'items.target_biblio_record_entry.simple_record' ) + ,( 31, 'items.target_biblio_record_entry.call_numbers' ) + ,( 31, 'items.target_biblio_record_entry.fixed_fields' ) + ,( 31, 'items.target_biblio_record_entry.notes' ) + ,( 31, 'items.target_biblio_record_entry.full_record_entries' ) + ,( 32, 'owner' ) + ,( 32, 'items' ) + ,( 32, 'items.target_biblio_record_entry' ) + ,( 32, 'items.target_biblio_record_entry.simple_record' ) + ,( 32, 'items.target_biblio_record_entry.call_numbers' ) + ,( 32, 'items.target_biblio_record_entry.fixed_fields' ) + ,( 32, 'items.target_biblio_record_entry.notes' ) + ,( 32, 'items.target_biblio_record_entry.full_record_entries' ) +; -- Org unit settings for fund spending limits diff --git a/Open-ILS/src/sql/Pg/upgrade/0294.data.bre_format.sql b/Open-ILS/src/sql/Pg/upgrade/0294.data.bre_format.sql new file mode 100644 index 0000000000..df0f8d2bb1 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0294.data.bre_format.sql @@ -0,0 +1,149 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0294'); -- phasefx + +INSERT INTO container.biblio_record_entry_bucket_type( code, label ) VALUES ( + 'temp', + oils_i18n_gettext( + 'temp', + 'Temporary bucket which gets deleted after use.', + 'cbrebt', + 'label' + ) +); + +INSERT INTO action_trigger.cleanup ( module, description ) VALUES ( + 'DeleteTempBiblioBucket', + oils_i18n_gettext( + 'DeleteTempBiblioBucket', + 'Deletes a cbreb object used as a target if it has a btype of "temp"', + 'atclean', + 'description' + ) +); + +INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES ( + 'biblio.format.record_entry.email', + 'cbreb', + oils_i18n_gettext( + 'biblio.format.record_entry.email', + 'An email has been requested for one or more biblio record entries.', + 'ath', + 'description' + ), + FALSE + ) + ,( + 'biblio.format.record_entry.print', + 'cbreb', + oils_i18n_gettext( + 'biblio.format.record_entry.print', + 'One or more biblio record entries need to be formatted for printing.', + 'ath', + 'description' + ), + FALSE + ) +; + +INSERT INTO action_trigger.event_definition ( + id, + active, + owner, + name, + hook, + validator, + reactor, + cleanup_success, + cleanup_failure, + group_field, + granularity, + template + ) VALUES ( + 31, + TRUE, + 1, + 'biblio.record_entry.email', + 'biblio.format.record_entry.email', + 'NOOP_True', + 'SendEmail', + 'DeleteTempBiblioBucket', + 'DeleteTempBiblioBucket', + 'owner', + NULL, +$$ +[%- USE date -%] +[%- SET user = target.0.owner -%] +To: [%- params.recipient_email || user.email %] +From: [%- params.sender_email || default_sender %] +Subject: Bibliographic Records + + [% FOR cbreb IN target %] + [% FOR cbrebi IN cbreb.items %] + Bib ID# [% cbrebi.target_biblio_record_entry.id %] ISBN: [% crebi.target_biblio_record_entry.simple_record.isbn %] + Title: [% cbrebi.target_biblio_record_entry.simple_record.title %] + Author: [% cbrebi.target_biblio_record_entry.simple_record.author %] + Publication Year: [% cbrebi.target_biblio_record_entry.simple_record.pubdate %] + + [% END %] + [% END %] +$$ + ) + ,( + 32, + TRUE, + 1, + 'biblio.record_entry.print', + 'biblio.format.record_entry.print', + 'NOOP_True', + 'ProcessTemplate', + 'DeleteTempBiblioBucket', + 'DeleteTempBiblioBucket', + 'owner', + 'print-on-demand', +$$ +[%- USE date -%] +
+ +
    + [% FOR cbreb IN target %] + [% FOR cbrebi IN cbreb.items %] +
  1. Bib ID# [% cbrebi.target_biblio_record_entry.id %] ISBN: [% crebi.target_biblio_record_entry.simple_record.isbn %]
    + Title: [% cbrebi.target_biblio_record_entry.simple_record.title %]
    + Author: [% cbrebi.target_biblio_record_entry.simple_record.author %]
    + Publication Year: [% cbrebi.target_biblio_record_entry.simple_record.pubdate %] +
  2. + [% END %] + [% END %] +
+
+$$ + ) +; + +INSERT INTO action_trigger.environment ( + event_def, + path + ) VALUES -- for fleshing cbreb objects + ( 31, 'owner' ) + ,( 31, 'items' ) + ,( 31, 'items.target_biblio_record_entry' ) + ,( 31, 'items.target_biblio_record_entry.simple_record' ) + ,( 31, 'items.target_biblio_record_entry.call_numbers' ) + ,( 31, 'items.target_biblio_record_entry.fixed_fields' ) + ,( 31, 'items.target_biblio_record_entry.notes' ) + ,( 31, 'items.target_biblio_record_entry.full_record_entries' ) + ,( 32, 'owner' ) + ,( 32, 'items' ) + ,( 32, 'items.target_biblio_record_entry' ) + ,( 32, 'items.target_biblio_record_entry.simple_record' ) + ,( 32, 'items.target_biblio_record_entry.call_numbers' ) + ,( 32, 'items.target_biblio_record_entry.fixed_fields' ) + ,( 32, 'items.target_biblio_record_entry.notes' ) + ,( 32, 'items.target_biblio_record_entry.full_record_entries' ) +; + +-- DELETE FROM action_trigger.environment WHERE event_def IN (31,32); DELETE FROM action_trigger.event where event_def IN (31,32); DELETE FROM action_trigger.event_definition WHERE id IN (31,32); DELETE FROM action_trigger.hook WHERE key IN ('biblio.format.record_entry.email','biblio.format.record_entry.print'); DELETE FROM action_trigger.cleanup WHERE module = 'DeleteTempBiblioBucket'; DELETE FROM container.biblio_record_entry_bucket_item WHERE bucket IN (SELECT id FROM container.biblio_record_entry_bucket WHERE btype = 'temp'); DELETE FROM container.biblio_record_entry_bucket WHERE btype = 'temp'; DELETE FROM container.biblio_record_entry_bucket_type WHERE code = 'temp'; DELETE FROM config.upgrade_log WHERE version = '0294'; -- from testing, this sql will remove these events, etc. + +COMMIT; + -- 2.43.2