Working template-based batch bib updater!
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 11 Oct 2010 16:07:47 +0000 (16:07 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 11 Oct 2010 16:07:47 +0000 (16:07 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18264 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
Open-ILS/src/perlmods/OpenILS/WWW/TemplateBatchBibUpdate.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/0434.data.merge_template_container_type.sql [new file with mode: 0644]

index f1b2303..df16b4e 100644 (file)
@@ -248,25 +248,23 @@ sub template_overlay_container {
 
     my $items = $e->search_container_biblio_record_entry_bucket_item({ bucket => $container });
 
+    my $titem;
     if (!$template) {
-        my $titem = $e->retrieve_biblio_record_entry(
-            map { $_->target_biblio_record_entry }
-            grep { $_->target_biblio_record_entry < 0 } @$items
-        );
-
+        ($titem) = grep { $_->target_biblio_record_entry < 0 } @$items;
         if (!$titem) {
             $e->rollback;
             return undef;
         }
+        $items = [grep { $_->target_biblio_record_entry > 0 } @$items];
 
-        $template = $titem->marc;
-        return $e->die_event unless ($e->delete_container_biblio_record_entry_bucket_item($titem));
+        $template = $e->retrieve_biblio_record_entry( $titem->target_biblio_record_entry )->marc;
     }
 
     my $responses = [];
+    my $some_failed = 0;
 
     $self->respond_complete(
-        $actor->request('open-ils.actor.anon_cache.set_value', $responses)->gather(1)
+        $actor->request('open-ils.actor.anon_cache.set_value', $auth, res_list => $responses)->gather(1)
     ) if ($actor);
 
     for my $item ( @$items ) {
@@ -280,36 +278,44 @@ sub template_overlay_container {
             )->[0]->{'vandelay.template_overlay_bib_record'};
         }
 
+        $some_failed++ if ($success eq 'f');
+
         if ($actor) {
             push @$responses, { record => $rec->id, success => $success };
-            $actor->request('open-ils.actor.anon_cache.set_value', $responses);
+            $actor->request('open-ils.actor.anon_cache.set_value', $auth, res_list => $responses);
         } else {
             $conn->respond({ record => $rec->id, success => $success });
         }
 
-        unless ($e->delete_container_biblio_record_entry_bucket_item($item)) {
-            $e->rollback;
-            if ($actor) {
-                push @$responses, { complete => 1, success => 'f' };
-                $actor->request('open-ils.actor.anon_cache.set_value', $responses);
-                return undef;
-            } else {
-                return { complete => 1, success => 'f' };
+        if ($success eq 't') {
+            unless ($e->delete_container_biblio_record_entry_bucket_item($item)) {
+                $e->rollback;
+                if ($actor) {
+                    push @$responses, { complete => 1, success => 'f' };
+                    $actor->request('open-ils.actor.anon_cache.set_value', $auth, res_list => $responses);
+                    return undef;
+                } else {
+                    return { complete => 1, success => 'f' };
+                }
             }
         }
     }
 
+    if ($titem && !$some_failed) {
+        return $e->die_event unless ($e->delete_container_biblio_record_entry_bucket_item($titem));
+    }
+
     if ($e->commit) {
         if ($actor) {
             push @$responses, { complete => 1, success => 't' };
-            $actor->request('open-ils.actor.anon_cache.set_value', $responses);
+            $actor->request('open-ils.actor.anon_cache.set_value', $auth, res_list => $responses);
         } else {
             return { complete => 1, success => 't' };
         }
     } else {
         if ($actor) {
             push @$responses, { complete => 1, success => 'f' };
-            $actor->request('open-ils.actor.anon_cache.set_value', $responses);
+            $actor->request('open-ils.actor.anon_cache.set_value', $auth, res_list => $responses);
         } else {
             return { complete => 1, success => 'f' };
         }
index 5e88fea..b51d69a 100644 (file)
@@ -138,7 +138,10 @@ sub handler {
     # create the new container for the records and the template
     my $bucket = Fieldmapper::container::biblio_record_entry_bucket->new;
     $bucket->owner($usr->id);
-    $bucket->name('Temporary Merge Bucket');
+    $bucket->btype('template_merge');
+
+    my $bname = $cgi->param('bname') || 'Temporary Merge Bucket '. localtime() . ' ' . $usr->id;
+    $bucket->name($bname);
 
     $bucket = $e->request('open-ils.cstore.direct.container.biblio_record_entry_bucket.create', $bucket )->gather(1);
 
@@ -159,8 +162,8 @@ sub handler {
 
     # fire the background bucket processor
     my $cache_key = OpenSRF::AppSession
-        ->create('open-ils.actor')
-        ->request('open-ils.cat.container.template_overlay.background', $bucket->id)
+        ->create('open-ils.cat')
+        ->request('open-ils.cat.container.template_overlay.background', $authid, $bucket->id)
         ->gather(1);
 
     return show_processing_template($r, $bucket->id, \@records, $cache_key);
@@ -221,29 +224,29 @@ sub show_processing_template {
             dojo.require('fieldmapper.dojoData');
             dojo.require('openils.User');
             dojo.require('openils.CGI');
-            dojo.require('openils.widget.PogressDialog');
+            dojo.require('openils.widget.ProgressDialog');
 
             var cgi = new openils.CGI();
             var u = new openils.User({ authcookie : 'ses' });
 
-            var rec_count = $rec_string;
-            var cache_key = '$cache_key';
-
             dojo.addOnLoad(function () {
                 progress_dialog.show(true);
-                progress_dialog.update({maximum:rec_ids.length});
+                progress_dialog.update({maximum:$rec_string});
 
-                setInterval( function() {
+                var interval;
+                interval = setInterval( function() {
                     fieldmapper.standardRequest(
                         ['open-ils.actor','open-ils.actor.anon_cache.get_value'],
                         { async : false,
-                          params: [ cache_key ],
+                          params: [ u.authtoken, 'res_list' ],
+                          onerror : function (r) { progress_dialog.hide(); },
                           onresponse : function (r) {
                             var counter = { success : 0, fail : 0, total : 0 };
                             dojo.forEach( openils.Util.readResponse(r), function(x) {
                                 if (x.complete) {
+                                    clearInterval(interval);
                                     progress_dialog.hide();
-                                    if (x.success == 'f') dojo.byId('complete_msg').innerHTML = 'Overlay completed successfully';
+                                    if (x.success == 't') dojo.byId('complete_msg').innerHTML = 'Overlay completed successfully';
                                     else dojo.byId('complete_msg').innerHTML = 'Overlay did not complet successfully';
                                 } else {
                                     counter.total++;
@@ -487,34 +490,49 @@ sub show_template {
         <div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data" action="" method="POST">
                 <script type='dojo/method' event='onSubmit'>
                     var rec = ruleset_to_record();
+
+                    // no-op to force replace mode
+                    rec.appendFields(
+                        new MARC.Field ({
+                            tag : '905',
+                            ind1 : ' ',
+                            ind2 : ' ',
+                            subfields : [['r','901c']]
+                        })
+                    );
+
                     dojo.byId('template_value').value = rec.toXmlString();
                     return true;
                 </script>
 
             <input type='hidden' id='template_value' name='template'/>
 
-            <div>
-                <label for='bucketList'>Batch update records in Bucket:</label>
-                <div name='containerid' jsId='bucketList' dojoType='dijit.form.FilteringSelect' store='bucketStore' searchAttr='name' id='bucketList'>
-                    <script type='dojo/method' event='postCreate'>
-                        if (cgi.param('containerid')) this.attr('value',cgi.param('containerid'));
-                    </script>
-                </div>
-            </div>
-    
-            <div style='text-align: center; width: 50%;'>or</div>
-    
-            <div>
-                <label for='idfile'>Batch update records from column <input style='width:75px;' type='text' dojoType='dijit.form.NumberSpinner' name='idcolumn' value='0' constraints='{min:0,max:100,places:0}' /> (starting from 0) in CSV file:</label>
-                <input id='idfile' type="file" name="idfile"/>
-            </div>
-    
-            <div style='text-align: center; width: 50%;'>or</div>
-
-            <label for='recid'>Test Ruleset by applying to one record:</label> <input name='recid' style='width:75px;' type='text' dojoType='dijit.form.NumberTextBox' name='id' value='' constraints='{min:0}' />
-
-            <br/>
-            <br/>
+            <table>
+                <tr>
+                    <th>Optional merge queue name:</th>
+                    <td><input id='bucketName' type='text' dojoType='dijit.form.TextBox' name='bname' value=''/></td>
+                </tr>
+                <tr>
+                    <th>Batch update records in Bucket:</th>
+                    <td>
+                        <div name='containerid' jsId='bucketList' dojoType='dijit.form.FilteringSelect' store='bucketStore' searchAttr='name' id='bucketList'>
+                            <script type='dojo/method' event='postCreate'>
+                                if (cgi.param('containerid')) this.attr('value',cgi.param('containerid'));
+                            </script>
+                        </div>
+                    </td>
+                </tr>
+                <tr><th colspan='2'><div style='text-align: center;'>or</div></hd></tr>
+                <tr>
+                    <th>Batch update records from CSV file:</th>
+                    <td><input id='idfile' type="file" name="idfile"/><br/>Column <input style='width:75px;' type='text' dojoType='dijit.form.NumberSpinner' name='idcolumn' value='0' constraints='{min:0,max:100,places:0}' /> starting from 0</td>
+                </tr>
+                <tr><th colspan='2'><div style='text-align: center;'>or</div></th></tr>
+                <tr>
+                    <th>Test Ruleset by applying to one record:</th>
+                    <td><input name='recid' style='width:75px;' type='text' dojoType='dijit.form.NumberTextBox' name='id' value='' constraints='{min:0}' /></td>
+                </tr>
+            </table>
 
             <button type="submit" dojoType='dijit.form.Button'>Apply Ruleset</button>
 
@@ -541,10 +559,9 @@ sub show_template {
                         <th>Rule Type</th>
                         <td name='typeSelectContainer'>
                             <select name='typeSelect'>
+                                <option value='r'>Replace</option>
                                 <option value='a'>Add</option>
                                 <option value='d'>Delete</option>
-                                <option value='r'>Replace</option>
-                                <option value='p'>Preserve</option>
                             </select>
                         </td>
                     </tr>
index 9dc9251..dee49b8 100644 (file)
@@ -2345,6 +2345,7 @@ INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('misc
 INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('staff_client', oils_i18n_gettext('staff_client', 'General Staff Client container', 'cbrebt', 'label'));
 INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('bookbag', oils_i18n_gettext('bookbag', 'Book Bag', 'cbrebt', 'label'));
 INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('reading_list', oils_i18n_gettext('reading_list', 'Reading List', 'cbrebt', 'label'));
+INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('template_merge',oils_i18n_gettext('template_merge','Template Merge Container', 'cbrebt', 'label'));
 
 INSERT INTO container.user_bucket_type (code,label) VALUES ('misc', oils_i18n_gettext('misc', 'Miscellaneous', 'cubt', 'label'));
 INSERT INTO container.user_bucket_type (code,label) VALUES ('folks', oils_i18n_gettext('folks', 'Friends', 'cubt', 'label'));
diff --git a/Open-ILS/src/sql/Pg/upgrade/0434.data.merge_template_container_type.sql b/Open-ILS/src/sql/Pg/upgrade/0434.data.merge_template_container_type.sql
new file mode 100644 (file)
index 0000000..1a0fd0f
--- /dev/null
@@ -0,0 +1,9 @@
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0434');
+
+INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('template_merge','Template Merge Container');
+
+COMMIT;
+