[open-ils-commits] [GIT] Evergreen ILS branch master updated. cf5da241bad88898d9ed9ced6cc1d89f301ddfd5

Evergreen Git git at git.evergreen-ils.org
Wed Dec 21 10:57:23 EST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  cf5da241bad88898d9ed9ced6cc1d89f301ddfd5 (commit)
      from  447e0d800963a1e64845adecbc7a09e9fc1a96c4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit cf5da241bad88898d9ed9ced6cc1d89f301ddfd5
Author: Bill Erickson <berick at esilibrary.com>
Date:   Tue Nov 8 10:56:14 2011 -0500

    bookbag CSV gets bib attrs; A/T unapi method
    
    * Added a bib record unapi retrieval utility method for action/trigger
    templates.
    
    * Updated the bookbag CSV template to include data for the "item_type"
    record attribute both to have it and as an example of how the unapi
    retrieval works.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Lebbeous Fogle-Weekley <lebbeous at esilibrary.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
index 0ecf415..d214274 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
@@ -1876,8 +1876,9 @@ sub bib_record_list_via_search {
     return [ map { pop @$_ } @{$search_result->{ids}} ];
 }
 
+# 'no_flesh' avoids fleshing the target_biblio_record_entry
 sub bib_container_items_via_search {
-    my ($class, $container_id, $search_query, $search_args) = @_;
+    my ($class, $container_id, $search_query, $search_args, $no_flesh) = @_;
 
     # First, Use search API to get container items sorted in any way that crad
     # sorters support.
@@ -1903,13 +1904,16 @@ sub bib_container_items_via_search {
         return;
     }
 
+    my @flesh_fields = qw/notes/;
+    push(@flesh_fields, 'target_biblio_record_entry') unless $no_flesh;
+
     my $items = $e->search_container_biblio_record_entry_bucket_item([
         {
             "target_biblio_record_entry" => $id_list,
             "bucket" => $container_id
         }, {
             flesh => 1,
-            flesh_fields => {"cbrebi" => [qw/notes target_biblio_record_entry/]}
+            flesh_fields => {"cbrebi" => \@flesh_fields}
         }
     ]);
     unless ($items) {
@@ -1920,11 +1924,13 @@ sub bib_container_items_via_search {
         return;
     }
 
-    $e->disconnect;
-
     # ... and put them in the same order that the search API said they
     # should be in.
-    my %ordering_hash = map { $_->target_biblio_record_entry->id, $_ } @$items;
+    my %ordering_hash = map { 
+        ($no_flesh) ? $_->target_biblio_record_entry : $_->target_biblio_record_entry->id, 
+        $_ 
+    } @$items;
+
     return [map { $ordering_hash{$_} } @$id_list];
 }
 
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm
index 14a69e7..1bd0e43 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm
@@ -37,7 +37,8 @@ sub get_li_attr {
 }
 
 # helper functions inserted into the TT environment
-my $_TT_helpers = {
+my $_TT_helpers; # define first so one helper can use another
+$_TT_helpers = {
 
     # turns a date into something TT can understand
     format_date => sub {
@@ -270,8 +271,27 @@ my $_TT_helpers = {
     xml_doc => sub {
         my ($str) = @_;
         return $str ? (new XML::LibXML)->parse_string($str) : undef;
-    }
+    },
 
+    unapi_bre => sub {
+        my ($bre_id, $unapi_args) = @_;
+        $unapi_args ||= {};
+        $unapi_args->{flesh} ||= '{}',
+
+        my $query = { 
+            from => [
+                'unapi.bre', $bre_id, 'marcxml','record', 
+                $unapi_args->{flesh}, 
+                $unapi_args->{site}, 
+                $unapi_args->{depth}, 
+                $unapi_args->{flesh_depth}, 
+            ]
+        };
+
+        my $unapi = new_editor()->json_query($query);
+        return undef unless @$unapi;
+        return $_TT_helpers->{xml_doc}->($unapi->[0]->{'unapi.bre'});
+    }
 };
 
 
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/ContainerCSV.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/ContainerCSV.pm
index 28a3419..6e2306e 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/ContainerCSV.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/ContainerCSV.pm
@@ -28,9 +28,9 @@ sub handler {
 
     # get items for bookbags (bib containers of btype bookbag)
     if ($env->{user_data}{item_search}) {
-        # use the search api for bib container items
+        # use the search api for bib container items.  fetch record IDs only.
         my $items = $U->bib_container_items_via_search(
-            $env->{target}->id, $env->{user_data}{item_search}
+            $env->{target}->id, $env->{user_data}{item_search}, undef, 1 
         ) or return 0;  # TODO build error output for db?
 
         $env->{items} = $items;
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index defe858..863045b 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -86,7 +86,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0659', :eg_version); -- tsbere/dbs
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0660', :eg_version); -- berick/senator
 
 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 eca99a4..e23ceac 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -10231,14 +10231,15 @@ $$
 # the environment because a special reactor will take care of filling it in.
 
 FOR item IN items;
-    bibxml = helpers.xml_doc(item.target_biblio_record_entry.marc);
+    bibxml = helpers.unapi_bre(item.target_biblio_record_entry, {flesh => '{mra}'});
     title = "";
     FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
         title = title _ part.textContent;
     END;
     author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
+    item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value');
 
-    helpers.csv_datum(title) %],[% helpers.csv_datum(author) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
+    helpers.csv_datum(title) %],[% helpers.csv_datum(author) %],[% helpers.csv_datum(item_type) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
 END -%]
 $$
 );
diff --git a/Open-ILS/src/sql/Pg/upgrade/0660.data.bib-container-csv-unapi-template.sql b/Open-ILS/src/sql/Pg/upgrade/0660.data.bib-container-csv-unapi-template.sql
new file mode 100644
index 0000000..db81402
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/0660.data.bib-container-csv-unapi-template.sql
@@ -0,0 +1,24 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('0660', :eg_version);
+
+UPDATE action_trigger.event_definition SET template = $$
+[%-
+# target is the bookbag itself. The 'items' variable does not need to be in
+# the environment because a special reactor will take care of filling it in.
+
+FOR item IN items;
+    bibxml = helpers.unapi_bre(item.target_biblio_record_entry, {flesh => '{mra}'});
+    title = "";
+    FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
+        title = title _ part.textContent;
+    END;
+    author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
+    item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value');
+
+    helpers.csv_datum(title) %],[% helpers.csv_datum(author) %],[% helpers.csv_datum(item_type) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
+END -%]
+$$
+WHERE reactor = 'ContainerCSV';
+
+COMMIT;

-----------------------------------------------------------------------

Summary of changes:
 .../perlmods/lib/OpenILS/Application/AppUtils.pm   |   16 +++++++++----
 .../lib/OpenILS/Application/Trigger/Reactor.pm     |   24 ++++++++++++++++++-
 .../Application/Trigger/Reactor/ContainerCSV.pm    |    4 +-
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 Open-ILS/src/sql/Pg/950.data.seed-values.sql       |    5 ++-
 .../0660.data.bib-container-csv-unapi-template.sql |   24 ++++++++++++++++++++
 6 files changed, 63 insertions(+), 12 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0660.data.bib-container-csv-unapi-template.sql


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list