SIP2Gateway DB configs wip
authorBill Erickson <berickxx@gmail.com>
Wed, 25 Mar 2020 14:28:15 +0000 (10:28 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 28 Oct 2020 18:57:39 +0000 (14:57 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/SIP2Gateway.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.sip-config.sql

index 2b88721..587d557 100644 (file)
@@ -113,7 +113,7 @@ my $json = JSON::XS->new;
 $json->ascii(1);
 $json->allow_nonref(1);
 
-my $SIP_DATE_FORMAT = "%Y%m%d    %H%M%S";
+use constant SIP_DATE_FORMAT => "%Y%m%d    %H%M%S";
 
  # TODO: move to config / database
 my $config = {
@@ -162,6 +162,7 @@ sub import {
     $osrf_config = shift;
 }
 
+my $config;
 my $init_complete = 0;
 sub init {
     return if $init_complete;
@@ -170,12 +171,48 @@ sub init {
     OpenSRF::System->bootstrap_client(config_file => $osrf_config);
     OpenILS::Utils::CStoreEditor->init;
 
-    return Apache2::Const::OK;
+    my $e = new_editor();
+
+    my $settings = $e->retrieve_all_config_sip_setting;
+
+    $config = {
+        institutions => []
+    };
+
+    # Institution specific settings.
+    # In addition to the options, this tells us what institutions we support.
+    for my $set (grep {$_->institution ne '*'} @$settings) {
+        my $inst = $set->institution;
+        my $value = $json->decode($set->value);
+        my $name = $set->name;
+
+        my ($inst_conf) = 
+            grep {$_->id eq $inst} @{$config->{institutions}} ||
+            {   id => $inst,
+                currency => 'USD',
+                supports => [],
+                options => {}
+            };
+
+        $inst_conf->{options}->{$name} = $value;
+    }
+
+    # Global options only are only used when they do not replace
+    # institution-specific options.
+    for my $set (grep {$_->institution eq '*'} @$settings) {
+        my $name = $set->name;
+        my $value = $json->decode($set->value);
+
+        for my $inst_conf (@{$config->{institutions}}) {
+            $inst_conf->{options}->{$name} = $value
+                unless exists $inst_conf->{options}->{$name};
+        }
+    }
 }
 
 sub sipdate {
     my $date = shift || DateTime->now;
-    return $date->strftime($SIP_DATE_FORMAT);
+    return $date->strftime(SIP_DATE_FORMAT);
 }
 
 # False == 'N'
index 1d094d5..39e9bee 100644 (file)
@@ -31,14 +31,20 @@ INSERT INTO actor.passwd_type (code, name, login, crypt_algo, iter_count)
     VALUES ('sip2', 'SIP2 Client Password', FALSE, 'bf', 5);
 
 /* EXAMPLE SETTINGS
+
+-- Example linking a SIP password to the 'admin' account.
+SELECT actor.set_passwd(1, 'sip2', 'sip_password');
+
 INSERT INTO config.sip_setting (institution, name, value)
 VALUES 
     ('*',       'allow_sc_status_before_login', 'true'),
+    ('*',       'currency', 'USD'),
     ('example', 'due_date_use_sip_date_format', 'false'),
     ('example', 'patron_status_permit_loans', 'false'),
     ('example', 'patron_status_permit_all', 'false'), 
     ('example', 'msg64_hold_items_available', 'false')
-);
+;
+
 */
 
 COMMIT;