3 #----------------------------------------------------------------
4 # Generic header for tesing OpenSRF methods
5 #----------------------------------------------------------------
12 use OpenSRF::AppSession;
13 use OpenSRF::EX qw(:try);
14 use Time::HiRes qw/time/;
15 use Digest::MD5 qw(md5_hex);
16 use OpenILS::Utils::Fieldmapper;
17 use OpenILS::Application::AppUtils;
18 use OpenSRF::Utils::Logger qw/:logger/;
22 our $apputils = "OpenILS::Application::AppUtils";
28 # Some constants for our services
29 our $AUTH = 'open-ils.auth';
30 our $STORAGE = 'open-ils.storage';
31 our $SEARCH = 'open-ils.search';
32 our $CIRC = 'open-ils.circ';
33 our $CAT = 'open-ils.cat';
34 our $MATH = 'opensrf.math';
35 our $SETTINGS = 'opensrf.settings';
36 our $ACTOR = 'open-ils.actor';
39 #----------------------------------------------------------------
41 #----------------------------------------------------------------
43 my ($pkg, $file, $line, $sub) = _caller();
45 die "Script halted with error ".
46 "($pkg : $file : $line : $sub):\n" . shift() . "\n";
49 #----------------------------------------------------------------
51 #----------------------------------------------------------------
52 sub printl { print "@_\n"; }
54 #----------------------------------------------------------------
55 # Print with Data::Dumper
56 #----------------------------------------------------------------
57 sub debug { printl(Dumper(@_)); }
60 #----------------------------------------------------------------
61 # This is not the function you're looking for
62 #----------------------------------------------------------------
64 my ($pkg, $file, $line, $sub) = caller(2);
66 ($pkg, $file, $line) = caller(1);
69 return ($pkg, $file, $line, $sub);
73 #----------------------------------------------------------------
74 # Connect to the servers
75 #----------------------------------------------------------------
78 err("Bootstrap config required") unless $config;
79 OpenSRF::System->bootstrap_client( config_file => $config );
82 #----------------------------------------------------------------
83 # Get a handle for the memcache object
84 #----------------------------------------------------------------
86 eval 'use OpenSRF::Utils::Cache;';
87 $memcache = OpenSRF::Utils::Cache->new('global') unless $memcache;
91 #----------------------------------------------------------------
92 # Is the given object an OILS event?
93 #----------------------------------------------------------------
96 if( $e and ref($e) eq 'HASH' ) {
97 return 1 if defined($e->{ilsevent});
102 #----------------------------------------------------------------
103 # If the given object is an event, this prints the event info
104 # and exits the script
105 #----------------------------------------------------------------
108 my ($pkg, $file, $line, $sub) = _caller();
109 if(oils_is_event($evt)) {
110 if($evt->{ilsevent}) {
111 printl("\nReceived Event($pkg : $file : $line : $sub): \n" . Dumper($evt));
118 #----------------------------------------------------------------
119 # Login to the auth server and set the global $authtoken var
120 #----------------------------------------------------------------
122 my( $username, $password ) = @_;
124 my $seed = $apputils->simplereq( $AUTH,
125 'open-ils.auth.authenticate.init', $username );
126 err("No auth seed") unless $seed;
128 my $response = $apputils->simplereq( $AUTH,
129 'open-ils.auth.authenticate.complete', $username,
130 md5_hex($seed . md5_hex($password)));
131 err("No auth response returned on login") unless $response;
133 oils_event_die($response);
135 $authtime = $response->{payload}->{authtime};
136 $authtoken = $response->{payload}->{authtoken};
140 #----------------------------------------------------------------
141 # Fetches the user object and sets the global $user var
142 #----------------------------------------------------------------
143 sub oils_fetch_session {
145 my $resp = $apputils->simplereq( $AUTH,
146 'open-ils.auth.session.retrieve', $ses, 'staff' );
147 oils_event_die($resp);
148 return $user = $resp;
151 #----------------------------------------------------------------
152 # var $response = simplereq( $service, $method, @params );
153 #----------------------------------------------------------------
154 sub simplereq { return $apputils->simplereq(@_); }