LP#1379815 Better error handling
authorRemington Steed <rjs7@calvin.edu>
Tue, 7 Jul 2015 20:08:23 +0000 (16:08 -0400)
committerBen Shum <bshum@biblio.org>
Wed, 19 Aug 2015 16:14:09 +0000 (12:14 -0400)
This commit adds more thorough error checking and handling for the stat
cat import feature, including adding two custom import error codes.

Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/YYYY.schema.vandelay-stat-cat-import.sql

index b5ae6f6..a93a51e 100644 (file)
@@ -1931,16 +1931,28 @@ sub import_record_asset_list_impl {
                             push (@$stat_cat_entries, $stat_cat_entry) if $stat_cat_entry;
                         }
                     } else {
-                        $logger->warn("Bad format for stat cat data ($stat_cat_pair), should be like: CAT 1|VALUE 1");
+                        $$report_args{import_error} = "import.item.invalid.stat_cat_format";
+                        last;
                     }
 
                     if (!$stat_cat or !$stat_cat_entry) {
-                        $logger->warn("Invalid stat cat data ($stat_cat_pair): " . $e->die_event);
+                        $$report_args{import_error} = "import.item.invalid.stat_cat_data";
+                        last;
                     }
                 }
+                if ($$report_args{import_error}) {
+                    $logger->error("vl: invalid stat cat data: " . $item->stat_cat_data);
+                    respond_with_status($report_args);
+                    next;
+                }
                 $copy->stat_cat_entries( $stat_cat_entries );
                 $copy->ischanged(1);
                 $evt = OpenILS::Application::Cat::AssetCommon->update_copy_stat_entries($e, $copy, 0, 1); #delete_stats=0, add_or_update_only=1
+                if($evt) {
+                    $$report_args{evt} = $evt;
+                    respond_with_status($report_args);
+                    next;
+                }
             }
 
             # set the import data on the import item
index 0ce75a4..3e30e7c 100644 (file)
@@ -10399,6 +10399,10 @@ INSERT INTO vandelay.import_error ( code, description ) VALUES (
     'import.item.invalid.circ_as_type', oils_i18n_gettext('import.item.invalid.circ_as_type', 'Invalid value for "circ_as_type"', 'vie', 'description') );
 INSERT INTO vandelay.import_error ( code, description ) VALUES ( 
     'import.record.perm_failure', oils_i18n_gettext('import.record.perm_failure', 'Perm failure creating a record', 'vie', 'description') );
+INSERT INTO vandelay.import_error ( code, description ) VALUES (
+    'import.item.invalid.stat_cat_format', oils_i18n_gettext('import.item.invalid.stat_cat_format', 'Bad format for stat cat data, should be like: CAT 1|VALUE 1', 'vie', 'description') );
+INSERT INTO vandelay.import_error ( code, description ) VALUES (
+    'import.item.invalid.stat_cat_data', oils_i18n_gettext('import.item.invalid.stat_cat_data', 'Invalid stat cat data', 'vie', 'description') );
 
 -- Event def for email notice for hold cancelled due to lack of target -----
 
index 0256b1b..57b0a45 100644 (file)
@@ -2,6 +2,11 @@ BEGIN;
 
 --SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
 
+INSERT INTO vandelay.import_error ( code, description ) VALUES (
+    'import.item.invalid.stat_cat_format', oils_i18n_gettext('import.item.invalid.stat_cat_format', 'Bad format for stat cat data, should be like: CAT 1|VALUE 1', 'vie', 'description') );
+INSERT INTO vandelay.import_error ( code, description ) VALUES (
+    'import.item.invalid.stat_cat_data', oils_i18n_gettext('import.item.invalid.stat_cat_data', 'Invalid stat cat data', 'vie', 'description') );
+
 ALTER TABLE vandelay.import_item_attr_definition
     ADD COLUMN stat_cat_data TEXT;