summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-07-18 16:27:21 +0200
committerChristoph Helma <helma@in-silico.ch>2012-07-18 16:27:21 +0200
commitb3d32c18947b659dfa98b066931fb8912f7dc102 (patch)
treefd55c3d2eb0ae9a501b13caa0d2a805c3dab6b32 /lib
parent81f0924c654875a738b646ad951a28f906e0a97c (diff)
dataset-large tests pass
Diffstat (limited to 'lib')
-rw-r--r--lib/error.rb12
-rw-r--r--lib/opentox.rb37
-rw-r--r--lib/overwrite.rb4
3 files changed, 25 insertions, 28 deletions
diff --git a/lib/error.rb b/lib/error.rb
index 3017c7f..d1abe52 100644
--- a/lib/error.rb
+++ b/lib/error.rb
@@ -76,16 +76,4 @@ module OpenTox
end
end
-=begin
- # Errors received from RestClientWrapper calls
- class RestCallError < Error
- attr_accessor :request#, :response
- def initialize message, request, uri
- @request = request
- #@response = response
- super 502, message, uri
- end
- end
-=end
-
end
diff --git a/lib/opentox.rb b/lib/opentox.rb
index 2e0f05a..825531c 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -60,34 +60,29 @@ module OpenTox
end
# Get object from webservice
- def get wait=true
+ def get
+ # TODO: RDFXML
response = RestClientWrapper.get(@uri,{},{:accept => "text/plain", :subjectid => @subjectid})
- if URI.task?(response) and wait
- t = OpenTox::Task.new(uri).wait
+ if URI.task?(response)
+ wait_for_task response
response = RestClientWrapper.get(t.resultURI,{},{:accept => "text/plain", :subjectid => @subjectid})
end
parse_ntriples response
- #rescue # fall back to rdfxml
- #parse_rdfxml RestClientWrapper.get(@uri,{},{:accept => "application/rdf+xml", :subjectid => @subjectid})
end
# Post object to webservice
def post service_uri, wait=true
+ # TODO: RDFXML
uri = RestClientWrapper.post service_uri, to_ntriples, { :content_type => "text/plain", :subjectid => @subjectid}
- OpenTox::Task.new(uri).wait if URI.task?(uri) and wait
- #rescue # fall back to rdfxml
- #RestClientWrapper.post service_uri, to_rdfxml, { :content_type => "application/rdf+xml", :subjectid => @subjectid}
+ wait_for_task uri if wait
end
# Save object at webservice
def put wait=true
+ # TODO: RDFXML
append RDF::DC.modified, DateTime.now
- #begin
- RestClientWrapper.put @uri.to_s, self.to_ntriples, { :content_type => "text/plain", :subjectid => @subjectid}
- #rescue # fall back to rdfxml
- #RestClientWrapper.put @uri.to_s, self.to_rdfxml, { :content_type => "application/rdf+xml", :subjectid => @subjectid}
- #end
- OpenTox::Task.new(uri).wait if URI.task?(uri) and wait
+ uri = RestClientWrapper.put @uri.to_s, self.to_ntriples, { :content_type => "text/plain", :subjectid => @subjectid}
+ wait_for_task uri if wait
end
# Delete object at webservice
@@ -95,6 +90,20 @@ module OpenTox
RestClientWrapper.delete(@uri.to_s,nil,{:subjectid => @subjectid})
end
+ def wait_for_task uri
+ if URI.task?(uri)
+ t = OpenTox::Task.new uri
+ t.wait
+ if t.completed?
+ uri = t.resultURI
+ else
+ #TODO raise correct error
+ internal_server_error "Task #{uri} failed with #{$!.inspect}"
+ end
+ end
+ uri
+ end
+
RDF_FORMATS.each do |format|
# rdf parse methods for all formats e.g. parse_rdfxml
diff --git a/lib/overwrite.rb b/lib/overwrite.rb
index 0a55ce2..785fbcd 100644
--- a/lib/overwrite.rb
+++ b/lib/overwrite.rb
@@ -86,10 +86,10 @@ module Kernel
stdout = stdout_stream.read
stderr = stderr_stream.read
end
- internal_server_error "`" + cmd + "` failed.\n" + stdout + stderr if !status.success?
+ internal_server_error "`" + cmd + "` failed.\n" + stdout + stderr unless status.success?
return stdout
rescue
- internal_server_error $!.message
+ internal_server_error $!.message
end
end