From 3c73d87e062e69d08ca1b4095f5dd40c3380337e Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 27 Jan 2006 16:52:26 +0000 Subject: [PATCH] broke the permit portion of circ into patron and copy permit scripts git-svn-id: svn://svn.open-ils.org/ILS/trunk@2859 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/openils.xml.example | 12 ++ .../{circ_permit.js => circ_permit_copy.js} | 15 +- .../backend/circ/circ_permit_patron.js | 41 ++++++ .../OpenILS/Application/Circ/Circulate.pm | 128 ++++++++++++------ 4 files changed, 142 insertions(+), 54 deletions(-) rename Open-ILS/src/javascript/backend/circ/{circ_permit.js => circ_permit_copy.js} (79%) create mode 100644 Open-ILS/src/javascript/backend/circ/circ_permit_patron.js diff --git a/Open-ILS/examples/openils.xml.example b/Open-ILS/examples/openils.xml.example index db7e5a4564..35dc8d5b8e 100644 --- a/Open-ILS/examples/openils.xml.example +++ b/Open-ILS/examples/openils.xml.example @@ -281,6 +281,18 @@ For non-core config info, see the inline documentation within this file permit_hold.rules permit_renew.rules + + /openils/var/circ/ + + circ_permit_patron.js + circ_permit_copy.js + circ_duration.js + circ_recurring_fines.js + circ_max_fines.js + hold_permit.js + renew_permit.js + + diff --git a/Open-ILS/src/javascript/backend/circ/circ_permit.js b/Open-ILS/src/javascript/backend/circ/circ_permit_copy.js similarity index 79% rename from Open-ILS/src/javascript/backend/circ/circ_permit.js rename to Open-ILS/src/javascript/backend/circ/circ_permit_copy.js index 344ded58d4..1aeff6e66b 100644 --- a/Open-ILS/src/javascript/backend/circ/circ_permit.js +++ b/Open-ILS/src/javascript/backend/circ/circ_permit_copy.js @@ -4,7 +4,6 @@ function go() { load_lib('circ_lib.js'); - /* collect some useful variables */ var copy = environment.copy; var patron = environment.patron; @@ -16,7 +15,7 @@ var fines = environment.patronFines; var isRenewal = environment.isRenewal; -log_debug('CIRC PERMIT: permit circ on ' + +log_debug('circ_permit_copy: permit circ on ' + ' Copy: ' + copy.id + ', Patron:' + patron.id + ', Patron Username:' + patron.usrname + @@ -32,9 +31,6 @@ log_debug('CIRC PERMIT: permit circ on ' + -if( standing != 'good' ) - return result.event = 'PATRON_BAD_STANDING'; - if( copy.circulate == '0' ) return result.event = 'COPY_CIRC_NOT_ALLOWED'; @@ -45,15 +41,6 @@ if( status != 'available' && status != 'on holds shelf' ) return result.event = 'COPY_NOT_AVAILABLE'; - - -if( profile == 'patrons' && itemsOut > 10 ) - return result.event = 'PATRON_EXCEEDS_CHECKOUT_COUNT'; - -if( profile == 'staff' && itemsOut > 30 ) - return result.event = 'PATRON_EXCEEDS_CHECKOUT_COUNT'; - - var hold = copy.fetchHold(); if( hold && hold.usr != patron.id ) return result.event = 'COPY_NEEDED_FOR_HOLD'; diff --git a/Open-ILS/src/javascript/backend/circ/circ_permit_patron.js b/Open-ILS/src/javascript/backend/circ/circ_permit_patron.js new file mode 100644 index 0000000000..a0b6270800 --- /dev/null +++ b/Open-ILS/src/javascript/backend/circ/circ_permit_patron.js @@ -0,0 +1,41 @@ +function go() { + +/* load the lib script */ +load_lib('circ_lib.js'); + + +/* collect some useful variables */ +var patron = environment.patron; +var standing = patron.standing.value.toLowerCase(); +var profile = patron.profile.name.toLowerCase(); +var itemsOut = environment.patronItemsOut; +var fines = environment.patronFines; +var isRenewal = environment.isRenewal; + + +log_debug('circ_permit_patron: permit circ on ' + + ', Patron:' + patron.id + + ', Patron Username:' + patron.usrname + + ', Patron Profile: ' + patron.profile.name + + ', Patron Standing: ' + patron.standing.value + + ', Patron copies: ' + itemsOut + + ', Patron Library: ' + patron.home_ou.name + + ', Patron fines: ' + fines + + ', Is Renewal: ' + ( (isRenewal) ? "yes" : "no" ) + + ''); + + + +if( standing != 'good' ) + return result.event = 'PATRON_BAD_STANDING'; + +if( profile == 'patrons' && itemsOut > 10 ) + return result.event = 'PATRON_EXCEEDS_CHECKOUT_COUNT'; + +if( profile == 'staff' && itemsOut > 30 ) + return result.event = 'PATRON_EXCEEDS_CHECKOUT_COUNT'; + + +} go(); + + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index f209b3a6ed..54b55a6e99 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -25,20 +25,23 @@ sub initialize { my $self = shift; my $conf = OpenSRF::Utils::SettingsClient->new; - my @pfx = ( "apps", "open-ils.circ","app_settings", "scripts" ); - - my $p = $conf->config_value( @pfx, 'permission' ); - my $d = $conf->config_value( @pfx, 'duration' ); - my $f = $conf->config_value( @pfx, 'recurring_fines' ); - my $m = $conf->config_value( @pfx, 'max_fines' ); - my $pr = $conf->config_value( @pfx, 'permit_renew' ); - my $ph = $conf->config_value( @pfx, 'permit_hold' ); - my $lb = $conf->config_value( 'apps', 'open-ils.circ', 'app_settings', 'script_path' ); + my @pfx2 = ( "apps", "open-ils.circ","app_settings" ); + my @pfx = ( @pfx2, "scripts" ); + + my $p = $conf->config_value( @pfx, 'circ_permit_patron' ); + my $c = $conf->config_value( @pfx, 'circ_permit_copy' ); + my $d = $conf->config_value( @pfx, 'circ_duration' ); + my $f = $conf->config_value( @pfx, 'circ_recurring_fines' ); + my $m = $conf->config_value( @pfx, 'circ_max_fines' ); + my $pr = $conf->config_value( @pfx, 'renew_permit' ); + my $ph = $conf->config_value( @pfx, 'hold_permit' ); + my $lb = $conf->config_value( @pfx2, 'script_path' ); $logger->error( "Missing circ script(s)" ) - unless( $p and $d and $f and $m and $pr and $ph ); + unless( $p and $c and $d and $f and $m and $pr and $ph ); - $scripts{circ_permit} = $p; + $scripts{circ_permit_patron} = $p; + $scripts{circ_permit_copy} = $c; $scripts{circ_duration} = $d; $scripts{circ_recurring_fines}= $f; $scripts{circ_max_fines} = $m; @@ -49,7 +52,8 @@ sub initialize { $script_libs = $lb; $logger->debug("Loaded rules scripts for circ: " . - "circ permit : $p, circ duration :$d , circ recurring fines : $f, " . + "circ permit patron: $p, circ permit copy: $c, ". + "circ duration :$d , circ recurring fines : $f, " . "circ max fines : $m, circ renew permit : $pr, permit hold: $ph"); } @@ -63,16 +67,30 @@ sub create_circ_ctx { my %params = @_; 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 $evt; my $ctx = {}; - $ctx->{patron} = $patron; - $ctx->{type} = $params{type}; - $ctx->{isrenew} = $params{isrenew}; + + $ctx->{type} = $params{type}; + $ctx->{isrenew} = $params{isrenew}; + $ctx->{noncat} = $params{noncat}; + + $evt = _ctx_add_patron_objects($ctx, %params); + return $evt if $evt; + $evt = _ctx_add_copy_objects($ctx, %params) unless $ctx->{noncat}; + return $evt if $evt; + + _doctor_circ_objects($ctx); + _build_circ_script_runner($ctx); + _add_script_runner_methods( $ctx ); + + return $ctx; +} + +sub _ctx_add_patron_objects { + my( $ctx, %params) = @_; + + $ctx->{patron} = $params{patron}; if(!defined($cache{patron_standings})) { $cache{patron_standings} = $apputils->fetch_patron_standings(); @@ -82,32 +100,38 @@ sub create_circ_ctx { $ctx->{patron_standings} = $cache{patron_standings}; $ctx->{group_tree} = $cache{group_tree}; + $ctx->{patron_circ_summary} = + $apputils->fetch_patron_circ_summary($ctx->{patron}->id) + if $params{fetch_patron_circsummary}; + + return undef; +} + + +sub _ctx_add_copy_objects { + my($ctx, %params) = @_; + my $evt; + $cache{copy_statuses} = $apputils->fetch_copy_statuses - if( $fetch_cstatus and !defined($cache{copy_statuses}) ); + if( $params{fetch_copy_statuses} and !defined($cache{copy_statuses}) ); $cache{copy_locations} = $apputils->fetch_copy_locations - if( $fetch_clocs and !defined($cache{copy_locations})); + if( $params{fetch_copy_locations} and !defined($cache{copy_locations})); $ctx->{copy_statuses} = $cache{copy_statuses}; $ctx->{copy_locations} = $cache{copy_locations}; - $ctx->{patron_circ_summary} = - $apputils->fetch_patron_circ_summary($patron->id) if $fetch_summary; - - ( $ctx->{copy}, $evt ) = $apputils->fetch_copy_by_barcode( $barcode ); - return ( undef, $evt ) if $evt; + ( $ctx->{copy}, $evt ) = $apputils->fetch_copy_by_barcode( $params{barcode} ); + return $evt if $evt; ( $ctx->{title}, $evt ) = $apputils->fetch_record_by_copy( $ctx->{copy}->id ); - return ( undef, $evt ) if $evt; - - _doctor_circ_objects($ctx); - _build_circ_script_runner($ctx); - _add_script_runner_methods( $ctx ); + return $evt if $evt; - return $ctx; + return undef; } + # ------------------------------------------------------------------------------ # Patches up circ objects to make them easier to use from within the script # environment @@ -245,8 +269,9 @@ sub permit_circ { my $barcode = $params{barcode}; my $patronid = $params{patron}; my $isrenew = $params{renew}; - my ( $requestor, $patron, $ctx, $evt ); + my $noncat = $params{noncat}; + my ( $requestor, $patron, $ctx, $evt ); # check permisson of the requestor ( $requestor, $patron, $evt ) = @@ -254,8 +279,9 @@ sub permit_circ { $authtoken, $patronid, 'VIEW_PERMIT_CHECKOUT' ); return $evt if $evt; - $logger->info("Checking circulation permission for staff: " . $requestor->id . - ", patron " . $patron->id . ", and barcode $barcode" ); + $logger->info("Checking circulation permission for staff: " . + $requestor->id . ", patron " . $patron->id . + ", and barcode " . (($barcode) ? $barcode : "") ); # fetch and build the circulation environment ( $ctx, $evt ) = create_circ_ctx( @@ -266,18 +292,40 @@ sub permit_circ { fetch_copy_statuses => 1, fetch_copy_locations => 1, isrenew => ($isrenew) ? 1 : 0, + noncat => $noncat, ); return $evt if $evt; - # run the script - my $runner = $ctx->{runner}; + return _run_permit_scripts($ctx); +} + - $runner->load($scripts{circ_permit}); - $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Script Died: $@"); +# Runs the patron and copy permit scripts +# if this is a non-cat circulation, the copy permit script +# is not run +sub _run_permit_scripts { + my $ctx = shift; + my $runner = $ctx->{runner}; + my $patronid = $ctx->{patron}->id; + my $barcode = $ctx->{copy}->barcode; + + $runner->load($scripts{circ_permit_patron}); + $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Patron Script Died: $@"); my $evtname = $runner->retrieve('result.event'); - $logger->activity("Permit Circ for user $patronid and barcode $barcode returned event: $evtname"); + $logger->activity("circ_permit_patron for user $patronid returned event: $evtname"); + + return OpenILS::Event->new($evtname) + if ( $ctx->{noncat} or $evtname ne 'SUCCESS' ); + + $runner->load($scripts{circ_permit_copy}); + $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Copy Script Died: $@"); + $evtname = $runner->retrieve('result.event'); + $logger->activity("circ_permit_patron for user $patronid ". + "and copy $barcode returned event: $evtname"); + return OpenILS::Event->new($evtname); + } -- 2.43.2