From 7300bda293ba1dbd1a6dde13cede636e82b0365c Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 23 Feb 2006 03:26:09 +0000 Subject: [PATCH] breaking up unapi and supercat rest interfaces; adding oisbn git-svn-id: svn://svn.open-ils.org/ILS/trunk@3175 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm | 231 ++++++++++++------ 1 file changed, 152 insertions(+), 79 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm index eee3beb4ff..2fdd5f09fb 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm @@ -33,107 +33,180 @@ sub child_init { $supercat = OpenSRF::AppSession->create('open-ils.supercat'); } -sub handler { +sub oisbn { my $apache = shift; return Apache2::Const::DECLINED if (-e $apache->filename); - my $path = $apache->path_info; + (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o; - my ($id,$type,$format,$command) = reverse split '/', $path; + my $list = $supercat + ->request("open-ils.supercat.oisbn", $isbn) + ->gather(1); - print "Content-type: application/xml; charset=utf-8\n"; - - if ( $path =~ m{^/?$}o ) { - my $cgi = new CGI; + print "Content-type: application/xml; charset=utf-8\n\n"; + print "\n"; - my $uri = $cgi->param('uri') || ''; - my $base = $cgi->url; + unless (exists $$list{metarecord}) { + print ''; + return Apache2::Const::OK; + } - $format = $cgi->param('format'); - ($id,$type) = ('',''); + print "\n"; - if (!$format) { - if ($uri =~ m{^info:oils/([^\/]+)/(\d+)}o) { - $id = $2; - $type = 'record'; - $type = 'metarecord' if ($1 =~ /^m/o); + for ( keys %{ $$list{record_list} } ) { + (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o; + print " $o\n" + } - my $list = $supercat - ->request("open-ils.supercat.$type.formats") - ->gather(1); + print ""; - print "\n"; - - my $body = - " - $uri - - opac - text/html - ". - - join('', - map { " - $_ - application/xml - " - } @$list - ). - - ''; - - $apache->custom_response( 300, $body); - return 300; - } else { - my $list = $supercat - ->request("open-ils.supercat.record.formats") - ->gather(1); - push @$list, - @{ $supercat - ->request("open-ils.supercat.metarecord.formats") - ->gather(1); - }; - - my %hash = map { ($_ => $_) } @$list; - $list = [ sort keys %hash ]; - - print "\n - - opac - text/html - ". - join('', - map { - "$_text/xml" - } @$list - ).''; - return Apache2::Const::OK; - } - } + return Apache2::Const::OK; +} - +sub unapi { + + my $apache = shift; + return Apache2::Const::DECLINED if (-e $apache->filename); + + print "Content-type: application/xml; charset=utf-8\n"; + + my $cgi = new CGI; + + my $uri = $cgi->param('uri') || ''; + my $base = $cgi->url; + + my $format = $cgi->param('format'); + my ($id,$type,$command) = ('','',''); + + if (!$format) { if ($uri =~ m{^info:oils/([^\/]+)/(\d+)}o) { $id = $2; $type = 'record'; $type = 'metarecord' if ($1 =~ /^m/o); - $command = 'retrieve'; + + my $list = $supercat + ->request("open-ils.supercat.$type.formats") + ->gather(1); + + print "\n"; + + my $body = + " + $uri + + opac + text/html + ". + + join('', + map { " + $_ + application/xml + " + } @$list + ). + + ''; + + $apache->custom_response( 300, $body); + return 300; + } else { + my $list = $supercat + ->request("open-ils.supercat.record.formats") + ->gather(1); + + push @$list, + @{ $supercat + ->request("open-ils.supercat.metarecord.formats") + ->gather(1); + }; + + my %hash = map { ($_ => $_) } @$list; + $list = [ sort keys %hash ]; + + print "\n + + opac + text/html + ". + join('', + map { + "$_text/xml" + } @$list + ).''; + return Apache2::Const::OK; } + } + + + if ($uri =~ m{^info:oils/([^\/]+)/(\d+)}o) { + $id = $2; + $type = 'record'; + $type = 'metarecord' if ($1 =~ /^m/o); + $command = 'retrieve'; + } + + if ($format eq 'opac') { + print "Location: $base/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n" + if ($type eq 'metarecord'); + print "Location: $base/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n" + if ($type eq 'record'); + return 302; + } + + print "\n" . $supercat->request("open-ils.supercat.$type.$format.$command",$id)->gather(1); + + return Apache2::Const::OK; +} - if ($format eq 'opac') { - print "Location: $base/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n" - if ($type eq 'metarecord'); - print "Location: $base/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n" - if ($type eq 'record'); - return 302; +sub supercat { + + my $apache = shift; + return Apache2::Const::DECLINED if (-e $apache->filename); + + my $path = $apache->path_info; + + my ($id,$type,$format,$command) = reverse split '/', $path; + + print "Content-type: application/xml; charset=utf-8\n"; + + if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) { + if ($1) { + my $list = $supercat + ->request("open-ils.supercat.$1.formats") + ->gather(1); + + print "\n + opac + text/html". + join('', + map { + "$_text/xml" + } @$list + ).''; + + return Apache2::Const::OK; } - } elsif ( $path =~ m{^/formats/([^\/]+)$}o ) { my $list = $supercat - ->request("open-ils.supercat.$1.formats") + ->request("open-ils.supercat.record.formats") ->gather(1); - - print "\n". + + push @$list, + @{ $supercat + ->request("open-ils.supercat.metarecord.formats") + ->gather(1); + }; + + my %hash = map { ($_ => $_) } @$list; + $list = [ sort keys %hash ]; + + print "\n + + opac + text/html + ". join('', map { "$_text/xml" -- 2.43.2