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";
# ---------------------------------------------------------------------------
$logger->debug("Setting global storage session to ".
"session: " . $session->session_id . " : " . $session->app );
- $storage_session = $session;
return $session;
}
$session->finish();
$session->disconnect();
$session->kill_me();
- $storage_session = undef;
}
sub rollback_db_session {
$session->finish();
$session->disconnect();
$session->kill_me();
- $storage_session = undef;
}
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 );
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);
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;
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";
}
}
- $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";
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'));
}
my $CR = $self->editor->search_action_circulation(
{
target_copy => $copy->id,
- stop_fines => 'CLAIMSRETURNED',
+ stop_fines => OILS_STOP_FINES_CLAIMSRETURNED,
checkin_time => undef,
}
);
$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'));
}
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;
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;
}
$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 );
$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 || "");
{
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];
}
# 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;
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 {
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);
}
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'));
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);
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);
}
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 {
# 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));
# 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);
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");
}
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');
}
$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)
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 );
}
--- /dev/null
+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 ] );
+