From: erickson Date: Sun, 6 Aug 2006 15:14:18 +0000 (+0000) Subject: moved constants out to their own module, updating code X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ee42523c550afe4b77f26caedcd3424363df01c9;p=evergreen%2Fpines.git moved constants out to their own module, updating code git-svn-id: svn://svn.open-ils.org/ILS/trunk@5318 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index c4817fb013..2cf0ae7d9c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -22,6 +22,7 @@ use OpenSRF::Utils::Cache; use JSON; use DateTime; use DateTime::Format::ISO8601; +use OpenILS::Const qw/:const/; use OpenILS::Application::Actor::Container; use OpenILS::Application::Actor::ClosedDates; @@ -1588,14 +1589,14 @@ sub user_transaction_retrieve { $u->start_mods_batch($title->marc()); $mods = $u->finish_mods_batch(); } otherwise { - if ($title->id == -1) { + if ($title->id == OILS_PRECAT_RECORD) { my $copy = $apputils->simple_scalar_request( "open-ils.cstore", "open-ils.cstore.direct.asset.copy.retrieve", $circ->target_copy ); $mods = new Fieldmapper::metabib::virtual_record; - $mods->doc_id(-1); + $mods->doc_id(OILS_PRECAT_RECORD); $mods->title($copy->dummy_title); $mods->author($copy->dummy_author); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index 0fd4a18c8d..a46cc7cf68 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -8,15 +8,12 @@ use OpenSRF::EX qw(:try); use OpenILS::Event; use Data::Dumper; use OpenILS::Utils::CStoreEditor; - - -my $cache_client = "OpenSRF::Utils::Cache"; - -my $storage_session = undef; +use OpenILS::Const qw/:const/; # --------------------------------------------------------------------------- # Pile of utilty methods used accross applications. # --------------------------------------------------------------------------- +my $cache_client = "OpenSRF::Utils::Cache"; # --------------------------------------------------------------------------- @@ -39,7 +36,6 @@ sub start_db_session { $logger->debug("Setting global storage session to ". "session: " . $session->session_id . " : " . $session->app ); - $storage_session = $session; return $session; } @@ -91,7 +87,6 @@ sub commit_db_session { $session->finish(); $session->disconnect(); $session->kill_me(); - $storage_session = undef; } sub rollback_db_session { @@ -104,7 +99,6 @@ sub rollback_db_session { $session->finish(); $session->disconnect(); $session->kill_me(); - $storage_session = undef; } @@ -144,36 +138,11 @@ sub simplereq { return $self->simple_scalar_request($service, $method, @params); } -sub get_storage_session { - - return undef; # XXX testing - - if( $storage_session and - $storage_session->connected and - $storage_session->transport_connected and - $storage_session->app eq 'open-ils.storage' ) { - - $logger->debug("get_storage_session(): returning existing session"); - return $storage_session; - } - $logger->debug("get_storage_session(): returning undef"); - $storage_session = undef; - return undef; -} - sub simple_scalar_request { my($self, $service, $method, @params) = @_; - my $session = undef; - - if( $service eq 'open-ils.storage' ) { - if( $session = get_storage_session() ) { - $logger->debug("simple request using existing storage session ".$session->session_id); - } else { $session = undef; } - } - - $session = OpenSRF::AppSession->create( $service ) unless $session; + my $session = OpenSRF::AppSession->create( $service ); my $request = $session->request( $method, @params ); @@ -924,6 +893,15 @@ sub copy_status_to_name { return undef; } + +sub copy_status { + my( $self, $arg ) = @_; + return $arg if ref $arg; + $copy_statuses = $self->fetch_copy_statuses unless $copy_statuses; + my ($stat) = grep { $_->id == $arg } @$copy_statuses; + return $stat; +} + sub fetch_open_transit_by_copy { my( $self, $copyid ) = @_; my($transit, $evt); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index 648350f644..d52de29a78 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -14,8 +14,7 @@ use DateTime; use DateTime::Format::ISO8601; use OpenILS::Application::AppUtils; -my $apputils = "OpenILS::Application::AppUtils"; -my $U = $apputils; + use OpenSRF::Utils qw/:datetime/; use OpenILS::Utils::ModsParser; use OpenILS::Event; @@ -24,6 +23,10 @@ use OpenSRF::Utils::Logger qw(:logger); use OpenILS::Utils::Fieldmapper; use OpenILS::Utils::Editor q/:funcs/; use OpenILS::Utils::CStoreEditor q/:funcs/; +use OpenILS::Const qw/:const/; + +my $apputils = "OpenILS::Application::AppUtils"; +my $U = $apputils; # ------------------------------------------------------------------------ @@ -261,10 +264,8 @@ sub _set_circ_lost { $logger->activity("user ".$reqr->id." marking copy ".$copy->id. " lost for circ ". $circ->id. " and checking for necessary charges"); - my $newstat = $U->copy_status_from_name('lost'); - if( $copy->status ne $newstat->id ) { - - $copy->status($newstat->id); + if( $copy->status ne OILS_COPY_STATUS_LOST ) { + $copy->status(OILS_COPY_STATUS_LOST); $U->update_copy( copy => $copy, editor => $reqr->id, @@ -296,7 +297,7 @@ sub _set_circ_lost { return $evt if $evt; } - $circ->stop_fines("LOST"); + $circ->stop_fines(OILS_STOP_FINES_LOST); return undef; } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index 4c6f4c2f43..0cbdc18303 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -4,7 +4,7 @@ use base 'OpenSRF::Application'; use OpenSRF::EX qw(:try); use OpenSRF::Utils::SettingsClient; use OpenSRF::Utils::Logger qw(:logger); -#use OpenILS::Application::Circ::Circulator; +use OpenILS::Const qw/:const/; my %scripts; my $script_libs; @@ -253,9 +253,8 @@ use OpenILS::Application::Circ::Transit; use OpenSRF::Utils::Logger qw(:logger); use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Application::Circ::ScriptBuilder; +use OpenILS::Const qw/:const/; -sub PRECAT_FINE_LEVEL { return 2; } -sub PRECAT_LOAN_DURATION { return 2; } my $U = "OpenILS::Application::AppUtils"; my $holdcode = "OpenILS::Application::Circ::Holds"; my $transcode = "OpenILS::Application::Circ::Transit"; @@ -451,7 +450,7 @@ sub mk_script_runner { } } - $self->is_precat(1) if $self->copy and $self->copy->call_number == -1; + $self->is_precat(1) if $self->copy and $self->copy->call_number == OILS_PRECAT_CALL_NUMBER; # Set some circ-specific flags in the script environment my $evt = "environment"; @@ -513,7 +512,7 @@ sub do_copy_checks { my $stat = (ref $copy->status) ? $copy->status->id : $copy->status; # We cannot check out a copy if it is in-transit - if( $stat == $U->copy_status_from_name('in transit')->id ) { + if( $stat == OILS_COPY_STATUS_IN_TRANSIT ) { return $self->bail_on_events(OpenILS::Event->new('COPY_IN_TRANSIT')); } @@ -663,7 +662,7 @@ sub handle_claims_returned { my $CR = $self->editor->search_action_circulation( { target_copy => $copy->id, - stop_fines => 'CLAIMSRETURNED', + stop_fines => OILS_STOP_FINES_CLAIMSRETURNED, checkin_time => undef, } ); @@ -729,7 +728,7 @@ sub do_checkout { $self->make_precat_copy; return if $self->bail_out; - } elsif( $self->copy->call_number == -1 ) { + } elsif( $self->copy->call_number == OILS_PRECAT_CALL_NUMBER ) { return $self->bail_on_events(OpenILS::Event->new('ITEM_NOT_CATALOGED')); } @@ -748,7 +747,7 @@ sub do_checkout { return $self->bail_on_events($self->editor->event) unless $self->editor->create_action_circulation($self->circ); - $self->copy->status($U->copy_status_from_name('checked out')); + $self->copy->status(OILS_COPY_STATUS_CHECKED_OUT); $self->update_copy; return if $self->bail_out; @@ -792,7 +791,7 @@ sub update_copy { return $self->bail_on_events($self->editor->event) unless $self->editor->update_asset_copy($self->copy); - $copy->status($stat) if $stat; + $copy->status($U->copy_status($copy->status)); $copy->location($loc) if $loc; $copy->circ_lib($circ_lib) if $circ_lib; } @@ -924,13 +923,13 @@ sub build_checkout_circ_object { $logger->debug("circulator: building circulation with duration=$dname, ". "maxfine=$mname, recurring=$rname, duration-level=$dur_level, recurring-level=$rec_level"); - $circ->duration( $duration->shrt ) if ($dur_level == 1); - $circ->duration( $duration->normal ) if ($dur_level == 2); - $circ->duration( $duration->extended ) if ($dur_level == 3); + $circ->duration( $duration->shrt ) if ($dur_level == OILS_CIRC_DURATION_SHORT); + $circ->duration( $duration->normal ) if ($dur_level == OILS_CIRC_DURATION_NORMAL); + $circ->duration( $duration->extended ) if ($dur_level == OILS_CIRC_DURATION_EXTENDED); - $circ->recuring_fine( $recurring->low ) if ($rec_level =~ /low/io); - $circ->recuring_fine( $recurring->normal ) if ($rec_level =~ /normal/io); - $circ->recuring_fine( $recurring->high ) if ($rec_level =~ /high/io); + $circ->recuring_fine( $recurring->low ) if ($rec_level eq OILS_REC_FINE_LEVEL_LOW); + $circ->recuring_fine( $recurring->normal ) if ($rec_level eq OILS_REC_FINE_LEVEL_NORMAL); + $circ->recuring_fine( $recurring->high ) if ($rec_level eq OILS_REC_FINE_LEVEL_HIGH); $circ->duration_rule( $duration->name ); $circ->recuring_fine_rule( $recurring->name ); @@ -1040,9 +1039,9 @@ sub make_precat_copy { $copy->creator($self->editor->requestor->id); $copy->editor($self->editor->requestor->id); $copy->barcode($self->copy_barcode); - $copy->call_number(-1); #special CN for precat materials - $copy->loan_duration(&PRECAT_LOAN_DURATION); - $copy->fine_level(&PRECAT_FINE_LEVEL); + $copy->call_number(OILS_PRECAT_CALL_NUMBER); + $copy->loan_duration(OILS_PRECAT_COPY_LOAN_DURATION); + $copy->fine_level(OILS_PRECAT_COPY_FINE_LEVEL); $copy->dummy_title($self->dummy_title || ""); $copy->dummy_author($self->dummy_author || ""); @@ -1121,7 +1120,11 @@ sub do_checkin { { target_copy => $self->copy->id, xact_finish => undef, - stop_fines => [ 'CLAIMSRETURNED', 'LOST', 'LONGOVERDUE' ] + stop_fines => [ + OILS_STOP_FINES_CLAIMSRETURNED, + OILS_STOP_FINES_LOST, + OILS_STOP_FINES_LONGOVERDUE, + ] } )->[0]; } @@ -1132,7 +1135,7 @@ sub do_checkin { # if the circ is marked as 'claims returned', add the event to the list $self->push_events(OpenILS::Event->new('CIRC_CLAIMS_RETURNED')) if ($self->circ and $self->circ->stop_fines - and $self->circ->stop_fines eq 'CLAIMSRETURNED'); + and $self->circ->stop_fines eq OILS_STOP_FINES_CLAIMSRETURNED); # handle the overridable events $self->override_events unless $self->is_renewal; @@ -1212,7 +1215,7 @@ sub do_checkin { my $stat = (ref $self->copy->status) ? $self->copy->status->id : $self->copy->status; $self->hold($U->fetch_open_hold_by_copy($self->copy->id)) - if( $stat == $U->copy_status_from_name('on holds shelf')->id ); + if( $stat == OILS_COPY_STATUS_ON_HOLDS_SHELF ); $self->bail_out(1); # no need to commit anything } else { @@ -1232,13 +1235,13 @@ sub reshelve_copy { my $stat = ref($copy->status) ? $copy->status->id : $copy->status; if($force || ( - $stat != $U->copy_status_from_name('on holds shelf')->id and - $stat != $U->copy_status_from_name('available')->id and - $stat != $U->copy_status_from_name('cataloging')->id and - $stat != $U->copy_status_from_name('in transit')->id and - $stat != $U->copy_status_from_name('reshelving')->id) ) { + $stat != OILS_COPY_STATUS_ON_HOLDS_SHELF and + $stat != OILS_COPY_STATUS_AVAILABLE and + $stat != OILS_COPY_STATUS_CATALOGING and + $stat != OILS_COPY_STATUS_IN_TRANSIT and + $stat != OILS_COPY_STATUS_RESHELVING )) { - $copy->status( $U->copy_status_from_name('reshelving') ); + $copy->status( OILS_COPY_STATUS_RESHELVING ); $self->update_copy; $self->checkin_changed(1); } @@ -1248,10 +1251,9 @@ sub reshelve_copy { sub checkin_handle_precat { my $self = shift; my $copy = $self->copy; - my $catstat = $U->copy_status_from_name('cataloging'); - if( $self->is_precat and ($copy->status != $catstat->id) ) { - $copy->status($catstat); + if( $self->is_precat and ($copy->status != OILS_COPY_STATUS_CATALOGING) ) { + $copy->status(OILS_COPY_STATUS_CATALOGING); $self->update_copy(); $self->checkin_changed(1); $self->push_events(OpenILS::Event->new('ITEM_NOT_CATALOGED')); @@ -1261,7 +1263,7 @@ sub checkin_handle_precat { sub checkin_build_copy_transit { my $self = shift; - my $copy = $self->copy; + my $copy = $self->copy; my $transit = Fieldmapper::action::transit_copy->new; $transit->source($self->editor->requestor->ws_ou); @@ -1273,7 +1275,7 @@ sub checkin_build_copy_transit { return $self->bail_on_events($self->editor->event) unless $self->editor->create_action_transit_copy($transit); - $copy->status($U->copy_status_from_name('in transit')); + $copy->status(OILS_COPY_STATUS_IN_TRANSIT); $self->update_copy; $self->checkin_changed(1); } @@ -1316,7 +1318,7 @@ sub attempt_checkin_hold_capture { if( $hold->pickup_lib == $self->editor->requestor->ws_ou ) { # This hold was captured in the correct location - $copy->status( $U->copy_status_from_name('on holds shelf') ); + $copy->status(OILS_COPY_STATUS_ON_HOLDS_SHELF); $self->push_events(OpenILS::Event->new('SUCCESS')); } else { @@ -1324,7 +1326,7 @@ sub attempt_checkin_hold_capture { # Hold needs to be picked up elsewhere. Build a hold # transit and route the item. $self->checkin_build_hold_transit(); - $copy->status($U->copy_status_from_name('in transit') ); + $copy->status(OILS_COPY_STATUS_IN_TRANSIT); return 1 if $self->bail_out; $self->push_events( OpenILS::Event->new('ROUTE_ITEM', org => $hold->pickup_lib)); @@ -1352,7 +1354,7 @@ sub checkin_build_hold_transit { # when the copy gets to its destination, it will recover # this status - put it onto the holds shelf - $trans->copy_status($U->copy_status_from_name('on holds shelf')->id); + $trans->copy_status(OILS_COPY_STATUS_IN_TRANSIT); return $self->bail_on_events($self->editor->event) unless $self->editor->create_action_hold_transit_copy($trans); @@ -1365,7 +1367,7 @@ sub process_received_transit { my $copy = $self->copy; my $copyid = $self->copy->id; - my $status_name = $U->copy_status_to_name($copy->status); + my $status_name = $U->copy_status($copy->status)->name; $logger->debug("circulator: attempting transit receive on ". "copy $copyid. Copy status is $status_name"); @@ -1422,8 +1424,8 @@ sub checkin_handle_circ { } if(!$circ->stop_fines) { - $circ->stop_fines('CHECKIN'); - $circ->stop_fines('RENEW') if $self->is_renewal; + $circ->stop_fines(OILS_STOP_FINES_CHECKIN); + $circ->stop_fines(OILS_STOP_FINES_RENEW) if $self->is_renewal; $circ->stop_fines_time('now'); } @@ -1436,7 +1438,7 @@ sub checkin_handle_circ { $circ->checkin_staff($self->editor->requestor->id); $circ->checkin_lib($self->editor->requestor->ws_ou); - $self->copy->status($U->copy_status_from_name('reshelving')); + $self->copy->status($U->copy_status(OILS_COPY_STATUS_RESHELVING)); $self->update_copy; return $self->bail_on_events($self->editor->event) @@ -1512,17 +1514,17 @@ sub check_checkin_copy_status { my $status = ref($copy->status) ? $copy->status->id : $copy->status; return undef - if( $status == $U->copy_status_from_name('available')->id || - $status == $U->copy_status_from_name('checked out')->id || - $status == $U->copy_status_from_name('in process')->id || - $status == $U->copy_status_from_name('in transit')->id || - $status == $U->copy_status_from_name('reshelving')->id ); + if( $status == OILS_COPY_STATUS_AVAILABLE || + $status == OILS_COPY_STATUS_CHECKED_OUT || + $status == OILS_COPY_STATUS_IN_PROCESS || + $status == OILS_COPY_STATUS_IN_TRANSIT || + $status == OILS_COPY_STATUS_RESHELVING ); return OpenILS::Event->new('COPY_STATUS_LOST', payload => $copy ) - if( $status == $U->copy_status_from_name('lost')->id ); + if( $status == OILS_COPY_STATUS_LOST ); return OpenILS::Event->new('COPY_STATUS_MISSING', payload => $copy ) - if( $status == $U->copy_status_from_name('missing')->id ); + if( $status == OILS_COPY_STATUS_MISSING ); return OpenILS::Event->new('COPY_BAD_STATUS', payload => $copy ); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index f58ed71cf6..55f3d147b1 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -23,9 +23,9 @@ use OpenSRF::EX qw(:try); use OpenILS::Perm; use OpenILS::Event; use OpenSRF::Utils::Logger qw(:logger); -#use OpenILS::Utils::Editor q/:funcs/; use OpenILS::Utils::CStoreEditor q/:funcs/; use OpenILS::Utils::PermitHold; +use OpenILS::Const qw/:const/; my $apputils = "OpenILS::Application::AppUtils"; my $U = $apputils; @@ -425,7 +425,7 @@ sub cancel_hold { if( $copy->status == $stat->id ) { $logger->info("setting copy to status 'reshelving' on hold cancel"); - $copy->status($U->copy_status_from_name('reshelving')->id); + $copy->status(OILS_COPY_STATUS_RESHELVING); $copy->editor($e->requestor->id); $copy->edit_date('now'); $e->update_asset_copy($copy) or return $e->event; @@ -566,7 +566,7 @@ sub capture_copy { if(!$stat) { throw OpenSRF::EX::ERROR ("Error updating hold request " . $copy->id); } - $copy->status(8); #status on holds shelf + $copy->status(OILS_COPY_STATUS_ON_HOLDS_SHELF); #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 ) { @@ -869,7 +869,7 @@ sub fetch_captured_holds { ); my @res; - my $stat = $U->copy_status_from_name('on holds shelf'); + my $stat = OILS_COPY_STATUS_ON_HOLDS_SHELF; for my $h (@$holds) { my $copy = $e->retrieve_asset_copy($h->current_copy) or return $e->event; diff --git a/Open-ILS/src/perlmods/OpenILS/Const.pm b/Open-ILS/src/perlmods/OpenILS/Const.pm new file mode 100644 index 0000000000..029ed86bfb --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Const.pm @@ -0,0 +1,78 @@ +package OpenILS::Const; +use strict; use warnings; +use vars qw(@EXPORT_OK %EXPORT_TAGS); +use Exporter; +use base qw/Exporter/; + + +# --------------------------------------------------------------------- +# Shoves defined constants into the export array +# so they don't have to be listed twice in the code +# --------------------------------------------------------------------- +sub econst { + my($name, $value) = @_; + my $caller = caller; + no strict; + *{$name} = sub () { $value }; + push @{$caller.'::EXPORT_OK'}, $name; +} + +# --------------------------------------------------------------------- +# CONSTANTS +# --------------------------------------------------------------------- + + + +# --------------------------------------------------------------------- +# Copy Statuses +# --------------------------------------------------------------------- +econst OILS_COPY_STATUS_AVAILABLE => 0; +econst OILS_COPY_STATUS_CHECKED_OUT => 1; +econst OILS_COPY_STATUS_BINDERY => 2; +econst OILS_COPY_STATUS_LOST => 3; +econst OILS_COPY_STATUS_MISSING => 4; +econst OILS_COPY_STATUS_IN_PROCESS => 5; +econst OILS_COPY_STATUS_IN_TRANSIT => 6; +econst OILS_COPY_STATUS_RESHELVING => 7; +econst OILS_COPY_STATUS_ON_HOLDS_SHELF=> 8; +econst OILS_COPY_STATUS_ON_ORDER => 9; +econst OILS_COPY_STATUS_ILL => 10; +econst OILS_COPY_STATUS_CATALOGING => 11; +econst OILS_COPY_STATUS_RESERVES => 12; +econst OILS_COPY_STATUS_DISCARD => 13; +econst OILS_COPY_STATUS_DAMAGED => 14; + + +# --------------------------------------------------------------------- +# Circ defaults for pre-cataloged copies +# --------------------------------------------------------------------- +econst OILS_PRECAT_COPY_FINE_LEVEL => 2; +econst OILS_PRECAT_COPY_LOAN_DURATION => 2; +econst OILS_PRECAT_CALL_NUMBER => -1; +econst OILS_PRECAT_RECORD => -1; + + +# --------------------------------------------------------------------- +# Circ constants +# --------------------------------------------------------------------- +econst OILS_CIRC_DURATION_SHORT => 1; +econst OILS_CIRC_DURATION_NORMAL => 2; +econst OILS_CIRC_DURATION_EXTENDED => 3; +econst OILS_REC_FINE_LEVEL_LOW => 'low'; +econst OILS_REC_FINE_LEVEL_NORMAL => 'normal'; +econst OILS_REC_FINE_LEVEL_HIGH => 'high'; +econst OILS_STOP_FINES_CHECKIN => 'CHECKIN'; +econst OILS_STOP_FINES_RENEW => 'RENEW'; +econst OILS_STOP_FINES_LOST => 'LOST'; +econst OILS_STOP_FINES_CLAIMSRETURNED => 'CLAIMSRETURNED'; +econst OILS_STOP_FINES_LONGOVERDUE => 'LONGOVERDUE'; + + + + + +# --------------------------------------------------------------------- +# finally, export all the constants +# --------------------------------------------------------------------- +%EXPORT_TAGS = ( const => [ @EXPORT_OK ] ); +