From: miker Date: Tue, 13 May 2008 21:38:53 +0000 (+0000) Subject: mod_perl stub for uploading vandelay files X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c36565ba1022009a292826ab39dea0ef35d00a03;p=Evergreen.git mod_perl stub for uploading vandelay files git-svn-id: svn://svn.open-ils.org/ILS/trunk@9593 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm index 8b71b50e83..3a620544fb 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm @@ -175,6 +175,29 @@ __PACKAGE__->register_method( argc => 3, ); +sub process_marc { + my $r = shift; + my $cgi = new CGI; + + my $auth = $cgi->param('ses') || $cgi->cookie('ses'); + + return Apache2::Const::FORBIDDEN unless verify_login($auth); + + my $fingerprint = $cgi->param('fingerprint') + my $type = $cgi->param('type') + my $queue = $cgi->param('queue') + + my $cache = new OpenSRF::Utils::Cache(); + + my $data = $cache->get_cache('vandelay_import_spool_' . $fingerprint); + $data = decode_base64($data); + + print "Content-type: text/plain; charset=utf-8\n\n$data_fingerprint"; + + return Apache2::Const::OK; + +} + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/Vandelay.pm b/Open-ILS/src/perlmods/OpenILS/WWW/Vandelay.pm new file mode 100644 index 0000000000..44c91a1c12 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/WWW/Vandelay.pm @@ -0,0 +1,97 @@ +package OpenILS::WWW::Vandelay; +use strict; +use warnings; +use bytes; + +use Apache2::Log; +use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log); +use APR::Const -compile => qw(:error SUCCESS); +use APR::Table; + +use Apache2::RequestRec (); +use Apache2::RequestIO (); +use Apache2::RequestUtil; +use CGI; +use Data::Dumper; +use Text::CSV; + +use OpenSRF::EX qw(:try); +use OpenSRF::Utils qw/:datetime/; +use OpenSRF::Utils::Cache; +use OpenSRF::System; +use OpenSRF::AppSession; +use XML::LibXML; +use XML::LibXSLT; + +use Encode; +use Unicode::Normalize; +use OpenILS::Utils::Fieldmapper; +use OpenSRF::Utils::Logger qw/$logger/; + +use MARC::Record; +use MARC::File::XML; + +use MIME::Base64; +use Digest::MD5 qw/md5_hex/; + +use UNIVERSAL::require; + +our @formats = qw/USMARC UNIMARC XML BRE/; + +# set the bootstrap config and template include directory when +# this module is loaded +my $bootstrap; + +sub import { + my $self = shift; + $bootstrap = shift; +} + + +sub child_init { + OpenSRF::System->bootstrap_client( config_file => $bootstrap ); +} + +sub spool_marc { + my $r = shift; + my $cgi = new CGI; + + my $auth = $cgi->param('ses') || $cgi->cookie('ses'); + + return Apache2::Const::FORBIDDEN unless verify_login($auth); + + my $cache = new OpenSRF::Utils::Cache(); + my $file = $cgi->param('marc_upload'); + my $filename = "$file"; + + my $data = join '', (<$file>); + $data = encode_base64($data); + + my $data_fingerprint = md5_hex($data); + + $cache->put_cache('vandelay_import_spool_' . $data_fingerprint, $data); + + print "Content-type: text/plain; charset=utf-8\n\n$data_fingerprint"; + + return Apache2::Const::OK; + +} + +sub verify_login { + my $auth_token = shift; + return undef unless $auth_token; + + my $user = OpenSRF::AppSession + ->create("open-ils.auth") + ->request( "open-ils.auth.session.retrieve", $auth_token ) + ->gather(1); + + if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) { + return undef; + } + + return $user if ref($user); + return undef; +} + +1;