use OpenILS::SIP::Transaction;
use OpenILS::SIP::Transaction::Checkout;
use OpenILS::SIP::Transaction::Checkin;
-#use OpenILS::SIP::Transaction::FeePayment;
-#use OpenILS::SIP::Transaction::Hold;
use OpenILS::SIP::Transaction::Renew;
-#use OpenILS::SIP::Transaction::RenewAll;
-
use OpenSRF::System;
use OpenILS::Utils::Fieldmapper;
use OpenILS::Application::AppUtils;
my $U = 'OpenILS::Application::AppUtils';
-use Digest::MD5 qw(md5_hex);
-
-# PUT ME IN THE CONFIG XXX
-my %supports = (
- 'magnetic media' => 1,
- 'security inhibit' => 0,
- 'offline operation' => 0
- );
+my $editor;
+my $config;
+use Digest::MD5 qw(md5_hex);
sub new {
my ($class, $institution, $login) = @_;
my $type = ref($class) || $class;
my $self = {};
+ $config = $institution;
syslog("LOG_DEBUG", "new ILS '%s'", $institution->{id});
$self->{institution} = $institution;
- my $config = $institution->{implementation_config}->{bootstrap};
+ my $bsconfig = $institution->{implementation_config}->{bootstrap};
- syslog('LOG_DEBUG', "loading bootstrap config: $config");
+ syslog('LOG_DEBUG', "loading bootstrap config: $bsconfig");
local $/ = "\n";
- OpenSRF::System->bootstrap_client(config_file => $config);
+ OpenSRF::System->bootstrap_client(config_file => $bsconfig);
syslog('LOG_DEBUG', "bootstrap loaded..");
$self->{osrf_config} = OpenSRF::Utils::SettingsClient->new;
return $self;
}
+sub to_bool {
+ my $val = shift;
+ return ($val and $val =~ /true/io);
+}
+
+sub editor {
+ $editor = make_editor() unless $editor;
+ return $editor;
+}
+sub reset_editor {
+ $editor = undef;
+ return editor();
+}
+
+
+# Creates the global editor object
+sub make_editor {
+ require OpenILS::Utils::CStoreEditor;
+ my $e = OpenILS::Utils::CStoreEditor->new(xact => 1);
+ # gnarly cstore hack to re-gen autogen methods after IDL is loaded
+ if(!UNIVERSAL::can($e, 'search_actor_card')) {
+ syslog("LOG_WARNING", "Reloading CStoreEditor...");
+ delete $INC{'OpenILS/Utils/CStoreEditor.pm'};
+ require OpenILS::Utils::CStoreEditor;
+ $e = OpenILS::Utils::CStoreEditor->new(xact =>1);
+ }
+ return $e;
+}
+
+
+
sub login {
my( $self, $username, $password ) = @_;
syslog('LOG_DEBUG', "OpenILS: Logging in with username $username");
}
);
- my $key;
- if( ref($response) eq 'HASH' and $response->{payload}
- and $key = $response->{payload}->{authtoken} ) {
- syslog('LOG_INFO', "OpenILS: Login succeeded for $username : authkey = $key");
-
- } else {
- syslog('LOG_WARN', "OpenILS: Login failed for $username");
+ if( my $code = $U->event_code($response) ) {
+ my $txt = $response->{textcode};
+ syslog('LOG_WARN', "OpenILS: Login failed for $username. $txt:$code");
+ return undef;
}
+ my $key = $response->{payload}->{authtoken};
+ syslog('LOG_INFO', "OpenILS: Login succeeded for $username : authkey = $key");
return $self->{authtoken} = $key;
}
sub institution {
my $self = shift;
-
return $self->{institution}->{id};
}
-
-# XXX Get me from the config?
sub supports {
- my ($self, $op) = @_;
- return exists($supports{$op}) ? $supports{$op} : 0;
+ my ($self, $op) = @_;
+ my ($i) = grep { $_->{name} eq $op }
+ @{$config->{implementation_config}->{supports}->{item}};
+ return to_bool($i->{value});
}
sub check_inst_id {
- my ($self, $id, $whence) = @_;
-
- if ($id ne $self->{institution}->{id}) {
- syslog("LOG_WARNING", "%s: received institution '%s', expected '%s'",
- $whence, $id, $self->{institution}->{id});
- }
+ my ($self, $id, $whence) = @_;
+ if ($id ne $self->{institution}->{id}) {
+ syslog("LOG_WARNING",
+ "%s: received institution '%s', expected '%s'",
+ $whence, $id, $self->{institution}->{id});
+ }
}
-
-# XXX by default, these should come from the config
sub checkout_ok {
- return 1;
+ return to_bool($config->{policy}->{checkout});
}
sub checkin_ok {
+ return to_bool($config->{policy}->{checkin});
return 0;
}
+sub renew_ok {
+ return to_bool($config->{policy}->{renew});
+}
+
sub status_update_ok {
- return 1;
+ return to_bool($config->{policy}->{status_update});
}
sub offline_ok {
- return 0;
+ return to_bool($config->{policy}->{offline});
}
+
##
## Checkout(patron_id, item_id, sc_renew):
## patron_id & item_id are the identifiers send by the terminal
syslog('LOG_DEBUG', "OpenILS::Checkout attempt: patron=$patron_id, item=$item_id");
my $xact = OpenILS::SIP::Transaction::Checkout->new( authtoken => $self->{authtoken} );
- my $patron = OpenILS::SIP::Patron->new($patron_id);
- my $item = OpenILS::SIP::Item->new($item_id);
+ my $patron = $self->find_patron($patron_id);
+ my $item = $self->find_item($item_id);
$xact->patron($patron);
$xact->item($item);
if( $xact->ok ) {
- $xact->editor->commit;
+ #editor()->commit;
syslog("LOG_DEBUG", "OpenILS::Checkout: " .
"patron %s checkout %s succeeded", $patron_id, $item_id);
} else {
- $xact->editor->xact_rollback;
+ #editor()->xact_rollback;
syslog("LOG_DEBUG", "OpenILS::Checkout: " .
"patron %s checkout %s FAILED, rolling back xact...", $patron_id, $item_id);
}
my $patron;
my $xact = OpenILS::SIP::Transaction::Checkin->new(authtoken => $self->{authtoken});
- my $item = OpenILS::SIP::Item->new($item_id);
+ my $item = $self->find_item($item_id);
$xact->item($item);
+ if(!$xact->item) {
+ $xact->screen_msg("Invalid item barcode: $item_id");
+ $xact->ok(0);
+ return $xact;
+ }
+
$xact->do_checkin( $trans_date, $return_date, $current_loc, $item_props );
if ($xact->ok) {
- $xact->patron($patron = OpenILS::SIP::Patron->new($item->{patron}));
+ $xact->patron($patron = $self->find_patron($item->{patron}));
delete $item->{patron};
delete $item->{due_date};
syslog('LOG_INFO', "OpenILS: Checkin succeeded");
- $xact->editor->commit;
+ #editor()->commit;
} else {
- $xact->editor->xact_rollback;
+ #editor()->xact_rollback;
syslog('LOG_WARNING', "OpenILS: Checkin failed");
}
# END TRANSACTION
return $xact;
}
-
-
-
## If the ILS caches patron information, this lets it free it up
sub end_patron_session {
my ($self, $patron_id) = @_;
$no_block, $nb_due_date, $third_party, $item_props, $fee_ack) = @_;
my $trans = OpenILS::SIP::Transaction::Renew->new( authtoken => $self->{authtoken} );
- $trans->patron(OpenILS::SIP::Patron->new($patron_id));
- $trans->item(OpenILS::SIP::Item->new($item_id));
+ $trans->patron($self->find_patron($patron_id));
+ $trans->item($self->find_item($item_id));
if(!$trans->patron) {
$trans->screen_msg("Invalid patron barcode.");
#
package OpenILS::SIP::Item;
-
-use strict;
-use warnings;
+use strict; use warnings;
use Sys::Syslog qw(syslog);
+use OpenILS::SIP;
use OpenILS::SIP::Transaction;
use OpenILS::Application::AppUtils;
my $U = 'OpenILS::Application::AppUtils';
sub new {
my ($class, $item_id) = @_;
my $type = ref($class) || $class;
- my $self = {};
- bless $self, $type;
-
- require OpenILS::Utils::CStoreEditor;
- my $e = OpenILS::Utils::CStoreEditor->new;
+ my $self = bless( {}, $type );
- if(!UNIVERSAL::can($e, 'search_actor_card')) {
- syslog("LOG_WARNING", "Reloading CStoreEditor...");
- delete $INC{'OpenILS/Utils/CStoreEditor.pm'};
- require OpenILS::Utils::CStoreEditor;
- $e = OpenILS::Utils::CStoreEditor->new;
- }
+ syslog('LOG_DEBUG', "Loading item $item_id...");
+ return undef unless $item_id;
+ my $e = OpenILS::SIP->editor();
# FLESH ME
- my $copy = $e->search_asset_copy(
+ my $copy = $e->search_asset_copy(
[
{ barcode => $item_id },
{
]
);
- if(!@$copy) {
+ $copy = $$copy[0];
+
+ if(!$copy) {
syslog("LOG_DEBUG", "OpenILS: Item '%s' : not found", $item_id);
return undef;
- }
-
- $copy = $$copy[0];
+ }
- # XXX See if i am checked out, if so set $self->{patron} to the user's barcode
my ($circ) = $U->fetch_open_circulation($copy->id);
if($circ) {
+ # if i am checked out, set $self->{patron} to the user's barcode
my $user = $e->retrieve_actor_user(
[
$circ->usr,
- {
- flesh => 1,
- flesh_fields => {
- "au" => [ 'card' ],
- }
- }
+ { flesh => 1, flesh_fields => { "au" => [ 'card' ] } }
]
);
$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->{mods} = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
- syslog("LOG_DEBUG", "new OpenILS Item('%s'): found with title '%s'",
- $item_id, $self->title_id);
+ syslog("LOG_DEBUG", "Item('$item_id'): found with title '%s'", $self->title_id);
- return $self;
+ return $self;
}
sub magnetic {
sub status_update {
my ($self, $props) = @_;
- my $status = new OpenILS::SIP::Transaction;
+ my $status = OpenILS::SIP::Transaction->new;
$self->{sip_item_properties} = $props;
$status->{ok} = 1;
return $status;
use Data::Dumper;
use Digest::MD5 qw(md5_hex);
+use OpenILS::SIP;
use OpenILS::Application::AppUtils;
use OpenILS::Application::Actor;
my $U = 'OpenILS::Application::AppUtils';
syslog("LOG_DEBUG", "new OpenILS Patron(%s): searching...", $patron_id);
- require OpenILS::Utils::CStoreEditor;
- my $e = OpenILS::Utils::CStoreEditor->new;
+ my $e = OpenILS::SIP->editor();
- if(!UNIVERSAL::can($e, 'search_actor_card')) {
- syslog("LOG_WARNING", "Reloading CStoreEditor...");
- delete $INC{'OpenILS/Utils/CStoreEditor.pm'};
- require OpenILS::Utils::CStoreEditor;
- $e = OpenILS::Utils::CStoreEditor->new;
- }
-
-
- my $c = $e->search_actor_card({barcode => $patron_id}, {idlist=>1});
- my $user;
+ my $c = $e->search_actor_card({barcode => $patron_id}, {idlist=>1});
+ my $user;
- if( @$c ) {
+ if( @$c ) {
$user = $e->search_actor_user(
[
sub __copy_to_title {
my( $e, $copy ) = @_;
+ syslog('LOG_DEBUG', "copy_to_title(%s)", $copy->id);
return $copy->dummy_title if $copy->call_number == -1;
my $vol = $e->retrieve_asset_call_number($copy->call_number);
return __volume_to_title($e, $vol);
sub __volume_to_title {
my( $e, $volume ) = @_;
+ syslog('LOG_DEBUG', "volume_to_title(%s)", $volume->id);
return __record_to_title($e, $volume->record);
}
sub __record_to_title {
my( $e, $title_id ) = @_;
+ syslog('LOG_DEBUG', "record_to_title($title_id)");
my $mods = $U->simplereq(
'open-ils.search',
'open-ils.search.biblio.record.mods_slim.retrieve', $title_id );
sub __metarecord_to_title {
my( $e, $m_id ) = @_;
+ syslog('LOG_DEBUG', "metarecord_to_title($m_id)");
my $mods = $U->simplereq(
'open-ils.search',
'open-ils.search.biblio.metarecord.mods_slim.retrieve', $m_id);
# stay in synch
$self->{user}->alert_message( $note );
- $e->finish; # commits and resets
+ $e->commit; # commits and resets
+ $self->{editor} = OpenILS::SIP->reset_editor();
return $self;
}
use strict; use warnings;
use Sys::Syslog qw(syslog);
+use OpenILS::SIP;
+
my %fields = (
ok => 0,
our $AUTOLOAD;
-# returns the global transaction pointer
-#sub get_xact {
-# my $class = shift;
-# return $XACT;
-#}
-#
-#sub session {
-# my( $self, $session ) = @_;
-# $self->{session} = $session if $session;
-# return $self->{session};
-#}
-#
-#
-#sub create_session {
-# my( $self, $patron ) = @_;
-# $self->commit_session if $self->session_is_alive;
-# require OpenILS::Utils::CStoreEditor;
-# return $self->{session} = {
-# editor => OpenILS::Utils::CStoreEditor->new(xact=>1),
-# patron => $patron
-# }
-#}
-#
-#sub commit_session {
-# my $self = shift;
-# if( my $session = $self->session ) {
-# $session->{editor}->commit;
-# delete $$session{editor};
-# delete $$session{patron};
-# }
-#}
-#
-#
-#sub rollback_session {
-# my $self = shift;
-# if( my $session = $self->session ) {
-# $session->{editor}->xact_rollback;
-# delete $$session{editor};
-# delete $$session{patron};
-# }
-#}
-#
-#sub session_is_alive {
-# my $self = shift;
-# return $self->session and $self->session->{editor};
-#}
-
-
-
sub new {
my( $class, %args ) = @_;
syslog('LOG_DEBUG', "OpenILS: Created new transaction with authtoken %s", $self->authtoken);
- require OpenILS::Utils::CStoreEditor;
- $self->editor(OpenILS::Utils::CStoreEditor->new(
- xact=>1, authtoken => $self->authtoken));
+ my $e = OpenILS::SIP->editor();
+ $e->{authtoken} = $self->authtoken;
return $self;
}
-sub DESTROY {
- # be cool
+sub DESTROY {
+ # be cool
}
sub AUTOLOAD {
- my $self = shift;
- my $class = ref($self) or croak "$self is not an object";
- my $name = $AUTOLOAD;
+ my $self = shift;
+ my $class = ref($self) or croak "$self is not an object";
+ my $name = $AUTOLOAD;
- $name =~ s/.*://;
+ $name =~ s/.*://;
- unless (exists $self->{_permitted}->{$name}) {
- croak "Can't access '$name' field of class '$class'";
- }
+ unless (exists $self->{_permitted}->{$name}) {
+ croak "Can't access '$name' field of class '$class'";
+ }
- if (@_) {
- return $self->{$name} = shift;
- } else {
- return $self->{$name};
- }
+ if (@_) {
+ return $self->{$name} = shift;
+ } else {
+ return $self->{$name};
+ }
}
1;