diff options
-rw-r--r-- | lib/4store.rb | 6 | ||||
-rw-r--r-- | lib/opentox.rb | 36 |
2 files changed, 38 insertions, 4 deletions
diff --git a/lib/4store.rb b/lib/4store.rb index 0c78580..02f3a89 100644 --- a/lib/4store.rb +++ b/lib/4store.rb @@ -8,9 +8,9 @@ module OpenTox def self.list mime_type bad_request_error "'#{mime_type}' is not a supported mime type. Please specify one of #{@@accept_formats.join(", ")} in the Accept Header." unless @@accept_formats.include? mime_type if mime_type =~ /(uri-list|html|sparql-results)/ - sparql = "SELECT DISTINCT ?s WHERE {GRAPH ?g {?s <#{RDF.type}> <#{klass}>.} }" + sparql = "SELECT DISTINCT ?uri WHERE {GRAPH ?uri {?uri <#{RDF.type}> <#{klass}>.} }" else - sparql = "CONSTRUCT {?s <#{RDF.type}> <#{klass}>.} WHERE { GRAPH ?g {?s <#{RDF.type}> <#{klass}>.} }" + sparql = "CONSTRUCT {?uri <#{RDF.type}> <#{klass}>.} WHERE { GRAPH ?uri {?uri <#{RDF.type}> <#{klass}>.} }" end query sparql, mime_type end @@ -34,7 +34,7 @@ module OpenTox bad_request_error "'#{mime_type}' is not a supported content type. Please use one of #{@@content_type_formats.join(", ")}." unless @@content_type_formats.include? mime_type or mime_type == "multipart/form-data" 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) + 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 quotes) update "INSERT DATA { GRAPH <#{uri}> { <#{uri}> <#{RDF::DC.modified}> \"#{DateTime.now}\" } }" end diff --git a/lib/opentox.rb b/lib/opentox.rb index e3f1910..762c1f7 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -28,7 +28,7 @@ module OpenTox end before do - @uri = uri(request.env['REQUEST_URI']) + @uri = uri(request.env['PATH_INFO']) # prevent /algorithm/algorithm in algorithm service get_subjectid if respond_to? :get_subjectid # fix IE request.env['HTTP_ACCEPT'] += ";text/html" if request.env["HTTP_USER_AGENT"]=~/MSIE/ @@ -45,6 +45,7 @@ module OpenTox after do Authorization.check_policy(@uri, @subjectid) if env['REQUEST_METHOD'].to_s == "POST" && $aa[:uri] + end @@ -63,6 +64,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 |