From 6f66d558e8512f7f2b0071c2d9c87ea69ec55472 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 7 May 2012 14:31:08 +0000 Subject: error code from error report --- application.rb | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/application.rb b/application.rb index a27b48a..e0a33ab 100644 --- a/application.rb +++ b/application.rb @@ -3,13 +3,8 @@ module OpenTox helpers do def status_code uri - sparql = "SELECT ?o WHERE {<#{uri}> <#{RDF::OT.hasStatus}> ?o. }" - result = Backend::FourStore.query(sparql,nil) - unless result.size == 1 - # TODO: identify error cause and fix, simultanous 4stoer access? - internal_server_error "Cannot find status for '#{uri}', candidates are #{result.inspect}" - end - status = result.last.gsub(/"|'/,'').gsub(/\^\^.*$/,'') + sparql = "SELECT ?o WHERE { GRAPH <#{uri}> { <#{uri}> <#{RDF::OT.hasStatus}> ?o. } }" + status = Backend::FourStore.query(sparql,nil).last.gsub(/"|'/,'').gsub(/\^\^.*$/,'') case status when "Completed" 200 @@ -18,10 +13,12 @@ module OpenTox when "Cancelled" 503 when "Error" - # TODO: get code from error report - 500 + sparql = "SELECT ?code WHERE { GRAPH <#{uri}> { <#{uri}> <#{RDF::OT.error}> ?error. ?error <#{RDF::OT.statusCode}> ?code } }" + code = Backend::FourStore.query(sparql,nil).last.to_i + code ? code : 500 end end + end get '/task/:id/?' do @@ -30,12 +27,6 @@ module OpenTox halt status_code(uri), rdf end -=begin - get '/:id/:status/?' do - end - -=end - put '/task/:id/:status/?' do uri = uri("/task/#{params[:id]}") sparql = [] @@ -55,7 +46,6 @@ module OpenTox sparql << "INSERT DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.hasStatus}> \"Cancelled\"}}" sparql << "INSERT DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.finished_at}> \"#{DateTime.now}\"}}" when "Error" - puts "ERROR" sparql << "DELETE DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.hasStatus}> \"Running\"}}" sparql << "INSERT DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.hasStatus}> \"Error\"}}" sparql << "INSERT DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.finished_at}> \"#{DateTime.now}\"}}" -- cgit v1.2.3