updated some logging, added script support to SIP for determining magnetic, etc....
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Aug 2006 16:43:26 +0000 (16:43 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Aug 2006 16:43:26 +0000 (16:43 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5488 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/oils_sip.xml.example
Open-ILS/src/javascript/backend/circ/circ_item_config.js
Open-ILS/src/perlmods/OpenILS/SIP.pm
Open-ILS/src/perlmods/OpenILS/SIP/Item.pm
Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm
Open-ILS/src/perlmods/OpenILS/SIP/Transaction.pm
Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkin.pm
Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm

index d8f1ae3..c968849 100644 (file)
                                        <item name='item status update' value='false'/>
                                        <item name='patron enable' value='false'/>
                                        <item name='hold' value='false'/>
-                                       <item name='renew'  value='true'/>
+                                       <item name='renew' value='true'/>
                                        <item name='renew all' value='false'/>
                                </supports>
+
+                               <scripts>
+                                       <path>/openils/var/</path>
+                                       <item_config>circ/circ_item_config.js</item_config>
+                               <scripts>
+
                        </implementation_config>
        
                </institution>
index 2bf0cd6..084a926 100644 (file)
@@ -297,6 +297,11 @@ CIRC_MOD_MAP['STATE-MFRM'] =  {
        maxFine                                 : "overdue_mid"
 };
 
+/* this will set defaults even if no one asked for them */
+log_debug("Calling getItemConfig() to force defaults..");
+getItemConfig();
+log_debug("getItemConfig() set magneticMedia to "+result.magneticMedia);
+
 
 function getItemConfig() {
 
@@ -325,11 +330,17 @@ function getItemConfig() {
                config = MARC_ITEM_TYPE_MAP[marcType];
        }
 
-       if( config ) {
-               /* go ahead and set some default result 
-                       data (which may be overidden) */
-               for( var i in config ) 
-                       result[i] = config[i];
+       /* if no config could be found, default to 'book' */
+       if(!config) {
+               log_warn("item_config found no circ_mod OR MARC config, defaulting to 'book'");
+               config = CIRC_MOD_MAP['book'];
+       }
+
+       /* go ahead and set some default result 
+               data (which may be overidden) */
+       for( var i in config ) {
+               log_debug("item_config setting result defaults: "+i+" = " +config[i]);
+               result[i] = config[i];
        }
 
        return config;
index 49b0b4f..bddd83d 100644 (file)
@@ -31,16 +31,16 @@ sub new {
        my $self = {};
 
        $config = $institution;
-       syslog("LOG_DEBUG", "new ILS '%s'", $institution->{id});
+       syslog("LOG_DEBUG", "OILS: new ILS '%s'", $institution->{id});
        $self->{institution} = $institution;
 
        my $bsconfig = $institution->{implementation_config}->{bootstrap};
 
-       syslog('LOG_DEBUG', "loading bootstrap config: $bsconfig");
+       syslog('LOG_DEBUG', "OILS: loading bootstrap config: $bsconfig");
        
        local $/ = "\n";
        OpenSRF::System->bootstrap_client(config_file => $bsconfig);
-       syslog('LOG_DEBUG', "bootstrap loaded..");
+       syslog('LOG_DEBUG', "OILS: bootstrap loaded..");
 
        $self->{osrf_config} = OpenSRF::Utils::SettingsClient->new;
 
@@ -68,6 +68,10 @@ sub reset_editor {
        return editor();
 }
 
+sub config {
+       return $config;
+}
+
 
 # Creates the global editor object
 sub make_editor {
@@ -75,7 +79,7 @@ sub make_editor {
        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...");
+               syslog("LOG_WARNING", "OILS: Reloading CStoreEditor...");
                delete $INC{'OpenILS/Utils/CStoreEditor.pm'};
                require OpenILS::Utils::CStoreEditor;
                $e = OpenILS::Utils::CStoreEditor->new(xact =>1);
@@ -87,7 +91,7 @@ sub make_editor {
 
 sub login {
        my( $self, $username, $password ) = @_;
-       syslog('LOG_DEBUG', "OpenILS: Logging in with username $username");
+       syslog('LOG_DEBUG', "OILS: Logging in with username $username");
 
        my $seed = $U->simplereq( 
                'open-ils.auth',
@@ -105,12 +109,12 @@ sub login {
 
        if( my $code = $U->event_code($response) ) {
                my $txt = $response->{textcode};
-               syslog('LOG_WARNING', "OpenILS: Login failed for $username.  $txt:$code");
+               syslog('LOG_WARNING', "OILS: Login failed for $username.  $txt:$code");
                return undef;
        }
 
        my $key = $response->{payload}->{authtoken};
-       syslog('LOG_INFO', "OpenILS: Login succeeded for $username : authkey = $key");
+       syslog('LOG_INFO', "OILS: Login succeeded for $username : authkey = $key");
        return $self->{authtoken} = $key;
 }
 
@@ -143,7 +147,7 @@ sub check_inst_id {
        my ($self, $id, $whence) = @_;
        if ($id ne $self->{institution}->{id}) {
                syslog("LOG_WARNING", 
-                       "%s: received institution '%s', expected '%s'",
+                       "OILS: %s: received institution '%s', expected '%s'",
                        $whence, $id, $self->{institution}->{id});
        }
 }
@@ -183,7 +187,7 @@ sub offline_ok {
 sub checkout {
        my ($self, $patron_id, $item_id, $sc_renew) = @_;
        
-       syslog('LOG_DEBUG', "OpenILS::Checkout attempt: patron=$patron_id, item=$item_id");
+       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);
@@ -207,7 +211,7 @@ sub checkout {
                return $xact;
        }
 
-       syslog('LOG_DEBUG', "OpenILS::Checkout data loaded OK, checking out...");
+       syslog('LOG_DEBUG', "OILS: OpenILS::Checkout data loaded OK, checking out...");
        $xact->do_checkout();
 
        if ($item->{patron} && ($item->{patron} ne $patron_id)) {
@@ -222,13 +226,13 @@ sub checkout {
        if( $xact->ok ) {
 
                #editor()->commit;
-               syslog("LOG_DEBUG", "OpenILS::Checkout: " .
+               syslog("LOG_DEBUG", "OILS: OpenILS::Checkout: " .
                        "patron %s checkout %s succeeded", $patron_id, $item_id);
 
        } else {
 
                #editor()->xact_rollback;
-               syslog("LOG_DEBUG", "OpenILS::Checkout: " .
+               syslog("LOG_DEBUG", "OILS: OpenILS::Checkout: " .
                        "patron %s checkout %s FAILED, rolling back xact...", $patron_id, $item_id);
        }
 
@@ -240,7 +244,7 @@ sub checkin {
        my ($self, $item_id, $trans_date, $return_date,
        $current_loc, $item_props, $cancel) = @_;
 
-       syslog('LOG_DEBUG', "OpenILS::Checkin on item=$item_id");
+       syslog('LOG_DEBUG', "OILS: OpenILS::Checkin on item=$item_id");
        
        my $patron;
        my $xact                = OpenILS::SIP::Transaction::Checkin->new(authtoken => $self->{authtoken});
@@ -261,13 +265,13 @@ sub checkin {
                $xact->patron($patron = $self->find_patron($item->{patron}));
                delete $item->{patron};
                delete $item->{due_date};
-               syslog('LOG_INFO', "OpenILS: Checkin succeeded");
+               syslog('LOG_INFO', "OILS: Checkin succeeded");
                #editor()->commit;
 
        } else {
 
                #editor()->xact_rollback;
-               syslog('LOG_WARNING', "OpenILS: Checkin failed");
+               syslog('LOG_WARNING', "OILS: Checkin failed");
        }
        # END TRANSACTION
 
index 8b367dc..d0a1229 100644 (file)
@@ -12,6 +12,8 @@ use Sys::Syslog qw(syslog);
 use OpenILS::SIP;
 use OpenILS::SIP::Transaction;
 use OpenILS::Application::AppUtils;
+use OpenILS::Application::Circ::ScriptBuilder;
+use Data::Dumper;
 my $U = 'OpenILS::Application::AppUtils';
 
 my %item_db;
@@ -21,12 +23,11 @@ sub new {
     my $type = ref($class) || $class;
     my $self = bless( {}, $type );
 
-       syslog('LOG_DEBUG', "Loading item $item_id...");
+       syslog('LOG_DEBUG', "OILS: Loading item $item_id...");
        return undef unless $item_id;
 
        my $e = OpenILS::SIP->editor();
 
-        # FLESH ME
        my $copy = $e->search_asset_copy(
                [
                        { barcode => $item_id },
@@ -40,10 +41,11 @@ sub new {
                ]
        );
 
+
        $copy = $$copy[0];
 
        if(!$copy) {
-               syslog("LOG_DEBUG", "OpenILS: Item '%s' : not found", $item_id);
+               syslog("LOG_DEBUG", "OILS: Item '%s' : not found", $item_id);
                return undef;
        }
 
@@ -61,7 +63,7 @@ sub new {
                $self->{patron} = $bc;
                $self->{patron_object} = $user;
 
-               syslog('LOG_DEBUG', "Open circulation exists on $item_id : user = $bc");
+               syslog('LOG_DEBUG', "OILS: Open circulation exists on $item_id : user = $bc");
        }
 
        $self->{id}                     = $item_id;
@@ -70,14 +72,49 @@ sub new {
        $self->{record} = $copy->call_number->record;
        $self->{mods}           = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
 
-       syslog("LOG_DEBUG", "Item('$item_id'): found with title '%s'", $self->title_id);
+       syslog("LOG_DEBUG", "OILS: Item('$item_id'): found with title '%s'", $self->title_id);
 
        return $self;
 }
 
+sub run_attr_script {
+       my $self = shift;
+       return 1 if $self->{ran_script};
+       $self->{ran_script} = 1;
+
+       my $config = OpenILS::SIP->config();
+       my $path = $config->{implementation_config}->{scripts}->{path};
+       my $item_config_script = $config->{implementation_config}->{scripts}->{item_config};
+
+       syslog('LOG_DEBUG', "OILS: Script path = $path, Item config script = $item_config_script");
+
+       my $runner = 
+               OpenILS::Application::Circ::ScriptBuilder->build(
+                       {
+                               copy => $self->{copy},
+                               editor => OpenILS::SIP->editor(),
+                       }
+               );
+
+       $runner->add_path($path);
+       $runner->load($item_config_script);
+
+       unless( $self->{item_config_result} = $runner->run ) {
+               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: $@");
+               return undef;
+       }
+
+       return 1;
+}
+
 sub magnetic {
     my $self = shift;
-        return 0;
+        return 0 unless $self->run_attr_script;
+        syslog('LOG_DEBUG', "OILS: ITEM CONFIG => ". Dumper($self->{item_config_result}));
+        my $mag = $self->{item_config_result}->{magneticMedia};
+        syslog('LOG_DEBUG', "OILS: magnetic = $mag");
+        return ($mag and $mag eq 't') ? 1 : 0;
 }
 
 sub sip_media_type {
index 5e900c2..32b566e 100644 (file)
@@ -17,6 +17,8 @@ use Digest::MD5 qw(md5_hex);
 use OpenILS::SIP;
 use OpenILS::Application::AppUtils;
 use OpenILS::Application::Actor;
+use OpenSRF::Utils qw/:datetime/;
+use DateTime::Format::ISO8601;
 my $U = 'OpenILS::Application::AppUtils';
 
 our (@ISA, @EXPORT_OK);
@@ -32,7 +34,7 @@ sub new {
     my $type = ref($class) || $class;
     my $self = {};
 
-       syslog("LOG_DEBUG", "new OpenILS Patron(%s): searching...", $patron_id);
+       syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s): searching...", $patron_id);
 
        my $e = OpenILS::SIP->editor();
 
@@ -66,7 +68,7 @@ sub new {
         }
 
         if(!$user) {
-               syslog("LOG_WARNING", "Unable to find patron %s", $patron_id);
+               syslog("LOG_WARNING", "OILS: Unable to find patron %s", $patron_id);
                return undef;
         }
 
@@ -74,7 +76,7 @@ sub new {
        $self->{id}                     = $patron_id;
        $self->{editor} = $e;
 
-       syslog("LOG_DEBUG", "new OpenILS Patron(%s): found patron : barred=%s, card:active=%s", 
+       syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s): found patron : barred=%s, card:active=%s", 
                $patron_id, $self->{user}->barred, $self->{user}->card->active );
 
 
@@ -110,10 +112,12 @@ 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 $maddr = $u->mailing_address;
-       $str .= "\n" . __addr_string($maddr) 
-               if $maddr and $maddr->id ne $addr->id;
+       syslog('LOG_DEBUG', "OILS: Patron address: $str");
+       #my $maddr = $u->mailing_address;
+       #$str .= "\n" . __addr_string($maddr) 
+               #if $maddr and $maddr->id ne $addr->id;
        return $str;
 }
 
@@ -128,8 +132,25 @@ sub home_phone {
 }
 
 sub sip_birthdate {
-    my $self = shift;
-       return $self->{user}->dob;
+       my $self = shift;
+       my $dob = $self->{user}->dob;
+       return "" unless $dob;
+
+       $dob = DateTime::Format::ISO8601->new->
+               parse_datetime(OpenSRF::Utils::clense_ISO8601($dob));
+       my @time = localtime($dob->epoch);
+
+       my $year = $time[5]+1900;
+       my $mon = $time[4]+1;
+       my $day = $time[3];
+
+       $mon =~ s/^(\d)$/0$1/;
+       $day =~ s/^(\d)$/0$1/;
+       $dob = "$year$mon$day";
+
+       syslog('LOG_DEBUG', "OILS: Patron DOB = $dob");
+
+       return $dob;
 }
 
 sub ptype {
@@ -306,7 +327,7 @@ sub __hold_to_title {
 
 sub __copy_to_title {
        my( $e, $copy ) = @_;
-       syslog('LOG_DEBUG', "copy_to_title(%s)", $copy->id);
+       syslog('LOG_DEBUG', "OILS: 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);
@@ -315,14 +336,14 @@ sub __copy_to_title {
 
 sub __volume_to_title {
        my( $e, $volume ) = @_;
-       syslog('LOG_DEBUG', "volume_to_title(%s)", $volume->id);
+       syslog('LOG_DEBUG', "OILS: 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)");
+       syslog('LOG_DEBUG', "OILS: record_to_title($title_id)");
        my $mods = $U->simplereq(
                'open-ils.search',
                'open-ils.search.biblio.record.mods_slim.retrieve', $title_id );
@@ -331,11 +352,11 @@ sub __record_to_title {
 
 sub __metarecord_to_title {
        my( $e, $m_id ) = @_;
-       syslog('LOG_DEBUG', "metarecord_to_title($m_id)");
+       syslog('LOG_DEBUG', "OILS: metarecord_to_title($m_id)");
        my $mods = $U->simplereq(
                'open-ils.search',
                'open-ils.search.biblio.metarecord.mods_slim.retrieve', $m_id);
-       return ($mods) ? $mods->title : "";
+       return ($U->event_code($mods)) ? "<unknown>" : $mods->title;
 }
 
 
@@ -366,7 +387,7 @@ sub overdue_items {
        my @o;
        for my $circid (@overdues) {
                next unless $circid;
-               syslog('LOG_DEBUG', "overdue_items() fleshing circ $circid");
+               syslog('LOG_DEBUG', "OILS: overdue_items() fleshing circ $circid");
                push( @o, __circ_to_title($self->{editor}, $circid) );
        }
        @overdues = @o;
@@ -398,7 +419,7 @@ sub charged_items {
        my @c;
        for my $circid (@charges) {
                next unless $circid;
-               syslog('LOG_DEBUG', "charged_items() fleshing circ $circid");
+               syslog('LOG_DEBUG', "OILS: charged_items() fleshing circ $circid");
                push( @c, __circ_to_title($self->{editor}, $circid) );
        }
        @charges = @c;
@@ -434,13 +455,13 @@ sub block {
        my $u = $self->{user};
        my $e = $self->{editor} = OpenILS::SIP->reset_editor();
 
-       syslog('LOG_INFO', "Blocking user %s", $u->card->barcode );
+       syslog('LOG_INFO', "OILS: Blocking user %s", $u->card->barcode );
 
        return $self if $u->card->active eq 'f';
 
        $u->card->active('f');
        if( ! $e->update_actor_card($u->card) ) {
-               syslog('LOG_ERR', "Block card update failed: %s", $e->event->{textcode});
+               syslog('LOG_ERR', "OILS: Block card update failed: %s", $e->event->{textcode});
                $e->xact_rollback;
                return $self;
        }
@@ -453,7 +474,7 @@ sub block {
        $u->alert_message($note);
 
        if( ! $e->update_actor_user($u) ) {
-               syslog('LOG_ERR', "Block: patron alert update failed: %s", $e->event->{textcode});
+               syslog('LOG_ERR', "OILS: Block: patron alert update failed: %s", $e->event->{textcode});
                $e->xact_rollback;
                return $self;
        }
@@ -491,7 +512,9 @@ sub inet_privileges {
        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;
-       return $level->name;
+       my $name = $level->name;
+       syslog('LOG_DEBUG', "OILS: Patron inet_privs = $name");
+       return $name;
 }
 
 
index e2999f8..84b6101 100644 (file)
@@ -37,7 +37,7 @@ sub new {
        bless $self, $class;
        $self->authtoken($args{authtoken});
 
-       syslog('LOG_DEBUG', "OpenILS: Created new transaction with authtoken %s", $self->authtoken);
+       syslog('LOG_DEBUG', "OILS: Created new transaction with authtoken %s", $self->authtoken);
 
        my $e = OpenILS::SIP->editor();
        $e->{authtoken} = $self->authtoken;
index d19b152..23bbf13 100644 (file)
@@ -54,13 +54,20 @@ sub do_checkin {
 
        if( my $code = $U->event_code($resp) ) {
                my $txt = $resp->{textcode};
-               syslog('LOG_INFO', "Checkin failed with event $code : $txt");
-               $self->ok(0);
-               return 0;
+               if( $txt ne 'ROUTE_ITEM' ) {
+                       syslog('LOG_INFO', "OILS: Checkin failed with event $code : $txt");
+                       $self->ok(0);
+                       return 0;
+               }
        }
 
        my $circ = $resp->{payload}->{circ};
 
+       unless( $circ ) {
+               $self->ok(0);
+               return 0;
+       }
+
        $self->{item}->{patron} = 
                OpenILS::SIP->editor->search_actor_card(
                { usr => $circ->usr, active => 't' } )->[0]->barcode;
index b7b5c06..8e0165a 100644 (file)
@@ -50,7 +50,7 @@ sub new {
 # XXX Set $self->ok(0) on any errors
 sub do_checkout {
        my $self = shift;
-       syslog('LOG_DEBUG', "OpenILS: performing checkout...");
+       syslog('LOG_DEBUG', "OILS: performing checkout...");
 
        $self->ok(0); 
 
@@ -67,23 +67,23 @@ sub do_checkout {
        if( ref($resp) eq 'ARRAY' ) {
                my @e;
                push( @e, $_->{textcode} ) for @$resp;
-               syslog('LOG_INFO', "Checkout permit failed with events: @e");
+               syslog('LOG_INFO', "OILS: Checkout permit failed with events: @e");
                return 0;
        }
 
        if( my $code = $U->event_code($resp) ) {
                my $txt = $resp->{textcode};
-               syslog('LOG_INFO', "Checkout permit failed with event $code : $txt");
+               syslog('LOG_INFO', "OILS: Checkout permit failed with event $code : $txt");
                return 0; 
        }
 
        my $key;
 
        if( $key = $resp->{payload} ) {
-               syslog('LOG_INFO', "OpenILS: circ permit key => $key");
+               syslog('LOG_INFO', "OILS: circ permit key => $key");
 
        } else {
-               syslog('LOG_WARN', "OpenILS: Circ permit failed :\n" . Dumper($resp) );
+               syslog('LOG_WARN', "OILS: Circ permit failed :\n" . Dumper($resp) );
                return 0;
        }
 
@@ -104,11 +104,11 @@ sub do_checkout {
 
                if( my $code = $U->event_code($resp) ) {
                        my $txt = $resp->{textcode};
-                       syslog('LOG_INFO', "Checkout failed with event $code : $txt");
+                       syslog('LOG_INFO', "OILS: Checkout failed with event $code : $txt");
                        return 0; 
                }
 
-               syslog('LOG_INFO', "OpenILS: Checkout succeeded");
+               syslog('LOG_INFO', "OILS: Checkout succeeded");
 
                my $circ = $resp->{payload}->{circ};
                $self->{'due'} = $circ->due_date;