From 7794424ddd003ff4fdc9b7e73a7991824543b907 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 9 Jan 2006 15:21:59 +0000 Subject: [PATCH] more circ utility code more example permit script code more environment setup code git-svn-id: svn://svn.open-ils.org/ILS/trunk@2660 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Evergreen/circ_rules/circ_permit.js | 9 ++- Evergreen/circ_rules/script_libs.js | 21 ++++-- .../perlmods/OpenILS/Application/AppUtils.pm | 14 ++++ .../OpenILS/Application/Circ/Circulate.pm | 70 ++++++++++++++----- 4 files changed, 89 insertions(+), 25 deletions(-) diff --git a/Evergreen/circ_rules/circ_permit.js b/Evergreen/circ_rules/circ_permit.js index a91aecf1e0..2e7408d237 100644 --- a/Evergreen/circ_rules/circ_permit.js +++ b/Evergreen/circ_rules/circ_permit.js @@ -6,7 +6,10 @@ log_debug('Checking permit circ on ' + ' Patron Profile: ' + patron.profile + ' Patron Standing: ' + patron.standing + ' Patron copies: ' + patron_info.items_out + - ' Patron fines: ' + patron_info.fines ); + ' Patron fines: ' + patron_info.fines + + ' Copy status: ' + copy.status + + ' Copy location: ' + copy.location.name + + ''); /* Patron checks --------------------------------------------- */ @@ -19,11 +22,13 @@ if( patron.profile.match(/patrons/i) && patron_info.items_out > 10 ) if( patron.profile.match(/staff/i) && patron_info.items_out > 30 ) return result.event = 'PATRON_EXCEEDS_CHECKOUT_COUNT'; - /* Copy checks ------------------------------------------------ */ if( is_false( copy.circulate ) ) return result.event = 'COPY_CIRC_NOT_ALLOWED'; +if( !copy.status.match(/available/i) && !copy.status.match(/on holds shelf/i) ) + return result.event = 'COPY_NOT_AVAILABLE'; + /* check for holds -------------------------------------------- */ fetch_hold_by_copy( copy.id ); if( hold && hold.usr != patron.id ) diff --git a/Evergreen/circ_rules/script_libs.js b/Evergreen/circ_rules/script_libs.js index ceb6e4b397..d76a3c2f16 100644 --- a/Evergreen/circ_rules/script_libs.js +++ b/Evergreen/circ_rules/script_libs.js @@ -1,9 +1,22 @@ -function is_true(item) { - return !is_false(item); -} +/* pre-define all global circ vars. This way, any vars not fetched and + defined by the circ code won't throw exceptions when accessed */ + +var hold = null; /* most recently retrieve hold object */ +var copy = null; /* the current copy object */ +var title = null; /* the current title (biblio record entry) object */ +var patron = null; /* the current patron object */ +var patron_info = null; /* additional info on the current patron */ + + + + +/* Utility function ----------------------------------------------------- */ + +function is_true(item) { return !is_false(item); } function is_false(item) { if( ! item ) return true; if( item.match(/0/) ) return true; - false; + return false; } + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index 1a3410fa07..ceb572f3f4 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -581,5 +581,19 @@ sub fetch_patron_circ_summary { } +sub fetch_copy_statuses { + my( $self ) = @_; + $logger->debug("Fetching copy statuses"); + return $self->simplereq( + 'open-ils.storage', + 'open-ils.storage.direct.config.copy_status.retrieve.all.atomic' ); +} + +sub fetch_copy_locations { + my $self = shift; + return $self->simplereq( + 'open-ils.storage', + 'open-ils.storage.direct.asset.copy_location.retrieve.all.atomic'); +} 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index d96937a957..c88ec73c87 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -10,10 +10,12 @@ use OpenILS::Application::Circ::Holds; my $apputils = "OpenILS::Application::AppUtils"; my $holdcode = "OpenILS::Application::Circ::Holds"; -my %scripts; # - circulation script filenames -my $standings; # - cached patron standings -my $group_tree; # - cached permission group tree -my $script_libs; # - any additional script libraries +my %scripts; # - circulation script filenames +my $standings; # - cached patron standings +my $group_tree; # - cached permission group tree +my $script_libs; # - any additional script libraries +my $copy_statuses; # - copy status objects +my $copy_locations; # - shelving locations # ------------------------------------------------------------------------------ # Load the circ script from the config @@ -59,9 +61,11 @@ sub initialize { sub create_circ_env { my %params = @_; - my $barcode = $params{barcode}; - my $patron = $params{patron}; - my $summary = $params{fetch_patron_circ_summary}; + my $barcode = $params{barcode}; + my $patron = $params{patron}; + my $fetch_summary = $params{fetch_patron_circ_summary}; + my $fetch_cstatus = $params{fetch_copy_statuses}; + my $fetch_clocs = $params{fetch_copy_locations}; my ( $copy, $title, $evt ); @@ -70,15 +74,18 @@ sub create_circ_env { $group_tree = $apputils->fetch_permission_group_tree(); } + # XXX must decide if caching is "right" + my $cstatus = $apputils->fetch_copy_statuses if( $fetch_cstatus and !$copy_statuses ); + my $clocs = $apputils->fetch_copy_locations if( $fetch_clocs and !$copy_locations); + my $summary = $apputils->fetch_patron_circ_summary($patron->id) if $fetch_summary; + ( $copy, $evt ) = $apputils->fetch_copy_by_barcode( $barcode ); return ( undef, $evt ) if $evt; ( $title, $evt ) = $apputils->fetch_record_by_copy( $copy->id ); return ( undef, $evt ) if $evt; - $summary = $apputils->fetch_patron_circ_summary($patron->id) if $summary; - - _doctor_circ_objects( $patron, $title, $copy, $summary ); + _doctor_circ_objects( $patron, $title, $copy, $summary, $cstatus, $clocs ); my $runner = _build_circ_script_runner( $patron, $title, $copy, $summary ); @@ -87,8 +94,6 @@ sub create_circ_env { title => $title, patron => $patron, copy => $copy, - standings => $standings, - group_tree => $group_tree, circ_summary => $summary, }; } @@ -99,7 +104,7 @@ sub create_circ_env { # environment # ------------------------------------------------------------------------------ sub _doctor_circ_objects { - my( $patron, $title, $copy, $summary ) = @_; + my( $patron, $title, $copy, $summary, $cstatus, $clocs ) = @_; # set the patron standing to the standing name for my $s (@$standings) { @@ -108,9 +113,18 @@ sub _doctor_circ_objects { # set the patron ptofile to the profile name $patron->profile( _patron_get_profile( $patron, $group_tree ) ); + + # set the copy status to a status name + $copy->status( _get_copy_status_name( $copy, $cstatus ) ); + + # set the copy location to the location object + $copy->location( _get_copy_location( $copy, $clocs ) ); + } # recurse and find the patron profile name from the tree +# another option would be to grab the groups for the patron +# and cycle through those until the "profile" group has been found sub _patron_get_profile { my( $patron, $group_tree ) = @_; return $group_tree->name if ($group_tree->id eq $patron->profile); @@ -121,6 +135,21 @@ sub _patron_get_profile { return undef; } +sub _get_copy_status_name { + my( $copy, $cstatus ) = @_; + for my $status (@$cstatus) { + return $status->name if( $status->id eq $copy->status ) + } + return undef; +} + +sub _get_copy_location { + my( $copy, $locations ) = @_; + for my $loc (@$locations) { + return $loc if $loc->id eq $copy->location; + } +} + # ------------------------------------------------------------------------------ # Constructs and shoves data into the script environment @@ -136,8 +165,6 @@ sub _build_circ_script_runner { $runner->insert( 'patron', $patron ); $runner->insert( 'title', $title ); $runner->insert( 'copy', $copy ); - $runner->insert( 'standings', $standings ); - $runner->insert( 'group_tree', $group_tree ); # circ script result $runner->insert( 'result', {} ); @@ -192,9 +219,12 @@ sub permit_circ { # fetch and build the circulation environment ( $env, $evt ) = create_circ_env( - barcode => $barcode, - patron => $patron, - fetch_patron_circ_summary => 1 ); + barcode => $barcode, + patron => $patron, + fetch_patron_circ_summary => 1, + fetch_copy_statuses => 1, + fetch_copy_locations => 1, + ); return $evt if $evt; # run the script @@ -202,7 +232,9 @@ sub permit_circ { $runner->load($scripts{circ_permit}); $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Script Died"); - return OpenILS::Event->new($runner->retrieve('result.event')); + my $evtname = $runner->retrieve('result.event'); + $logger->activity("Permit Circ for user $patronid and barcode $barcode returned event: $evtname"); + return OpenILS::Event->new($evtname); } -- 2.43.2