summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2013-05-29 15:05:43 +0200
committerChristoph Helma <helma@in-silico.ch>2013-05-29 15:05:43 +0200
commit2ae4341e7e35f9ce4a059712cbb559a7544ee98e (patch)
tree064fe85136522f7d27f6854c6157af94d1f84bb2
parentade0195b8790c481c6dcd12db6f755e8b2955f5d (diff)
render function added, modification time update moved to opentox-client
-rw-r--r--lib/4store.rb4
-rw-r--r--lib/opentox.rb37
2 files changed, 38 insertions, 3 deletions
diff --git a/lib/4store.rb b/lib/4store.rb
index 4240879..13f5fd2 100644
--- a/lib/4store.rb
+++ b/lib/4store.rb
@@ -28,7 +28,7 @@ module OpenTox
bad_request_error "Request body empty." unless rdf
mime_type = "application/x-turtle" if mime_type == "text/plain" # ntriples is turtle in 4store
RestClient.post File.join(four_store_uri,"data")+"/", :data => rdf.gsub(/\\C/,'C'), :graph => uri, "mime-type" => mime_type # remove backslashes in SMILES (4store interprets them as UTF-8 \C even within single quoates)
- update "INSERT DATA { GRAPH <#{uri}> { <#{uri}> <#{RDF::DC.modified}> \"#{DateTime.now}\" } }"
+ #update "INSERT DATA { GRAPH <#{uri}> { <#{uri}> <#{RDF::DC.modified}> \"#{DateTime.now}\" } }"
end
def self.put uri, rdf, mime_type
@@ -36,7 +36,7 @@ module OpenTox
bad_request_error "Reqest body empty." unless rdf
mime_type = "application/x-turtle" if mime_type == "text/plain"
RestClientWrapper.put File.join(four_store_uri,"data",uri), rdf, :content_type => mime_type
- update "INSERT DATA { GRAPH <#{uri}> { <#{uri}> <#{RDF::DC.modified}> \"#{DateTime.now}\" } }"
+ #update "INSERT DATA { GRAPH <#{uri}> { <#{uri}> <#{RDF::DC.modified}> \"#{DateTime.now}\" } }"
end
def self.delete uri
diff --git a/lib/opentox.rb b/lib/opentox.rb
index 8e20ab2..06026be 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -28,7 +28,8 @@ module OpenTox
end
before do
- @uri = uri(request.env['REQUEST_URI'])
+ @uri = uri(request.env['PATH_INFO']) # prevent /algorithm/algorithm in algorithm service
+ #@uri = uri(request.env['REQUEST_URI'])
get_subjectid if respond_to? :get_subjectid
# fix IE
request.env['HTTP_ACCEPT'] += ";text/html" if request.env["HTTP_USER_AGENT"]=~/MSIE/
@@ -45,6 +46,7 @@ module OpenTox
after do
Authorization.check_policy(@uri, @subjectid) if env['REQUEST_METHOD'].to_s == "POST" && $aa[:uri]
+
end
@@ -63,6 +65,39 @@ module OpenTox
@content_type = request.content_type
end
end
+
+ # format output according to accept header
+ def render object
+ if object.class == String
+ case @accept
+ when /text\/html/
+ content_type "text/html"
+ object.to_html
+ else
+ content_type 'text/uri-list'
+ object
+ end
+ elsif object.class == Array
+ content_type 'text/uri-list'
+ object.join "\n"
+ else
+ case @accept
+ when "application/rdf+xml"
+ content_type "application/rdf+xml"
+ object.to_rdfxml
+ when /text\/html/
+ content_type "text/html"
+ object.to_html
+ when /turtle/
+ content_type "text/turtle"
+ object.to_turtle
+ else
+ content_type "text/plain"
+ object.to_ntriples
+ end
+
+ end
+ end
end
# Attention: Error within tasks are catched by Task.run