]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/checkout.pl
Fix empty statuses filter
[working/Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / checkout.pl
1 #!/usr/bin/perl
2
3 #----------------------------------------------------------------
4 # Code for testing the container API
5 #----------------------------------------------------------------
6
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/;
11
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 #----------------------------------------------------------------
21
22 my $config              = shift; 
23 my $username    = shift;
24 my $password    = shift;
25 my $patronid    = shift;
26 my $barcode             = shift;
27 my $type                        = shift || "";
28 my $nc_type             = shift;
29
30 my $start;
31
32
33
34
35 sub go {
36         osrf_connect($config);
37         oils_login($username, $password);
38
39         if( $patronid eq 'random' ) {
40                 my $p;
41                 while( !($p = $apputils->storagereq(
42                         'open-ils.storage.direct.actor.user.random'))) {}
43                 $patronid = $p->id;
44                 print "Fetched random user : $patronid\n";
45         }
46         
47         if( $barcode eq 'random' ) {
48                 my $p;
49                 while( !($p = $apputils->storagereq(
50                         'open-ils.storage.direct.asset.copy.random'))) {}
51                 $barcode = $p->barcode;
52                 print "Fetched random barcode: $barcode\n";
53         }
54
55         if($type eq 'renew') {
56                 do_renew($patronid, $barcode);
57
58         } elsif( $type eq 'transit_receive' ) {
59                 do_transit_receive($barcode);
60
61         } elsif( $type eq 'checkin' ) {
62                 do_checkin($barcode);
63         } else {
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/);
68         }
69         #oils_logout(); # - this will break the post-method db updates
70 }
71
72 go();
73
74 #----------------------------------------------------------------
75
76 sub do_permit {
77         my( $patronid, $barcode, $noncat ) = @_;
78
79         my $precat = 0;
80         my $args = { patron => $patronid, barcode => $barcode };
81         if($noncat) {
82                 $args->{noncat} = 1;
83                 $args->{noncat_type} = $nc_type;
84         }
85
86         $start = time();
87         my $resp = simplereq( 
88                 CIRC(), 'open-ils.circ.checkout.permit', $authtoken, $args );
89
90         if( oils_event_equals($resp, 'ITEM_NOT_CATALOGED') ) {
91                 $precat = 1;
92
93
94         } else {
95
96                 oils_event_die($resp);   
97         
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});
101                                 printl("");
102                                 debug($resp);
103                                 printl("");
104                         }
105
106                         printl("received event: ".$_->{textcode}) for @$resp;
107                         return undef;
108                 } 
109         }
110
111         my $e = time() - $start;
112         my $key = $resp->{payload};
113         printl("Permit OK: \n\ttime =\t$e\n\tkey =\t$key" );
114         
115         return ( $key, $precat );
116 }
117
118 sub do_checkout {
119         my( $key, $patronid, $barcode, $precat, $noncat, $nc_type ) = @_;
120
121         my $args = { permit_key => $key, patron => $patronid, barcode => $barcode };
122
123         if($noncat) {
124                 $args->{noncat} = 1;
125                 $args->{noncat_type} = $nc_type;
126         }
127
128         if($precat) {
129                 $args->{precat} = 1;
130                 $args->{dummy_title} = "Dummy Title";
131                 $args->{dummy_author} = "Dummy Author";
132         }
133
134         my $start_checkout = time();
135         my $resp = osrf_request(
136                 'open-ils.circ', 
137                 'open-ils.circ.checkout', $authtoken, $args );
138         my $finish = time();
139
140         oils_event_die($resp);
141
142         my $d = $finish - $start_checkout;
143         my $dd = $finish - $start;
144
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;
150 }
151
152
153
154 sub do_renew {
155         my( $patronid, $barcode ) = @_;
156         #my $args = { patron => $patronid, barcode => $barcode };
157         my $args = { barcode => $barcode };
158         my $t = time();
159         my $resp = simplereq( 
160                 CIRC(), 'open-ils.circ.renew', $authtoken, $args );
161         my $e = time() - $t;
162         oils_event_die($resp);
163         printl("Renewal succeeded\nTime: $e");
164 }
165
166 sub do_checkin {
167         my $barcode  = shift;
168         my $args = { barcode => $barcode };
169         my $t = time();
170         my $resp = simplereq( 
171                 CIRC(), 'open-ils.circ.checkin', $authtoken, $args );
172         my $e = time() - $t;
173         oils_event_die($resp);
174         debug($resp) if(ref($resp) eq 'ARRAY');
175         printl("Checkin succeeded\nTime: $e");
176
177 }
178
179 sub do_transit_receive {
180         my $barcode = shift;
181         my $args = { barcode => $barcode };
182         my $t = time();
183         my $resp = simplereq( 
184                 CIRC(), 'open-ils.circ.copy_transit.receive', $authtoken, $args );
185         my $e = time() - $t;
186         oils_event_die($resp);
187         printl("Transit receive succeeded\nTime: $t");
188 }