forked from MITLibraries/Aleph_API_adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.pl
executable file
·103 lines (95 loc) · 3.79 KB
/
validate.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl
#----------------------------------------------------------------------------------
# The following BEGIN block is required to trap error messages from
# 'use' statements.
#----------------------------------------------------------------------------------
use strict;
use warnings;
my %perl_modules;
my $aleph_id = $ARGV[0];
my $jboss_port = $ARGV[1];
die 'No correct Aleph ID was specified.'
unless (defined($aleph_id)
and $aleph_id =~ /^\S{1,12}$/);
die 'No correct JBoss port was specified.'
unless (defined($jboss_port)
and $jboss_port =~ /^\d+$/
and $jboss_port > 0 and $jboss_port < 65536);
BEGIN {
#------------------------------------------------
# Read the file created by install_adapter.pl.
#------------------------------------------------
my $textfile = 'sql_lookup.txt';
open(FH1,"<$textfile") or die "Unable to open $textfile\n";
my $xserver_licensed = <FH1>;
close(FH1);
chomp $xserver_licensed;
my @modules = ('DateTime','HTTP::Request','LWP::UserAgent','POSIX','Switch');
if (!$xserver_licensed) {
push @modules, 'DBI';
push @modules, 'DBD::Oracle';
}
%perl_modules = ();
foreach (@modules) {
my $module = $_;
if (!eval "require $module; 1") {
$perl_modules{$module} = '[Module not found]';
} else {
$perl_modules{$module} = ' [OK]';
}
}
} # End BEGIN block
#-----------------------------------------------
# Display status of Perl modules
#-----------------------------------------------
print "\nStatus of required Perl modules:\n";
foreach my $key (sort keys %perl_modules) {
print "\n\t$key\n\t$perl_modules{$key}\n";
}
print "\n";
#-----------------------------------------------
# Construct a url for the Aleph x-server that
# will retrieve a bib record in xml format.
#-----------------------------------------------
my $ua = LWP::UserAgent->new;
my $operation = 'find-doc&doc_number=';
my $x_url = "http://localhost/X?op=bor_by_key&bor_id=$aleph_id";
print "Sending $x_url\n";
my $response = $ua->get($x_url);
if (not $response->is_success or grep /<error>/, $response->content) {
print "X-server retrieval status:\n\t[failed]\n";
} else {
print "X-server retrieval status:\n\t[OK]\n";
}
#---------------------------------------------------
# Construct a url for the Aleph REST API that
# will retrieve patron information in xml format.
#---------------------------------------------------
my $rest_url = "http://localhost:PORT/rest-dlf/patron/$aleph_id/patronInformation/address";
$rest_url =~ s/PORT/$jboss_port/g;
print "\nSending $rest_url\n";
$response = $ua->get($rest_url);
if (not $response->is_success or !grep /<reply-code>0000<\/reply-code>/, $response->content) {
print "REST API retrieval status:\n\t[failed]\n";
} else {
print "REST API retrieval status:\n\t[OK]\n";
}
#---------------------------------------------------
# Test the retrieval of Aleph version information.
#---------------------------------------------------
my @aleph_info = `./get_aleph_info.csh`;
if (grep /aleph/i, @aleph_info) {
print "\nAleph version retrieval status:\n\t[OK]\n";
} else {
print "\nAleph version retrieval status:\n\t[failed]\n";
}
#------------------------------------------------
# Generate a URL for testing the installation.
#------------------------------------------------
die "\n".'$ENV{WWW_HOST} not defined.'
unless (defined($ENV{WWW_HOST})
and $ENV{WWW_HOST} !~ /^\s*$/);
my $test_url = "https://$ENV{WWW_HOST}/rest-dlf/patron/$aleph_id/patronInformation/address";
print "\nPut this URL in a browser to test the adapter after all the installation steps are completed.\n\t$test_url\n\n";
exit;
# vim:textwidth=80:expandtab:tabstop=4:shiftwidth=4:fileencodings=utf8:spelllang=en