onward and upward
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 May 2005 13:19:12 +0000 (13:19 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 May 2005 13:19:12 +0000 (13:19 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@719 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/StatCat.pm
Open-ILS/src/perlmods/OpenILS/Application/Search.pm
Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
Open-ILS/src/perlmods/OpenILS/Utils/ModsParser.pm
Open-ILS/src/templates/opac/pages/chunks/body_header.ttk
Open-ILS/src/templates/opac/pages/chunks/search_bar_form.ttk
Open-ILS/src/templates/opac/pages/chunks/status_bar.ttk
Open-ILS/src/templates/opac/pages/record_result.ttk

index 12c7189..1ed1a7c 100644 (file)
@@ -41,7 +41,7 @@ sub update_patron {
 
        try {
                # create/update the patron first so we can use his id
-               if( $patron->isnew() ) {
+               if($patron->isnew()) {
                        $new_patron = _add_patron(
                                        $session, _clone_patron($patron));
                } else { 
@@ -50,6 +50,8 @@ sub update_patron {
 
                $new_patron = _add_update_addresses($session, $patron, $new_patron);
                $new_patron = _add_update_cards($session, $patron, $new_patron);
+               $new_patron = _add_survey_responses($session, $patron, $new_patron);
+               $new_patron     = _create_stat_maps($user_session, $patron, $new_patron);
 
                # re-update the patron if anything has happened to him during this process
                if($new_patron->ischanged()) {
@@ -97,6 +99,11 @@ sub flesh_user {
                        $user->id() );
        $user->addresses( $add_req->gather(1) );
 
+       my $stat_req = $session->request(
+               "open-ils.storage.direct.actor.stat_cat_entry_user_map.search.target_usr",
+               $user->id() );
+       $user->stat_cat_entries($stat_req->gather(1));
+
        if($kill) { $session->disconnect(); }
        $user->clear_passwd();
        warn Dumper $user;
@@ -130,6 +137,7 @@ sub _clone_patron {
        $new_patron->clear_isnew();
        $new_patron->clear_changed();
        $new_patron->clear_deleted();
+       $new_patron->clear_stat_cat_entries();
 
        return $new_patron;
 }
@@ -147,16 +155,20 @@ sub _add_patron {
        my $id = $req->gather(1);
        if(!$id) { throw OpenSRF::EX::ERROR ("Unable to create new user"); }
        warn "Created new patron with id $id\n";
-       $patron->id($id);
 
-       return $patron;
+       # retrieve the patron from the db to collect defaults
+       my $ureq = $session->request(
+                       "open-ils.storage.direct.actor.user.retrieve",
+                       $id);
+       return $ureq->gather(1);
 }
 
 
 sub _update_patron {
        my( $session, $patron) = @_;
 
-       warn "updating patron " . $patron->usrname() . "\n";
+       warn "updating patron " . Dumper($patron) . "\n";
+
        my $req = $session->request(
                "open-ils.storage.direct.actor.user.update",$patron );
        my $status = $req->gather(1);
@@ -351,6 +363,60 @@ sub _delete_address {
 
 
 
+sub _add_survey_responses {
+       my ($session, $patron, $new_patron) = @_;
+
+       warn "updating responses for user " . $new_patron->id . "\n";
+
+       my $responses = $patron->survey_responses;
+       for my $resp( @$responses ) {
+               $resp->usr($new_patron->id);
+       }
+
+       my $status = $apputils->simple_scalar_request(
+               "open-ils.circ", 
+               "open-ils.circ.survey.submit.user_id",
+               $responses );
+
+       return $new_patron;
+}
+
+
+sub _create_stat_maps {
+
+       my($user_session, $patron, $new_patron) = @_;
+       my $maps = $patron->stat_cat_entries();
+
+       my $session = OpenSRF::AppSession->create("open-ils.circ");
+
+       for my $map (@$maps) {
+
+               next unless($map->isnew() || $map->ischanged());
+
+               my $method = "open-ils.circ.stat_cat.actor.user_map.update";
+               if($map->isnew()) {
+                       $method = "open-ils.circ.stat_cat.actor.user_map.create";
+               }
+
+               warn "Updating stat entry with method $method and 
+                       session $user_session and map $map\n";
+
+               my $req = $session->request($method, $user_session, $map);
+               my $status = $req->gather(1);
+
+               warn "Updated\n";
+
+               if(!$status) {
+                       throw OpenSRF::EX::ERROR 
+                               ("Error updating stat map with method $method");        
+               }
+       }
+
+       $session->disconnect();
+       return $new_patron;
+}
+
+
 
 __PACKAGE__->register_method(
        method  => "search_username",
@@ -367,6 +433,8 @@ sub search_username {
 }
 
 
+
+
 __PACKAGE__->register_method(
        method  => "user_retrieve_by_barcode",
        api_name        => "open-ils.actor.user.fleshed.retrieve_by_barcode",
@@ -392,11 +460,27 @@ sub user_retrieve_by_barcode {
 
 
 
+__PACKAGE__->register_method(
+       method  => "get_user_by_id",
+       api_name        => "open-ils.actor.user.retrieve",);
+
+sub get_user_by_id {
+       my ($self, $client, $user_session, $id) = @_;
+
+       my $user_obj = $apputils->check_user_session( $user_session ); 
+
+       return $apputils->simple_scalar_request(
+               "open-ils.storage",
+               "open-ils.storage.direct.actor.user.retrieve",
+               $id );
+}
+
+
 
 __PACKAGE__->register_method(
        method  => "get_org_types",
-       api_name        => "open-ils.actor.org_types.retrieve",
-);
+       api_name        => "open-ils.actor.org_types.retrieve",);
+
 my $org_types;
 sub get_org_types {
        my($self, $client) = @_;
@@ -409,6 +493,7 @@ sub get_org_types {
 }
 
 
+
 __PACKAGE__->register_method(
        method  => "get_user_profiles",
        api_name        => "open-ils.actor.user.profiles.retrieve",
@@ -596,6 +681,15 @@ sub patron_adv_search {
        use Data::Dumper;
        warn "patron adv with $staff_login and search " . 
                Dumper($search_hash) . "\n";
+
+       my $session = OpenSRF::AppSession->create("open-ils.storage");
+       my $req = $session->request(
+               "open-ils.storage.actor.user.crazy_search", $search_hash);
+
+       my $ans = $req->gather(1);
+       $session->disconnect();
+       return $ans;
+
 }
 
 
index 91dcd99..c1bdfe1 100644 (file)
@@ -8,19 +8,119 @@ use Time::HiRes qw(time);
 use OpenSRF::EX qw(:try);
 use JSON;
 use OpenILS::Utils::Fieldmapper;
+use XML::LibXML;
+use Data::Dumper;
+use OpenILS::Utils::FlatXML;
 
 my $apputils = "OpenILS::Application::AppUtils";
 
 my $utils = "OpenILS::Application::Cat::Utils";
 
 
+__PACKAGE__->register_method(
+       method  => "biblio_record_tree_import",
+       api_name        => "open-ils.cat.biblio.record.tree.import",
+);
+
+sub biblio_record_tree_import {
+       my( $self, $client, $user_session, $tree) = @_;
+       my $user_obj = $apputils->check_user_session($user_session);
+
+       warn "importing new record " . Dumper($tree) . "\n";
+
+       my $nodeset = $utils->tree2nodeset($tree);
+       warn "turned into nodeset " . Dumper($nodeset) . "\n";
+
+       # copy the doc so that we can mangle the namespace.  
+       my $marcxml = OpenILS::Utils::FlatXML->new()->nodeset_to_xml($nodeset);
+       my $copy_marcxml = XML::LibXML->new->parse_string($marcxml);
+
+       $marcxml->documentElement->setNamespace( "http://www.loc.gov/MARC21/slim", "marc", 1 );
+       my $tcn;
+
+       my $xpath = '//controlfield[@tag="001"]';
+       $tcn = $marcxml->documentElement->findvalue($xpath);
+       my $tcn_source = "External";
+       my $source = 2; # system local source
+
+       warn "Starting db session in import\n";
+       my $session = $apputils->start_db_session();
+
+       if(!$tcn) {
+               $xpath = '//datafield[@tag="020"]';
+               $tcn = $marcxml->documentElement->findvalue($xpath);
+               $tcn_source = "ISBN";
+               if(_tcn_exists($session, $tcn)) {$tcn = undef;}
+       }
+
+       if(!$tcn) { 
+               $xpath = '//datafield[@tag="022"]';
+               $tcn = $marcxml->documentElement->findvalue($xpath);
+               $tcn_source = "ISSN";
+               if(_tcn_exists($session, $tcn)) {$tcn = undef;}
+       }
+
+       if(!$tcn) {
+               $xpath = '//datafield[@tag="010"]';
+               $tcn = $marcxml->documentElement->findvalue($xpath);
+               $tcn_source = "LCCN";
+               if(_tcn_exists($session, $tcn)) {$tcn = undef;}
+       }
+
+       if(!$tcn) {
+               $xpath = '//datafield[@tag="035"]';
+               $tcn = $marcxml->documentElement->findvalue($xpath);
+               $tcn_source = "System";
+               if(_tcn_exists($session, $tcn)) {$tcn = undef;}
+       }
+
+       warn "Record import with tcn: $tcn\n";
+
+       my $record = Fieldmapper::biblio::record_entry->new;
+
+       $record->source($source);
+       $record->tcn_source($tcn_source);
+       $record->tcn_value($tcn);
+       $record->creator($user_obj->id);
+       $record->editor($user_obj->id);
+       $record->marc($copy_marcxml->toString);
+
+
+       my $req = $session->request(
+               "open-ils.storage.direct.biblio.record_entry.create",
+               $record );
+       my $id = $req->gather(1);
+
+       my $wreq = $session->request("open-ils.worm.wormize", $id);
+       $wreq->gather(1);
+
+       $apputils->commit_db_session($session);
+
+       return $self->biblio_record_tree_retrieve($client, $id);
+}
+
+sub _tcn_exists {
+       my $session = shift;
+       my $tcn = shift;
+
+       if(!$tcn) {return 0;}
+
+       my $req = $session->request(      
+               "open-ils.storage.direct.biblio.record_entry.search.tcn_value",
+               $tcn );
+       my $recs = $req->gather(1);
+
+       if($recs and $recs->[0]) {
+               return 1;
+       }
+       return 0;
+}
+
 
 
 __PACKAGE__->register_method(
        method  => "biblio_record_tree_retrieve",
        api_name        => "open-ils.cat.biblio.record.tree.retrieve",
-       argc            => 1, 
-       note            => "Returns the tree associated with the nodeset of the given doc id"
 );
 
 sub biblio_record_tree_retrieve {
@@ -63,9 +163,6 @@ __PACKAGE__->register_method(
 sub biblio_record_tree_commit {
 
        my( $self, $client, $user_session,  $tree ) = @_;
-       new Fieldmapper::biblio::record_node ($tree);
-
-       use Data::Dumper;
 
        throw OpenSRF::EX::InvalidArg 
                ("Not enough args to to open-ils.cat.biblio.record.tree.commit")
@@ -90,7 +187,7 @@ sub biblio_record_tree_commit {
 
        # turn the tree into a nodeset
        my $nodeset = $utils->tree2nodeset($tree);
-       $nodeset = $utils->clean_nodeset( $nodeset );
+       $nodeset = $utils->clean_nodeset($nodeset);
 
        if(!defined($docid)) { # be sure
                for my $node (@$nodeset) {
@@ -402,61 +499,6 @@ sub _build_volume_list {
 }
 
 
-
-
-=head
-__PACKAGE__->register_method(
-       method  => "generic_edit_copies_volumes",
-       api_name        => "open-ils.cat.asset.volume.batch.update",
-);
-
-__PACKAGE__->register_method(
-       method  => "generic_edit_copies_volumes",
-       api_name        => "open-ils.cat.asset.volume.batch.delete",
-);
-
-__PACKAGE__->register_method(
-       method  => "generic_edit_copies_volumes",
-       api_name        => "open-ils.cat.asset.copy.batch.update",
-);
-
-__PACKAGE__->register_method(
-       method  => "generic_edit_copies_volumes",
-       api_name        => "open-ils.cat.asset.copy.batch.delete",
-);
-
-
-sub generic_edit_copies_volumes {
-
-       my( $self, $client, $user_session, $items ) = @_;
-
-       my $method = $self->api_name;
-       $method =~ s/open-ils\.cat/open-ils\.storage\.direct/og;
-       warn "our method is $method\n";
-
-       my $user_obj = 
-               OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
-       
-       warn "updating editor info\n";
-
-       for my $item (@$items) {
-               $item->editor( $user_obj->id );
-       }
-
-       my $session = OpenILS::Application::AppUtils->start_db_session;
-       my $request = $session->request( $method, @$items );
-       my $result = $request->gather(1);
-
-       OpenILS::Application::AppUtils->commit_db_session($session);
-
-       warn "looks like we succeeded\n";
-       return $result;
-}
-
-=cut
-
-
-
 # -----------------------------------------------------------------
 # Fleshed volume tree batch add/update.  This does everything a 
 # volume tree could want, add, update, delete
@@ -481,7 +523,15 @@ sub volume_tree_fleshed_update {
 
                my $update_copy_list = $volume->copies;
 
-               if( $volume->isnew ) {
+
+               if( $volume->isdeleted) {
+                       my $status = _delete_volume($session, $volume);
+                       if(!$status) {
+                               throw OpenSRF::EX::ERROR
+                                       ("Volume delete failed for volume " . $volume->id);
+                       }
+
+               } elsif( $volume->isnew ) {
 
                        $volume->clear_id;
                        $volume->editor($user_obj->id);
@@ -489,30 +539,34 @@ sub volume_tree_fleshed_update {
                        $volume = _add_volume($session, $volume);
 
                } elsif( $volume->ischanged ) {
+
                        $volume->editor($user_obj->id);
                        _update_volume($session, $volume);
-
-               } elsif( $volume->isdeleted) {
-                       return _delete_volume($session, $volume);
                }
 
-               for my $copy (@{$update_copy_list}) {
-
-                       $copy->editor($user_obj->id);
-                       warn "updating copy for volume " . $volume->id . "\n";
-                       if( $copy->isnew ) {
-
-                               $copy->clear_id;
-                               $copy->call_number($volume->id);
-                               $copy->creator($user_obj->id);
-                               $copy = _fleshed_copy_update($session,$copy,$user_obj->id);
-
-                       } elsif( $copy->ischanged ) {
-                               $copy->call_number($volume->id);
-                               $copy = _fleshed_copy_update($session, $copy, $user_obj->id);
 
-                       } elsif( $copy->isdeleted ) {
-                               _fleshed_copy_update($session, $copy, $user_obj->id);
+               if( ! $volume->isdeleted ) {
+                       for my $copy (@{$update_copy_list}) {
+       
+                               $copy->editor($user_obj->id);
+                               warn "updating copy for volume " . $volume->id . "\n";
+       
+                               if( $copy->isnew ) {
+       
+                                       $copy->clear_id;
+                                       $copy->call_number($volume->id);
+                                       $copy->creator($user_obj->id);
+                                       $copy = _fleshed_copy_update($session,$copy,$user_obj->id);
+       
+                               } elsif( $copy->ischanged ) {
+                                       $copy->call_number($volume->id);
+                                       $copy = _fleshed_copy_update($session, $copy, $user_obj->id);
+       
+                               } elsif( $copy->isdeleted ) {
+                                       warn "Deleting copy " . $copy->id . " for volume " . $volume->id . "\n";
+                                       my $status = _fleshed_copy_update($session, $copy, $user_obj->id);
+                                       warn "Copy delete returned a status of $status\n";
+                               }
                        }
                }
        }
@@ -521,35 +575,26 @@ sub volume_tree_fleshed_update {
 }
 
 
-#XXX make me
 sub _delete_volume {
        my( $session, $volume ) = @_;
 
-       $volume = _find_volume($session, $volume);
+       #$volume = _find_volume($session, $volume);
+       warn "Deleting volume " . $volume->id . "\n";
 
-#      my $copies = $session->request(
-#              "open-ils.storage.direct.asset.copy.search.call_number",
-#              $volume-id )->gather(1);
-#      if(@$copies) {
-#              throw OpenSRF::EX::ERROR 
-#                      ("Cannot remove volume with copies attached");
-#      }
+       my $copies = $session->request(
+               "open-ils.storage.direct.asset.copy.search.call_number",
+               $volume->id )->gather(1);
+       if(@$copies) {
+               throw OpenSRF::EX::ERROR 
+                       ("Cannot remove volume with copies attached");
+       }
 
+       my $req = $session->request(
+               "open-ils.storage.direct.asset.call_number.delete",
+               $volume );
+       return $req->gather(1);
 }
 
-=head
-sub _find_volume {
-       my( $session, $volume ) = @_;
-       my $cn_req = $session->request( 
-               'open-ils.storage.direct.asset.call_number.search' =>
-            {       owning_lib      => $volume->owning_lib,
-                    label           => $volume->label,
-                    record          => $volume->record,
-               }); 
-
-       return $cn_req->gather(1);
-}
-=cut
 
 sub _update_volume {
        my($session, $volume) = @_;
@@ -582,120 +627,6 @@ sub _add_volume {
 
 
 
-=head
-__PACKAGE__->register_method(
-       method  => "volume_tree_add",
-       api_name        => "open-ils.cat.asset.volume.tree.batch.add",
-);
-
-sub volume_tree_add {
-
-       my( $self, $client, $user_session, $volumes ) = @_;
-       return undef unless $volumes;
-
-       use Data::Dumper;
-       warn "Volumes:\n";
-       warn Dumper $volumes;
-
-       my $user_obj = 
-               OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
-
-       warn "volume_tree_add creating new db session\n";
-
-       my $session = OpenILS::Application::AppUtils->start_db_session;
-
-       for my $volume (@$volumes) {
-
-               warn "Looping on volumes\n";
-
-               my $new_copy_list = $volume->copies;
-
-               warn "Searching for volume with ".$volume->owning_lib . " " .
-                       $volume->label . " " . $volume->record . "\n";
-
-               my $cn = _find_volume($session, $volume);
-
-               
-               if($cn) {
-
-                       $volume = $cn;
-                       $volume->editor( $user_obj->id );
-
-               } else {
-
-                       $volume->creator( $user_obj->id );
-                       $volume->editor( $user_obj->id );
-                       $volume = _add_volume($volume);
-
-               }
-
-               for my $copy (@{$new_copy_list}) {
-
-                       warn "adding a copy for volume $id\n";
-
-                       $copy->call_number($id);
-                       $copy->creator($user_obj->id);
-                       $copy->editor($user_obj->id);
-
-                       warn Dumper $copy;
-
-                       if( $copy->isnew() ) {
-
-                               my $req = $session->request(
-                                               "open-ils.storage.direct.asset.copy.create", $copy );
-                               my $cid = $req->gather(1);
-
-                               if(!$cid) {
-                                       OpenILS::Application::AppUtils->rollback_db_session($session);
-                                       throw OpenSRF::EX::ERROR ("Error adding copy to volume $id" );
-                               }
-       
-                               warn "got new copy id $cid\n";
-
-                       } elsif( $copy->ischanged() ) {
-
-                       }
-
-               }
-
-               warn "completed adding copies for $id\n";
-
-
-       }
-
-       warn "committing volume tree add db session\n";
-       OpenILS::Application::AppUtils->commit_db_session($session);
-
-       return scalar(@$volumes);
-
-}
-
-__PACKAGE__->register_method(
-       method  => "copy_update",
-       api_name        => "open-ils.cat.asset.copy.batch.update",
-);
-
-sub copy_update {
-       my($self, $client, $user_session, $copies) = @_;
-
-       my $user_obj = $apputils->check_user_session( $user_session ); #throws EX on error
-
-       my $session = $apputils->start_db_session();
-       for my $copy (@$copies) {
-               $copy->editor($user_obj->id);
-               my $req = $session->request(
-                       "open-ils.storage.direct.asset.copy.update",
-                       $copy );
-               my $status = $req->gather(1);
-       }
-
-       $apputils->commit_db_session($session);
-       return 1;
-}
-
-=cut
-
-
 __PACKAGE__->register_method(
        method  => "fleshed_copy_update",
        api_name        => "open-ils.cat.asset.copy.fleshed.batch.update",
@@ -708,7 +639,7 @@ sub fleshed_copy_update {
        my $session = $apputils->start_db_session();
 
        for my $copy (@$copies) {
-               _fleshed_copy_update($session, $copies, $user_obj->id);
+               _fleshed_copy_update($session, $copy, $user_obj->id);
        }
 
        $apputils->commit_db_session($session);
@@ -716,6 +647,7 @@ sub fleshed_copy_update {
 }
 
 
+
 sub _delete_copy {
        my($session, $copy) = @_;
        warn "Deleting copy " . $copy->id . "\n";
@@ -747,10 +679,10 @@ sub _create_copy {
 sub _update_copy {
        my($session, $copy) = @_;
        my $request = $session->request(
-               "open-ils.storage.asset.copy.update",
-               $copy );
+               "open-ils.storage.direct.asset.copy.update", $copy );
+       my $status = $request->gather(1);
        warn "Updated copy " . $copy->id . "\n";
-       return $request->gather(1);
+       return $status;
 }
 
 
@@ -769,6 +701,7 @@ sub _fleshed_copy_update {
        if(ref($copy->location))        {$copy->location( $copy->location->id ); }
        if(ref($copy->circ_lib))        {$copy->circ_lib( $copy->circ_lib->id ); }
 
+       warn "Updating copy " . Dumper($copy) . "\n";
 
        if( $copy->isdeleted ) { 
                return _delete_copy($session, $copy);
@@ -778,7 +711,6 @@ sub _fleshed_copy_update {
                _update_copy($session, $copy);
        }
 
-       warn "Updating copy " . Dumper($copy) . "\n";
        
        if(!@$stat_cat_entries) { return 1; }
 
@@ -786,7 +718,7 @@ sub _fleshed_copy_update {
                "open-ils.storage.direct.asset.stat_cat_entry_copy_map.search.owning_copy",
                $copy->id )->gather(1);
 
-       if( ! $copy->isnew ) { _delete_stale_maps($session, $copy); }
+       if(!$copy->isnew) { _delete_stale_maps($session, $stat_maps, $copy); }
        
        # go through the stat cat update/create process
        for my $stat_entry (@{$stat_cat_entries}){ 
@@ -856,87 +788,5 @@ sub _copy_update_stat_cats {
 
 
 
-=head
-__PACKAGE__->register_method(
-       method  => "volume_tree_delete",
-       api_name        => "open-ils.cat.asset.volume.tree.batch.delete",
-);
-
-sub volume_tree_delete {
-
-       my( $self, $client, $user_session, $volumes ) = @_;
-       return undef unless $volumes;
-
-       my $user_obj = 
-               OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
-
-       my $session = OpenILS::Application::AppUtils->start_db_session;
-
-       for my $volume (@$volumes) {
-
-               $volume->editor($user_obj->id);
-
-               new Fieldmapper::asset::call_number($volume);
-
-               for my $copy (@{$volume->copies}) {
-
-                       new Fieldmapper::asset::copy($copy);
-
-                       $copy->editor( $user_obj->id );
-
-                       warn "Deleting copy " . $copy->id . " from db\n";
-
-                       my $req = $session->request(
-                                       "open-ils.storage.direct.asset.copy.delete", $copy );
-
-                       my $resp = $req->recv();
-
-                       if( !$req->complete ) {
-                               OpenILS::Application::AppUtils->rollback_db_session($session);
-                               throw OpenSRF::EX::ERROR (
-                                               "No response from storage on copy delete");
-                       }
-       
-                       if(UNIVERSAL::isa($resp, "Error")) {
-                               OpenILS::Application::AppUtils->rollback_db_session($session);
-                               throw $resp ($resp->stringify);
-                       }
-                       
-                       $req->finish();
-               }
-
-               warn "Deleting volume " . $volume->id . " from database\n";
-
-               my $vol_req = $session->request(
-                               "open-ils.storage.direct.asset.call_number.delete", $volume );
-               my $vol_resp = $vol_req;
-
-               if(!$vol_req->complete) {
-                       OpenILS::Application::AppUtils->rollback_db_session($session);
-                               throw OpenSRF::EX::ERROR 
-                                       ("No response from storage on volume delete");
-               }
-
-               if( $vol_resp and UNIVERSAL::isa($vol_resp, "Error")) {
-                       OpenILS::Application::AppUtils->rollback_db_session($session);
-                       throw $vol_resp ($vol_resp->stringify);
-               }
-
-               $vol_req->finish();
-
-       }
-
-       warn "committing delete volume tree add db session\n";
-
-       OpenILS::Application::AppUtils->commit_db_session($session);
-
-       return scalar(@$volumes);
-
-}
-
-
-=cut
-
-
 
 1;
index 593147d..882f488 100644 (file)
@@ -37,10 +37,10 @@ sub retrieve_stat_cats {
 
 
 __PACKAGE__->register_method(
-       method  => "retrieve_ranged_stat_cats",
-       api_name        => "open-ils.circ.stat_cat.asset.multirange.retrieve");
+       method  => "retrieve_ranged_intersect_stat_cats",
+       api_name        => "open-ils.circ.stat_cat.asset.multirange.intersect.retrieve");
 
-sub retrieve_ranged_stat_cats {
+sub retrieve_ranged_intersect_stat_cats {
        my( $self, $client, $user_session, $orglist ) = @_;
 
        my $user_obj = $apputils->check_user_session($user_session); 
@@ -52,12 +52,35 @@ sub retrieve_ranged_stat_cats {
 
        warn "range: @$orglist\n";
 
-       my      $method = "open-ils.storage.multiranged.fleshed.asset.stat_cat.all.atomic";
+       my      $method = "open-ils.storage.multiranged.intersect.fleshed.asset.stat_cat.all.atomic";
        return $apputils->simple_scalar_request(
                                "open-ils.storage", $method, $orglist );
 }
 
 
+__PACKAGE__->register_method(
+       method  => "retrieve_ranged_union_stat_cats",
+       api_name        => "open-ils.circ.stat_cat.asset.multirange.union.retrieve");
+
+sub retrieve_ranged_union_stat_cats {
+       my( $self, $client, $user_session, $orglist ) = @_;
+
+       my $user_obj = $apputils->check_user_session($user_session); 
+       if(!$orglist) { $orglist = [ $user_obj->home_ou ]; }
+
+       # uniquify, yay!
+       my %hash = map { ($_ => 1) } @$orglist;
+       $orglist = [ keys %hash ];
+
+       warn "range: @$orglist\n";
+
+       my      $method = "open-ils.storage.multiranged.union.fleshed.asset.stat_cat.all.atomic";
+       return $apputils->simple_scalar_request(
+                               "open-ils.storage", $method, $orglist );
+}
+
+
+
 
 
 __PACKAGE__->register_method(
@@ -162,10 +185,15 @@ sub _create_stat_cat {
 
 sub _create_stat_entry {
        my( $session, $stat_entry, $method) = @_;
+
        warn "Creating new stat entry with value " . $stat_entry->value . "\n";
        $stat_entry->clear_id();
+
        my $req = $session->request($method, $stat_entry);
        my $id = $req->gather(1);
+
+       warn "Stat entry " . Dumper($stat_entry) . "\n";        
+       
        if(!$id) {
                throw OpenSRF::EX::ERROR 
                ("Error creating new stat cat entry"); }
@@ -202,6 +230,65 @@ sub update_stat_entry {
 }
 
 
+__PACKAGE__->register_method(
+       method  => "update_stat",
+       api_name        => "open-ils.circ.stat_cat.actor.update");
+
+__PACKAGE__->register_method(
+       method  => "update_stat",
+       api_name        => "open-ils.circ.stat_cat.asset.update");
+
+sub update_stat {
+       my( $self, $client, $user_session, $cat ) = @_;
+
+       my $user_obj = $apputils->check_user_session($user_session); 
+
+       my $method = "open-ils.storage.direct.actor.stat_cat.update";
+       if($self->api_name =~ /asset/) {
+               $method = "open-ils.storage.direct.asset.stat_cat.update";
+       }
+
+       my $session = $apputils->start_db_session();
+       my $req = $session->request($method, $cat); 
+       my $status = $req->gather(1);
+       $apputils->commit_db_session($session);
+       warn "stat cat with id " . $cat->id . " updated with status $status\n";
+       return 1;
+}
+
+
+__PACKAGE__->register_method(
+       method  => "create_stat_entry",
+       api_name        => "open-ils.circ.stat_cat.actor.entry.create");
+
+__PACKAGE__->register_method(
+       method  => "create_stat_entry",
+       api_name        => "open-ils.circ.stat_cat.asset.entry.create");
+
+sub create_stat_entry {
+       my( $self, $client, $user_session, $entry ) = @_;
+
+       my $user_obj = $apputils->check_user_session($user_session); 
+
+       $entry->clear_id();
+       use Data::Dumper;
+       warn Dumper($entry);
+
+       my $method = "open-ils.storage.direct.actor.stat_cat_entry.create";
+       if($self->api_name =~ /asset/) {
+               $method = "open-ils.storage.direct.asset.stat_cat_entry.create";
+       }
+
+       my $session = $apputils->start_db_session();
+       my $req = $session->request($method, $entry); 
+       my $status = $req->gather(1);
+       $apputils->commit_db_session($session);
+
+       warn "stat cat entry with id " . $status . " updated with status $status\n";
+       return $status;
+}
+
+
 
 __PACKAGE__->register_method(
        method  => "create_stat_map",
@@ -238,6 +325,36 @@ sub create_stat_map {
 }
 
 
+__PACKAGE__->register_method(
+       method  => "update_stat_map",
+       api_name        => "open-ils.circ.stat_cat.actor.user_map.update");
+
+__PACKAGE__->register_method(
+       method  => "update_stat_map",
+       api_name        => "open-ils.circ.stat_cat.asset.copy_map.update");
+
+sub update_stat_map {
+       my( $self, $client, $user_session, $map ) = @_;
+
+       my $user_obj = $apputils->check_user_session($user_session); 
+
+       warn "Updating stat_cat_map\n";
+
+       my $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.update";
+       if($self->api_name =~ /asset/) {
+               $method = "open-ils.storage.direct.asset.stat_cat_entry_copy_map.update";
+       }
+
+       my $session = $apputils->start_db_session();
+       my $req = $session->request($method, $map); 
+       my $newid = $req->gather(1);
+       warn "Updated new stat cat map with id $newid\n";
+       $apputils->commit_db_session($session);
+
+       return $newid;
+}
+
+
 
 __PACKAGE__->register_method(
        method  => "retrieve_maps",
@@ -264,10 +381,62 @@ sub retrieve_maps {
 
 
 
+__PACKAGE__->register_method(
+       method  => "delete_stats",
+       api_name        => "open-ils.circ.stat_cat.actor.delete");
 
+__PACKAGE__->register_method(
+       method  => "delete_stats",
+       api_name        => "open-ils.circ.stat_cat.asset.delete");
 
+sub delete_stats {
+       my( $self, $client, $user_session, $target ) = @_;
+       my $user_obj = $apputils->check_user_session($user_session); 
+       my $session = OpenSRF::AppSession->create("open-ils.storage");
+       my $type = "actor";
+       if($self->api_name =~ /asset/) { $type = "asset"; }
+       return _delete_stats($session, $target, $type);
+}
 
+sub _delete_stats {
+       my( $session, $stat, $type) = @_;
 
+       my      $method = "open-ils.storage.direct.asset.stat_cat.delete";
+       if($type =~ /actor/ ) {
+               $method = "open-ils.storage.direct.actor.stat_cat.delete";
+       }
+       return $session->request($method, $stat)->gather(1);
+}
+
+
+
+__PACKAGE__->register_method(
+       method  => "delete_entry",
+       api_name        => "open-ils.circ.stat_cat.actor.entry.delete");
+
+__PACKAGE__->register_method(
+       method  => "delete_entry",
+       api_name        => "open-ils.circ.stat_cat.asset.entry.delete");
+
+sub delete_entry {
+       my( $self, $client, $user_session, $target ) = @_;
+       my $user_obj = $apputils->check_user_session($user_session); 
+       my $session = OpenSRF::AppSession->create("open-ils.storage");
+       my $type = "actor";
+       if($self->api_name =~ /asset/) { $type = "asset"; }
+       return _delete_entry($session, $target, $type);
+}
+
+sub _delete_entry {
+       my( $session, $stat_entry, $type) = @_;
+
+       my      $method = "open-ils.storage.direct.asset.stat_cat_entry.delete";
+       if($type =~ /actor/ ) {
+               $method = "open-ils.storage.direct.actor.stat_cat_entry.delete";
+       }
+
+       return $session->request($method, $stat_entry)->gather(1);
+}
 
 
 
index 44b76cb..b3a6d73 100644 (file)
@@ -25,6 +25,10 @@ sub child_init {
        OpenILS::Application::SearchCache->child_init();
 }
 
+sub initialize {
+       OpenILS::Application::Search::Z3950->initialize();
+}
+
 sub filter_search {
        my($self, $str, $full) = @_;
 
index 7be4461..efb56a5 100644 (file)
@@ -164,6 +164,11 @@ __PACKAGE__->register_method(
        method  => "record_id_to_copy_count",
        api_name        => "open-ils.search.biblio.metarecord.copy_count",
 );
+
+__PACKAGE__->register_method(
+       method  => "record_id_to_copy_count",
+       api_name        => "open-ils.search.biblio.metarecord.copy_count.staff",
+);
 sub record_id_to_copy_count {
        my( $self, $client, $org_id, $record_id ) = @_;
 
@@ -174,6 +179,12 @@ sub record_id_to_copy_count {
                $key = "metarecord";
        }
 
+       if($self->api_name =~ /staff/ ) {
+               $method =~ s/atomic/staff\.atomic/og;
+               warn "Doing staff search $method\n";
+       }
+
+
        my $session = OpenSRF::AppSession->create("open-ils.storage");
        warn "copy_count retrieve $record_id\n";
        return undef unless(defined $record_id);
@@ -564,9 +575,13 @@ sub cat_biblio_search_class_id {
 __PACKAGE__->register_method(
        method  => "biblio_search_class_count",
        api_name        => "open-ils.search.biblio.class.count",
-       argc            => 3, 
-       note            => "Searches biblio information by search class and returns the IDs",
 );
+
+__PACKAGE__->register_method(
+       method  => "biblio_search_class_count",
+       api_name        => "open-ils.search.biblio.class.count.staff",
+);
+
 sub biblio_search_class_count {
 
        my( $self, $client, $class, $string, $org_id, $org_type ) = @_;
@@ -598,7 +613,8 @@ sub biblio_search_class_count {
        $class =~ s/\s+//g;
 
        if( ($class ne "title") and ($class ne "author") and 
-               ($class ne "subject") and ($class ne "keyword") ) {
+               ($class ne "subject") and ($class ne "keyword") 
+               and ($class ne "series"  )) {
                warn "Invalid search class: $class\n";
                throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
        }
@@ -606,7 +622,10 @@ sub biblio_search_class_count {
        # grab the mr id's from storage
 
        my $method = "open-ils.storage.metabib.$class.search_fts.metarecord_count";
+       if($self->api_name =~ /staff/) { $method = "$method.staff"; }
        warn "Performing count method $method\n";
+       warn "API name " . $self->api_name() . "\n";
+
        my $session = OpenSRF::AppSession->create('open-ils.storage');
 
        my $request = $session->request( $method, 
@@ -631,6 +650,16 @@ __PACKAGE__->register_method(
        api_name        => "open-ils.search.biblio.class.unordered",
 );
 
+__PACKAGE__->register_method(
+       method  => "biblio_search_class",
+       api_name        => "open-ils.search.biblio.class.staff",
+);
+
+__PACKAGE__->register_method(
+       method  => "biblio_search_class",
+       api_name        => "open-ils.search.biblio.class.unordered.staff",
+);
+
 sub biblio_search_class {
 
        my( $self, $client, $class, $string, 
@@ -663,7 +692,8 @@ sub biblio_search_class {
        $class =~ s/\s+//g;
 
        if( ($class ne "title") and ($class ne "author") and 
-               ($class ne "subject") and ($class ne "keyword") ) {
+               ($class ne "subject") and ($class ne "keyword") 
+               and ($class ne "series") ) {
                warn "Invalid search class: $class\n";
                throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
        }
@@ -674,6 +704,11 @@ sub biblio_search_class {
                $method = "open-ils.storage.metabib.$class.search_fts.metarecord.unordered.atomic";
        }
 
+       if($self->api_name =~ /staff/) { 
+               $method =~ s/atomic/staff\.atomic/og;
+       }
+
+       warn "Performing search method $method\n";
        warn "MR search method is $method\n";
 
        my $session = OpenSRF::AppSession->create('open-ils.storage');
index cd4f8f4..239ba29 100755 (executable)
@@ -17,6 +17,7 @@ my $utils = "OpenILS::Application::Cat::Utils";
 my $apputils = "OpenILS::Application::AppUtils";
 
 use OpenILS::Utils::ModsParser;
+use Data::Dumper;
 
 my $output = "USMARC"; # only support output for now
 my $host;
@@ -83,10 +84,26 @@ sub z39_search_by_string {
 
 
        for( my $x = 0; $x != $hash->{count}; $x++ ) {
+               warn "Churning on z39 record count $x\n";
+
                my $rec = $rs->record($x+1);
                my $marc = MARC::Record->new_from_usmarc($rec->rawdata());
 
-               my $nodes = OpenILS::Utils::FlatXML->new()->xml_to_nodeset( $marc->as_xml() ); 
+               my $marcxml = $marc->as_xml();
+               my $flat = OpenILS::Utils::FlatXML->new( xml => $marcxml ); 
+               my $doc = $flat->xml_to_doc();
+
+
+               if( $doc->documentElement->nodeName =~ /collection/io ) {
+                       $doc->setDocumentElement( $doc->documentElement->firstChild );
+                       $doc->documentElement->setNamespace(
+                                       "http://www.loc.gov/MARC21/slim", undef, 1);
+               }
+
+               warn $doc->toString . "\n";
+
+               my $nodes = $flat->xmldoc_to_nodeset($doc);
+
                warn "turning nodeset into tree\n";
                my $tree = $utils->nodeset2tree( $nodes->nodeset );
 
index 04768b5..57a258c 100644 (file)
@@ -23,8 +23,11 @@ my $pub_xpath                        = "//mods:mods/mods:originInfo//mods:dateIssued[\@encoding='marc
 my $tcn_xpath                  = "//mods:mods/mods:recordInfo/mods:recordIdentifier";
 my $publisher_xpath    = "//mods:mods/mods:originInfo//mods:publisher[1]";
 
+my $edition_xpath = "//mods:mods/mods:originInfo//mods:edition[1]";
+
 
 my $xpathset = {
+
        title => {
                abbreviated => 
                        "//mods:mods/mods:titleInfo[mods:title and (\@type='abreviated')]",
@@ -35,6 +38,7 @@ my $xpathset = {
                proper =>
                        "//mods:mods/mods:titleInfo[mods:title and not (\@type)]",
        },
+
        author => {
                corporate => 
                        "//mods:mods/mods:name[\@type='corporate']/*[local-name()='namePart']".
@@ -48,6 +52,7 @@ my $xpathset = {
                other => 
                        "//mods:mods/mods:name[\@type='personal']/*[local-name()='namePart']",
        },
+
        subject => {
 
                topic => 
@@ -278,6 +283,9 @@ sub start_mods_batch {
        ($self->{master_doc}->{publisher}) = 
                $self->get_field_value( $mods, $publisher_xpath );
 
+       ($self->{master_doc}->{edition}) =
+               $self->get_field_value( $mods, $edition_xpath );
+
 }
 
 # ---------------------------------------------------------------------------
@@ -331,6 +339,11 @@ sub finish_mods_batch {
                push @series, (split( /\s*;/, $s ))[0];
        }
 
+       # uniquify the types of resource
+       my $rtypes = $perl->{type_of_resource};
+       my %hash = map { ($_ => 1) } @$rtypes;
+       $rtypes = [ keys %hash ];
+
        $record->title($title);
        $record->author($author);
 
@@ -340,12 +353,13 @@ sub finish_mods_batch {
        $record->publisher($perl->{publisher});
        $record->tcn($perl->{tcn});
 
+       $record->edition($perl->{edition});
+
        $record->subject($perl->{subject});
-       $record->types_of_resource($perl->{types_of_resource});
+       $record->types_of_resource($rtypes);
        $record->series(\@series);
 
        $self->{master_doc} = undef;
-       #return $perl
        return $record;
 }
 
index 453e690..401e566 100644 (file)
@@ -3,6 +3,24 @@
        box(id='progress_bar_percent_location'); 
        INCLUDE opac/pages/chunks/opac_search_bar.ttk;
        lines(1);
+
        INCLUDE opac/pages/chunks/status_bar.ttk;
+
+       WRAPPER html/div class='hit_count_selector_div';
+
+               WRAPPER html/div class='hit_count_cell' id='hit_count_cell';
+               END;
+
+               "Hits per page ";
+               WRAPPER html/select name='hits_per_page' id='hits_per_page';
+                       option(value='5',               content="5");
+                       option(value='10',      selected='selected', content="10");
+                       option(value='15',      content="15");
+                       option(value='25',      content="25");
+                       option(value='50',      content="50");
+                       option(value='100',  content="100");
+               END;
+       END;
+
        INCLUDE opac/pages/chunks/org_tree.ttk;
 %]
index 832ffe4..119ecdc 100644 (file)
@@ -27,6 +27,8 @@
                                value=tm.search, onclick='alert("help");' );
 
                space(1);
+
+               
                
        END;
 
index 10c2456..43107b7 100644 (file)
@@ -6,6 +6,7 @@
                WRAPPER html/cell class='search_range_cell' nowrap='nowrap';
        
                        
+
                        WRAPPER html/span;
                                space(3);
                                "Expand search to ";
@@ -28,6 +29,7 @@
                        ); 
 
        
+               
                END;
 
        END;
index b569f64..df4feec 100644 (file)
@@ -30,7 +30,7 @@
                                                WRAPPER html/table class='record_result_box', id='record_result_box'; 
                                                        WRAPPER html/thead class='record_result_thead'; 
                                                                WRAPPER html/row id='record_result_thead_row';
-                                                                       cell(id='hit_count_cell', nowrap='nowrap', colspan='2', class='hit_count_cell'); 
+                                                                       cell(nowrap='nowrap', colspan='2' ); 
                                                                END;
                                                        END;
                                                END;