LP#1596595 AOUS lookup batch by org id
authorBill Erickson <berickxx@gmail.com>
Tue, 7 Feb 2017 17:25:01 +0000 (12:25 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Fri, 26 May 2017 13:29:06 +0000 (09:29 -0400)
Org unit setting value lookup for batches of org units, instead of the
traditional batches by setting name.

Perl live test included.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/live_t/21-batch-org-settings.t [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/YYYY.schema.batch_settings_by_org.sql [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/live_t/21-batch-org-settings.t b/Open-ILS/src/perlmods/live_t/21-batch-org-settings.t
new file mode 100644 (file)
index 0000000..27d88b5
--- /dev/null
@@ -0,0 +1,43 @@
+#!perl
+use strict; use warnings;
+use Test::More tests => 180; # 15 orgs * 12 settings
+use OpenILS::Utils::TestUtils;
+use OpenILS::Application::AppUtils;
+my $U = 'OpenILS::Application::AppUtils';
+
+diag("Tests batch org setting retrieval");
+
+my $script = OpenILS::Utils::TestUtils->new();
+$script->bootstrap;
+
+my $org_ids = [1 .. 15];
+# All settings at time of writing.  None of these have view perms.
+my @settings = qw/
+    circ.patron_search.diacritic_insensitive
+    circ.checkout_auto_renew_age
+    cat.label.font.weight
+    cat.spine.line.height
+    circ.grace.extend
+    cat.label.font.size
+    circ.booking_reservation.default_elbow_room
+    cat.spine.line.width
+    lib.info_url
+    circ.hold_go_home_interval
+    cat.label.font.family
+    cat.spine.line.margin
+/;
+
+# compare the values returned from the batch-by-org setting to the
+# traditional setting value lookup call.
+for my $setting (@settings) {
+    my %batch_settings = 
+        $U->ou_ancestor_setting_batch_by_org_insecure($org_ids, $setting);
+
+    for my $org_id (@$org_ids) {
+        my $value = $U->ou_ancestor_setting_value($org_id, $setting);
+        is($value, $batch_settings{$org_id}->{value}, 
+            "Value matches for setting $setting and org $org_id");
+    }
+}
+
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.batch_settings_by_org.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.batch_settings_by_org.sql
new file mode 100644 (file)
index 0000000..567183f
--- /dev/null
@@ -0,0 +1,24 @@
+BEGIN;
+
+CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting_batch_by_org(
+    setting_name TEXT, org_ids INTEGER[]) 
+    RETURNS SETOF actor.org_unit_setting AS 
+$FUNK$
+DECLARE
+    setting RECORD;
+    org_id INTEGER;
+BEGIN
+    /*  Returns one actor.org_unit_setting row per org unit ID provided.
+        When no setting exists for a given org unit, the setting row
+        will contain all empty values. */
+    FOREACH org_id IN ARRAY org_ids LOOP
+        SELECT INTO setting * FROM 
+            actor.org_unit_ancestor_setting(setting_name, org_id);
+        RETURN NEXT setting;
+    END LOOP;
+    RETURN;
+END;
+$FUNK$ LANGUAGE plpgsql STABLE;
+
+COMMIT;
+