From: tla Date: Fri, 8 Nov 2013 13:11:16 +0000 (+0100) Subject: Try out and debug interaction with Stemweb callbacks. Fixes #27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=67b2a66507872211d107218b185fe8ad376cab9c;p=scpubgit%2Fstemmaweb.git Try out and debug interaction with Stemweb callbacks. Fixes #27 --- diff --git a/lib/stemmaweb/Controller/Stemweb.pm b/lib/stemmaweb/Controller/Stemweb.pm index cab3b2e..8804c4c 100644 --- a/lib/stemmaweb/Controller/Stemweb.pm +++ b/lib/stemmaweb/Controller/Stemweb.pm @@ -29,7 +29,7 @@ L + { jobid: status: 0 format: result: } @@ -50,7 +50,9 @@ sub result :Local :Args(0) { my $answer; if( ref( $c->request->body ) eq 'File::Temp' ) { # Read in the file and parse that. - open( POSTDATA, $c->request->body ) or die "Failed to open post data file"; + $c->log->debug( "Request body is in a temp file" ); + open( POSTDATA, $c->request->body ) + or return _json_error( 500, "Failed to open post data file" ); binmode( POSTDATA, ':utf8' ); # JSON should be all one line my $pdata = ; @@ -65,6 +67,8 @@ sub result :Local :Args(0) { } else { $answer = from_json( $c->request->body ); } + $c->log->debug( "Received push notification from Stemweb: " + . to_json( $answer ) ); return _process_stemweb_result( $c, $answer ); } else { return _json_error( $c, 403, 'Please use POST!' ); @@ -122,7 +126,7 @@ sub _process_stemweb_result { $m->scan( sub{ push( @traditions, $_[0] ) if $_[0]->$_isa('Text::Tradition') && $_[0]->has_stemweb_jobid - && $_[0]->stemweb_jobid eq $answer->{job_id}; + && $_[0]->stemweb_jobid eq $answer->{jobid}; push( @users, $_[0] ) if $_[0]->$_isa('Text::Tradition::User'); } ); if( @traditions == 1 ) { @@ -154,14 +158,14 @@ sub _process_stemweb_result { } } elsif( @traditions ) { return _json_error( $c, 500, - "Multiple traditions with Stemweb job ID " . $answer->{job_id} . "!" ); + "Multiple traditions with Stemweb job ID " . $answer->{jobid} . "!" ); } else { # Possible that the tradition got updated in the meantime... if( $answer->{status} == 0 ) { $c->stash->{'result'} = { 'status' => 'notfound' }; } else { return _json_error( $c, 400, - "No tradition found with Stemweb job ID " . $answer->{job_id} ); + "No tradition found with Stemweb job ID " . $answer->{jobid} ); } } $c->forward('View::JSON'); @@ -197,8 +201,9 @@ sub request :Local :Args(0) { my $stemweb_request = { return_path => $return_uri->path, return_host => $return_uri->host_port, - data => $t->collation->as_tsv, + data => $t->collation->as_tsv({noac => 1}), userid => $c->user->get_object->email, + textid => $tid, parameters => $reqparams }; # Call to the appropriate URL with the request parameters. diff --git a/script/maketestdb.pl b/script/maketestdb.pl index db1b1e8..389b8ec 100755 --- a/script/maketestdb.pl +++ b/script/maketestdb.pl @@ -56,7 +56,6 @@ $t3->name( 'John verse' ); $dir->store( $t3 ); my $t4 = Text::Tradition->new( input => 'Self', file => 't/data/collatecorr.xml' ); $t4->public( 1 ); -$t4->set_stemweb_jobid( '16' ); $user->add_tradition( $t4 ); $dir->store( $t4 ); $dir->store( $user );