3 #----------------------------------------------------------------
4 # Code for testing the container API
5 #----------------------------------------------------------------
7 require '../oils_header.pl';
8 use vars qw/ $apputils $memcache $user $authtoken $authtime /;
9 use strict; use warnings;
10 use Time::HiRes qw/time/;
12 #----------------------------------------------------------------
13 err("\nusage: $0 <config> <oils_login_username> ".
14 " <oils_login_password> <patronid> <copy_barcode> [<type>, <noncat_type>]\n".
15 "Where <type> is one of:\n".
16 "\t'permit' to run the permit only\n".
17 "\t'noncat_permit' to run the permit script against a noncat item\n".
18 "\t'noncat' to check out a noncat item\n".
19 "\t(blank) to do a regular checkout\n" ) unless $ARGV[4];
20 #----------------------------------------------------------------
27 my $type = shift || "";
33 osrf_connect($config);
34 oils_login($username, $password);
36 if($type eq 'renew') {
37 do_renew($patronid, $barcode);
39 } elsif( $type eq 'checkin' ) {
42 my($key,$precat) = do_permit($patronid, $barcode, $type =~ /noncat/ );
43 printl("Item is pre-cataloged...") if $precat;
44 do_checkout($key, $patronid, $barcode,
45 $precat, $type =~ /noncat/, $nc_type ) unless ($type =~ /permit/);
52 #----------------------------------------------------------------
55 my( $patronid, $barcode, $noncat ) = @_;
58 my $args = { patron => $patronid, barcode => $barcode };
61 $args->{noncat_type} = $nc_type;
66 CIRC(), 'open-ils.circ.checkout.permit', $authtoken, $args );
68 if( oils_event_equals($resp, 'ITEM_NOT_CATALOGED') ) {
70 } else { oils_event_die($resp); }
72 my $e = time() - $start;
73 my $key = $resp->{payload};
74 printl("Permit OK: \n\ttime =\t$e\n\tkey =\t$key" );
76 return ( $key, $precat );
80 my( $key, $patronid, $barcode, $precat, $noncat, $nc_type ) = @_;
82 my $args = { permit_key => $key, patron => $patronid, barcode => $barcode };
86 $args->{noncat_type} = $nc_type;
91 $args->{dummy_title} = "Dummy Title";
92 $args->{dummy_author} = "Dummy Author";
95 my $start_checkout = time();
96 my $resp = osrf_request(
98 'open-ils.circ.checkout', $authtoken, $args );
101 oils_event_die($resp);
103 my $d = $finish - $start_checkout;
104 my $dd = $finish - $start;
106 printl("Checkout OK:");
107 printl("\ttime = $d");
108 printl("\ttotal time = $dd");
109 printl("\ttitle = " . $resp->{payload}->{record}->title ) unless($noncat or $precat);
110 printl("\tdue_date = " . $resp->{payload}->{circ}->due_date ) unless $noncat;
116 my( $patronid, $barcode ) = @_;
117 my $args = { patron => $patronid, barcode => $barcode };
119 my $resp = simplereq(
120 CIRC(), 'open-ils.circ.renew', $authtoken, $args );
122 oils_event_die($resp);
123 printl("Renewal succeeded\nTime: $t");
128 my $args = { barcode => $barcode };
130 my $resp = simplereq(
131 CIRC(), 'open-ils.circ.checkin', $authtoken, $args );
133 oils_event_die($resp);
134 printl("Checkin succeeded\nTime: $t");