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 || "";
36 osrf_connect($config);
37 oils_login($username, $password);
39 if( $patronid eq 'random' ) {
41 while( !($p = $apputils->storagereq(
42 'open-ils.storage.direct.actor.user.random'))) {}
44 print "Fetched random user : $patronid\n";
47 if( $barcode eq 'random' ) {
49 while( !($p = $apputils->storagereq(
50 'open-ils.storage.direct.asset.copy.random'))) {}
51 $barcode = $p->barcode;
52 print "Fetched random barcode: $barcode\n";
55 if($type eq 'renew') {
56 do_renew($patronid, $barcode);
58 } elsif( $type eq 'transit_receive' ) {
59 do_transit_receive($barcode);
61 } elsif( $type eq 'checkin' ) {
64 my($key,$precat) = do_permit($patronid, $barcode, $type =~ /noncat/ );
65 printl("Item is pre-cataloged...") if $precat;
66 do_checkout($key, $patronid, $barcode,
67 $precat, $type =~ /noncat/, $nc_type ) unless ($type =~ /permit/);
69 #oils_logout(); # - this will break the post-method db updates
74 #----------------------------------------------------------------
77 my( $patronid, $barcode, $noncat ) = @_;
80 my $args = { patron => $patronid, barcode => $barcode };
83 $args->{noncat_type} = $nc_type;
88 CIRC(), 'open-ils.circ.checkout.permit', $authtoken, $args );
90 if( oils_event_equals($resp, 'ITEM_NOT_CATALOGED') ) {
96 oils_event_die($resp);
98 if( ref($resp) eq 'ARRAY' ) { # we received a list of non-success events
99 if( oils_event_equals($$resp[0], 'COPY_ALERT_MESSAGE') ) {
100 printl("copy has alert attached: " . $$resp[0]->{payload});
106 printl("received event: ".$_->{textcode}) for @$resp;
111 my $e = time() - $start;
112 my $key = $resp->{payload};
113 printl("Permit OK: \n\ttime =\t$e\n\tkey =\t$key" );
115 return ( $key, $precat );
119 my( $key, $patronid, $barcode, $precat, $noncat, $nc_type ) = @_;
121 my $args = { permit_key => $key, patron => $patronid, barcode => $barcode };
125 $args->{noncat_type} = $nc_type;
130 $args->{dummy_title} = "Dummy Title";
131 $args->{dummy_author} = "Dummy Author";
134 my $start_checkout = time();
135 my $resp = osrf_request(
137 'open-ils.circ.checkout', $authtoken, $args );
140 oils_event_die($resp);
142 my $d = $finish - $start_checkout;
143 my $dd = $finish - $start;
145 printl("Checkout OK:");
146 printl("\ttime = $d");
147 printl("\ttotal time = $dd");
148 printl("\ttitle = " . $resp->{payload}->{record}->title ) unless($noncat or $precat);
149 printl("\tdue_date = " . $resp->{payload}->{circ}->due_date ) unless $noncat;
155 my( $patronid, $barcode ) = @_;
156 #my $args = { patron => $patronid, barcode => $barcode };
157 my $args = { barcode => $barcode };
159 my $resp = simplereq(
160 CIRC(), 'open-ils.circ.renew', $authtoken, $args );
162 oils_event_die($resp);
163 printl("Renewal succeeded\nTime: $e");
168 my $args = { barcode => $barcode };
170 my $resp = simplereq(
171 CIRC(), 'open-ils.circ.checkin', $authtoken, $args );
173 oils_event_die($resp);
174 debug($resp) if(ref($resp) eq 'ARRAY');
175 printl("Checkin succeeded\nTime: $e");
179 sub do_transit_receive {
181 my $args = { barcode => $barcode };
183 my $resp = simplereq(
184 CIRC(), 'open-ils.circ.copy_transit.receive', $authtoken, $args );
186 oils_event_die($resp);
187 printl("Transit receive succeeded\nTime: $t");