some bugfixes for Stemweb requests. For issue #29
tla [Thu, 7 Nov 2013 12:44:55 +0000 (13:44 +0100)]
lib/stemmaweb/Controller/Stemweb.pm
root/js/componentload.js

index f0ffa08..1a8a56e 100644 (file)
@@ -1,7 +1,8 @@
 package stemmaweb::Controller::Stemweb;
 use Moose;
 use namespace::autoclean;
-use JSON qw/ from_json /;
+use Encode qw/ decode_utf8 /;
+use JSON qw/ decode_json encode_json from_json /;
 use LWP::UserAgent;
 use Safe::Isa;
 use TryCatch;
@@ -129,16 +130,19 @@ sub request :Local :Args(0) {
                return_path => $return_uri->path,
                return_host => $return_uri->host_port,
                data => $t->collation->as_tsv,
-               userid => $c->user->email,
+               userid => $t->user->email,
                parameters => $reqparams };
                
        # Call to the appropriate URL with the request parameters.
+    $DB::single = 1;
        my $ua = LWP::UserAgent->new();
        my $resp = $ua->post( $STEMWEB_BASE_URL . "/algorithms/process/$algorithm/",
                'Content-Type' => 'application/json; charset=utf-8', 
                'Content' => encode_json( $stemweb_request ) ); 
        if( $resp->is_success ) {
                # Process it
+               $c->log->debug( 'Got a response from the server: '
+                       . decode_utf8( $stemweb_response ) );
                my $stemweb_response = decode_json( $resp->content );
                try {
                        $t->set_stemweb_jobid( $stemweb_response->{jobid} );
@@ -153,7 +157,7 @@ sub request :Local :Args(0) {
                # The server was unavailable.
                return _json_error( $c, 503, "The Stemweb server is currently unreachable." );
        } else {
-               return _json_error( $c, 500, "Stemweb error: " . $resp->status . " / "
+               return _json_error( $c, 500, "Stemweb error: " . $resp->code . " / "
                        . $resp->content );
        }
 }
@@ -183,4 +187,4 @@ sub _json_error {
        return 0;
 }
 
-1;
\ No newline at end of file
+1;
index 0f98f35..e804204 100644 (file)
@@ -511,7 +511,7 @@ $(document).ready( function() {
                                                        optCtrl = $('<checkbox>');
                                                }
                                                // Add the name and element ID
-                                               optCtrl.attr( 'name', argInfo.name ).attr( 'id', optId );
+                                               optCtrl.attr( 'name', argInfo.key ).attr( 'id', optId );
                                                // Append the label and the option itself to the form.
                                                $('#stemweb_runtime_options').append( optLabel )
                                                        .append( optCtrl ).append( $('<br>') );
@@ -527,8 +527,7 @@ $(document).ready( function() {
                },
        }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
                $(event.target).parent().find('.ui-button').button("enable");
-       if( ajaxSettings.url.indexOf( 'algorithms' ) > -1 
-               && ajaxSettings.type == 'POST' ) {
+       if( ajaxSettings.url.indexOf( 'stemweb/request' ) > -1 ) {
                        display_error( jqXHR, $("#stemweb_run_status") );
        }
        });