[open-ils-commits] r16601 - in trunk/Open-ILS/src: perlmods/OpenILS/Application/Search perlmods/OpenILS/Application/Trigger sql/Pg sql/Pg/upgrade (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Jun 4 17:36:09 EDT 2010


Author: phasefx
Date: 2010-06-04 17:36:03 -0400 (Fri, 04 Jun 2010)
New Revision: 16601

Added:
   trunk/Open-ILS/src/sql/Pg/upgrade/0294.data.bre_format.sql
Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Cleanup.pm
   trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
   trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
Log:
Email/print methods for printing A/T templated bib information

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm	2010-06-04 20:53:27 UTC (rev 16600)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm	2010-06-04 21:36:03 UTC (rev 16601)
@@ -1688,8 +1688,98 @@
 	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(
     method   => "retrieve_all_copy_statuses",
     api_name => "open-ils.search.config.copy_status.retrieve.all"

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Cleanup.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Cleanup.pm	2010-06-04 20:53:27 UTC (rev 16600)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Cleanup.pm	2010-06-04 21:36:03 UTC (rev 16601)
@@ -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;

Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-06-04 20:53:27 UTC (rev 16600)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-06-04 21:36:03 UTC (rev 16601)
@@ -65,7 +65,7 @@
     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,

Modified: trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql	2010-06-04 20:53:27 UTC (rev 16600)
+++ trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql	2010-06-04 21:36:03 UTC (rev 16601)
@@ -5246,7 +5246,149 @@
         ,( 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 -%]
+<div>
+    <style> li { padding: 8px; margin 5px; }</style>
+    <ol>
+    [% FOR cbreb IN target %]
+    [% FOR cbrebi IN cbreb.items %]
+        <li>Bib ID# [% cbrebi.target_biblio_record_entry.id %] ISBN: [% crebi.target_biblio_record_entry.simple_record.isbn %]<br />
+            Title: [% cbrebi.target_biblio_record_entry.simple_record.title %]<br />
+            Author: [% cbrebi.target_biblio_record_entry.simple_record.author %]<br />
+            Publication Year: [% cbrebi.target_biblio_record_entry.simple_record.pubdate %]
+        </li>
+    [% END %]
+    [% END %]
+    </ol>
+</div>
+$$
+    )
+;
+
+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
 
 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )

Added: trunk/Open-ILS/src/sql/Pg/upgrade/0294.data.bre_format.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0294.data.bre_format.sql	                        (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0294.data.bre_format.sql	2010-06-04 21:36:03 UTC (rev 16601)
@@ -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 -%]
+<div>
+    <style> li { padding: 8px; margin 5px; }</style>
+    <ol>
+    [% FOR cbreb IN target %]
+    [% FOR cbrebi IN cbreb.items %]
+        <li>Bib ID# [% cbrebi.target_biblio_record_entry.id %] ISBN: [% crebi.target_biblio_record_entry.simple_record.isbn %]<br />
+            Title: [% cbrebi.target_biblio_record_entry.simple_record.title %]<br />
+            Author: [% cbrebi.target_biblio_record_entry.simple_record.author %]<br />
+            Publication Year: [% cbrebi.target_biblio_record_entry.simple_record.pubdate %]
+        </li>
+    [% END %]
+    [% END %]
+    </ol>
+</div>
+$$
+    )
+;
+
+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;
+



More information about the open-ils-commits mailing list