see diffs. lots of small changes, extra logging, bug fixes, etc.
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 25 Jul 2005 23:40:04 +0000 (23:40 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 25 Jul 2005 23:40:04 +0000 (23:40 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1466 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/OpenILS/Application/Cat.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Rules.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/StatCat.pm
Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
Open-ILS/src/templates/strings/perm.ttk

index 4dcf8dc..2b7c6a4 100644 (file)
@@ -7,6 +7,7 @@ use Digest::MD5 qw(md5_hex);
 
 use OpenSRF::EX qw(:try);
 use OpenILS::EX;
+use OpenILS::Perm;
 
 use OpenILS::Application::AppUtils;
 use OpenILS::Utils::Fieldmapper;
@@ -36,7 +37,6 @@ sub update_patron {
                                $user_session ); #throws EX on error
 
        # XXX does this user have permission to add/create users.  Granularity?
-
        # $new_patron is the patron in progress.  $patron is the original patron
        # passed in with the method.  new_patron will change as the components
        # of patron are added/updated.
@@ -83,13 +83,6 @@ sub update_patron {
                return undef;
        }
 
-       $new_patron     = _create_stat_maps($session, $user_session, $patron, $new_patron, $user_obj);
-       if(UNIVERSAL::isa($new_patron, "OpenILS::EX") || 
-               UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
-               $client->respond_complete($new_patron->ex);
-               return undef;
-       }
-
 
        # re-update the patron if anything has happened to him during this process
        if($new_patron->ischanged()) {
@@ -101,8 +94,18 @@ sub update_patron {
                        return undef;
                }
        }
+
        $apputils->commit_db_session($session);
 
+       $session = OpenSRF::AppSession->create("open-ils.storage");
+       $new_patron     = _create_stat_maps($session, $user_session, $patron, $new_patron, $user_obj);
+       if(UNIVERSAL::isa($new_patron, "OpenILS::EX") || 
+               UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
+               $client->respond_complete($new_patron->ex);
+               return undef;
+       }
+
+
        warn "Patron Update/Create complete\n";
        return flesh_user($new_patron->id());
 }
@@ -118,8 +121,10 @@ sub user_retrieve_fleshed_by_id {
        my( $self, $client, $user_session, $user_id ) = @_;
        my $user_obj = $apputils->check_user_session( $user_session ); 
 
-       if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER")) {
-               return OpenILS::Perm->new("VIEW_USER");
+       if( $user_obj->id ne $user_id ) {
+               if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER")) {
+                       return OpenILS::Perm->new("VIEW_USER");
+               }
        }
 
        return flesh_user($user_id);
@@ -497,6 +502,7 @@ sub _create_stat_maps {
                my $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.update";
                if($map->isnew()) {
                        $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.create";
+                       $map->clear_id;
                }
 
                $map->target_usr($new_patron->id);
@@ -512,6 +518,7 @@ sub _create_stat_maps {
                        throw OpenSRF::EX::ERROR 
                                ("Error updating stat map with method $method");        
                }
+
        }
 
        return $new_patron;
index 3d1296d..25f4c52 100644 (file)
@@ -37,13 +37,15 @@ sub start_db_session {
 sub check_user_perms {
        my($self, $user_id, $org_id, @perm_types ) = @_;
 
+       warn "Checking perm with user : $user_id , org: $org_id, @perm_types\n";
+
        throw OpenSRF::EX::ERROR ("Invalid call to check_user_perms()")
                unless( defined($user_id) and defined($org_id) and @perm_types); 
 
        my $session = OpenSRF::AppSession->create("open-ils.storage");
        for my $type (@perm_types) {
                my $req = $session->request(
-                       "open-ils.storage.permission.user_has_perm",
+                       "open-ils.storage.permission.user_has_perm", 
                        $user_id, $type, $org_id );
                my $resp = $req->gather(1);
                if(!$resp) { 
@@ -109,7 +111,7 @@ sub check_user_session {
        my $response = $request->recv();
 
        if(!$response) {
-               throw OpenSRF::EX::ERROR ("Session [$user_session] cannot be authenticated" );
+               throw OpenSRF::EX::User ("Session [$user_session] cannot be authenticated" );
        }
 
        if($response->isa("OpenSRF::EX")) {
index c93b0ec..9e79187 100644 (file)
@@ -91,6 +91,9 @@ sub biblio_record_tree_import {
                if(_tcn_exists($session, $tcn)) {$tcn = undef;}
        }
 
+       $tcn =~ s/^\s+//g;
+       $tcn =~ s/\s+$//g;
+
        warn "Record import with tcn: $tcn and source $tcn_source\n";
 
        my $record = Fieldmapper::biblio::record_entry->new;
@@ -104,16 +107,24 @@ sub biblio_record_tree_import {
 
 
        my $req = $session->request(
-               "open-ils.storage.direct.biblio.record_entry.create",
-               $record );
+               "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);
+       if(!$id) { throw OpenSRF::EX::ERROR ("Unable to create new record_entry from import"); }
+       warn "received id: $id from record_entry create\n";
 
        $apputils->commit_db_session($session);
 
+       $session = OpenSRF::AppSession->create("open-ils.storage");
+
+       my $wreq = $session->request("open-ils.worm.wormize", $id)->gather(1);
+       warn "Done worming record $id\n";
+
+       if(!$wreq) { throw OpenSRF::EX::ERROR ("Unable to wormize imported record"); }
+
        return $self->biblio_record_tree_retrieve($client, $id);
+
 }
 
 sub _tcn_exists {
@@ -563,7 +574,7 @@ sub volume_tree_fleshed_update {
                                throw OpenSRF::EX::ERROR
                                        ("Volume delete failed for volume " . $volume->id);
                        }
-                       if(UNIVERSAL::isa($status, "OpenILS::Perm")) { return $status; }
+                       if(UNIVERSAL::isa($status, "Fieldmapper::perm_ex")) { return $status; }
 
                } elsif( $volume->isnew ) {
 
@@ -571,13 +582,15 @@ sub volume_tree_fleshed_update {
                        $volume->editor($user_obj->id);
                        $volume->creator($user_obj->id);
                        $volume = _add_volume($session, $volume, $user_obj);
-                       if($volume and UNIVERSAL::isa($volume, "OpenILS::Perm")) { return $volume; }
+                       use Data::Dumper;
+                       warn Dumper $volume;
+                       if($volume and UNIVERSAL::isa($volume, "Fieldmapper::perm_ex")) { return $volume; }
 
                } elsif( $volume->ischanged ) {
 
                        $volume->editor($user_obj->id);
                        my $stat = _update_volume($session, $volume, $user_obj);
-                       if($stat and UNIVERSAL::isa($stat, "OpenILS::Perm")) { return $stat; }
+                       if($stat and UNIVERSAL::isa($stat, "Fieldmapper::perm_ex")) { return $stat; }
                }
 
 
@@ -655,7 +668,9 @@ sub _add_volume {
 
        if($apputils->check_user_perms(
                        $user_obj->id, $user_obj->home_ou, "CREATE_VOLUME")) {
-               return OpenILS::Perm->new("CREATE_VOLUME"); }
+               warn "User does not have priveleges to create new volumes\n";
+               return OpenILS::Perm->new("CREATE_VOLUME"); 
+       }
 
        my $request = $session->request( 
                "open-ils.storage.direct.asset.call_number.create", $volume );
index 7d5c1c3..a15745a 100644 (file)
@@ -345,6 +345,8 @@ __PACKAGE__->register_method(
 sub capture_copy {
        my( $self, $client, $login_session, $barcode, $flesh ) = @_;
 
+       warn "Capturing copy with barcode $barcode, flesh=$flesh \n";
+
        my $user = $apputils->check_user_session($login_session);
 
        if($apputils->check_user_perms($user->id, $user->home_ou, "COPY_CHECKIN")) {
@@ -355,12 +357,15 @@ sub capture_copy {
        my $copy = $session->request(
                "open-ils.storage.direct.asset.copy.search.barcode",
                $barcode )->gather(1);
+
+       warn "Found copy $copy\n";
+
        return OpenILS::EX->new("UNKNOWN_BARCODE")->ex unless $copy;
 
        warn "Capturing copy " . $copy->id . "\n";
 
        my $hold = _find_local_hold_for_copy($session, $copy, $user);
-       if(!$hold) {return OpenILS::EX->new("HOLD_NOT_FOUND")->ex;}
+       if(!$hold) {return OpenILS::EX->new("NO_HOLD_FOUND")->ex;}
 
        warn "Found hold " . $hold->id . "\n";
 
index 43dd8e2..b1415d1 100644 (file)
@@ -265,17 +265,17 @@ sub gather_circ_objects {
        warn "Gathering circ objects with barcode $barcode_string and patron id $patron_id\n";
 
        # see if all of the circ objects are in cache
-       my $cache_key =  "circ_object_" . md5_hex( $barcode_string, $patron_id );
-       $circ_objects = $cache_handle->get_cache($cache_key);
-
-       if($circ_objects) { 
-               $stash = Template::Stash->new(
-                       circ_objects                    => $circ_objects,
-                       result                                  => [],
-                       target_copy_status      => 1,
-                       );
-               return;
-       }
+#      my $cache_key =  "circ_object_" . md5_hex( $barcode_string, $patron_id );
+#      $circ_objects = $cache_handle->get_cache($cache_key);
+
+#      if($circ_objects) { 
+#              $stash = Template::Stash->new(
+#                      circ_objects                    => $circ_objects,
+#                      result                                  => [],
+#                      target_copy_status      => 1,
+#                      );
+#              return;
+#      }
 
        # only necessary if the circ objects have not been built yet
 
@@ -300,7 +300,7 @@ sub gather_circ_objects {
 
        #$circ_objects->{title} = $title_req->gather(1);
        $circ_objects->{title} = _grab_title_by_copy($session, $circ_objects->{copy}->id);
-       $cache_handle->put_cache( $cache_key, $circ_objects, 30 );
+#      $cache_handle->put_cache( $cache_key, $circ_objects, 30 );
 
        $stash = Template::Stash->new(
                        circ_objects                    => $circ_objects,
@@ -737,6 +737,8 @@ sub transit_receive {
                        $copy->editor($user->id); #hold shelf status
                        $copy->edit_date("now"); #hold shelf status
 
+                       warn "Updating copy " . $copy->id . " with new status, editor, and edit date\n";
+
                        my $s = $session->request(
                                "open-ils.storage.direct.asset.copy.update", $copy )->gather(1);
                        if(!$s) {throw OpenSRF::EX::ERROR ("Error putting copy on holds shelf ".$copy->id);} # blah..
@@ -837,6 +839,29 @@ sub checkin {
                                $circ->stop_fines("CHECKIN");
                                $circ->stop_fines("RENEW") if($isrenewal);
                                $circ->xact_finish("now") if($transaction->balance_owed <= 0 );
+
+                               if($backdate) { 
+                                       $circ->xact_finish($backdate); 
+
+                                       # void any bills the resulted after the backdate time
+                                       my $bills = $session->request(
+                                               "open-ils.storage.direct.money.billing.search_where.atomic",
+                                               billing_ts => { ">=" => $backdate })->gather(1);
+
+                                       if($bills) {
+                                               for my $bill (@$bills) {
+
+                                                       $bill->voided('t');
+                                                       my $s = $session->request(
+                                                               "open-ils.storage.direct.money.billing.update", $bill)->gather(1);
+
+                                                       if(!$s) { 
+                                                               throw OpenSRF::EX::ERROR 
+                                                                       ("Error voiding bill on checkin with backdate : $backdate, circ id: " . $circ->id);
+                                                       }
+                                               }
+                                       }
+                               }
                        
                                my $cp_up = $session->request(
                                        "open-ils.storage.direct.asset.copy.update", $copy );
index 7d998a5..57a357b 100644 (file)
@@ -37,14 +37,15 @@ __PACKAGE__->register_method(
 sub retrieve_stat_cats {
        my( $self, $client, $user_session, $orgid ) = @_;
 
-       my $user_obj = $apputils->check_user_session($user_session); 
-       if(!$orgid) { $orgid = $user_obj->home_ou; }
-
        my $method = "open-ils.storage.ranged.fleshed.actor.stat_cat.all.atomic"; 
        if( $self->api_name =~ /asset/ ) {
                $method = "open-ils.storage.ranged.fleshed.asset.stat_cat.all.atomic"; 
        }
 
+
+       my $user_obj = $apputils->check_user_session($user_session); 
+       if(!$orgid) { $orgid = $user_obj->home_ou; }
+
        return $apputils->simple_scalar_request(
                                "open-ils.storage", $method, $orgid );
 }
@@ -80,6 +81,10 @@ __PACKAGE__->register_method(
 sub retrieve_ranged_union_stat_cats {
        my( $self, $client, $user_session, $orglist ) = @_;
 
+       my      $method = "open-ils.storage.multiranged.union.fleshed.asset.stat_cat.all.atomic";
+       use Data::Dumper;
+       warn "Retrieving stat_cats with method $method and orgs " . Dumper($orglist) . "\n";
+
        my $user_obj = $apputils->check_user_session($user_session); 
        if(!$orglist) { $orglist = [ $user_obj->home_ou ]; }
 
@@ -89,7 +94,6 @@ sub retrieve_ranged_union_stat_cats {
 
        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 );
 }
index 30b5673..187e55c 100644 (file)
@@ -589,11 +589,11 @@ sub biblio_search_class_count {
        my $session = OpenSRF::AppSession->create('open-ils.storage');
 
        my $request = $session->request( $method, 
-                       term => $string, 
-                       org_unit => $org_id, 
-                       cache_page_size => 1,
-                       depth =>$org_type,
-                       format => $format );
+                       term                                    => $string, 
+                       org_unit                                => $org_id, 
+                       cache_page_size => 1,
+                       depth                                   => $org_type,
+                       format                          => $format );
 
        my $count = $request->gather(1);
        warn "Received count $count\n";
@@ -850,6 +850,11 @@ __PACKAGE__->register_method(
        api_name        => "open-ils.search.biblio.metarecord_to_records",
 );
 
+__PACKAGE__->register_method(
+       method  => "biblio_mrid_to_record_ids",
+       api_name        => "open-ils.search.biblio.metarecord_to_records.staff",
+);
+
 sub biblio_mrid_to_record_ids {
        my( $self, $client, $mrid, $format ) = @_;
 
@@ -859,10 +864,15 @@ sub biblio_mrid_to_record_ids {
 
        warn "Searching for record for MR $mrid and format $format\n";
 
+       my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
+       if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
+       warn "Performing record retrieval with method $method\n";
+
+
        my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request( 
                        "open-ils.storage", 
                        #"open-ils.storage.direct.metabib.metarecord_source_map.search.metarecord", $mrid );
-                       "open-ils.storage.ordered.metabib.metarecord.records.atomic"
+                       $method
                        $mrid, $format );
 
 
index b46572b..723b822 100755 (executable)
@@ -13,6 +13,8 @@ use OpenILS::Utils::FlatXML;
 use OpenILS::Application::Cat::Utils;
 use OpenILS::Application::AppUtils;
 
+use OpenSRF::EX qw(:try);
+
 my $utils = "OpenILS::Application::Cat::Utils";
 my $apputils = "OpenILS::Application::AppUtils";
 
@@ -100,14 +102,29 @@ sub z39_search_by_string {
                                        "http://www.loc.gov/MARC21/slim", undef, 1);
                }
 
-               warn $doc->toString . "\n";
+               warn "Z3950 XML doc:\n" . $doc->toString . "\n";
+
+               warn "Turning doc into a nodeset...\n";
 
-               my $nodes = OpenILS::Utils::FlatXML->new->xmldoc_to_nodeset($doc);
+               my $tree;
+               my $err;
 
-               warn "turning nodeset into tree\n";
-               my $tree = $utils->nodeset2tree( $nodes->nodeset );
+               try {
+                       my $nodes = OpenILS::Utils::FlatXML->new->xmldoc_to_nodeset($doc);
+                       #use Data::Dumper;
+                       #warn Dumper $nodes;
+                       warn "turning nodeset into tree\n";
+                       $tree = $utils->nodeset2tree( $nodes->nodeset );
+               } catch Error with {
+                       $err = shift;
+               };
+
+               if($err) {
+                       warn "Error turning doc into nodeset/node tree: $err\n";
+               } else {
+                       push @$records, $tree;
+               }
 
-               push @$records, $tree;
        }
 
        use Data::Dumper;
index fe9159d..01de49e 100644 (file)
@@ -20,6 +20,7 @@
        perm_map.REQUEST_HOLDS = "Requesting a hold for another user";
        perm_map.REQUEST_HOLDS_OVERRIDE = "Requesting a dissallowed hold for another user";
        perm_map.RENEW_HOLD_OVERRIDE = "Requesting renew for copy needed for hold";
+       perm_map.CREATE_VOLUME = "Creating a new volume";
 
 
        ret(perm_map.$type);