my $logger = "OpenSRF::Utils::Logger";
-# Creates a new Event object.
+# Returns a new Event data hash (not a blessed object)
# The first param is the event name
# Following the first param is an optional hash of params:
# perm => the name of the permission error for permimssion errors
my $events = undef;
-my $descs = undef;
+my $descs = undef;
sub new {
- my( $class, $event, %params ) = @_;
- _load_events() unless $events;
-
- throw OpenSRF::EX ("Bad event name: $event") unless $event;
- my $e = $events->{$event} || '';
-
- my( $m, $f, $l ) = caller(0);
- my( $mm, $ff, $ll ) = caller(1);
- my( $mmm, $fff, $lll ) = caller(2);
-
- $f ||= "";
- $l ||= "";
- $ff ||= "";
- $ll ||= "";
- $fff ||= "";
- $lll ||= "";
-
- my $lang = 'en-US'; # assume english for now
-
- my $t = CORE::localtime();
-
- return {
- ilsevent => $e,
- textcode => $event,
- stacktrace => "$f:$l $ff:$ll $fff:$lll",
- desc => $descs->{$lang}->{$e} || '',
- servertime => $t,
- pid => $$, %params };
+ my( $class, $event, %params ) = @_;
+ _load_events() unless $events;
+
+ throw OpenSRF::EX ("Bad event name: $event") unless $event;
+ my $e = $events->{$event} || '';
+
+ my( $m, $f, $l ) = caller(0);
+ my( $mm, $ff, $ll ) = caller(1);
+ my( $mmm, $fff, $lll ) = caller(2);
+
+ $f ||= "";
+ $l ||= "";
+ $ff ||= "";
+ $ll ||= "";
+ $fff ||= "";
+ $lll ||= "";
+
+ my $lang = 'en-US'; # assume english for now
+
+ my $t = CORE::localtime();
+
+ return {
+ ilsevent => $e,
+ textcode => $event,
+ stacktrace => "$f:$l $ff:$ll $fff:$lll",
+ desc => $descs->{$lang}->{$e || ''} || '',
+ servertime => $t,
+ pid => $$, %params
+ };
}
sub _load_events {
}
-
-
1;
syslog("LOG_DEBUG", "OILS: new ILS '%s'", $institution->{id});
$self->{institution} = $institution;
- my $bsconfig = $institution->{implementation_config}->{bootstrap};
+ my $bsconfig = $institution->{implementation_config}->{bootstrap};
$target_encoding = $institution->{implementation_config}->{encoding} || 'ascii';
syslog('LOG_DEBUG', "OILS: loading bootstrap config: $bsconfig");
- local $/ = "\n";
+ local $/ = "\n"; # why?
OpenSRF::System->bootstrap_client(config_file => $bsconfig);
syslog('LOG_DEBUG', "OILS: bootstrap loaded..");
return $self->login( $self->{login}->{id}, $self->{login}->{password} );
}
-sub to_bool {
- my $val = shift;
- return ($val and $val =~ /true/io);
-}
-
sub editor {
return $editor = make_editor();
}
parse_datetime(OpenSRF::Utils::cleanse_ISO8601($date));
my @time = localtime($date->epoch);
- my $year = $time[5]+1900;
- my $mon = $time[4]+1;
- my $day = $time[3];
- my $hour = $time[2];
+ my $year = $time[5]+1900;
+ my $mon = $time[4]+1;
+ my $day = $time[3];
+ my $hour = $time[2];
my $minute = $time[1];
my $second = $time[0];
sub institution {
my $self = shift;
- return $self->{institution}->{id};
+ return $self->{institution}->{id}; # consider making this return the whole institution
+}
+
+sub institution_id {
+ my $self = shift;
+ return $self->{institution}->{id}; # then use this for just the ID
}
sub supports {
}
sub check_inst_id {
- my ($self, $id, $whence) = @_;
- if ($id ne $self->{institution}->{id}) {
- syslog("LOG_WARNING",
- "OILS: %s: received institution '%s', expected '%s'",
- $whence, $id, $self->{institution}->{id});
- }
+ my ($self, $id, $whence) = @_;
+ if ($id ne $self->{institution}->{id}) {
+ syslog("LOG_WARNING", "OILS: %s: received institution '%s', expected '%s'", $whence, $id, $self->{institution}->{id});
+ # Just an FYI check, we don't expect the user to change location from that in SIPconfig.xml
+ }
+}
+
+
+sub to_bool {
+ my $bool = shift;
+ # If it's defined, and matches a true sort of string, or is
+ # a non-zero number, then it's true.
+ defined($bool) or return; # false
+ ($bool =~ /true|y|yes/i) and return 1; # true
+ return ($bool =~ /^\d+$/ and $bool != 0); # true for non-zero numbers, false otherwise
}
sub checkout_ok {
sub checkin_ok {
return to_bool($config->{policy}->{checkin});
- return 0;
}
sub renew_ok {
$sc_renew = 0;
$self->verify_session;
-
+
syslog('LOG_DEBUG', "OILS: OpenILS::Checkout attempt: patron=$patron_id, item=$item_id");
-
- my $xact = OpenILS::SIP::Transaction::Checkout->new( authtoken => $self->{authtoken} );
- my $patron = $self->find_patron($patron_id);
- my $item = $self->find_item($item_id);
-
+
+ my $xact = OpenILS::SIP::Transaction::Checkout->new( authtoken => $self->{authtoken} );
+ my $patron = $self->find_patron($patron_id);
+ my $item = $self->find_item($item_id);
+
$xact->patron($patron);
$xact->item($item);
syslog('LOG_DEBUG', "OILS: OpenILS::Checkin on item=$item_id");
- my $patron;
- my $xact = OpenILS::SIP::Transaction::Checkin->new(authtoken => $self->{authtoken});
- my $item = $self->find_item($item_id);
+ my $patron;
+ my $xact = OpenILS::SIP::Transaction::Checkin->new(authtoken => $self->{authtoken});
+ my $item = $self->find_item($item_id);
$xact->item($item);
$xact->do_checkin( $trans_date, $return_date, $current_loc, $item_props );
if ($xact->ok) {
-
- $xact->patron($patron = $self->find_patron($item->{patron}));
- delete $item->{patron};
- delete $item->{due_date};
- syslog('LOG_INFO', "OILS: Checkin succeeded");
- #editor()->commit;
-
- } else {
-
- #editor()->xact_rollback;
- syslog('LOG_WARNING', "OILS: Checkin failed");
- }
+ $xact->patron($patron = $self->find_patron($item->{patron}));
+ delete $item->{patron};
+ delete $item->{due_date};
+ syslog('LOG_INFO', "OILS: Checkin succeeded");
+ #editor()->commit;
+ } else {
+ #editor()->xact_rollback;
+ syslog('LOG_WARNING', "OILS: Checkin failed");
+ }
# END TRANSACTION
return $xact;
}
-## If the ILS caches patron information, this lets it free it up
+## If the ILS caches patron information, this lets it free it up.
+## Also, this could be used for centrally logging session duration.
+## We don't do anything with it.
sub end_patron_session {
my ($self, $patron_id) = @_;
return (1, 'Thank you for using OpenILS!', '');
use OpenILS::SIP::Transaction;
use OpenILS::Application::AppUtils;
use OpenILS::Application::Circ::ScriptBuilder;
-use Data::Dumper;
+# use Data::Dumper;
use OpenILS::Const qw/:const/;
use OpenSRF::Utils qw/:datetime/;
use DateTime::Format::ISO8601;
my $type = ref($class) || $class;
my $self = bless( {}, $type );
- syslog('LOG_DEBUG', "OILS: Loading item $item_id...");
- return undef unless $item_id;
+ syslog('LOG_DEBUG', "OILS: Loading item $item_id...");
+ return undef unless $item_id;
- my $e = OpenILS::SIP->editor();
+ my $e = OpenILS::SIP->editor();
- my $copy = $e->search_asset_copy(
+ my $copy = $e->search_asset_copy(
[
{ barcode => $item_id, deleted => 'f' },
{
}
}
]
- );
+ );
- $copy = $$copy[0];
+ $copy = $copy->[0];
if(!$copy) {
syslog("LOG_DEBUG", "OILS: Item '%s' : not found", $item_id);
]
);
- my $bc = ($user) ? $user->card->barcode : "";
- $self->{patron} = $bc;
- $self->{patron_object} = $user;
+ my $bc = ($user) ? $user->card->barcode : "";
+ $self->{patron} = $bc;
+ $self->{patron_object} = $user;
- syslog('LOG_DEBUG', "OILS: Open circulation exists on $item_id : user = $bc");
- }
+ syslog('LOG_DEBUG', "OILS: Open circulation exists on $item_id : user = $bc");
+ }
- $self->{id} = $item_id;
- $self->{copy} = $copy;
- $self->{volume} = $copy->call_number;
- $self->{record} = $copy->call_number->record;
- $self->{mods} = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
+ $self->{id} = $item_id;
+ $self->{copy} = $copy;
+ $self->{volume} = $copy->call_number;
+ $self->{record} = $copy->call_number->record;
+ $self->{mods} = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
- syslog("LOG_DEBUG", "OILS: Item('$item_id'): found with title '%s'", $self->title_id);
+ syslog("LOG_DEBUG", "OILS: Item('$item_id'): found with title '%s'", $self->title_id);
my $config = OpenILS::SIP->config();
apps => 'open-ils.circ' => app_settings => 'legacy_script_support')
}
- return $self;
+ return $self;
}
sub run_attr_script {
if($self->{legacy_script_support}){
my $config = OpenILS::SIP->config();
- my $path = $config->{implementation_config}->{scripts}->{path};
+ my $path = $config->{implementation_config}->{scripts}->{path};
my $item_config_script = $config->{implementation_config}->{scripts}->{item_config};
$path = ref($path) eq 'ARRAY' ? $path : [$path];
+ my $path_str = join(", ", @$path);
- syslog('LOG_DEBUG', "OILS: Script path = $path, Item config script = $item_config_script");
+ syslog('LOG_DEBUG', "OILS: Script path = [$path_str], Item config script = $item_config_script");
- my $runner =
- OpenILS::Application::Circ::ScriptBuilder->build(
- {
- copy => $self->{copy},
- editor => OpenILS::SIP->editor(),
- }
- );
+ my $runner = OpenILS::Application::Circ::ScriptBuilder->build({
+ copy => $self->{copy},
+ editor => OpenILS::SIP->editor(),
+ });
$runner->add_path($_) for @$path;
$runner->load($item_config_script);
- unless( $self->{item_config_result} = $runner->run ) {
+ unless( $self->{item_config_result} = $runner->run ) { # assignment, not comparison
$runner->cleanup;
- warn "Item config script [$path : $item_config_script] failed to run: $@\n";
- syslog('LOG_ERR', "OILS: Item config script [$path : $item_config_script] failed to run: $@");
+ warn "Item config script [$path_str : $item_config_script] failed to run: $@\n";
+ syslog('LOG_ERR', "OILS: Item config script [$path_str : $item_config_script] failed to run: $@");
return undef;
}
} else {
# use the in-db circ modifier configuration
- my $config = {magneticMedia => 'f', SIPMediaType => '001'};
+ my $config = {magneticMedia => 'f', SIPMediaType => '001'}; # defaults
my $mod = $self->{copy}->circ_modifier;
if($mod) {
my $mod_obj = OpenILS::SIP->editor()->search_config_circ_modifier($mod);
if($mod_obj) {
$config->{magneticMedia} = $mod_obj->magnetic_media;
- $config->{SIPMediaType} = $mod_obj->sip2_media_type;
+ $config->{SIPMediaType} = $mod_obj->sip2_media_type;
}
}
sub magnetic {
my $self = shift;
- return 0 unless $self->run_attr_script;
- my $mag = $self->{item_config_result}->{item_config}->{magneticMedia};
- syslog('LOG_DEBUG', "OILS: magnetic = $mag");
- return ($mag and $mag eq 't') ? 1 : 0;
+ return 0 unless $self->run_attr_script;
+ my $mag = $self->{item_config_result}->{item_config}->{magneticMedia};
+ syslog('LOG_DEBUG', "OILS: magnetic = $mag");
+ return ($mag and $mag eq 't') ? 1 : 0;
}
sub sip_media_type {
my $self = shift;
- return 0 unless $self->run_attr_script;
- my $media = $self->{item_config_result}->{item_config}->{SIPMediaType};
- syslog('LOG_DEBUG', "OILS: media type = $media");
- return ($media) ? $media : '001';
+ return 0 unless $self->run_attr_script;
+ my $media = $self->{item_config_result}->{item_config}->{SIPMediaType};
+ syslog('LOG_DEBUG', "OILS: media type = $media");
+ return ($media) ? $media : '001';
}
sub sip_item_properties {
my $self = shift;
- return "";
+ return "";
}
-sub status_update {
+sub status_update { # FIXME: this looks unimplemented
my ($self, $props) = @_;
my $status = OpenILS::SIP::Transaction->new;
$self->{sip_item_properties} = $props;
# 12 Lost
# 13 Missing
sub sip_circulation_status {
- my $self = shift;
- my $stat = $self->{copy}->status->id;
-
- return '02' if $stat == OILS_COPY_STATUS_ON_ORDER;
- return '03' if $stat == OILS_COPY_STATUS_AVAILABLE;
- return '04' if $stat == OILS_COPY_STATUS_CHECKED_OUT;
- return '06' if $stat == OILS_COPY_STATUS_IN_PROCESS;
- return '08' if $stat == OILS_COPY_STATUS_ON_HOLDS_SHELF;
- return '09' if $stat == OILS_COPY_STATUS_RESHELVING;
- return '10' if $stat == OILS_COPY_STATUS_IN_TRANSIT;
- return '12' if $stat == OILS_COPY_STATUS_LOST;
- return '13' if $stat == OILS_COPY_STATUS_MISSING;
-
- return 01;
+ my $self = shift;
+ my $stat = $self->{copy}->status->id;
+
+ return '02' if $stat == OILS_COPY_STATUS_ON_ORDER;
+ return '03' if $stat == OILS_COPY_STATUS_AVAILABLE;
+ return '04' if $stat == OILS_COPY_STATUS_CHECKED_OUT;
+ return '06' if $stat == OILS_COPY_STATUS_IN_PROCESS;
+ return '08' if $stat == OILS_COPY_STATUS_ON_HOLDS_SHELF;
+ return '09' if $stat == OILS_COPY_STATUS_RESHELVING;
+ return '10' if $stat == OILS_COPY_STATUS_IN_TRANSIT;
+ return '12' if $stat == OILS_COPY_STATUS_LOST;
+ return '13' if $stat == OILS_COPY_STATUS_MISSING;
+
+ return 01;
}
sub sip_security_marker {
- return '02';
+ return '02'; # FIXME? 00-other; 01-None; 02-Tattle-Tape Security Strip (3M); 03-Whisper Tape (3M)
}
sub sip_fee_type {
- return '01';
+ return '01'; # FIXME? 01-09 enumerated in spec. We just use O1-other/unknown.
}
sub fee {
my $self = shift;
- return 0;
+ return 0;
}
sub hold_queue {
my $self = shift;
- return [];
+ return [];
}
sub hold_queue_position {
my ($self, $patron_id) = @_;
- return 1;
+ return 1;
}
sub due_date {
- my $self = shift;
+ my $self = shift;
- # this should force correct circ fetching
- require OpenILS::Utils::CStoreEditor;
- my $e = OpenILS::Utils::CStoreEditor->new(xact => 1);
- #my $e = OpenILS::SIP->editor();
+ # this should force correct circ fetching
+ require OpenILS::Utils::CStoreEditor;
+ my $e = OpenILS::Utils::CStoreEditor->new(xact => 1);
+ #my $e = OpenILS::SIP->editor();
- my $circ = $e->search_action_circulation(
- { target_copy => $self->{copy}->id, checkin_time => undef } )->[0];
+ my $circ = $e->search_action_circulation(
+ { target_copy => $self->{copy}->id, checkin_time => undef } )->[0];
- $e->rollback;
+ $e->rollback;
- if( !$circ ) {
- syslog('LOG_INFO', "OILS: No open circ found for copy");
- return 0;
- }
+ if( !$circ ) {
+ syslog('LOG_INFO', "OILS: No open circ found for copy");
+ return 0;
+ }
- my $due = OpenILS::SIP->format_date($circ->due_date, 'due');
- syslog('LOG_DEBUG', "OILS: Found item due date = $due");
- return $due;
+ my $due = OpenILS::SIP->format_date($circ->due_date, 'due');
+ syslog('LOG_DEBUG', "OILS: Found item due date = $due");
+ return $due;
}
sub recall_date {
sub hold_pickup_date {
my $self = shift;
- return 0;
+ return 0;
}
# message to display on console
# reciept printer
sub print_line {
- my $self = shift;
- return OpenILS::SIP::clean_text($self->{print_line}) || '';
+ my $self = shift;
+ return OpenILS::SIP::clean_text($self->{print_line}) || '';
}
# OR
# 2) It's checked out to the patron and there's no hold queue
sub available {
- my ($self, $for_patron) = @_;
-
- my $stat = $self->{copy}->status->id;
- return 1 if
- $stat == OILS_COPY_STATUS_AVAILABLE or
- $stat == OILS_COPY_STATUS_RESHELVING;
-
- return 0;
+ my ($self, $for_patron) = @_;
+
+ my $stat = $self->{copy}->status->id;
+ return 1 if
+ $stat == OILS_COPY_STATUS_AVAILABLE or
+ $stat == OILS_COPY_STATUS_RESHELVING;
+
+ return 0;
}
my $INET_PRIVS;
+#
+# OpenILS::SIP::Patron->new($barcode);
+# OpenILS::SIP::Patron->new(barcode => $barcode); # same as above
+# OpenILS::SIP::Patron->new( usr => $id);
+
sub new {
my ($class, $patron_id) = @_;
my $type = ref($class) || $class;
return undef;
}
- $self->{user} = $user;
- $self->{id} = $patron_id;
- $self->{editor} = $e;
+ $self->{user} = $user;
+ $self->{id} = $patron_id;
+ $self->{editor} = $e;
syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s): found patron : barred=%s, card:active=%s",
$patron_id, $self->{user}->barred, $self->{user}->card->active );
sub address {
my $self = shift;
- my $u = $self->{user};
- my $addr = $u->billing_address;
- $addr = $u->mailing_address unless $addr;
- my $str = __addr_string($addr);
+ my $u = $self->{user};
+ my $str = __addr_string($u->billing_address || $u->mailing_address);
syslog('LOG_DEBUG', "OILS: Patron address: $str");
return $str;
}
# not completely sure what this means
sub too_many_renewal {
my $self = shift;
- return 0;
+ return 0;
}
# not relevant, handled by fines/fees
sub too_many_claim_return {
my $self = shift;
- return 0;
+ return 0;
}
# not relevant, handled by fines/fees
sub too_many_lost {
my $self = shift;
- return 0;
+ return 0;
}
sub excessive_fines {
# not currently supported
sub recall_items {
my ($self, $start, $end) = @_;
- return [];
+ return [];
}
sub unavail_holds {
}
sub inet_privileges {
- my( $self ) = @_;
- my $e = OpenILS::SIP->editor();
- $INET_PRIVS = $e->retrieve_all_config_net_access_level() unless $INET_PRIVS;
- my ($level) = grep { $_->id eq $self->{user}->net_access_level } @$INET_PRIVS;
- my $name = OpenILS::SIP::clean_text($level->name);
- syslog('LOG_DEBUG', "OILS: Patron inet_privs = $name");
- return $name;
+ my( $self ) = @_;
+ my $e = OpenILS::SIP->editor();
+ $INET_PRIVS = $e->retrieve_all_config_net_access_level() unless $INET_PRIVS;
+ my ($level) = grep { $_->id eq $self->{user}->net_access_level } @$INET_PRIVS;
+ my $name = OpenILS::SIP::clean_text($level->name);
+ syslog('LOG_DEBUG', "OILS: Patron inet_privs = $name");
+ return $name;
}
my %fields = (
- ok => 0,
- patron => undef,
- item => undef,
- desensitize => 0,
- alert => '',
- transation_id => undef,
- sip_fee_type => '01', # Other/Unknown
- fee_amount => undef,
- sip_currency => 'CAD',
- screen_msg => '',
- print_line => '',
- editor => undef,
- authtoken => '',
- );
+ ok => 0,
+ patron => undef,
+ item => undef,
+ desensitize => 0,
+ alert => '',
+ transation_id => undef,
+ sip_fee_type => '01', # Other/Unknown
+ fee_amount => undef,
+ sip_currency => 'CAD',
+ screen_msg => '',
+ print_line => '',
+ editor => undef,
+ authtoken => '',
+);
our $AUTOLOAD;
my $core = OpenILS::Utils::Cronscript->new(\%defaults);
my $opts = $core->MyGetOptions(); # options now in, e.g.: $opts->{max}
- $ocre->bootstrap;
+ $core->bootstrap;
Or if you don't need any additional options and just want to get a session going:
-- initialize it with something if the table is not empty. The initial
-- value, 'ORDERS', may not always be appropriate. Massage as needed.
+-- For example, if you have already processed responses, this fixes them:
+-- update acq.edi_message set message_type='ORDRSP' where edi LIKE '%ORDRSP%';
+
ALTER TABLE acq.edi_message
ADD COLUMN message_type TEXT;
use strict;
use warnings;
+#FIXME: use Test::More or any kind of Test module instead of eval/die if
+
BEGIN {
eval "use OpenSRF::Utils::Config;";
die "Please ensure that /openils/lib/perl5 is in your PERL5LIB environment variable.