more work on holds capturing, adding permissions, etc
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 20 Jul 2005 14:56:44 +0000 (14:56 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 20 Jul 2005 14:56:44 +0000 (14:56 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1306 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/Circ/Holds.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Rules.pm
Open-ILS/src/perlmods/OpenILS/Application/Proxy.pm

index a2633bc..11f6050 100644 (file)
@@ -43,47 +43,61 @@ sub update_patron {
 
        my $new_patron;
 
-       #try {
-               # create/update the patron first so we can use his id
-               if($patron->isnew()) {
-                       $new_patron = _add_patron(
-                                       $session, _clone_patron($patron));
-                       if(UNIVERSAL::isa($new_patron, "OpenILS::EX")) {
-                               $client->respond_complete($new_patron->ex);
-                               return undef;
-                       }
-
-               } else { 
-                       $new_patron = $patron; 
-               }
+       # create/update the patron first so we can use his id
+       if($patron->isnew()) {
 
-               $new_patron = _add_update_addresses($session, $patron, $new_patron);
-               $new_patron = _add_update_cards($session, $patron, $new_patron);
+               $new_patron = _add_patron($session, _clone_patron($patron), $user_obj);
 
-               if(UNIVERSAL::isa($new_patron,"OpenILS::EX")) {
+               if(UNIVERSAL::isa($new_patron, "OpenILS::EX") || 
+                       UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
                        $client->respond_complete($new_patron->ex);
                        return undef;
                }
 
-               $new_patron = _add_survey_responses($session, $patron, $new_patron);
-               $new_patron     = _create_stat_maps($session, $user_session, $patron, $new_patron);
+       } else { $new_patron = $patron; }
 
-               # re-update the patron if anything has happened to him during this process
-               if($new_patron->ischanged()) {
-                       $new_patron = _update_patron($session, $new_patron);
-               }
-               $apputils->commit_db_session($session);
+       $new_patron = _add_update_addresses($session, $patron, $new_patron, $user_obj);
 
-=head
-       } catch Error with { 
-               my $e = shift;
-               $err =  "-*- Failure adding user: $e";
-               $apputils->rollback_db_session($session);
-               warn $err;
-       };
+       if(UNIVERSAL::isa($new_patron, "OpenILS::EX") || 
+               UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
+               $client->respond_complete($new_patron->ex);
+               return undef;
+       }
 
-       if($err) { throw OpenSRF::EX::ERROR ($err); }
-=cut
+       $new_patron = _add_update_cards($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;
+       }
+
+       $new_patron = _add_survey_responses($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;
+       }
+
+       $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()) {
+               $new_patron = _update_patron($session, $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;
+               }
+       }
+       $apputils->commit_db_session($session);
 
        warn "Patron Update/Create complete\n";
        return flesh_user($new_patron->id());
@@ -200,6 +214,13 @@ sub _clone_patron {
 sub _add_patron {
        my $session             = shift;
        my $patron              = shift;
+       my $user_obj    = shift;
+
+
+       if($apputils->check_user_perms(
+                               $user_obj->id, $user_obj->home_ou, "CREATE_USER")) {
+               return OpenILS::Perm->new("CREATE_USER");
+       }
 
        warn "Creating new patron\n";
        _d($patron);
@@ -223,7 +244,13 @@ sub _add_patron {
 
 
 sub _update_patron {
-       my( $session, $patron) = @_;
+       my( $session, $patron, $user_obj) = @_;
+
+
+       if($apputils->check_user_perms(
+                               $user_obj->id, $user_obj->home_ou, "UPDATE_USER")) {
+               return OpenILS::Perm->new("UPDATE_USER");
+       }
 
        warn "updating patron " . Dumper($patron) . "\n";
 
index 05d1091..3d1296d 100644 (file)
@@ -242,8 +242,6 @@ sub build_org_tree {
 
        my( $self, $orglist, $add_types ) = @_;
 
-
-
        return $orglist unless ( 
                        ref($orglist) and @$orglist > 1 );
 
@@ -271,81 +269,11 @@ sub build_org_tree {
 
 }
 
-       
-sub start_long_request {
-
-       my($self, $service, $method, @params) = @_;
-
-       my $session = OpenSRF::AppSession->create( $service );
-       my $request = $session->request( $method, @params );
-       my $response = $request->recv(30);
-
-       $request->wait_complete;
 
-       if(!$request->complete) {
-               throw $response ("Call to $service for method $method with params @params" . 
-                               "\n did not complete successfully");
-       }
 
-       if(!$response) {
-               warn "No response from $service for method $method with params @params";
-       }
-
-       if($response and UNIVERSAL::isa($response,"Error")) {
-               throw $response ("Call to $service for method $method with params @params" . 
-                               "\n failed with exception: " . $response->stringify );
-       }
-
-       $request->finish();
-
-       my $value;
-
-       if($response) { $value = $response->content; }
-       else { $value = undef; }
-
-       return [ $session, $value ];
-}
 
-sub long_request {
 
-       my($self, $session, $service, $method, @params) = @_;
 
-       my $request = $session->request( $method, @params );
-       my $response = $request->recv(30);
-
-       $request->wait_complete;
-
-       if(!$request->complete) {
-               throw $response ("Call to $service for method $method with params @params" . 
-                               "\n did not complete successfully");
-       }
-
-       if(!$response) {
-               warn "No response from $service for method $method with params @params";
-       }
-
-       if($response and UNIVERSAL::isa($response,"Error")) {
-               throw $response ("Call to $service for method $method with params @params" . 
-                               "\n failed with exception: " . $response->stringify );
-       }
-
-       $request->finish();
-
-       my $value;
-
-       if($response) { $value = $response->content; }
-       else { $value = undef; }
-
-       return $value;
-}
-
-sub finish_long_request {
-       my($self, $session) = @_;
-       if($session) {
-               $session->finish();
-               $session->disconnect();
-       }
-}
 
 
 1;
index f0f96f4..9e0bac1 100644 (file)
@@ -329,6 +329,114 @@ sub _fetch_hold_transit {
                $holdid )->gather(1);
 }
 
+__PACKAGE__->register_method(
+       method  => "capture_copy",
+       api_name        => "open-ils.circ.hold.capture_copy.barcode",
+       notes           => <<"  NOTE");
+       Captures a copy to fulfil a hold
+       Params is login session and copy barcode
+       login mus have COPY_CHECKIN permissions (since this is essentially
+       copy checkin)
+       NOTE
+
+sub capture_copy {
+       my( $self, $client, $login_session, $barcode ) = @_;
+
+       my $user = $apputils->check_user_session($login_session);
+
+       if($apputils->check_user_perms($user->id, $user->home_ou, "COPY_CHECKIN")) {
+               return OpenILS::Perm->new("COPY_CHECKIN");
+       }
+
+       my $session = $apputils->start_db_session();
+       my $copy = $session->request(
+               "open-ils.storage.direct.asset.copy.search.barcode",
+               $barcode )->gather(1);
+
+       warn "Capturing copy " . $copy->id . "\n";
+
+       # retrieve the hold copy maps for this copy
+       my $maps = $session->request(
+               "open-ils.storage.direct.action.hold_copy_map.search.target_copy.atomic",
+               $copy->id)->gather(1);
+
+       my @holdids = map { $_->hold } @$maps;
+
+       use Data::Dumper;
+       warn "Found possible holds\n" . Dumper(\@holdids) . "\n";
+
+       # retrieve sorted list of holds for the given maps and use the first
+       # if there is a hold for this lib, use that
+       my $holds = $session->request(
+               "open-ils.storage.direct.action.hold_request.search_where.atomic",
+               { id => \@holdids, current_copy => undef }, 
+               { order_by => "CASE WHEN ". $copy->circ_lib .
+                       " = (SELECT a.home_ou FROM actor.usr a where a.id = usr ) THEN 0 ELSE 1 END, request_time" }
+               )->gather(1);
+
+       my $hold = $holds->[0];
+
+       warn "Found hold " . $hold->id . "\n";
+
+       $hold->current_copy($copy->id);
+       $hold->capture_time("now"); # ???
+
+       #update the hold
+       my $stat = $session->request(
+                       "open-ils.storage.direct.action.hold_request.update", $hold)->gather(1);
+       if(!$stat) { throw OpenSRF::EX ("Error updating hold request " . $copy->id); }
+
+       $copy->status(8); #status on holds shelf
+
+       # if the staff member capturing this item is not at the pickup lib
+       if( $user->home_ou ne $hold->pickup_lib ) {
+               my $trans = Fieldmapper::action::hold_transit_copy->new;
+               $trans->hold($hold->id);
+               $trans->source($user->home_ou);
+               $trans->dest($hold->pickup_lib);
+               $trans->source_send_time("now");
+               my $meth = $self->method_lookup("open-ils.circ.hold_transit.create");
+               my ($stat) = $meth->run( $login_session, $trans, $session );
+               if(!$stat) { throw OpenSRF::EX ("Error creating new hold transit"); }
+               else { $copy->status(6); } #status in transit 
+       }
+
+       $copy->editor($user->id);
+       $copy->edit_date("now");
+       $stat = $session->request(
+               "open-ils.storage.direct.asset.copy.update", $copy )->gather(1);
+       if(!$stat) { throw OpenSRF::EX ("Error updating copy " . $copy->id); }
+
+       $apputils->commit_db_session($session);
+
+       return { route_to => $hold->pickup_lib };
+
+}
+
+
+__PACKAGE__->register_method(
+       method  => "create_hold_transit",
+       api_name        => "open-ils.circ.hold_transit.create",
+       notes           => <<"  NOTE");
+       Creates a new transit object
+       NOTE
+
+sub create_hold_transit {
+       my( $self, $client, $login_session, $transit, $session ) = @_;
+
+       my $user = $apputils->check_user_session($login_session);
+       if($apputils->check_user_perms($user->id, $user->home_ou, "CREATE_TRANSIT")) {
+               return OpenILS::Perm->new("CREATE_TRANSIT");
+       }
+       
+       my $ses;
+       if($session) { $ses = $session; } 
+       else { $ses = OpenSRF::AppSession->create("open-ils.storage"); }
+
+       return $ses->request(
+               "open-ils.storage.direct.action.hold_transit_copy.create", $transit )->gather(1);
+}
+
 
 
 
index 72062eb..498848b 100644 (file)
@@ -342,13 +342,14 @@ __PACKAGE__->register_method(
 sub permit_circ {
        my( $self, $client, $user_session, $barcode, $user_id, $outstanding_count ) = @_;
 
+       my $copy_status_mangled;
+
        my $renew = 0;
        if(defined($outstanding_count) && $outstanding_count eq "renew") {
                $renew = 1;
                $outstanding_count = 0;
        } else { $outstanding_count ||= 0; }
 
-
        my $session     = OpenSRF::AppSession->create("open-ils.storage");
        
        # collect items necessary for circ calculation
@@ -360,6 +361,13 @@ sub permit_circ {
                        text => "No copy available with barcode $barcode"
                };
        }
+       my $copy = $stash->get("circ_objects")->{copy};
+
+       if( $copy->status eq "8" ) { 
+               $copy_status_mangled = 8; 
+               $copy->status(0);
+       }
+
 
        $stash->set("run_block", $permission_script);
 
@@ -380,8 +388,24 @@ sub permit_circ {
        # run the permissibility script
        run_script();
 
-       
        my $arr = $stash->get("result");
+
+       if( $arr->[0] eq "0" and $copy_status_mangled == 8) {
+               my $hold = $session->request(
+                       "open-ils.storage.direct.action.hold_request.search.current_copy",
+                       $copy->id )->gather(1);
+               if($hold) {
+                       if( $hold->usr eq $user_id ) {
+                               return { status => 0, text => "OK" };
+                       } else {
+                               return { status => 6, 
+                                       text => "Copy is needed by a different user to fulfill a hold" };
+                       }
+               }
+       }
+
+
+       
        return { status => $arr->[0], text => $arr->[1] };
 
 }
@@ -613,6 +637,10 @@ sub checkin {
        my $transaction;
        my $user = $apputils->check_user_session($user_session);
 
+       if($apputils->check_user_perms($user->id, $user->home_ou, "COPY_CHECKIN")) {
+               return OpenILS::Perm->new("COPY_CHECKIN");
+       }
+
        try {
                my $session = $apputils->start_db_session();
                        
@@ -730,9 +758,6 @@ sub checkin {
 
 
 
-
-
-
 # ------------------------------------------------------------------------------
 # RENEWALS
 # ------------------------------------------------------------------------------
@@ -763,8 +788,15 @@ sub renew {
                "open-ils.storage.direct.action.hold_copy_map.search.target_copy.atomic",
                $copy->id )->gather(1);
 
+       my @holdids = map { $_->hold  } @$r;
+
        if(@$r != 0) { 
-               if( $user->id ne $circ->usr ) {
+
+               my $holds = $session->request(
+                       "open-ils.storage.direct.action.hold_request.search_where", 
+                               { id => \@holdids, current_copy => undef } )->gather(1);
+
+               if( $holds and $user->id ne $circ->usr ) {
                        if($apputils->check_user_perms($user->id, $user->home_ou, "RENEW_HOLD_OVERRIDE")) {
                                return OpenILS::Perm->new("RENEW_HOLD_OVERRIDE");
                        }
index f0d2ca1..e2423e5 100644 (file)
@@ -7,6 +7,7 @@ use OpenSRF::EX qw(:try);
 __PACKAGE__->register_method(
        method  => "proxy",
        api_name        => "open-ils.proxy.proxy",
+       stream  => 1,
 );