3 #----------------------------------------------------------------
4 # Generic header for tesing OpenSRF methods
5 #----------------------------------------------------------------
9 use OpenSRF::Utils::JSON;
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::SettingsClient;
19 use OpenSRF::Utils::Logger qw/:logger/;
20 use UNIVERSAL::require;
24 our $cache = "OpenSRF::Utils::Cache";
25 our $apputils = "OpenILS::Application::AppUtils";
31 # Some constants for our services
32 our $AUTH = 'open-ils.auth';
33 our $STORAGE = 'open-ils.storage';
34 our $SEARCH = 'open-ils.search';
35 our $CIRC = 'open-ils.circ';
36 our $CAT = 'open-ils.cat';
37 our $MATH = 'opensrf.math';
38 our $SETTINGS = 'opensrf.settings';
39 our $ACTOR = 'open-ils.actor';
41 sub AUTH { return $AUTH; }
42 sub STORAGE { return $STORAGE; }
43 sub SEARCH { return $SEARCH; }
44 sub CIRC { return $CIRC; }
45 sub CAT { return $CAT; }
46 sub MATH { return $MATH; }
47 sub SETTINGS { return $SETTINGS; }
48 sub ACTOR { return $ACTOR; }
51 #----------------------------------------------------------------
53 #----------------------------------------------------------------
55 my ($pkg, $file, $line, $sub) = _caller();
57 die "Script halted with error ".
58 "($pkg : $file : $line : $sub):\n" . shift() . "\n";
61 #----------------------------------------------------------------
63 #----------------------------------------------------------------
64 sub printl { print "@_\n"; }
66 #----------------------------------------------------------------
67 # Print with Data::Dumper
68 #----------------------------------------------------------------
69 sub debug { printl(Dumper(@_)); }
72 #----------------------------------------------------------------
73 # This is not the function you're looking for
74 #----------------------------------------------------------------
76 my ($pkg, $file, $line, $sub) = caller(2);
78 ($pkg, $file, $line) = caller(1);
81 return ($pkg, $file, $line, $sub);
85 #----------------------------------------------------------------
86 # Connect to the servers
87 #----------------------------------------------------------------
90 err("Bootstrap config required") unless $config;
91 OpenSRF::System->bootstrap_client( config_file => $config );
92 Fieldmapper->import(IDL =>
93 OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
98 my ($key) = grep { $_ =~ /OpenILS.*CStoreEditor/o } keys %INC;
101 my $h = $SIG{__WARN__};
102 $SIG{__WARN__} = sub {};
103 require OpenILS::Utils::CStoreEditor;
108 #----------------------------------------------------------------
109 # Get a handle for the memcache object
110 #----------------------------------------------------------------
113 $memcache = $cache->new('global') unless $memcache;
117 #----------------------------------------------------------------
118 # Is the given object an OILS event?
119 #----------------------------------------------------------------
122 if( $e and ref($e) eq 'HASH' ) {
123 return 1 if defined($e->{ilsevent});
128 sub oils_event_equals {
129 my( $e, $name ) = @_;
130 return 1 if (oils_is_event($e) and ($e->{textcode} eq $name));
134 #----------------------------------------------------------------
135 # If the given object is an event, this prints the event info
136 # and exits the script
137 #----------------------------------------------------------------
140 my ($pkg, $file, $line, $sub) = _caller();
141 if(oils_is_event($evt)) {
142 if($evt->{ilsevent}) {
143 printl("\nReceived Event($pkg : $file : $line : $sub): \n" . Dumper($evt));
150 #----------------------------------------------------------------
151 # Login to the auth server and set the global $authtoken var
152 #----------------------------------------------------------------
154 my( $username, $password, $type ) = @_;
158 my $seed = $apputils->simplereq( $AUTH,
159 'open-ils.auth.authenticate.init', $username );
160 err("No auth seed") unless $seed;
162 my $response = $apputils->simplereq( $AUTH,
163 'open-ils.auth.authenticate.complete',
164 { username => $username,
165 password => md5_hex($seed . md5_hex($password)),
168 err("No auth response returned on login") unless $response;
170 oils_event_die($response);
172 $authtime = $response->{payload}->{authtime};
173 $authtoken = $response->{payload}->{authtoken};
178 #----------------------------------------------------------------
179 # Destroys the login session on the server
180 #----------------------------------------------------------------
182 $apputils->simplereq(
184 'open-ils.auth.session.delete', (@_ ? shift : $authtoken) );
187 #----------------------------------------------------------------
188 # Fetches the user object and sets the global $user var
189 #----------------------------------------------------------------
190 sub oils_fetch_session {
192 my $resp = $apputils->simplereq( $AUTH,
193 'open-ils.auth.session.retrieve', $ses, 'staff' );
194 oils_event_die($resp);
195 return $user = $resp;
198 #----------------------------------------------------------------
199 # var $response = simplereq( $service, $method, @params );
200 #----------------------------------------------------------------
201 sub simplereq { return $apputils->simplereq(@_); }
202 sub osrf_request { return $apputils->simplereq(@_); }