LP1209291 vandelay item import defaults
authorBill Erickson <berick@esilibrary.com>
Thu, 8 Aug 2013 13:06:12 +0000 (09:06 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 8 Aug 2013 13:06:12 +0000 (09:06 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm
Open-ILS/src/sql/Pg/999.functions.global.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-item-import-defaults.sql

index 0524ea0..1c98be2 100644 (file)
@@ -1610,9 +1610,9 @@ sub import_record_asset_list_impl {
         );
 
         # if any items have no call_number label and a value should be
-        # applied automatically (via org settings), keep a record-level
-        # copy handy so we can use the same call number for all such copies
-        my $auto_callnumber;
+        # applied automatically (via org settings), we want to use the same
+        # call number label for every copy per org per record.
+        my $auto_callnumber = {};
 
         for my $item_id (@$item_ids) {
             my $e = new_editor(requestor => $requestor, xact => 1);
@@ -1766,7 +1766,7 @@ sub import_record_asset_list_impl {
 
                 # appply defaults values from org settings as needed
                 # if $auto_callnumber is unset, it will be set within
-                apply_import_item_defaults($e, $item, \$auto_callnumber);
+                apply_import_item_defaults($e, $item, $auto_callnumber);
 
                 if($evt) {
                     $$report_args{evt} = $evt;
@@ -1866,7 +1866,7 @@ sub import_record_asset_list_impl {
 }
 
 sub apply_import_item_defaults {
-    my ($e, $item, $auto_cn_ref) = @_;
+    my ($e, $item, $auto_cn) = @_;
     my $org = $item->owning_lib || $item->circ_lib;
     my %c = %item_defaults_cache;  
 
@@ -1900,16 +1900,16 @@ sub apply_import_item_defaults {
 
         if ($set->('call_number.auto')) {
 
-            if (!$$auto_cn_ref) {
+            if (!$auto_cn->{$org}) {
                 my $pfx = $set->('call_number.prefix') || 'VAN';
 
                 # use the ID of the first item to differentiate this 
                 # call number from others linked to the same record
-                $$auto_cn_ref = $pfx . $item->record . $item->id;
+                $auto_cn->{$org} = $pfx . $item->record . $item->id;
             }
 
-            $logger->info("vl: using auto call number $$auto_cn_ref");
-            $item->call_number($$auto_cn_ref);
+            $logger->info("vl: using auto call number ".$auto_cn->{$org});
+            $item->call_number($auto_cn->{$org});
 
         } else {
             $logger->error("vl: no call number or default for item ".$item->id);
index 8cb6c2d..4ff7498 100644 (file)
@@ -1873,6 +1873,15 @@ BEGIN
                         'vandelay.item.circ_modifier.default', 
                         attr_set.owning_lib
                     );
+
+                -- make sure the value from the org setting is still valid
+                PERFORM 1 FROM config.circ_modifier WHERE code = attr_set.circ_modifier;
+                IF NOT FOUND THEN
+                    attr_set.import_error := 'import.item.invalid.circ_modifier';
+                    attr_set.error_detail := tmp_attr_set.circ_mod;
+                    RETURN NEXT attr_set; CONTINUE; 
+                END IF;
+
             ELSE 
 
                 SELECT code INTO attr_set.circ_modifier FROM config.circ_modifier WHERE code = tmp_attr_set.circ_mod;
@@ -1900,6 +1909,14 @@ BEGIN
                         'vandelay.item.copy_location.default', 
                         attr_set.owning_lib
                     );
+
+                -- make sure the value from the org setting is still valid
+                PERFORM 1 FROM asset.copy_location WHERE id = attr_set.location;
+                IF NOT FOUND THEN
+                    attr_set.import_error := 'import.item.invalid.location';
+                    attr_set.error_detail := tmp_attr_set.cs;
+                    RETURN NEXT attr_set; CONTINUE; 
+                END IF;
             ELSE
 
                 -- search up the org unit tree for a matching copy location
@@ -1972,6 +1989,7 @@ $$ LANGUAGE PLPGSQL;
 
 
 
+
 CREATE OR REPLACE FUNCTION vandelay.ingest_bib_items ( ) RETURNS TRIGGER AS $func$
 DECLARE
     attr_def    BIGINT;
index 540dce1..905f926 100644 (file)
@@ -373,6 +373,15 @@ BEGIN
                         'vandelay.item.circ_modifier.default', 
                         attr_set.owning_lib
                     );
+
+                -- make sure the value from the org setting is still valid
+                PERFORM 1 FROM config.circ_modifier WHERE code = attr_set.circ_modifier;
+                IF NOT FOUND THEN
+                    attr_set.import_error := 'import.item.invalid.circ_modifier';
+                    attr_set.error_detail := tmp_attr_set.circ_mod;
+                    RETURN NEXT attr_set; CONTINUE; 
+                END IF;
+
             ELSE 
 
                 SELECT code INTO attr_set.circ_modifier FROM config.circ_modifier WHERE code = tmp_attr_set.circ_mod;
@@ -400,6 +409,14 @@ BEGIN
                         'vandelay.item.copy_location.default', 
                         attr_set.owning_lib
                     );
+
+                -- make sure the value from the org setting is still valid
+                PERFORM 1 FROM asset.copy_location WHERE id = attr_set.location;
+                IF NOT FOUND THEN
+                    attr_set.import_error := 'import.item.invalid.location';
+                    attr_set.error_detail := tmp_attr_set.cs;
+                    RETURN NEXT attr_set; CONTINUE; 
+                END IF;
             ELSE
 
                 -- search up the org unit tree for a matching copy location